From 49c2fbf45d9ed3d3eceabdd46080f329b7626ae3 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Tue, 26 Sep 2023 21:25:40 +0800 Subject: [PATCH] refactor: file association field should default to using preview field as title field (#2718) --- .../core/client/src/schema-initializer/utils.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/core/client/src/schema-initializer/utils.ts b/packages/core/client/src/schema-initializer/utils.ts index 87881ab45..d3878fd67 100644 --- a/packages/core/client/src/schema-initializer/utils.ts +++ b/packages/core/client/src/schema-initializer/utils.ts @@ -270,12 +270,12 @@ export const useFormItemInitializerFields = (options?: any) => { const { readPretty = form.readPretty, block = 'Form' } = options || {}; const { snapshot, fieldSchema } = useActionContext(); const action = fieldSchema?.['x-action']; - return currentFields ?.filter((field) => field?.interface && !field?.isForeignKey && !field?.treeChildren) ?.map((field) => { const interfaceConfig = getInterface(field.interface); const targetCollection = getCollection(field.target); + const isFileCollection = field?.target && getCollection(field?.target)?.template === 'file'; // const component = // field.interface === 'o2m' && targetCollection?.template !== 'file' && !snapshot // ? 'TableField' @@ -287,7 +287,14 @@ export const useFormItemInitializerFields = (options?: any) => { 'x-component': 'CollectionField', 'x-decorator': 'FormItem', 'x-collection-field': `${name}.${field.name}`, - 'x-component-props': {}, + 'x-component-props': isFileCollection + ? { + fieldNames: { + label: 'preview', + value: 'id', + }, + } + : {}, 'x-read-pretty': field?.uiSchema?.['x-read-pretty'], }; // interfaceConfig?.schemaInitialize?.(schema, { field, block: 'Form', readPretty: form.readPretty }); @@ -397,14 +404,20 @@ export const useAssociatedFormItemInitializerFields = (options?: any) => { ) ?.map((subField) => { const interfaceConfig = getInterface(subField.interface); + const isFileCollection = field?.target && getCollection(field?.target)?.template === 'file'; const schema = { type: 'string', name: `${field.name}.${subField.name}`, 'x-designer': 'FormItem.Designer', 'x-component': 'CollectionField', + 'x-read-pretty': readPretty, 'x-component-props': { 'pattern-disable': block === 'Form' && readPretty, + fieldNames: { + label: isFileCollection ? 'preview' : 'id', + value: 'id', + }, }, 'x-decorator': 'FormItem', 'x-collection-field': `${name}.${field.name}.${subField.name}`,