From efbd7c7020c0e2c720fbfea63fa92c2d31b40108 Mon Sep 17 00:00:00 2001 From: chenos Date: Fri, 26 May 2023 11:38:03 +0800 Subject: [PATCH] fix(association-field): allow multiple (#1938) --- packages/core/client/src/locale/zh_CN.ts | 2 +- .../antd/association-field/AssociationFieldProvider.tsx | 3 ++- .../src/schema-component/antd/association-field/Nester.tsx | 4 ++-- .../src/schema-component/antd/association-field/context.ts | 3 ++- .../src/schema-component/antd/association-field/hooks.ts | 7 ++++++- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/core/client/src/locale/zh_CN.ts b/packages/core/client/src/locale/zh_CN.ts index 3744380e0..ec0d0f67a 100644 --- a/packages/core/client/src/locale/zh_CN.ts +++ b/packages/core/client/src/locale/zh_CN.ts @@ -312,7 +312,7 @@ export default { "Display association fields": "显示关联表的字段", "Display field title": "显示字段标题", "Field component": "字段组件", - "Allow multiple": "允许多选", + "Allow multiple": "允许添加/关联多条", "Quick upload": "快速上传", "Select file": "选择文件", "Subtable": "子表格", diff --git a/packages/core/client/src/schema-component/antd/association-field/AssociationFieldProvider.tsx b/packages/core/client/src/schema-component/antd/association-field/AssociationFieldProvider.tsx index 33fdbecc9..ef9ddcde6 100644 --- a/packages/core/client/src/schema-component/antd/association-field/AssociationFieldProvider.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/AssociationFieldProvider.tsx @@ -8,6 +8,7 @@ export const AssociationFieldProvider = observer((props) => { const field = useField(); const { getCollectionJoinField, getCollection } = useCollectionManager(); const fieldSchema = useFieldSchema(); + const allowMultiple = fieldSchema['x-component-props']?.multiple !== false; const collectionField = useMemo( () => getCollectionJoinField(fieldSchema['x-collection-field']), @@ -23,7 +24,7 @@ export const AssociationFieldProvider = observer((props) => { ); return collectionField ? ( - + {props.children} ) : null; diff --git a/packages/core/client/src/schema-component/antd/association-field/Nester.tsx b/packages/core/client/src/schema-component/antd/association-field/Nester.tsx index 4ad58961e..5d8fe4d52 100644 --- a/packages/core/client/src/schema-component/antd/association-field/Nester.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/Nester.tsx @@ -24,7 +24,7 @@ const ToOneNester = (props) => { const ToManyNester = observer((props) => { const fieldSchema = useFieldSchema(); - const { field } = useAssociationFieldContext(); + const { field, allowMultiple } = useAssociationFieldContext(); const { t } = useTranslation(); return ( @@ -48,7 +48,7 @@ const ToManyNester = observer((props) => { ); })} - {field.editable && ( + {field.editable && allowMultiple && (