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 template from 'lodash/template';
import React, { createContext, useContext } from 'react'; import React, { createContext, useContext } from 'react';
import { Link } from 'react-router-dom'; 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 { CollectionProvider, useCollection, useCollectionManager } from '../collection-manager';
import { useRecordIndex } from '../record-provider'; import { useRecordIndex } from '../record-provider';
@ -49,8 +49,9 @@ const useReousrce = (props: UseReousrceProps) => {
}; };
return new TableFieldResource(options); return new TableFieldResource(options);
} }
const withoutTableFieldResource = useContext(WithoutTableFieldResource);
const __parent = useContext(BlockRequestContext); const __parent = useContext(BlockRequestContext);
if (__parent?.block === 'TableField' && __parent?.resource instanceof TableFieldResource) { if (!withoutTableFieldResource && __parent?.block === 'TableField' && __parent?.resource instanceof TableFieldResource) {
return __parent.resource; return __parent.resource;
} }
if (!association) { if (!association) {
@ -143,9 +144,12 @@ export const useFilterByTk = () => {
const collection = useCollection(); const collection = useCollection();
const { getCollectionField } = useCollectionManager(); const { getCollectionField } = useCollectionManager();
const assoc = useContext(BlockAssociationContext); const assoc = useContext(BlockAssociationContext);
const withoutTableFieldResource = useContext(WithoutTableFieldResource);
if (!withoutTableFieldResource) {
if (resource instanceof TableFieldResource || __parent?.block === 'TableField') { if (resource instanceof TableFieldResource || __parent?.block === 'TableField') {
return recordIndex; return recordIndex;
} }
}
if (assoc) { if (assoc) {
const association = getCollectionField(assoc); const association = getCollectionField(assoc);
return record?.[association.targetKey || 'id']; return record?.[association.targetKey || 'id'];

View File

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

View File

@ -3,7 +3,7 @@ import { observer, RecursionField, useField, useFieldSchema } from '@formily/rea
import { toArr } from '@formily/shared'; import { toArr } from '@formily/shared';
import { Space } from 'antd'; import { Space } from 'antd';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { BlockAssociationContext } from '../../../block-provider'; import { BlockAssociationContext, WithoutTableFieldResource } from '../../../block-provider';
import { CollectionProvider, useCollection } from '../../../collection-manager'; import { CollectionProvider, useCollection } from '../../../collection-manager';
import { RecordProvider } from '../../../record-provider'; import { RecordProvider } from '../../../record-provider';
import { FormProvider } from '../../core'; import { FormProvider } from '../../core';
@ -44,9 +44,11 @@ export const ReadPrettyRecordPicker: React.FC = observer((props: any) => {
</Space> </Space>
<ActionContext.Provider value={{ visible, setVisible, openMode: 'drawer' }}> <ActionContext.Provider value={{ visible, setVisible, openMode: 'drawer' }}>
<RecordProvider record={record}> <RecordProvider record={record}>
<WithoutTableFieldResource.Provider value={true}>
<FormProvider> <FormProvider>
<RecursionField schema={fieldSchema} onlyRenderProperties /> <RecursionField schema={fieldSchema} onlyRenderProperties />
</FormProvider> </FormProvider>
</WithoutTableFieldResource.Provider>
</RecordProvider> </RecordProvider>
</ActionContext.Provider> </ActionContext.Provider>
</CollectionProvider> </CollectionProvider>