From 19a33dfe74dfccff5fbd5327a16543e3589e7a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rairn?= <958414905@qq.com> Date: Mon, 15 May 2023 15:26:46 +0800 Subject: [PATCH] fix: fix multi-select field not show 'Allow multiple' switch (#1857) * fix: fix multi-select field not show 'Allow multiple' switch * fix: use uiSchema --- .../association-select/AssociationSelect.tsx | 54 ++++++++--------- .../antd/form-item/FormItem.tsx | 59 +++++++++---------- .../hooks/useIsShowMultipleSwitch.ts | 19 ++++++ 3 files changed, 73 insertions(+), 59 deletions(-) create mode 100644 packages/core/client/src/schema-settings/hooks/useIsShowMultipleSwitch.ts diff --git a/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx b/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx index ba6614ea7..4e0fd63fb 100644 --- a/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx +++ b/packages/core/client/src/schema-component/antd/association-select/AssociationSelect.tsx @@ -15,6 +15,7 @@ import { } from '../../../collection-manager'; import { isTitleField } from '../../../collection-manager/Configuration/CollectionFields'; import { GeneralSchemaDesigner, SchemaSettings, isPatternDisabled, isShowDefaultValue } from '../../../schema-settings'; +import { useIsShowMultipleSwitch } from '../../../schema-settings/hooks/useIsShowMultipleSwitch'; import { useCompile, useDesignable, useFieldComponentOptions, useFieldTitle } from '../../hooks'; import { removeNullCondition } from '../filter'; import { RemoteSelect, RemoteSelectProps } from '../remote-select'; @@ -102,6 +103,8 @@ AssociationSelect.Designer = function Designer() { const tk = useFilterByTk(); const { dn, refresh, insertAdjacent } = useDesignable(); const compile = useCompile(); + const IsShowMultipleSwitch = useIsShowMultipleSwitch(); + const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']); const fieldComponentOptions = useFieldComponentOptions(); const isSubFormAssociationField = field.address.segments.includes('__form_grid'); @@ -495,36 +498,31 @@ AssociationSelect.Designer = function Designer() { }} /> )} - {form && - !form?.readPretty && - ['o2m', 'm2m'].includes(collectionField.interface) && - fieldSchema['x-component'] !== 'TableField' && ( - { - const schema = { - ['x-uid']: fieldSchema['x-uid'], - }; - fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {}; - field.componentProps = field.componentProps || {}; + {IsShowMultipleSwitch() ? ( + { + const schema = { + ['x-uid']: fieldSchema['x-uid'], + }; + fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {}; + field.componentProps = field.componentProps || {}; - fieldSchema['x-component-props'].multiple = value; - field.componentProps.multiple = value; + fieldSchema['x-component-props'].multiple = value; + field.componentProps.multiple = value; - schema['x-component-props'] = fieldSchema['x-component-props']; - dn.emit('patch', { - schema, - }); - refresh(); - }} - /> - )} + schema['x-component-props'] = fieldSchema['x-component-props']; + dn.emit('patch', { + schema, + }); + refresh(); + }} + /> + ) : null} { FormItem.Designer = function Designer() { const { getCollectionFields, getInterface, getCollectionJoinField, getCollection } = useCollectionManager(); const { getField } = useCollection(); - const tk = useFilterByTk(); const { form } = useFormBlockContext(); const field = useField(); const fieldSchema = useFieldSchema(); const { t } = useTranslation(); - const { dn, refresh, insertAdjacent } = useDesignable(); + const { dn, refresh } = useDesignable(); const compile = useCompile(); const variablesCtx = useVariablesCtx(); + const IsShowMultipleSwitch = useIsShowMultipleSwitch(); + const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']); const targetCollection = getCollection(collectionField?.target); const interfaceConfig = getInterface(collectionField?.interface); @@ -705,36 +707,31 @@ FormItem.Designer = function Designer() { }} /> )} - {form && - !form?.readPretty && - ['o2m', 'm2m'].includes(collectionField?.interface) && - fieldSchema['x-component'] !== 'TableField' && ( - { - const schema = { - ['x-uid']: fieldSchema['x-uid'], - }; - fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {}; - field.componentProps = field.componentProps || {}; + {IsShowMultipleSwitch() ? ( + { + const schema = { + ['x-uid']: fieldSchema['x-uid'], + }; + fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {}; + field.componentProps = field.componentProps || {}; - fieldSchema['x-component-props'].multiple = value; - field.componentProps.multiple = value; + fieldSchema['x-component-props'].multiple = value; + field.componentProps.multiple = value; - schema['x-component-props'] = fieldSchema['x-component-props']; - dn.emit('patch', { - schema, - }); - refresh(); - }} - /> - )} + schema['x-component-props'] = fieldSchema['x-component-props']; + dn.emit('patch', { + schema, + }); + refresh(); + }} + /> + ) : null} {field.readPretty && options.length > 0 && fieldSchema['x-component'] === 'CollectionField' && !isFileField && (