useSavedDashboard: call toast methods in their context (#86803)

This commit is contained in:
Alejandro Fernández Haro 2020-12-22 20:27:17 +01:00 committed by GitHub
parent a75ca7abe9
commit 5e3c84ca05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -36,7 +36,7 @@ export const useSavedDashboard = (savedDashboardId: string | undefined, history:
// abstraction of service dependencies easier.
const { indexPatterns } = data;
const { recentlyAccessed: recentlyAccessedPaths, docTitle } = chrome;
const { addDanger: showDangerToast, addWarning: showWarningToast } = core.notifications.toasts;
const { toasts } = core.notifications;
useEffect(() => {
(async function loadSavedDashboard() {
@ -46,7 +46,7 @@ export const useSavedDashboard = (savedDashboardId: string | undefined, history:
pathname: DashboardConstants.CREATE_NEW_DASHBOARD_URL,
});
showWarningToast(getDashboard60Warning());
toasts.addWarning(getDashboard60Warning());
return;
}
@ -63,7 +63,7 @@ export const useSavedDashboard = (savedDashboardId: string | undefined, history:
setSavedDashboard(dashboard);
} catch (error) {
// E.g. a corrupt or deleted dashboard
showDangerToast(error.message);
toasts.addDanger(error.message);
history.push(DashboardConstants.LANDING_PAGE_PATH);
}
})();
@ -75,8 +75,7 @@ export const useSavedDashboard = (savedDashboardId: string | undefined, history:
recentlyAccessedPaths,
savedDashboardId,
savedDashboards,
showDangerToast,
showWarningToast,
toasts,
]);
return savedDashboard;