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 e13283d8a1..7e1db4f002 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 028a8f4e13..2482a057b3 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: {