mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #2243 from craftytrickster/blank-variable-fix
Added fix for template variables when no options are available to select
This commit is contained in:
commit
aaeab3177e
@ -27,7 +27,7 @@ function (angular, _) {
|
|||||||
this._texts = {};
|
this._texts = {};
|
||||||
|
|
||||||
_.each(this.variables, function(variable) {
|
_.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._values[variable.name] = this.renderVariableValue(variable);
|
||||||
this._texts[variable.name] = variable.current.text;
|
this._texts[variable.name] = variable.current.text;
|
||||||
|
@ -10,6 +10,7 @@ function (angular, _, kbn) {
|
|||||||
|
|
||||||
module.service('templateValuesSrv', function($q, $rootScope, datasourceSrv, $location, templateSrv, timeSrv) {
|
module.service('templateValuesSrv', function($q, $rootScope, datasourceSrv, $location, templateSrv, timeSrv) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
function getNoneOption() { return { text: 'None', value: '', isNone: true }; }
|
||||||
|
|
||||||
$rootScope.onAppEvent('time-range-changed', function() {
|
$rootScope.onAppEvent('time-range-changed', function() {
|
||||||
var variable = _.findWhere(self.variables, { type: 'interval' });
|
var variable = _.findWhere(self.variables, { type: 'interval' });
|
||||||
@ -175,6 +176,9 @@ function (angular, _, kbn) {
|
|||||||
if (variable.includeAll) {
|
if (variable.includeAll) {
|
||||||
self.addAllOption(variable);
|
self.addAllOption(variable);
|
||||||
}
|
}
|
||||||
|
if (!variable.options.length) {
|
||||||
|
variable.options.push(getNoneOption());
|
||||||
|
}
|
||||||
return datasource;
|
return datasource;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -224,8 +224,9 @@ define([
|
|||||||
scenario.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
|
scenario.queryResult = [{text: 'apps.backend.backend_01.counters.req'}, {text: 'apps.backend.backend_02.counters.req'}];
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not add non matching items', function() {
|
it('should not add non matching items, None option should be added instead', function() {
|
||||||
expect(scenario.variable.options.length).to.be(0);
|
expect(scenario.variable.options.length).to.be(1);
|
||||||
|
expect(scenario.variable.options[0].isNone).to.be(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user