Skip to content

Commit 58df60f

Browse files
committed
fix(templating): another fix for repeating panels and having old panels/scoped vars stuck after switching repeat variable, fixes grafana#5795
1 parent cbf0e77 commit 58df60f

File tree

4 files changed

+33
-277
lines changed

4 files changed

+33
-277
lines changed

public/app/features/dashboard/dynamic_dashboard_srv.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ export class DynamicDashboardSrv {
2727
this.iteration = (this.iteration || new Date().getTime()) + 1;
2828

2929
var cleanUpOnly = options.cleanUpOnly;
30-
3130
var i, j, row, panel;
31+
32+
// cleanup scopedVars
3233
for (i = 0; i < this.dashboard.rows.length; i++) {
3334
row = this.dashboard.rows[i];
35+
for (j = 0; j < row.panels.length; j++) {
36+
delete row.panels[j].scopedVars;
37+
}
38+
}
39+
40+
for (i = 0; i < this.dashboard.rows.length; i++) {
41+
row = this.dashboard.rows[i];
42+
3443
// handle row repeats
3544
if (row.repeat) {
3645
if (!cleanUpOnly) {
@@ -54,10 +63,6 @@ export class DynamicDashboardSrv {
5463
// clean up old left overs
5564
row.panels = _.without(row.panels, panel);
5665
j = j - 1;
57-
} else if (row.repeat || row.repeatRowId) {
58-
continue;
59-
} else if (!_.isEmpty(panel.scopedVars) && panel.repeatIteration !== this.iteration) {
60-
panel.scopedVars = {};
6166
}
6267
}
6368
}

public/app/features/dashboard/specs/dynamic_dashboard_srv_specs.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,29 @@ dynamicDashScenario('given dashboard with panel repeat', function(ctx) {
9393
});
9494
});
9595

96+
describe('After a second iteration with different variable', function() {
97+
beforeEach(function() {
98+
ctx.dash.templating.list.push({
99+
name: 'server',
100+
current: { text: 'se1, se2, se3', value: ['se1']},
101+
options: [{text: 'se1', value: 'se1', selected: true}]
102+
});
103+
ctx.rows[0].panels[0].repeat = "server";
104+
ctx.dynamicDashboardSrv.update(ctx.dash);
105+
});
106+
107+
it('should remove scopedVars value for last variable', function() {
108+
expect(ctx.rows[0].panels[0].scopedVars.apps).to.be(undefined);
109+
});
110+
111+
it('should have new variable value in scopedVars', function() {
112+
expect(ctx.rows[0].panels[0].scopedVars.server.value).to.be("se1");
113+
});
114+
});
115+
96116
describe('After a second iteration and selected values reduced', function() {
97117
beforeEach(function() {
98118
ctx.dash.templating.list[0].options[1].selected = false;
99-
100119
ctx.dynamicDashboardSrv.update(ctx.dash);
101120
});
102121

@@ -116,7 +135,7 @@ dynamicDashScenario('given dashboard with panel repeat', function(ctx) {
116135
});
117136

118137
it('should remove scoped vars from reused panel', function() {
119-
expect(ctx.rows[0].panels[0].scopedVars).to.be.empty();
138+
expect(ctx.rows[0].panels[0].scopedVars).to.be(undefined);
120139
});
121140
});
122141

public/app/features/dashboard/specs/exporter_specs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ describe('given dashboard with repeated panels', function() {
4747
});
4848
dash.rows.push({
4949
repeat: null,
50-
repeatRowId: 1
50+
repeatRowId: 1,
51+
panels: [],
5152
});
5253

5354
var datasourceSrvStub = {

public/test/specs/dynamicDashboardSrv-specs.js

Lines changed: 0 additions & 269 deletions
This file was deleted.

0 commit comments

Comments
 (0)