mirror of https://github.com/buster-so/buster.git
Invalidation after add to dashboard
This commit is contained in:
parent
ac6b63bd6d
commit
2ba9044d13
|
@ -745,10 +745,26 @@ export const useRemoveMetricsFromDashboard = () => {
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: removeMetricFromDashboard,
|
mutationFn: removeMetricFromDashboard,
|
||||||
onSuccess: (data) => {
|
onMutate: (variables) => {
|
||||||
|
variables.metricIds.forEach((id) => {
|
||||||
|
queryClient.setQueryData(metricsQueryKeys.metricsGetMetric(id, null).queryKey, (old) => {
|
||||||
|
if (!old) return old;
|
||||||
|
return create(old, (draft) => {
|
||||||
|
draft.dashboards = old?.dashboards?.filter((d) => d.id !== variables.dashboardId) || [];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onSuccess: (data, variables) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
setLatestDashboardVersion(data.dashboard.id, data.dashboard.version_number);
|
setLatestDashboardVersion(data.dashboard.id, data.dashboard.version_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variables.metricIds.forEach((id) => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: metricsQueryKeys.metricsGetMetric(id, null).queryKey
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -152,6 +152,7 @@ const useDashboardSelectMenu = ({ metricId }: { metricId: string }) => {
|
||||||
const { mutateAsync: saveMetricsToDashboard } = useAddMetricsToDashboard();
|
const { mutateAsync: saveMetricsToDashboard } = useAddMetricsToDashboard();
|
||||||
const { mutateAsync: removeMetricsFromDashboard } = useRemoveMetricsFromDashboard();
|
const { mutateAsync: removeMetricsFromDashboard } = useRemoveMetricsFromDashboard();
|
||||||
const { data: dashboards } = useGetMetric({ id: metricId }, { select: (x) => x.dashboards });
|
const { data: dashboards } = useGetMetric({ id: metricId }, { select: (x) => x.dashboards });
|
||||||
|
const { openInfoMessage } = useBusterNotifications();
|
||||||
|
|
||||||
const onSaveToDashboard = useMemoizedFn(async (dashboardIds: string[]) => {
|
const onSaveToDashboard = useMemoizedFn(async (dashboardIds: string[]) => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
|
@ -159,14 +160,16 @@ const useDashboardSelectMenu = ({ metricId }: { metricId: string }) => {
|
||||||
saveMetricsToDashboard({ metricIds: [metricId], dashboardId })
|
saveMetricsToDashboard({ metricIds: [metricId], dashboardId })
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
openInfoMessage('Metric added to dashboard');
|
||||||
});
|
});
|
||||||
|
|
||||||
const onRemoveFromDashboard = useMemoizedFn(async (dashboardIds: string[]) => {
|
const onRemoveFromDashboard = useMemoizedFn(async (dashboardIds: string[]) => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
dashboardIds.map((dashboardId) =>
|
dashboardIds.map((dashboardId) =>
|
||||||
removeMetricsFromDashboard({ metricIds: [metricId], dashboardId })
|
removeMetricsFromDashboard({ metricIds: [metricId], dashboardId, useConfirmModal: false })
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
openInfoMessage('Metric removed from dashboard');
|
||||||
});
|
});
|
||||||
|
|
||||||
const { items, footerContent, selectType, menuHeader } = useSaveToDashboardDropdownContent({
|
const { items, footerContent, selectType, menuHeader } = useSaveToDashboardDropdownContent({
|
||||||
|
|
Loading…
Reference in New Issue