mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Scenes: Fix issue with discarding unsaved changes modal in new dashboards (#84369)
This commit is contained in:
@@ -165,9 +165,15 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
||||
window.__grafanaSceneContext = this;
|
||||
|
||||
if (this.state.isEditing) {
|
||||
this._initialUrlState = locationService.getLocation();
|
||||
this._changeTracker.startTrackingChanges();
|
||||
}
|
||||
|
||||
if (this.state.meta.isNew) {
|
||||
this.onEnterEditMode();
|
||||
this.setState({ isDirty: true });
|
||||
}
|
||||
|
||||
if (!this.state.meta.isEmbedded && this.state.uid) {
|
||||
dashboardWatcher.watch(this.state.uid);
|
||||
}
|
||||
@@ -246,14 +252,14 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
||||
}
|
||||
}
|
||||
|
||||
public exitEditMode({ skipConfirm, restoreIntialState }: { skipConfirm: boolean; restoreIntialState?: boolean }) {
|
||||
public exitEditMode({ skipConfirm, restoreInitialState }: { skipConfirm: boolean; restoreInitialState?: boolean }) {
|
||||
if (!this.canDiscard()) {
|
||||
console.error('Trying to discard back to a state that does not exist, initialState undefined');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.state.isDirty || skipConfirm) {
|
||||
this.exitEditModeConfirmed(restoreIntialState || this.state.isDirty);
|
||||
this.exitEditModeConfirmed(restoreInitialState || this.state.isDirty);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -268,7 +274,7 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
||||
);
|
||||
}
|
||||
|
||||
private exitEditModeConfirmed(restoreIntialState = true) {
|
||||
private exitEditModeConfirmed(restoreInitialState = true) {
|
||||
// No need to listen to changes anymore
|
||||
this._changeTracker.stopTrackingChanges();
|
||||
// Stop url sync before updating url
|
||||
@@ -287,7 +293,7 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
||||
})
|
||||
);
|
||||
|
||||
if (restoreIntialState) {
|
||||
if (restoreInitialState) {
|
||||
// Restore initial state and disable editing
|
||||
this.setState({ ...this._initialState, isEditing: false });
|
||||
} else {
|
||||
@@ -328,7 +334,7 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
||||
newState.version = versionRsp.version;
|
||||
|
||||
this.setState(newState);
|
||||
this.exitEditMode({ skipConfirm: true, restoreIntialState: false });
|
||||
this.exitEditMode({ skipConfirm: true, restoreInitialState: false });
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user