@nocobase/plugin-workflow 0.10.0-alpha.5 → 0.11.0-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 (265) hide show
  1. package/client.d.ts +2 -3
  2. package/client.js +1 -30
  3. package/lib/client/AddButton.js +1 -8
  4. package/lib/client/Branch.js +8 -8
  5. package/lib/client/CanvasContent.js +8 -8
  6. package/lib/client/ExecutionCanvas.js +20 -27
  7. package/lib/client/ExecutionPage.js +1 -8
  8. package/lib/client/WorkflowCanvas.js +3 -10
  9. package/lib/client/WorkflowPage.js +1 -8
  10. package/lib/client/WorkflowProvider.js +3 -42
  11. package/lib/client/components/CollectionFieldset.d.ts +1 -1
  12. package/lib/client/components/CollectionFieldset.js +8 -15
  13. package/lib/client/components/Duration.js +5 -5
  14. package/lib/client/components/DynamicExpression.d.ts +3 -3
  15. package/lib/client/components/DynamicExpression.js +14 -4
  16. package/lib/client/components/FieldsSelect.d.ts +1 -1
  17. package/lib/client/components/FieldsSelect.js +6 -6
  18. package/lib/client/components/NodeDescription.js +11 -11
  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/nodes/aggregate.d.ts +10 -4
  25. package/lib/client/nodes/aggregate.js +12 -9
  26. package/lib/client/nodes/calculation.d.ts +11 -16
  27. package/lib/client/nodes/calculation.js +72 -52
  28. package/lib/client/nodes/condition.d.ts +2 -6
  29. package/lib/client/nodes/condition.js +20 -24
  30. package/lib/client/nodes/create.d.ts +8 -5
  31. package/lib/client/nodes/create.js +34 -7
  32. package/lib/client/nodes/destroy.d.ts +1 -1
  33. package/lib/client/nodes/index.d.ts +4 -4
  34. package/lib/client/nodes/index.js +79 -86
  35. package/lib/client/nodes/loop.d.ts +3 -1
  36. package/lib/client/nodes/loop.js +48 -35
  37. package/lib/client/nodes/manual/ModeConfig.js +23 -30
  38. package/lib/client/nodes/manual/SchemaConfig.d.ts +3 -3
  39. package/lib/client/nodes/manual/SchemaConfig.js +18 -17
  40. package/lib/client/nodes/manual/WorkflowTodo.js +66 -72
  41. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +2 -5
  42. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +6 -5
  43. package/lib/client/nodes/manual/forms/custom.js +11 -18
  44. package/lib/client/nodes/manual/index.d.ts +11 -5
  45. package/lib/client/nodes/manual/index.js +21 -10
  46. package/lib/client/nodes/parallel.js +20 -20
  47. package/lib/client/nodes/query.d.ts +7 -4
  48. package/lib/client/nodes/query.js +34 -7
  49. package/lib/client/nodes/request.d.ts +10 -6
  50. package/lib/client/nodes/request.js +37 -9
  51. package/lib/client/nodes/update.d.ts +2 -2
  52. package/lib/client/nodes/update.js +1 -1
  53. package/lib/client/schemas/collection.d.ts +1 -1
  54. package/lib/client/schemas/collection.js +3 -10
  55. package/lib/client/style.js +18 -18
  56. package/lib/client/triggers/collection.d.ts +4 -3
  57. package/lib/client/triggers/collection.js +21 -7
  58. package/lib/client/triggers/index.d.ts +2 -2
  59. package/lib/client/triggers/index.js +46 -52
  60. package/lib/client/triggers/schedule/DateFieldsSelect.js +1 -1
  61. package/lib/client/triggers/schedule/EndsByField.js +11 -11
  62. package/lib/client/triggers/schedule/OnField.js +11 -11
  63. package/lib/client/triggers/schedule/RepeatField.js +4 -4
  64. package/lib/client/triggers/schedule/ScheduleConfig.js +17 -24
  65. package/lib/client/triggers/schedule/index.d.ts +3 -4
  66. package/lib/client/triggers/schedule/index.js +21 -11
  67. package/lib/client/variable.d.ts +3 -4
  68. package/lib/client/variable.js +110 -45
  69. package/lib/server/Plugin.d.ts +2 -3
  70. package/lib/server/Plugin.js +8 -9
  71. package/lib/server/Processor.d.ts +2 -4
  72. package/lib/server/actions/nodes.js +7 -7
  73. package/lib/server/fields/expression-field.d.ts +1 -2
  74. package/lib/server/fields/expression-field.js +1 -8
  75. package/lib/server/functions/index.d.ts +2 -3
  76. package/lib/server/index.d.ts +1 -0
  77. package/lib/server/index.js +12 -0
  78. package/lib/server/instructions/aggregate.d.ts +1 -1
  79. package/lib/server/instructions/aggregate.js +5 -5
  80. package/lib/server/instructions/condition.d.ts +2 -1
  81. package/lib/server/instructions/create.d.ts +1 -1
  82. package/lib/server/instructions/delay.d.ts +3 -3
  83. package/lib/server/instructions/delay.js +66 -64
  84. package/lib/server/instructions/destroy.d.ts +1 -1
  85. package/lib/server/instructions/index.d.ts +5 -5
  86. package/lib/server/instructions/loop.d.ts +1 -2
  87. package/lib/server/instructions/manual/actions.js +1 -1
  88. package/lib/server/instructions/manual/forms/index.d.ts +1 -1
  89. package/lib/server/instructions/manual/index.d.ts +1 -1
  90. package/lib/server/instructions/parallel.d.ts +1 -2
  91. package/lib/server/instructions/query.d.ts +1 -1
  92. package/lib/server/instructions/request.d.ts +2 -2
  93. package/lib/server/instructions/request.js +1 -0
  94. package/lib/server/instructions/update.d.ts +1 -1
  95. package/lib/server/migrations/20230221071831-calculation-expression.js +1 -1
  96. package/lib/server/migrations/20230221121203-condition-calculation.js +1 -1
  97. package/lib/server/migrations/20230221162902-jsonb-to-json.js +7 -7
  98. package/lib/server/migrations/20230411034722-manual-multi-form.js +1 -8
  99. package/lib/server/triggers/collection.d.ts +1 -1
  100. package/lib/server/triggers/collection.js +2 -2
  101. package/lib/server/triggers/index.d.ts +1 -1
  102. package/lib/server/triggers/schedule.d.ts +1 -1
  103. package/lib/server/triggers/schedule.js +18 -18
  104. package/lib/server/{models → types}/Execution.d.ts +2 -3
  105. package/lib/server/{models → types}/FlowNode.d.ts +1 -2
  106. package/lib/server/{models → types}/Job.d.ts +1 -2
  107. package/lib/server/{models → types}/Workflow.d.ts +1 -2
  108. package/lib/server/types/index.d.ts +4 -0
  109. package/lib/server/types/index.js +5 -0
  110. package/package.json +40 -20
  111. package/server.d.ts +2 -3
  112. package/server.js +1 -30
  113. package/src/client/AddButton.tsx +99 -0
  114. package/src/client/Branch.tsx +35 -0
  115. package/src/client/CanvasContent.tsx +23 -0
  116. package/src/client/ExecutionCanvas.tsx +168 -0
  117. package/src/client/ExecutionLink.tsx +16 -0
  118. package/src/client/ExecutionPage.tsx +44 -0
  119. package/src/client/ExecutionResourceProvider.tsx +21 -0
  120. package/src/client/FlowContext.ts +7 -0
  121. package/src/client/WorkflowCanvas.tsx +220 -0
  122. package/src/client/WorkflowLink.tsx +16 -0
  123. package/src/client/WorkflowPage.tsx +51 -0
  124. package/src/client/WorkflowProvider.tsx +84 -0
  125. package/src/client/components/CollectionBlockInitializer.tsx +71 -0
  126. package/src/client/components/CollectionFieldset.tsx +158 -0
  127. package/src/client/components/Duration.tsx +45 -0
  128. package/src/client/components/DynamicExpression.tsx +53 -0
  129. package/src/client/components/FieldsSelect.tsx +28 -0
  130. package/src/client/components/FilterDynamicComponent.tsx +15 -0
  131. package/src/client/components/NodeDescription.tsx +44 -0
  132. package/src/client/components/NullRender.tsx +3 -0
  133. package/src/client/components/OpenDrawer.tsx +24 -0
  134. package/src/client/components/RadioWithTooltip.tsx +38 -0
  135. package/src/client/components/ValueBlock.tsx +67 -0
  136. package/src/client/components/renderEngineReference.tsx +30 -0
  137. package/src/client/constants.tsx +91 -0
  138. package/src/client/index.tsx +51 -0
  139. package/src/client/interfaces/expression.tsx +25 -0
  140. package/src/client/locale/en-US.ts +136 -0
  141. package/src/client/locale/es-ES.ts +129 -0
  142. package/src/client/locale/index.ts +18 -0
  143. package/src/client/locale/ja-JP.ts +90 -0
  144. package/src/client/locale/pt-BR.ts +136 -0
  145. package/src/client/locale/ru-RU.ts +90 -0
  146. package/src/client/locale/tr-TR.ts +90 -0
  147. package/src/client/locale/zh-CN.ts +242 -0
  148. package/src/client/nodes/aggregate.tsx +327 -0
  149. package/src/client/nodes/calculation.tsx +217 -0
  150. package/src/client/nodes/condition.tsx +490 -0
  151. package/src/client/nodes/create.tsx +86 -0
  152. package/src/client/nodes/delay.tsx +37 -0
  153. package/src/client/nodes/destroy.tsx +34 -0
  154. package/src/client/nodes/index.tsx +489 -0
  155. package/src/client/nodes/loop.tsx +159 -0
  156. package/src/client/nodes/manual/AssigneesSelect.tsx +33 -0
  157. package/src/client/nodes/manual/DetailsBlockProvider.tsx +80 -0
  158. package/src/client/nodes/manual/FormBlockInitializer.tsx +68 -0
  159. package/src/client/nodes/manual/FormBlockProvider.tsx +75 -0
  160. package/src/client/nodes/manual/ModeConfig.tsx +84 -0
  161. package/src/client/nodes/manual/SchemaConfig.tsx +365 -0
  162. package/src/client/nodes/manual/WorkflowTodo.tsx +611 -0
  163. package/src/client/nodes/manual/WorkflowTodoBlockInitializer.tsx +28 -0
  164. package/src/client/nodes/manual/forms/create.tsx +88 -0
  165. package/src/client/nodes/manual/forms/custom.tsx +388 -0
  166. package/src/client/nodes/manual/forms/update.tsx +130 -0
  167. package/src/client/nodes/manual/index.tsx +162 -0
  168. package/src/client/nodes/manual/utils.ts +28 -0
  169. package/src/client/nodes/parallel.tsx +137 -0
  170. package/src/client/nodes/query.tsx +89 -0
  171. package/src/client/nodes/request.tsx +185 -0
  172. package/src/client/nodes/update.tsx +99 -0
  173. package/src/client/schemas/collection.ts +75 -0
  174. package/src/client/schemas/executions.tsx +169 -0
  175. package/src/client/schemas/workflows.ts +364 -0
  176. package/src/client/style.tsx +312 -0
  177. package/src/client/triggers/collection.tsx +186 -0
  178. package/src/client/triggers/index.tsx +307 -0
  179. package/src/client/triggers/schedule/DateFieldsSelect.tsx +28 -0
  180. package/src/client/triggers/schedule/EndsByField.tsx +40 -0
  181. package/src/client/triggers/schedule/OnField.tsx +50 -0
  182. package/src/client/triggers/schedule/RepeatField.tsx +116 -0
  183. package/src/client/triggers/schedule/ScheduleConfig.tsx +225 -0
  184. package/src/client/triggers/schedule/constants.ts +4 -0
  185. package/src/client/triggers/schedule/index.tsx +72 -0
  186. package/src/client/triggers/schedule/locale/Cron.zh-CN.ts +79 -0
  187. package/src/client/utils.ts +36 -0
  188. package/src/client/variable.tsx +296 -0
  189. package/src/index.ts +1 -0
  190. package/src/server/Plugin.ts +351 -0
  191. package/src/server/Processor.ts +354 -0
  192. package/src/server/__tests__/Plugin.test.ts +398 -0
  193. package/src/server/__tests__/Processor.test.ts +474 -0
  194. package/src/server/__tests__/actions/workflows.test.ts +419 -0
  195. package/src/server/__tests__/collections/categories.ts +23 -0
  196. package/src/server/__tests__/collections/comments.ts +24 -0
  197. package/src/server/__tests__/collections/posts.ts +42 -0
  198. package/src/server/__tests__/collections/replies.ts +9 -0
  199. package/src/server/__tests__/collections/tags.ts +15 -0
  200. package/src/server/__tests__/index.ts +89 -0
  201. package/src/server/__tests__/instructions/aggregate.test.ts +294 -0
  202. package/src/server/__tests__/instructions/calculation.test.ts +265 -0
  203. package/src/server/__tests__/instructions/condition.test.ts +335 -0
  204. package/src/server/__tests__/instructions/create.test.ts +129 -0
  205. package/src/server/__tests__/instructions/delay.test.ts +182 -0
  206. package/src/server/__tests__/instructions/destroy.test.ts +58 -0
  207. package/src/server/__tests__/instructions/loop.test.ts +331 -0
  208. package/src/server/__tests__/instructions/manual.test.ts +854 -0
  209. package/src/server/__tests__/instructions/parallel.test.ts +445 -0
  210. package/src/server/__tests__/instructions/query.test.ts +359 -0
  211. package/src/server/__tests__/instructions/request.test.ts +217 -0
  212. package/src/server/__tests__/instructions/update.test.ts +189 -0
  213. package/src/server/__tests__/triggers/collection.test.ts +298 -0
  214. package/src/server/__tests__/triggers/schedule.test.ts +369 -0
  215. package/src/server/actions/index.ts +25 -0
  216. package/src/server/actions/nodes.ts +214 -0
  217. package/src/server/actions/workflows.ts +178 -0
  218. package/src/server/collections/executions.ts +35 -0
  219. package/src/server/collections/flow_nodes.ts +54 -0
  220. package/src/server/collections/jobs.ts +31 -0
  221. package/src/server/collections/workflows.ts +88 -0
  222. package/src/server/constants.ts +26 -0
  223. package/src/server/fields/expression-field.ts +11 -0
  224. package/src/server/fields/index.ts +7 -0
  225. package/src/server/functions/index.ts +16 -0
  226. package/src/server/index.ts +6 -0
  227. package/src/server/instructions/aggregate.ts +42 -0
  228. package/src/server/instructions/calculation.ts +41 -0
  229. package/src/server/instructions/condition.ts +172 -0
  230. package/src/server/instructions/create.ts +37 -0
  231. package/src/server/instructions/delay.ts +105 -0
  232. package/src/server/instructions/destroy.ts +23 -0
  233. package/src/server/instructions/index.ts +63 -0
  234. package/src/server/instructions/loop.ts +99 -0
  235. package/src/server/instructions/manual/actions.ts +79 -0
  236. package/src/server/instructions/manual/collecions/jobs.ts +17 -0
  237. package/src/server/instructions/manual/collecions/users.ts +15 -0
  238. package/src/server/instructions/manual/collecions/users_jobs.ts +50 -0
  239. package/src/server/instructions/manual/forms/create.ts +22 -0
  240. package/src/server/instructions/manual/forms/index.ts +12 -0
  241. package/src/server/instructions/manual/forms/update.ts +22 -0
  242. package/src/server/instructions/manual/index.ts +184 -0
  243. package/src/server/instructions/parallel.ts +121 -0
  244. package/src/server/instructions/query.ts +31 -0
  245. package/src/server/instructions/request.ts +87 -0
  246. package/src/server/instructions/update.ts +24 -0
  247. package/src/server/migrations/20221129153547-calculation-variables.ts +64 -0
  248. package/src/server/migrations/20230221032941-change-request-body-type.ts +76 -0
  249. package/src/server/migrations/20230221071831-calculation-expression.ts +102 -0
  250. package/src/server/migrations/20230221121203-condition-calculation.ts +82 -0
  251. package/src/server/migrations/20230221162902-jsonb-to-json.ts +51 -0
  252. package/src/server/migrations/20230411034722-manual-multi-form.ts +282 -0
  253. package/src/server/migrations/20230612021134-manual-collection-block.ts +138 -0
  254. package/src/server/triggers/collection.ts +142 -0
  255. package/src/server/triggers/index.ts +22 -0
  256. package/src/server/triggers/schedule.ts +567 -0
  257. package/src/server/types/Execution.ts +26 -0
  258. package/src/server/types/FlowNode.ts +21 -0
  259. package/src/server/types/Job.ts +18 -0
  260. package/src/server/types/Workflow.ts +36 -0
  261. package/src/server/types/index.ts +4 -0
  262. /package/lib/server/{models → types}/Execution.js +0 -0
  263. /package/lib/server/{models → types}/FlowNode.js +0 -0
  264. /package/lib/server/{models → types}/Job.js +0 -0
  265. /package/lib/server/{models → types}/Workflow.js +0 -0
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { Link } from 'react-router-dom';
4
+
5
+ import { useActionContext, useRecord } from '@nocobase/client';
6
+
7
+ export const WorkflowLink = () => {
8
+ const { t } = useTranslation();
9
+ const { id } = useRecord();
10
+ const { setVisible } = useActionContext();
11
+ return (
12
+ <Link to={`/admin/settings/workflow/workflows/${id}`} onClick={() => setVisible(false)}>
13
+ {t('View')}
14
+ </Link>
15
+ );
16
+ };
@@ -0,0 +1,51 @@
1
+ import { cx, SchemaComponent } from '@nocobase/client';
2
+ import React from 'react';
3
+ import { useParams } from 'react-router-dom';
4
+ import { workflowPageClass } from './style';
5
+ import { WorkflowCanvas } from './WorkflowCanvas';
6
+
7
+ export const WorkflowPage = () => {
8
+ const params = useParams<any>();
9
+
10
+ return (
11
+ <div className={cx(workflowPageClass)}>
12
+ <SchemaComponent
13
+ schema={{
14
+ type: 'void',
15
+ properties: {
16
+ [`provider_${params.id}`]: {
17
+ type: 'void',
18
+ 'x-decorator': 'ResourceActionProvider',
19
+ 'x-decorator-props': {
20
+ collection: {
21
+ name: 'workflows',
22
+ fields: [],
23
+ },
24
+ resourceName: 'workflows',
25
+ request: {
26
+ resource: 'workflows',
27
+ action: 'get',
28
+ params: {
29
+ filter: { id: params.id },
30
+ appends: [
31
+ 'nodes',
32
+ 'revisions.id',
33
+ 'revisions.createdAt',
34
+ 'revisions.current',
35
+ 'revisions.executed',
36
+ 'revisions.enabled',
37
+ ],
38
+ },
39
+ },
40
+ },
41
+ 'x-component': 'WorkflowCanvas',
42
+ },
43
+ },
44
+ }}
45
+ components={{
46
+ WorkflowCanvas,
47
+ }}
48
+ />
49
+ </div>
50
+ );
51
+ };
@@ -0,0 +1,84 @@
1
+ import {
2
+ CollectionManagerContext,
3
+ PluginManagerContext,
4
+ SchemaComponent,
5
+ SettingsCenterProvider,
6
+ } from '@nocobase/client';
7
+ import { Card } from 'antd';
8
+ import React, { useContext } from 'react';
9
+ import OpenDrawer from './components/OpenDrawer';
10
+ import { ExecutionLink } from './ExecutionLink';
11
+ import { ExecutionResourceProvider } from './ExecutionResourceProvider';
12
+ import expressionField from './interfaces/expression';
13
+ import { lang } from './locale';
14
+ import { instructions } from './nodes';
15
+ import { workflowSchema } from './schemas/workflows';
16
+ import { triggers } from './triggers';
17
+ import { WorkflowLink } from './WorkflowLink';
18
+
19
+ // registerField(expressionField.group, 'expression', expressionField);
20
+
21
+ export const WorkflowContext = React.createContext({});
22
+
23
+ export function useWorkflowContext() {
24
+ return useContext(WorkflowContext);
25
+ }
26
+
27
+ function WorkflowPane() {
28
+ return (
29
+ <Card bordered={false}>
30
+ <SchemaComponent
31
+ schema={workflowSchema}
32
+ components={{
33
+ WorkflowLink,
34
+ ExecutionResourceProvider,
35
+ ExecutionLink,
36
+ OpenDrawer,
37
+ }}
38
+ />
39
+ </Card>
40
+ );
41
+ }
42
+
43
+ export const WorkflowProvider = (props) => {
44
+ const pmCtx = useContext(PluginManagerContext);
45
+ const cmCtx = useContext(CollectionManagerContext);
46
+ return (
47
+ <SettingsCenterProvider
48
+ settings={{
49
+ workflow: {
50
+ icon: 'PartitionOutlined',
51
+ // title: `{{t("Workflow", { ns: "${NAMESPACE}" })}}`,
52
+ title: lang('Workflow'),
53
+ tabs: {
54
+ workflows: {
55
+ isBookmark: true,
56
+ title: lang('Workflow'),
57
+ component: WorkflowPane,
58
+ },
59
+ },
60
+ },
61
+ }}
62
+ >
63
+ <PluginManagerContext.Provider
64
+ value={{
65
+ components: {
66
+ ...pmCtx?.components,
67
+ },
68
+ }}
69
+ >
70
+ <CollectionManagerContext.Provider
71
+ value={{
72
+ ...cmCtx,
73
+ interfaces: {
74
+ ...cmCtx.interfaces,
75
+ expression: expressionField,
76
+ },
77
+ }}
78
+ >
79
+ <WorkflowContext.Provider value={{ triggers, instructions }}>{props.children}</WorkflowContext.Provider>
80
+ </CollectionManagerContext.Provider>
81
+ </PluginManagerContext.Provider>
82
+ </SettingsCenterProvider>
83
+ );
84
+ };
@@ -0,0 +1,71 @@
1
+ import React from 'react';
2
+
3
+ import {
4
+ CollectionProvider,
5
+ SchemaInitializer,
6
+ SchemaInitializerItemOptions,
7
+ useCollectionManager,
8
+ useRecordCollectionDataSourceItems,
9
+ useSchemaTemplateManager,
10
+ } from '@nocobase/client';
11
+ import { traverseSchema } from '../nodes/manual/utils';
12
+
13
+ function InnerCollectionBlockInitializer({ insert, collection, dataSource, ...props }) {
14
+ const { getTemplateSchemaByMode } = useSchemaTemplateManager();
15
+ const { getCollection } = useCollectionManager();
16
+ const items = useRecordCollectionDataSourceItems('FormItem') as SchemaInitializerItemOptions[];
17
+ const resovledCollection = getCollection(collection);
18
+
19
+ async function onConfirm({ item }) {
20
+ const template = item.template ? await getTemplateSchemaByMode(item) : null;
21
+ const result = {
22
+ type: 'void',
23
+ name: resovledCollection.name,
24
+ title: resovledCollection.title,
25
+ 'x-decorator': 'DetailsBlockProvider',
26
+ 'x-decorator-props': {
27
+ collection,
28
+ dataSource,
29
+ },
30
+ 'x-component': 'CardItem',
31
+ 'x-component-props': {
32
+ title: props.title,
33
+ },
34
+ 'x-designer': 'SimpleDesigner',
35
+ properties: {
36
+ grid: {
37
+ type: 'void',
38
+ 'x-component': 'FormV2',
39
+ 'x-component-props': {
40
+ useProps: '{{useDetailsBlockProps}}',
41
+ },
42
+ 'x-read-pretty': true,
43
+ properties: {
44
+ grid: template || {
45
+ type: 'void',
46
+ 'x-component': 'Grid',
47
+ 'x-initializer': 'ReadPrettyFormItemInitializers',
48
+ properties: {},
49
+ },
50
+ },
51
+ },
52
+ },
53
+ };
54
+ traverseSchema(result, (node) => {
55
+ if (node['x-uid']) {
56
+ delete node['x-uid'];
57
+ }
58
+ });
59
+ insert(result);
60
+ }
61
+
62
+ return <SchemaInitializer.Item {...props} onClick={onConfirm} items={items} />;
63
+ }
64
+
65
+ export function CollectionBlockInitializer(props) {
66
+ return (
67
+ <CollectionProvider collection={props.collection}>
68
+ <InnerCollectionBlockInitializer {...props} />
69
+ </CollectionProvider>
70
+ );
71
+ }
@@ -0,0 +1,158 @@
1
+ import { CloseCircleOutlined, PlusOutlined } from '@ant-design/icons';
2
+ import { observer, useField, useForm } from '@formily/react';
3
+ import {
4
+ CollectionField,
5
+ CollectionProvider,
6
+ css,
7
+ SchemaComponent,
8
+ useCollectionManager,
9
+ useCompile,
10
+ Variable,
11
+ } from '@nocobase/client';
12
+ import { Button, Dropdown, Form, Input, MenuProps } from 'antd';
13
+ import React, { useMemo } from 'react';
14
+ import { useTranslation } from 'react-i18next';
15
+ import { lang } from '../locale';
16
+ import { useWorkflowVariableOptions } from '../variable';
17
+
18
+ function AssociationInput(props) {
19
+ const { getCollectionFields } = useCollectionManager();
20
+ const { path } = useField();
21
+ const fieldName = path.segments[path.segments.length - 1] as string;
22
+ const { values: config } = useForm();
23
+ const fields = getCollectionFields(config?.collection);
24
+ const { type } = fields.find((item) => item.name === fieldName);
25
+
26
+ const value = Array.isArray(props.value) ? props.value.join(',') : props.value;
27
+ function onChange(ev) {
28
+ const trimed = ev.target.value.trim();
29
+ props.onChange(['belongsTo', 'hasOne'].includes(type) ? trimed : trimed.split(/[,\s]+/));
30
+ }
31
+ return <Input {...props} value={value} onChange={onChange} />;
32
+ }
33
+
34
+ export function useCollectionUIFields(collection) {
35
+ const { getCollectionFields } = useCollectionManager();
36
+
37
+ return getCollectionFields(collection).filter(
38
+ (field) => !field.hidden && (field.uiSchema ? !field.uiSchema['x-read-pretty'] : false),
39
+ );
40
+ }
41
+
42
+ // NOTE: observer for watching useProps
43
+ const CollectionFieldSet = observer(
44
+ ({ value, disabled, onChange, filter }: any) => {
45
+ const { t } = useTranslation();
46
+ const compile = useCompile();
47
+ const form = useForm();
48
+ const { getCollection } = useCollectionManager();
49
+ const scope = useWorkflowVariableOptions();
50
+ const { values: config } = form;
51
+ const collectionName = config?.collection;
52
+ const collectionFields = useCollectionUIFields(collectionName);
53
+ const fields = filter ? collectionFields.filter(filter.bind(config)) : collectionFields;
54
+
55
+ const unassignedFields = useMemo(() => fields.filter((field) => !value || !(field.name in value)), [fields, value]);
56
+ const mergedDisabled = disabled || form.disabled;
57
+ const menu = useMemo<MenuProps>(() => {
58
+ return {
59
+ onClick: ({ key }) => {
60
+ onChange({ ...value, [key]: null });
61
+ },
62
+ style: {
63
+ maxHeight: 300,
64
+ overflowY: 'auto',
65
+ },
66
+ items: unassignedFields.map((field) => ({
67
+ key: field.name,
68
+ label: compile(field.uiSchema?.title ?? field.name),
69
+ })),
70
+ };
71
+ }, [onChange, unassignedFields, value]);
72
+
73
+ return (
74
+ <fieldset
75
+ className={css`
76
+ margin-top: 0.5em;
77
+
78
+ > .ant-formily-item {
79
+ flex-direction: column;
80
+
81
+ > .ant-formily-item-label {
82
+ line-height: 32px;
83
+ }
84
+ }
85
+ `}
86
+ >
87
+ {fields.length ? (
88
+ <CollectionProvider collection={getCollection(collectionName)}>
89
+ {fields
90
+ .filter((field) => value && field.name in value)
91
+ .map((field) => {
92
+ // constant for associations to use Input, others to use CollectionField
93
+ // dynamic values only support belongsTo/hasOne association, other association type should disable
94
+ const ConstantCompoent = ['belongsTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(field.type)
95
+ ? AssociationInput
96
+ : CollectionField;
97
+ // TODO: try to use <ObjectField> to replace this map
98
+ return (
99
+ <Form.Item
100
+ key={field.name}
101
+ label={compile(field.uiSchema?.title ?? field.name)}
102
+ labelAlign="left"
103
+ className={css`
104
+ .ant-form-item-control-input-content {
105
+ display: flex;
106
+ }
107
+ `}
108
+ >
109
+ <Variable.Input
110
+ scope={scope}
111
+ value={value[field.name]}
112
+ onChange={(next) => {
113
+ onChange({ ...value, [field.name]: next });
114
+ }}
115
+ >
116
+ <SchemaComponent
117
+ schema={{
118
+ type: 'void',
119
+ properties: {
120
+ [field.name]: {
121
+ 'x-component': ConstantCompoent,
122
+ ['x-validator']() {
123
+ return '';
124
+ },
125
+ },
126
+ },
127
+ }}
128
+ />
129
+ </Variable.Input>
130
+ {!mergedDisabled ? (
131
+ <Button
132
+ type="link"
133
+ icon={<CloseCircleOutlined />}
134
+ onClick={() => {
135
+ const { [field.name]: _, ...rest } = value;
136
+ onChange(rest);
137
+ }}
138
+ />
139
+ ) : null}
140
+ </Form.Item>
141
+ );
142
+ })}
143
+ {unassignedFields.length ? (
144
+ <Dropdown menu={menu}>
145
+ <Button icon={<PlusOutlined />}>{t('Add field')}</Button>
146
+ </Dropdown>
147
+ ) : null}
148
+ </CollectionProvider>
149
+ ) : (
150
+ <p>{lang('Please select collection first')}</p>
151
+ )}
152
+ </fieldset>
153
+ );
154
+ },
155
+ { displayName: 'CollectionFieldSet' },
156
+ );
157
+
158
+ export default CollectionFieldSet;
@@ -0,0 +1,45 @@
1
+ import { css } from '@nocobase/client';
2
+ import { InputNumber, Select } from 'antd';
3
+ import React from 'react';
4
+ import { lang } from '../locale';
5
+
6
+ const UnitOptions = [
7
+ { value: 1_000, label: 'Seconds' },
8
+ { value: 60_000, label: 'Minutes' },
9
+ { value: 3600_000, label: 'Hours' },
10
+ { value: 86400_000, label: 'Days' },
11
+ { value: 604800_000, label: 'Weeks' },
12
+ ];
13
+
14
+ function getNumberOption(v) {
15
+ return UnitOptions.slice()
16
+ .reverse()
17
+ .find((item) => !(v % item.value));
18
+ }
19
+
20
+ export default function ({ value = 60000, onChange }) {
21
+ const option = getNumberOption(value);
22
+ const quantity = Math.round(value / option.value);
23
+
24
+ return (
25
+ <fieldset
26
+ className={css`
27
+ display: flex;
28
+ gap: 0.5em;
29
+ `}
30
+ >
31
+ <InputNumber min={1} value={quantity} onChange={(v) => onChange(Math.round(v * option.value))} />
32
+ <Select
33
+ popupMatchSelectWidth={false}
34
+ value={option.value}
35
+ onChange={(unit) => onChange(Math.round(quantity * unit))}
36
+ >
37
+ {UnitOptions.map((item) => (
38
+ <Select.Option key={item.value} value={item.value}>
39
+ {lang(item.label)}
40
+ </Select.Option>
41
+ ))}
42
+ </Select>
43
+ </fieldset>
44
+ );
45
+ }
@@ -0,0 +1,53 @@
1
+ import { onFieldInputValueChange, onFormInitialValuesChange } from '@formily/core';
2
+ import { connect, mapReadPretty, observer, useForm, useFormEffects } from '@formily/react';
3
+ import { Tag } from 'antd';
4
+ import React, { useMemo, useState } from 'react';
5
+ import { useTranslation } from 'react-i18next';
6
+
7
+ import { useCollectionManager, useCompile, useRecord, Variable } from '@nocobase/client';
8
+
9
+ import { NAMESPACE } from '../locale';
10
+ import { getCollectionFieldOptions } from '../variable';
11
+
12
+ const InternalExpression = observer(
13
+ (props: any) => {
14
+ const { onChange } = props;
15
+ const { values } = useForm();
16
+ const [collection, setCollection] = useState(values?.sourceCollection);
17
+ const compile = useCompile();
18
+ const { getCollectionFields } = useCollectionManager();
19
+
20
+ useFormEffects(() => {
21
+ onFormInitialValuesChange((form) => {
22
+ setCollection(form.values.sourceCollection);
23
+ });
24
+ onFieldInputValueChange('sourceCollection', (f) => {
25
+ setCollection(f.value);
26
+ onChange(null);
27
+ });
28
+ });
29
+
30
+ const options = getCollectionFieldOptions({ collection, compile, getCollectionFields });
31
+
32
+ return <Variable.TextArea {...props} scope={options} />;
33
+ },
34
+ { displayName: 'InternalExpression' },
35
+ );
36
+
37
+ function Result(props) {
38
+ const { t } = useTranslation();
39
+ const values = useRecord();
40
+ const compile = useCompile();
41
+ const { getCollectionFields } = useCollectionManager();
42
+ const options = useMemo(
43
+ () => getCollectionFieldOptions({ collection: values.sourceCollection, compile, getCollectionFields }),
44
+ [values.sourceCollection, values.sourceCollection],
45
+ );
46
+ return props.value ? (
47
+ <Variable.TextArea {...props} scope={options} />
48
+ ) : (
49
+ <Tag>{t('Unconfigured', { ns: NAMESPACE })}</Tag>
50
+ );
51
+ }
52
+
53
+ export const DynamicExpression = connect(InternalExpression, mapReadPretty(Result));
@@ -0,0 +1,28 @@
1
+ import { observer, useForm } from '@formily/react';
2
+ import { Select } from 'antd';
3
+ import React from 'react';
4
+
5
+ import { useCollectionManager, useCompile } from '@nocobase/client';
6
+
7
+ export const FieldsSelect = observer(
8
+ (props: any) => {
9
+ const { filter = () => true, ...others } = props;
10
+ const compile = useCompile();
11
+ const { getCollectionFields } = useCollectionManager();
12
+ const { values } = useForm();
13
+ const fields = getCollectionFields(values?.collection);
14
+
15
+ return (
16
+ <Select
17
+ className="full-width"
18
+ popupMatchSelectWidth={false}
19
+ {...others}
20
+ options={fields.filter(filter).map((field) => ({
21
+ label: compile(field.uiSchema?.title),
22
+ value: field.name,
23
+ }))}
24
+ />
25
+ );
26
+ },
27
+ { displayName: 'FieldsSelect' },
28
+ );
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+
3
+ import { Variable } from '@nocobase/client';
4
+
5
+ import { useWorkflowVariableOptions } from '../variable';
6
+
7
+ export function FilterDynamicComponent({ value, onChange, renderSchemaComponent }) {
8
+ const scope = useWorkflowVariableOptions();
9
+
10
+ return (
11
+ <Variable.Input value={value} onChange={onChange} scope={scope}>
12
+ {renderSchemaComponent()}
13
+ </Variable.Input>
14
+ );
15
+ }
@@ -0,0 +1,44 @@
1
+ import { css, cx } from '@nocobase/client';
2
+ import { Tag } from 'antd';
3
+ import React from 'react';
4
+ import { lang } from '../locale';
5
+
6
+ export function NodeDescription(props) {
7
+ const { instruction } = props;
8
+ const className = css`
9
+ margin-bottom: 1.5em;
10
+ padding: 1em;
11
+ background: #f6f6f6;
12
+
13
+ > *:last-child {
14
+ margin-bottom: 0;
15
+ }
16
+
17
+ dl {
18
+ display: flex;
19
+
20
+ dt {
21
+ &:after {
22
+ content: ':';
23
+ margin-right: 0.5em;
24
+ }
25
+ }
26
+ }
27
+
28
+ p {
29
+ color: rgba(0, 0, 0, 0.45);
30
+ }
31
+ `;
32
+
33
+ return (
34
+ <div className={cx(className, props.className)}>
35
+ <dl>
36
+ <dt>{lang('Node type')}</dt>
37
+ <dd>
38
+ <Tag>{instruction.title}</Tag>
39
+ </dd>
40
+ </dl>
41
+ {instruction.description ? <p>{instruction.description}</p> : null}
42
+ </div>
43
+ );
44
+ }
@@ -0,0 +1,3 @@
1
+ export function NullRender() {
2
+ return null;
3
+ }
@@ -0,0 +1,24 @@
1
+ import React, { useState } from 'react';
2
+ import { useFieldSchema } from '@formily/react';
3
+
4
+ import { ActionContextProvider, SchemaComponent } from '@nocobase/client';
5
+
6
+ export default function ({ component = 'div', children, ...props }) {
7
+ const [visible, setVisible] = useState(false);
8
+ const fieldSchema = useFieldSchema();
9
+ return (
10
+ <ActionContextProvider value={{ visible, setVisible, fieldSchema }}>
11
+ {React.createElement(
12
+ component,
13
+ {
14
+ ...props,
15
+ onClick() {
16
+ setVisible(true);
17
+ },
18
+ },
19
+ children,
20
+ )}
21
+ <SchemaComponent schema={fieldSchema} onlyRenderProperties />
22
+ </ActionContextProvider>
23
+ );
24
+ }
@@ -0,0 +1,38 @@
1
+ import { QuestionCircleOutlined } from '@ant-design/icons';
2
+ import { css, useCompile } from '@nocobase/client';
3
+ import { Radio, Tooltip } from 'antd';
4
+ import React from 'react';
5
+
6
+ export interface RadioWithTooltipOption {
7
+ value: any;
8
+ label: string;
9
+ tooltip?: string;
10
+ }
11
+
12
+ export function RadioWithTooltip(props) {
13
+ const { options = [], ...other } = props;
14
+ const compile = useCompile();
15
+
16
+ return (
17
+ <Radio.Group {...other}>
18
+ {options.map((option) => (
19
+ <Radio key={option.value} value={option.value}>
20
+ <span
21
+ className={css`
22
+ & + .anticon {
23
+ margin-left: 0.25em;
24
+ }
25
+ `}
26
+ >
27
+ {compile(option.label)}
28
+ </span>
29
+ {option.tooltip && (
30
+ <Tooltip title={compile(option.tooltip)}>
31
+ <QuestionCircleOutlined style={{ color: '#666' }} />
32
+ </Tooltip>
33
+ )}
34
+ </Radio>
35
+ ))}
36
+ </Radio.Group>
37
+ );
38
+ }