From f24972c01dd8cce040b6455b0ad3570164c92363 Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Wed, 11 Sep 2024 17:21:13 +0800 Subject: [PATCH] feat: do not update x-action-context when doNotUpdateContext is true (#5253) --- .../antd/page/pagePopupUtils.tsx | 8 ++++---- ...ePopupContextInActionOrAssociationField.ts | 19 ++++++++++++------- .../src/client/WorkflowTodo.tsx | 1 + 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/page/pagePopupUtils.tsx b/packages/core/client/src/schema-component/antd/page/pagePopupUtils.tsx index 7303e3e9a0..3c6d588ff6 100644 --- a/packages/core/client/src/schema-component/antd/page/pagePopupUtils.tsx +++ b/packages/core/client/src/schema-component/antd/page/pagePopupUtils.tsx @@ -190,7 +190,7 @@ export const usePopupUtils = ( [association, cm, collection, dataSourceKey, parentRecord?.data, association], ); - const getPopupContext = useCallback(() => { + const getNewPopupContext = useCallback(() => { const context = { dataSource: dataSourceKey, collection: association ? undefined : collection.name, @@ -247,7 +247,7 @@ export const usePopupUtils = ( sourceId, }); - updatePopupContext(getPopupContext(), customActionSchema); + updatePopupContext(getNewPopupContext(), customActionSchema); navigate(withSearchParams(`${url}${pathname}`)); }, @@ -265,7 +265,7 @@ export const usePopupUtils = ( location, isPopupVisibleControlledByURL, getSourceId, - getPopupContext, + getNewPopupContext, ], ); @@ -344,7 +344,7 @@ export const usePopupUtils = ( * @deprecated * TODO: remove this */ - getPopupContext, + getPopupContext: getNewPopupContext, }; }; diff --git a/packages/core/client/src/schema-component/antd/page/usePopupContextInActionOrAssociationField.ts b/packages/core/client/src/schema-component/antd/page/usePopupContextInActionOrAssociationField.ts index 7ab2090301..317dbf037c 100644 --- a/packages/core/client/src/schema-component/antd/page/usePopupContextInActionOrAssociationField.ts +++ b/packages/core/client/src/schema-component/antd/page/usePopupContextInActionOrAssociationField.ts @@ -16,6 +16,10 @@ export interface PopupContext { dataSource: string; collection?: string; association?: string; + /** + * if true, the context will never be updated + */ + doNotUpdateContext?: boolean; } export const CONTEXT_SCHEMA_KEY = 'x-action-context'; @@ -29,20 +33,21 @@ export const usePopupContextInActionOrAssociationField = () => { const { dn } = useDesignable(); const updatePopupContext = useCallback( - (context: PopupContext, customSchema?: ISchema) => { - customSchema = customSchema || fieldSchema; - context = _.omitBy(context, _.isNil) as PopupContext; + (newContext: PopupContext, customSchema?: ISchema) => { + const schema = customSchema || fieldSchema; + const oldContext = getPopupContextFromActionOrAssociationFieldSchema(schema); + newContext = _.omitBy(newContext, _.isNil) as PopupContext; - if (_.isEqual(context, getPopupContextFromActionOrAssociationFieldSchema(customSchema))) { + if (_.isEqual(newContext, oldContext) || oldContext?.doNotUpdateContext) { return; } - customSchema[CONTEXT_SCHEMA_KEY] = context; + schema[CONTEXT_SCHEMA_KEY] = newContext; return dn.emit('initializeActionContext', { schema: { - 'x-uid': customSchema['x-uid'], - [CONTEXT_SCHEMA_KEY]: context, + 'x-uid': schema['x-uid'], + [CONTEXT_SCHEMA_KEY]: newContext, }, }); }, diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowTodo.tsx b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowTodo.tsx index 22ba76c1f0..816a62476c 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowTodo.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowTodo.tsx @@ -406,6 +406,7 @@ export function getWorkflowTodoViewActionSchema({ defaultOpenMode, collectionNam 'x-action-context': { dataSource: 'main', collection: collectionName, + doNotUpdateContext: true, }, properties: { drawer: {