Преглед изворни кода

fix(templating): fixed issue with current data source variable value, fixes #4934

Torkel Ödegaard пре 9 година
родитељ
комит
040dd91d2e

+ 4 - 0
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

+ 2 - 3
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 {

+ 12 - 2
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');
+      });
     });
 
   });