DataLinks: Fixes interpolation (formatting) of __all_variables and __url_time_range (#65162)

* DataLinks: Fixes interpolation (formatting) of __all_variables and __url_time_range

* simplify if statement
This commit is contained in:
Torkel Ödegaard
2023-03-22 18:56:18 +01:00
committed by GitHub
parent 0409cfd116
commit cd490ba0be
9 changed files with 28 additions and 11 deletions

View File

@@ -821,6 +821,15 @@ describe('templateSrv', () => {
const target = _templateSrv.replace('${adhoc}', { adhoc: { value: 'value2', text: 'value2' } }, 'queryparam');
expect(target).toBe('var-adhoc=value2');
});
it('Variable named ${__all_variables} is already formatted so skip any formatting', () => {
const target = _templateSrv.replace(
'${__all_variables}',
{ __all_variables: { value: 'var-server=server+name+with+plus%2B', skipFormat: true } },
'percentencode'
);
expect(target).toBe('var-server=server+name+with+plus%2B');
});
});
describe('scenes compatibility', () => {

View File

@@ -295,13 +295,17 @@ export class TemplateSrv implements BaseTemplateSrv {
return target.replace(this.regex, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
const variableName = var1 || var2 || var3;
const variable = this.getVariableAtIndex(variableName);
const fmt = fmt2 || fmt3 || format;
let fmt = fmt2 || fmt3 || format;
if (scopedVars) {
const value = this.getVariableValue(variableName, fieldPath, scopedVars);
const text = this.getVariableText(variableName, value, scopedVars);
if (value !== null && value !== undefined) {
if (scopedVars[variableName].skipFormat) {
fmt = undefined;
}
return this.formatValue(value, fmt, variable, text);
}
}