[release-12.0.7] DashboardScene: Ignore defaults changes when exiting edit mode (#113505)
DashboardScene: Ignore defaults changes when exiting edit mode (#112796)
* exit dashboard without confirmation with only optional changes
* centralise
* clean up logic
* export to util
(cherry picked from commit 51b39d8c6e)
This commit is contained in:
@@ -10,7 +10,7 @@ import { contextSrv } from 'app/core/services/context_srv';
|
||||
|
||||
import { SaveLibraryVizPanelModal } from '../panel-edit/SaveLibraryVizPanelModal';
|
||||
import { DashboardScene } from '../scene/DashboardScene';
|
||||
import { getLibraryPanelBehavior, isLibraryPanel } from '../utils/utils';
|
||||
import { getLibraryPanelBehavior, hasActualSaveChanges, isLibraryPanel } from '../utils/utils';
|
||||
|
||||
interface DashboardPromptProps {
|
||||
dashboard: DashboardScene;
|
||||
@@ -183,5 +183,5 @@ export function ignoreChanges(scene: DashboardScene | null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !canSave || fromScript || fromFile;
|
||||
return !canSave || fromScript || fromFile || (scene.state.isEditing && !hasActualSaveChanges(scene));
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ import {
|
||||
getDefaultVizPanel,
|
||||
getLayoutManagerFor,
|
||||
getPanelIdForVizPanel,
|
||||
hasActualSaveChanges,
|
||||
} from '../utils/utils';
|
||||
import { SchemaV2EditorDrawer } from '../v2schema/SchemaV2EditorDrawer';
|
||||
|
||||
@@ -322,7 +323,7 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> impleme
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.state.isDirty || skipConfirm) {
|
||||
if (!this.state.isDirty || skipConfirm || !hasActualSaveChanges(this)) {
|
||||
this.exitEditModeConfirmed(restoreInitialState || this.state.isDirty);
|
||||
this.state.scopesBridge?.setReadOnly(false);
|
||||
return;
|
||||
|
||||
@@ -468,3 +468,11 @@ export function useInterpolatedTitle<T extends SceneObjectState & { title?: stri
|
||||
export function getLayoutOrchestratorFor(scene: SceneObject): DashboardLayoutOrchestrator | undefined {
|
||||
return getDashboardSceneFor(scene).state.layoutOrchestrator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there are save changes but not counting time range, refresh rate and default variable value change
|
||||
*/
|
||||
export function hasActualSaveChanges(dashboard: DashboardScene) {
|
||||
const changes = dashboard.getDashboardChanges();
|
||||
return !!changes.diffCount;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user