feat: notice hard coded (#1136)

Reviewed-on: daoyoucloud/tachybase#1136
This commit is contained in:
sealday 2024-06-06 14:25:16 +08:00
parent 8b47ac3f7c
commit 8cb3893caa
5 changed files with 39 additions and 38 deletions

View File

@ -38,7 +38,7 @@ export const useNoticeManager = () => {
return useContext(NoticeManagerContext);
};
export const useNoticeSub = (name: string, handler: () => {}) => {
export const useNoticeSub = (name: string, handler: () => void) => {
const { manager } = useNoticeManager();
useEffect(() => {
manager.emitter.on(name, handler);

View File

@ -32,7 +32,6 @@ export class NoticeInstruction extends Instruction {
notifiedPerson: {
type: 'array',
title: tval('The Notified Person'),
required: true,
'x-decorator': 'FormItem',
'x-component': 'ArrayItems',
'x-component-props': {

View File

@ -1,4 +1,3 @@
// import { PlusOutlined } from '@ant-design/icons';
import React, { useCallback, useState } from 'react';
import { ArrayItems } from '@tachybase/components';
import { useWorkflowExecuted } from '@tachybase/plugin-workflow/client';
@ -29,13 +28,7 @@ export const AdditionNotifiedPerson = () => {
onOpenChange={setIsOpen}
content={<PopoverContent onSlecet={onSlecet} onQuery={onQuery} />}
>
<Button
className="ant-formily-array-base-addition"
// icon={<PlusOutlined />}
type="dashed"
block={true}
disabled={isWorkflowExecuted}
>
<Button className="ant-formily-array-base-addition" type="dashed" block={true} disabled={isWorkflowExecuted}>
{t('Add Notified Person')}
</Button>
</Popover>

View File

@ -15,37 +15,42 @@ class NoticeInstruction extends Instruction {
upstreamId: prevJob?.id ?? null,
});
const notifiedPerson = await parsePerson(node, processor);
const { db } = processor.options.plugin;
// TODO-A: 改成取上一个节点的数据集, 或者当前执行流数据源的数据集, 目前是对审批事件做了特化处理; 需要理解下其他类型的触发事件, 怎么拿数据
const ApprovalRepo = db.getRepository('approvals');
const approval = await ApprovalRepo.findOne({
filter: {
'executions.id': processor.execution.id,
},
fields: ['id', 'status', 'data', 'summary', 'collectionName'],
appends: ['approvalExecutions'],
except: ['data'],
});
if (notifiedPerson) {
const { db } = processor.options.plugin;
// TODO-A: 改成取上一个节点的数据集, 或者当前执行流数据源的数据集, 目前是对审批事件做了特化处理; 需要理解下其他类型的触发事件, 怎么拿数据
const ApprovalRepo = db.getRepository('approvals');
const approval = await ApprovalRepo.findOne({
filter: {
'executions.id': processor.execution.id,
},
fields: ['id', 'status', 'data', 'summary', 'collectionName'],
appends: ['approvalExecutions'],
except: ['data'],
});
const NoticeModel = db.getModel(COLLECTION_NOTICE_NAME);
const NoticeModel = db.getModel(COLLECTION_NOTICE_NAME);
const notifiedPersonMapData = notifiedPerson.map((userId, index) => ({
userId,
jobId: job.id,
nodeId: node.id,
executionId: job.executionId,
workflowId: node.workflowId,
index,
status: node.config.order && index ? NOTICE_ACTION_STATUS.ASSIGNED : NOTICE_ACTION_STATUS.APPROVED,
snapshot: approval.data,
summary: approval.summary,
collectionName: approval.collectionName,
dataKey: approval.dataKey,
}));
const notifiedPersonMapData = notifiedPerson.map((userId, index) => ({
userId,
jobId: job.id,
nodeId: node.id,
executionId: job.executionId,
workflowId: node.workflowId,
index,
status: node.config.order && index ? NOTICE_ACTION_STATUS.ASSIGNED : NOTICE_ACTION_STATUS.APPROVED,
snapshot: approval.data,
summary: approval.summary,
collectionName: approval.collectionName,
dataKey: approval.dataKey,
}));
await NoticeModel.bulkCreate(notifiedPersonMapData, {
transaction: processor.transaction,
});
await NoticeModel.bulkCreate(notifiedPersonMapData, {
transaction: processor.transaction,
});
}
// notify
this.workflow.noticeManager.notify('workflow:regular', { msg: 'done' });
return job;
}

View File

@ -6,6 +6,7 @@ import {
useCollection_deprecated,
useCompile,
useLocalVariables,
useNoticeSub,
useRecord,
useRequest,
useTableBlockContext,
@ -42,6 +43,9 @@ export const usePropsAPIRegular = () => {
manual: true,
},
);
useNoticeSub('workflow:regular', () => {
service.refresh();
});
return {
async onClick() {