From b8fac535f29f59045ea8a7db01b589f77d805f9c Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 2 Jun 2022 10:06:49 +0800 Subject: [PATCH] fix: the details of the associated data in the subtable are not displayed (#454) --- .../core/client/src/block-provider/BlockProvider.tsx | 12 ++++++++---- .../client/src/block-provider/TableFieldProvider.tsx | 10 +++++++--- .../antd/record-picker/ReadPrettyRecordPicker.tsx | 10 ++++++---- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/core/client/src/block-provider/BlockProvider.tsx b/packages/core/client/src/block-provider/BlockProvider.tsx index 4b8b8e1c45..30f27f821a 100644 --- a/packages/core/client/src/block-provider/BlockProvider.tsx +++ b/packages/core/client/src/block-provider/BlockProvider.tsx @@ -4,7 +4,7 @@ import { useRequest } from 'ahooks'; import template from 'lodash/template'; import React, { createContext, useContext } from 'react'; import { Link } from 'react-router-dom'; -import { ACLCollectionProvider, TableFieldResource, useAPIClient, useRecord } from '../'; +import { ACLCollectionProvider, TableFieldResource, useAPIClient, useRecord, WithoutTableFieldResource } from '../'; import { CollectionProvider, useCollection, useCollectionManager } from '../collection-manager'; import { useRecordIndex } from '../record-provider'; @@ -49,8 +49,9 @@ const useReousrce = (props: UseReousrceProps) => { }; return new TableFieldResource(options); } + const withoutTableFieldResource = useContext(WithoutTableFieldResource); const __parent = useContext(BlockRequestContext); - if (__parent?.block === 'TableField' && __parent?.resource instanceof TableFieldResource) { + if (!withoutTableFieldResource && __parent?.block === 'TableField' && __parent?.resource instanceof TableFieldResource) { return __parent.resource; } if (!association) { @@ -143,8 +144,11 @@ export const useFilterByTk = () => { const collection = useCollection(); const { getCollectionField } = useCollectionManager(); const assoc = useContext(BlockAssociationContext); - if (resource instanceof TableFieldResource || __parent?.block === 'TableField') { - return recordIndex; + const withoutTableFieldResource = useContext(WithoutTableFieldResource); + if (!withoutTableFieldResource) { + if (resource instanceof TableFieldResource || __parent?.block === 'TableField') { + return recordIndex; + } } if (assoc) { const association = getCollectionField(assoc); diff --git a/packages/core/client/src/block-provider/TableFieldProvider.tsx b/packages/core/client/src/block-provider/TableFieldProvider.tsx index 8b6491bc10..9ad713fb5f 100644 --- a/packages/core/client/src/block-provider/TableFieldProvider.tsx +++ b/packages/core/client/src/block-provider/TableFieldProvider.tsx @@ -108,11 +108,15 @@ export class TableFieldResource { } } +export const WithoutTableFieldResource = createContext(null); + export const TableFieldProvider = (props) => { return ( - - - + + + + + ); }; diff --git a/packages/core/client/src/schema-component/antd/record-picker/ReadPrettyRecordPicker.tsx b/packages/core/client/src/schema-component/antd/record-picker/ReadPrettyRecordPicker.tsx index 6d2c2e83b8..731354964d 100644 --- a/packages/core/client/src/schema-component/antd/record-picker/ReadPrettyRecordPicker.tsx +++ b/packages/core/client/src/schema-component/antd/record-picker/ReadPrettyRecordPicker.tsx @@ -3,7 +3,7 @@ import { observer, RecursionField, useField, useFieldSchema } from '@formily/rea import { toArr } from '@formily/shared'; import { Space } from 'antd'; import React, { useState } from 'react'; -import { BlockAssociationContext } from '../../../block-provider'; +import { BlockAssociationContext, WithoutTableFieldResource } from '../../../block-provider'; import { CollectionProvider, useCollection } from '../../../collection-manager'; import { RecordProvider } from '../../../record-provider'; import { FormProvider } from '../../core'; @@ -44,9 +44,11 @@ export const ReadPrettyRecordPicker: React.FC = observer((props: any) => { - - - + + + + +