@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.
- package/client.d.ts +2 -3
- package/client.js +1 -30
- package/lib/client/AddButton.js +13 -11
- package/lib/client/Branch.js +10 -8
- package/lib/client/CanvasContent.js +12 -10
- package/lib/client/ExecutionCanvas.js +37 -33
- package/lib/client/ExecutionPage.js +4 -9
- package/lib/client/WorkflowCanvas.js +18 -15
- package/lib/client/WorkflowPage.js +4 -9
- package/lib/client/WorkflowProvider.js +1 -40
- package/lib/client/components/CollectionBlockInitializer.js +3 -3
- package/lib/client/components/CollectionFieldset.d.ts +1 -1
- package/lib/client/components/CollectionFieldset.js +15 -16
- package/lib/client/components/Duration.js +5 -5
- package/lib/client/components/DynamicExpression.d.ts +3 -3
- package/lib/client/components/FieldsSelect.d.ts +1 -1
- package/lib/client/components/FieldsSelect.js +10 -7
- package/lib/client/components/NodeDescription.js +45 -31
- package/lib/client/components/RadioWithTooltip.js +13 -20
- package/lib/client/components/ValueBlock.js +14 -21
- package/lib/client/components/renderEngineReference.js +1 -8
- package/lib/client/index.d.ts +12 -4
- package/lib/client/index.js +78 -15
- package/lib/client/locale/zh-CN.d.ts +5 -1
- package/lib/client/locale/zh-CN.js +6 -2
- package/lib/client/nodes/aggregate.d.ts +8 -3
- package/lib/client/nodes/aggregate.js +5 -4
- package/lib/client/nodes/calculation.d.ts +6 -4
- package/lib/client/nodes/calculation.js +22 -28
- package/lib/client/nodes/condition.d.ts +2 -10
- package/lib/client/nodes/condition.js +19 -37
- package/lib/client/nodes/create.d.ts +5 -6
- package/lib/client/nodes/create.js +1 -3
- package/lib/client/nodes/destroy.d.ts +1 -1
- package/lib/client/nodes/index.d.ts +2 -3
- package/lib/client/nodes/index.js +95 -102
- package/lib/client/nodes/loop.d.ts +1 -1
- package/lib/client/nodes/loop.js +46 -54
- package/lib/client/nodes/manual/FormBlockInitializer.js +6 -5
- package/lib/client/nodes/manual/ModeConfig.js +23 -30
- package/lib/client/nodes/manual/SchemaConfig.d.ts +4 -5
- package/lib/client/nodes/manual/SchemaConfig.js +180 -25
- package/lib/client/nodes/manual/WorkflowTodo.js +95 -110
- package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +2 -5
- package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +6 -5
- package/lib/client/nodes/manual/forms/create.js +8 -1
- package/lib/client/nodes/manual/forms/custom.js +22 -22
- package/lib/client/nodes/manual/forms/update.js +8 -1
- package/lib/client/nodes/manual/index.d.ts +6 -1
- package/lib/client/nodes/manual/index.js +5 -4
- package/lib/client/nodes/parallel.js +23 -20
- package/lib/client/nodes/query.d.ts +3 -5
- package/lib/client/nodes/query.js +1 -3
- package/lib/client/nodes/request.d.ts +2 -2
- package/lib/client/nodes/request.js +7 -7
- package/lib/client/nodes/sql.d.ts +26 -0
- package/lib/client/{triggers/schedule/DateFieldsSelect.js → nodes/sql.js} +37 -46
- package/lib/client/nodes/update.d.ts +2 -2
- package/lib/client/nodes/update.js +1 -1
- package/lib/client/schemas/collection.d.ts +3 -4
- package/lib/client/schemas/collection.js +11 -17
- package/lib/client/style.d.ts +18 -13
- package/lib/client/style.js +315 -292
- package/lib/client/triggers/collection.d.ts +13 -13
- package/lib/client/triggers/collection.js +5 -1
- package/lib/client/triggers/index.d.ts +3 -4
- package/lib/client/triggers/index.js +51 -53
- package/lib/client/triggers/schedule/EndsByField.js +11 -11
- package/lib/client/triggers/schedule/OnField.js +45 -33
- package/lib/client/triggers/schedule/RepeatField.js +4 -4
- package/lib/client/triggers/schedule/ScheduleConfig.js +24 -31
- package/lib/client/triggers/schedule/index.d.ts +1 -1
- package/lib/client/triggers/schedule/index.js +32 -20
- package/lib/client/variable.d.ts +31 -13
- package/lib/client/variable.js +44 -29
- package/lib/server/Plugin.d.ts +3 -6
- package/lib/server/Plugin.js +15 -12
- package/lib/server/Processor.d.ts +3 -5
- package/lib/server/Processor.js +2 -2
- package/lib/server/actions/nodes.js +7 -7
- package/lib/server/fields/expression-field.d.ts +1 -2
- package/lib/server/fields/expression-field.js +1 -8
- package/lib/server/functions/index.d.ts +2 -3
- package/lib/server/index.d.ts +1 -0
- package/lib/server/index.js +12 -0
- package/lib/server/instructions/aggregate.d.ts +1 -1
- package/lib/server/instructions/aggregate.js +5 -5
- package/lib/server/instructions/condition.d.ts +2 -1
- package/lib/server/instructions/create.d.ts +2 -2
- package/lib/server/instructions/create.js +13 -13
- package/lib/server/instructions/delay.d.ts +3 -3
- package/lib/server/instructions/delay.js +66 -64
- package/lib/server/instructions/destroy.d.ts +1 -1
- package/lib/server/instructions/index.d.ts +5 -5
- package/lib/server/instructions/index.js +1 -1
- package/lib/server/instructions/loop.d.ts +1 -2
- package/lib/server/instructions/manual/actions.js +19 -7
- package/lib/server/instructions/manual/forms/create.js +7 -1
- package/lib/server/instructions/manual/forms/index.d.ts +1 -1
- package/lib/server/instructions/manual/forms/update.js +7 -1
- package/lib/server/instructions/manual/index.d.ts +1 -1
- package/lib/server/instructions/parallel.d.ts +1 -2
- package/lib/server/instructions/query.d.ts +1 -1
- package/lib/server/instructions/query.js +8 -1
- package/lib/server/instructions/request.d.ts +3 -3
- package/lib/server/instructions/request.js +5 -2
- package/lib/server/instructions/sql.d.ts +12 -0
- package/lib/server/instructions/sql.js +34 -0
- package/lib/server/instructions/update.d.ts +1 -1
- package/lib/server/migrations/20230221071831-calculation-expression.js +1 -1
- package/lib/server/migrations/20230221121203-condition-calculation.js +1 -1
- package/lib/server/migrations/20230221162902-jsonb-to-json.js +7 -7
- package/lib/server/migrations/20230411034722-manual-multi-form.js +1 -8
- package/lib/server/migrations/20230710115902-manual-action-values.d.ts +4 -0
- package/lib/server/migrations/20230710115902-manual-action-values.js +97 -0
- package/lib/server/triggers/collection.d.ts +1 -1
- package/lib/server/triggers/collection.js +15 -13
- package/lib/server/triggers/index.d.ts +1 -1
- package/lib/server/triggers/schedule.d.ts +1 -1
- package/lib/server/triggers/schedule.js +18 -18
- package/lib/server/{models → types}/Execution.d.ts +2 -3
- package/lib/server/{models → types}/FlowNode.d.ts +1 -2
- package/lib/server/{models → types}/Job.d.ts +1 -2
- package/lib/server/{models → types}/Workflow.d.ts +1 -2
- package/lib/server/types/index.d.ts +4 -0
- package/lib/server/types/index.js +5 -0
- package/lib/server/utils.d.ts +2 -0
- package/lib/server/utils.js +21 -0
- package/package.json +39 -18
- package/server.d.ts +2 -3
- package/server.js +1 -30
- package/src/client/AddButton.tsx +111 -0
- package/src/client/Branch.tsx +37 -0
- package/src/client/CanvasContent.tsx +25 -0
- package/src/client/ExecutionCanvas.tsx +166 -0
- package/src/client/ExecutionLink.tsx +16 -0
- package/src/client/ExecutionPage.tsx +45 -0
- package/src/client/ExecutionResourceProvider.tsx +21 -0
- package/src/client/FlowContext.ts +7 -0
- package/src/client/WorkflowCanvas.tsx +221 -0
- package/src/client/WorkflowLink.tsx +16 -0
- package/src/client/WorkflowPage.tsx +52 -0
- package/src/client/WorkflowProvider.tsx +84 -0
- package/src/client/components/CollectionBlockInitializer.tsx +71 -0
- package/src/client/components/CollectionFieldset.tsx +160 -0
- package/src/client/components/Duration.tsx +45 -0
- package/src/client/components/DynamicExpression.tsx +53 -0
- package/src/client/components/FieldsSelect.tsx +32 -0
- package/src/client/components/FilterDynamicComponent.tsx +15 -0
- package/src/client/components/NodeDescription.tsx +51 -0
- package/src/client/components/NullRender.tsx +3 -0
- package/src/client/components/OpenDrawer.tsx +24 -0
- package/src/client/components/RadioWithTooltip.tsx +38 -0
- package/src/client/components/ValueBlock.tsx +67 -0
- package/src/client/components/renderEngineReference.tsx +30 -0
- package/src/client/constants.tsx +91 -0
- package/src/client/index.tsx +51 -0
- package/src/client/interfaces/expression.tsx +25 -0
- package/src/client/locale/en-US.ts +136 -0
- package/src/client/locale/es-ES.ts +129 -0
- package/src/client/locale/index.ts +18 -0
- package/src/client/locale/ja-JP.ts +90 -0
- package/src/client/locale/pt-BR.ts +136 -0
- package/src/client/locale/ru-RU.ts +90 -0
- package/src/client/locale/tr-TR.ts +90 -0
- package/src/client/locale/zh-CN.ts +248 -0
- package/src/client/nodes/aggregate.tsx +327 -0
- package/src/client/nodes/calculation.tsx +216 -0
- package/src/client/nodes/condition.tsx +463 -0
- package/src/client/nodes/create.tsx +85 -0
- package/src/client/nodes/delay.tsx +37 -0
- package/src/client/nodes/destroy.tsx +34 -0
- package/src/client/nodes/index.tsx +485 -0
- package/src/client/nodes/loop.tsx +144 -0
- package/src/client/nodes/manual/AssigneesSelect.tsx +33 -0
- package/src/client/nodes/manual/DetailsBlockProvider.tsx +80 -0
- package/src/client/nodes/manual/FormBlockInitializer.tsx +69 -0
- package/src/client/nodes/manual/FormBlockProvider.tsx +75 -0
- package/src/client/nodes/manual/ModeConfig.tsx +84 -0
- package/src/client/nodes/manual/SchemaConfig.tsx +509 -0
- package/src/client/nodes/manual/WorkflowTodo.tsx +607 -0
- package/src/client/nodes/manual/WorkflowTodoBlockInitializer.tsx +28 -0
- package/src/client/nodes/manual/forms/create.tsx +92 -0
- package/src/client/nodes/manual/forms/custom.tsx +392 -0
- package/src/client/nodes/manual/forms/update.tsx +134 -0
- package/src/client/nodes/manual/index.tsx +162 -0
- package/src/client/nodes/manual/utils.ts +28 -0
- package/src/client/nodes/parallel.tsx +138 -0
- package/src/client/nodes/query.tsx +88 -0
- package/src/client/nodes/request.tsx +185 -0
- package/src/client/nodes/sql.tsx +37 -0
- package/src/client/nodes/update.tsx +99 -0
- package/src/client/schemas/collection.ts +75 -0
- package/src/client/schemas/executions.tsx +169 -0
- package/src/client/schemas/workflows.ts +364 -0
- package/src/client/style.tsx +347 -0
- package/src/client/triggers/collection.tsx +190 -0
- package/src/client/triggers/index.tsx +311 -0
- package/src/client/triggers/schedule/EndsByField.tsx +40 -0
- package/src/client/triggers/schedule/OnField.tsx +64 -0
- package/src/client/triggers/schedule/RepeatField.tsx +116 -0
- package/src/client/triggers/schedule/ScheduleConfig.tsx +227 -0
- package/src/client/triggers/schedule/constants.ts +4 -0
- package/src/client/triggers/schedule/index.tsx +78 -0
- package/src/client/triggers/schedule/locale/Cron.zh-CN.ts +79 -0
- package/src/client/utils.ts +36 -0
- package/src/client/variable.tsx +318 -0
- package/src/index.ts +1 -0
- package/src/server/Plugin.ts +355 -0
- package/src/server/Processor.ts +354 -0
- package/src/server/__tests__/Plugin.test.ts +398 -0
- package/src/server/__tests__/Processor.test.ts +474 -0
- package/src/server/__tests__/actions/workflows.test.ts +419 -0
- package/src/server/__tests__/collections/categories.ts +27 -0
- package/src/server/__tests__/collections/comments.ts +24 -0
- package/src/server/__tests__/collections/posts.ts +42 -0
- package/src/server/__tests__/collections/replies.ts +9 -0
- package/src/server/__tests__/collections/tags.ts +15 -0
- package/src/server/__tests__/index.ts +89 -0
- package/src/server/__tests__/instructions/aggregate.test.ts +294 -0
- package/src/server/__tests__/instructions/calculation.test.ts +265 -0
- package/src/server/__tests__/instructions/condition.test.ts +335 -0
- package/src/server/__tests__/instructions/create.test.ts +129 -0
- package/src/server/__tests__/instructions/delay.test.ts +182 -0
- package/src/server/__tests__/instructions/destroy.test.ts +58 -0
- package/src/server/__tests__/instructions/loop.test.ts +331 -0
- package/src/server/__tests__/instructions/manual.test.ts +1173 -0
- package/src/server/__tests__/instructions/parallel.test.ts +445 -0
- package/src/server/__tests__/instructions/query.test.ts +359 -0
- package/src/server/__tests__/instructions/request.test.ts +247 -0
- package/src/server/__tests__/instructions/sql.test.ts +162 -0
- package/src/server/__tests__/instructions/update.test.ts +189 -0
- package/src/server/__tests__/triggers/collection.test.ts +333 -0
- package/src/server/__tests__/triggers/schedule.test.ts +369 -0
- package/src/server/actions/index.ts +25 -0
- package/src/server/actions/nodes.ts +214 -0
- package/src/server/actions/workflows.ts +178 -0
- package/src/server/collections/executions.ts +35 -0
- package/src/server/collections/flow_nodes.ts +54 -0
- package/src/server/collections/jobs.ts +31 -0
- package/src/server/collections/workflows.ts +88 -0
- package/src/server/constants.ts +26 -0
- package/src/server/fields/expression-field.ts +11 -0
- package/src/server/fields/index.ts +7 -0
- package/src/server/functions/index.ts +16 -0
- package/src/server/index.ts +6 -0
- package/src/server/instructions/aggregate.ts +42 -0
- package/src/server/instructions/calculation.ts +41 -0
- package/src/server/instructions/condition.ts +172 -0
- package/src/server/instructions/create.ts +39 -0
- package/src/server/instructions/delay.ts +105 -0
- package/src/server/instructions/destroy.ts +23 -0
- package/src/server/instructions/index.ts +64 -0
- package/src/server/instructions/loop.ts +99 -0
- package/src/server/instructions/manual/actions.ts +91 -0
- package/src/server/instructions/manual/collecions/jobs.ts +17 -0
- package/src/server/instructions/manual/collecions/users.ts +15 -0
- package/src/server/instructions/manual/collecions/users_jobs.ts +50 -0
- package/src/server/instructions/manual/forms/create.ts +23 -0
- package/src/server/instructions/manual/forms/index.ts +12 -0
- package/src/server/instructions/manual/forms/update.ts +23 -0
- package/src/server/instructions/manual/index.ts +184 -0
- package/src/server/instructions/parallel.ts +121 -0
- package/src/server/instructions/query.ts +42 -0
- package/src/server/instructions/request.ts +88 -0
- package/src/server/instructions/sql.ts +25 -0
- package/src/server/instructions/update.ts +24 -0
- package/src/server/migrations/20221129153547-calculation-variables.ts +64 -0
- package/src/server/migrations/20230221032941-change-request-body-type.ts +76 -0
- package/src/server/migrations/20230221071831-calculation-expression.ts +102 -0
- package/src/server/migrations/20230221121203-condition-calculation.ts +82 -0
- package/src/server/migrations/20230221162902-jsonb-to-json.ts +51 -0
- package/src/server/migrations/20230411034722-manual-multi-form.ts +282 -0
- package/src/server/migrations/20230612021134-manual-collection-block.ts +138 -0
- package/src/server/migrations/20230710115902-manual-action-values.ts +78 -0
- package/src/server/triggers/collection.ts +146 -0
- package/src/server/triggers/index.ts +22 -0
- package/src/server/triggers/schedule.ts +567 -0
- package/src/server/types/Execution.ts +26 -0
- package/src/server/types/FlowNode.ts +21 -0
- package/src/server/types/Job.ts +18 -0
- package/src/server/types/Workflow.ts +36 -0
- package/src/server/types/index.ts +4 -0
- package/src/server/utils.ts +17 -0
- package/lib/client/triggers/schedule/DateFieldsSelect.d.ts +0 -2
- /package/lib/server/{models → types}/Execution.js +0 -0
- /package/lib/server/{models → types}/FlowNode.js +0 -0
- /package/lib/server/{models → types}/Job.js +0 -0
- /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,69 @@
|
|
|
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': 'ManualActionDesigner',
|
|
38
|
+
'x-designer-props': {},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
...schema,
|
|
42
|
+
template,
|
|
43
|
+
});
|
|
44
|
+
delete result['x-acl-action-props'];
|
|
45
|
+
delete result['x-acl-action'];
|
|
46
|
+
const [formKey] = Object.keys(result.properties);
|
|
47
|
+
result.properties[formKey].properties.actions['x-decorator'] = 'ActionBarProvider';
|
|
48
|
+
result.properties[formKey].properties.actions['x-component-props'].style = {
|
|
49
|
+
marginTop: '1.5em',
|
|
50
|
+
flexWrap: 'wrap',
|
|
51
|
+
};
|
|
52
|
+
traverseSchema(result, (node) => {
|
|
53
|
+
if (node['x-uid']) {
|
|
54
|
+
delete node['x-uid'];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
insert(result);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return <SchemaInitializer.Item {...others} onClick={onConfirm} items={items} />;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function FormBlockInitializer(props) {
|
|
64
|
+
return (
|
|
65
|
+
<CollectionProvider collection={props.schema?.collection}>
|
|
66
|
+
<InternalFormBlockInitializer {...props} />
|
|
67
|
+
</CollectionProvider>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
@@ -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
|
+
}
|