diff --git a/packages/core/client/src/common/useFieldComponentName.tsx b/packages/core/client/src/common/useFieldComponentName.tsx index a20cbca9a..f993220b0 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 22724c1db..bf186bd9f 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 b3f9bac57..5d24fe83c 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 6e5801303..a525d6ef8 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 3ca9d45d1..e3ea77a52 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 dd99735fc..725c76b72 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 4432d31a6..a09fb0674 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 3bc7db00a..6d5d9c69f 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 3c47f1758..000000000 --- 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 f8d2d4a92..c228165d0 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' },