AzureMonitor: Do not quote variables when a custom All variable option is used (#49428)

This commit is contained in:
Andres Martinez Gotor 2022-05-24 11:29:24 +02:00 committed by GitHub
parent 71ffa5e5db
commit b0300d56ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -81,5 +81,15 @@ describe('When interpolating variables', () => {
const variable = { ...initialCustomVariableModelState, includeAll: true };
expect(interpolateVariable('abc', variable)).toEqual("'abc'");
});
it('should not return a quoted value if the all value is modified', () => {
const variable = { ...initialCustomVariableModelState, includeAll: true, allValue: 'All' };
expect(interpolateVariable('abc', variable)).toEqual('abc');
});
it('should return a quoted value if multi is selected even if the allValue is set', () => {
const variable = { ...initialCustomVariableModelState, includeAll: true, multi: true, allValue: 'All' };
expect(interpolateVariable('abc', variable)).toEqual("'abc'");
});
});
});

View File

@ -1,6 +1,7 @@
import { map } from 'lodash';
import { rangeUtil } from '@grafana/data';
import { VariableWithMultiSupport } from 'app/features/variables/types';
import TimegrainConverter from '../time_grain_converter';
import { AzureMonitorOption } from '../types';
@ -40,9 +41,12 @@ export const routeNames = {
resourceGraph: 'resourcegraph',
};
export function interpolateVariable(value: any, variable: { multi: any; includeAll: any }) {
export function interpolateVariable(value: any, variable: VariableWithMultiSupport) {
if (typeof value === 'string') {
if (variable.multi || variable.includeAll) {
// When enabling multiple responses, quote the value to mimic the array result below
// even if only one response is selected. This does not apply if only the "include all"
// option is enabled but with a custom value.
if (variable.multi || (variable.includeAll && !variable.allValue)) {
return "'" + value + "'";
} else {
return value;