Refactor default value for select (#5343)
In this PR, we are refactoring two things: - leverage field.defaultValue for Select and MultiSelect settings form (instead of option.isDefault) - use quoted string (ex: "'USD'") for string default values to embrace backend format --------- Co-authored-by: Thaïs Guigon <guigon.thais@gmail.com>
This commit is contained in:
@ -0,0 +1,25 @@
|
||||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { applySimpleQuotesToString } from '~/utils/string/applySimpleQuotesToString';
|
||||
|
||||
export const isSelectOptionDefaultValue = (
|
||||
optionValue: string,
|
||||
fieldMetadataItem: Pick<FieldMetadataItem, 'defaultValue' | 'type'>,
|
||||
): boolean => {
|
||||
if (fieldMetadataItem.type === FieldMetadataType.Select) {
|
||||
return (
|
||||
applySimpleQuotesToString(optionValue) === fieldMetadataItem.defaultValue
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
fieldMetadataItem.type === FieldMetadataType.MultiSelect &&
|
||||
Array.isArray(fieldMetadataItem.defaultValue)
|
||||
) {
|
||||
return fieldMetadataItem.defaultValue.includes(
|
||||
applySimpleQuotesToString(optionValue),
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
Reference in New Issue
Block a user