From ea0fcf754ab19d7c3301a34e1b41b3f7e9c7caf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 9 Jan 2025 15:38:09 +0900 Subject: [PATCH] added history --- .../AppChrome/AddonBar/AddonBar.tsx | 27 ++++++++++++++++- .../AppChrome/History/HistoryContainer.tsx | 29 ++++--------------- .../AppChrome/History/HistoryWrapper.tsx | 29 ++++++++++--------- 3 files changed, 47 insertions(+), 38 deletions(-) diff --git a/public/app/core/components/AppChrome/AddonBar/AddonBar.tsx b/public/app/core/components/AppChrome/AddonBar/AddonBar.tsx index 66ac942d539..2e76b049a46 100644 --- a/public/app/core/components/AppChrome/AddonBar/AddonBar.tsx +++ b/public/app/core/components/AppChrome/AddonBar/AddonBar.tsx @@ -8,6 +8,7 @@ import { config } from '@grafana/runtime'; import { Dropdown, Icon, IconButton, ToolbarButton, useStyles2 } from '@grafana/ui'; import { useGrafana } from 'app/core/context/GrafanaContext'; import { contextSrv } from 'app/core/core'; +import { t } from 'app/core/internationalization'; import { useSelector } from 'app/types/store'; import { HistoryContainer } from '../History/HistoryContainer'; @@ -70,6 +71,20 @@ export function AddonBar() { }); }; + const onToggleHistory = () => { + if (state.addonBarPane?.id === 'history') { + chrome.update({ addonBarPane: undefined }); + return; + } + + chrome.update({ + addonBarPane: { + id: 'history', + content: , + }, + }); + }; + const transientApps = state.addonApps.filter((app) => app.isApp); const contextApps = state.addonApps.filter((app) => !app.isApp); @@ -113,7 +128,17 @@ export function AddonBar() { - {unifiedHistoryEnabled && } + {unifiedHistoryEnabled && ( + + + + )} {enrichedHelpNode && ( // } placement="bottom-end"> diff --git a/public/app/core/components/AppChrome/History/HistoryContainer.tsx b/public/app/core/components/AppChrome/History/HistoryContainer.tsx index 941e61a1b74..b037f689e66 100644 --- a/public/app/core/components/AppChrome/History/HistoryContainer.tsx +++ b/public/app/core/components/AppChrome/History/HistoryContainer.tsx @@ -1,22 +1,19 @@ import { css } from '@emotion/css'; import { useEffect } from 'react'; -import { useToggle } from 'react-use'; import { GrafanaTheme2, store } from '@grafana/data'; -import { Drawer, ToolbarButton } from '@grafana/ui'; +import { Drawer } from '@grafana/ui'; import { appEvents } from 'app/core/app_events'; import { t } from 'app/core/internationalization'; import { RecordHistoryEntryEvent } from 'app/types/events'; +import { AddonBarPane } from '../AddonBar/AddonBarPane'; import { HISTORY_LOCAL_STORAGE_KEY } from '../AppChromeService'; import { HistoryEntry } from '../types'; import { HistoryWrapper } from './HistoryWrapper'; export function HistoryContainer() { - const [showHistoryDrawer, onToggleShowHistoryDrawer] = useToggle(false); - // const styles = useStyles2(getStyles); - useEffect(() => { const sub = appEvents.subscribe(RecordHistoryEntryEvent, (ev) => { const clickedHistory = store.getObject('CLICKING_HISTORY'); @@ -47,25 +44,9 @@ export function HistoryContainer() { }, []); return ( - <> - - {/* */} - {showHistoryDrawer && ( - - onToggleShowHistoryDrawer(false)} /> - - )} - + + + ); } diff --git a/public/app/core/components/AppChrome/History/HistoryWrapper.tsx b/public/app/core/components/AppChrome/History/HistoryWrapper.tsx index 687f631fd8c..f409a466704 100644 --- a/public/app/core/components/AppChrome/History/HistoryWrapper.tsx +++ b/public/app/core/components/AppChrome/History/HistoryWrapper.tsx @@ -34,8 +34,8 @@ export function HistoryWrapper({ onClose }: { onClose: () => void }) { }, {}); return ( - - + + {Object.keys(hist).map((entries, date) => { return ( @@ -55,13 +55,14 @@ export function HistoryWrapper({ onClose }: { onClose: () => void }) { ); })} - - {history.length > numItemsToShow && ( - - )} - + + {history.length > numItemsToShow && ( + + )} + + ); } interface ItemProps { @@ -96,7 +97,7 @@ function HistoryEntryAppView({ entry, isSelected, onClick }: ItemProps) { className={styles.iconButton} /> ) : ( - + )}
{breadcrumbs.map((breadcrumb, index) => ( - + {breadcrumb.text} {index !== breadcrumbs.length - 1 ? '> ' : ''} ))}
- {moment(time).format('h:mm A')} + + {moment(time).format('h:mm A')} + {sparklineData && ( { expanded: css({ display: 'flex', flexDirection: 'column', - marginLeft: theme.spacing(5), + marginLeft: theme.spacing(0), gap: theme.spacing(1), position: 'relative', '&:before': {