mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboards: Fixes issue with the initial panel layout counting as an unsaved change (#51315)
This commit is contained in:
@@ -100,7 +100,7 @@ export class DashboardGridUnconnected extends PureComponent<Props, State> {
|
||||
|
||||
onLayoutChange = (newLayout: ReactGridLayout.Layout[]) => {
|
||||
for (const newPos of newLayout) {
|
||||
this.panelMap[newPos.i!].updateGridPos(newPos);
|
||||
this.panelMap[newPos.i!].updateGridPos(newPos, this.state.isLayoutInitialized);
|
||||
}
|
||||
|
||||
this.props.dashboard.sortPanelsByGridPos();
|
||||
|
||||
@@ -436,17 +436,23 @@ describe('PanelModel', () => {
|
||||
});
|
||||
|
||||
describe('updateGridPos', () => {
|
||||
it('Should not cause configRev if no change', () => {
|
||||
it('Should not have changes if no change', () => {
|
||||
model.gridPos = { w: 1, h: 1, x: 1, y: 2 };
|
||||
model.updateGridPos({ w: 1, h: 1, x: 1, y: 2 });
|
||||
expect(model.hasChanged).toBe(false);
|
||||
});
|
||||
|
||||
it('Should not cause configRev if gridPos is different', () => {
|
||||
it('Should have changes if gridPos is different', () => {
|
||||
model.gridPos = { w: 1, h: 1, x: 1, y: 2 };
|
||||
model.updateGridPos({ w: 10, h: 1, x: 1, y: 2 });
|
||||
expect(model.hasChanged).toBe(true);
|
||||
});
|
||||
|
||||
it('Should not have changes if not manually updated', () => {
|
||||
model.gridPos = { w: 1, h: 1, x: 1, y: 2 };
|
||||
model.updateGridPos({ w: 10, h: 1, x: 1, y: 2 }, false);
|
||||
expect(model.hasChanged).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('destroy', () => {
|
||||
|
||||
@@ -304,7 +304,7 @@ export class PanelModel implements DataConfigSource, IPanelModel {
|
||||
this.isViewing = isViewing;
|
||||
}
|
||||
|
||||
updateGridPos(newPos: GridPos) {
|
||||
updateGridPos(newPos: GridPos, manuallyUpdated = true) {
|
||||
if (
|
||||
newPos.x === this.gridPos.x &&
|
||||
newPos.y === this.gridPos.y &&
|
||||
@@ -318,7 +318,9 @@ export class PanelModel implements DataConfigSource, IPanelModel {
|
||||
this.gridPos.y = newPos.y;
|
||||
this.gridPos.w = newPos.w;
|
||||
this.gridPos.h = newPos.h;
|
||||
this.configRev++;
|
||||
if (manuallyUpdated) {
|
||||
this.configRev++;
|
||||
}
|
||||
}
|
||||
|
||||
runAllPanelQueries(
|
||||
|
||||
Reference in New Issue
Block a user