Variables: Fixes issue with All variable not being resolved (#27151)

* Variables: Fixes issue with All variable not being resolved

* Tests: update tests according to changes
This commit is contained in:
Hugo Häggmark
2020-08-24 00:29:21 -07:00
committed by GitHub
parent 69df8b424c
commit 09a1af3f91
9 changed files with 142 additions and 48 deletions

View File

@ -1,5 +1,6 @@
import isString from 'lodash/isString';
import { ScopedVars } from '@grafana/data';
import { ALL_VARIABLE_TEXT } from './state/types';
/*
* This regex matches 3 types of variable reference with an optional format specifier
@ -58,3 +59,47 @@ export function containsVariable(...args: any[]) {
return !!isMatchingVariable;
}
export const isAllVariable = (variable: any): boolean => {
if (!variable) {
return false;
}
if (!variable.current) {
return false;
}
if (!variable.current.text) {
return false;
}
if (Array.isArray(variable.current.text)) {
return variable.current.text.length ? variable.current.text[0] === ALL_VARIABLE_TEXT : false;
}
return variable.current.text === ALL_VARIABLE_TEXT;
};
export const getCurrentText = (variable: any): string => {
if (!variable) {
return '';
}
if (!variable.current) {
return '';
}
if (!variable.current.text) {
return '';
}
if (Array.isArray(variable.current.text)) {
return variable.current.text.toString();
}
if (typeof variable.current.text !== 'string') {
return '';
}
return variable.current.text;
};