@nocobase/plugin-workflow-manual 0.20.0-alpha.9 → 0.21.0-alpha.2

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.
Files changed (39) hide show
  1. package/dist/client/index.js +4 -4
  2. package/dist/client/instruction/SchemaConfig.d.ts +14 -3
  3. package/dist/client/instruction/createManualFormBlockUISchema.d.ts +57 -0
  4. package/dist/client/instruction/forms/custom.d.ts +7 -2
  5. package/dist/externalVersion.js +9 -9
  6. package/dist/locale/index.d.ts +2 -1
  7. package/dist/locale/index.js +3 -0
  8. package/dist/locale/zh-CN.json +2 -1
  9. package/dist/server/forms/create.d.ts +2 -1
  10. package/dist/server/forms/create.js +4 -4
  11. package/dist/server/forms/update.d.ts +2 -1
  12. package/dist/server/forms/update.js +4 -4
  13. package/dist/server/migrations/20240325213145-fix-schema.d.ts +4 -0
  14. package/dist/server/migrations/20240325213145-fix-schema.js +88 -0
  15. package/package.json +2 -2
  16. package/src/client/WorkflowTodo.tsx +4 -4
  17. package/src/client/__e2e__/createRecordForm.test.ts +123 -67
  18. package/src/client/__e2e__/customFormBlocks.test.ts +135 -70
  19. package/src/client/__e2e__/datablocks.test.ts +43 -30
  20. package/src/client/__e2e__/updateRecordForm.test.ts +241 -57
  21. package/src/client/__e2e__/workflowTodo.test.ts +16 -7
  22. package/src/client/index.ts +12 -4
  23. package/src/client/instruction/FormBlockInitializer.tsx +3 -3
  24. package/src/client/instruction/SchemaConfig.tsx +162 -40
  25. package/src/client/instruction/createManualFormBlockUISchema.ts +5 -0
  26. package/src/client/instruction/forms/create.tsx +1 -1
  27. package/src/client/instruction/forms/custom.tsx +52 -21
  28. package/src/client/instruction/forms/update.tsx +16 -8
  29. package/src/client/instruction/index.tsx +1 -1
  30. package/src/locale/index.ts +3 -1
  31. package/src/locale/zh-CN.json +2 -1
  32. package/src/server/__tests__/data-source.test.ts +223 -0
  33. package/src/server/__tests__/{instruction.test.ts → form.test.ts} +1 -510
  34. package/src/server/__tests__/mode.test.ts +561 -0
  35. package/src/server/forms/create.ts +10 -3
  36. package/src/server/forms/update.ts +10 -3
  37. package/src/server/migrations/20240325213145-fix-schema.ts +81 -0
  38. package/dist/client/instruction/DetailsBlockProvider.d.ts +0 -2
  39. package/src/client/instruction/DetailsBlockProvider.tsx +0 -87
@@ -0,0 +1,561 @@
1
+ import Database from '@nocobase/database';
2
+ import { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
3
+ import { getApp, sleep } from '@nocobase/plugin-workflow-test';
4
+ import { MockServer } from '@nocobase/test';
5
+
6
+ // NOTE: skipped because time is not stable on github ci, but should work in local
7
+ describe('workflow > instructions > manual', () => {
8
+ let app: MockServer;
9
+ let agent;
10
+ let userAgents;
11
+ let db: Database;
12
+ let PostRepo;
13
+ let CommentRepo;
14
+ let WorkflowModel;
15
+ let workflow;
16
+ let UserModel;
17
+ let users;
18
+ let UserJobModel;
19
+
20
+ beforeEach(async () => {
21
+ app = await getApp({
22
+ plugins: ['users', 'auth', 'workflow-manual'],
23
+ });
24
+ // await app.getPlugin('auth').install();
25
+ agent = app.agent();
26
+ db = app.db;
27
+ WorkflowModel = db.getCollection('workflows').model;
28
+ PostRepo = db.getCollection('posts').repository;
29
+ CommentRepo = db.getCollection('comments').repository;
30
+ UserModel = db.getCollection('users').model;
31
+ UserJobModel = db.getModel('users_jobs');
32
+
33
+ users = await UserModel.bulkCreate([
34
+ { id: 2, nickname: 'a' },
35
+ { id: 3, nickname: 'b' },
36
+ ]);
37
+
38
+ userAgents = users.map((user) => app.agent().login(user));
39
+
40
+ workflow = await WorkflowModel.create({
41
+ enabled: true,
42
+ type: 'collection',
43
+ config: {
44
+ mode: 1,
45
+ collection: 'posts',
46
+ },
47
+ });
48
+ });
49
+
50
+ afterEach(() => app.destroy());
51
+
52
+ describe('mode: 0 (single record)', () => {
53
+ it('the only user assigned could submit', async () => {
54
+ const n1 = await workflow.createNode({
55
+ type: 'manual',
56
+ config: {
57
+ assignees: [users[0].id],
58
+ forms: {
59
+ f1: {
60
+ actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
61
+ },
62
+ },
63
+ },
64
+ });
65
+
66
+ const post = await PostRepo.create({ values: { title: 't1' } });
67
+
68
+ await sleep(500);
69
+
70
+ const [pending] = await workflow.getExecutions();
71
+ expect(pending.status).toBe(EXECUTION_STATUS.STARTED);
72
+ const [j1] = await pending.getJobs();
73
+ expect(j1.status).toBe(JOB_STATUS.PENDING);
74
+
75
+ const usersJobs = await UserJobModel.findAll();
76
+ expect(usersJobs.length).toBe(1);
77
+ expect(usersJobs[0].status).toBe(JOB_STATUS.PENDING);
78
+ expect(usersJobs[0].userId).toBe(users[0].id);
79
+ expect(usersJobs[0].jobId).toBe(j1.id);
80
+
81
+ const res1 = await agent.resource('users_jobs').submit({
82
+ filterByTk: usersJobs[0].id,
83
+ values: { result: { f1: {}, _: 'resolve' } },
84
+ });
85
+ expect(res1.status).toBe(401);
86
+
87
+ const res2 = await userAgents[1].resource('users_jobs').submit({
88
+ filterByTk: usersJobs[0].id,
89
+ values: {
90
+ result: { f1: {}, _: 'resolve' },
91
+ },
92
+ });
93
+ expect(res2.status).toBe(403);
94
+
95
+ const res3 = await userAgents[0].resource('users_jobs').submit({
96
+ filterByTk: usersJobs[0].id,
97
+ values: {
98
+ result: { f1: { a: 1 }, _: 'resolve' },
99
+ },
100
+ });
101
+ expect(res3.status).toBe(202);
102
+
103
+ await sleep(1000);
104
+
105
+ const [j2] = await pending.getJobs();
106
+ expect(j2.status).toBe(JOB_STATUS.RESOLVED);
107
+ expect(j2.result).toEqual({ f1: { a: 1 }, _: 'resolve' });
108
+
109
+ const usersJobsAfter = await UserJobModel.findAll();
110
+ expect(usersJobsAfter.length).toBe(1);
111
+ expect(usersJobsAfter[0].status).toBe(JOB_STATUS.RESOLVED);
112
+ expect(usersJobsAfter[0].result).toEqual({ f1: { a: 1 }, _: 'resolve' });
113
+
114
+ const res4 = await userAgents[0].resource('users_jobs').submit({
115
+ filterByTk: usersJobs[0].id,
116
+ values: {
117
+ result: { f1: { a: 2 }, _: 'resolve' },
118
+ },
119
+ });
120
+ expect(res4.status).toBe(400);
121
+ });
122
+
123
+ it('any user assigned could submit', async () => {
124
+ const n1 = await workflow.createNode({
125
+ type: 'manual',
126
+ config: {
127
+ assignees: [users[0].id, users[1].id],
128
+ forms: {
129
+ f1: {
130
+ actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
131
+ },
132
+ },
133
+ },
134
+ });
135
+
136
+ const post = await PostRepo.create({ values: { title: 't1' } });
137
+
138
+ await sleep(500);
139
+
140
+ const [pending] = await workflow.getExecutions();
141
+ expect(pending.status).toBe(EXECUTION_STATUS.STARTED);
142
+ const [j1] = await pending.getJobs();
143
+ expect(j1.status).toBe(JOB_STATUS.PENDING);
144
+
145
+ const usersJobs = await j1.getUsersJobs();
146
+
147
+ const res1 = await userAgents[1].resource('users_jobs').submit({
148
+ filterByTk: usersJobs.find((item) => item.userId === users[1].id).id,
149
+ values: {
150
+ result: { f1: { a: 1 }, _: 'resolve' },
151
+ },
152
+ });
153
+ expect(res1.status).toBe(202);
154
+
155
+ await sleep(1000);
156
+
157
+ const [j2] = await pending.getJobs();
158
+ expect(j2.status).toBe(JOB_STATUS.RESOLVED);
159
+ expect(j2.result).toEqual({ f1: { a: 1 }, _: 'resolve' });
160
+
161
+ const res2 = await userAgents[0].resource('users_jobs').submit({
162
+ filterByTk: usersJobs.find((item) => item.userId === users[0].id).id,
163
+ values: {
164
+ result: { f1: { a: 1 }, _: 'resolve' },
165
+ },
166
+ });
167
+ expect(res2.status).toBe(400);
168
+ });
169
+
170
+ it('also could submit to users_jobs api', async () => {
171
+ const n1 = await workflow.createNode({
172
+ type: 'manual',
173
+ config: {
174
+ assignees: [users[0].id],
175
+ forms: {
176
+ f1: {
177
+ actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
178
+ },
179
+ },
180
+ },
181
+ });
182
+
183
+ const post = await PostRepo.create({ values: { title: 't1' } });
184
+
185
+ await sleep(500);
186
+
187
+ const UserJobModel = db.getModel('users_jobs');
188
+ const usersJobs = await UserJobModel.findAll();
189
+ expect(usersJobs.length).toBe(1);
190
+ expect(usersJobs[0].get('status')).toBe(JOB_STATUS.PENDING);
191
+ expect(usersJobs[0].get('userId')).toBe(users[0].id);
192
+
193
+ const res = await userAgents[0].resource('users_jobs').submit({
194
+ filterByTk: usersJobs[0].get('id'),
195
+ values: {
196
+ result: { f1: { a: 1 }, _: 'resolve' },
197
+ },
198
+ });
199
+ expect(res.status).toBe(202);
200
+
201
+ await sleep(1000);
202
+
203
+ const [execution] = await workflow.getExecutions();
204
+ expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
205
+ const [job] = await execution.getJobs();
206
+ expect(job.status).toBe(JOB_STATUS.RESOLVED);
207
+ expect(job.result).toEqual({ f1: { a: 1 }, _: 'resolve' });
208
+ });
209
+ });
210
+
211
+ describe('mode: 1 (multiple record, all)', () => {
212
+ it('all resolved', async () => {
213
+ const n1 = await workflow.createNode({
214
+ type: 'manual',
215
+ config: {
216
+ assignees: [users[0].id, users[1].id],
217
+ mode: 1,
218
+ forms: {
219
+ f1: {
220
+ actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
221
+ },
222
+ },
223
+ },
224
+ });
225
+
226
+ const post = await PostRepo.create({ values: { title: 't1' } });
227
+
228
+ await sleep(500);
229
+
230
+ const UserJobModel = db.getModel('users_jobs');
231
+ const pendingJobs = await UserJobModel.findAll({
232
+ order: [['userId', 'ASC']],
233
+ });
234
+ expect(pendingJobs.length).toBe(2);
235
+
236
+ const res1 = await userAgents[0].resource('users_jobs').submit({
237
+ filterByTk: pendingJobs[0].get('id'),
238
+ values: {
239
+ result: { f1: { a: 1 }, _: 'resolve' },
240
+ },
241
+ });
242
+ expect(res1.status).toBe(202);
243
+
244
+ await sleep(1000);
245
+
246
+ const [e1] = await workflow.getExecutions();
247
+ expect(e1.status).toBe(EXECUTION_STATUS.STARTED);
248
+ const [j1] = await e1.getJobs();
249
+ expect(j1.status).toBe(JOB_STATUS.PENDING);
250
+ expect(j1.result).toBe(0.5);
251
+ const usersJobs1 = await UserJobModel.findAll({
252
+ order: [['userId', 'ASC']],
253
+ });
254
+ expect(usersJobs1.length).toBe(2);
255
+
256
+ const res2 = await userAgents[1].resource('users_jobs').submit({
257
+ filterByTk: pendingJobs[1].get('id'),
258
+ values: {
259
+ result: { f1: { a: 2 }, _: 'resolve' },
260
+ },
261
+ });
262
+ expect(res2.status).toBe(202);
263
+
264
+ await sleep(1000);
265
+
266
+ const [e2] = await workflow.getExecutions();
267
+ expect(e2.status).toBe(EXECUTION_STATUS.RESOLVED);
268
+ const [j2] = await e2.getJobs();
269
+ expect(j2.status).toBe(JOB_STATUS.RESOLVED);
270
+ expect(j2.result).toBe(1);
271
+ });
272
+
273
+ it('first rejected', async () => {
274
+ const n1 = await workflow.createNode({
275
+ type: 'manual',
276
+ config: {
277
+ assignees: [users[0].id, users[1].id],
278
+ mode: 1,
279
+ forms: {
280
+ f1: {
281
+ actions: [{ status: JOB_STATUS.REJECTED, key: 'reject' }],
282
+ },
283
+ },
284
+ },
285
+ });
286
+
287
+ const post = await PostRepo.create({ values: { title: 't1' } });
288
+
289
+ await sleep(500);
290
+
291
+ const UserJobModel = db.getModel('users_jobs');
292
+ const pendingJobs = await UserJobModel.findAll({
293
+ order: [['userId', 'ASC']],
294
+ });
295
+ expect(pendingJobs.length).toBe(2);
296
+
297
+ const res1 = await userAgents[0].resource('users_jobs').submit({
298
+ filterByTk: pendingJobs[0].get('id'),
299
+ values: {
300
+ result: { f1: { a: 0 }, _: 'reject' },
301
+ },
302
+ });
303
+ expect(res1.status).toBe(202);
304
+
305
+ await sleep(1000);
306
+
307
+ const [e1] = await workflow.getExecutions();
308
+ expect(e1.status).toBe(EXECUTION_STATUS.REJECTED);
309
+ const [j1] = await e1.getJobs();
310
+ expect(j1.status).toBe(JOB_STATUS.REJECTED);
311
+ expect(j1.result).toBe(0.5);
312
+ const usersJobs1 = await UserJobModel.findAll({
313
+ order: [['userId', 'ASC']],
314
+ });
315
+ expect(usersJobs1.length).toBe(2);
316
+
317
+ const res2 = await userAgents[1].resource('users_jobs').submit({
318
+ filterByTk: pendingJobs[1].get('id'),
319
+ values: {
320
+ result: { f1: { a: 0 }, _: 'reject' },
321
+ },
322
+ });
323
+ expect(res2.status).toBe(400);
324
+ });
325
+
326
+ it('last rejected', async () => {
327
+ const n1 = await workflow.createNode({
328
+ type: 'manual',
329
+ config: {
330
+ assignees: [users[0].id, users[1].id],
331
+ mode: 1,
332
+ forms: {
333
+ f1: {
334
+ actions: [
335
+ { status: JOB_STATUS.RESOLVED, key: 'resolve' },
336
+ { status: JOB_STATUS.REJECTED, key: 'reject' },
337
+ ],
338
+ },
339
+ },
340
+ },
341
+ });
342
+
343
+ const post = await PostRepo.create({ values: { title: 't1' } });
344
+
345
+ await sleep(500);
346
+
347
+ const UserJobModel = db.getModel('users_jobs');
348
+ const pendingJobs = await UserJobModel.findAll({
349
+ order: [['userId', 'ASC']],
350
+ });
351
+ expect(pendingJobs.length).toBe(2);
352
+
353
+ const res1 = await userAgents[0].resource('users_jobs').submit({
354
+ filterByTk: pendingJobs[0].get('id'),
355
+ values: {
356
+ result: { f1: { a: 1 }, _: 'resolve' },
357
+ },
358
+ });
359
+ expect(res1.status).toBe(202);
360
+
361
+ await sleep(1000);
362
+
363
+ const [e1] = await workflow.getExecutions();
364
+ expect(e1.status).toBe(EXECUTION_STATUS.STARTED);
365
+ const [j1] = await e1.getJobs();
366
+ expect(j1.status).toBe(JOB_STATUS.PENDING);
367
+ expect(j1.result).toBe(0.5);
368
+ const usersJobs1 = await UserJobModel.findAll({
369
+ order: [['userId', 'ASC']],
370
+ });
371
+ expect(usersJobs1.length).toBe(2);
372
+
373
+ const res2 = await userAgents[1].resource('users_jobs').submit({
374
+ filterByTk: pendingJobs[1].get('id'),
375
+ values: {
376
+ result: { f1: { a: 0 }, _: 'reject' },
377
+ },
378
+ });
379
+ expect(res2.status).toBe(202);
380
+
381
+ await sleep(1000);
382
+
383
+ const [e2] = await workflow.getExecutions();
384
+ expect(e2.status).toBe(EXECUTION_STATUS.REJECTED);
385
+ const [j2] = await e2.getJobs();
386
+ expect(j2.status).toBe(JOB_STATUS.REJECTED);
387
+ expect(j2.result).toBe(1);
388
+ });
389
+ });
390
+
391
+ describe('mode: -1 (multiple record, any)', () => {
392
+ it('first resolved', async () => {
393
+ const n1 = await workflow.createNode({
394
+ type: 'manual',
395
+ config: {
396
+ assignees: [users[0].id, users[1].id],
397
+ mode: -1,
398
+ forms: {
399
+ f1: {
400
+ actions: [
401
+ { status: JOB_STATUS.RESOLVED, key: 'resolve' },
402
+ { status: JOB_STATUS.REJECTED, key: 'reject' },
403
+ ],
404
+ },
405
+ },
406
+ },
407
+ });
408
+
409
+ const post = await PostRepo.create({ values: { title: 't1' } });
410
+
411
+ await sleep(500);
412
+
413
+ const UserJobModel = db.getModel('users_jobs');
414
+ const pendingJobs = await UserJobModel.findAll({
415
+ order: [['userId', 'ASC']],
416
+ });
417
+ expect(pendingJobs.length).toBe(2);
418
+
419
+ const res1 = await userAgents[0].resource('users_jobs').submit({
420
+ filterByTk: pendingJobs[0].get('id'),
421
+ values: {
422
+ result: { f1: { a: 1 }, _: 'resolve' },
423
+ },
424
+ });
425
+ expect(res1.status).toBe(202);
426
+
427
+ await sleep(1000);
428
+
429
+ const [e1] = await workflow.getExecutions();
430
+ expect(e1.status).toBe(EXECUTION_STATUS.RESOLVED);
431
+ const [j1] = await e1.getJobs();
432
+ expect(j1.status).toBe(JOB_STATUS.RESOLVED);
433
+ expect(j1.result).toBe(0.5);
434
+
435
+ const res2 = await userAgents[1].resource('users_jobs').submit({
436
+ filterByTk: pendingJobs[1].get('id'),
437
+ values: {
438
+ result: { f1: { a: 0 }, _: 'reject' },
439
+ },
440
+ });
441
+ expect(res2.status).toBe(400);
442
+ });
443
+
444
+ it('any resolved', async () => {
445
+ const n1 = await workflow.createNode({
446
+ type: 'manual',
447
+ config: {
448
+ assignees: [users[0].id, users[1].id],
449
+ mode: -1,
450
+ forms: {
451
+ f1: {
452
+ actions: [
453
+ { status: JOB_STATUS.RESOLVED, key: 'resolve' },
454
+ { status: JOB_STATUS.REJECTED, key: 'reject' },
455
+ ],
456
+ },
457
+ },
458
+ },
459
+ });
460
+
461
+ const post = await PostRepo.create({ values: { title: 't1' } });
462
+
463
+ await sleep(500);
464
+
465
+ const UserJobModel = db.getModel('users_jobs');
466
+ const pendingJobs = await UserJobModel.findAll({
467
+ order: [['userId', 'ASC']],
468
+ });
469
+ expect(pendingJobs.length).toBe(2);
470
+
471
+ const res1 = await userAgents[0].resource('users_jobs').submit({
472
+ filterByTk: pendingJobs[0].get('id'),
473
+ values: {
474
+ result: { f1: { a: 0 }, _: 'reject' },
475
+ },
476
+ });
477
+ expect(res1.status).toBe(202);
478
+
479
+ await sleep(1000);
480
+
481
+ const [e1] = await workflow.getExecutions();
482
+ expect(e1.status).toBe(EXECUTION_STATUS.STARTED);
483
+ const [j1] = await e1.getJobs();
484
+ expect(j1.status).toBe(JOB_STATUS.PENDING);
485
+ expect(j1.result).toBe(0.5);
486
+
487
+ const res2 = await userAgents[1].resource('users_jobs').submit({
488
+ filterByTk: pendingJobs[1].get('id'),
489
+ values: {
490
+ result: { f1: { a: 1 }, _: 'resolve' },
491
+ },
492
+ });
493
+ expect(res2.status).toBe(202);
494
+
495
+ await sleep(1000);
496
+
497
+ const [e2] = await workflow.getExecutions();
498
+ expect(e2.status).toBe(EXECUTION_STATUS.RESOLVED);
499
+ const [j2] = await e2.getJobs();
500
+ expect(j2.status).toBe(JOB_STATUS.RESOLVED);
501
+ expect(j2.result).toBe(1);
502
+ });
503
+
504
+ it('all rejected', async () => {
505
+ const n1 = await workflow.createNode({
506
+ type: 'manual',
507
+ config: {
508
+ assignees: [users[0].id, users[1].id],
509
+ mode: -1,
510
+ forms: {
511
+ f1: {
512
+ actions: [{ status: JOB_STATUS.REJECTED, key: 'reject' }],
513
+ },
514
+ },
515
+ },
516
+ });
517
+
518
+ const post = await PostRepo.create({ values: { title: 't1' } });
519
+
520
+ await sleep(500);
521
+
522
+ const UserJobModel = db.getModel('users_jobs');
523
+ const pendingJobs = await UserJobModel.findAll({
524
+ order: [['userId', 'ASC']],
525
+ });
526
+ expect(pendingJobs.length).toBe(2);
527
+
528
+ const res1 = await userAgents[0].resource('users_jobs').submit({
529
+ filterByTk: pendingJobs[0].get('id'),
530
+ values: {
531
+ result: { f1: { a: 0 }, _: 'reject' },
532
+ },
533
+ });
534
+ expect(res1.status).toBe(202);
535
+
536
+ await sleep(1000);
537
+
538
+ const [e1] = await workflow.getExecutions();
539
+ expect(e1.status).toBe(EXECUTION_STATUS.STARTED);
540
+ const [j1] = await e1.getJobs();
541
+ expect(j1.status).toBe(JOB_STATUS.PENDING);
542
+ expect(j1.result).toBe(0.5);
543
+
544
+ const res2 = await userAgents[1].resource('users_jobs').submit({
545
+ filterByTk: pendingJobs[1].get('id'),
546
+ values: {
547
+ result: { f1: { a: 0 }, _: 'reject' },
548
+ },
549
+ });
550
+ expect(res2.status).toBe(202);
551
+
552
+ await sleep(1000);
553
+
554
+ const [e2] = await workflow.getExecutions();
555
+ expect(e2.status).toBe(EXECUTION_STATUS.REJECTED);
556
+ const [j2] = await e2.getJobs();
557
+ expect(j2.status).toBe(JOB_STATUS.REJECTED);
558
+ expect(j2.result).toBe(1);
559
+ });
560
+ });
561
+ });
@@ -1,8 +1,15 @@
1
1
  import { Processor } from '@nocobase/plugin-workflow';
2
2
  import ManualInstruction from '../ManualInstruction';
3
3
 
4
- export default async function (this: ManualInstruction, instance, { collection }, processor: Processor) {
5
- const repo = this.workflow.db.getRepository(collection);
4
+ export default async function (
5
+ this: ManualInstruction,
6
+ instance,
7
+ { dataSource = 'main', collection },
8
+ processor: Processor,
9
+ ) {
10
+ const repo = this.workflow.app.dataSourceManager.dataSources
11
+ .get(dataSource)
12
+ .collectionManager.getRepository(collection);
6
13
  if (!repo) {
7
14
  throw new Error(`collection ${collection} for create data on manual node not found`);
8
15
  }
@@ -18,6 +25,6 @@ export default async function (this: ManualInstruction, instance, { collection }
18
25
  context: {
19
26
  executionId: processor.execution.id,
20
27
  },
21
- // transaction: processor.transaction,
28
+ transaction: processor.transaction,
22
29
  });
23
30
  }
@@ -1,8 +1,15 @@
1
1
  import { Processor } from '@nocobase/plugin-workflow';
2
2
  import ManualInstruction from '../ManualInstruction';
3
3
 
4
- export default async function (this: ManualInstruction, instance, { collection, filter = {} }, processor: Processor) {
5
- const repo = this.workflow.db.getRepository(collection);
4
+ export default async function (
5
+ this: ManualInstruction,
6
+ instance,
7
+ { dataSource = 'main', collection, filter = {} },
8
+ processor: Processor,
9
+ ) {
10
+ const repo = this.workflow.app.dataSourceManager.dataSources
11
+ .get(dataSource)
12
+ .collectionManager.getRepository(collection);
6
13
  if (!repo) {
7
14
  throw new Error(`collection ${collection} for update data on manual node not found`);
8
15
  }
@@ -18,6 +25,6 @@ export default async function (this: ManualInstruction, instance, { collection,
18
25
  context: {
19
26
  executionId: processor.execution.id,
20
27
  },
21
- // transaction: processor.transaction,
28
+ transaction: processor.transaction,
22
29
  });
23
30
  }
@@ -0,0 +1,81 @@
1
+ import { Migration } from '@nocobase/server';
2
+
3
+ function findSchema(root, filter, onlyLeaf = false) {
4
+ const result = [];
5
+
6
+ if (!root) {
7
+ return result;
8
+ }
9
+
10
+ if (filter(root) && (!onlyLeaf || !root.properties)) {
11
+ result.push(root);
12
+ return result;
13
+ }
14
+
15
+ if (root.properties) {
16
+ Object.keys(root.properties).forEach((key) => {
17
+ result.push(...findSchema(root.properties[key], filter));
18
+ });
19
+ }
20
+ return result;
21
+ }
22
+
23
+ function changeToDataPath(item) {
24
+ if (item && item['x-decorator-props']?.dataSource) {
25
+ item['x-decorator-props'].dataPath = item['x-decorator-props'].dataSource.replace(/^{{|}}$/g, '');
26
+ delete item['x-decorator-props'].dataSource;
27
+ }
28
+ }
29
+
30
+ function migrateSchema(schema) {
31
+ const root = { properties: schema };
32
+
33
+ const detailNodes = findSchema(root, (item) => {
34
+ return (
35
+ item['x-decorator'] === 'DetailsBlockProvider' &&
36
+ item['x-component'] === 'CardItem' &&
37
+ item['x-designer'] === 'SimpleDesigner'
38
+ );
39
+ });
40
+
41
+ detailNodes.forEach(changeToDataPath);
42
+
43
+ return schema;
44
+ }
45
+
46
+ export default class extends Migration {
47
+ async up() {
48
+ const { db } = this.context;
49
+ const NodeRepo = db.getRepository('flow_nodes');
50
+ await db.sequelize.transaction(async (transaction) => {
51
+ const nodes = await NodeRepo.find({
52
+ filter: {
53
+ type: 'manual',
54
+ },
55
+ transaction,
56
+ });
57
+ console.log('%d nodes need to be migrated.', nodes.length);
58
+
59
+ await nodes.reduce(
60
+ (promise, node) =>
61
+ promise.then(() => {
62
+ const { assignees, forms, schema = {}, ...tabs } = node.config;
63
+ return node.update(
64
+ {
65
+ config: {
66
+ assignees,
67
+ forms,
68
+ schema: migrateSchema({ ...tabs, ...schema }),
69
+ },
70
+ },
71
+ {
72
+ silent: true,
73
+ transaction,
74
+ },
75
+ );
76
+ }),
77
+ Promise.resolve(),
78
+ );
79
+ });
80
+ }
81
+ }
@@ -1,2 +0,0 @@
1
- import React from 'react';
2
- export declare function DetailsBlockProvider(props: any): React.JSX.Element;