Skip to content

Commit 9d5928d

Browse files
committed
feat(templating): don't persist template variable options when variable has refresh enabled, closes grafana#6586
1 parent eafe0d6 commit 9d5928d

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
### Enhancements
1111
* **Singlestat**: Support repeated template variables in prefix/postfix [#6595](https://github.com/grafana/grafana/issues/6595)
12+
* **Templating**: Don't persist variable options with refresh option [#6586](https://github.com/grafana/grafana/issues/6586)
1213

1314
# 4.0-beta1 (2016-11-09)
1415

public/app/features/templating/datasource_variable.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export class DatasourceVariable implements Variable {
3232

3333
getSaveModel() {
3434
assignModelProperties(this.model, this, this.defaults);
35+
36+
// dont persist options
37+
if (this.refresh !== 0) {
38+
this.model.options = [];
39+
}
40+
3541
return this.model;
3642
}
3743

public/app/features/templating/query_variable.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export class QueryVariable implements Variable {
5050
getSaveModel() {
5151
// copy back model properties to model
5252
assignModelProperties(this.model, this, this.defaults);
53+
54+
// remove options
55+
if (this.refresh !== 0) {
56+
this.model.options = [];
57+
}
58+
5359
return this.model;
5460
}
5561

public/app/features/templating/specs/query_variable_specs.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ describe('QueryVariable', function() {
3333
expect(model.sort).to.be(50);
3434
});
3535

36-
});
36+
it('if refresh != 0 then remove options in presisted mode', () => {
37+
var variable = new QueryVariable({}, null, null, null, null);
38+
variable.options = [{text: 'test'}];
39+
variable.refresh = 1;
3740

41+
var model = variable.getSaveModel();
42+
expect(model.options.length).to.be(0);
43+
});
44+
45+
});
3846
});
3947

0 commit comments

Comments
 (0)