import {
ExtendedSettingDefinition,
SettingDefinition,
+ SettingType,
SettingValue,
SettingValueResponse,
} from '../types/settings';
const { key } = definition;
const data: RequestData = { key, component };
- if (isCategoryDefinition(definition) && definition.multiValues) {
- data.values = value;
- } else if (definition.type === 'PROPERTY_SET') {
+ if (definition.type === SettingType.PROPERTY_SET) {
data.fieldValues = value
.map((fields: any) => omitBy(fields, (value) => value == null))
.map(JSON.stringify);
+ } else if (isCategoryDefinition(definition) && definition.multiValues) {
+ data.values = value;
} else {
data.value = value;
}
export function getSettingValue(definition: SettingDefinition, settingValue?: SettingValue) {
const { fieldValues, value, values } = settingValue || {};
- if (isCategoryDefinition(definition) && definition.multiValues) {
- return values;
- } else if (definition.type === SettingType.PROPERTY_SET) {
+ if (definition.type === SettingType.PROPERTY_SET) {
return fieldValues;
+ } else if (isCategoryDefinition(definition) && definition.multiValues) {
+ return values;
} else if (definition.type === SettingType.FORMATTED_TEXT) {
return values ? values[0] : undefined;
}
export function getEmptyValue(item: SettingDefinition | ExtendedSettingDefinition): any {
if (isCategoryDefinition(item)) {
- if (item.multiValues) {
- return [getEmptyValue({ ...item, multiValues: false })];
- }
-
- if (item.type === 'PROPERTY_SET') {
+ if (item.type === SettingType.PROPERTY_SET) {
const value: Dict<string> = {};
item.fields.forEach((field) => (value[field.key] = getEmptyValue(field)));
return [value];
}
+
+ if (item.multiValues) {
+ return [getEmptyValue({ ...item, multiValues: false })];
+ }
}
if (item.type === 'BOOLEAN' || item.type === 'SINGLE_SELECT_LIST') {
return parentValues.join(', ');
}
- if (definition.type === 'PROPERTY_SET' && parentFieldValues && parentFieldValues.length > 0) {
+ if (
+ definition.type === SettingType.PROPERTY_SET &&
+ parentFieldValues &&
+ parentFieldValues.length > 0
+ ) {
return translate('settings.default.complex_value');
}