mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Chore: initial commit * Tests: fixes MetricsQueryEditor.test.tsx * Tests: fixes cloudwatch/specs/datasource.test.ts * Tests: fixes stackdriver/specs/datasource.test.ts * Tests: remove refrences to CustomVariable * Refactor: moves DefaultVariableQueryEditor * Refactor: moves utils * Refactor: moves types * Refactor: removes variableSrv * Refactor: removes feature toggle newVariables * Refactor: removes valueSelectDropDown * Chore: removes GeneralTabCtrl * Chore: migrates RowOptions * Refactor: adds RowOptionsButton * Refactor: makes the interface more explicit * Refactor: small changes * Refactor: changed type as it can be any variable type * Tests: fixes broken test * Refactor: changes after PR comments * Refactor: adds loading state and call to onChange in componentDidMount
45 lines
910 B
TypeScript
45 lines
910 B
TypeScript
import { VariableOption } from 'app/features/variables/types';
|
|
|
|
export const alignCurrentWithMulti = (current: VariableOption, value: boolean): VariableOption => {
|
|
if (!current) {
|
|
return current;
|
|
}
|
|
|
|
if (value && !Array.isArray(current.value)) {
|
|
return {
|
|
...current,
|
|
value: convertToMulti(current.value),
|
|
text: convertToMulti(current.text),
|
|
};
|
|
}
|
|
|
|
if (!value && Array.isArray(current.value)) {
|
|
return {
|
|
...current,
|
|
value: convertToSingle(current.value),
|
|
text: convertToSingle(current.text),
|
|
};
|
|
}
|
|
|
|
return current;
|
|
};
|
|
|
|
const convertToSingle = (value: string | string[]): string => {
|
|
if (!Array.isArray(value)) {
|
|
return value;
|
|
}
|
|
|
|
if (value.length > 0) {
|
|
return value[0];
|
|
}
|
|
|
|
return '';
|
|
};
|
|
|
|
const convertToMulti = (value: string | string[]): string[] => {
|
|
if (Array.isArray(value)) {
|
|
return value;
|
|
}
|
|
return [value];
|
|
};
|