Fixed issue with multi select template variable and restoring state from url, #2196

This commit is contained in:
Torkel Ödegaard 2015-06-19 15:10:34 -04:00
parent fb7b475457
commit 2a693f7f08
3 changed files with 9 additions and 5 deletions

View File

@ -57,10 +57,6 @@ function (angular, _, kbn) {
var option = _.findWhere(variable.options, { text: urlValue }); var option = _.findWhere(variable.options, { text: urlValue });
option = option || { text: urlValue, value: urlValue }; option = option || { text: urlValue, value: urlValue };
if (_.isArray(urlValue)) {
option.text = urlValue.join(', ');
}
this.updateAutoInterval(variable); this.updateAutoInterval(variable);
return this.setVariableValue(variable, option); return this.setVariableValue(variable, option);
}; };
@ -79,6 +75,11 @@ function (angular, _, kbn) {
this.setVariableValue = function(variable, option) { this.setVariableValue = function(variable, option) {
variable.current = angular.copy(option); variable.current = angular.copy(option);
if (_.isArray(variable.current.value)) {
variable.current.text = variable.current.value.join(' + ');
}
templateSrv.updateTemplateData(); templateSrv.updateTemplateData();
return this.updateOptionsInChildVariables(variable); return this.updateOptionsInChildVariables(variable);
}; };
@ -127,6 +128,7 @@ function (angular, _, kbn) {
this.validateVariableSelectionState = function(variable) { this.validateVariableSelectionState = function(variable) {
if (!variable.current) { if (!variable.current) {
if (!variable.options.length) { return; }
return self.setVariableValue(variable, variable.options[0]); return self.setVariableValue(variable, variable.options[0]);
} }

View File

@ -132,5 +132,7 @@
} }
.dash-nav-link { .dash-nav-link {
padding: 8px 7px;
display: inline-block;
color: @textColor; color: @textColor;
} }

View File

@ -68,7 +68,7 @@ define([
expect(variable.current.value.length).to.be(2); expect(variable.current.value.length).to.be(2);
expect(variable.current.value[0]).to.be("new"); expect(variable.current.value[0]).to.be("new");
expect(variable.current.value[1]).to.be("other"); expect(variable.current.value[1]).to.be("other");
expect(variable.current.text).to.be("new, other"); expect(variable.current.text).to.be("new + other");
}); });
}); });