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 = ( export const formatFieldMetadataItemInput = (
input: Pick< input: Pick<
Field, Field,
'label' | 'icon' | 'description' | 'defaultValue' | 'type' | 'options' 'label' | 'icon' | 'description' | 'defaultValue' | 'options'
>, > & { type?: FieldMetadataType },
) => { ) => {
const options = input.options as FieldMetadataOption[]; const options = input.options as FieldMetadataOption[];
let defaultValue = input.defaultValue; let defaultValue = input.defaultValue;

View File

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

View File

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

View File

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