mirror of https://github.com/buster-so/buster.git
update verification is snappier
This commit is contained in:
parent
7ffb8f1628
commit
5bfba6d082
|
@ -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<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(() => {
|
||||
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
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -615,7 +615,11 @@ export const useRemoveMetricsFromDashboard = () => {
|
|||
};
|
||||
|
||||
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(() => {
|
||||
return {
|
||||
|
@ -627,6 +631,7 @@ export const useGetDashboardsList = (
|
|||
|
||||
return useQuery({
|
||||
...dashboardQueryKeys.dashboardGetList(params),
|
||||
queryFn: () => dashboardsGetList(filters)
|
||||
queryFn: () => dashboardsGetList(filters),
|
||||
...options
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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<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(
|
||||
() => ({ ...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
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue