diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/collection.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/collection.tsx index 9fa48b9a30..a08881e5b8 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/collection.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/collection.tsx @@ -160,10 +160,10 @@ export default class extends Trigger { 'x-component-props': {}, 'x-reactions': [ { - dependencies: ['collection'], + dependencies: ['collection', 'mode'], fulfill: { state: { - visible: '{{!!$deps[0]}}', + visible: `{{!!$deps[0] && !($deps[1] & ${COLLECTION_TRIGGER_MODE.DELETED})}}`, }, }, }, diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts index f793519dab..992e0caf8c 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts @@ -434,6 +434,29 @@ describe('workflow > triggers > collection', () => { expect(executions.length).toBe(1); expect(executions[0].context.data.title).toBe('t1'); }); + + it('condition will not effect destroy', async () => { + const workflow = await WorkflowModel.create({ + enabled: true, + type: 'collection', + config: { + mode: 4, + collection: 'posts', + condition: { + title: 't1', + }, + }, + }); + + const post1 = await PostRepo.create({ values: { title: 't1' } }); + await PostRepo.destroy({ filterByTk: post1.id }); + + await sleep(500); + + const executions = await workflow.getExecutions(); + expect(executions.length).toBe(1); + expect(executions[0].context.data.title).toBe('t1'); + }); }); describe('config.appends', () => { diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/CollectionTrigger.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/CollectionTrigger.ts index b64a426e13..0d1f08c4ad 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/CollectionTrigger.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/CollectionTrigger.ts @@ -68,7 +68,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M } // NOTE: if no configured condition, or not match, do not trigger - if (isValidFilter(condition)) { + if (isValidFilter(condition) && !(mode & MODE_BITMAP.DESTROY)) { // TODO: change to map filter format to calculation format // const calculation = toCalculation(condition); const count = await repository.count({