From 8321e4a3a5bd43325f3f7eea6642458f120305b9 Mon Sep 17 00:00:00 2001 From: Devon Thomson Date: Tue, 20 Jul 2021 15:40:55 -0300 Subject: [PATCH] [Dashboard] Allow Reporting after Discarding Unsaved Changes (#106026) Allowed dashboard diffing to happen in view mode to fix dashboard unsaved changes not updating after discard changes --- .../application/hooks/use_dashboard_app_state.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/dashboard/public/application/hooks/use_dashboard_app_state.ts b/src/plugins/dashboard/public/application/hooks/use_dashboard_app_state.ts index e9a5275300ff..e665ca44798e 100644 --- a/src/plugins/dashboard/public/application/hooks/use_dashboard_app_state.ts +++ b/src/plugins/dashboard/public/application/hooks/use_dashboard_app_state.ts @@ -219,8 +219,14 @@ export const useDashboardAppState = ({ const unsavedChanges = current.viewMode === ViewMode.EDIT ? diffDashboardState(lastSaved, current) : {}; + let savedTimeChanged = false; + + /** + * changes to the time filter should only be considered 'unsaved changes' when + * editing the dashboard + */ if (current.viewMode === ViewMode.EDIT) { - const savedTimeChanged = + savedTimeChanged = lastSaved.timeRestore && !areTimeRangesEqual( { @@ -229,9 +235,9 @@ export const useDashboardAppState = ({ }, timefilter.getTime() ); - const hasUnsavedChanges = Object.keys(unsavedChanges).length > 0 || savedTimeChanged; - setDashboardAppState((s) => ({ ...s, hasUnsavedChanges })); } + const hasUnsavedChanges = Object.keys(unsavedChanges).length > 0 || savedTimeChanged; + setDashboardAppState((s) => ({ ...s, hasUnsavedChanges })); unsavedChanges.viewMode = current.viewMode; // always push view mode into session store. dashboardSessionStorage.setState(savedDashboardId, unsavedChanges);