mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 10:20:29 -06:00
Fix dashboard crash on dashboard leave in panel edit (#89353)
* Fix dashboard crashing when leaving dashboard in panel edit * add test * test
This commit is contained in:
parent
e5a50a7db8
commit
51c858f32e
@ -200,6 +200,20 @@ describe('DashboardScene', () => {
|
||||
expect(resoredLayout.state.children.map((c) => c.state.key)).toEqual(originalPanelOrder);
|
||||
});
|
||||
|
||||
it('Should exit edit mode and discard panel changes if leaving the dashboard while in panel edit', () => {
|
||||
const panel = findVizPanelByKey(scene, 'panel-1');
|
||||
const editPanel = buildPanelEditScene(panel!);
|
||||
scene.setState({
|
||||
editPanel,
|
||||
});
|
||||
|
||||
expect(scene.state.editPanel!['_discardChanges']).toBe(false);
|
||||
|
||||
scene.exitEditMode({ skipConfirm: true });
|
||||
|
||||
expect(scene.state.editPanel!['_discardChanges']).toBe(true);
|
||||
});
|
||||
|
||||
it.each`
|
||||
prop | value
|
||||
${'title'} | ${'new title'}
|
||||
|
@ -317,6 +317,13 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
||||
this.setState({ isEditing: false });
|
||||
}
|
||||
|
||||
// if we are in edit panel, we need to onDiscard()
|
||||
// so the useEffect cleanup comes later and
|
||||
// doesn't try to commit the changes
|
||||
if (this.state.editPanel) {
|
||||
this.state.editPanel.onDiscard();
|
||||
}
|
||||
|
||||
// Disable grid dragging
|
||||
this.propagateEditModeChange();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user