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
+18 -18
View File
@@ -5055,7 +5055,7 @@ exports[`better eslint`] = {
[21, 38, 3, "Unexpected any. Specify a different type.", "193409811"], [21, 38, 3, "Unexpected any. Specify a different type.", "193409811"],
[21, 59, 3, "Unexpected any. Specify a different type.", "193409811"] [21, 59, 3, "Unexpected any. Specify a different type.", "193409811"]
], ],
"public/app/features/dashboard/dashgrid/DashboardGrid.tsx:3771579139": [ "public/app/features/dashboard/dashgrid/DashboardGrid.tsx:25656274": [
[79, 22, 3, "Unexpected any. Specify a different type.", "193409811"], [79, 22, 3, "Unexpected any. Specify a different type.", "193409811"],
[189, 40, 3, "Unexpected any. Specify a different type.", "193409811"], [189, 40, 3, "Unexpected any. Specify a different type.", "193409811"],
[189, 53, 3, "Unexpected any. Specify a different type.", "193409811"], [189, 53, 3, "Unexpected any. Specify a different type.", "193409811"],
@@ -5282,7 +5282,7 @@ exports[`better eslint`] = {
[1137, 40, 3, "Unexpected any. Specify a different type.", "193409811"], [1137, 40, 3, "Unexpected any. Specify a different type.", "193409811"],
[1137, 48, 3, "Unexpected any. Specify a different type.", "193409811"] [1137, 48, 3, "Unexpected any. Specify a different type.", "193409811"]
], ],
"public/app/features/dashboard/state/PanelModel.test.ts:1787146930": [ "public/app/features/dashboard/state/PanelModel.test.ts:4035235685": [
[29, 11, 92, "Do not use any type assertions.", "2976372744"], [29, 11, 92, "Do not use any type assertions.", "2976372744"],
[34, 5, 3, "Unexpected any. Specify a different type.", "193409811"], [34, 5, 3, "Unexpected any. Specify a different type.", "193409811"],
[52, 15, 3, "Unexpected any. Specify a different type.", "193409811"], [52, 15, 3, "Unexpected any. Specify a different type.", "193409811"],
@@ -5295,12 +5295,12 @@ exports[`better eslint`] = {
[373, 28, 3, "Unexpected any. Specify a different type.", "193409811"], [373, 28, 3, "Unexpected any. Specify a different type.", "193409811"],
[376, 80, 25, "Do not use any type assertions.", "2825799852"], [376, 80, 25, "Do not use any type assertions.", "2825799852"],
[376, 102, 3, "Unexpected any. Specify a different type.", "193409811"], [376, 102, 3, "Unexpected any. Specify a different type.", "193409811"],
[453, 49, 81, "Do not use any type assertions.", "1932069967"], [459, 49, 81, "Do not use any type assertions.", "1932069967"],
[454, 32, 15, "Do not use any type assertions.", "1703404951"], [460, 32, 15, "Do not use any type assertions.", "1703404951"],
[490, 25, 293, "Do not use any type assertions.", "3989849883"], [496, 25, 293, "Do not use any type assertions.", "3989849883"],
[492, 21, 213, "Do not use any type assertions.", "2695721884"] [498, 21, 213, "Do not use any type assertions.", "2695721884"]
], ],
"public/app/features/dashboard/state/PanelModel.ts:3953810869": [ "public/app/features/dashboard/state/PanelModel.ts:2979822970": [
[112, 16, 3, "Unexpected any. Specify a different type.", "193409811"], [112, 16, 3, "Unexpected any. Specify a different type.", "193409811"],
[131, 10, 3, "Unexpected any. Specify a different type.", "193409811"], [131, 10, 3, "Unexpected any. Specify a different type.", "193409811"],
[145, 15, 3, "Unexpected any. Specify a different type.", "193409811"], [145, 15, 3, "Unexpected any. Specify a different type.", "193409811"],
@@ -5319,17 +5319,17 @@ exports[`better eslint`] = {
[223, 7, 11, "Do not use any type assertions.", "3816020039"], [223, 7, 11, "Do not use any type assertions.", "3816020039"],
[223, 15, 3, "Unexpected any. Specify a different type.", "193409811"], [223, 15, 3, "Unexpected any. Specify a different type.", "193409811"],
[285, 17, 3, "Unexpected any. Specify a different type.", "193409811"], [285, 17, 3, "Unexpected any. Specify a different type.", "193409811"],
[367, 21, 11, "Do not use any type assertions.", "3816020039"], [369, 21, 11, "Do not use any type assertions.", "3816020039"],
[367, 29, 3, "Unexpected any. Specify a different type.", "193409811"], [369, 29, 3, "Unexpected any. Specify a different type.", "193409811"],
[380, 7, 11, "Do not use any type assertions.", "3816020039"], [382, 7, 11, "Do not use any type assertions.", "3816020039"],
[380, 15, 3, "Unexpected any. Specify a different type.", "193409811"], [382, 15, 3, "Unexpected any. Specify a different type.", "193409811"],
[431, 14, 11, "Do not use any type assertions.", "3816020039"], [433, 14, 11, "Do not use any type assertions.", "3816020039"],
[431, 22, 3, "Unexpected any. Specify a different type.", "193409811"], [433, 22, 3, "Unexpected any. Specify a different type.", "193409811"],
[451, 16, 3, "Unexpected any. Specify a different type.", "193409811"], [453, 16, 3, "Unexpected any. Specify a different type.", "193409811"],
[462, 22, 3, "Unexpected any. Specify a different type.", "193409811"], [464, 22, 3, "Unexpected any. Specify a different type.", "193409811"],
[510, 22, 18, "Do not use any type assertions.", "1060162663"], [512, 22, 18, "Do not use any type assertions.", "1060162663"],
[593, 38, 3, "Unexpected any. Specify a different type.", "193409811"], [595, 38, 3, "Unexpected any. Specify a different type.", "193409811"],
[652, 14, 3, "Unexpected any. Specify a different type.", "193409811"] [654, 14, 3, "Unexpected any. Specify a different type.", "193409811"]
], ],
"public/app/features/dashboard/state/TimeModel.ts:2763994651": [ "public/app/features/dashboard/state/TimeModel.ts:2763994651": [
[3, 8, 3, "Unexpected any. Specify a different type.", "193409811"], [3, 8, 3, "Unexpected any. Specify a different type.", "193409811"],
@@ -100,7 +100,7 @@ export class DashboardGridUnconnected extends PureComponent<Props, State> {
onLayoutChange = (newLayout: ReactGridLayout.Layout[]) => { onLayoutChange = (newLayout: ReactGridLayout.Layout[]) => {
for (const newPos of newLayout) { for (const newPos of newLayout) {
this.panelMap[newPos.i!].updateGridPos(newPos); this.panelMap[newPos.i!].updateGridPos(newPos, this.state.isLayoutInitialized);
} }
this.props.dashboard.sortPanelsByGridPos(); this.props.dashboard.sortPanelsByGridPos();
@@ -436,17 +436,23 @@ describe('PanelModel', () => {
}); });
describe('updateGridPos', () => { 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.gridPos = { w: 1, h: 1, x: 1, y: 2 };
model.updateGridPos({ w: 1, h: 1, x: 1, y: 2 }); model.updateGridPos({ w: 1, h: 1, x: 1, y: 2 });
expect(model.hasChanged).toBe(false); 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.gridPos = { w: 1, h: 1, x: 1, y: 2 };
model.updateGridPos({ w: 10, h: 1, x: 1, y: 2 }); model.updateGridPos({ w: 10, h: 1, x: 1, y: 2 });
expect(model.hasChanged).toBe(true); 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', () => { describe('destroy', () => {
@@ -304,7 +304,7 @@ export class PanelModel implements DataConfigSource, IPanelModel {
this.isViewing = isViewing; this.isViewing = isViewing;
} }
updateGridPos(newPos: GridPos) { updateGridPos(newPos: GridPos, manuallyUpdated = true) {
if ( if (
newPos.x === this.gridPos.x && newPos.x === this.gridPos.x &&
newPos.y === this.gridPos.y && newPos.y === this.gridPos.y &&
@@ -318,7 +318,9 @@ export class PanelModel implements DataConfigSource, IPanelModel {
this.gridPos.y = newPos.y; this.gridPos.y = newPos.y;
this.gridPos.w = newPos.w; this.gridPos.w = newPos.w;
this.gridPos.h = newPos.h; this.gridPos.h = newPos.h;
this.configRev++; if (manuallyUpdated) {
this.configRev++;
}
} }
runAllPanelQueries( runAllPanelQueries(