Fix relation field type (#4992)

This commit is contained in:
martmull 2024-04-17 14:56:27 +02:00 committed by GitHub
parent cf50391b00
commit 64cc6ecc3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 5 deletions

View File

@ -23,8 +23,8 @@ export const getOptionValueFromLabel = (label: string) => {
export const formatFieldMetadataItemInput = (
input: Pick<
Field,
'label' | 'icon' | 'description' | 'defaultValue' | 'type' | 'options'
>,
'label' | 'icon' | 'description' | 'defaultValue' | 'options'
> & { type?: FieldMetadataType },
) => {
const options = input.options as FieldMetadataOption[];
let defaultValue = input.defaultValue;

View File

@ -12,7 +12,7 @@ export type FormatRelationMetadataInputParams = {
field: Pick<Field, 'label' | 'icon' | 'description' | 'type'>;
objectMetadataId: string;
connect: {
field: Pick<Field, 'label' | 'icon' | 'type'>;
field: Pick<Field, 'label' | 'icon'>;
objectMetadataId: string;
};
};

View File

@ -36,6 +36,12 @@ export const fieldMetadataFormDefaultValues: FormValues = {
select: [{ color: 'green', label: 'Option 1', value: v4() }],
multiSelect: [{ color: 'green', label: 'Option 1', value: v4() }],
};
const relationTargetFieldSchema = z.object({
description: z.string().optional(),
icon: z.string().startsWith('Icon'),
label: z.string().min(1),
defaultValue: z.any(),
});
const fieldSchema = z.object({
description: z.string().optional(),
icon: z.string().startsWith('Icon'),
@ -62,7 +68,7 @@ const relationSchema = fieldSchema.merge(
z.object({
type: z.literal(FieldMetadataType.Relation),
relation: z.object({
field: fieldSchema,
field: relationTargetFieldSchema,
objectMetadataId: z.string().uuid(),
type: z.enum([
RelationMetadataType.OneToMany,

View File

@ -141,7 +141,6 @@ export const SettingsObjectNewFieldStep2 = () => {
field: {
icon: validatedFormValues.relation.field.icon,
label: validatedFormValues.relation.field.label,
type: validatedFormValues.relation.field.type,
},
objectMetadataId: validatedFormValues.relation.objectMetadataId,
},