2020-06-04 06:44:48 -05:00
|
|
|
import { VariableOption } from 'app/features/variables/types';
|
2020-04-01 11:13:38 -05:00
|
|
|
|
|
|
|
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];
|
|
|
|
};
|