mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
25 lines
620 B
TypeScript
25 lines
620 B
TypeScript
import { VariableModel } from '@grafana/data';
|
|
|
|
import { VariableWithOptions } from '../types';
|
|
|
|
export const formatVariableLabel = (variable: VariableModel) => {
|
|
if (!isVariableWithOptions(variable)) {
|
|
return variable.name;
|
|
}
|
|
|
|
const { current } = variable;
|
|
|
|
if (Array.isArray(current.text)) {
|
|
return current.text.join(' + ');
|
|
}
|
|
|
|
return current.text;
|
|
};
|
|
|
|
const isVariableWithOptions = (variable: VariableModel): variable is VariableWithOptions => {
|
|
return (
|
|
Array.isArray((variable as VariableWithOptions)?.options) ||
|
|
typeof (variable as VariableWithOptions)?.current === 'object'
|
|
);
|
|
};
|