Live: show popup if local changes exist (#36093)

* change tracker

* not needed
This commit is contained in:
Ryan McKinley
2021-09-20 09:28:46 -07:00
committed by GitHub
parent fcbcfd232b
commit a6fbb8d724
4 changed files with 22 additions and 2 deletions

View File

@@ -27,6 +27,8 @@ export const useDashboardSave = (dashboard: DashboardModel) => {
useEffect(() => { useEffect(() => {
if (state.value) { if (state.value) {
dashboard.version = state.value.version; dashboard.version = state.value.version;
dashboard.clearUnsavedChanges();
// important that these happen before location redirect below // important that these happen before location redirect below
appEvents.publish(new DashboardSavedEvent()); appEvents.publish(new DashboardSavedEvent());
appEvents.emit(AppEvents.alertSuccess, ['Dashboard saved']); appEvents.emit(AppEvents.alertSuccess, ['Dashboard saved']);

View File

@@ -110,7 +110,9 @@ export class DashboardGrid extends PureComponent<Props, State> {
}; };
onResize: ItemCallback = (layout, oldItem, newItem) => { 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) => { onResizeStop: ItemCallback = (layout, oldItem, newItem) => {

View File

@@ -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() { cleanUpRepeats() {
if (this.isSnapshotTruthy() || !this.hasVariables()) { if (this.isSnapshotTruthy() || !this.hasVariables()) {
return; return;

View File

@@ -116,7 +116,7 @@ class DashboardWatcher {
return; return;
} }
const showPopup = this.editing; // || changeTracker.hasChanges(); const showPopup = this.editing || dash.hasUnsavedChanges();
if (action === DashboardEventAction.Saved) { if (action === DashboardEventAction.Saved) {
if (showPopup) { if (showPopup) {