From a6fbb8d72401869c2b13ae8e8a54620bacf8fa95 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Mon, 20 Sep 2021 09:28:46 -0700 Subject: [PATCH] Live: show popup if local changes exist (#36093) * change tracker * not needed --- .../SaveDashboard/useDashboardSave.tsx | 2 ++ .../dashboard/dashgrid/DashboardGrid.tsx | 4 +++- .../features/dashboard/state/DashboardModel.ts | 16 ++++++++++++++++ .../features/live/dashboard/dashboardWatcher.ts | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/public/app/features/dashboard/components/SaveDashboard/useDashboardSave.tsx b/public/app/features/dashboard/components/SaveDashboard/useDashboardSave.tsx index 7b607eb8d85..146aa4d45ab 100644 --- a/public/app/features/dashboard/components/SaveDashboard/useDashboardSave.tsx +++ b/public/app/features/dashboard/components/SaveDashboard/useDashboardSave.tsx @@ -27,6 +27,8 @@ export const useDashboardSave = (dashboard: DashboardModel) => { useEffect(() => { if (state.value) { dashboard.version = state.value.version; + dashboard.clearUnsavedChanges(); + // important that these happen before location redirect below appEvents.publish(new DashboardSavedEvent()); appEvents.emit(AppEvents.alertSuccess, ['Dashboard saved']); diff --git a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx index f9144f20ad6..a50735ce4b4 100644 --- a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx @@ -110,7 +110,9 @@ export class DashboardGrid extends PureComponent { }; onResize: ItemCallback = (layout, oldItem, newItem) => { - this.panelMap[newItem.i!].updateGridPos(newItem); + const panel = this.panelMap[newItem.i!]; + panel.updateGridPos(newItem); + panel.configRev++; // trigger change handler }; onResizeStop: ItemCallback = (layout, oldItem, newItem) => { diff --git a/public/app/features/dashboard/state/DashboardModel.ts b/public/app/features/dashboard/state/DashboardModel.ts index 5bb6aab1c10..14b6d4d6878 100644 --- a/public/app/features/dashboard/state/DashboardModel.ts +++ b/public/app/features/dashboard/state/DashboardModel.ts @@ -497,6 +497,22 @@ export class DashboardModel { }); } + clearUnsavedChanges() { + for (const panel of this.panels) { + panel.configRev = 0; + } + } + + hasUnsavedChanges() { + for (const panel of this.panels) { + if (panel.hasChanged) { + console.log('Panel has changed', panel); + return true; + } + } + return false; + } + cleanUpRepeats() { if (this.isSnapshotTruthy() || !this.hasVariables()) { return; diff --git a/public/app/features/live/dashboard/dashboardWatcher.ts b/public/app/features/live/dashboard/dashboardWatcher.ts index 4eaa1d85b9e..a49de120d17 100644 --- a/public/app/features/live/dashboard/dashboardWatcher.ts +++ b/public/app/features/live/dashboard/dashboardWatcher.ts @@ -116,7 +116,7 @@ class DashboardWatcher { return; } - const showPopup = this.editing; // || changeTracker.hasChanges(); + const showPopup = this.editing || dash.hasUnsavedChanges(); if (action === DashboardEventAction.Saved) { if (showPopup) {