@nocobase/plugin-workflow-delay 0.17.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/DelayInstruction.d.ts +38 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +4 -0
- package/dist/externalVersion.js +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +9 -0
- package/dist/locale/es-ES.json +8 -0
- package/dist/locale/fr-FR.json +8 -0
- package/dist/locale/index.d.ts +3 -0
- package/dist/locale/index.js +39 -0
- package/dist/locale/pt-BR.json +8 -0
- package/dist/locale/zh-CN.json +9 -0
- package/dist/server/DelayInstruction.d.ts +13 -0
- package/dist/server/DelayInstruction.js +105 -0
- package/dist/server/Plugin.d.ts +6 -0
- package/dist/server/Plugin.js +42 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/package.json +24 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/DelayInstruction.tsx +87 -0
- package/src/client/index.ts +19 -0
- package/src/index.ts +2 -0
- package/src/locale/en-US.json +9 -0
- package/src/locale/es-ES.json +8 -0
- package/src/locale/fr-FR.json +8 -0
- package/src/locale/index.ts +12 -0
- package/src/locale/pt-BR.json +8 -0
- package/src/locale/zh-CN.json +9 -0
- package/src/server/DelayInstruction.ts +109 -0
- package/src/server/Plugin.ts +14 -0
- package/src/server/__tests__/instruction.test.ts +190 -0
- package/src/server/index.ts +1 -0
package/client.d.ts
ADDED
package/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/client/index.js');
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Instruction } from '@nocobase/plugin-workflow/client';
|
|
3
|
+
declare function Duration({ value, onChange }: {
|
|
4
|
+
value?: number;
|
|
5
|
+
onChange: any;
|
|
6
|
+
}): React.JSX.Element;
|
|
7
|
+
export default class extends Instruction {
|
|
8
|
+
title: string;
|
|
9
|
+
type: string;
|
|
10
|
+
group: string;
|
|
11
|
+
description: string;
|
|
12
|
+
fieldset: {
|
|
13
|
+
duration: {
|
|
14
|
+
type: string;
|
|
15
|
+
title: string;
|
|
16
|
+
'x-decorator': string;
|
|
17
|
+
'x-component': string;
|
|
18
|
+
default: number;
|
|
19
|
+
required: boolean;
|
|
20
|
+
};
|
|
21
|
+
endStatus: {
|
|
22
|
+
type: string;
|
|
23
|
+
title: string;
|
|
24
|
+
'x-decorator': string;
|
|
25
|
+
'x-component': string;
|
|
26
|
+
enum: {
|
|
27
|
+
label: string;
|
|
28
|
+
value: number;
|
|
29
|
+
}[];
|
|
30
|
+
required: boolean;
|
|
31
|
+
default: number;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
components: {
|
|
35
|
+
Duration: typeof Duration;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
(function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("antd"),require("@nocobase/plugin-workflow/client"),require("react-i18next")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","antd","@nocobase/plugin-workflow/client","react-i18next"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e["@nocobase/plugin-workflow-delay"]={},e["@nocobase/client"],e.jsxRuntime,e.antd,e["@nocobase/plugin-workflow"]))})(this,function(e,t,n,p,s){"use strict";var v=Object.defineProperty;var S=(e,t,n)=>t in e?v(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var r=(e,t,n)=>(S(e,typeof t!="symbol"?t+"":t,n),n);var w=(e,t,n)=>new Promise((p,s)=>{var a=o=>{try{c(n.next(o))}catch(d){s(d)}},f=o=>{try{c(n.throw(o))}catch(d){s(d)}},c=o=>o.done?p(o.value):Promise.resolve(o.value).then(a,f);c((n=n.apply(e,t)).next())});const a="workflow-delay",f=[{value:1e3,label:`{{t('Seconds', { ns: "workflow" })}}`},{value:6e4,label:`{{t('Minutes', { ns: "workflow" })}}`},{value:36e5,label:`{{t('Hours', { ns: "workflow" })}}`},{value:864e5,label:`{{t('Days', { ns: "workflow" })}}`},{value:6048e5,label:`{{t('Weeks', { ns: "workflow" })}}`}];function c(u){return f.slice().reverse().find(l=>!(u%l.value))}function o({value:u=6e4,onChange:l}){const m=t.useCompile(),b=c(u),y=Math.round(u/b.value);return n.jsxs("fieldset",{className:t.css`
|
|
2
|
+
display: flex;
|
|
3
|
+
gap: 0.5em;
|
|
4
|
+
`,children:[n.jsx(p.InputNumber,{min:1,value:y,onChange:i=>l(Math.round(i*b.value)),className:"auto-width"}),n.jsx(p.Select,{role:"button","data-testid":"select-time-unit",popupMatchSelectWidth:!1,value:b.value,onChange:i=>l(Math.round(y*i)),className:"auto-width",options:f.map(i=>({value:i.value,label:m(i.label)}))})]})}class d extends s.Instruction{constructor(){super(...arguments);r(this,"title",`{{t("Delay", { ns: "${a}" })}}`);r(this,"type","delay");r(this,"group","control");r(this,"description",`{{t("Delay a period of time and then continue or exit the process. Can be used to set wait or timeout times in parallel branches.", { ns: "${a}" })}}`);r(this,"fieldset",{duration:{type:"number",title:`{{t("Duration", { ns: "${a}" })}}`,"x-decorator":"FormItem","x-component":"Duration",default:6e4,required:!0},endStatus:{type:"number",title:`{{t("End Status", { ns: "${a}" })}}`,"x-decorator":"FormItem","x-component":"Radio.Group",enum:[{label:`{{t("Succeed and continue", { ns: "${a}" })}}`,value:s.JOB_STATUS.RESOLVED},{label:`{{t("Fail and exit", { ns: "${a}" })}}`,value:s.JOB_STATUS.FAILED}],required:!0,default:s.JOB_STATUS.RESOLVED}});r(this,"components",{Duration:o})}}class x extends t.Plugin{afterAdd(){return w(this,null,function*(){})}beforeLoad(){return w(this,null,function*(){})}load(){return w(this,null,function*(){const l=this.app.pm.get("workflow"),m=new d;l.instructions.register(m.type,m)})}}e.default=x,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
default: () => import_server.default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(src_exports);
|
|
34
|
+
__reExport(src_exports, require("./server"), module.exports);
|
|
35
|
+
var import_server = __toESM(require("./server"));
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
...require("./server")
|
|
39
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Delay": "Delay",
|
|
3
|
+
"Delay a period of time and then continue or exit the process. Can be used to set wait or timeout times in parallel branches.": "Delay a period of time and then continue or exit the process. Can be used to set wait or timeout times in parallel branches.",
|
|
4
|
+
"Duration": "Duration",
|
|
5
|
+
"End Status": "End Status",
|
|
6
|
+
"Select status": "Select status",
|
|
7
|
+
"Succeed and continue": "Succeed and continue",
|
|
8
|
+
"Fail and exit": "Fail and exit"
|
|
9
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var locale_exports = {};
|
|
19
|
+
__export(locale_exports, {
|
|
20
|
+
NAMESPACE: () => NAMESPACE,
|
|
21
|
+
useLang: () => useLang,
|
|
22
|
+
usePluginTranslation: () => usePluginTranslation
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(locale_exports);
|
|
25
|
+
var import_react_i18next = require("react-i18next");
|
|
26
|
+
const NAMESPACE = "workflow-delay";
|
|
27
|
+
function useLang(key, options = {}) {
|
|
28
|
+
const { t } = usePluginTranslation(options);
|
|
29
|
+
return t(key);
|
|
30
|
+
}
|
|
31
|
+
function usePluginTranslation(options) {
|
|
32
|
+
return (0, import_react_i18next.useTranslation)(NAMESPACE, options);
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
NAMESPACE,
|
|
37
|
+
useLang,
|
|
38
|
+
usePluginTranslation
|
|
39
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Delay": "延时",
|
|
3
|
+
"Delay a period of time and then continue or exit the process. Can be used to set wait or timeout times in parallel branches.": "延时一段时间,然后继续或退出流程。可以用于并行分支中等待其他分支或设置超时时间。",
|
|
4
|
+
"Duration": "时长",
|
|
5
|
+
"End Status": "到时状态",
|
|
6
|
+
"Select status": "选择状态",
|
|
7
|
+
"Succeed and continue": "通过并继续",
|
|
8
|
+
"Fail and exit": "失败并退出"
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import WorkflowPlugin, { Processor, Instruction } from '@nocobase/plugin-workflow';
|
|
3
|
+
export default class extends Instruction {
|
|
4
|
+
plugin: WorkflowPlugin;
|
|
5
|
+
timers: Map<number, NodeJS.Timeout>;
|
|
6
|
+
constructor(plugin: WorkflowPlugin);
|
|
7
|
+
load: () => Promise<void>;
|
|
8
|
+
unload: () => void;
|
|
9
|
+
schedule(job: any): void;
|
|
10
|
+
trigger(job: any): Promise<void>;
|
|
11
|
+
run(node: any, prevJob: any, processor: Processor): Promise<any>;
|
|
12
|
+
resume(node: any, prevJob: any, processor: Processor): Promise<any>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var DelayInstruction_exports = {};
|
|
19
|
+
__export(DelayInstruction_exports, {
|
|
20
|
+
default: () => DelayInstruction_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(DelayInstruction_exports);
|
|
23
|
+
var import_plugin_workflow = require("@nocobase/plugin-workflow");
|
|
24
|
+
class DelayInstruction_default extends import_plugin_workflow.Instruction {
|
|
25
|
+
constructor(plugin) {
|
|
26
|
+
super(plugin);
|
|
27
|
+
this.plugin = plugin;
|
|
28
|
+
plugin.app.on("afterStart", this.load);
|
|
29
|
+
plugin.app.on("beforeStop", this.unload);
|
|
30
|
+
}
|
|
31
|
+
timers = /* @__PURE__ */ new Map();
|
|
32
|
+
load = async () => {
|
|
33
|
+
const { model } = this.plugin.db.getCollection("jobs");
|
|
34
|
+
const jobs = await model.findAll({
|
|
35
|
+
where: {
|
|
36
|
+
status: import_plugin_workflow.JOB_STATUS.PENDING
|
|
37
|
+
},
|
|
38
|
+
include: [
|
|
39
|
+
{
|
|
40
|
+
association: "execution",
|
|
41
|
+
attributes: [],
|
|
42
|
+
where: {
|
|
43
|
+
status: import_plugin_workflow.EXECUTION_STATUS.STARTED
|
|
44
|
+
},
|
|
45
|
+
required: true
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
association: "node",
|
|
49
|
+
attributes: ["config"],
|
|
50
|
+
where: {
|
|
51
|
+
type: "delay"
|
|
52
|
+
},
|
|
53
|
+
required: true
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
jobs.forEach((job) => {
|
|
58
|
+
this.schedule(job);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
unload = () => {
|
|
62
|
+
for (const timer of this.timers.values()) {
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
}
|
|
65
|
+
this.timers = /* @__PURE__ */ new Map();
|
|
66
|
+
};
|
|
67
|
+
schedule(job) {
|
|
68
|
+
const now = /* @__PURE__ */ new Date();
|
|
69
|
+
const createdAt = Date.parse(job.createdAt);
|
|
70
|
+
const delay = createdAt + job.node.config.duration - now.getTime();
|
|
71
|
+
if (delay > 0) {
|
|
72
|
+
const trigger = this.trigger.bind(this, job);
|
|
73
|
+
this.timers.set(job.id, setTimeout(trigger, delay));
|
|
74
|
+
} else {
|
|
75
|
+
this.trigger(job);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async trigger(job) {
|
|
79
|
+
if (!job.execution) {
|
|
80
|
+
job.execution = await job.getExecution();
|
|
81
|
+
}
|
|
82
|
+
if (job.execution.status === import_plugin_workflow.EXECUTION_STATUS.STARTED) {
|
|
83
|
+
this.plugin.resume(job);
|
|
84
|
+
}
|
|
85
|
+
if (this.timers.get(job.id)) {
|
|
86
|
+
this.timers.delete(job.id);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async run(node, prevJob, processor) {
|
|
90
|
+
const job = await processor.saveJob({
|
|
91
|
+
status: import_plugin_workflow.JOB_STATUS.PENDING,
|
|
92
|
+
result: null,
|
|
93
|
+
nodeId: node.id,
|
|
94
|
+
upstreamId: (prevJob == null ? void 0 : prevJob.id) ?? null
|
|
95
|
+
});
|
|
96
|
+
job.node = node;
|
|
97
|
+
this.schedule(job);
|
|
98
|
+
return processor.exit();
|
|
99
|
+
}
|
|
100
|
+
async resume(node, prevJob, processor) {
|
|
101
|
+
const { endStatus } = node.config;
|
|
102
|
+
prevJob.set("status", endStatus);
|
|
103
|
+
return prevJob;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var Plugin_exports = {};
|
|
29
|
+
__export(Plugin_exports, {
|
|
30
|
+
default: () => Plugin_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(Plugin_exports);
|
|
33
|
+
var import_server = require("@nocobase/server");
|
|
34
|
+
var import_DelayInstruction = __toESM(require("./DelayInstruction"));
|
|
35
|
+
class Plugin_default extends import_server.Plugin {
|
|
36
|
+
workflow;
|
|
37
|
+
async load() {
|
|
38
|
+
const workflowPlugin = this.app.getPlugin("workflow");
|
|
39
|
+
this.workflow = workflowPlugin;
|
|
40
|
+
workflowPlugin.instructions.register("delay", new import_DelayInstruction.default(workflowPlugin));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Plugin';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
default: () => import_Plugin.default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_Plugin = __toESM(require("./Plugin"));
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-workflow-delay",
|
|
3
|
+
"displayName": "Workflow: Delay node",
|
|
4
|
+
"displayName.zh-CN": "工作流:延时节点",
|
|
5
|
+
"description": "Could be used in workflow parallel branch for waiting other branches.",
|
|
6
|
+
"description.zh-CN": "可用于工作流并行分支中等待其他分支执行完成。",
|
|
7
|
+
"version": "0.17.0-alpha.4",
|
|
8
|
+
"license": "AGPL-3.0",
|
|
9
|
+
"main": "./dist/server/index.js",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"antd": "5.x",
|
|
12
|
+
"react": "18.x",
|
|
13
|
+
"react-i18next": "^11.15.1"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"@nocobase/client": "0.x",
|
|
17
|
+
"@nocobase/database": "0.x",
|
|
18
|
+
"@nocobase/plugin-workflow": ">=0.17.0-alpha.3",
|
|
19
|
+
"@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3",
|
|
20
|
+
"@nocobase/server": "0.x",
|
|
21
|
+
"@nocobase/test": "0.x"
|
|
22
|
+
},
|
|
23
|
+
"gitHead": "663b03a3799a70ba1a2bc6a0d686e679331a50ad"
|
|
24
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { InputNumber, Select } from 'antd';
|
|
3
|
+
import { css, useCompile } from '@nocobase/client';
|
|
4
|
+
import { Instruction, JOB_STATUS } from '@nocobase/plugin-workflow/client';
|
|
5
|
+
|
|
6
|
+
import { NAMESPACE } from '../locale';
|
|
7
|
+
|
|
8
|
+
const UnitOptions = [
|
|
9
|
+
{ value: 1_000, label: `{{t('Seconds', { ns: "workflow" })}}` },
|
|
10
|
+
{ value: 60_000, label: `{{t('Minutes', { ns: "workflow" })}}` },
|
|
11
|
+
{ value: 3600_000, label: `{{t('Hours', { ns: "workflow" })}}` },
|
|
12
|
+
{ value: 86400_000, label: `{{t('Days', { ns: "workflow" })}}` },
|
|
13
|
+
{ value: 604800_000, label: `{{t('Weeks', { ns: "workflow" })}}` },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
function getNumberOption(v) {
|
|
17
|
+
return UnitOptions.slice()
|
|
18
|
+
.reverse()
|
|
19
|
+
.find((item) => !(v % item.value));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function Duration({ value = 60000, onChange }) {
|
|
23
|
+
const compile = useCompile();
|
|
24
|
+
const option = getNumberOption(value);
|
|
25
|
+
const quantity = Math.round(value / option.value);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<fieldset
|
|
29
|
+
className={css`
|
|
30
|
+
display: flex;
|
|
31
|
+
gap: 0.5em;
|
|
32
|
+
`}
|
|
33
|
+
>
|
|
34
|
+
<InputNumber
|
|
35
|
+
min={1}
|
|
36
|
+
value={quantity}
|
|
37
|
+
onChange={(v) => onChange(Math.round(v * option.value))}
|
|
38
|
+
className="auto-width"
|
|
39
|
+
/>
|
|
40
|
+
<Select
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
role="button"
|
|
43
|
+
data-testid="select-time-unit"
|
|
44
|
+
popupMatchSelectWidth={false}
|
|
45
|
+
value={option.value}
|
|
46
|
+
onChange={(unit) => onChange(Math.round(quantity * unit))}
|
|
47
|
+
className="auto-width"
|
|
48
|
+
options={UnitOptions.map((item) => ({
|
|
49
|
+
value: item.value,
|
|
50
|
+
label: compile(item.label),
|
|
51
|
+
}))}
|
|
52
|
+
/>
|
|
53
|
+
</fieldset>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default class extends Instruction {
|
|
58
|
+
title = `{{t("Delay", { ns: "${NAMESPACE}" })}}`;
|
|
59
|
+
type = 'delay';
|
|
60
|
+
group = 'control';
|
|
61
|
+
description = `{{t("Delay a period of time and then continue or exit the process. Can be used to set wait or timeout times in parallel branches.", { ns: "${NAMESPACE}" })}}`;
|
|
62
|
+
fieldset = {
|
|
63
|
+
duration: {
|
|
64
|
+
type: 'number',
|
|
65
|
+
title: `{{t("Duration", { ns: "${NAMESPACE}" })}}`,
|
|
66
|
+
'x-decorator': 'FormItem',
|
|
67
|
+
'x-component': 'Duration',
|
|
68
|
+
default: 60000,
|
|
69
|
+
required: true,
|
|
70
|
+
},
|
|
71
|
+
endStatus: {
|
|
72
|
+
type: 'number',
|
|
73
|
+
title: `{{t("End Status", { ns: "${NAMESPACE}" })}}`,
|
|
74
|
+
'x-decorator': 'FormItem',
|
|
75
|
+
'x-component': 'Radio.Group',
|
|
76
|
+
enum: [
|
|
77
|
+
{ label: `{{t("Succeed and continue", { ns: "${NAMESPACE}" })}}`, value: JOB_STATUS.RESOLVED },
|
|
78
|
+
{ label: `{{t("Fail and exit", { ns: "${NAMESPACE}" })}}`, value: JOB_STATUS.FAILED },
|
|
79
|
+
],
|
|
80
|
+
required: true,
|
|
81
|
+
default: JOB_STATUS.RESOLVED,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
components = {
|
|
85
|
+
Duration,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Plugin } from '@nocobase/client';
|
|
2
|
+
import WorkflowPlugin from '@nocobase/plugin-workflow/client';
|
|
3
|
+
|
|
4
|
+
import DelayInstruction from './DelayInstruction';
|
|
5
|
+
|
|
6
|
+
export default class extends Plugin {
|
|
7
|
+
async afterAdd() {
|
|
8
|
+
// await this.app.pm.add()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async beforeLoad() {}
|
|
12
|
+
|
|
13
|
+
// You can get and modify the app instance here
|
|
14
|
+
async load() {
|
|
15
|
+
const workflow = this.app.pm.get('workflow') as WorkflowPlugin;
|
|
16
|
+
const delayInstruction = new DelayInstruction();
|
|
17
|
+
workflow.instructions.register(delayInstruction.type, delayInstruction);
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Delay": "Delay",
|
|
3
|
+
"Delay a period of time and then continue or exit the process. Can be used to set wait or timeout times in parallel branches.": "Delay a period of time and then continue or exit the process. Can be used to set wait or timeout times in parallel branches.",
|
|
4
|
+
"Duration": "Duration",
|
|
5
|
+
"End Status": "End Status",
|
|
6
|
+
"Select status": "Select status",
|
|
7
|
+
"Succeed and continue": "Succeed and continue",
|
|
8
|
+
"Fail and exit": "Fail and exit"
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
|
|
3
|
+
export const NAMESPACE = 'workflow-delay';
|
|
4
|
+
|
|
5
|
+
export function useLang(key: string, options = {}) {
|
|
6
|
+
const { t } = usePluginTranslation(options);
|
|
7
|
+
return t(key);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function usePluginTranslation(options) {
|
|
11
|
+
return useTranslation(NAMESPACE, options);
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Delay": "延时",
|
|
3
|
+
"Delay a period of time and then continue or exit the process. Can be used to set wait or timeout times in parallel branches.": "延时一段时间,然后继续或退出流程。可以用于并行分支中等待其他分支或设置超时时间。",
|
|
4
|
+
"Duration": "时长",
|
|
5
|
+
"End Status": "到时状态",
|
|
6
|
+
"Select status": "选择状态",
|
|
7
|
+
"Succeed and continue": "通过并继续",
|
|
8
|
+
"Fail and exit": "失败并退出"
|
|
9
|
+
}
|