diff --git a/web/src/api/buster_rest/metrics/queryRequests.ts b/web/src/api/buster_rest/metrics/queryRequests.ts index 607bb334e..acce93cb4 100644 --- a/web/src/api/buster_rest/metrics/queryRequests.ts +++ b/web/src/api/buster_rest/metrics/queryRequests.ts @@ -50,14 +50,15 @@ export const useGetMetricVersionNumber = ({ ? versionNumberQueryParam || versionNumberPathParam : undefined; - const versionNumber = useMemo(() => { + const versionNumberX = useMemo(() => { if (versionNumberProp === null) return undefined; - return versionNumberProp || versionNumberFromParams - ? parseInt(versionNumberFromParams!) - : undefined; + return ( + versionNumberProp ?? + (versionNumberFromParams ? parseInt(versionNumberFromParams!) : undefined) + ); }, [versionNumberProp, versionNumberFromParams]); - return versionNumber; + return versionNumberX; }; /** @@ -81,9 +82,7 @@ export const useGetMetric = ( const versionNumber = useGetMetricVersionNumber({ versionNumber: versionNumberProp }); - const options = useMemo(() => { - return metricsQueryKeys.metricsGetMetric(id!, versionNumber); - }, [id, versionNumber]); + const options = metricsQueryKeys.metricsGetMetric(id!, versionNumber); const queryFn = useMemoizedFn(async () => { const result = await getMetric({ id: id!, password, version_number: versionNumber }); @@ -92,6 +91,7 @@ export const useGetMetric = ( const isLatestVersion = updatedMetric.version_number === last(updatedMetric.versions)?.version_number; + if (isLatestVersion) setOriginalMetric(updatedMetric); if (!versionNumber && result?.version_number) { @@ -247,6 +247,7 @@ export const useSaveMetric = (params?: { updateOnSave?: boolean }) => { ); const newMetric = upgradeMetricToIMetric(data, oldMetric || null); if (updateOnSave && data) { + //We need to update BOTH the versioned and the non-versioned metric queryClient.setQueryData( metricsQueryKeys.metricsGetMetric(data.id, data.version_number).queryKey, newMetric @@ -375,6 +376,7 @@ export const useShareMetric = () => { metricsQueryKeys.metricsGetMetric(data.id, data.version_number).queryKey ); const upgradedMetric = upgradeMetricToIMetric(data, oldMetric || null); + queryClient.setQueryData( metricsQueryKeys.metricsGetMetric(data.id, data.version_number).queryKey, upgradedMetric diff --git a/web/src/components/features/versionHistory/useListVersionHistories.tsx b/web/src/components/features/versionHistory/useListVersionHistories.tsx index ebb804c47..dc2b7cbb2 100644 --- a/web/src/components/features/versionHistory/useListVersionHistories.tsx +++ b/web/src/components/features/versionHistory/useListVersionHistories.tsx @@ -170,7 +170,7 @@ const useListMetricVersions = ({ const metricVersionNumber = useChatLayoutContextSelector((x) => x.metricVersionNumber); - const { data: metric, isFetched } = useGetMetric( + const { data: metric } = useGetMetric( { id: type === 'metric' ? assetId : undefined }, diff --git a/web/src/context/BusterReactQuery/createPersister.ts b/web/src/context/BusterReactQuery/createPersister.ts index d3e3b3815..6b0976d27 100644 --- a/web/src/context/BusterReactQuery/createPersister.ts +++ b/web/src/context/BusterReactQuery/createPersister.ts @@ -17,7 +17,10 @@ export const PERSISTED_QUERIES = [ queryKeys.metricsGetList().queryKey, queryKeys.collectionsGetList().queryKey, queryKeys.termsGetList.queryKey, - queryKeys.datasetsListQueryOptions().queryKey + queryKeys.datasetsListQueryOptions().queryKey, + queryKeys.permissionGroupList.queryKey, + queryKeys.datasourceGetList.queryKey, + queryKeys.datasetGroupsList.queryKey ].map(hashKey); export const PERMANENT_QUERIES = [queryKeys.getCurrencies.queryKey].map(hashKey); diff --git a/web/src/context/Metrics/useIsMetricChanged.tsx b/web/src/context/Metrics/useIsMetricChanged.tsx index 0a251b3bd..41788ab3a 100644 --- a/web/src/context/Metrics/useIsMetricChanged.tsx +++ b/web/src/context/Metrics/useIsMetricChanged.tsx @@ -1,23 +1,30 @@ -import { useQueryClient } from '@tanstack/react-query'; +import { useQuery, useQueryClient } from '@tanstack/react-query'; import { useOriginalMetricStore } from './useOriginalMetricStore'; import { useMemoizedFn } from '@/hooks'; import { metricsQueryKeys } from '@/api/query_keys/metric'; import { useGetMetric } from '@/api/buster_rest/metrics'; import { compareObjectsByKeys } from '@/lib/objects'; import { useMemo } from 'react'; +import last from 'lodash/last'; export const useIsMetricChanged = ({ metricId }: { metricId: string }) => { const queryClient = useQueryClient(); const originalMetric = useOriginalMetricStore((x) => x.getOriginalMetric(metricId)); - const { data: currentMetric, refetch: refetchCurrentMetric } = useGetMetric( + const { data: latestVersionNumber } = useGetMetric( { id: metricId }, + { select: (x) => last(x.versions)?.version_number } + ); + + const { data: currentMetric, refetch: refetchCurrentMetric } = useGetMetric( + { id: metricId, versionNumber: latestVersionNumber }, { select: (x) => ({ name: x.name, description: x.description, chart_config: x.chart_config, - file: x.file + file: x.file, + updated_at: x.updated_at }) } ); diff --git a/web/src/context/Metrics/useIsMetricReadOnly.tsx b/web/src/context/Metrics/useIsMetricReadOnly.tsx index 742efb0cb..9bb1cd57d 100644 --- a/web/src/context/Metrics/useIsMetricReadOnly.tsx +++ b/web/src/context/Metrics/useIsMetricReadOnly.tsx @@ -20,7 +20,6 @@ export const useIsMetricReadOnly = ({ } = useGetMetric( { id: metricId }, { - enabled: false, select: (x) => ({ permission: x.permission, versions: x.versions, diff --git a/web/src/lib/metrics/saveToServerHelpers.ts b/web/src/lib/metrics/saveToServerHelpers.ts index b66706251..0337e4da6 100644 --- a/web/src/lib/metrics/saveToServerHelpers.ts +++ b/web/src/lib/metrics/saveToServerHelpers.ts @@ -33,7 +33,6 @@ export const getChangedTopLevelMessageValues = ( 'sql', 'file' ]); - return changes; }; diff --git a/web/src/lib/objects.ts b/web/src/lib/objects.ts index 977b0615f..7f7fba495 100644 --- a/web/src/lib/objects.ts +++ b/web/src/lib/objects.ts @@ -47,11 +47,25 @@ export const compareObjectsByKeys = ( if (typeof val1 === 'object' && typeof val2 === 'object') { const itWasEqual = isEqual(val1, val2) || isEqual(JSON.stringify(val1), JSON.stringify(val2)); + // if (!itWasEqual) { + // console.log('--------------NESTED KEYS NOT EQUAL------------------'); + // console.log('KEY', key); + // console.log('ORIGINAL', val1); + // console.log('NEW', val2); + // } + return itWasEqual; } const itWasEqual = isEqual(val1, val2); + // if (!itWasEqual) { + // console.log('--------------KEYS NOT EQUAL------------------'); + // console.log('KEY', key); + // console.log('ORIGINAL', val1); + // console.log('NEW', val2); + // } + return itWasEqual; }); };