From fdb9e47faeee91ce05eb5103a8ca5b099f7e5ecd Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Thu, 17 Apr 2025 11:39:30 -0600 Subject: [PATCH] dashboard filter predicate updates --- .../dashboards/dashboardQueryHelpers.ts | 18 +++++++++++------- .../metrics/getMetricQueryRequests.ts | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/web/src/api/buster_rest/dashboards/dashboardQueryHelpers.ts b/web/src/api/buster_rest/dashboards/dashboardQueryHelpers.ts index d5a11344c..bb6dca930 100644 --- a/web/src/api/buster_rest/dashboards/dashboardQueryHelpers.ts +++ b/web/src/api/buster_rest/dashboards/dashboardQueryHelpers.ts @@ -30,7 +30,11 @@ export const useEnsureDashboardConfig = (prefetchData: boolean = true) => { return null; }); if (res) { - queryClient.setQueryData(options.queryKey, res); + queryClient.setQueryData( + dashboardQueryKeys.dashboardGetDashboard(res.dashboard.id, res.dashboard.version_number) + .queryKey, + res + ); dashboardResponse = res; } } @@ -76,9 +80,10 @@ export const useGetDashboardAndInitializeMetrics = (prefetchData: boolean = true initializeMetrics(data.metrics); setOriginalDashboards(data.dashboard); - if (!version_number && data.dashboard.version_number) { + if (data.dashboard.version_number) { queryClient.setQueryData( - dashboardQueryKeys.dashboardGetDashboard(id, data.dashboard.version_number).queryKey, + dashboardQueryKeys.dashboardGetDashboard(data.dashboard.id, data.dashboard.version_number) + .queryKey, data ); } @@ -118,13 +123,12 @@ export const useGetDashboardVersionNumber = (props?: { }; type PredicateType = (query: Query) => boolean; -const filterMetricPredicate = ((query) => { +const filterDashboardPredicate = ((query) => { const lastKey = last(query.queryKey); return ( typeof lastKey === 'number' && !!lastKey && query.state.data !== undefined && - typeof query.state.data === 'object' && query.state.data !== null && 'versions' in query.state.data ); @@ -158,7 +162,7 @@ const useGetLatestDashboardVersion = ({ dashboardId }: { dashboardId: string }) const updateLatestVersion = useMemoizedFn(() => { const queries = queryClient.getQueriesData({ queryKey: memoizedKey, - predicate: filterMetricPredicate + predicate: filterDashboardPredicate }); const newVersion = getLatestVersionNumber(queries); setLatestVersion(newVersion); @@ -192,7 +196,7 @@ export const useGetLatestDashboardVersionNumber = () => { const method = useMemoizedFn((dashboardId: string) => { const queries = queryClient.getQueriesData({ queryKey: dashboardQueryKeys.dashboardGetDashboard(dashboardId, null).queryKey.slice(0, -1), - predicate: filterMetricPredicate + predicate: filterDashboardPredicate }); return getLatestVersionNumber(queries); diff --git a/web/src/api/buster_rest/metrics/getMetricQueryRequests.ts b/web/src/api/buster_rest/metrics/getMetricQueryRequests.ts index ea70c6aae..8bd6f256c 100644 --- a/web/src/api/buster_rest/metrics/getMetricQueryRequests.ts +++ b/web/src/api/buster_rest/metrics/getMetricQueryRequests.ts @@ -43,7 +43,7 @@ export const useGetMetric = ( const isLatestVersion = updatedMetric.version_number === last(updatedMetric.versions)?.version_number; if (isLatestVersion) setOriginalMetric(updatedMetric); - if (!paramVersionNumber && result?.version_number) { + if (result?.version_number) { queryClient.setQueryData( metricsQueryKeys.metricsGetMetric(result.id, result.version_number).queryKey, updatedMetric