grafana/public/app/features/dashboard/components/DeleteDashboard/useDashboardDelete.tsx
Agnès Toulet a832b92988
Dashboard: Clean up state after deletion (#50316)
* Dashboard: Clean up after deletion

* cleanup

* rename cleanUp function
2022-06-10 17:08:09 +02:00

22 lines
812 B
TypeScript

import { useEffect } from 'react';
import { useAsyncFn } from 'react-use';
import { locationService } from '@grafana/runtime';
import { useAppNotification } from 'app/core/copy/appNotification';
import { deleteDashboard } from 'app/features/manage-dashboards/state/actions';
export const useDashboardDelete = (uid: string, cleanUpDashboardAndVariables: () => void) => {
const [state, onDeleteDashboard] = useAsyncFn(() => deleteDashboard(uid, false), []);
const notifyApp = useAppNotification();
useEffect(() => {
if (state.value) {
cleanUpDashboardAndVariables();
locationService.replace('/');
notifyApp.success('Dashboard Deleted', `${state.value.title} has been deleted`);
}
}, [state, notifyApp, cleanUpDashboardAndVariables]);
return { state, onDeleteDashboard };
};