mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Graphite: Never escape asPercent function params as string (#56593)
* handle asPercent func by never esc params as string * add test and clean up
This commit is contained in:
parent
5128659d19
commit
c34c1d0cb4
@ -1,4 +1,4 @@
|
||||
import gfunc from './gfunc';
|
||||
import gfunc, { FuncInstance } from './gfunc';
|
||||
|
||||
describe('gfunc', () => {
|
||||
const INDEX = {
|
||||
@ -20,4 +20,35 @@ describe('gfunc', () => {
|
||||
unknown: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('renders the version < .9 asPercent function parameters by not escaping them as a string', () => {
|
||||
// this function is returned from the graphite functions endpoint
|
||||
const asPercentDef = {
|
||||
name: 'asPercent',
|
||||
description: 'Calculates a percentage.',
|
||||
category: 'Combine',
|
||||
params: [
|
||||
{
|
||||
name: 'total',
|
||||
type: 'string',
|
||||
optional: true,
|
||||
multiple: false,
|
||||
},
|
||||
{
|
||||
name: 'nodes',
|
||||
type: 'node_or_tag',
|
||||
optional: true,
|
||||
multiple: true,
|
||||
options: [],
|
||||
},
|
||||
],
|
||||
defaultParams: [],
|
||||
};
|
||||
|
||||
const asPercent = new FuncInstance(asPercentDef);
|
||||
|
||||
const asPercentRendered = asPercent.render('#A', () => '#A');
|
||||
|
||||
expect(asPercentRendered).toEqual('asPercent(#A)');
|
||||
});
|
||||
});
|
||||
|
@ -1028,7 +1028,13 @@ export class FuncInstance {
|
||||
}
|
||||
|
||||
// param types that should never be quoted
|
||||
if (includes(['value_or_series', 'boolean', 'int', 'float', 'node', 'int_or_infinity'], paramType)) {
|
||||
const neverQuotedParams = ['value_or_series', 'boolean', 'int', 'float', 'node', 'int_or_infinity'];
|
||||
|
||||
// functions that should not have param types quoted
|
||||
// https://github.com/grafana/grafana/issues/54924
|
||||
const neverQuotedFunctions = ['asPercent'];
|
||||
// params or functions that should never be quoted
|
||||
if (includes(neverQuotedParams, paramType) || includes(neverQuotedFunctions, this.def.name)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user