From b3551bf140e5277d13edfbce40f4c55c954375c8 Mon Sep 17 00:00:00 2001 From: Yunus M Date: Wed, 6 Aug 2025 13:11:55 +0530 Subject: [PATCH] feat: handle save views --- frontend/src/api/saveView/getAllViews.ts | 2 +- .../ExplorerOptions/ExplorerOptions.tsx | 38 +++++++++++----- .../container/ExplorerOptions/constants.ts | 1 + .../src/container/ExplorerOptions/types.ts | 5 ++- .../src/container/ExplorerOptions/utils.ts | 2 +- .../Explorer/Explorer.styles.scss | 16 +++++++ .../MeterExplorer/Explorer/TimeSeries.tsx | 45 ++++++++++++------- .../BuilderUnitsFilter/BuilderUnits.tsx | 6 ++- frontend/src/container/SideNav/menuItems.tsx | 5 ++- .../src/hooks/saveViews/useGetAllViews.ts | 4 +- 10 files changed, 86 insertions(+), 38 deletions(-) diff --git a/frontend/src/api/saveView/getAllViews.ts b/frontend/src/api/saveView/getAllViews.ts index 4a54d6af0df4..a26fd13441f5 100644 --- a/frontend/src/api/saveView/getAllViews.ts +++ b/frontend/src/api/saveView/getAllViews.ts @@ -4,6 +4,6 @@ import { AllViewsProps } from 'types/api/saveViews/types'; import { DataSource } from 'types/common/queryBuilder'; export const getAllViews = ( - sourcepage: DataSource, + sourcepage: DataSource | 'meter', ): Promise> => axios.get(`/explorer/views?sourcePage=${sourcepage}`); diff --git a/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx b/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx index f46e695b7531..d425b29d4d05 100644 --- a/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx +++ b/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx @@ -111,6 +111,7 @@ function ExplorerOptions({ const isLogsExplorer = sourcepage === DataSource.LOGS; const isMetricsExplorer = sourcepage === DataSource.METRICS; + const isMeterExplorer = signalSource === 'meter'; const PRESERVED_VIEW_LOCAL_STORAGE_KEY = LOCALSTORAGE.LAST_USED_SAVED_VIEWS; @@ -121,8 +122,11 @@ function ExplorerOptions({ if (isMetricsExplorer) { return PreservedViewsTypes.METRICS; } + if (isMeterExplorer) { + return PreservedViewsTypes.METER; + } return PreservedViewsTypes.TRACES; - }, [isLogsExplorer, isMetricsExplorer]); + }, [isLogsExplorer, isMetricsExplorer, isMeterExplorer]); const onModalToggle = useCallback((value: boolean) => { setIsExport(value); @@ -151,6 +155,10 @@ function ExplorerOptions({ [MetricsExplorerEventKeys.OneChartPerQueryEnabled]: isOneChartPerQuery, panelType, }); + } else if (isMeterExplorer) { + logEvent('Meter Explorer: Save view clicked', { + panelType, + }); } setIsSaveModalOpen(!isSaveModalOpen); }; @@ -244,7 +252,7 @@ function ExplorerOptions({ error, isRefetching, refetch: refetchAllView, - } = useGetAllViews(sourcepage); + } = useGetAllViews(isMeterExplorer ? 'meter' : sourcepage); const compositeQuery = mapCompositeQueryFromQuery(currentQuery, panelType); @@ -317,7 +325,7 @@ function ExplorerOptions({ compositeQuery, viewKey, extraData: updatedExtraData, - sourcePage: sourcepage, + sourcePage: isMeterExplorer ? 'meter' : sourcepage, viewName, }); @@ -333,7 +341,7 @@ function ExplorerOptions({ compositeQuery: mapCompositeQueryFromQuery(currentQuery, panelType), viewKey, extraData: updatedExtraData, - sourcePage: sourcepage, + sourcePage: isMeterExplorer ? 'meter' : sourcepage, viewName, }, { @@ -460,6 +468,11 @@ function ExplorerOptions({ panelType, viewName: option?.value, }); + } else if (isMeterExplorer) { + logEvent('Meter Explorer: Select view', { + panelType, + viewName: option?.value, + }); } updatePreservedViewInLocalStorage(option); @@ -555,7 +568,7 @@ function ExplorerOptions({ redirectWithQueryBuilderData, refetchAllView, saveViewAsync, - sourcePage: sourcepage, + sourcePage: isMeterExplorer ? 'meter' : sourcepage, viewName: newViewName, setNewViewName, }); @@ -674,7 +687,7 @@ function ExplorerOptions({ return `Query ${query.builder.queryData[0].queryName}`; }; - const alertButton = useMemo(() => { + const CreateAlertButton = useMemo(() => { if (isOneChartPerQuery) { const selectLabel = (