mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 03:34:15 -06:00
Dashboard: Fix repeats in snapshots (#41018)
This commit is contained in:
parent
25fe5bc027
commit
fbd68c4e96
@ -572,6 +572,61 @@ describe('DashboardModel', () => {
|
||||
const savedModelWithCollapsedRows: any = model.getSaveModelClone();
|
||||
expect(savedModelWithCollapsedRows.panels[0].panels.length).toBe(1);
|
||||
});
|
||||
|
||||
it('getSaveModelClone should not remove repeated panels and scopedVars during snapshot', () => {
|
||||
const dashboardJSON = {
|
||||
panels: [
|
||||
{ id: 1, type: 'row', repeat: 'dc', gridPos: { x: 0, y: 0, h: 1, w: 24 } },
|
||||
{ id: 2, repeat: 'app', repeatDirection: 'h', gridPos: { x: 0, y: 1, h: 2, w: 8 } },
|
||||
],
|
||||
templating: {
|
||||
list: [
|
||||
{
|
||||
name: 'dc',
|
||||
type: 'custom',
|
||||
current: {
|
||||
text: 'dc1 + dc2',
|
||||
value: ['dc1', 'dc2'],
|
||||
},
|
||||
options: [
|
||||
{ text: 'dc1', value: 'dc1', selected: true },
|
||||
{ text: 'dc2', value: 'dc2', selected: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'app',
|
||||
type: 'custom',
|
||||
current: {
|
||||
text: 'se1 + se2',
|
||||
value: ['se1', 'se2'],
|
||||
},
|
||||
options: [
|
||||
{ text: 'se1', value: 'se1', selected: true },
|
||||
{ text: 'se2', value: 'se2', selected: true },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const model = getDashboardModel(dashboardJSON);
|
||||
model.processRepeats();
|
||||
expect(model.panels.filter((x) => x.type === 'row')).toHaveLength(2);
|
||||
expect(model.panels.filter((x) => x.type !== 'row')).toHaveLength(4);
|
||||
expect(model.panels.find((x) => x.type !== 'row')?.scopedVars?.dc.value).toBe('dc1');
|
||||
expect(model.panels.find((x) => x.type !== 'row')?.scopedVars?.app.value).toBe('se1');
|
||||
|
||||
model.snapshot = { timestamp: new Date() };
|
||||
const saveModel = model.getSaveModelClone();
|
||||
expect(saveModel.panels.filter((x) => x.type === 'row')).toHaveLength(2);
|
||||
expect(saveModel.panels.filter((x) => x.type !== 'row')).toHaveLength(4);
|
||||
expect(saveModel.panels.find((x) => x.type !== 'row')?.scopedVars?.dc.value).toBe('dc1');
|
||||
expect(saveModel.panels.find((x) => x.type !== 'row')?.scopedVars?.app.value).toBe('se1');
|
||||
|
||||
model.collapseRows();
|
||||
const savedModelWithCollapsedRows: any = model.getSaveModelClone();
|
||||
expect(savedModelWithCollapsedRows.panels[0].panels.length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Given model with template variable of type query', () => {
|
||||
|
@ -272,6 +272,9 @@ export class DashboardModel {
|
||||
private getPanelSaveModels() {
|
||||
return this.panels
|
||||
.filter((panel: PanelModel) => {
|
||||
if (this.isSnapshotTruthy()) {
|
||||
return true;
|
||||
}
|
||||
if (panel.type === 'add-panel') {
|
||||
return false;
|
||||
}
|
||||
@ -295,6 +298,9 @@ export class DashboardModel {
|
||||
return panel.getSaveModel();
|
||||
})
|
||||
.map((model: any) => {
|
||||
if (this.isSnapshotTruthy()) {
|
||||
return model;
|
||||
}
|
||||
// Clear any scopedVars from persisted mode. This cannot be part of getSaveModel as we need to be able to copy
|
||||
// panel models with preserved scopedVars, for example when going into edit mode.
|
||||
delete model.scopedVars;
|
||||
|
Loading…
Reference in New Issue
Block a user