fix: add ClearCollectionFieldContext (#4101)

* fix: add ClearCollectionFieldContext

* chore: add comment

---------

Co-authored-by: Zeke Zhang <958414905@qq.com>
This commit is contained in:
chenos 2024-04-19 16:25:29 +08:00 committed by GitHub
parent cb91f7dbd4
commit 1bacd00739
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 18 deletions

View File

@ -42,6 +42,10 @@ export const CollectionFieldProvider: FC<CollectionFieldProviderProps> = (props)
return <CollectionFieldContext.Provider value={value}>{children}</CollectionFieldContext.Provider>;
};
export const ClearCollectionFieldContext: FC = (props) => {
return <CollectionFieldContext.Provider value={null}>{props.children}</CollectionFieldContext.Provider>;
};
export const useCollectionField = () => {
const context = useContext(CollectionFieldContext);
// if (!context) {

View File

@ -6,7 +6,7 @@ import { Space, message } from 'antd';
import { isFunction } from 'mathjs';
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { RecordProvider, useAPIClient, useCollectionRecordData } from '../../../';
import { ClearCollectionFieldContext, RecordProvider, useAPIClient, useCollectionRecordData } from '../../../';
import { isVariable } from '../../../variables/utils/isVariable';
import { getInnermostKeyAndValue } from '../../common/utils/uitls';
import { RemoteSelect, RemoteSelectProps } from '../remote-select';
@ -135,14 +135,17 @@ const InternalAssociationSelect = observer(
{(addMode === 'modalAdd' || isAllowAddNew) && (
<RecordProvider isNew={true} record={null} parent={recordData}>
<RecursionField
onlyRenderProperties
basePath={field.address}
schema={fieldSchema}
filterProperties={(s) => {
return s['x-component'] === 'Action';
}}
/>
{/* 快捷添加按钮添加的添加的是一个普通的 form 区块(非关系区块),不应该与任何字段有关联,所以在这里把字段相关的上下文给清除掉 */}
<ClearCollectionFieldContext>
<RecursionField
onlyRenderProperties
basePath={field.address}
schema={fieldSchema}
filterProperties={(s) => {
return s['x-component'] === 'Action';
}}
/>
</ClearCollectionFieldContext>
</RecordProvider>
)}
</Space.Compact>

View File

@ -9,7 +9,13 @@ import {
SchemaComponentOptions,
useActionContext,
} from '../..';
import { CollectionProvider_deprecated, RecordProvider, useFormBlockContext, useCollectionRecordData } from '../../../';
import {
ClearCollectionFieldContext,
CollectionProvider_deprecated,
RecordProvider,
useCollectionRecordData,
useFormBlockContext,
} from '../../../';
import {
TableSelectorParamsProvider,
useTableSelectorProps as useTsp,
@ -171,14 +177,17 @@ export const InternalPicker = observer(
</div>
{isAllowAddNew && (
<RecordProvider isNew record={null} parent={recordData}>
<RecursionField
onlyRenderProperties
basePath={field.address}
schema={fieldSchema}
filterProperties={(s) => {
return s['x-component'] === 'Action';
}}
/>
{/* 快捷添加按钮添加的添加的是一个普通的 form 区块(非关系区块),不应该与任何字段有关联,所以在这里把字段相关的上下文给清除掉 */}
<ClearCollectionFieldContext>
<RecursionField
onlyRenderProperties
basePath={field.address}
schema={fieldSchema}
filterProperties={(s) => {
return s['x-component'] === 'Action';
}}
/>
</ClearCollectionFieldContext>
</RecordProvider>
)}
</Input.Group>