AppNotifications: Migrate usage of deprecated appEvents.emit method to redux actions (#45607)

This commit is contained in:
kay delaney
2022-02-23 11:31:15 +00:00
committed by GitHub
parent d0d5304662
commit 59317a22e4
25 changed files with 163 additions and 119 deletions

View File

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