diff --git a/packages/core/client/src/block-provider/BlockProvider.tsx b/packages/core/client/src/block-provider/BlockProvider.tsx index 28e53fc10..15b3f855d 100644 --- a/packages/core/client/src/block-provider/BlockProvider.tsx +++ b/packages/core/client/src/block-provider/BlockProvider.tsx @@ -8,16 +8,14 @@ import React, { createContext, useContext } from 'react'; import { Link } from 'react-router-dom'; import { ACLCollectionProvider, - TableFieldContext, TableFieldResource, useActionContext, useAPIClient, useDesignable, useRecord, - useTableFieldContext, - WithoutTableFieldResource, + WithoutTableFieldResource } from '../'; -import { CollectionProvider, useCollection, useCollectionField, useCollectionManager } from '../collection-manager'; +import { CollectionProvider, useCollection, useCollectionManager } from '../collection-manager'; import { useRecordIndex } from '../record-provider'; import { SharedFilterProvider } from './SharedFilterProvider'; diff --git a/packages/core/client/src/block-provider/FormBlockProvider.tsx b/packages/core/client/src/block-provider/FormBlockProvider.tsx index fc4ac0c58..3f98241c3 100644 --- a/packages/core/client/src/block-provider/FormBlockProvider.tsx +++ b/packages/core/client/src/block-provider/FormBlockProvider.tsx @@ -1,11 +1,12 @@ import { createForm } from '@formily/core'; -import { useField, useFieldSchema } from '@formily/react'; +import { useField } from '@formily/react'; import { Spin } from 'antd'; +import isEmpty from 'lodash/isEmpty'; import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react'; -import { RecordProvider, useRecord } from '../record-provider'; -import { BlockProvider, useBlockRequestContext } from './BlockProvider'; -import { useDesignable } from '../schema-component'; import { useCollectionManager } from '../collection-manager'; +import { RecordProvider, useRecord } from '../record-provider'; +import { useDesignable } from '../schema-component'; +import { BlockProvider, useBlockRequestContext } from './BlockProvider'; export const FormBlockContext = createContext({}); @@ -21,6 +22,7 @@ const InternalFormBlockProvider = (props) => { ); const { resource, service } = useBlockRequestContext(); const formBlockRef = useRef(); + const record = useRecord(); if (service.loading) { return ; } @@ -37,7 +39,7 @@ const InternalFormBlockProvider = (props) => { }} > {readPretty ? ( - +
{props.children}
) : ( diff --git a/packages/core/client/src/record-provider/index.tsx b/packages/core/client/src/record-provider/index.tsx index e614270da..5be3ee5f5 100644 --- a/packages/core/client/src/record-provider/index.tsx +++ b/packages/core/client/src/record-provider/index.tsx @@ -4,10 +4,12 @@ import { useCurrentUserContext } from '../user'; export const RecordContext = createContext({}); export const RecordIndexContext = createContext(null); -export const RecordProvider: React.FC<{ record: any }> = (props) => { - const { record, children } = props; +export const RecordProvider: React.FC<{ record: any; parent?: any }> = (props) => { + const { record, children, parent = false } = props; const __parent = useContext(RecordContext); - return {children}; + const value = { ...record }; + value['__parent'] = parent ? parent : __parent; + return {children}; }; export const RecordIndexProvider: React.FC<{ index: any }> = (props) => {