1
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
910 B

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];
};