Commit 040dd91d by Torkel Ödegaard

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

parent c6c07599
# 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
......
......@@ -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 {
......
......@@ -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');
});
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment