From 1c1a11b3d09d86679049eb8675e0504edb8a7d05 Mon Sep 17 00:00:00 2001 From: sealday Date: Thu, 6 Jun 2024 16:17:04 +0800 Subject: [PATCH] feat: loop notify (#1138) Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1138 --- .../client/src/application/NoticesManager.tsx | 2 +- .../features/api-regular/usage/hooks.tsx | 19 ++++++++++++++++--- .../api-regular/APIRegular.trigger.ts | 4 ++++ .../server/features/loop/LoopInstruction.ts | 8 +++++++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/core/client/src/application/NoticesManager.tsx b/packages/core/client/src/application/NoticesManager.tsx index 76a5092d9..74833195d 100644 --- a/packages/core/client/src/application/NoticesManager.tsx +++ b/packages/core/client/src/application/NoticesManager.tsx @@ -38,7 +38,7 @@ export const useNoticeManager = () => { return useContext(NoticeManagerContext); }; -export const useNoticeSub = (name: string, handler: () => void) => { +export const useNoticeSub = (name: string, handler: (...args: any) => void) => { const { manager } = useNoticeManager(); useEffect(() => { manager.emitter.on(name, handler); diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/api-regular/usage/hooks.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/features/api-regular/usage/hooks.tsx index 46741b263..d43626d9e 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/api-regular/usage/hooks.tsx +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/api-regular/usage/hooks.tsx @@ -15,6 +15,7 @@ import { import { SchemaExpressionScopeContext, useField, useFieldSchema } from '@tachybase/schema'; import { App } from 'antd'; +import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import { lang } from '../../../locale'; @@ -25,11 +26,12 @@ export const usePropsAPIRegular = () => { const expressionScope = useContext(SchemaExpressionScopeContext); const tableBlockContext = useTableBlockContext(); const { rowKey } = tableBlockContext; + const { t } = useTranslation(); const navigate = useNavigate(); const compile = useCompile(); const actionField: any = useField(); - const { modal } = App.useApp(); + const { modal, notification } = App.useApp(); const variables = useVariables(); const record = useRecord(); const { name, getField } = useCollection_deprecated(); @@ -43,8 +45,19 @@ export const usePropsAPIRegular = () => { manual: true, }, ); - useNoticeSub('workflow:regular', () => { - service.refresh(); + useNoticeSub('workflow:regular', (event) => { + if (event.msg === 'start') { + notification.info({ key: 'workflow:regular', message: t('working'), description: t('starting') }); + } else if (event.msg === 'progress') { + notification.info({ + key: 'workflow:regular', + message: t('working'), + description: t('process') + `${event.current} / ${event.total}`, + }); + } else if (event.msg === 'done') { + notification.info({ key: 'workflow:regular', message: t('working'), description: t('done') }); + service.refresh(); + } }); return { diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/api-regular/APIRegular.trigger.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/api-regular/APIRegular.trigger.ts index 5e59abcb8..23105f459 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/api-regular/APIRegular.trigger.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/api-regular/APIRegular.trigger.ts @@ -149,6 +149,10 @@ export class APIRegularTrigger extends Trigger { for (const event of asyncGroup) { this.workflow.trigger(event[0], event[1]); } + + this.workflow.noticeManager.notify('workflow:regular', { + msg: 'start', + }); } on(workflow: WorkflowModel): void {} diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/loop/LoopInstruction.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/loop/LoopInstruction.ts index bfe779a9e..11a69b7b3 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/loop/LoopInstruction.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/loop/LoopInstruction.ts @@ -1,4 +1,4 @@ -import { Processor, Instruction, JOB_STATUS, FlowNodeModel, JobModel } from '../..'; +import { FlowNodeModel, Instruction, JOB_STATUS, JobModel, Processor } from '../..'; function getTargetLength(target) { let length = 0; @@ -93,6 +93,12 @@ export default class extends Instruction { length, }; + this.workflow.noticeManager.notify('workflow:regular', { + msg: 'progress', + current: index, + total: length, + }); + return result; } }