Skip to content

Commit ddbdb54

Browse files
committed
Merge branch 'master' of github.com:grafana/grafana
2 parents 181a671 + 1ce34ed commit ddbdb54

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

public/app/features/dashboard/dynamicDashboardSrv.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function (angular, _) {
3131
var i, j, row, panel;
3232
for (i = 0; i < this.dashboard.rows.length; i++) {
3333
row = this.dashboard.rows[i];
34-
3534
// handle row repeats
3635
if (row.repeat) {
3736
this.repeatRow(row, i);
@@ -40,6 +39,7 @@ function (angular, _) {
4039
else if (row.repeatRowId && row.repeatIteration !== this.iteration) {
4140
this.dashboard.rows.splice(i, 1);
4241
i = i - 1;
42+
continue;
4343
}
4444

4545
// repeat panels
@@ -52,6 +52,8 @@ function (angular, _) {
5252
else if (panel.repeatPanelId && panel.repeatIteration !== this.iteration) {
5353
row.panels = _.without(row.panels, panel);
5454
j = j - 1;
55+
} else if (!_.isEmpty(panel.scopedVars) && panel.repeatIteration !== this.iteration) {
56+
panel.scopedVars = {};
5557
}
5658
}
5759
}
@@ -116,8 +118,9 @@ function (angular, _) {
116118
panel = copy.panels[i];
117119
panel.scopedVars = {};
118120
panel.scopedVars[variable.name] = option;
121+
panel.repeatIteration = this.iteration;
119122
}
120-
});
123+
}, this);
121124
};
122125

123126
this.getPanelClone = function(sourcePanel, row, index) {

public/test/specs/dynamicDashboardSrv-specs.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,20 @@ define([
4141
dash.templating.list.push({
4242
name: 'apps',
4343
current: {
44-
text: 'se1, se2',
45-
value: ['se1', 'se2']
44+
text: 'se1, se2, se3',
45+
value: ['se1', 'se2', 'se3']
4646
},
4747
options: [
4848
{text: 'se1', value: 'se1', selected: true},
4949
{text: 'se2', value: 'se2', selected: true},
50+
{text: 'se3', value: 'se3', selected: true},
51+
{text: 'se4', value: 'se4', selected: false}
5052
]
5153
});
5254
});
5355

5456
it('should repeat panel one time', function() {
55-
expect(ctx.rows[0].panels.length).to.be(2);
57+
expect(ctx.rows[0].panels.length).to.be(3);
5658
});
5759

5860
it('should mark panel repeated', function() {
@@ -63,6 +65,7 @@ define([
6365
it('should set scopedVars on panels', function() {
6466
expect(ctx.rows[0].panels[0].scopedVars.apps.value).to.be('se1');
6567
expect(ctx.rows[0].panels[1].scopedVars.apps.value).to.be('se2');
68+
expect(ctx.rows[0].panels[2].scopedVars.apps.value).to.be('se3');
6669
});
6770

6871
describe('After a second iteration', function() {
@@ -83,19 +86,35 @@ define([
8386
});
8487

8588
it('should have same panel count', function() {
86-
expect(ctx.rows[0].panels.length).to.be(2);
89+
expect(ctx.rows[0].panels.length).to.be(3);
8790
});
8891
});
8992

9093
describe('After a second iteration and selected values reduced', function() {
9194
beforeEach(function() {
9295
ctx.dash.templating.list[0].options[1].selected = false;
96+
97+
ctx.dynamicDashboardSrv.update(ctx.dash);
98+
});
99+
100+
it('should clean up repeated panel', function() {
101+
expect(ctx.rows[0].panels.length).to.be(2);
102+
});
103+
});
104+
105+
describe('After a second iteration and panel repeat is turned off', function() {
106+
beforeEach(function() {
107+
ctx.rows[0].panels[0].repeat = null;
93108
ctx.dynamicDashboardSrv.update(ctx.dash);
94109
});
95110

96111
it('should clean up repeated panel', function() {
97112
expect(ctx.rows[0].panels.length).to.be(1);
98113
});
114+
115+
it('should remove scoped vars from reused panel', function() {
116+
expect(ctx.rows[0].panels[0].scopedVars).to.be.empty();
117+
});
99118
});
100119

101120
});

0 commit comments

Comments
 (0)