make dashboard more dynamic

This commit is contained in:
Nate Kelley 2025-03-18 15:21:23 -06:00
parent 3d1d998c53
commit 77597cdd93
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 26 additions and 8 deletions

View File

@ -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;
}
);
}
}
});
};

View File

@ -40,7 +40,7 @@ export const SaveToCollectionsDropdown: React.FC<{
footerContent={footerContent}
emptyStateText="No collections found"
items={items}>
<AppTooltip title={showDropdown ? '' : 'Save to collection'}>{children} </AppTooltip>
{children}
</Dropdown>
<>{modal}</>

View File

@ -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>{text}</Text>
<div className="border-border-default ml-1.5 min-h-[28px] border-l border-dashed" />
<div className="border-border-default ml-1.5 min-h-[24px] border-l border-dashed" />
<div
onClick={() => {

View File

@ -43,8 +43,6 @@ export const MetricTitle: React.FC<{
};
}, [title, useEllipsis]);
console.log(readOnly, isDragOverlay);
return (
<Link href={metricLink}>
<div
@ -64,7 +62,7 @@ export const MetricTitle: React.FC<{
<></>
) : (
<ThreeDotMenu
className="absolute top-[5px] right-[12px] opacity-0 transition group-hover:opacity-100"
className="absolute top-[10px] right-[12px] opacity-0 transition group-hover:opacity-100"
dashboardId={dashboardId}
metricId={metricId}
/>
@ -137,7 +135,7 @@ const ThreeDotMenu: React.FC<{
return (
<div onClick={onClick} className={`w-[24px] ${className}`}>
<Dropdown items={dropdownItems}>
<Dropdown items={dropdownItems} side="bottom">
<Button variant="ghost" prefix={<DotsVertical />} />
</Dropdown>
</div>