Dashboards: Fixes issue with the initial panel layout counting as an unsaved change (#51315)

This commit is contained in:
Joao Silva
2022-06-27 12:30:59 +01:00
committed by GitHub
parent 683f31f2c6
commit f2d8b1ceee
4 changed files with 31 additions and 23 deletions

View File

@@ -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();

View File

@@ -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', () => {

View File

@@ -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(