From a38e34cf9ae30662452223da4872a42fbd444e37 Mon Sep 17 00:00:00 2001 From: jack zhang <1098626505@qq.com> Date: Fri, 29 Mar 2024 09:12:52 +0800 Subject: [PATCH] fix: table settings get collectionField (#3837) * fix: table settings get collectionField * fix: remove duplicate useCollectionField * fix: bug * refactor: tagComponentFieldSettings --------- Co-authored-by: katherinehhh --- .../client/src/common/useFieldComponentName.tsx | 14 +------------- .../collection-field/CollectionFieldProvider.tsx | 4 ++-- .../cascadeSelectComponentFieldSettings.tsx | 2 +- .../Nester/subformComponentFieldSettings.tsx | 2 +- .../Picker/recordPickerComponentFieldSettings.tsx | 2 +- .../subformPopoverComponentFieldSettings.tsx | 2 +- .../Select/selectComponentFieldSettings.tsx | 2 +- .../component/Tag/tagComponentFieldSettings.tsx | 9 ++++++--- .../client/src/modules/fields/component/utils.tsx | 14 -------------- .../schema-component/antd/form-item/FormItem.tsx | 9 ++++----- 10 files changed, 18 insertions(+), 42 deletions(-) delete mode 100644 packages/core/client/src/modules/fields/component/utils.tsx diff --git a/packages/core/client/src/common/useFieldComponentName.tsx b/packages/core/client/src/common/useFieldComponentName.tsx index a20cbca9a5..f993220b00 100644 --- a/packages/core/client/src/common/useFieldComponentName.tsx +++ b/packages/core/client/src/common/useFieldComponentName.tsx @@ -2,19 +2,7 @@ import { Field } from '@formily/core'; import { useField, useFieldSchema } from '@formily/react'; import { useIsFileField } from '../schema-component/antd/form-item/FormItem.Settings'; import { useColumnSchema } from '../schema-component/antd/table-v2/Table.Column.Decorator'; -import { useCollectionManager_deprecated, useCollection_deprecated } from '../collection-manager'; - -/** - * 获取字段相关的配置信息 - * @returns - */ -function useCollectionField() { - const { getCollectionJoinField } = useCollectionManager_deprecated(); - const { getField } = useCollection_deprecated(); - const fieldSchema = useFieldSchema(); - const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']); - return collectionField; -} +import { useCollectionField } from '../data-source'; export function useFieldComponentName(): string { const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = useColumnSchema(); diff --git a/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx b/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx index 22724c1db3..bf186bd9ff 100644 --- a/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx +++ b/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx @@ -22,7 +22,7 @@ export const CollectionFieldProvider: FC = (props) const collectionManager = useCollectionManager(); const value = useMemo(() => { - if (!collection || allowNull) return null; + if (!collection) return null; const field = fieldSchema?.['x-component-props']?.['field']; return ( collectionManager.getCollectionField(fieldSchema?.['x-collection-field']) || @@ -31,7 +31,7 @@ export const CollectionFieldProvider: FC = (props) ); }, [collection, fieldSchema, name, collectionManager]); - if (!collection || allowNull) { + if (!value && allowNull) { return <>{children}; } diff --git a/packages/core/client/src/modules/fields/component/CascadeSelect/cascadeSelectComponentFieldSettings.tsx b/packages/core/client/src/modules/fields/component/CascadeSelect/cascadeSelectComponentFieldSettings.tsx index b3f9bac57e..5d24fe83ca 100644 --- a/packages/core/client/src/modules/fields/component/CascadeSelect/cascadeSelectComponentFieldSettings.tsx +++ b/packages/core/client/src/modules/fields/component/CascadeSelect/cascadeSelectComponentFieldSettings.tsx @@ -6,7 +6,7 @@ import { useFieldComponentName } from '../../../../common/useFieldComponentName' import { useDesignable, useFieldModeOptions, useIsAddNewForm } from '../../../../schema-component'; import { isSubMode } from '../../../../schema-component/antd/association-field/util'; import { useTitleFieldOptions } from '../../../../schema-component/antd/form-item/FormItem.Settings'; -import { useCollectionField } from '../utils'; +import { useCollectionField } from '../../../../data-source'; const fieldComponent: any = { name: 'fieldComponent', diff --git a/packages/core/client/src/modules/fields/component/Nester/subformComponentFieldSettings.tsx b/packages/core/client/src/modules/fields/component/Nester/subformComponentFieldSettings.tsx index 6e5801303a..a525d6ef86 100644 --- a/packages/core/client/src/modules/fields/component/Nester/subformComponentFieldSettings.tsx +++ b/packages/core/client/src/modules/fields/component/Nester/subformComponentFieldSettings.tsx @@ -9,7 +9,7 @@ import { useIsFieldReadPretty, useIsFormReadPretty, } from '../../../../schema-component/antd/form-item/FormItem.Settings'; -import { useCollectionField } from '../utils'; +import { useCollectionField } from '../../../../data-source'; import { useFormBlockType } from '../../../../block-provider'; const allowMultiple: any = { diff --git a/packages/core/client/src/modules/fields/component/Picker/recordPickerComponentFieldSettings.tsx b/packages/core/client/src/modules/fields/component/Picker/recordPickerComponentFieldSettings.tsx index 3ca9d45d17..e3ea77a523 100644 --- a/packages/core/client/src/modules/fields/component/Picker/recordPickerComponentFieldSettings.tsx +++ b/packages/core/client/src/modules/fields/component/Picker/recordPickerComponentFieldSettings.tsx @@ -10,7 +10,7 @@ import { useTitleFieldOptions, } from '../../../../schema-component/antd/form-item/FormItem.Settings'; import { useColumnSchema } from '../../../../schema-component/antd/table-v2/Table.Column.Decorator'; -import { useCollectionField } from '../utils'; +import { useCollectionField } from '../../../../data-source'; export const titleField: any = { name: 'titleField', diff --git a/packages/core/client/src/modules/fields/component/PopoverNester/subformPopoverComponentFieldSettings.tsx b/packages/core/client/src/modules/fields/component/PopoverNester/subformPopoverComponentFieldSettings.tsx index dd99735fc4..725c76b72a 100644 --- a/packages/core/client/src/modules/fields/component/PopoverNester/subformPopoverComponentFieldSettings.tsx +++ b/packages/core/client/src/modules/fields/component/PopoverNester/subformPopoverComponentFieldSettings.tsx @@ -6,7 +6,7 @@ import { useFieldComponentName } from '../../../../common/useFieldComponentName' import { useDesignable, useFieldModeOptions, useIsAddNewForm } from '../../../../schema-component'; import { isSubMode } from '../../../../schema-component/antd/association-field/util'; import { useIsFieldReadPretty } from '../../../../schema-component/antd/form-item/FormItem.Settings'; -import { useCollectionField } from '../utils'; +import { useCollectionField } from '../../../../data-source'; import { useColumnSchema } from '../../../../schema-component/antd/table-v2/Table.Column.Decorator'; import { titleField } from '../Picker/recordPickerComponentFieldSettings'; diff --git a/packages/core/client/src/modules/fields/component/Select/selectComponentFieldSettings.tsx b/packages/core/client/src/modules/fields/component/Select/selectComponentFieldSettings.tsx index 4432d31a61..a09fb06742 100644 --- a/packages/core/client/src/modules/fields/component/Select/selectComponentFieldSettings.tsx +++ b/packages/core/client/src/modules/fields/component/Select/selectComponentFieldSettings.tsx @@ -23,7 +23,7 @@ import { SchemaSettingsDataScope } from '../../../../schema-settings/SchemaSetti import { SchemaSettingsSortingRule } from '../../../../schema-settings/SchemaSettingsSortingRule'; import { useIsShowMultipleSwitch } from '../../../../schema-settings/hooks/useIsShowMultipleSwitch'; import { useLocalVariables, useVariables } from '../../../../variables'; -import { useCollectionField } from '../utils'; +import { useCollectionField } from '../../../../data-source'; const enableLink = { name: 'enableLink', diff --git a/packages/core/client/src/modules/fields/component/Tag/tagComponentFieldSettings.tsx b/packages/core/client/src/modules/fields/component/Tag/tagComponentFieldSettings.tsx index 3bc7db00a8..6d5d9c69f2 100644 --- a/packages/core/client/src/modules/fields/component/Tag/tagComponentFieldSettings.tsx +++ b/packages/core/client/src/modules/fields/component/Tag/tagComponentFieldSettings.tsx @@ -8,7 +8,7 @@ import { isSubMode } from '../../../../schema-component/antd/association-field/u import { useTitleFieldOptions } from '../../../../schema-component/antd/form-item/FormItem.Settings'; import { useColorFields } from '../../../../schema-component/antd/table-v2/Table.Column.Designer'; import { useColumnSchema } from '../../../../schema-component/antd/table-v2/Table.Column.Decorator'; -import { useCollectionField } from '../utils'; +import { useCollectionField } from '../../../../data-source'; const enableLink = { name: 'enableLink', @@ -140,9 +140,12 @@ export const tagComponentFieldSettings = new SchemaSettings({ useComponentProps() { const { t } = useTranslation(); const field = useField(); - const fieldSchema = useFieldSchema(); + const schema = useFieldSchema(); + const targetCollectionField = useCollectionField(); + const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = useColumnSchema(); + const fieldSchema = tableColumnSchema || schema; + const collectionField = tableColumnField || targetCollectionField; const { dn } = useDesignable(); - const collectionField = useCollectionField(); const colorFieldOptions = useColorFields(collectionField?.target ?? collectionField?.targetCollection); return { title: t('Tag color field'), diff --git a/packages/core/client/src/modules/fields/component/utils.tsx b/packages/core/client/src/modules/fields/component/utils.tsx deleted file mode 100644 index 3c47f17582..0000000000 --- a/packages/core/client/src/modules/fields/component/utils.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import { useFieldSchema } from '@formily/react'; -import { useCollection_deprecated, useCollectionManager_deprecated } from '../../../collection-manager'; - -/** - * 获取字段相关的配置信息 - * @returns - */ -export function useCollectionField() { - const { getCollectionJoinField } = useCollectionManager_deprecated(); - const { getField } = useCollection_deprecated(); - const fieldSchema = useFieldSchema(); - const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']); - return collectionField; -} diff --git a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx index f8d2d4a924..c228165d0a 100644 --- a/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx +++ b/packages/core/client/src/schema-component/antd/form-item/FormItem.tsx @@ -67,16 +67,15 @@ export const FormItem: any = observer( }, ); }, [showTitle]); - const fieldSchema = useFieldSchema(); return ( - - + + - - + + ); }, { displayName: 'FormItem' },