From 1bacd007393ef908d9359c02adf681aea4a915d4 Mon Sep 17 00:00:00 2001 From: chenos Date: Fri, 19 Apr 2024 16:25:29 +0800 Subject: [PATCH] fix: add ClearCollectionFieldContext (#4101) * fix: add ClearCollectionFieldContext * chore: add comment --------- Co-authored-by: Zeke Zhang <958414905@qq.com> --- .../CollectionFieldProvider.tsx | 4 +++ .../association-field/AssociationSelect.tsx | 21 ++++++++------- .../antd/association-field/InternalPicker.tsx | 27 ++++++++++++------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx b/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx index bf186bd9f..6f764323b 100644 --- a/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx +++ b/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx @@ -42,6 +42,10 @@ export const CollectionFieldProvider: FC = (props) return {children}; }; +export const ClearCollectionFieldContext: FC = (props) => { + return {props.children}; +}; + export const useCollectionField = () => { const context = useContext(CollectionFieldContext); // if (!context) { diff --git a/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx b/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx index 62af07e9f..7293655d0 100644 --- a/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/AssociationSelect.tsx @@ -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) && ( - { - return s['x-component'] === 'Action'; - }} - /> + {/* 快捷添加按钮添加的添加的是一个普通的 form 区块(非关系区块),不应该与任何字段有关联,所以在这里把字段相关的上下文给清除掉 */} + + { + return s['x-component'] === 'Action'; + }} + /> + )} diff --git a/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx b/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx index 12a45d9ab..73155248b 100644 --- a/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx @@ -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( {isAllowAddNew && ( - { - return s['x-component'] === 'Action'; - }} - /> + {/* 快捷添加按钮添加的添加的是一个普通的 form 区块(非关系区块),不应该与任何字段有关联,所以在这里把字段相关的上下文给清除掉 */} + + { + return s['x-component'] === 'Action'; + }} + /> + )}