@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
@@ -15,6 +15,7 @@ import {
15
15
  useDesignable,
16
16
  useMenuSearch,
17
17
  } from '@nocobase/client';
18
+ import { isValidFilter } from '@nocobase/utils/client';
18
19
  import { FilterDynamicComponent } from '@nocobase/plugin-workflow/client';
19
20
 
20
21
  import { NAMESPACE } from '../../../locale';
@@ -37,15 +38,15 @@ function UpdateFormDesigner() {
37
38
  name: 'filter',
38
39
  type: 'object',
39
40
  title: `{{t("Filter")}}`,
40
- // 'x-decorator': 'FormItem',
41
41
  'x-component': 'Filter',
42
+ 'x-use-component-props': () => {
43
+ // eslint-disable-next-line react-hooks/rules-of-hooks
44
+ const options = useCollectionFilterOptions(fieldSchema?.['x-decorator-props']?.collection);
45
+ return {
46
+ options,
47
+ };
48
+ },
42
49
  'x-component-props': {
43
- useProps() {
44
- const options = useCollectionFilterOptions(fieldSchema?.['x-decorator-props']?.collection);
45
- return {
46
- options,
47
- };
48
- },
49
50
  dynamicComponent: 'FilterDynamicComponent',
50
51
  },
51
52
  }}
@@ -101,7 +102,7 @@ export default {
101
102
  [allCollections],
102
103
  );
103
104
  const [openMenuKeys, setOpenMenuKeys] = useState([]);
104
- const searchedChildren = useMenuSearch(childItems, openMenuKeys);
105
+ const searchedChildren = useMenuSearch({ data: childItems, openKeys: openMenuKeys });
105
106
  return {
106
107
  name: 'updateRecordForm',
107
108
  key: 'updateRecordForm',
@@ -156,4 +157,11 @@ export default {
156
157
  },
157
158
  components: {},
158
159
  },
160
+ validate({ filter }) {
161
+ if (!filter || !isValidFilter(filter)) {
162
+ return 'Please check one of your update record form, and add at least one filter condition in form settings.';
163
+ }
164
+
165
+ return null;
166
+ },
159
167
  } as ManualFormType;
@@ -138,7 +138,7 @@ export default class extends Instruction {
138
138
  title: form.title ?? formKey,
139
139
  Component: CollectionBlockInitializer,
140
140
  collection: form.collection,
141
- dataSource: `{{$jobsMapByNodeKey.${node.key}.${formKey}}}`,
141
+ dataPath: `$jobsMapByNodeKey.${node.key}.${formKey}`,
142
142
  } as SchemaInitializerItemType)
143
143
  : null;
144
144
  })
@@ -7,6 +7,8 @@ export function useLang(key: string, options = {}) {
7
7
  return t(key);
8
8
  }
9
9
 
10
- export function usePluginTranslation(options) {
10
+ export const lang = useLang;
11
+
12
+ export function usePluginTranslation(options?) {
11
13
  return useTranslation(NAMESPACE, options);
12
14
  }
@@ -27,5 +27,6 @@
27
27
  "Filter settings": "筛选设置",
28
28
  "Workflow todos": "工作流待办",
29
29
  "Task node": "任务节点",
30
- "Unprocessed": "未处理"
30
+ "Unprocessed": "未处理",
31
+ "Please check one of your update record form, and add at least one filter condition in form settings.": "请检查您的其中的更新数据表单,并在表单设置中至少添加一个筛选条件。"
31
32
  }
@@ -0,0 +1,223 @@
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 AnotherPostRepo;
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
+ AnotherPostRepo = app.dataSourceManager.dataSources.get('another').collectionManager.getRepository('posts');
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('multiple data source', () => {
53
+ describe('create', () => {
54
+ it('create as configured', async () => {
55
+ const n1 = await workflow.createNode({
56
+ type: 'manual',
57
+ config: {
58
+ assignees: [users[0].id],
59
+ forms: {
60
+ f1: {
61
+ type: 'create',
62
+ actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
63
+ collection: 'posts',
64
+ dataSource: 'another',
65
+ },
66
+ },
67
+ },
68
+ });
69
+
70
+ const post = await PostRepo.create({ values: { title: 't1' } });
71
+
72
+ await sleep(500);
73
+
74
+ const UserJobModel = db.getModel('users_jobs');
75
+ const pendingJobs = await UserJobModel.findAll({
76
+ order: [['userId', 'ASC']],
77
+ });
78
+ expect(pendingJobs.length).toBe(1);
79
+
80
+ const res1 = await userAgents[0].resource('users_jobs').submit({
81
+ filterByTk: pendingJobs[0].get('id'),
82
+ values: {
83
+ result: { f1: { title: 't1' }, _: 'resolve' },
84
+ },
85
+ });
86
+ expect(res1.status).toBe(202);
87
+
88
+ await sleep(500);
89
+
90
+ const [e1] = await workflow.getExecutions();
91
+ expect(e1.status).toBe(EXECUTION_STATUS.RESOLVED);
92
+ const [j1] = await e1.getJobs();
93
+ expect(j1.status).toBe(JOB_STATUS.RESOLVED);
94
+ expect(j1.result).toMatchObject({ f1: { title: 't1' } });
95
+
96
+ const posts = await AnotherPostRepo.find();
97
+ expect(posts.length).toBe(1);
98
+ expect(posts[0]).toMatchObject({ title: 't1' });
99
+ });
100
+
101
+ it('save first and then commit', async () => {
102
+ const n1 = await workflow.createNode({
103
+ type: 'manual',
104
+ config: {
105
+ assignees: [users[0].id],
106
+ forms: {
107
+ f1: {
108
+ type: 'create',
109
+ actions: [
110
+ { status: JOB_STATUS.RESOLVED, key: 'resolve' },
111
+ { status: JOB_STATUS.PENDING, key: 'pending' },
112
+ ],
113
+ collection: 'posts',
114
+ dataSource: 'another',
115
+ },
116
+ },
117
+ },
118
+ });
119
+
120
+ const post = await PostRepo.create({ values: { title: 't1' } });
121
+
122
+ await sleep(500);
123
+
124
+ const UserJobModel = db.getModel('users_jobs');
125
+ const pendingJobs = await UserJobModel.findAll({
126
+ order: [['userId', 'ASC']],
127
+ });
128
+ expect(pendingJobs.length).toBe(1);
129
+
130
+ const res1 = await userAgents[0].resource('users_jobs').submit({
131
+ filterByTk: pendingJobs[0].get('id'),
132
+ values: {
133
+ result: { f1: { title: 't1' }, _: 'pending' },
134
+ },
135
+ });
136
+ expect(res1.status).toBe(202);
137
+
138
+ await sleep(500);
139
+
140
+ const [e1] = await workflow.getExecutions();
141
+ expect(e1.status).toBe(EXECUTION_STATUS.STARTED);
142
+ const [j1] = await e1.getJobs();
143
+ expect(j1.status).toBe(JOB_STATUS.PENDING);
144
+ expect(j1.result).toMatchObject({ f1: { title: 't1' } });
145
+
146
+ const c1 = await AnotherPostRepo.find();
147
+ expect(c1.length).toBe(0);
148
+
149
+ const res2 = await userAgents[0].resource('users_jobs').submit({
150
+ filterByTk: pendingJobs[0].get('id'),
151
+ values: {
152
+ result: { f1: { title: 't2' }, _: 'resolve' },
153
+ },
154
+ });
155
+
156
+ await sleep(500);
157
+
158
+ const [e2] = await workflow.getExecutions();
159
+ expect(e2.status).toBe(EXECUTION_STATUS.RESOLVED);
160
+ const [j2] = await e2.getJobs();
161
+ expect(j2.status).toBe(JOB_STATUS.RESOLVED);
162
+ expect(j2.result).toMatchObject({ f1: { title: 't2' } });
163
+
164
+ const c2 = await AnotherPostRepo.find();
165
+ expect(c2.length).toBe(1);
166
+ });
167
+ });
168
+
169
+ describe('update', () => {
170
+ it('update as configured', async () => {
171
+ const post = await AnotherPostRepo.create({ values: { title: 't1' } });
172
+
173
+ const n1 = await workflow.createNode({
174
+ type: 'manual',
175
+ config: {
176
+ assignees: [users[0].id],
177
+ forms: {
178
+ f1: {
179
+ type: 'update',
180
+ actions: [{ status: JOB_STATUS.RESOLVED, key: 'resolve' }],
181
+ collection: 'posts',
182
+ dataSource: 'another',
183
+ filter: {
184
+ id: post.id,
185
+ },
186
+ },
187
+ },
188
+ },
189
+ });
190
+
191
+ await PostRepo.create({ values: { title: 't1' } });
192
+
193
+ await sleep(500);
194
+
195
+ const UserJobModel = db.getModel('users_jobs');
196
+ const pendingJobs = await UserJobModel.findAll({
197
+ order: [['userId', 'ASC']],
198
+ });
199
+ expect(pendingJobs.length).toBe(1);
200
+
201
+ const res1 = await userAgents[0].resource('users_jobs').submit({
202
+ filterByTk: pendingJobs[0].get('id'),
203
+ values: {
204
+ result: { f1: { title: 't2' }, _: 'resolve' },
205
+ },
206
+ });
207
+ expect(res1.status).toBe(202);
208
+
209
+ await sleep(500);
210
+
211
+ const [e2] = await workflow.getExecutions();
212
+ expect(e2.status).toBe(EXECUTION_STATUS.RESOLVED);
213
+ const [j1] = await e2.getJobs();
214
+ expect(j1.status).toBe(JOB_STATUS.RESOLVED);
215
+ expect(j1.result).toMatchObject({ f1: { title: 't2' } });
216
+
217
+ const postsAfter = await AnotherPostRepo.find();
218
+ expect(postsAfter.length).toBe(1);
219
+ expect(postsAfter[0]).toMatchObject({ title: 't2' });
220
+ });
221
+ });
222
+ });
223
+ });