useDashboardDelete.tsx 812 B

123456789101112131415161718192021
  1. import { useEffect } from 'react';
  2. import { useAsyncFn } from 'react-use';
  3. import { locationService } from '@grafana/runtime';
  4. import { useAppNotification } from 'app/core/copy/appNotification';
  5. import { deleteDashboard } from 'app/features/manage-dashboards/state/actions';
  6. export const useDashboardDelete = (uid: string, cleanUpDashboardAndVariables: () => void) => {
  7. const [state, onDeleteDashboard] = useAsyncFn(() => deleteDashboard(uid, false), []);
  8. const notifyApp = useAppNotification();
  9. useEffect(() => {
  10. if (state.value) {
  11. cleanUpDashboardAndVariables();
  12. locationService.replace('/');
  13. notifyApp.success('Dashboard Deleted', `${state.value.title} has been deleted`);
  14. }
  15. }, [state, notifyApp, cleanUpDashboardAndVariables]);
  16. return { state, onDeleteDashboard };
  17. };