From a8eeec74149f29b7503edfde5ef69f3a50bf6b2f Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Fri, 2 May 2025 12:05:23 -0600 Subject: [PATCH] update saved version numbers --- .../buster_rest/dashboards/queryRequests.ts | 22 +++++++++++++++---- .../barAndLineTooltipHelper.test.ts | 8 ------- .../lineSeriesBuilder.test.ts | 2 -- .../legendHeadlineHelpers.ts | 1 - .../context/Assets/useGetFileLink.test.tsx | 1 - 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/web/src/api/buster_rest/dashboards/queryRequests.ts b/web/src/api/buster_rest/dashboards/queryRequests.ts index b6dea4a84..a117c6e29 100644 --- a/web/src/api/buster_rest/dashboards/queryRequests.ts +++ b/web/src/api/buster_rest/dashboards/queryRequests.ts @@ -198,6 +198,7 @@ export const useUpdateDashboardConfig = () => { export const useCreateDashboard = () => { const queryClient = useQueryClient(); const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard); + const setLatestDashboardVersion = useDashboardQueryStore((x) => x.onSetLatestDashboardVersion); return useMutation({ mutationFn: dashboardsCreateDashboard, onSuccess: (originalData, variables) => { @@ -214,6 +215,7 @@ export const useCreateDashboard = () => { data ); setOriginalDashboard(data.dashboard); + setLatestDashboardVersion(data.dashboard.id, data.dashboard.version_number); setTimeout(() => { queryClient.invalidateQueries({ queryKey: dashboardQueryKeys.dashboardGetList().queryKey, @@ -426,6 +428,7 @@ export const useAddAndRemoveMetricsFromDashboard = () => { const { openErrorMessage, openConfirmModal } = useBusterNotifications(); const ensureDashboardConfig = useEnsureDashboardConfig(false); const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard); + const setLatestDashboardVersion = useDashboardQueryStore((x) => x.onSetLatestDashboardVersion); const addAndRemoveMetrics = useMemoizedFn( async ({ @@ -456,7 +459,7 @@ export const useAddAndRemoveMetricsFromDashboard = () => { const availableSlots = MAX_NUMBER_OF_ITEMS_ON_DASHBOARD - currentMetricCount; const metricsToActuallyAdd = metricsToAdd.slice(0, availableSlots); - const addMethod = () => { + const addMethod = async () => { // Create the final list of metrics to include const finalMetricIds = [ ...Array.from(existingMetricIds).filter((id) => !metricsToRemove.includes(id)), @@ -468,10 +471,12 @@ export const useAddAndRemoveMetricsFromDashboard = () => { dashboardResponse.dashboard.config ); - return dashboardsUpdateDashboard({ + const data = await dashboardsUpdateDashboard({ id: dashboardId, config: newConfig }); + + return data; }; if (metricsToAdd.length > availableSlots) { @@ -507,7 +512,7 @@ export const useAddAndRemoveMetricsFromDashboard = () => { }); } - return addMethod(); + return await addMethod(); } openErrorMessage('Failed to save metrics to dashboard'); @@ -525,6 +530,7 @@ export const useAddAndRemoveMetricsFromDashboard = () => { data ); setOriginalDashboard(data.dashboard); + setLatestDashboardVersion(data.dashboard.id, data.dashboard.version_number); } } }); @@ -536,6 +542,7 @@ export const useAddMetricsToDashboard = () => { const ensureDashboardConfig = useEnsureDashboardConfig(false); const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard); const getLatestMetricVersion = useGetLatestMetricVersionMemoized(); + const setLatestDashboardVersion = useDashboardQueryStore((x) => x.onSetLatestDashboardVersion); const addMetricToDashboard = useMemoizedFn( async ({ metricIds, dashboardId }: { metricIds: string[]; dashboardId: string }) => { @@ -614,6 +621,7 @@ export const useAddMetricsToDashboard = () => { }); setOriginalDashboard(data.dashboard); + setLatestDashboardVersion(data.dashboard.id, data.dashboard.version_number); } } }); @@ -625,6 +633,7 @@ export const useRemoveMetricsFromDashboard = () => { const ensureDashboardConfig = useEnsureDashboardConfig(false); const setOriginalDashboard = useOriginalDashboardStore((x) => x.setOriginalDashboard); const getLatestMetricVersion = useGetLatestMetricVersionMemoized(); + const setLatestDashboardVersion = useDashboardQueryStore((x) => x.onSetLatestDashboardVersion); const removeMetricFromDashboard = useMemoizedFn( async ({ @@ -710,7 +719,12 @@ export const useRemoveMetricsFromDashboard = () => { ); return useMutation({ - mutationFn: removeMetricFromDashboard + mutationFn: removeMetricFromDashboard, + onSuccess: (data) => { + if (data) { + setLatestDashboardVersion(data.dashboard.id, data.dashboard.version_number); + } + } }); }; diff --git a/web/src/components/ui/charts/BusterChartJS/hooks/useOptions/useTooltipOptions.ts/barAndLineTooltipHelper.test.ts b/web/src/components/ui/charts/BusterChartJS/hooks/useOptions/useTooltipOptions.ts/barAndLineTooltipHelper.test.ts index 740bd7768..3dd9ab931 100644 --- a/web/src/components/ui/charts/BusterChartJS/hooks/useOptions/useTooltipOptions.ts/barAndLineTooltipHelper.test.ts +++ b/web/src/components/ui/charts/BusterChartJS/hooks/useOptions/useTooltipOptions.ts/barAndLineTooltipHelper.test.ts @@ -109,12 +109,6 @@ describe('barAndLineTooltipHelper', () => { const hasMultipleShownDatasets = true; const mockDataPoint = createMockDataPoint(); - console.log(JSON.stringify(mockChart, null, 2)); - - console.log(JSON.stringify(mockColumnLabelFormats, null, 2)); - - console.log(JSON.stringify(mockDataPoint, null, 2)); - const result = barAndLineTooltipHelper( [mockDataPoint], mockChart, @@ -124,8 +118,6 @@ describe('barAndLineTooltipHelper', () => { undefined ); - console.log(JSON.stringify(result, null, 2)); - expect(result).toHaveLength(2); // Check the value item diff --git a/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts b/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts index 44e0bc07d..f8cd605b0 100644 --- a/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts +++ b/web/src/components/ui/charts/BusterChartJS/hooks/useSeriesOptions/lineSeriesBuilder.test.ts @@ -307,9 +307,7 @@ describe('lineSeriesBuilder', () => { } }; const labels = lineSeriesBuilder_labels(props); - console.log(props.datasetOptions.ticks); expect(props.datasetOptions.ticks).toHaveLength(3); - console.log(labels); expect(labels).toHaveLength(3); expect(typeof labels[0]).not.toBe('string'); expect(createDayjsDate).toHaveBeenCalledWith('2023-01-01'); diff --git a/web/src/components/ui/charts/BusterChartLegend/legendHeadlineHelpers.ts b/web/src/components/ui/charts/BusterChartLegend/legendHeadlineHelpers.ts index 374f72b5f..1de0d5268 100644 --- a/web/src/components/ui/charts/BusterChartLegend/legendHeadlineHelpers.ts +++ b/web/src/components/ui/charts/BusterChartLegend/legendHeadlineHelpers.ts @@ -25,7 +25,6 @@ export const addLegendHeadlines = ( // const canUseRange = !hasMultipleXAxisDimensions && xIsDate; // let range: string; // if (canUseRange) { - // console.log(columnMetadata, firstXAxisDimensionName); // const firstXAxisDimensionMetadata = columnMetadata.find( // (metadata) => metadata.name === firstXAxisDimensionName // ); diff --git a/web/src/context/Assets/useGetFileLink.test.tsx b/web/src/context/Assets/useGetFileLink.test.tsx index 700803b10..c71a81327 100644 --- a/web/src/context/Assets/useGetFileLink.test.tsx +++ b/web/src/context/Assets/useGetFileLink.test.tsx @@ -222,7 +222,6 @@ describe('useGetFileLink', () => { fileType: 'dashboard', versionNumber: mockDashboardVersionNumber }); - console.log(meta); expect(meta).toEqual({ link: `/dashboards/${mockDashboardId}/v${mockDashboardVersionNumber}`,