update verification is snappier

This commit is contained in:
Nate Kelley 2025-04-17 00:32:25 -06:00
parent 7ffb8f1628
commit 5bfba6d082
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
6 changed files with 77 additions and 14 deletions

View File

@ -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 { collectionQueryKeys } from '@/api/query_keys/collection';
import { import {
collectionsGetList, collectionsGetList,
@ -18,9 +18,14 @@ import { useMemoizedFn } from '@/hooks';
import { useBusterAssetsContextSelector } from '@/context/Assets/BusterAssetsProvider'; import { useBusterAssetsContextSelector } from '@/context/Assets/BusterAssetsProvider';
import { create } from 'mutative'; import { create } from 'mutative';
import type { BusterCollection } from '@/api/asset_interfaces/collection'; import type { BusterCollection } from '@/api/asset_interfaces/collection';
import { RustApiError } from '../errors';
export const useGetCollectionsList = ( export const useGetCollectionsList = (
filters: Omit<Parameters<typeof collectionsGetList>[0], 'page' | 'page_size'> filters: Omit<Parameters<typeof collectionsGetList>[0], 'page' | 'page_size'>,
options?: Omit<
UseQueryOptions<Awaited<ReturnType<typeof collectionsGetList>>, RustApiError>,
'queryKey' | 'queryFn'
>
) => { ) => {
const payload = useMemo(() => { const payload = useMemo(() => {
return { page: 0, page_size: 3000, ...filters }; return { page: 0, page_size: 3000, ...filters };
@ -28,7 +33,8 @@ export const useGetCollectionsList = (
return useQuery({ return useQuery({
...collectionQueryKeys.collectionsGetList(filters), ...collectionQueryKeys.collectionsGetList(filters),
queryFn: () => collectionsGetList(payload) queryFn: () => collectionsGetList(payload),
...options
}); });
}; };

View File

@ -615,7 +615,11 @@ export const useRemoveMetricsFromDashboard = () => {
}; };
export const useGetDashboardsList = ( export const useGetDashboardsList = (
params: Omit<Parameters<typeof dashboardsGetList>[0], 'page_token' | 'page_size'> params: Omit<Parameters<typeof dashboardsGetList>[0], 'page_token' | 'page_size'>,
options?: Omit<
UseQueryOptions<Awaited<ReturnType<typeof dashboardsGetList>>, RustApiError>,
'queryKey' | 'queryFn'
>
) => { ) => {
const filters = useMemo(() => { const filters = useMemo(() => {
return { return {
@ -627,6 +631,7 @@ export const useGetDashboardsList = (
return useQuery({ return useQuery({
...dashboardQueryKeys.dashboardGetList(params), ...dashboardQueryKeys.dashboardGetList(params),
queryFn: () => dashboardsGetList(filters) queryFn: () => dashboardsGetList(filters),
...options
}); });
}; };

View File

@ -1,11 +1,16 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import { listMetrics } from './requests'; import { listMetrics } from './requests';
import { useQuery } from '@tanstack/react-query'; import { useQuery, UseQueryOptions } from '@tanstack/react-query';
import { useMemoizedFn } from '@/hooks'; import { useMemoizedFn } from '@/hooks';
import { metricsQueryKeys } from '@/api/query_keys/metric'; import { metricsQueryKeys } from '@/api/query_keys/metric';
import { RustApiError } from '../errors';
export const useGetMetricsList = ( export const useGetMetricsList = (
params: Omit<Parameters<typeof listMetrics>[0], 'page_token' | 'page_size'> params: Omit<Parameters<typeof listMetrics>[0], 'page_token' | 'page_size'>,
options?: Omit<
UseQueryOptions<Awaited<ReturnType<typeof listMetrics>>, RustApiError>,
'queryKey' | 'queryFn'
>
) => { ) => {
const compiledParams: Parameters<typeof listMetrics>[0] = useMemo( const compiledParams: Parameters<typeof listMetrics>[0] = useMemo(
() => ({ ...params, page_token: 0, page_size: 3000 }), () => ({ ...params, page_token: 0, page_size: 3000 }),
@ -16,6 +21,8 @@ export const useGetMetricsList = (
return useQuery({ return useQuery({
...metricsQueryKeys.metricsGetList(params), ...metricsQueryKeys.metricsGetList(params),
queryFn queryFn,
select: options?.select,
...options
}); });
}; };

View File

@ -1,6 +1,6 @@
import { useOriginalMetricStore } from '@/context/Metrics/useOriginalMetricStore'; import { useOriginalMetricStore } from '@/context/Metrics/useOriginalMetricStore';
import { useMutation, useQueryClient } from '@tanstack/react-query'; import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useGetMetricVersionNumber } from './metricQueryHelpers'; import { useGetLatestMetricVersionNumber, useGetMetricVersionNumber } from './metricQueryHelpers';
import { import {
bulkUpdateMetricVerificationStatus, bulkUpdateMetricVerificationStatus,
deleteMetrics, deleteMetrics,
@ -355,8 +355,25 @@ export const useUpdateMetric = (params: {
export const useBulkUpdateMetricVerificationStatus = () => { export const useBulkUpdateMetricVerificationStatus = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const getLatestVersionNumber = useGetLatestMetricVersionNumber();
return useMutation({ return useMutation({
mutationFn: bulkUpdateMetricVerificationStatus, 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) => { onSuccess: (data) => {
queryClient.invalidateQueries({ queryKey: metricsQueryKeys.metricsGetList({}).queryKey }); queryClient.invalidateQueries({ queryKey: metricsQueryKeys.metricsGetList({}).queryKey });
data.updated_metrics.forEach((metric) => { data.updated_metrics.forEach((metric) => {

View File

@ -125,10 +125,7 @@ export const useSaveToCollectionsDropdownContent = ({
onRemoveFromCollection(collection.id); onRemoveFromCollection(collection.id);
} else { } else {
const allCollectionsAndSelected = selectedCollections.map((id) => id).concat(collection.id); const allCollectionsAndSelected = selectedCollections.map((id) => id).concat(collection.id);
const differenceFromSelectedCollections = allCollectionsAndSelected.filter( onSaveToCollection(allCollectionsAndSelected);
(id) => !selectedCollections.some((selectedId) => selectedId === id)
);
onSaveToCollection(differenceFromSelectedCollections);
} }
}); });

View File

@ -1,4 +1,7 @@
import { ShareAssetType } from '@/api/asset_interfaces/share'; 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 { import {
useAddUserFavorite, useAddUserFavorite,
useDeleteUserFavorite, useDeleteUserFavorite,
@ -20,6 +23,34 @@ export const useThreeDotFavoritesOptions = ({
const { mutateAsync: addUserFavorite } = useAddUserFavorite(); const { mutateAsync: addUserFavorite } = useAddUserFavorite();
const { mutateAsync: removeUserFavorite } = useDeleteUserFavorite(); const { mutateAsync: removeUserFavorite } = useDeleteUserFavorite();
const { data: userFavorites } = useGetUserFavorites(); 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( const dropdownOptions: DropdownItems = useMemo(
() => [ () => [
@ -32,7 +63,7 @@ export const useThreeDotFavoritesOptions = ({
...itemIds.map((id) => ({ ...itemIds.map((id) => ({
id, id,
asset_type: assetType, asset_type: assetType,
name: userFavorites?.find((f) => f.id === id)?.name || '' name: nameSearchArray.find((n) => n.id === id)?.name || ''
})) }))
]); ]);
onFinish(itemIds); onFinish(itemIds);