Skip to content

Commit

Permalink
Added fix for template variables when no options are available to select
Browse files Browse the repository at this point in the history
  • Loading branch information
David Raifaizen committed Jun 26, 2015
1 parent 20d5d0e commit ca42d97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion public/app/features/templating/templateSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function (angular, _) {
this._texts = {};

_.each(this.variables, function(variable) {
if (!variable.current || !variable.current.value) { return; }
if (!variable.current || !variable.current.isNone && !variable.current.value) { return; }

this._values[variable.name] = this.renderVariableValue(variable);
this._texts[variable.name] = variable.current.text;
Expand Down
4 changes: 4 additions & 0 deletions public/app/features/templating/templateValuesSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function (angular, _, kbn) {

module.service('templateValuesSrv', function($q, $rootScope, datasourceSrv, $location, templateSrv, timeSrv) {
var self = this;
function getNoneOption() { return { text: 'None', value: '', isNone: true }; }

$rootScope.onAppEvent('time-range-changed', function() {
var variable = _.findWhere(self.variables, { type: 'interval' });
Expand Down Expand Up @@ -175,6 +176,9 @@ function (angular, _, kbn) {
if (variable.includeAll) {
self.addAllOption(variable);
}
if (!variable.options.length) {
variable.options.push(getNoneOption());
}
return datasource;
});
};
Expand Down
5 changes: 3 additions & 2 deletions public/test/specs/templateValuesSrv-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ define([
scenario.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
});

it('should not add non matching items', function() {
expect(scenario.variable.options.length).to.be(0);
it('should not add non matching items, None option should be added instead', function() {
expect(scenario.variable.options.length).to.be(1);
expect(scenario.variable.options[0].isNone).to.be(true);
});
});

Expand Down

0 comments on commit ca42d97

Please sign in to comment.