mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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', () => {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user