Skip to content

Commit

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

Allowed dashboard diffing to happen in view mode to  fix dashboard unsaved changes not updating after discard changes
  • Loading branch information
ThomThomson authored Jul 20, 2021
1 parent a687dc7 commit d4b7bb2
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 d4b7bb2

Please sign in to comment.