diff --git a/web/src/api/buster_rest/collections/queryRequests.ts b/web/src/api/buster_rest/collections/queryRequests.ts index 40a5ea401..b5cea00bc 100644 --- a/web/src/api/buster_rest/collections/queryRequests.ts +++ b/web/src/api/buster_rest/collections/queryRequests.ts @@ -1,4 +1,4 @@ -import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; +import { useMutation, useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'; import { collectionQueryKeys } from '@/api/query_keys/collection'; import { collectionsGetList, @@ -18,9 +18,14 @@ import { useMemoizedFn } from '@/hooks'; import { useBusterAssetsContextSelector } from '@/context/Assets/BusterAssetsProvider'; import { create } from 'mutative'; import type { BusterCollection } from '@/api/asset_interfaces/collection'; +import { RustApiError } from '../errors'; export const useGetCollectionsList = ( - filters: Omit[0], 'page' | 'page_size'> + filters: Omit[0], 'page' | 'page_size'>, + options?: Omit< + UseQueryOptions>, RustApiError>, + 'queryKey' | 'queryFn' + > ) => { const payload = useMemo(() => { return { page: 0, page_size: 3000, ...filters }; @@ -28,7 +33,8 @@ export const useGetCollectionsList = ( return useQuery({ ...collectionQueryKeys.collectionsGetList(filters), - queryFn: () => collectionsGetList(payload) + queryFn: () => collectionsGetList(payload), + ...options }); }; diff --git a/web/src/api/buster_rest/dashboards/queryRequests.ts b/web/src/api/buster_rest/dashboards/queryRequests.ts index cad29de9f..8ca5392ee 100644 --- a/web/src/api/buster_rest/dashboards/queryRequests.ts +++ b/web/src/api/buster_rest/dashboards/queryRequests.ts @@ -615,7 +615,11 @@ export const useRemoveMetricsFromDashboard = () => { }; export const useGetDashboardsList = ( - params: Omit[0], 'page_token' | 'page_size'> + params: Omit[0], 'page_token' | 'page_size'>, + options?: Omit< + UseQueryOptions>, RustApiError>, + 'queryKey' | 'queryFn' + > ) => { const filters = useMemo(() => { return { @@ -627,6 +631,7 @@ export const useGetDashboardsList = ( return useQuery({ ...dashboardQueryKeys.dashboardGetList(params), - queryFn: () => dashboardsGetList(filters) + queryFn: () => dashboardsGetList(filters), + ...options }); }; diff --git a/web/src/api/buster_rest/metrics/getMetricListQueryRequests.ts b/web/src/api/buster_rest/metrics/getMetricListQueryRequests.ts index e598f8194..bbfeab1bb 100644 --- a/web/src/api/buster_rest/metrics/getMetricListQueryRequests.ts +++ b/web/src/api/buster_rest/metrics/getMetricListQueryRequests.ts @@ -1,11 +1,16 @@ import { useMemo } from 'react'; import { listMetrics } from './requests'; -import { useQuery } from '@tanstack/react-query'; +import { useQuery, UseQueryOptions } from '@tanstack/react-query'; import { useMemoizedFn } from '@/hooks'; import { metricsQueryKeys } from '@/api/query_keys/metric'; +import { RustApiError } from '../errors'; export const useGetMetricsList = ( - params: Omit[0], 'page_token' | 'page_size'> + params: Omit[0], 'page_token' | 'page_size'>, + options?: Omit< + UseQueryOptions>, RustApiError>, + 'queryKey' | 'queryFn' + > ) => { const compiledParams: Parameters[0] = useMemo( () => ({ ...params, page_token: 0, page_size: 3000 }), @@ -16,6 +21,8 @@ export const useGetMetricsList = ( return useQuery({ ...metricsQueryKeys.metricsGetList(params), - queryFn + queryFn, + select: options?.select, + ...options }); }; diff --git a/web/src/api/buster_rest/metrics/updateMetricQueryRequests.ts b/web/src/api/buster_rest/metrics/updateMetricQueryRequests.ts index e6cb3ead3..0a32f7365 100644 --- a/web/src/api/buster_rest/metrics/updateMetricQueryRequests.ts +++ b/web/src/api/buster_rest/metrics/updateMetricQueryRequests.ts @@ -1,6 +1,6 @@ import { useOriginalMetricStore } from '@/context/Metrics/useOriginalMetricStore'; import { useMutation, useQueryClient } from '@tanstack/react-query'; -import { useGetMetricVersionNumber } from './metricQueryHelpers'; +import { useGetLatestMetricVersionNumber, useGetMetricVersionNumber } from './metricQueryHelpers'; import { bulkUpdateMetricVerificationStatus, deleteMetrics, @@ -355,8 +355,25 @@ export const useUpdateMetric = (params: { export const useBulkUpdateMetricVerificationStatus = () => { const queryClient = useQueryClient(); + const getLatestVersionNumber = useGetLatestMetricVersionNumber(); return useMutation({ mutationFn: bulkUpdateMetricVerificationStatus, + onMutate: (variables) => { + variables.forEach((metric) => { + const latestVersionNumber = getLatestVersionNumber(metric.id); + const foundMetric = queryClient.getQueryData( + metricsQueryKeys.metricsGetMetric(metric.id, latestVersionNumber).queryKey + ); + if (foundMetric) { + queryClient.setQueryData( + metricsQueryKeys.metricsGetMetric(metric.id, latestVersionNumber).queryKey, + create(foundMetric!, (draft: IBusterMetric) => { + draft.status = metric.status; + }) + ); + } + }); + }, onSuccess: (data) => { queryClient.invalidateQueries({ queryKey: metricsQueryKeys.metricsGetList({}).queryKey }); data.updated_metrics.forEach((metric) => { diff --git a/web/src/components/features/dropdowns/SaveToCollectionsDropdown.tsx b/web/src/components/features/dropdowns/SaveToCollectionsDropdown.tsx index a0d4b9dd7..762383616 100644 --- a/web/src/components/features/dropdowns/SaveToCollectionsDropdown.tsx +++ b/web/src/components/features/dropdowns/SaveToCollectionsDropdown.tsx @@ -125,10 +125,7 @@ export const useSaveToCollectionsDropdownContent = ({ onRemoveFromCollection(collection.id); } else { const allCollectionsAndSelected = selectedCollections.map((id) => id).concat(collection.id); - const differenceFromSelectedCollections = allCollectionsAndSelected.filter( - (id) => !selectedCollections.some((selectedId) => selectedId === id) - ); - onSaveToCollection(differenceFromSelectedCollections); + onSaveToCollection(allCollectionsAndSelected); } }); diff --git a/web/src/components/features/dropdowns/useThreeDotFavoritesOptions.tsx b/web/src/components/features/dropdowns/useThreeDotFavoritesOptions.tsx index b1838732f..4922c7332 100644 --- a/web/src/components/features/dropdowns/useThreeDotFavoritesOptions.tsx +++ b/web/src/components/features/dropdowns/useThreeDotFavoritesOptions.tsx @@ -1,4 +1,7 @@ import { ShareAssetType } from '@/api/asset_interfaces/share'; +import { useGetCollectionsList } from '@/api/buster_rest/collections'; +import { useGetDashboardsList } from '@/api/buster_rest/dashboards'; +import { useGetMetricsList } from '@/api/buster_rest/metrics'; import { useAddUserFavorite, useDeleteUserFavorite, @@ -20,6 +23,34 @@ export const useThreeDotFavoritesOptions = ({ const { mutateAsync: addUserFavorite } = useAddUserFavorite(); const { mutateAsync: removeUserFavorite } = useDeleteUserFavorite(); const { data: userFavorites } = useGetUserFavorites(); + const { data: metricList } = useGetMetricsList({}, { enabled: false }); + const { data: dashboardList } = useGetDashboardsList({}, { enabled: false }); + const { data: collectionList } = useGetCollectionsList({}, { enabled: false }); + + const nameSearchArray = useMemo(() => { + if (assetType === 'metric' && metricList) { + return metricList?.map((m) => ({ + id: m.id, + name: m.name + })); + } + + if (assetType === 'dashboard' && dashboardList) { + return dashboardList?.map((d) => ({ + id: d.id, + name: d.name + })); + } + + if (assetType === 'collection' && collectionList) { + return collectionList?.map((c) => ({ + id: c.id, + name: c.name + })); + } + + return []; + }, [assetType, metricList, dashboardList, collectionList]); const dropdownOptions: DropdownItems = useMemo( () => [ @@ -32,7 +63,7 @@ export const useThreeDotFavoritesOptions = ({ ...itemIds.map((id) => ({ id, asset_type: assetType, - name: userFavorites?.find((f) => f.id === id)?.name || '' + name: nameSearchArray.find((n) => n.id === id)?.name || '' })) ]); onFinish(itemIds);