From 77597cdd9321c3e646ad0f00870aed38a366ccd1 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 18 Mar 2025 15:21:23 -0600 Subject: [PATCH] make dashboard more dynamic --- .../api/buster_rest/metrics/queryRequests.ts | 22 ++++++++++++++++++- .../dropdowns/SaveToCollectionsDropdown.tsx | 2 +- .../ListSelectedOptionPopup.tsx | 4 ++-- .../DashboardMetricItem/MetricTitle.tsx | 6 ++--- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/web/src/api/buster_rest/metrics/queryRequests.ts b/web/src/api/buster_rest/metrics/queryRequests.ts index f609452d1..4342c653a 100644 --- a/web/src/api/buster_rest/metrics/queryRequests.ts +++ b/web/src/api/buster_rest/metrics/queryRequests.ts @@ -301,6 +301,7 @@ export const useSaveMetricToDashboard = () => { export const useRemoveMetricFromDashboard = () => { const { openConfirmModal } = useBusterNotifications(); const { mutateAsync: saveMetric } = useSaveMetric(); + const queryClient = useQueryClient(); const removeMetricFromDashboard = useMemoizedFn( async ({ metricId, @@ -329,7 +330,26 @@ export const useRemoveMetricFromDashboard = () => { ); return useMutation({ - mutationFn: removeMetricFromDashboard + mutationFn: removeMetricFromDashboard, + onMutate: async (variables) => { + const currentDashboard = queryClient.getQueryData( + dashboardQueryKeys.dashboardGetDashboard(variables.dashboardId).queryKey + ); + if (currentDashboard) { + queryClient.setQueryData( + dashboardQueryKeys.dashboardGetDashboard(variables.dashboardId).queryKey, + (currentDashboard) => { + if (currentDashboard?.dashboard.config.rows) { + currentDashboard.dashboard.config.rows.forEach((row) => { + row.items = row.items.filter((item) => item.id !== variables.metricId); + }); + } + delete currentDashboard!.metrics[variables.metricId]; + return currentDashboard; + } + ); + } + } }); }; diff --git a/web/src/components/features/dropdowns/SaveToCollectionsDropdown.tsx b/web/src/components/features/dropdowns/SaveToCollectionsDropdown.tsx index bbb651d5d..e9e473b68 100644 --- a/web/src/components/features/dropdowns/SaveToCollectionsDropdown.tsx +++ b/web/src/components/features/dropdowns/SaveToCollectionsDropdown.tsx @@ -40,7 +40,7 @@ export const SaveToCollectionsDropdown: React.FC<{ footerContent={footerContent} emptyStateText="No collections found" items={items}> - {children} + {children} <>{modal} diff --git a/web/src/components/ui/list/BusterList/ListSelectedOptionPopup/ListSelectedOptionPopup.tsx b/web/src/components/ui/list/BusterList/ListSelectedOptionPopup/ListSelectedOptionPopup.tsx index b4ac49bc9..44d7b5bdf 100644 --- a/web/src/components/ui/list/BusterList/ListSelectedOptionPopup/ListSelectedOptionPopup.tsx +++ b/web/src/components/ui/list/BusterList/ListSelectedOptionPopup/ListSelectedOptionPopup.tsx @@ -38,12 +38,12 @@ const SelectedButton: React.FC<{ className={cn( 'flex items-center', 'bg-bg-container rounded pl-2', - 'min-h-[28px]', + 'min-h-[24px]', 'border-border-default border border-dashed' )}> {text} -
+
{ diff --git a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardMetricItem/MetricTitle.tsx b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardMetricItem/MetricTitle.tsx index 771bf8e25..d7d19fadb 100644 --- a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardMetricItem/MetricTitle.tsx +++ b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardContentController/DashboardMetricItem/MetricTitle.tsx @@ -43,8 +43,6 @@ export const MetricTitle: React.FC<{ }; }, [title, useEllipsis]); - console.log(readOnly, isDragOverlay); - return (
) : ( @@ -137,7 +135,7 @@ const ThreeDotMenu: React.FC<{ return (
- +