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); return useContext(NoticeManagerContext);
}; };
export const useNoticeSub = (name: string, handler: () => {}) => { export const useNoticeSub = (name: string, handler: () => void) => {
const { manager } = useNoticeManager(); const { manager } = useNoticeManager();
useEffect(() => { useEffect(() => {
manager.emitter.on(name, handler); manager.emitter.on(name, handler);

View File

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

View File

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

View File

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

View File

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