mirror of https://github.com/buster-so/buster.git
make dashboard more dynamic
This commit is contained in:
parent
3d1d998c53
commit
77597cdd93
|
@ -301,6 +301,7 @@ export const useSaveMetricToDashboard = () => {
|
||||||
export const useRemoveMetricFromDashboard = () => {
|
export const useRemoveMetricFromDashboard = () => {
|
||||||
const { openConfirmModal } = useBusterNotifications();
|
const { openConfirmModal } = useBusterNotifications();
|
||||||
const { mutateAsync: saveMetric } = useSaveMetric();
|
const { mutateAsync: saveMetric } = useSaveMetric();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
const removeMetricFromDashboard = useMemoizedFn(
|
const removeMetricFromDashboard = useMemoizedFn(
|
||||||
async ({
|
async ({
|
||||||
metricId,
|
metricId,
|
||||||
|
@ -329,7 +330,26 @@ export const useRemoveMetricFromDashboard = () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
return useMutation({
|
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;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ export const SaveToCollectionsDropdown: React.FC<{
|
||||||
footerContent={footerContent}
|
footerContent={footerContent}
|
||||||
emptyStateText="No collections found"
|
emptyStateText="No collections found"
|
||||||
items={items}>
|
items={items}>
|
||||||
<AppTooltip title={showDropdown ? '' : 'Save to collection'}>{children} </AppTooltip>
|
{children}
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
|
|
||||||
<>{modal}</>
|
<>{modal}</>
|
||||||
|
|
|
@ -38,12 +38,12 @@ const SelectedButton: React.FC<{
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex items-center',
|
'flex items-center',
|
||||||
'bg-bg-container rounded pl-2',
|
'bg-bg-container rounded pl-2',
|
||||||
'min-h-[28px]',
|
'min-h-[24px]',
|
||||||
'border-border-default border border-dashed'
|
'border-border-default border border-dashed'
|
||||||
)}>
|
)}>
|
||||||
<Text>{text}</Text>
|
<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
|
<div
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|
|
@ -43,8 +43,6 @@ export const MetricTitle: React.FC<{
|
||||||
};
|
};
|
||||||
}, [title, useEllipsis]);
|
}, [title, useEllipsis]);
|
||||||
|
|
||||||
console.log(readOnly, isDragOverlay);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link href={metricLink}>
|
<Link href={metricLink}>
|
||||||
<div
|
<div
|
||||||
|
@ -64,7 +62,7 @@ export const MetricTitle: React.FC<{
|
||||||
<></>
|
<></>
|
||||||
) : (
|
) : (
|
||||||
<ThreeDotMenu
|
<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}
|
dashboardId={dashboardId}
|
||||||
metricId={metricId}
|
metricId={metricId}
|
||||||
/>
|
/>
|
||||||
|
@ -137,7 +135,7 @@ const ThreeDotMenu: React.FC<{
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div onClick={onClick} className={`w-[24px] ${className}`}>
|
<div onClick={onClick} className={`w-[24px] ${className}`}>
|
||||||
<Dropdown items={dropdownItems}>
|
<Dropdown items={dropdownItems} side="bottom">
|
||||||
<Button variant="ghost" prefix={<DotsVertical />} />
|
<Button variant="ghost" prefix={<DotsVertical />} />
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue