feat: set Select field option as default option (#2725)

Closes #2591
This commit is contained in:
Thaïs
2023-11-29 12:19:56 +01:00
committed by GitHub
parent f00c05c342
commit 34a3197fee
14 changed files with 127 additions and 74 deletions

View File

@ -26,8 +26,10 @@ const defaultValues: FormValues = {
type: FieldMetadataType.Text,
relation: {
type: RelationMetadataType.OneToMany,
objectMetadataId: '',
field: { label: '' },
},
select: [{ color: 'green', text: 'Option 1' }],
select: [{ color: 'green', label: 'Option 1' }],
};
const fieldSchema = z.object({
@ -60,7 +62,8 @@ const selectSchema = fieldSchema.merge(
color: z.enum(
Object.keys(mainColors) as [ThemeColor, ...ThemeColor[]],
),
text: z.string().min(1),
isDefault: z.boolean().optional(),
label: z.string().min(1),
}),
)
.nonempty(),
@ -90,7 +93,7 @@ const schema = z.discriminatedUnion('type', [
otherFieldTypesSchema,
]);
type PartialFormValues = Partial<FormValues> &
type PartialFormValues = Partial<Omit<FormValues, 'relation'>> &
DeepPartial<Pick<FormValues, 'relation'>>;
export const useFieldMetadataForm = () => {