Skip to content

Commit

Permalink
[Dashboard] Allow Reporting after Discarding Unsaved Changes (elastic…
Browse files Browse the repository at this point in the history
…#106026)

Allowed dashboard diffing to happen in view mode to  fix dashboard unsaved changes not updating after discard changes
  • Loading branch information
ThomThomson committed Jul 20, 2021
1 parent 6cdf712 commit 8321e4a
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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);
Expand Down

0 comments on commit 8321e4a

Please sign in to comment.