@nocobase/plugin-workflow 0.10.1-alpha.1 → 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 (260) 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/FieldsSelect.d.ts +1 -1
  16. package/lib/client/components/FieldsSelect.js +6 -6
  17. package/lib/client/components/NodeDescription.js +11 -11
  18. package/lib/client/components/RadioWithTooltip.js +13 -20
  19. package/lib/client/components/ValueBlock.js +14 -21
  20. package/lib/client/components/renderEngineReference.js +1 -8
  21. package/lib/client/index.d.ts +12 -4
  22. package/lib/client/index.js +78 -15
  23. package/lib/client/nodes/aggregate.d.ts +2 -2
  24. package/lib/client/nodes/aggregate.js +1 -1
  25. package/lib/client/nodes/calculation.d.ts +1 -1
  26. package/lib/client/nodes/calculation.js +16 -23
  27. package/lib/client/nodes/condition.d.ts +1 -3
  28. package/lib/client/nodes/condition.js +13 -20
  29. package/lib/client/nodes/create.d.ts +4 -3
  30. package/lib/client/nodes/destroy.d.ts +1 -1
  31. package/lib/client/nodes/index.d.ts +2 -2
  32. package/lib/client/nodes/index.js +79 -86
  33. package/lib/client/nodes/loop.d.ts +1 -1
  34. package/lib/client/nodes/loop.js +35 -34
  35. package/lib/client/nodes/manual/ModeConfig.js +23 -30
  36. package/lib/client/nodes/manual/SchemaConfig.d.ts +3 -3
  37. package/lib/client/nodes/manual/SchemaConfig.js +18 -17
  38. package/lib/client/nodes/manual/WorkflowTodo.js +61 -69
  39. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +2 -5
  40. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +6 -5
  41. package/lib/client/nodes/manual/forms/custom.js +11 -18
  42. package/lib/client/nodes/parallel.js +20 -20
  43. package/lib/client/nodes/query.d.ts +3 -2
  44. package/lib/client/nodes/request.d.ts +2 -2
  45. package/lib/client/nodes/request.js +7 -7
  46. package/lib/client/nodes/update.d.ts +2 -2
  47. package/lib/client/nodes/update.js +1 -1
  48. package/lib/client/schemas/collection.d.ts +1 -1
  49. package/lib/client/schemas/collection.js +3 -10
  50. package/lib/client/style.js +18 -18
  51. package/lib/client/triggers/collection.d.ts +4 -3
  52. package/lib/client/triggers/collection.js +1 -1
  53. package/lib/client/triggers/index.d.ts +2 -2
  54. package/lib/client/triggers/index.js +45 -52
  55. package/lib/client/triggers/schedule/DateFieldsSelect.js +1 -1
  56. package/lib/client/triggers/schedule/EndsByField.js +11 -11
  57. package/lib/client/triggers/schedule/OnField.js +11 -11
  58. package/lib/client/triggers/schedule/RepeatField.js +4 -4
  59. package/lib/client/triggers/schedule/ScheduleConfig.js +17 -24
  60. package/lib/client/triggers/schedule/index.d.ts +2 -1
  61. package/lib/client/triggers/schedule/index.js +2 -2
  62. package/lib/client/variable.d.ts +2 -2
  63. package/lib/client/variable.js +5 -5
  64. package/lib/server/Plugin.d.ts +2 -3
  65. package/lib/server/Plugin.js +8 -9
  66. package/lib/server/Processor.d.ts +2 -4
  67. package/lib/server/actions/nodes.js +7 -7
  68. package/lib/server/fields/expression-field.d.ts +1 -2
  69. package/lib/server/fields/expression-field.js +1 -8
  70. package/lib/server/functions/index.d.ts +2 -3
  71. package/lib/server/index.d.ts +1 -0
  72. package/lib/server/index.js +12 -0
  73. package/lib/server/instructions/aggregate.d.ts +1 -1
  74. package/lib/server/instructions/aggregate.js +5 -5
  75. package/lib/server/instructions/condition.d.ts +2 -1
  76. package/lib/server/instructions/create.d.ts +1 -1
  77. package/lib/server/instructions/delay.d.ts +3 -3
  78. package/lib/server/instructions/delay.js +66 -64
  79. package/lib/server/instructions/destroy.d.ts +1 -1
  80. package/lib/server/instructions/index.d.ts +5 -5
  81. package/lib/server/instructions/loop.d.ts +1 -2
  82. package/lib/server/instructions/manual/actions.js +1 -1
  83. package/lib/server/instructions/manual/forms/index.d.ts +1 -1
  84. package/lib/server/instructions/manual/index.d.ts +1 -1
  85. package/lib/server/instructions/parallel.d.ts +1 -2
  86. package/lib/server/instructions/query.d.ts +1 -1
  87. package/lib/server/instructions/request.d.ts +2 -2
  88. package/lib/server/instructions/request.js +1 -0
  89. package/lib/server/instructions/update.d.ts +1 -1
  90. package/lib/server/migrations/20230221071831-calculation-expression.js +1 -1
  91. package/lib/server/migrations/20230221121203-condition-calculation.js +1 -1
  92. package/lib/server/migrations/20230221162902-jsonb-to-json.js +7 -7
  93. package/lib/server/migrations/20230411034722-manual-multi-form.js +1 -8
  94. package/lib/server/triggers/collection.d.ts +1 -1
  95. package/lib/server/triggers/collection.js +2 -2
  96. package/lib/server/triggers/index.d.ts +1 -1
  97. package/lib/server/triggers/schedule.d.ts +1 -1
  98. package/lib/server/triggers/schedule.js +18 -18
  99. package/lib/server/{models → types}/Execution.d.ts +2 -3
  100. package/lib/server/{models → types}/FlowNode.d.ts +1 -2
  101. package/lib/server/{models → types}/Job.d.ts +1 -2
  102. package/lib/server/{models → types}/Workflow.d.ts +1 -2
  103. package/lib/server/types/index.d.ts +4 -0
  104. package/lib/server/types/index.js +5 -0
  105. package/package.json +40 -20
  106. package/server.d.ts +2 -3
  107. package/server.js +1 -30
  108. package/src/client/AddButton.tsx +99 -0
  109. package/src/client/Branch.tsx +35 -0
  110. package/src/client/CanvasContent.tsx +23 -0
  111. package/src/client/ExecutionCanvas.tsx +168 -0
  112. package/src/client/ExecutionLink.tsx +16 -0
  113. package/src/client/ExecutionPage.tsx +44 -0
  114. package/src/client/ExecutionResourceProvider.tsx +21 -0
  115. package/src/client/FlowContext.ts +7 -0
  116. package/src/client/WorkflowCanvas.tsx +220 -0
  117. package/src/client/WorkflowLink.tsx +16 -0
  118. package/src/client/WorkflowPage.tsx +51 -0
  119. package/src/client/WorkflowProvider.tsx +84 -0
  120. package/src/client/components/CollectionBlockInitializer.tsx +71 -0
  121. package/src/client/components/CollectionFieldset.tsx +158 -0
  122. package/src/client/components/Duration.tsx +45 -0
  123. package/src/client/components/DynamicExpression.tsx +53 -0
  124. package/src/client/components/FieldsSelect.tsx +28 -0
  125. package/src/client/components/FilterDynamicComponent.tsx +15 -0
  126. package/src/client/components/NodeDescription.tsx +44 -0
  127. package/src/client/components/NullRender.tsx +3 -0
  128. package/src/client/components/OpenDrawer.tsx +24 -0
  129. package/src/client/components/RadioWithTooltip.tsx +38 -0
  130. package/src/client/components/ValueBlock.tsx +67 -0
  131. package/src/client/components/renderEngineReference.tsx +30 -0
  132. package/src/client/constants.tsx +91 -0
  133. package/src/client/index.tsx +51 -0
  134. package/src/client/interfaces/expression.tsx +25 -0
  135. package/src/client/locale/en-US.ts +136 -0
  136. package/src/client/locale/es-ES.ts +129 -0
  137. package/src/client/locale/index.ts +18 -0
  138. package/src/client/locale/ja-JP.ts +90 -0
  139. package/src/client/locale/pt-BR.ts +136 -0
  140. package/src/client/locale/ru-RU.ts +90 -0
  141. package/src/client/locale/tr-TR.ts +90 -0
  142. package/src/client/locale/zh-CN.ts +242 -0
  143. package/src/client/nodes/aggregate.tsx +327 -0
  144. package/src/client/nodes/calculation.tsx +217 -0
  145. package/src/client/nodes/condition.tsx +490 -0
  146. package/src/client/nodes/create.tsx +86 -0
  147. package/src/client/nodes/delay.tsx +37 -0
  148. package/src/client/nodes/destroy.tsx +34 -0
  149. package/src/client/nodes/index.tsx +489 -0
  150. package/src/client/nodes/loop.tsx +159 -0
  151. package/src/client/nodes/manual/AssigneesSelect.tsx +33 -0
  152. package/src/client/nodes/manual/DetailsBlockProvider.tsx +80 -0
  153. package/src/client/nodes/manual/FormBlockInitializer.tsx +68 -0
  154. package/src/client/nodes/manual/FormBlockProvider.tsx +75 -0
  155. package/src/client/nodes/manual/ModeConfig.tsx +84 -0
  156. package/src/client/nodes/manual/SchemaConfig.tsx +365 -0
  157. package/src/client/nodes/manual/WorkflowTodo.tsx +611 -0
  158. package/src/client/nodes/manual/WorkflowTodoBlockInitializer.tsx +28 -0
  159. package/src/client/nodes/manual/forms/create.tsx +88 -0
  160. package/src/client/nodes/manual/forms/custom.tsx +388 -0
  161. package/src/client/nodes/manual/forms/update.tsx +130 -0
  162. package/src/client/nodes/manual/index.tsx +162 -0
  163. package/src/client/nodes/manual/utils.ts +28 -0
  164. package/src/client/nodes/parallel.tsx +137 -0
  165. package/src/client/nodes/query.tsx +89 -0
  166. package/src/client/nodes/request.tsx +185 -0
  167. package/src/client/nodes/update.tsx +99 -0
  168. package/src/client/schemas/collection.ts +75 -0
  169. package/src/client/schemas/executions.tsx +169 -0
  170. package/src/client/schemas/workflows.ts +364 -0
  171. package/src/client/style.tsx +312 -0
  172. package/src/client/triggers/collection.tsx +186 -0
  173. package/src/client/triggers/index.tsx +307 -0
  174. package/src/client/triggers/schedule/DateFieldsSelect.tsx +28 -0
  175. package/src/client/triggers/schedule/EndsByField.tsx +40 -0
  176. package/src/client/triggers/schedule/OnField.tsx +50 -0
  177. package/src/client/triggers/schedule/RepeatField.tsx +116 -0
  178. package/src/client/triggers/schedule/ScheduleConfig.tsx +225 -0
  179. package/src/client/triggers/schedule/constants.ts +4 -0
  180. package/src/client/triggers/schedule/index.tsx +72 -0
  181. package/src/client/triggers/schedule/locale/Cron.zh-CN.ts +79 -0
  182. package/src/client/utils.ts +36 -0
  183. package/src/client/variable.tsx +296 -0
  184. package/src/index.ts +1 -0
  185. package/src/server/Plugin.ts +351 -0
  186. package/src/server/Processor.ts +354 -0
  187. package/src/server/__tests__/Plugin.test.ts +398 -0
  188. package/src/server/__tests__/Processor.test.ts +474 -0
  189. package/src/server/__tests__/actions/workflows.test.ts +419 -0
  190. package/src/server/__tests__/collections/categories.ts +23 -0
  191. package/src/server/__tests__/collections/comments.ts +24 -0
  192. package/src/server/__tests__/collections/posts.ts +42 -0
  193. package/src/server/__tests__/collections/replies.ts +9 -0
  194. package/src/server/__tests__/collections/tags.ts +15 -0
  195. package/src/server/__tests__/index.ts +89 -0
  196. package/src/server/__tests__/instructions/aggregate.test.ts +294 -0
  197. package/src/server/__tests__/instructions/calculation.test.ts +265 -0
  198. package/src/server/__tests__/instructions/condition.test.ts +335 -0
  199. package/src/server/__tests__/instructions/create.test.ts +129 -0
  200. package/src/server/__tests__/instructions/delay.test.ts +182 -0
  201. package/src/server/__tests__/instructions/destroy.test.ts +58 -0
  202. package/src/server/__tests__/instructions/loop.test.ts +331 -0
  203. package/src/server/__tests__/instructions/manual.test.ts +854 -0
  204. package/src/server/__tests__/instructions/parallel.test.ts +445 -0
  205. package/src/server/__tests__/instructions/query.test.ts +359 -0
  206. package/src/server/__tests__/instructions/request.test.ts +217 -0
  207. package/src/server/__tests__/instructions/update.test.ts +189 -0
  208. package/src/server/__tests__/triggers/collection.test.ts +298 -0
  209. package/src/server/__tests__/triggers/schedule.test.ts +369 -0
  210. package/src/server/actions/index.ts +25 -0
  211. package/src/server/actions/nodes.ts +214 -0
  212. package/src/server/actions/workflows.ts +178 -0
  213. package/src/server/collections/executions.ts +35 -0
  214. package/src/server/collections/flow_nodes.ts +54 -0
  215. package/src/server/collections/jobs.ts +31 -0
  216. package/src/server/collections/workflows.ts +88 -0
  217. package/src/server/constants.ts +26 -0
  218. package/src/server/fields/expression-field.ts +11 -0
  219. package/src/server/fields/index.ts +7 -0
  220. package/src/server/functions/index.ts +16 -0
  221. package/src/server/index.ts +6 -0
  222. package/src/server/instructions/aggregate.ts +42 -0
  223. package/src/server/instructions/calculation.ts +41 -0
  224. package/src/server/instructions/condition.ts +172 -0
  225. package/src/server/instructions/create.ts +37 -0
  226. package/src/server/instructions/delay.ts +105 -0
  227. package/src/server/instructions/destroy.ts +23 -0
  228. package/src/server/instructions/index.ts +63 -0
  229. package/src/server/instructions/loop.ts +99 -0
  230. package/src/server/instructions/manual/actions.ts +79 -0
  231. package/src/server/instructions/manual/collecions/jobs.ts +17 -0
  232. package/src/server/instructions/manual/collecions/users.ts +15 -0
  233. package/src/server/instructions/manual/collecions/users_jobs.ts +50 -0
  234. package/src/server/instructions/manual/forms/create.ts +22 -0
  235. package/src/server/instructions/manual/forms/index.ts +12 -0
  236. package/src/server/instructions/manual/forms/update.ts +22 -0
  237. package/src/server/instructions/manual/index.ts +184 -0
  238. package/src/server/instructions/parallel.ts +121 -0
  239. package/src/server/instructions/query.ts +31 -0
  240. package/src/server/instructions/request.ts +87 -0
  241. package/src/server/instructions/update.ts +24 -0
  242. package/src/server/migrations/20221129153547-calculation-variables.ts +64 -0
  243. package/src/server/migrations/20230221032941-change-request-body-type.ts +76 -0
  244. package/src/server/migrations/20230221071831-calculation-expression.ts +102 -0
  245. package/src/server/migrations/20230221121203-condition-calculation.ts +82 -0
  246. package/src/server/migrations/20230221162902-jsonb-to-json.ts +51 -0
  247. package/src/server/migrations/20230411034722-manual-multi-form.ts +282 -0
  248. package/src/server/migrations/20230612021134-manual-collection-block.ts +138 -0
  249. package/src/server/triggers/collection.ts +142 -0
  250. package/src/server/triggers/index.ts +22 -0
  251. package/src/server/triggers/schedule.ts +567 -0
  252. package/src/server/types/Execution.ts +26 -0
  253. package/src/server/types/FlowNode.ts +21 -0
  254. package/src/server/types/Job.ts +18 -0
  255. package/src/server/types/Workflow.ts +36 -0
  256. package/src/server/types/index.ts +4 -0
  257. /package/lib/server/{models → types}/Execution.js +0 -0
  258. /package/lib/server/{models → types}/FlowNode.js +0 -0
  259. /package/lib/server/{models → types}/Job.js +0 -0
  260. /package/lib/server/{models → types}/Workflow.js +0 -0
@@ -0,0 +1,80 @@
1
+ import React, { useRef, useMemo, useContext } from 'react';
2
+ import { createForm } from '@formily/core';
3
+ import { useField } from '@formily/react';
4
+ import {
5
+ BlockRequestContext,
6
+ CollectionProvider,
7
+ FormBlockContext,
8
+ RecordProvider,
9
+ useAPIClient,
10
+ useAssociationNames,
11
+ } from '@nocobase/client';
12
+ import { useFlowContext } from '../../FlowContext';
13
+ import { parse } from '@nocobase/utils/client';
14
+
15
+ function useFlowContextData(dataSource) {
16
+ const { execution } = useFlowContext();
17
+ const data = useMemo(
18
+ () => ({
19
+ $context: execution?.context,
20
+ $jobsMapByNodeId: (execution?.jobs ?? []).reduce(
21
+ (map, job) => Object.assign(map, { [job.nodeId]: job.result }),
22
+ {},
23
+ ),
24
+ }),
25
+ [execution],
26
+ );
27
+
28
+ const result = useMemo(() => parse(dataSource)(data), [execution]);
29
+ return result;
30
+ }
31
+
32
+ export function DetailsBlockProvider(props) {
33
+ const field = useField();
34
+ const formBlockRef = useRef(null);
35
+ const { appends, updateAssociationValues } = useAssociationNames();
36
+ const values = useFlowContextData(props.dataSource);
37
+
38
+ const form = useMemo(
39
+ () =>
40
+ createForm({
41
+ values,
42
+ readPretty: true,
43
+ }),
44
+ [values],
45
+ );
46
+
47
+ const params = {
48
+ appends,
49
+ };
50
+ const service = {
51
+ loading: false,
52
+ data: {
53
+ data: values,
54
+ },
55
+ };
56
+ const api = useAPIClient();
57
+ const resource = api.resource(props.collection);
58
+ const __parent = useContext(BlockRequestContext);
59
+
60
+ return (
61
+ <CollectionProvider collection={props.collection}>
62
+ <RecordProvider record={values} parent={false}>
63
+ <BlockRequestContext.Provider value={{ block: 'form', field, service, resource, __parent }}>
64
+ <FormBlockContext.Provider
65
+ value={{
66
+ params,
67
+ form,
68
+ field,
69
+ service,
70
+ updateAssociationValues,
71
+ formBlockRef,
72
+ }}
73
+ >
74
+ {props.children}
75
+ </FormBlockContext.Provider>
76
+ </BlockRequestContext.Provider>
77
+ </RecordProvider>
78
+ </CollectionProvider>
79
+ );
80
+ }
@@ -0,0 +1,68 @@
1
+ import React from 'react';
2
+
3
+ import {
4
+ CollectionProvider,
5
+ SchemaInitializer,
6
+ SchemaInitializerItemOptions,
7
+ createFormBlockSchema,
8
+ useRecordCollectionDataSourceItems,
9
+ useSchemaTemplateManager,
10
+ } from '@nocobase/client';
11
+
12
+ import { traverseSchema } from './utils';
13
+
14
+ import { JOB_STATUS } from '../../constants';
15
+ import { NAMESPACE } from '../../locale';
16
+
17
+ function InternalFormBlockInitializer({ insert, schema, ...others }) {
18
+ const { getTemplateSchemaByMode } = useSchemaTemplateManager();
19
+ const items = useRecordCollectionDataSourceItems('FormItem') as SchemaInitializerItemOptions[];
20
+ async function onConfirm({ item }) {
21
+ const template = item.template ? await getTemplateSchemaByMode(item) : null;
22
+ const result = createFormBlockSchema({
23
+ actionInitializers: 'AddActionButton',
24
+ actions: {
25
+ resolve: {
26
+ type: 'void',
27
+ title: `{{t("Continue the process", { ns: "${NAMESPACE}" })}}`,
28
+ 'x-decorator': 'ManualActionStatusProvider',
29
+ 'x-decorator-props': {
30
+ value: JOB_STATUS.RESOLVED,
31
+ },
32
+ 'x-component': 'Action',
33
+ 'x-component-props': {
34
+ type: 'primary',
35
+ useAction: '{{ useSubmit }}',
36
+ },
37
+ 'x-designer': 'Action.Designer',
38
+ 'x-designer-props': {
39
+ type: 'record',
40
+ },
41
+ 'x-action': `${JOB_STATUS.RESOLVED}`,
42
+ },
43
+ },
44
+ ...schema,
45
+ template,
46
+ });
47
+ delete result['x-acl-action-props'];
48
+ delete result['x-acl-action'];
49
+ const [formKey] = Object.keys(result.properties);
50
+ result.properties[formKey].properties.actions['x-decorator'] = 'ActionBarProvider';
51
+ traverseSchema(result, (node) => {
52
+ if (node['x-uid']) {
53
+ delete node['x-uid'];
54
+ }
55
+ });
56
+ insert(result);
57
+ }
58
+
59
+ return <SchemaInitializer.Item {...others} onClick={onConfirm} items={items} />;
60
+ }
61
+
62
+ export function FormBlockInitializer(props) {
63
+ return (
64
+ <CollectionProvider collection={props.schema?.collection}>
65
+ <InternalFormBlockInitializer {...props} />
66
+ </CollectionProvider>
67
+ );
68
+ }
@@ -0,0 +1,75 @@
1
+ import React, { useRef, useMemo, useContext } from 'react';
2
+ import { createForm } from '@formily/core';
3
+ import { useFieldSchema, useField, RecursionField } from '@formily/react';
4
+ import {
5
+ BlockRequestContext,
6
+ CollectionProvider,
7
+ FormBlockContext,
8
+ FormV2,
9
+ RecordProvider,
10
+ useAPIClient,
11
+ useAssociationNames,
12
+ useDesignable,
13
+ useRecord,
14
+ } from '@nocobase/client';
15
+
16
+ export function FormBlockProvider(props) {
17
+ const userJob = useRecord();
18
+ const fieldSchema = useFieldSchema();
19
+ const field = useField();
20
+ const formBlockRef = useRef(null);
21
+ const { appends, updateAssociationValues } = useAssociationNames();
22
+ const [formKey] = Object.keys(fieldSchema.toJSON().properties ?? {});
23
+ const values = userJob?.result?.[formKey];
24
+
25
+ const { findComponent } = useDesignable();
26
+ const Component = findComponent(field.component?.[0]) || React.Fragment;
27
+
28
+ const form = useMemo(
29
+ () =>
30
+ createForm({
31
+ initialValues: values,
32
+ }),
33
+ [values],
34
+ );
35
+
36
+ const params = {
37
+ appends,
38
+ ...props.params,
39
+ };
40
+ const service = {
41
+ loading: false,
42
+ data: {
43
+ data: values,
44
+ },
45
+ };
46
+ const api = useAPIClient();
47
+ const resource = api.resource(props.collection);
48
+ const __parent = useContext(BlockRequestContext);
49
+
50
+ return (
51
+ <CollectionProvider collection={props.collection}>
52
+ <RecordProvider record={values} parent={false}>
53
+ <BlockRequestContext.Provider value={{ block: 'form', props, field, service, resource, __parent }}>
54
+ <FormBlockContext.Provider
55
+ value={{
56
+ params,
57
+ form,
58
+ field,
59
+ service,
60
+ updateAssociationValues,
61
+ formBlockRef,
62
+ }}
63
+ >
64
+ <Component {...field.componentProps}>
65
+ <FormV2.Templates style={{ marginBottom: 18 }} form={form} />
66
+ <div ref={formBlockRef}>
67
+ <RecursionField schema={fieldSchema} onlyRenderProperties />
68
+ </div>
69
+ </Component>
70
+ </FormBlockContext.Provider>
71
+ </BlockRequestContext.Provider>
72
+ </RecordProvider>
73
+ </CollectionProvider>
74
+ );
75
+ }
@@ -0,0 +1,84 @@
1
+ import { QuestionCircleOutlined } from '@ant-design/icons';
2
+ import { FormLayout } from '@formily/antd-v5';
3
+ import { Form, Radio, Tooltip } from 'antd';
4
+ import React from 'react';
5
+
6
+ import { css, FormItem } from '@nocobase/client';
7
+ import { lang } from '../../locale';
8
+
9
+ function parseMode(v) {
10
+ if (!v) {
11
+ return 'single';
12
+ }
13
+ if (v >= 1) {
14
+ return 'all';
15
+ }
16
+ if (v <= -1) {
17
+ return 'any';
18
+ }
19
+
20
+ const dir = Math.sign(v);
21
+ if (dir > 0) {
22
+ return '';
23
+ }
24
+ }
25
+
26
+ export function ModeConfig({ value, onChange }) {
27
+ const mode = parseMode(value);
28
+ return (
29
+ <fieldset
30
+ className={css`
31
+ .ant-radio-group {
32
+ .anticon {
33
+ margin-left: 0.5em;
34
+ }
35
+ }
36
+ `}
37
+ >
38
+ <Form.Item>
39
+ <Radio.Group
40
+ value={Boolean(value)}
41
+ onChange={({ target: { value: v } }) => {
42
+ console.log(v);
43
+ onChange(Number(v));
44
+ }}
45
+ >
46
+ <Radio value={true}>
47
+ <Tooltip title={lang('Each user has own task')} placement="bottom">
48
+ <span>{lang('Separately')}</span>
49
+ <QuestionCircleOutlined style={{ color: '#999' }} />
50
+ </Tooltip>
51
+ </Radio>
52
+ <Radio value={false}>
53
+ <Tooltip title={lang('Everyone shares one task')} placement="bottom">
54
+ <span>{lang('Collaboratively')}</span>
55
+ <QuestionCircleOutlined style={{ color: '#999' }} />
56
+ </Tooltip>
57
+ </Radio>
58
+ </Radio.Group>
59
+ </Form.Item>
60
+ {value ? (
61
+ <fieldset>
62
+ <FormLayout layout="vertical">
63
+ <FormItem label={lang('Negotiation')}>
64
+ <Radio.Group value={value} onChange={onChange}>
65
+ <Radio value={1}>
66
+ <Tooltip title={lang('Everyone should pass')} placement="bottom">
67
+ <span>{lang('All pass')}</span>
68
+ <QuestionCircleOutlined style={{ color: '#999' }} />
69
+ </Tooltip>
70
+ </Radio>
71
+ <Radio value={-1}>
72
+ <Tooltip title={lang('Anyone pass')} placement="bottom">
73
+ <span>{lang('Any pass')}</span>
74
+ <QuestionCircleOutlined style={{ color: '#999' }} />
75
+ </Tooltip>
76
+ </Radio>
77
+ </Radio.Group>
78
+ </FormItem>
79
+ </FormLayout>
80
+ </fieldset>
81
+ ) : null}
82
+ </fieldset>
83
+ );
84
+ }
@@ -0,0 +1,365 @@
1
+ import React, { useContext, useMemo, useState } from 'react';
2
+
3
+ import { ISchema, Schema, useFieldSchema, useForm } from '@formily/react';
4
+
5
+ import {
6
+ ActionContextProvider,
7
+ GeneralSchemaDesigner,
8
+ InitializerWithSwitch,
9
+ SchemaComponent,
10
+ SchemaComponentContext,
11
+ SchemaInitializer,
12
+ SchemaInitializerItemOptions,
13
+ SchemaInitializerProvider,
14
+ SchemaSettings,
15
+ gridRowColWrap,
16
+ useCompile,
17
+ useFormBlockContext,
18
+ } from '@nocobase/client';
19
+ import { Registry, lodash } from '@nocobase/utils/client';
20
+ import { Button } from 'antd';
21
+ import { instructions, useAvailableUpstreams, useNodeContext } from '..';
22
+ import { useFlowContext } from '../../FlowContext';
23
+ import { JOB_STATUS } from '../../constants';
24
+ import { NAMESPACE, lang } from '../../locale';
25
+ import { useTrigger } from '../../triggers';
26
+ import { DetailsBlockProvider } from './DetailsBlockProvider';
27
+ import { FormBlockProvider } from './FormBlockProvider';
28
+ import createForm from './forms/create';
29
+ import customForm from './forms/custom';
30
+ import updateForm from './forms/update';
31
+
32
+ type ValueOf<T> = T[keyof T];
33
+
34
+ export type FormType = {
35
+ type: 'create' | 'update' | 'custom';
36
+ title: string;
37
+ actions: ValueOf<typeof JOB_STATUS>[];
38
+ collection:
39
+ | string
40
+ | {
41
+ name: string;
42
+ fields: any[];
43
+ [key: string]: any;
44
+ };
45
+ };
46
+
47
+ export type ManualFormType = {
48
+ title: string;
49
+ config: {
50
+ useInitializer: () => SchemaInitializerItemOptions;
51
+ initializers?: {
52
+ [key: string]: React.FC;
53
+ };
54
+ components?: {
55
+ [key: string]: React.FC;
56
+ };
57
+ parseFormOptions(root: ISchema): { [key: string]: FormType };
58
+ };
59
+ block: {
60
+ scope?: {
61
+ [key: string]: () => any;
62
+ };
63
+ components?: {
64
+ [key: string]: React.FC;
65
+ };
66
+ };
67
+ };
68
+
69
+ export const manualFormTypes = new Registry<ManualFormType>();
70
+
71
+ manualFormTypes.register('customForm', customForm);
72
+ manualFormTypes.register('createForm', createForm);
73
+ manualFormTypes.register('updateForm', updateForm);
74
+
75
+ function useTriggerInitializers(): SchemaInitializerItemOptions | null {
76
+ const { workflow } = useFlowContext();
77
+ const trigger = useTrigger();
78
+ return trigger.useInitializers ? trigger.useInitializers(workflow.config) : null;
79
+ }
80
+
81
+ const blockTypeNames = {
82
+ customForm: customForm.title,
83
+ record: `{{t("Data record", { ns: "${NAMESPACE}" })}}`,
84
+ };
85
+
86
+ function SimpleDesigner() {
87
+ const schema = useFieldSchema();
88
+ const title = blockTypeNames[schema['x-designer-props']?.type] ?? '{{t("Block")}}';
89
+ const compile = useCompile();
90
+ return (
91
+ <GeneralSchemaDesigner title={compile(title)}>
92
+ <SchemaSettings.BlockTitleItem />
93
+ <SchemaSettings.Divider />
94
+ <SchemaSettings.Remove
95
+ removeParentsIfNoChildren
96
+ breakRemoveOn={{
97
+ 'x-component': 'Grid',
98
+ }}
99
+ />
100
+ </GeneralSchemaDesigner>
101
+ );
102
+ }
103
+
104
+ function AddBlockButton(props: any) {
105
+ const current = useNodeContext();
106
+ const nodes = useAvailableUpstreams(current);
107
+ const triggerInitializers = [useTriggerInitializers()].filter(Boolean);
108
+ const nodeBlockInitializers = nodes
109
+ .map((node) => {
110
+ const instruction = instructions.get(node.type);
111
+ return instruction?.useInitializers?.(node);
112
+ })
113
+ .filter(Boolean);
114
+ const dataBlockInitializers = [
115
+ ...triggerInitializers,
116
+ ...(nodeBlockInitializers.length
117
+ ? [
118
+ {
119
+ key: 'nodes',
120
+ type: 'subMenu',
121
+ title: `{{t("Node result", { ns: "${NAMESPACE}" })}}`,
122
+ children: nodeBlockInitializers,
123
+ },
124
+ ]
125
+ : []),
126
+ ].filter(Boolean);
127
+
128
+ const items = [
129
+ ...(dataBlockInitializers.length
130
+ ? [
131
+ {
132
+ type: 'itemGroup',
133
+ title: '{{t("Data blocks")}}',
134
+ children: dataBlockInitializers,
135
+ },
136
+ ]
137
+ : []),
138
+ {
139
+ type: 'itemGroup',
140
+ title: '{{t("Form")}}',
141
+ children: Array.from(manualFormTypes.getValues()).map((item) => {
142
+ const { useInitializer: getInitializer } = item.config;
143
+ return getInitializer();
144
+ }),
145
+ },
146
+ {
147
+ type: 'itemGroup',
148
+ title: '{{t("Other blocks")}}',
149
+ children: [
150
+ {
151
+ type: 'item',
152
+ title: '{{t("Markdown")}}',
153
+ component: 'MarkdownBlockInitializer',
154
+ },
155
+ ],
156
+ },
157
+ ] as SchemaInitializerItemOptions[];
158
+
159
+ return <SchemaInitializer.Button {...props} wrap={gridRowColWrap} items={items} title="{{t('Add block')}}" />;
160
+ }
161
+
162
+ function ActionInitializer({ action, actionProps, ...props }) {
163
+ return (
164
+ <InitializerWithSwitch
165
+ {...props}
166
+ schema={{
167
+ type: 'void',
168
+ title: props.title,
169
+ 'x-decorator': 'ManualActionStatusProvider',
170
+ 'x-decorator-props': {
171
+ value: action,
172
+ },
173
+ 'x-component': 'Action',
174
+ 'x-component-props': {
175
+ ...actionProps,
176
+ useAction: '{{ useSubmit }}',
177
+ },
178
+ 'x-designer': 'Action.Designer',
179
+ 'x-action': `${action}`,
180
+ }}
181
+ type="x-action"
182
+ />
183
+ );
184
+ }
185
+
186
+ function AddActionButton(props) {
187
+ return (
188
+ <SchemaInitializer.Button
189
+ {...props}
190
+ items={[
191
+ {
192
+ key: JOB_STATUS.RESOLVED,
193
+ type: 'item',
194
+ title: `{{t("Continue the process", { ns: "${NAMESPACE}" })}}`,
195
+ component: ActionInitializer,
196
+ action: JOB_STATUS.RESOLVED,
197
+ actionProps: {
198
+ type: 'primary',
199
+ },
200
+ },
201
+ {
202
+ key: JOB_STATUS.REJECTED,
203
+ type: 'item',
204
+ title: `{{t("Terminate the process", { ns: "${NAMESPACE}" })}}`,
205
+ component: ActionInitializer,
206
+ action: JOB_STATUS.REJECTED,
207
+ actionProps: {
208
+ type: 'primary',
209
+ danger: true,
210
+ },
211
+ },
212
+ {
213
+ key: JOB_STATUS.PENDING,
214
+ type: 'item',
215
+ title: `{{t("Save temporarily", { ns: "${NAMESPACE}" })}}`,
216
+ component: ActionInitializer,
217
+ action: JOB_STATUS.PENDING,
218
+ },
219
+ ]}
220
+ title="{{t('Configure actions')}}"
221
+ />
222
+ );
223
+ }
224
+
225
+ // NOTE: fake useAction for ui configuration
226
+ function useSubmit() {
227
+ // const { values, submit, id: formId } = useForm();
228
+ // const formSchema = useFieldSchema();
229
+ return {
230
+ run() {},
231
+ };
232
+ }
233
+
234
+ export function SchemaConfig({ value, onChange }) {
235
+ const ctx = useContext(SchemaComponentContext);
236
+ const trigger = useTrigger();
237
+ const node = useNodeContext();
238
+ const nodes = useAvailableUpstreams(node);
239
+ const form = useForm();
240
+ const { workflow } = useFlowContext();
241
+
242
+ const nodeInitializers = {};
243
+ const nodeComponents = {};
244
+ nodes.forEach((item) => {
245
+ const instruction = instructions.get(item.type);
246
+ Object.assign(nodeInitializers, instruction.initializers);
247
+ Object.assign(nodeComponents, instruction.components);
248
+ });
249
+
250
+ const schema = useMemo(
251
+ () =>
252
+ new Schema({
253
+ properties: {
254
+ drawer: {
255
+ type: 'void',
256
+ title: '{{t("Configure form")}}',
257
+ 'x-decorator': 'Form',
258
+ 'x-component': 'Action.Drawer',
259
+ 'x-component-props': {
260
+ className: 'nb-action-popup',
261
+ },
262
+ properties: {
263
+ tabs: {
264
+ type: 'void',
265
+ 'x-component': 'Tabs',
266
+ 'x-component-props': {},
267
+ 'x-initializer': 'TabPaneInitializers',
268
+ 'x-initializer-props': {
269
+ gridInitializer: 'AddBlockButton',
270
+ },
271
+ properties: value ?? {
272
+ tab1: {
273
+ type: 'void',
274
+ title: `{{t("Manual", { ns: "${NAMESPACE}" })}}`,
275
+ 'x-component': 'Tabs.TabPane',
276
+ 'x-designer': 'Tabs.Designer',
277
+ properties: {
278
+ grid: {
279
+ type: 'void',
280
+ 'x-component': 'Grid',
281
+ 'x-initializer': 'AddBlockButton',
282
+ properties: {},
283
+ },
284
+ },
285
+ },
286
+ },
287
+ },
288
+ },
289
+ },
290
+ },
291
+ }),
292
+ [],
293
+ );
294
+
295
+ return (
296
+ <SchemaComponentContext.Provider
297
+ value={{
298
+ ...ctx,
299
+ designable: !workflow.executed,
300
+ refresh() {
301
+ ctx.refresh?.();
302
+ const { tabs } = lodash.get(schema.toJSON(), 'properties.drawer.properties') as { tabs: ISchema };
303
+ const forms = Array.from(manualFormTypes.getValues()).reduce(
304
+ (result, item) => Object.assign(result, item.config.parseFormOptions(tabs)),
305
+ {},
306
+ );
307
+ form.setValuesIn('forms', forms);
308
+
309
+ onChange(tabs.properties);
310
+ },
311
+ }}
312
+ >
313
+ <SchemaInitializerProvider
314
+ initializers={{
315
+ AddBlockButton,
316
+ AddActionButton,
317
+ ...trigger.initializers,
318
+ ...nodeInitializers,
319
+ ...Array.from(manualFormTypes.getValues()).reduce(
320
+ (result, item) => Object.assign(result, item.config.initializers),
321
+ {},
322
+ ),
323
+ }}
324
+ >
325
+ <SchemaComponent
326
+ schema={schema}
327
+ components={{
328
+ ...nodeComponents,
329
+ ...Array.from(manualFormTypes.getValues()).reduce(
330
+ (result, item) => Object.assign(result, item.config.components),
331
+ {},
332
+ ),
333
+ FormBlockProvider,
334
+ DetailsBlockProvider,
335
+ // NOTE: fake provider component
336
+ ManualActionStatusProvider(props) {
337
+ return props.children;
338
+ },
339
+ ActionBarProvider(props) {
340
+ return props.children;
341
+ },
342
+ SimpleDesigner,
343
+ }}
344
+ scope={{
345
+ useSubmit,
346
+ useDetailsBlockProps: useFormBlockContext,
347
+ }}
348
+ />
349
+ </SchemaInitializerProvider>
350
+ </SchemaComponentContext.Provider>
351
+ );
352
+ }
353
+
354
+ export function SchemaConfigButton(props) {
355
+ const { workflow } = useFlowContext();
356
+ const [visible, setVisible] = useState(false);
357
+ return (
358
+ <>
359
+ <Button type="primary" onClick={() => setVisible(true)}>
360
+ {workflow.executed ? lang('View user interface') : lang('Configure user interface')}
361
+ </Button>
362
+ <ActionContextProvider value={{ visible, setVisible }}>{props.children}</ActionContextProvider>
363
+ </>
364
+ );
365
+ }