formatVariable.ts 620 B

123456789101112131415161718192021222324
  1. import { VariableModel } from '@grafana/data';
  2. import { VariableWithOptions } from '../types';
  3. export const formatVariableLabel = (variable: VariableModel) => {
  4. if (!isVariableWithOptions(variable)) {
  5. return variable.name;
  6. }
  7. const { current } = variable;
  8. if (Array.isArray(current.text)) {
  9. return current.text.join(' + ');
  10. }
  11. return current.text;
  12. };
  13. const isVariableWithOptions = (variable: VariableModel): variable is VariableWithOptions => {
  14. return (
  15. Array.isArray((variable as VariableWithOptions)?.options) ||
  16. typeof (variable as VariableWithOptions)?.current === 'object'
  17. );
  18. };