fix: the details of the associated data in the subtable are not displayed (#454)

This commit is contained in:
chenos 2022-06-02 10:06:49 +08:00 committed by GitHub
parent a494376f31
commit b8fac535f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 11 deletions

View File

@ -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);

View File

@ -108,11 +108,15 @@ export class TableFieldResource {
}
}
export const WithoutTableFieldResource = createContext(null);
export const TableFieldProvider = (props) => {
return (
<BlockProvider block={'TableField'} {...props}>
<InternalTableFieldProvider {...props} />
</BlockProvider>
<WithoutTableFieldResource.Provider value={false}>
<BlockProvider block={'TableField'} {...props}>
<InternalTableFieldProvider {...props} />
</BlockProvider>
</WithoutTableFieldResource.Provider>
);
};

View File

@ -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) => {
</Space>
<ActionContext.Provider value={{ visible, setVisible, openMode: 'drawer' }}>
<RecordProvider record={record}>
<FormProvider>
<RecursionField schema={fieldSchema} onlyRenderProperties />
</FormProvider>
<WithoutTableFieldResource.Provider value={true}>
<FormProvider>
<RecursionField schema={fieldSchema} onlyRenderProperties />
</FormProvider>
</WithoutTableFieldResource.Provider>
</RecordProvider>
</ActionContext.Provider>
</CollectionProvider>