diff --git a/packages/core/client/src/common/useFieldComponentName.tsx b/packages/core/client/src/common/useFieldComponentName.tsx index f993220b00..61b5edf926 100644 --- a/packages/core/client/src/common/useFieldComponentName.tsx +++ b/packages/core/client/src/common/useFieldComponentName.tsx @@ -2,7 +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 { useCollectionField } from '../data-source'; +import { useCollectionField } from '../data-source/collection-field/CollectionFieldProvider'; export function useFieldComponentName(): string { const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = useColumnSchema(); diff --git a/packages/core/client/src/data-source/collection/AssociationProvider.tsx b/packages/core/client/src/data-source/collection/AssociationProvider.tsx index 747a0ca5e4..9c7660b497 100644 --- a/packages/core/client/src/data-source/collection/AssociationProvider.tsx +++ b/packages/core/client/src/data-source/collection/AssociationProvider.tsx @@ -1,5 +1,5 @@ import React, { FC, ReactNode, createContext, useContext } from 'react'; -import { CollectionFieldProvider, useCollectionField } from '../collection-field'; +import { CollectionFieldProvider, useCollectionField } from '../collection-field/CollectionFieldProvider'; import { CollectionDeletedPlaceholder } from '../components/CollectionDeletedPlaceholder'; import { Collection } from './Collection'; import { useCollectionManager } from './CollectionManagerProvider'; diff --git a/packages/core/client/src/data-source/collection/CollectionProvider.tsx b/packages/core/client/src/data-source/collection/CollectionProvider.tsx index 249ffdf1c0..4f94aec414 100644 --- a/packages/core/client/src/data-source/collection/CollectionProvider.tsx +++ b/packages/core/client/src/data-source/collection/CollectionProvider.tsx @@ -1,8 +1,9 @@ import React, { FC, ReactNode, createContext, useContext, useMemo } from 'react'; -import { useCollectionManager } from './CollectionManagerProvider'; +import { CollectionFieldContext } from '../collection-field/CollectionFieldProvider'; import { CollectionDeletedPlaceholder } from '../components/CollectionDeletedPlaceholder'; -import type { CollectionOptions, Collection, GetCollectionFieldPredicate } from './Collection'; +import type { Collection, CollectionOptions, GetCollectionFieldPredicate } from './Collection'; +import { useCollectionManager } from './CollectionManagerProvider'; export const CollectionContext = createContext(null); CollectionContext.displayName = 'CollectionContext'; @@ -22,6 +23,19 @@ export const CollectionProvider: FC = (props) => { return {children}; }; +/** + * 用来消除普通区块(非关系区块)中可能存在的 CollectionField 上下文,因为普通区块就是一个区块,不应该和任何字段有关联 + * @param props + * @returns + */ +export const SanitizedCollectionProvider: FC = (props) => { + return ( + + + + ); +}; + export function useCollection(): (Mixins & Collection) | undefined { const context = useContext(CollectionContext); diff --git a/packages/core/client/src/data-source/data-block/DataBlockProvider.tsx b/packages/core/client/src/data-source/data-block/DataBlockProvider.tsx index e4067ffb8e..e601624578 100644 --- a/packages/core/client/src/data-source/data-block/DataBlockProvider.tsx +++ b/packages/core/client/src/data-source/data-block/DataBlockProvider.tsx @@ -4,7 +4,12 @@ import { ACLCollectionProvider } from '../../acl/ACLProvider'; import { UseRequestOptions, UseRequestService } from '../../api-client'; import { withDynamicSchemaProps } from '../../application/hoc'; import { Designable, useDesignable } from '../../schema-component'; -import { AssociationProvider, CollectionManagerProvider, CollectionOptions, CollectionProvider } from '../collection'; +import { + AssociationProvider, + CollectionManagerProvider, + CollectionOptions, + SanitizedCollectionProvider, +} from '../collection'; import { CollectionRecord } from '../collection-record'; import { BlockRequestProvider } from './DataBlockRequestProvider'; import { DataBlockResourceProvider } from './DataBlockResourceProvider'; @@ -121,7 +126,7 @@ export const AssociationOrCollectionProvider = (props: { }; } return { - Component: CollectionProvider, + Component: SanitizedCollectionProvider, name: collection, }; }, [collection, association]); 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 b03d92f668..0996939785 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 @@ -16,7 +16,7 @@ import { FilterFormDesigner } from './FormItem.FilterFormDesigner'; import { useEnsureOperatorsValid } from './SchemaSettingOptions'; import useLazyLoadDisplayAssociationFieldsOfForm from './hooks/useLazyLoadDisplayAssociationFieldsOfForm'; import useParseDefaultValue from './hooks/useParseDefaultValue'; -import { CollectionFieldProvider } from '../../../data-source'; +import { CollectionFieldProvider } from '../../../data-source/collection-field/CollectionFieldProvider'; Item.displayName = 'FormilyFormItem';