mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AppNotifications: Migrate usage of deprecated appEvents.emit method to redux actions (#45607)
This commit is contained in:
@@ -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 };
|
||||
};
|
||||
|
||||
@@ -3,11 +3,12 @@ import { css } from '@emotion/css';
|
||||
import { saveAs } from 'file-saver';
|
||||
import { Button, ClipboardButton, Modal, stylesFactory, TextArea, useTheme } from '@grafana/ui';
|
||||
import { SaveDashboardFormProps } from '../types';
|
||||
import { AppEvents, GrafanaTheme } from '@grafana/data';
|
||||
import appEvents from '../../../../../core/app_events';
|
||||
import { GrafanaTheme } from '@grafana/data';
|
||||
import { useAppNotification } from 'app/core/copy/appNotification';
|
||||
|
||||
export const SaveProvisionedDashboardForm: React.FC<SaveDashboardFormProps> = ({ dashboard, onCancel }) => {
|
||||
const theme = useTheme();
|
||||
const notifyApp = useAppNotification();
|
||||
const [dashboardJSON, setDashboardJson] = useState(() => {
|
||||
const clone = dashboard.getSaveModelClone();
|
||||
delete clone.id;
|
||||
@@ -22,8 +23,8 @@ export const SaveProvisionedDashboardForm: React.FC<SaveDashboardFormProps> = ({
|
||||
}, [dashboard.title, dashboardJSON]);
|
||||
|
||||
const onCopyToClipboardSuccess = useCallback(() => {
|
||||
appEvents.emit(AppEvents.alertSuccess, ['Dashboard JSON copied to clipboard']);
|
||||
}, []);
|
||||
notifyApp.success('Dashboard JSON copied to clipboard');
|
||||
}, [notifyApp]);
|
||||
|
||||
const styles = getStyles(theme);
|
||||
return (
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { useEffect } from 'react';
|
||||
import useAsyncFn from 'react-use/lib/useAsyncFn';
|
||||
import { AppEvents, locationUtil } from '@grafana/data';
|
||||
import { locationUtil } from '@grafana/data';
|
||||
import { SaveDashboardOptions } from './types';
|
||||
import appEvents from 'app/core/app_events';
|
||||
import { useAppNotification } from 'app/core/copy/appNotification';
|
||||
import { DashboardModel } from 'app/features/dashboard/state';
|
||||
import { saveDashboard as saveDashboardApiCall } from 'app/features/manage-dashboards/state/actions';
|
||||
import { locationService, reportInteraction } from '@grafana/runtime';
|
||||
@@ -24,6 +25,7 @@ export const useDashboardSave = (dashboard: DashboardModel) => {
|
||||
[]
|
||||
);
|
||||
|
||||
const notifyApp = useAppNotification();
|
||||
useEffect(() => {
|
||||
if (state.value) {
|
||||
dashboard.version = state.value.version;
|
||||
@@ -31,7 +33,7 @@ export const useDashboardSave = (dashboard: DashboardModel) => {
|
||||
|
||||
// important that these happen before location redirect below
|
||||
appEvents.publish(new DashboardSavedEvent());
|
||||
appEvents.emit(AppEvents.alertSuccess, ['Dashboard saved']);
|
||||
notifyApp.success('Dashboard saved');
|
||||
reportInteraction(`Dashboard ${dashboard.id ? 'saved' : 'created'}`, {
|
||||
name: dashboard.title,
|
||||
url: state.value.url,
|
||||
@@ -44,7 +46,7 @@ export const useDashboardSave = (dashboard: DashboardModel) => {
|
||||
setTimeout(() => locationService.replace(newUrl));
|
||||
}
|
||||
}
|
||||
}, [dashboard, state]);
|
||||
}, [dashboard, state, notifyApp]);
|
||||
|
||||
return { state, onDashboardSave };
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { useAsyncFn } from 'react-use';
|
||||
import { AppEvents, locationUtil } from '@grafana/data';
|
||||
import appEvents from 'app/core/app_events';
|
||||
import { locationUtil } from '@grafana/data';
|
||||
import { StoreState } from 'app/types';
|
||||
import { useAppNotification } from 'app/core/copy/appNotification';
|
||||
import { historySrv } from './HistorySrv';
|
||||
import { DashboardModel } from '../../state';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
@@ -15,6 +15,7 @@ const restoreDashboard = async (version: number, dashboard: DashboardModel) => {
|
||||
export const useDashboardRestore = (version: number) => {
|
||||
const dashboard = useSelector((state: StoreState) => state.dashboard.getModel());
|
||||
const [state, onRestoreDashboard] = useAsyncFn(async () => await restoreDashboard(version, dashboard!), []);
|
||||
const notifyApp = useAppNotification();
|
||||
|
||||
useEffect(() => {
|
||||
if (state.value) {
|
||||
@@ -26,8 +27,8 @@ export const useDashboardRestore = (version: number) => {
|
||||
pathname: newUrl,
|
||||
state: { routeReloadCounter: prevState ? prevState + 1 : 1 },
|
||||
});
|
||||
appEvents.emit(AppEvents.alertSuccess, ['Dashboard restored', 'Restored from version ' + version]);
|
||||
notifyApp.success('Dashboard restored', `Restored from version ${version}`);
|
||||
}
|
||||
}, [state, version]);
|
||||
}, [state, version, notifyApp]);
|
||||
return { state, onRestoreDashboard };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user