Skip to content

Commit e0e8fd6

Browse files
committed
fix(templating): fixed handling of numeric values in tempalting query results, fixes grafana#5097
1 parent 2416ee0 commit e0e8fd6

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

public/app/features/templating/templateValuesSrv.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ function (angular, _, kbn) {
313313
var value = item.value || item.text;
314314
var text = item.text || item.value;
315315

316+
if (_.isNumber(value)) {
317+
value = value.toString();
318+
}
319+
320+
if (_.isNumber(text)) {
321+
text = text.toString();
322+
}
323+
316324
if (regex) {
317325
matches = regex.exec(value);
318326
if (!matches) { continue; }

public/test/specs/templateSrv-specs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ define([
141141
});
142142

143143
it('slash should be properly escaped in regex format', function() {
144-
var result = _templateSrv.formatValue('Gi3/14', 'regex');
145-
expect(result).to.be('Gi3\\/14');
144+
var result = _templateSrv.formatValue('Gi3/14', 'regex');
145+
expect(result).to.be('Gi3\\/14');
146146
});
147147

148148
});

public/test/specs/templateValuesSrv-specs.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ define([
126126
});
127127
});
128128

129+
describeUpdateVariable('query variable with numeric results', function(scenario) {
130+
scenario.setup(function() {
131+
scenario.variable = { type: 'query', query: '', name: 'test', current: {} };
132+
scenario.queryResult = [{text: 12, value: 12}];
133+
});
134+
135+
it('should set current value to first option', function() {
136+
expect(scenario.variable.current.value).to.be('12');
137+
expect(scenario.variable.options[0].value).to.be('12');
138+
expect(scenario.variable.options[0].text).to.be('12');
139+
});
140+
});
141+
129142
describeUpdateVariable('interval variable without auto', function(scenario) {
130143
scenario.setup(function() {
131144
scenario.variable = { type: 'interval', query: '1s,2h,5h,1d', name: 'test' };

0 commit comments

Comments
 (0)