@nocobase/plugin-workflow-manual 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/WorkflowTodo.d.ts +5 -0
- package/dist/client/WorkflowTodoBlockInitializer.d.ts +2 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +13 -0
- package/dist/client/instruction/AssigneesSelect.d.ts +6 -0
- package/dist/client/instruction/DetailsBlockProvider.d.ts +2 -0
- package/dist/client/instruction/FormBlockInitializer.d.ts +2 -0
- package/dist/client/instruction/FormBlockProvider.d.ts +2 -0
- package/dist/client/instruction/ModeConfig.d.ts +5 -0
- package/dist/client/instruction/SchemaConfig.d.ts +49 -0
- package/dist/client/instruction/forms/create.d.ts +3 -0
- package/dist/client/instruction/forms/custom.d.ts +5 -0
- package/dist/client/instruction/forms/update.d.ts +3 -0
- package/dist/client/instruction/index.d.ts +83 -0
- package/dist/client/instruction/utils.d.ts +1 -0
- package/dist/externalVersion.js +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +30 -0
- package/dist/locale/index.d.ts +3 -0
- package/dist/locale/index.js +39 -0
- package/dist/locale/zh-CN.json +30 -0
- package/dist/server/ManualInstruction.d.ts +28 -0
- package/dist/server/ManualInstruction.js +150 -0
- package/dist/server/Plugin.d.ts +6 -0
- package/dist/server/Plugin.js +73 -0
- package/dist/server/actions.d.ts +2 -0
- package/dist/server/actions.js +94 -0
- package/dist/server/collecions/jobs.d.ts +19 -0
- package/dist/server/collecions/jobs.js +39 -0
- package/dist/server/collecions/users.d.ts +15 -0
- package/dist/server/collecions/users.js +37 -0
- package/dist/server/collecions/users_jobs.d.ts +3 -0
- package/dist/server/collecions/users_jobs.js +70 -0
- package/dist/server/forms/create.d.ts +5 -0
- package/dist/server/forms/create.js +41 -0
- package/dist/server/forms/index.d.ts +6 -0
- package/dist/server/forms/index.js +38 -0
- package/dist/server/forms/update.d.ts +6 -0
- package/dist/server/forms/update.js +41 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/package.json +33 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/WorkflowTodo.tsx +618 -0
- package/src/client/WorkflowTodoBlockInitializer.tsx +30 -0
- package/src/client/index.ts +44 -0
- package/src/client/instruction/AssigneesSelect.tsx +39 -0
- package/src/client/instruction/DetailsBlockProvider.tsx +85 -0
- package/src/client/instruction/FormBlockInitializer.tsx +72 -0
- package/src/client/instruction/FormBlockProvider.tsx +84 -0
- package/src/client/instruction/ModeConfig.tsx +85 -0
- package/src/client/instruction/SchemaConfig.tsx +538 -0
- package/src/client/instruction/forms/create.tsx +112 -0
- package/src/client/instruction/forms/custom.tsx +403 -0
- package/src/client/instruction/forms/update.tsx +150 -0
- package/src/client/instruction/index.tsx +157 -0
- package/src/client/instruction/utils.ts +19 -0
- package/src/index.ts +2 -0
- package/src/locale/en-US.json +30 -0
- package/src/locale/index.ts +12 -0
- package/src/locale/zh-CN.json +30 -0
- package/src/server/ManualInstruction.ts +151 -0
- package/src/server/Plugin.ts +48 -0
- package/src/server/__tests__/collections/categories.ts +15 -0
- package/src/server/__tests__/collections/comments.ts +24 -0
- package/src/server/__tests__/collections/posts.ts +40 -0
- package/src/server/__tests__/collections/replies.ts +9 -0
- package/src/server/__tests__/collections/tags.ts +15 -0
- package/src/server/__tests__/instruction.test.ts +1154 -0
- package/src/server/actions.ts +100 -0
- package/src/server/collecions/jobs.ts +17 -0
- package/src/server/collecions/users.ts +15 -0
- package/src/server/collecions/users_jobs.ts +50 -0
- package/src/server/forms/create.ts +23 -0
- package/src/server/forms/index.ts +13 -0
- package/src/server/forms/update.ts +23 -0
- package/src/server/index.ts +1 -0
|
@@ -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,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-workflow-manual",
|
|
3
|
+
"displayName": "Workflow: Manual node",
|
|
4
|
+
"displayName.zh-CN": "工作流:人工处理节点",
|
|
5
|
+
"description": "Could be used for workflows which some of decisions are made by users.",
|
|
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
|
+
"@ant-design/icons": "5.x",
|
|
12
|
+
"@formily/antd-v5": "1.x",
|
|
13
|
+
"@formily/core": "2.x",
|
|
14
|
+
"@formily/react": "2.x",
|
|
15
|
+
"antd": "5.x",
|
|
16
|
+
"lodash": "4.17.21",
|
|
17
|
+
"react": "18.x",
|
|
18
|
+
"react-i18next": "^11.15.1",
|
|
19
|
+
"react-router-dom": "^6.11.2"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@nocobase/client": "0.x",
|
|
23
|
+
"@nocobase/database": "0.x",
|
|
24
|
+
"@nocobase/plugin-collection-manager": "0.x",
|
|
25
|
+
"@nocobase/plugin-users": "0.x",
|
|
26
|
+
"@nocobase/plugin-workflow": ">=0.17.0-alpha.3",
|
|
27
|
+
"@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3",
|
|
28
|
+
"@nocobase/server": "0.x",
|
|
29
|
+
"@nocobase/test": "0.x",
|
|
30
|
+
"@nocobase/utils": "0.x"
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "663b03a3799a70ba1a2bc6a0d686e679331a50ad"
|
|
33
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
2
|
+
import { observer, useField, useFieldSchema, useForm } from '@formily/react';
|
|
3
|
+
import { Space, Spin, Tag } from 'antd';
|
|
4
|
+
import dayjs from 'dayjs';
|
|
5
|
+
|
|
6
|
+
import { css, usePlugin } from '@nocobase/client';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
CollectionManagerProvider,
|
|
10
|
+
SchemaComponent,
|
|
11
|
+
SchemaComponentContext,
|
|
12
|
+
TableBlockProvider,
|
|
13
|
+
useAPIClient,
|
|
14
|
+
useActionContext,
|
|
15
|
+
useCollectionManager,
|
|
16
|
+
useCompile,
|
|
17
|
+
useCurrentUserContext,
|
|
18
|
+
useFormBlockContext,
|
|
19
|
+
useRecord,
|
|
20
|
+
useTableBlockContext,
|
|
21
|
+
} from '@nocobase/client';
|
|
22
|
+
import WorkflowPlugin, {
|
|
23
|
+
useAvailableUpstreams,
|
|
24
|
+
FlowContext,
|
|
25
|
+
useFlowContext,
|
|
26
|
+
JobStatusOptions,
|
|
27
|
+
JobStatusOptionsMap,
|
|
28
|
+
linkNodes,
|
|
29
|
+
} from '@nocobase/plugin-workflow/client';
|
|
30
|
+
|
|
31
|
+
import { DetailsBlockProvider } from './instruction/DetailsBlockProvider';
|
|
32
|
+
import { FormBlockProvider } from './instruction/FormBlockProvider';
|
|
33
|
+
import { ManualFormType, manualFormTypes } from './instruction/SchemaConfig';
|
|
34
|
+
import { NAMESPACE } from '../locale';
|
|
35
|
+
|
|
36
|
+
const nodeCollection = {
|
|
37
|
+
title: `{{t("Task", { ns: "${NAMESPACE}" })}}`,
|
|
38
|
+
name: 'flow_nodes',
|
|
39
|
+
fields: [
|
|
40
|
+
{
|
|
41
|
+
type: 'bigInt',
|
|
42
|
+
name: 'id',
|
|
43
|
+
interface: 'm2o',
|
|
44
|
+
uiSchema: {
|
|
45
|
+
type: 'number',
|
|
46
|
+
title: 'ID',
|
|
47
|
+
'x-component': 'RemoteSelect',
|
|
48
|
+
'x-component-props': {
|
|
49
|
+
fieldNames: {
|
|
50
|
+
label: 'title',
|
|
51
|
+
value: 'id',
|
|
52
|
+
},
|
|
53
|
+
service: {
|
|
54
|
+
resource: 'flow_nodes',
|
|
55
|
+
params: {
|
|
56
|
+
filter: {
|
|
57
|
+
type: 'manual',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'string',
|
|
66
|
+
name: 'title',
|
|
67
|
+
interface: 'input',
|
|
68
|
+
uiSchema: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
title: '{{t("Title")}}',
|
|
71
|
+
'x-component': 'Input',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const workflowCollection = {
|
|
78
|
+
title: `{{t("Workflow", { ns: "${NAMESPACE}" })}}`,
|
|
79
|
+
name: 'workflows',
|
|
80
|
+
fields: [
|
|
81
|
+
{
|
|
82
|
+
type: 'string',
|
|
83
|
+
name: 'title',
|
|
84
|
+
interface: 'input',
|
|
85
|
+
uiSchema: {
|
|
86
|
+
title: '{{t("Name")}}',
|
|
87
|
+
type: 'string',
|
|
88
|
+
'x-component': 'Input',
|
|
89
|
+
required: true,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const todoCollection = {
|
|
96
|
+
title: `{{t("Workflow todos", { ns: "${NAMESPACE}" })}}`,
|
|
97
|
+
name: 'users_jobs',
|
|
98
|
+
fields: [
|
|
99
|
+
{
|
|
100
|
+
type: 'belongsTo',
|
|
101
|
+
name: 'user',
|
|
102
|
+
target: 'users',
|
|
103
|
+
foreignKey: 'userId',
|
|
104
|
+
interface: 'm2o',
|
|
105
|
+
uiSchema: {
|
|
106
|
+
type: 'number',
|
|
107
|
+
title: '{{t("User")}}',
|
|
108
|
+
'x-component': 'RemoteSelect',
|
|
109
|
+
'x-component-props': {
|
|
110
|
+
fieldNames: {
|
|
111
|
+
label: 'nickname',
|
|
112
|
+
value: 'id',
|
|
113
|
+
},
|
|
114
|
+
service: {
|
|
115
|
+
resource: 'users',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
type: 'belongsTo',
|
|
122
|
+
name: 'node',
|
|
123
|
+
target: 'flow_nodes',
|
|
124
|
+
foreignKey: 'nodeId',
|
|
125
|
+
interface: 'm2o',
|
|
126
|
+
isAssociation: true,
|
|
127
|
+
uiSchema: {
|
|
128
|
+
type: 'number',
|
|
129
|
+
title: `{{t("Task", { ns: "${NAMESPACE}" })}}`,
|
|
130
|
+
'x-component': 'RemoteSelect',
|
|
131
|
+
'x-component-props': {
|
|
132
|
+
fieldNames: {
|
|
133
|
+
label: 'title',
|
|
134
|
+
value: 'id',
|
|
135
|
+
},
|
|
136
|
+
service: {
|
|
137
|
+
resource: 'flow_nodes',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
type: 'belongsTo',
|
|
144
|
+
name: 'workflow',
|
|
145
|
+
target: 'workflows',
|
|
146
|
+
foreignKey: 'workflowId',
|
|
147
|
+
interface: 'm2o',
|
|
148
|
+
uiSchema: {
|
|
149
|
+
type: 'number',
|
|
150
|
+
title: `{{t("Workflow", { ns: "${NAMESPACE}" })}}`,
|
|
151
|
+
'x-component': 'RemoteSelect',
|
|
152
|
+
'x-component-props': {
|
|
153
|
+
fieldNames: {
|
|
154
|
+
label: 'title',
|
|
155
|
+
value: 'id',
|
|
156
|
+
},
|
|
157
|
+
service: {
|
|
158
|
+
resource: 'workflows',
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
type: 'integer',
|
|
165
|
+
name: 'status',
|
|
166
|
+
interface: 'select',
|
|
167
|
+
uiSchema: {
|
|
168
|
+
type: 'number',
|
|
169
|
+
title: `{{t("Status", { ns: "${NAMESPACE}" })}}`,
|
|
170
|
+
'x-component': 'Select',
|
|
171
|
+
enum: JobStatusOptions,
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: 'createdAt',
|
|
176
|
+
type: 'date',
|
|
177
|
+
interface: 'createdAt',
|
|
178
|
+
uiSchema: {
|
|
179
|
+
type: 'datetime',
|
|
180
|
+
title: '{{t("Created at")}}',
|
|
181
|
+
'x-component': 'DatePicker',
|
|
182
|
+
'x-component-props': {
|
|
183
|
+
showTime: true,
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const NodeColumn = observer(
|
|
191
|
+
() => {
|
|
192
|
+
const field = useField<any>();
|
|
193
|
+
return field?.value?.title ?? `#${field.value?.id}`;
|
|
194
|
+
},
|
|
195
|
+
{ displayName: 'NodeColumn' },
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const WorkflowColumn = observer(
|
|
199
|
+
() => {
|
|
200
|
+
const field = useField<any>();
|
|
201
|
+
return field?.value?.title ?? `#${field.value?.id}`;
|
|
202
|
+
},
|
|
203
|
+
{ displayName: 'WorkflowColumn' },
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const UserColumn = observer(
|
|
207
|
+
() => {
|
|
208
|
+
const field = useField<any>();
|
|
209
|
+
return field?.value?.nickname ?? field.value?.id;
|
|
210
|
+
},
|
|
211
|
+
{ displayName: 'UserColumn' },
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
export const WorkflowTodo: React.FC & { Drawer: React.FC; Decorator: React.FC } = () => {
|
|
215
|
+
return (
|
|
216
|
+
<SchemaComponent
|
|
217
|
+
components={{
|
|
218
|
+
NodeColumn,
|
|
219
|
+
WorkflowColumn,
|
|
220
|
+
UserColumn,
|
|
221
|
+
}}
|
|
222
|
+
schema={{
|
|
223
|
+
type: 'void',
|
|
224
|
+
properties: {
|
|
225
|
+
actions: {
|
|
226
|
+
type: 'void',
|
|
227
|
+
'x-component': 'ActionBar',
|
|
228
|
+
'x-component-props': {
|
|
229
|
+
style: {
|
|
230
|
+
marginBottom: 16,
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
properties: {
|
|
234
|
+
filter: {
|
|
235
|
+
type: 'void',
|
|
236
|
+
title: '{{ t("Filter") }}',
|
|
237
|
+
'x-action': 'filter',
|
|
238
|
+
'x-designer': 'Filter.Action.Designer',
|
|
239
|
+
'x-component': 'Filter.Action',
|
|
240
|
+
'x-component-props': {
|
|
241
|
+
icon: 'FilterOutlined',
|
|
242
|
+
useProps: '{{ useFilterActionProps }}',
|
|
243
|
+
},
|
|
244
|
+
'x-align': 'left',
|
|
245
|
+
},
|
|
246
|
+
refresher: {
|
|
247
|
+
type: 'void',
|
|
248
|
+
title: '{{ t("Refresh") }}',
|
|
249
|
+
'x-action': 'refresh',
|
|
250
|
+
'x-component': 'Action',
|
|
251
|
+
'x-designer': 'Action.Designer',
|
|
252
|
+
'x-component-props': {
|
|
253
|
+
icon: 'ReloadOutlined',
|
|
254
|
+
useProps: '{{ useRefreshActionProps }}',
|
|
255
|
+
},
|
|
256
|
+
'x-align': 'right',
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
table: {
|
|
261
|
+
type: 'array',
|
|
262
|
+
'x-component': 'TableV2',
|
|
263
|
+
'x-component-props': {
|
|
264
|
+
rowKey: 'id',
|
|
265
|
+
useProps: '{{ useTableBlockProps }}',
|
|
266
|
+
},
|
|
267
|
+
properties: {
|
|
268
|
+
node: {
|
|
269
|
+
type: 'void',
|
|
270
|
+
'x-decorator': 'TableV2.Column.Decorator',
|
|
271
|
+
'x-component': 'TableV2.Column',
|
|
272
|
+
title: `{{t("Task", { ns: "${NAMESPACE}" })}}`,
|
|
273
|
+
properties: {
|
|
274
|
+
node: {
|
|
275
|
+
'x-component': 'NodeColumn',
|
|
276
|
+
'x-read-pretty': true,
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
workflow: {
|
|
281
|
+
type: 'void',
|
|
282
|
+
'x-decorator': 'TableV2.Column.Decorator',
|
|
283
|
+
'x-component': 'TableV2.Column',
|
|
284
|
+
title: `{{t("Workflow", { ns: "${NAMESPACE}" })}}`,
|
|
285
|
+
properties: {
|
|
286
|
+
workflow: {
|
|
287
|
+
'x-component': 'WorkflowColumn',
|
|
288
|
+
'x-read-pretty': true,
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
createdAt: {
|
|
293
|
+
type: 'void',
|
|
294
|
+
'x-decorator': 'TableV2.Column.Decorator',
|
|
295
|
+
'x-component': 'TableV2.Column',
|
|
296
|
+
properties: {
|
|
297
|
+
createdAt: {
|
|
298
|
+
type: 'string',
|
|
299
|
+
'x-component': 'CollectionField',
|
|
300
|
+
'x-read-pretty': true,
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
user: {
|
|
305
|
+
type: 'void',
|
|
306
|
+
'x-decorator': 'TableV2.Column.Decorator',
|
|
307
|
+
'x-component': 'TableV2.Column',
|
|
308
|
+
title: `{{t("Assignee", { ns: "${NAMESPACE}" })}}`,
|
|
309
|
+
properties: {
|
|
310
|
+
user: {
|
|
311
|
+
'x-component': 'UserColumn',
|
|
312
|
+
'x-read-pretty': true,
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
status: {
|
|
317
|
+
type: 'void',
|
|
318
|
+
'x-decorator': 'TableV2.Column.Decorator',
|
|
319
|
+
'x-component': 'TableV2.Column',
|
|
320
|
+
properties: {
|
|
321
|
+
status: {
|
|
322
|
+
'x-component': 'CollectionField',
|
|
323
|
+
'x-read-pretty': true,
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
actions: {
|
|
328
|
+
type: 'void',
|
|
329
|
+
'x-decorator': 'TableV2.Column.Decorator',
|
|
330
|
+
'x-component': 'TableV2.Column',
|
|
331
|
+
title: '{{t("Actions")}}',
|
|
332
|
+
properties: {
|
|
333
|
+
view: {
|
|
334
|
+
type: 'void',
|
|
335
|
+
'x-component': 'Action.Link',
|
|
336
|
+
title: '{{t("View")}}',
|
|
337
|
+
properties: {
|
|
338
|
+
drawer: {
|
|
339
|
+
'x-component': 'WorkflowTodo.Drawer',
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
}}
|
|
349
|
+
/>
|
|
350
|
+
);
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
function ActionBarProvider(props) {
|
|
354
|
+
// * status is done:
|
|
355
|
+
// 1. form is this form: show action button, and emphasis used status button
|
|
356
|
+
// 2. form is not this form: hide action bar
|
|
357
|
+
// * status is not done:
|
|
358
|
+
// 1. current user: show action bar
|
|
359
|
+
// 2. not current user: disabled action bar
|
|
360
|
+
|
|
361
|
+
const { data: user } = useCurrentUserContext();
|
|
362
|
+
const { userJob } = useFlowContext();
|
|
363
|
+
const { status, result, userId } = userJob;
|
|
364
|
+
const buttonSchema = useFieldSchema();
|
|
365
|
+
const { name } = buttonSchema.parent.toJSON();
|
|
366
|
+
|
|
367
|
+
let { children: content } = props;
|
|
368
|
+
if (status) {
|
|
369
|
+
if (!result[name]) {
|
|
370
|
+
content = null;
|
|
371
|
+
}
|
|
372
|
+
} else {
|
|
373
|
+
if (user?.data?.id !== userId) {
|
|
374
|
+
content = null;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return content;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const ManualActionStatusContext = createContext<number | null>(null);
|
|
382
|
+
|
|
383
|
+
function ManualActionStatusProvider({ value, children }) {
|
|
384
|
+
const { userJob } = useFlowContext();
|
|
385
|
+
const button = useField();
|
|
386
|
+
const buttonSchema = useFieldSchema();
|
|
387
|
+
|
|
388
|
+
useEffect(() => {
|
|
389
|
+
if (userJob.status) {
|
|
390
|
+
button.disabled = true;
|
|
391
|
+
button.visible = userJob.status === value && userJob.result._ === buttonSchema.name;
|
|
392
|
+
}
|
|
393
|
+
}, [userJob, value, button, buttonSchema.name]);
|
|
394
|
+
|
|
395
|
+
return <ManualActionStatusContext.Provider value={value}>{children}</ManualActionStatusContext.Provider>;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function useSubmit() {
|
|
399
|
+
const api = useAPIClient();
|
|
400
|
+
const { setVisible } = useActionContext();
|
|
401
|
+
const { values, submit } = useForm();
|
|
402
|
+
const buttonSchema = useFieldSchema();
|
|
403
|
+
const { service } = useTableBlockContext();
|
|
404
|
+
const { userJob } = useFlowContext();
|
|
405
|
+
const { name: actionKey } = buttonSchema;
|
|
406
|
+
const { name: formKey } = buttonSchema.parent.parent;
|
|
407
|
+
return {
|
|
408
|
+
async run() {
|
|
409
|
+
if (userJob.status) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
await submit();
|
|
413
|
+
await api.resource('users_jobs').submit({
|
|
414
|
+
filterByTk: userJob.id,
|
|
415
|
+
values: {
|
|
416
|
+
result: { [formKey]: values, _: actionKey },
|
|
417
|
+
},
|
|
418
|
+
});
|
|
419
|
+
setVisible(false);
|
|
420
|
+
service.refresh();
|
|
421
|
+
},
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function FlowContextProvider(props) {
|
|
426
|
+
const workflowPlugin = usePlugin(WorkflowPlugin);
|
|
427
|
+
const api = useAPIClient();
|
|
428
|
+
const { id } = useRecord();
|
|
429
|
+
const [flowContext, setFlowContext] = useState<any>(null);
|
|
430
|
+
const [node, setNode] = useState<any>(null);
|
|
431
|
+
|
|
432
|
+
useEffect(() => {
|
|
433
|
+
if (!id) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
api
|
|
437
|
+
.resource('users_jobs')
|
|
438
|
+
.get?.({
|
|
439
|
+
filterByTk: id,
|
|
440
|
+
appends: ['node', 'workflow', 'workflow.nodes', 'execution', 'execution.jobs'],
|
|
441
|
+
})
|
|
442
|
+
.then(({ data }) => {
|
|
443
|
+
const { node, workflow: { nodes = [], ...workflow } = {}, execution, ...userJob } = data?.data ?? {};
|
|
444
|
+
linkNodes(nodes);
|
|
445
|
+
setNode(node);
|
|
446
|
+
setFlowContext({
|
|
447
|
+
userJob,
|
|
448
|
+
workflow,
|
|
449
|
+
nodes,
|
|
450
|
+
execution,
|
|
451
|
+
});
|
|
452
|
+
return;
|
|
453
|
+
});
|
|
454
|
+
}, [api, id]);
|
|
455
|
+
|
|
456
|
+
const upstreams = useAvailableUpstreams(flowContext?.nodes.find((item) => item.id === node.id));
|
|
457
|
+
const nodeComponents = upstreams.reduce(
|
|
458
|
+
(components, { type }) => Object.assign(components, workflowPlugin.instructions.get(type).components),
|
|
459
|
+
{},
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
return node && flowContext ? (
|
|
463
|
+
<FlowContext.Provider value={flowContext}>
|
|
464
|
+
<SchemaComponent
|
|
465
|
+
components={{
|
|
466
|
+
FormBlockProvider,
|
|
467
|
+
DetailsBlockProvider,
|
|
468
|
+
ActionBarProvider,
|
|
469
|
+
ManualActionStatusProvider,
|
|
470
|
+
// @ts-ignore
|
|
471
|
+
...Array.from(manualFormTypes.getValues()).reduce(
|
|
472
|
+
(result, item: ManualFormType) => Object.assign(result, item.block.components),
|
|
473
|
+
{},
|
|
474
|
+
),
|
|
475
|
+
...nodeComponents,
|
|
476
|
+
}}
|
|
477
|
+
scope={{
|
|
478
|
+
useSubmit,
|
|
479
|
+
useFormBlockProps,
|
|
480
|
+
useDetailsBlockProps,
|
|
481
|
+
// @ts-ignore
|
|
482
|
+
...Array.from(manualFormTypes.getValues()).reduce(
|
|
483
|
+
(result, item: ManualFormType) => Object.assign(result, item.block.scope),
|
|
484
|
+
{},
|
|
485
|
+
),
|
|
486
|
+
}}
|
|
487
|
+
schema={{
|
|
488
|
+
type: 'void',
|
|
489
|
+
name: 'tabs',
|
|
490
|
+
'x-component': 'Tabs',
|
|
491
|
+
properties: node.config?.schema,
|
|
492
|
+
}}
|
|
493
|
+
/>
|
|
494
|
+
</FlowContext.Provider>
|
|
495
|
+
) : (
|
|
496
|
+
<Spin />
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function useFormBlockProps() {
|
|
501
|
+
const { userJob } = useFlowContext();
|
|
502
|
+
const record = useRecord();
|
|
503
|
+
const { data: user } = useCurrentUserContext();
|
|
504
|
+
const { form } = useFormBlockContext();
|
|
505
|
+
|
|
506
|
+
const pattern = userJob.status
|
|
507
|
+
? record
|
|
508
|
+
? 'readPretty'
|
|
509
|
+
: 'disabled'
|
|
510
|
+
: user?.data?.id !== userJob.userId
|
|
511
|
+
? 'disabled'
|
|
512
|
+
: 'editable';
|
|
513
|
+
|
|
514
|
+
useEffect(() => {
|
|
515
|
+
form?.setPattern(pattern);
|
|
516
|
+
}, [pattern, form]);
|
|
517
|
+
|
|
518
|
+
return { form };
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function useDetailsBlockProps() {
|
|
522
|
+
const { form } = useFormBlockContext();
|
|
523
|
+
return { form };
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function FooterStatus() {
|
|
527
|
+
const compile = useCompile();
|
|
528
|
+
const { status, updatedAt } = useRecord();
|
|
529
|
+
const statusOption = JobStatusOptionsMap[status];
|
|
530
|
+
return status ? (
|
|
531
|
+
<Space>
|
|
532
|
+
<time
|
|
533
|
+
className={css`
|
|
534
|
+
margin-right: 0.5em;
|
|
535
|
+
`}
|
|
536
|
+
>
|
|
537
|
+
{dayjs(updatedAt).format('YYYY-MM-DD HH:mm:ss')}
|
|
538
|
+
</time>
|
|
539
|
+
<Tag icon={statusOption.icon} color={statusOption.color}>
|
|
540
|
+
{compile(statusOption.label)}
|
|
541
|
+
</Tag>
|
|
542
|
+
</Space>
|
|
543
|
+
) : null;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function Drawer() {
|
|
547
|
+
const ctx = useContext(SchemaComponentContext);
|
|
548
|
+
const { id, node, workflow, status } = useRecord();
|
|
549
|
+
|
|
550
|
+
return (
|
|
551
|
+
<SchemaComponentContext.Provider value={{ ...ctx, reset() {}, designable: false }}>
|
|
552
|
+
<SchemaComponent
|
|
553
|
+
components={{
|
|
554
|
+
FooterStatus,
|
|
555
|
+
FlowContextProvider,
|
|
556
|
+
}}
|
|
557
|
+
schema={{
|
|
558
|
+
type: 'void',
|
|
559
|
+
name: `drawer-${id}-${status}`,
|
|
560
|
+
'x-component': 'Action.Drawer',
|
|
561
|
+
'x-component-props': {
|
|
562
|
+
className: 'nb-action-popup',
|
|
563
|
+
},
|
|
564
|
+
title: `${workflow.title} - ${node.title ?? `#${node.id}`}`,
|
|
565
|
+
properties: {
|
|
566
|
+
tabs: {
|
|
567
|
+
type: 'void',
|
|
568
|
+
'x-component': 'FlowContextProvider',
|
|
569
|
+
},
|
|
570
|
+
footer: {
|
|
571
|
+
type: 'void',
|
|
572
|
+
'x-component': 'Action.Drawer.Footer',
|
|
573
|
+
properties: {
|
|
574
|
+
content: {
|
|
575
|
+
type: 'void',
|
|
576
|
+
'x-component': 'FooterStatus',
|
|
577
|
+
},
|
|
578
|
+
},
|
|
579
|
+
},
|
|
580
|
+
},
|
|
581
|
+
}}
|
|
582
|
+
/>
|
|
583
|
+
</SchemaComponentContext.Provider>
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function Decorator({ params = {}, children }) {
|
|
588
|
+
const { collections, ...cm } = useCollectionManager();
|
|
589
|
+
const blockProps = {
|
|
590
|
+
collection: 'users_jobs',
|
|
591
|
+
resource: 'users_jobs',
|
|
592
|
+
action: 'list',
|
|
593
|
+
params: {
|
|
594
|
+
pageSize: 20,
|
|
595
|
+
sort: ['-createdAt'],
|
|
596
|
+
...params,
|
|
597
|
+
appends: ['user', 'node', 'workflow'],
|
|
598
|
+
except: ['node.config', 'workflow.config', 'workflow.options'],
|
|
599
|
+
},
|
|
600
|
+
rowKey: 'id',
|
|
601
|
+
showIndex: true,
|
|
602
|
+
dragSort: false,
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
return (
|
|
606
|
+
<CollectionManagerProvider
|
|
607
|
+
{...cm}
|
|
608
|
+
collections={[...collections, nodeCollection, workflowCollection, todoCollection]}
|
|
609
|
+
>
|
|
610
|
+
<TableBlockProvider name="workflow-todo" {...blockProps}>
|
|
611
|
+
{children}
|
|
612
|
+
</TableBlockProvider>
|
|
613
|
+
</CollectionManagerProvider>
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
WorkflowTodo.Drawer = Drawer;
|
|
618
|
+
WorkflowTodo.Decorator = Decorator;
|