From 040dd91d2e7ae691d839b88ed3dacf5a62834d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 9 May 2016 10:17:30 +0200 Subject: [PATCH] fix(templating): fixed issue with current data source variable value, fixes #4934 --- CHANGELOG.md | 4 ++++ .../app/features/templating/templateValuesSrv.js | 5 ++--- public/test/specs/templateValuesSrv-specs.js | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78502480fa3..930a91af1da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 3.0.0 stable (unreleased) + +* **Templating**: Fixed issue with new data source variable not persisting current selected value, fixes [#4934](https://github.com/grafana/grafana/issues/4934) + # 3.0.0-beta7 (2016-05-02) ### Bug fixes diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index dc878c19c08..472c24aef61 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -213,8 +213,7 @@ function (angular, _, kbn) { this.updateOptions = function(variable) { if (variable.type !== 'query') { self._updateNonQueryVariable(variable); - self.setVariableValue(variable, variable.options[0]); - return $q.when([]); + return self.validateVariableSelectionState(variable); } return datasourceSrv.get(variable.datasource) @@ -251,7 +250,7 @@ function (angular, _, kbn) { if (_.isArray(variable.current.value)) { self.selectOptionsForCurrentValue(variable); } else { - var currentOption = _.findWhere(variable.options, { text: variable.current.text }); + var currentOption = _.findWhere(variable.options, {text: variable.current.text}); if (currentOption) { return self.setVariableValue(variable, currentOption, true); } else { diff --git a/public/test/specs/templateValuesSrv-specs.js b/public/test/specs/templateValuesSrv-specs.js index 3f4cd96c444..2edcd03da9a 100644 --- a/public/test/specs/templateValuesSrv-specs.js +++ b/public/test/specs/templateValuesSrv-specs.js @@ -166,7 +166,7 @@ define([ describeUpdateVariable('update custom variable', function(scenario) { scenario.setup(function() { - scenario.variable = { type: 'custom', query: 'hej, hop, asd', name: 'test'}; + scenario.variable = {type: 'custom', query: 'hej, hop, asd', name: 'test'}; }); it('should update options array', function() { @@ -286,7 +286,13 @@ define([ describeUpdateVariable('datasource variable with regex filter', function(scenario) { scenario.setup(function() { - scenario.variable = {type: 'datasource', query: 'graphite', name: 'test', current: {}, regex: '/pee$/' }; + scenario.variable = { + type: 'datasource', + query: 'graphite', + name: 'test', + current: {value: 'backend4_pee', text: 'backend4_pee'}, + regex: '/pee$/' + }; scenario.metricSources = [ {name: 'backend1', meta: {id: 'influx'}}, {name: 'backend2_pee', meta: {id: 'graphite'}}, @@ -300,6 +306,10 @@ define([ expect(scenario.variable.options[0].value).to.be('backend2_pee'); expect(scenario.variable.options[1].value).to.be('backend4_pee'); }); + + it('should keep current value if available', function() { + expect(scenario.variable.current.value).to.be('backend4_pee'); + }); }); });