mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix for Graphite function parameter quoting (#12907)
* fix: graphite function parameters should never be quoted for boolean, node, int and float types, fixes #11927 * Update gfunc.ts
This commit is contained in:
parent
e37931b79d
commit
7e0482e78d
@ -973,13 +973,12 @@ export class FuncInstance {
|
||||
} else if (_.get(_.last(this.def.params), 'multiple')) {
|
||||
paramType = _.get(_.last(this.def.params), 'type');
|
||||
}
|
||||
if (paramType === 'value_or_series') {
|
||||
// param types that should never be quoted
|
||||
if (_.includes(['value_or_series', 'boolean', 'int', 'float', 'node'], paramType)) {
|
||||
return value;
|
||||
}
|
||||
if (paramType === 'boolean' && _.includes(['true', 'false'], value)) {
|
||||
return value;
|
||||
}
|
||||
if (_.includes(['int', 'float', 'int_or_interval', 'node_or_tag', 'node'], paramType) && _.isFinite(+value)) {
|
||||
// param types that might be quoted
|
||||
if (_.includes(['int_or_interval', 'node_or_tag'], paramType) && _.isFinite(+value)) {
|
||||
return _.toString(+value);
|
||||
}
|
||||
return "'" + value + "'";
|
||||
|
@ -55,6 +55,24 @@ describe('when rendering func instance', function() {
|
||||
expect(func.render('hello')).toEqual("movingMedian(hello, '5min')");
|
||||
});
|
||||
|
||||
it('should never quote boolean paramater', function() {
|
||||
var func = gfunc.createFuncInstance('sortByName');
|
||||
func.params[0] = '$natural';
|
||||
expect(func.render('hello')).toEqual('sortByName(hello, $natural)');
|
||||
});
|
||||
|
||||
it('should never quote int paramater', function() {
|
||||
var func = gfunc.createFuncInstance('maximumAbove');
|
||||
func.params[0] = '$value';
|
||||
expect(func.render('hello')).toEqual('maximumAbove(hello, $value)');
|
||||
});
|
||||
|
||||
it('should never quote node paramater', function() {
|
||||
var func = gfunc.createFuncInstance('aliasByNode');
|
||||
func.params[0] = '$node';
|
||||
expect(func.render('hello')).toEqual('aliasByNode(hello, $node)');
|
||||
});
|
||||
|
||||
it('should handle metric param and int param and string param', function() {
|
||||
var func = gfunc.createFuncInstance('groupByNode');
|
||||
func.params[0] = 5;
|
||||
|
Loading…
Reference in New Issue
Block a user