@nocobase/plugin-workflow 0.10.1-alpha.1 → 0.11.1-alpha.1

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 (289) hide show
  1. package/client.d.ts +2 -3
  2. package/client.js +1 -30
  3. package/lib/client/AddButton.js +13 -11
  4. package/lib/client/Branch.js +10 -8
  5. package/lib/client/CanvasContent.js +12 -10
  6. package/lib/client/ExecutionCanvas.js +37 -33
  7. package/lib/client/ExecutionPage.js +4 -9
  8. package/lib/client/WorkflowCanvas.js +18 -15
  9. package/lib/client/WorkflowPage.js +4 -9
  10. package/lib/client/WorkflowProvider.js +1 -40
  11. package/lib/client/components/CollectionBlockInitializer.js +3 -3
  12. package/lib/client/components/CollectionFieldset.d.ts +1 -1
  13. package/lib/client/components/CollectionFieldset.js +15 -16
  14. package/lib/client/components/Duration.js +5 -5
  15. package/lib/client/components/DynamicExpression.d.ts +3 -3
  16. package/lib/client/components/FieldsSelect.d.ts +1 -1
  17. package/lib/client/components/FieldsSelect.js +10 -7
  18. package/lib/client/components/NodeDescription.js +45 -31
  19. package/lib/client/components/RadioWithTooltip.js +13 -20
  20. package/lib/client/components/ValueBlock.js +14 -21
  21. package/lib/client/components/renderEngineReference.js +1 -8
  22. package/lib/client/index.d.ts +12 -4
  23. package/lib/client/index.js +78 -15
  24. package/lib/client/locale/zh-CN.d.ts +5 -1
  25. package/lib/client/locale/zh-CN.js +6 -2
  26. package/lib/client/nodes/aggregate.d.ts +8 -3
  27. package/lib/client/nodes/aggregate.js +5 -4
  28. package/lib/client/nodes/calculation.d.ts +6 -4
  29. package/lib/client/nodes/calculation.js +22 -28
  30. package/lib/client/nodes/condition.d.ts +2 -10
  31. package/lib/client/nodes/condition.js +19 -37
  32. package/lib/client/nodes/create.d.ts +5 -6
  33. package/lib/client/nodes/create.js +1 -3
  34. package/lib/client/nodes/destroy.d.ts +1 -1
  35. package/lib/client/nodes/index.d.ts +2 -3
  36. package/lib/client/nodes/index.js +95 -102
  37. package/lib/client/nodes/loop.d.ts +1 -1
  38. package/lib/client/nodes/loop.js +46 -54
  39. package/lib/client/nodes/manual/FormBlockInitializer.js +6 -5
  40. package/lib/client/nodes/manual/ModeConfig.js +23 -30
  41. package/lib/client/nodes/manual/SchemaConfig.d.ts +4 -5
  42. package/lib/client/nodes/manual/SchemaConfig.js +180 -25
  43. package/lib/client/nodes/manual/WorkflowTodo.js +95 -110
  44. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +2 -5
  45. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +6 -5
  46. package/lib/client/nodes/manual/forms/create.js +8 -1
  47. package/lib/client/nodes/manual/forms/custom.js +22 -22
  48. package/lib/client/nodes/manual/forms/update.js +8 -1
  49. package/lib/client/nodes/manual/index.d.ts +6 -1
  50. package/lib/client/nodes/manual/index.js +5 -4
  51. package/lib/client/nodes/parallel.js +23 -20
  52. package/lib/client/nodes/query.d.ts +3 -5
  53. package/lib/client/nodes/query.js +1 -3
  54. package/lib/client/nodes/request.d.ts +2 -2
  55. package/lib/client/nodes/request.js +7 -7
  56. package/lib/client/nodes/sql.d.ts +26 -0
  57. package/lib/client/{triggers/schedule/DateFieldsSelect.js → nodes/sql.js} +37 -46
  58. package/lib/client/nodes/update.d.ts +2 -2
  59. package/lib/client/nodes/update.js +1 -1
  60. package/lib/client/schemas/collection.d.ts +3 -4
  61. package/lib/client/schemas/collection.js +11 -17
  62. package/lib/client/style.d.ts +18 -13
  63. package/lib/client/style.js +315 -292
  64. package/lib/client/triggers/collection.d.ts +13 -13
  65. package/lib/client/triggers/collection.js +5 -1
  66. package/lib/client/triggers/index.d.ts +3 -4
  67. package/lib/client/triggers/index.js +51 -53
  68. package/lib/client/triggers/schedule/EndsByField.js +11 -11
  69. package/lib/client/triggers/schedule/OnField.js +45 -33
  70. package/lib/client/triggers/schedule/RepeatField.js +4 -4
  71. package/lib/client/triggers/schedule/ScheduleConfig.js +24 -31
  72. package/lib/client/triggers/schedule/index.d.ts +1 -1
  73. package/lib/client/triggers/schedule/index.js +32 -20
  74. package/lib/client/variable.d.ts +31 -13
  75. package/lib/client/variable.js +44 -29
  76. package/lib/server/Plugin.d.ts +3 -6
  77. package/lib/server/Plugin.js +15 -12
  78. package/lib/server/Processor.d.ts +3 -5
  79. package/lib/server/Processor.js +2 -2
  80. package/lib/server/actions/nodes.js +7 -7
  81. package/lib/server/fields/expression-field.d.ts +1 -2
  82. package/lib/server/fields/expression-field.js +1 -8
  83. package/lib/server/functions/index.d.ts +2 -3
  84. package/lib/server/index.d.ts +1 -0
  85. package/lib/server/index.js +12 -0
  86. package/lib/server/instructions/aggregate.d.ts +1 -1
  87. package/lib/server/instructions/aggregate.js +5 -5
  88. package/lib/server/instructions/condition.d.ts +2 -1
  89. package/lib/server/instructions/create.d.ts +2 -2
  90. package/lib/server/instructions/create.js +13 -13
  91. package/lib/server/instructions/delay.d.ts +3 -3
  92. package/lib/server/instructions/delay.js +66 -64
  93. package/lib/server/instructions/destroy.d.ts +1 -1
  94. package/lib/server/instructions/index.d.ts +5 -5
  95. package/lib/server/instructions/index.js +1 -1
  96. package/lib/server/instructions/loop.d.ts +1 -2
  97. package/lib/server/instructions/manual/actions.js +19 -7
  98. package/lib/server/instructions/manual/forms/create.js +7 -1
  99. package/lib/server/instructions/manual/forms/index.d.ts +1 -1
  100. package/lib/server/instructions/manual/forms/update.js +7 -1
  101. package/lib/server/instructions/manual/index.d.ts +1 -1
  102. package/lib/server/instructions/parallel.d.ts +1 -2
  103. package/lib/server/instructions/query.d.ts +1 -1
  104. package/lib/server/instructions/query.js +8 -1
  105. package/lib/server/instructions/request.d.ts +3 -3
  106. package/lib/server/instructions/request.js +5 -2
  107. package/lib/server/instructions/sql.d.ts +12 -0
  108. package/lib/server/instructions/sql.js +34 -0
  109. package/lib/server/instructions/update.d.ts +1 -1
  110. package/lib/server/migrations/20230221071831-calculation-expression.js +1 -1
  111. package/lib/server/migrations/20230221121203-condition-calculation.js +1 -1
  112. package/lib/server/migrations/20230221162902-jsonb-to-json.js +7 -7
  113. package/lib/server/migrations/20230411034722-manual-multi-form.js +1 -8
  114. package/lib/server/migrations/20230710115902-manual-action-values.d.ts +4 -0
  115. package/lib/server/migrations/20230710115902-manual-action-values.js +97 -0
  116. package/lib/server/triggers/collection.d.ts +1 -1
  117. package/lib/server/triggers/collection.js +15 -13
  118. package/lib/server/triggers/index.d.ts +1 -1
  119. package/lib/server/triggers/schedule.d.ts +1 -1
  120. package/lib/server/triggers/schedule.js +18 -18
  121. package/lib/server/{models → types}/Execution.d.ts +2 -3
  122. package/lib/server/{models → types}/FlowNode.d.ts +1 -2
  123. package/lib/server/{models → types}/Job.d.ts +1 -2
  124. package/lib/server/{models → types}/Workflow.d.ts +1 -2
  125. package/lib/server/types/index.d.ts +4 -0
  126. package/lib/server/types/index.js +5 -0
  127. package/lib/server/utils.d.ts +2 -0
  128. package/lib/server/utils.js +21 -0
  129. package/package.json +39 -18
  130. package/server.d.ts +2 -3
  131. package/server.js +1 -30
  132. package/src/client/AddButton.tsx +111 -0
  133. package/src/client/Branch.tsx +37 -0
  134. package/src/client/CanvasContent.tsx +25 -0
  135. package/src/client/ExecutionCanvas.tsx +166 -0
  136. package/src/client/ExecutionLink.tsx +16 -0
  137. package/src/client/ExecutionPage.tsx +45 -0
  138. package/src/client/ExecutionResourceProvider.tsx +21 -0
  139. package/src/client/FlowContext.ts +7 -0
  140. package/src/client/WorkflowCanvas.tsx +221 -0
  141. package/src/client/WorkflowLink.tsx +16 -0
  142. package/src/client/WorkflowPage.tsx +52 -0
  143. package/src/client/WorkflowProvider.tsx +84 -0
  144. package/src/client/components/CollectionBlockInitializer.tsx +71 -0
  145. package/src/client/components/CollectionFieldset.tsx +160 -0
  146. package/src/client/components/Duration.tsx +45 -0
  147. package/src/client/components/DynamicExpression.tsx +53 -0
  148. package/src/client/components/FieldsSelect.tsx +32 -0
  149. package/src/client/components/FilterDynamicComponent.tsx +15 -0
  150. package/src/client/components/NodeDescription.tsx +51 -0
  151. package/src/client/components/NullRender.tsx +3 -0
  152. package/src/client/components/OpenDrawer.tsx +24 -0
  153. package/src/client/components/RadioWithTooltip.tsx +38 -0
  154. package/src/client/components/ValueBlock.tsx +67 -0
  155. package/src/client/components/renderEngineReference.tsx +30 -0
  156. package/src/client/constants.tsx +91 -0
  157. package/src/client/index.tsx +51 -0
  158. package/src/client/interfaces/expression.tsx +25 -0
  159. package/src/client/locale/en-US.ts +136 -0
  160. package/src/client/locale/es-ES.ts +129 -0
  161. package/src/client/locale/index.ts +18 -0
  162. package/src/client/locale/ja-JP.ts +90 -0
  163. package/src/client/locale/pt-BR.ts +136 -0
  164. package/src/client/locale/ru-RU.ts +90 -0
  165. package/src/client/locale/tr-TR.ts +90 -0
  166. package/src/client/locale/zh-CN.ts +248 -0
  167. package/src/client/nodes/aggregate.tsx +327 -0
  168. package/src/client/nodes/calculation.tsx +216 -0
  169. package/src/client/nodes/condition.tsx +463 -0
  170. package/src/client/nodes/create.tsx +85 -0
  171. package/src/client/nodes/delay.tsx +37 -0
  172. package/src/client/nodes/destroy.tsx +34 -0
  173. package/src/client/nodes/index.tsx +485 -0
  174. package/src/client/nodes/loop.tsx +144 -0
  175. package/src/client/nodes/manual/AssigneesSelect.tsx +33 -0
  176. package/src/client/nodes/manual/DetailsBlockProvider.tsx +80 -0
  177. package/src/client/nodes/manual/FormBlockInitializer.tsx +69 -0
  178. package/src/client/nodes/manual/FormBlockProvider.tsx +75 -0
  179. package/src/client/nodes/manual/ModeConfig.tsx +84 -0
  180. package/src/client/nodes/manual/SchemaConfig.tsx +509 -0
  181. package/src/client/nodes/manual/WorkflowTodo.tsx +607 -0
  182. package/src/client/nodes/manual/WorkflowTodoBlockInitializer.tsx +28 -0
  183. package/src/client/nodes/manual/forms/create.tsx +92 -0
  184. package/src/client/nodes/manual/forms/custom.tsx +392 -0
  185. package/src/client/nodes/manual/forms/update.tsx +134 -0
  186. package/src/client/nodes/manual/index.tsx +162 -0
  187. package/src/client/nodes/manual/utils.ts +28 -0
  188. package/src/client/nodes/parallel.tsx +138 -0
  189. package/src/client/nodes/query.tsx +88 -0
  190. package/src/client/nodes/request.tsx +185 -0
  191. package/src/client/nodes/sql.tsx +37 -0
  192. package/src/client/nodes/update.tsx +99 -0
  193. package/src/client/schemas/collection.ts +75 -0
  194. package/src/client/schemas/executions.tsx +169 -0
  195. package/src/client/schemas/workflows.ts +364 -0
  196. package/src/client/style.tsx +347 -0
  197. package/src/client/triggers/collection.tsx +190 -0
  198. package/src/client/triggers/index.tsx +311 -0
  199. package/src/client/triggers/schedule/EndsByField.tsx +40 -0
  200. package/src/client/triggers/schedule/OnField.tsx +64 -0
  201. package/src/client/triggers/schedule/RepeatField.tsx +116 -0
  202. package/src/client/triggers/schedule/ScheduleConfig.tsx +227 -0
  203. package/src/client/triggers/schedule/constants.ts +4 -0
  204. package/src/client/triggers/schedule/index.tsx +78 -0
  205. package/src/client/triggers/schedule/locale/Cron.zh-CN.ts +79 -0
  206. package/src/client/utils.ts +36 -0
  207. package/src/client/variable.tsx +318 -0
  208. package/src/index.ts +1 -0
  209. package/src/server/Plugin.ts +355 -0
  210. package/src/server/Processor.ts +354 -0
  211. package/src/server/__tests__/Plugin.test.ts +398 -0
  212. package/src/server/__tests__/Processor.test.ts +474 -0
  213. package/src/server/__tests__/actions/workflows.test.ts +419 -0
  214. package/src/server/__tests__/collections/categories.ts +27 -0
  215. package/src/server/__tests__/collections/comments.ts +24 -0
  216. package/src/server/__tests__/collections/posts.ts +42 -0
  217. package/src/server/__tests__/collections/replies.ts +9 -0
  218. package/src/server/__tests__/collections/tags.ts +15 -0
  219. package/src/server/__tests__/index.ts +89 -0
  220. package/src/server/__tests__/instructions/aggregate.test.ts +294 -0
  221. package/src/server/__tests__/instructions/calculation.test.ts +265 -0
  222. package/src/server/__tests__/instructions/condition.test.ts +335 -0
  223. package/src/server/__tests__/instructions/create.test.ts +129 -0
  224. package/src/server/__tests__/instructions/delay.test.ts +182 -0
  225. package/src/server/__tests__/instructions/destroy.test.ts +58 -0
  226. package/src/server/__tests__/instructions/loop.test.ts +331 -0
  227. package/src/server/__tests__/instructions/manual.test.ts +1173 -0
  228. package/src/server/__tests__/instructions/parallel.test.ts +445 -0
  229. package/src/server/__tests__/instructions/query.test.ts +359 -0
  230. package/src/server/__tests__/instructions/request.test.ts +247 -0
  231. package/src/server/__tests__/instructions/sql.test.ts +162 -0
  232. package/src/server/__tests__/instructions/update.test.ts +189 -0
  233. package/src/server/__tests__/triggers/collection.test.ts +333 -0
  234. package/src/server/__tests__/triggers/schedule.test.ts +369 -0
  235. package/src/server/actions/index.ts +25 -0
  236. package/src/server/actions/nodes.ts +214 -0
  237. package/src/server/actions/workflows.ts +178 -0
  238. package/src/server/collections/executions.ts +35 -0
  239. package/src/server/collections/flow_nodes.ts +54 -0
  240. package/src/server/collections/jobs.ts +31 -0
  241. package/src/server/collections/workflows.ts +88 -0
  242. package/src/server/constants.ts +26 -0
  243. package/src/server/fields/expression-field.ts +11 -0
  244. package/src/server/fields/index.ts +7 -0
  245. package/src/server/functions/index.ts +16 -0
  246. package/src/server/index.ts +6 -0
  247. package/src/server/instructions/aggregate.ts +42 -0
  248. package/src/server/instructions/calculation.ts +41 -0
  249. package/src/server/instructions/condition.ts +172 -0
  250. package/src/server/instructions/create.ts +39 -0
  251. package/src/server/instructions/delay.ts +105 -0
  252. package/src/server/instructions/destroy.ts +23 -0
  253. package/src/server/instructions/index.ts +64 -0
  254. package/src/server/instructions/loop.ts +99 -0
  255. package/src/server/instructions/manual/actions.ts +91 -0
  256. package/src/server/instructions/manual/collecions/jobs.ts +17 -0
  257. package/src/server/instructions/manual/collecions/users.ts +15 -0
  258. package/src/server/instructions/manual/collecions/users_jobs.ts +50 -0
  259. package/src/server/instructions/manual/forms/create.ts +23 -0
  260. package/src/server/instructions/manual/forms/index.ts +12 -0
  261. package/src/server/instructions/manual/forms/update.ts +23 -0
  262. package/src/server/instructions/manual/index.ts +184 -0
  263. package/src/server/instructions/parallel.ts +121 -0
  264. package/src/server/instructions/query.ts +42 -0
  265. package/src/server/instructions/request.ts +88 -0
  266. package/src/server/instructions/sql.ts +25 -0
  267. package/src/server/instructions/update.ts +24 -0
  268. package/src/server/migrations/20221129153547-calculation-variables.ts +64 -0
  269. package/src/server/migrations/20230221032941-change-request-body-type.ts +76 -0
  270. package/src/server/migrations/20230221071831-calculation-expression.ts +102 -0
  271. package/src/server/migrations/20230221121203-condition-calculation.ts +82 -0
  272. package/src/server/migrations/20230221162902-jsonb-to-json.ts +51 -0
  273. package/src/server/migrations/20230411034722-manual-multi-form.ts +282 -0
  274. package/src/server/migrations/20230612021134-manual-collection-block.ts +138 -0
  275. package/src/server/migrations/20230710115902-manual-action-values.ts +78 -0
  276. package/src/server/triggers/collection.ts +146 -0
  277. package/src/server/triggers/index.ts +22 -0
  278. package/src/server/triggers/schedule.ts +567 -0
  279. package/src/server/types/Execution.ts +26 -0
  280. package/src/server/types/FlowNode.ts +21 -0
  281. package/src/server/types/Job.ts +18 -0
  282. package/src/server/types/Workflow.ts +36 -0
  283. package/src/server/types/index.ts +4 -0
  284. package/src/server/utils.ts +17 -0
  285. package/lib/client/triggers/schedule/DateFieldsSelect.d.ts +0 -2
  286. /package/lib/server/{models → types}/Execution.js +0 -0
  287. /package/lib/server/{models → types}/FlowNode.js +0 -0
  288. /package/lib/server/{models → types}/Job.js +0 -0
  289. /package/lib/server/{models → types}/Workflow.js +0 -0
@@ -0,0 +1,190 @@
1
+ import { SchemaInitializerItemOptions, useCollectionDataSource, useCollectionManager, useCompile } from '@nocobase/client';
2
+ import { CollectionBlockInitializer } from '../components/CollectionBlockInitializer';
3
+ import { FieldsSelect } from '../components/FieldsSelect';
4
+ import { NAMESPACE, lang } from '../locale';
5
+ import { appends, collection, filter } from '../schemas/collection';
6
+ import { getCollectionFieldOptions } from '../variable';
7
+
8
+ const COLLECTION_TRIGGER_MODE = {
9
+ CREATED: 1,
10
+ UPDATED: 2,
11
+ SAVED: 3,
12
+ DELETED: 4,
13
+ };
14
+
15
+ const collectionModeOptions = [
16
+ { label: `{{t("After record added", { ns: "${NAMESPACE}" })}}`, value: COLLECTION_TRIGGER_MODE.CREATED },
17
+ { label: `{{t("After record updated", { ns: "${NAMESPACE}" })}}`, value: COLLECTION_TRIGGER_MODE.UPDATED },
18
+ { label: `{{t("After record added or updated", { ns: "${NAMESPACE}" })}}`, value: COLLECTION_TRIGGER_MODE.SAVED },
19
+ { label: `{{t("After record deleted", { ns: "${NAMESPACE}" })}}`, value: COLLECTION_TRIGGER_MODE.DELETED },
20
+ ];
21
+
22
+ export default {
23
+ title: `{{t("Collection event", { ns: "${NAMESPACE}" })}}`,
24
+ type: 'collection',
25
+ fieldset: {
26
+ collection: {
27
+ ...collection,
28
+ ['x-reactions']: [
29
+ ...collection['x-reactions'],
30
+ {
31
+ target: 'changed',
32
+ effects: ['onFieldValueChange'],
33
+ fulfill: {
34
+ state: {
35
+ value: [],
36
+ },
37
+ },
38
+ },
39
+ {
40
+ target: 'condition',
41
+ effects: ['onFieldValueChange'],
42
+ fulfill: {
43
+ state: {
44
+ value: null,
45
+ },
46
+ },
47
+ },
48
+ {
49
+ target: 'appends',
50
+ effects: ['onFieldValueChange'],
51
+ fulfill: {
52
+ state: {
53
+ value: [],
54
+ },
55
+ },
56
+ },
57
+ ],
58
+ },
59
+ mode: {
60
+ type: 'number',
61
+ title: `{{t("Trigger on", { ns: "${NAMESPACE}" })}}`,
62
+ 'x-decorator': 'FormItem',
63
+ 'x-component': 'Select',
64
+ 'x-component-props': {
65
+ popupMatchSelectWidth: false,
66
+ options: collectionModeOptions,
67
+ placeholder: `{{t("Trigger on", { ns: "${NAMESPACE}" })}}`,
68
+ },
69
+ required: true,
70
+ 'x-reactions': [
71
+ {
72
+ dependencies: ['collection'],
73
+ fulfill: {
74
+ state: {
75
+ visible: '{{!!$deps[0]}}',
76
+ },
77
+ },
78
+ },
79
+ ],
80
+ },
81
+ changed: {
82
+ type: 'array',
83
+ title: `{{t("Changed fields", { ns: "${NAMESPACE}" })}}`,
84
+ description: `{{t("Triggered only if one of the selected fields changes. If unselected, it means that it will be triggered when any field changes. When record is added or deleted, any field is considered to have been changed.", { ns: "${NAMESPACE}" })}}`,
85
+ 'x-decorator': 'FormItem',
86
+ 'x-component': 'FieldsSelect',
87
+ 'x-component-props': {
88
+ className: 'full-width',
89
+ mode: 'multiple',
90
+ placeholder: '{{t("Select field")}}',
91
+ filter(field) {
92
+ return (
93
+ !field.hidden &&
94
+ (field.uiSchema ? !field.uiSchema['x-read-pretty'] : true) &&
95
+ !['linkTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(field.type)
96
+ );
97
+ },
98
+ },
99
+ 'x-reactions': [
100
+ {
101
+ dependencies: ['collection', 'mode'],
102
+ fulfill: {
103
+ state: {
104
+ visible: `{{!!$deps[0] && ($deps[1] & ${COLLECTION_TRIGGER_MODE.UPDATED})}}`,
105
+ },
106
+ },
107
+ },
108
+ ],
109
+ },
110
+ condition: {
111
+ ...filter,
112
+ title: `{{t("Only triggers when match conditions", { ns: "${NAMESPACE}" })}}`,
113
+ 'x-component-props': {
114
+ useProps: filter['x-component-props'].useProps,
115
+ },
116
+ 'x-reactions': [
117
+ {
118
+ dependencies: ['collection'],
119
+ fulfill: {
120
+ state: {
121
+ visible: '{{!!$deps[0]}}',
122
+ },
123
+ },
124
+ },
125
+ ],
126
+ },
127
+ appends: {
128
+ ...appends,
129
+ 'x-reactions': [
130
+ ...appends['x-reactions'],
131
+ {
132
+ dependencies: ['mode'],
133
+ fulfill: {
134
+ state: {
135
+ visible: `{{!($deps[0] & ${COLLECTION_TRIGGER_MODE.DELETED})}}`,
136
+ },
137
+ },
138
+ },
139
+ ],
140
+ },
141
+ },
142
+ scope: {
143
+ useCollectionDataSource,
144
+ },
145
+ components: {
146
+ FieldsSelect,
147
+ },
148
+ useVariables(config, options) {
149
+ const compile = useCompile();
150
+ const { getCollectionFields } = useCollectionManager();
151
+ const rootFields = [
152
+ {
153
+ collectionName: config.collection,
154
+ name: 'data',
155
+ type: 'hasOne',
156
+ target: config.collection,
157
+ uiSchema: {
158
+ title: lang('Trigger data'),
159
+ },
160
+ },
161
+ ];
162
+ // const depth = config.appends?.length
163
+ // ? config.appends.reduce((max, item) => Math.max(max, item.split('.').length), 1) + 1
164
+ // : 1;
165
+ const result = getCollectionFieldOptions({
166
+ // depth,
167
+ ...options,
168
+ fields: rootFields,
169
+ appends: ['data', ...(config.appends?.map((item) => `data.${item}`) || [])],
170
+ compile,
171
+ getCollectionFields,
172
+ });
173
+ return result;
174
+ },
175
+ useInitializers(config): SchemaInitializerItemOptions | null {
176
+ if (!config.collection) {
177
+ return null;
178
+ }
179
+
180
+ return {
181
+ type: 'item',
182
+ key: 'triggerData',
183
+ title: `{{t("Trigger data", { ns: "${NAMESPACE}" })}}`,
184
+ component: CollectionBlockInitializer,
185
+ collection: config.collection,
186
+ dataSource: '{{$context.data}}',
187
+ };
188
+ },
189
+ initializers: {},
190
+ };
@@ -0,0 +1,311 @@
1
+ import { InfoOutlined } from '@ant-design/icons';
2
+ import { createForm } from '@formily/core';
3
+ import { ISchema, useForm } from '@formily/react';
4
+ import {
5
+ ActionContextProvider,
6
+ SchemaComponent,
7
+ SchemaInitializerItemOptions,
8
+ css,
9
+ cx,
10
+ useAPIClient,
11
+ useActionContext,
12
+ useCompile,
13
+ useResourceActionContext,
14
+ } from '@nocobase/client';
15
+ import { Registry } from '@nocobase/utils/client';
16
+ import { Alert, Button, Input, Tag, message } from 'antd';
17
+ import React, { useEffect, useMemo, useState } from 'react';
18
+ import { useFlowContext } from '../FlowContext';
19
+ import { NAMESPACE, lang } from '../locale';
20
+ import useStyles from '../style';
21
+ import { VariableOptions } from '../variable';
22
+ import collection from './collection';
23
+ import schedule from './schedule/';
24
+
25
+ function useUpdateConfigAction() {
26
+ const form = useForm();
27
+ const api = useAPIClient();
28
+ const { workflow } = useFlowContext() ?? {};
29
+ const ctx = useActionContext();
30
+ const { refresh } = useResourceActionContext();
31
+ return {
32
+ async run() {
33
+ if (workflow.executed) {
34
+ message.error(lang('Trigger in executed workflow cannot be modified'));
35
+ return;
36
+ }
37
+ await form.submit();
38
+ await api.resource('workflows').update?.({
39
+ filterByTk: workflow.id,
40
+ values: {
41
+ config: form.values,
42
+ },
43
+ });
44
+ ctx.setVisible(false);
45
+ refresh();
46
+ },
47
+ };
48
+ }
49
+
50
+ export interface Trigger {
51
+ title: string;
52
+ type: string;
53
+ // group: string;
54
+ useVariables?(config: any, options?): VariableOptions;
55
+ fieldset: { [key: string]: ISchema };
56
+ view?: ISchema;
57
+ scope?: { [key: string]: any };
58
+ components?: { [key: string]: any };
59
+ useInitializers?(config): SchemaInitializerItemOptions | null;
60
+ initializers?: any;
61
+ }
62
+
63
+ export const triggers = new Registry<Trigger>();
64
+
65
+ triggers.register(collection.type, collection);
66
+ triggers.register(schedule.type, schedule);
67
+
68
+ function TriggerExecution() {
69
+ const compile = useCompile();
70
+ const { workflow, execution } = useFlowContext();
71
+ const { styles } = useStyles();
72
+
73
+ if (!execution) {
74
+ return null;
75
+ }
76
+
77
+ const trigger = triggers.get(workflow.type);
78
+
79
+ return (
80
+ <SchemaComponent
81
+ schema={{
82
+ type: 'void',
83
+ name: 'execution',
84
+ 'x-component': 'Action',
85
+ 'x-component-props': {
86
+ title: <InfoOutlined />,
87
+ shape: 'circle',
88
+ size: 'small',
89
+ className: styles.nodeJobButtonClass,
90
+ type: 'primary',
91
+ },
92
+ properties: {
93
+ [execution.id]: {
94
+ type: 'void',
95
+ 'x-decorator': 'Form',
96
+ 'x-decorator-props': {
97
+ initialValue: execution,
98
+ },
99
+ 'x-component': 'Action.Modal',
100
+ title: (
101
+ <div className={cx(styles.nodeTitleClass)}>
102
+ <Tag>{compile(trigger.title)}</Tag>
103
+ <strong>{workflow.title}</strong>
104
+ <span className="workflow-node-id">#{execution.id}</span>
105
+ </div>
106
+ ),
107
+ properties: {
108
+ createdAt: {
109
+ type: 'string',
110
+ title: `{{t("Triggered at", { ns: "${NAMESPACE}" })}}`,
111
+ 'x-decorator': 'FormItem',
112
+ 'x-component': 'DatePicker',
113
+ 'x-component-props': {
114
+ showTime: true,
115
+ },
116
+ 'x-read-pretty': true,
117
+ },
118
+ context: {
119
+ type: 'object',
120
+ title: `{{t("Trigger variables", { ns: "${NAMESPACE}" })}}`,
121
+ 'x-decorator': 'FormItem',
122
+ 'x-component': 'Input.JSON',
123
+ 'x-component-props': {
124
+ className: css`
125
+ padding: 1em;
126
+ background-color: #eee;
127
+ `,
128
+ },
129
+ 'x-read-pretty': true,
130
+ },
131
+ },
132
+ },
133
+ },
134
+ }}
135
+ />
136
+ );
137
+ }
138
+
139
+ export const TriggerConfig = () => {
140
+ const api = useAPIClient();
141
+ const compile = useCompile();
142
+ const { workflow, refresh } = useFlowContext();
143
+ const [editingTitle, setEditingTitle] = useState<string>('');
144
+ const [editingConfig, setEditingConfig] = useState(false);
145
+ const { styles } = useStyles();
146
+ let typeTitle = '';
147
+ useEffect(() => {
148
+ if (workflow) {
149
+ setEditingTitle(workflow.title ?? typeTitle);
150
+ }
151
+ }, [workflow]);
152
+
153
+ const form = useMemo(
154
+ () =>
155
+ createForm({
156
+ initialValues: workflow?.config,
157
+ values: workflow?.config,
158
+ disabled: workflow?.executed,
159
+ }),
160
+ [workflow],
161
+ );
162
+
163
+ if (!workflow || !workflow.type) {
164
+ return null;
165
+ }
166
+ const { title, type, executed } = workflow;
167
+ const trigger = triggers.get(type);
168
+ const { fieldset, scope, components } = trigger;
169
+ typeTitle = trigger.title;
170
+ const detailText = executed ? '{{t("View")}}' : '{{t("Configure")}}';
171
+ const titleText = `${lang('Trigger')}: ${compile(typeTitle)}`;
172
+
173
+ async function onChangeTitle(next) {
174
+ const t = next || typeTitle;
175
+ setEditingTitle(t);
176
+ if (t === title) {
177
+ return;
178
+ }
179
+ await api.resource('workflows').update?.({
180
+ filterByTk: workflow.id,
181
+ values: {
182
+ title: t,
183
+ },
184
+ });
185
+ refresh();
186
+ }
187
+
188
+ function onOpenDrawer(ev) {
189
+ if (ev.target === ev.currentTarget) {
190
+ setEditingConfig(true);
191
+ return;
192
+ }
193
+ const whiteSet = new Set(['workflow-node-meta', 'workflow-node-config-button', 'ant-input-disabled']);
194
+ for (let el = ev.target; el && el !== ev.currentTarget; el = el.parentNode) {
195
+ if ((Array.from(el.classList ?? []) as string[]).some((name: string) => whiteSet.has(name))) {
196
+ setEditingConfig(true);
197
+ ev.stopPropagation();
198
+ return;
199
+ }
200
+ }
201
+ }
202
+
203
+ return (
204
+ <div className={cx(styles.nodeCardClass)} onClick={onOpenDrawer}>
205
+ <div className={cx(styles.nodeMetaClass, 'workflow-node-meta')}>
206
+ <Tag color="gold">{titleText}</Tag>
207
+ </div>
208
+ <div>
209
+ <Input.TextArea
210
+ value={editingTitle}
211
+ onChange={(ev) => setEditingTitle(ev.target.value)}
212
+ onBlur={(ev) => onChangeTitle(ev.target.value)}
213
+ autoSize
214
+ />
215
+ </div>
216
+ <TriggerExecution />
217
+ <ActionContextProvider value={{ visible: editingConfig, setVisible: setEditingConfig }}>
218
+ <SchemaComponent
219
+ schema={{
220
+ name: `workflow-trigger-${workflow.id}`,
221
+ type: 'void',
222
+ properties: {
223
+ config: {
224
+ type: 'void',
225
+ 'x-content': detailText,
226
+ 'x-component': Button,
227
+ 'x-component-props': {
228
+ type: 'link',
229
+ className: 'workflow-node-config-button',
230
+ },
231
+ },
232
+ drawer: {
233
+ type: 'void',
234
+ title: titleText,
235
+ 'x-component': 'Action.Drawer',
236
+ 'x-decorator': 'FormV2',
237
+ 'x-decorator-props': {
238
+ form,
239
+ },
240
+ properties: {
241
+ ...(executed
242
+ ? {
243
+ alert: {
244
+ 'x-component': Alert,
245
+ 'x-component-props': {
246
+ type: 'warning',
247
+ showIcon: true,
248
+ message: `{{t("Trigger in executed workflow cannot be modified", { ns: "${NAMESPACE}" })}}`,
249
+ className: css`
250
+ width: 100%;
251
+ font-size: 85%;
252
+ margin-bottom: 2em;
253
+ `,
254
+ },
255
+ },
256
+ }
257
+ : {}),
258
+ fieldset: {
259
+ type: 'void',
260
+ 'x-component': 'fieldset',
261
+ 'x-component-props': {
262
+ className: css`
263
+ .ant-select:not(.full-width) {
264
+ width: auto;
265
+ min-width: 6em;
266
+ }
267
+ `,
268
+ },
269
+ properties: fieldset,
270
+ },
271
+ actions: {
272
+ ...(executed
273
+ ? {}
274
+ : {
275
+ type: 'void',
276
+ 'x-component': 'Action.Drawer.Footer',
277
+ properties: {
278
+ cancel: {
279
+ title: '{{t("Cancel")}}',
280
+ 'x-component': 'Action',
281
+ 'x-component-props': {
282
+ useAction: '{{ cm.useCancelAction }}',
283
+ },
284
+ },
285
+ submit: {
286
+ title: '{{t("Submit")}}',
287
+ 'x-component': 'Action',
288
+ 'x-component-props': {
289
+ type: 'primary',
290
+ useAction: useUpdateConfigAction,
291
+ },
292
+ },
293
+ },
294
+ }),
295
+ },
296
+ },
297
+ },
298
+ },
299
+ }}
300
+ scope={scope}
301
+ components={components}
302
+ />
303
+ </ActionContextProvider>
304
+ </div>
305
+ );
306
+ };
307
+
308
+ export function useTrigger() {
309
+ const { workflow } = useFlowContext();
310
+ return triggers.get(workflow.type);
311
+ }
@@ -0,0 +1,40 @@
1
+ import { css } from '@nocobase/client';
2
+ import { dayjs } from '@nocobase/utils/client';
3
+ import { DatePicker, Select } from 'antd';
4
+ import React from 'react';
5
+ import { useWorkflowTranslation } from '../../locale';
6
+ import { OnField } from './OnField';
7
+
8
+ export function EndsByField({ value, onChange }) {
9
+ const { t } = useWorkflowTranslation();
10
+ const type = value != null ? (typeof value === 'object' && !(value instanceof Date) ? 'field' : 'date') : null;
11
+ return (
12
+ <fieldset
13
+ className={css`
14
+ display: flex;
15
+ gap: 0.5em;
16
+ `}
17
+ >
18
+ <Select
19
+ value={type}
20
+ onChange={(t) => {
21
+ onChange(t ? (t === 'field' ? {} : new Date()) : null);
22
+ }}
23
+ >
24
+ <Select.Option value={null}>{t('No end')}</Select.Option>
25
+ <Select.Option value={'field'}>{t('By field')}</Select.Option>
26
+ <Select.Option value={'date'}>{t('By custom date')}</Select.Option>
27
+ </Select>
28
+ {type === 'field' ? <OnField value={value} onChange={onChange} /> : null}
29
+ {type === 'date' ? (
30
+ <DatePicker
31
+ showTime
32
+ value={dayjs(value)}
33
+ onChange={(v) => {
34
+ onChange(v ? v.toDate() : null);
35
+ }}
36
+ />
37
+ ) : null}
38
+ </fieldset>
39
+ );
40
+ }
@@ -0,0 +1,64 @@
1
+ import { css } from '@nocobase/client';
2
+ import { InputNumber, Select } from 'antd';
3
+ import React, { useState } from 'react';
4
+ import { useTranslation } from 'react-i18next';
5
+
6
+ import { FieldsSelect } from '../../components/FieldsSelect';
7
+ import { lang } from '../../locale';
8
+
9
+ function dateFieldFilter(field) {
10
+ return !field.hidden && (field.uiSchema ? field.type === 'date' : false);
11
+ }
12
+
13
+ export function OnField({ value, onChange }) {
14
+ const { t } = useTranslation();
15
+ const [dir, setDir] = useState(value.offset ? value.offset / Math.abs(value.offset) : 0);
16
+
17
+ return (
18
+ <fieldset
19
+ className={css`
20
+ display: flex;
21
+ gap: 0.5em;
22
+ `}
23
+ >
24
+ <FieldsSelect
25
+ value={value.field}
26
+ onChange={(field) => onChange({ ...value, field })}
27
+ filter={dateFieldFilter}
28
+ placeholder={t('Select field')}
29
+ />
30
+ {value.field ? (
31
+ <Select
32
+ value={dir}
33
+ onChange={(v) => {
34
+ setDir(v);
35
+ onChange({ ...value, offset: Math.abs(value.offset) * v });
36
+ }}
37
+ options={[
38
+ { value: 0, label: lang('Exactly at') },
39
+ { value: -1, label: t('Before') },
40
+ { value: 1, label: t('After') },
41
+ ]}
42
+ />
43
+ ) : null}
44
+ {dir ? (
45
+ <>
46
+ <InputNumber
47
+ value={Math.abs(value.offset)}
48
+ onChange={(v) => onChange({ ...value, offset: (v ?? 0) * dir })}
49
+ />
50
+ <Select
51
+ value={value.unit || 86400000}
52
+ onChange={(unit) => onChange({ ...value, unit })}
53
+ options={[
54
+ { value: 86400000, label: lang('Days') },
55
+ { value: 3600000, label: lang('Hours') },
56
+ { value: 60000, label: lang('Minutes') },
57
+ { value: 1000, label: lang('Seconds') },
58
+ ]}
59
+ />
60
+ </>
61
+ ) : null}
62
+ </fieldset>
63
+ );
64
+ }