From 9d5928ddd6d08b746dd22b074c47f3a254e12d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 17 Nov 2016 11:38:06 +0100 Subject: [PATCH] feat(templating): don't persist template variable options when variable has refresh enabled, closes #6586 --- CHANGELOG.md | 1 + public/app/features/templating/datasource_variable.ts | 6 ++++++ public/app/features/templating/query_variable.ts | 6 ++++++ .../features/templating/specs/query_variable_specs.ts | 10 +++++++++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e3f3766162..aa1be53c522 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Enhancements * **Singlestat**: Support repeated template variables in prefix/postfix [#6595](https://github.com/grafana/grafana/issues/6595) +* **Templating**: Don't persist variable options with refresh option [#6586](https://github.com/grafana/grafana/issues/6586) # 4.0-beta1 (2016-11-09) diff --git a/public/app/features/templating/datasource_variable.ts b/public/app/features/templating/datasource_variable.ts index 234c8c13fd5..17ba3522d00 100644 --- a/public/app/features/templating/datasource_variable.ts +++ b/public/app/features/templating/datasource_variable.ts @@ -32,6 +32,12 @@ export class DatasourceVariable implements Variable { getSaveModel() { assignModelProperties(this.model, this, this.defaults); + + // dont persist options + if (this.refresh !== 0) { + this.model.options = []; + } + return this.model; } diff --git a/public/app/features/templating/query_variable.ts b/public/app/features/templating/query_variable.ts index baabc554b23..e083aa2aab5 100644 --- a/public/app/features/templating/query_variable.ts +++ b/public/app/features/templating/query_variable.ts @@ -50,6 +50,12 @@ export class QueryVariable implements Variable { getSaveModel() { // copy back model properties to model assignModelProperties(this.model, this, this.defaults); + + // remove options + if (this.refresh !== 0) { + this.model.options = []; + } + return this.model; } diff --git a/public/app/features/templating/specs/query_variable_specs.ts b/public/app/features/templating/specs/query_variable_specs.ts index 6ddaaf3630f..7f695081ba0 100644 --- a/public/app/features/templating/specs/query_variable_specs.ts +++ b/public/app/features/templating/specs/query_variable_specs.ts @@ -33,7 +33,15 @@ describe('QueryVariable', function() { expect(model.sort).to.be(50); }); - }); + it('if refresh != 0 then remove options in presisted mode', () => { + var variable = new QueryVariable({}, null, null, null, null); + variable.options = [{text: 'test'}]; + variable.refresh = 1; + var model = variable.getSaveModel(); + expect(model.options.length).to.be(0); + }); + + }); });