Commit a747d333 by bergquist

templating: allow whitespace values

closes #7382
parent d7201158
......@@ -140,8 +140,13 @@ export class QueryVariable implements Variable {
}
for (i = 0; i < metricNames.length; i++) {
var item = metricNames[i];
var value = item.value || item.text;
var text = item.text || item.value;
var text = item.text === undefined || item.text === null
? item.value
: item.text;
var value = item.value === undefined || item.value === null
? item.text
: item.value;
if (_.isNumber(value)) {
value = value.toString();
......@@ -178,7 +183,7 @@ export class QueryVariable implements Variable {
if (sortType === 1) {
options = _.sortBy(options, 'text');
} else if (sortType === 2) {
options = _.sortBy(options, function(opt) {
options = _.sortBy(options, (opt) => {
var matches = opt.text.match(/.*?(\d+).*/);
if (!matches || matches.length < 2) {
return -1;
......
......@@ -51,20 +51,23 @@ describe('QueryVariable', () => {
var input = [
{text: '0', value: '0'},
{text: '1', value: '1'},
{text: '', value: ''},
{text: null, value: 3},
{text: undefined, value: 4},
{text: '5', value: null},
{text: '6', value: undefined},
{text: null, value: '3'},
{text: undefined, value: '4'},
{text: 5, value: null},
{text: 6, value: undefined},
{text: null, value: '7'},
{text: undefined, value: '8'},
{text: 9, value: null},
{text: 10, value: undefined},
{text: '', value: undefined},
{text: undefined, value: ''},
];
var result = variable.metricNamesToVariableValues(input);
it('should return in same order', () => {
var i = 0;
expect(result.length).to.be(11);
expect(result[i++].text).to.be('');
expect(result[i++].text).to.be('0');
expect(result[i++].text).to.be('1');
......
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