diff --git a/packages/core/client/src/schema-component/antd/association-field/Editable.tsx b/packages/core/client/src/schema-component/antd/association-field/Editable.tsx index 980d347cb3..e70f00519f 100644 --- a/packages/core/client/src/schema-component/antd/association-field/Editable.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/Editable.tsx @@ -5,7 +5,7 @@ import { InternalNester } from './InternalNester'; import { InternalPicker } from './InternalPicker'; import { AssociationSelect } from './AssociationSelect'; import { useAssociationCreateActionProps as useCAP } from '../../../block-provider/hooks'; -import { useCollection, useCollectionManager } from '../../../collection-manager'; +import { useCollectionManager } from '../../../collection-manager'; import { SchemaComponentOptions } from '../../'; import { InternalSubTable } from './InternalSubTable'; import { InternalFileManager } from './FileManager'; @@ -18,9 +18,8 @@ export const Editable = observer((props: any) => { const field: any = useField(); const form = useForm(); const fieldSchema = useFieldSchema(); - const { getField } = useCollection(); - const { getCollection } = useCollectionManager(); - const collectionField = getField(field.props.name); + const { getCollection, getCollectionJoinField } = useCollectionManager(); + const collectionField = getCollectionJoinField(fieldSchema?.['x-collection-field']); const isFileCollection = getCollection(collectionField?.target)?.template === 'file'; const [currentMode, setCurrentMode] = useState(props.mode || (isFileCollection ? 'FileManager' : 'Select')); const useCreateActionProps = () => { diff --git a/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx b/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx index 647a2ee5b3..635e5b9a39 100644 --- a/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/InternalViewer.tsx @@ -2,7 +2,7 @@ import { RecursionField, observer, useField, useFieldSchema } from '@formily/rea import { toArr } from '@formily/shared'; import React, { Fragment, useRef, useState } from 'react'; import { BlockAssociationContext, WithoutTableFieldResource } from '../../../block-provider'; -import { CollectionProvider, useCollection, useCollectionManager } from '../../../collection-manager'; +import { CollectionProvider, useCollectionManager } from '../../../collection-manager'; import { RecordProvider, useRecord } from '../../../record-provider'; import { FormProvider } from '../../core'; import { useCompile } from '../../hooks'; @@ -32,8 +32,7 @@ export const ReadPrettyInternalViewer: React.FC = observer((props: any) => { const fieldNames = useFieldNames(props); const [visible, setVisible] = useState(false); const insertViewer = useInsertSchema('Viewer'); - const { getField } = useCollection(); - const collectionField = getField(fieldSchema.name) || getCollectionJoinField(fieldSchema?.['x-collection-field']); + const collectionField = getCollectionJoinField(fieldSchema?.['x-collection-field']); const [record, setRecord] = useState({}); const compile = useCompile(); const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.label || 'label'); diff --git a/packages/core/client/src/schema-component/antd/association-field/ReadPretty.tsx b/packages/core/client/src/schema-component/antd/association-field/ReadPretty.tsx index d07e91f180..56da6277c1 100644 --- a/packages/core/client/src/schema-component/antd/association-field/ReadPretty.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/ReadPretty.tsx @@ -1,17 +1,16 @@ import React, { useEffect, useState } from 'react'; -import { useField, observer } from '@formily/react'; +import { useFieldSchema, observer } from '@formily/react'; import { AssociationFieldProvider } from './AssociationFieldProvider'; import { InternalNester } from './InternalNester'; import { ReadPrettyInternalViewer } from './InternalViewer'; -import { useCollection, useCollectionManager } from '../../../collection-manager'; +import { useCollectionManager } from '../../../collection-manager'; import { InternalSubTable } from './InternalSubTable'; import { FileManageReadPretty } from './FileManager'; export const ReadPretty = observer((props: any) => { - const field: any = useField(); - const { getField } = useCollection(); - const { getCollection } = useCollectionManager(); - const collectionField = getField(field.props.name); + const fieldSchema = useFieldSchema(); + const { getCollection, getCollectionJoinField } = useCollectionManager(); + const collectionField = getCollectionJoinField(fieldSchema?.['x-collection-field']); const isFileCollection = getCollection(collectionField?.target)?.template === 'file'; const [currentMode, setCurrentMode] = useState(props.mode || (isFileCollection ? 'FileManager' : 'Select')); useEffect(() => {