@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,116 @@
|
|
|
1
|
+
import { css } from '@nocobase/client';
|
|
2
|
+
import { InputNumber, Select } from 'antd';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Cron } from 'react-js-cron';
|
|
5
|
+
import { useWorkflowTranslation } from '../../locale';
|
|
6
|
+
import CronZhCN from './locale/Cron.zh-CN';
|
|
7
|
+
|
|
8
|
+
const languages = {
|
|
9
|
+
'zh-CN': CronZhCN,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const RepeatOptions = [
|
|
13
|
+
{ value: 'none', text: 'No repeat' },
|
|
14
|
+
{ value: 60_000, text: 'By minute', unitText: 'Minutes' },
|
|
15
|
+
{ value: 3600_000, text: 'By hour', unitText: 'Hours' },
|
|
16
|
+
{ value: 86400_000, text: 'By day', unitText: 'Days' },
|
|
17
|
+
{ value: 604800_000, text: 'By week', unitText: 'Weeks' },
|
|
18
|
+
// { value: 18144_000_000, text: 'By 30 days' },
|
|
19
|
+
{ value: 'cron', text: 'Advanced' },
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
function getNumberOption(v) {
|
|
23
|
+
const opts = RepeatOptions.filter((option) => typeof option.value === 'number').reverse() as any[];
|
|
24
|
+
return opts.find((item) => !(v % item.value));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getRepeatTypeValue(v) {
|
|
28
|
+
switch (typeof v) {
|
|
29
|
+
case 'number':
|
|
30
|
+
const option = getNumberOption(v);
|
|
31
|
+
return option ? option.value : 'none';
|
|
32
|
+
case 'string':
|
|
33
|
+
return 'cron';
|
|
34
|
+
default:
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
return 'none';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function CommonRepeatField({ value, onChange }) {
|
|
41
|
+
const { t } = useWorkflowTranslation();
|
|
42
|
+
const option = getNumberOption(value);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<InputNumber
|
|
46
|
+
value={value / option.value}
|
|
47
|
+
onChange={(v) => onChange(v * option.value)}
|
|
48
|
+
min={1}
|
|
49
|
+
addonBefore={t('Every')}
|
|
50
|
+
addonAfter={t(option.unitText)}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function RepeatField({ value = null, onChange }) {
|
|
56
|
+
const { t } = useWorkflowTranslation();
|
|
57
|
+
const typeValue = getRepeatTypeValue(value);
|
|
58
|
+
function onTypeChange(v) {
|
|
59
|
+
if (v === 'none') {
|
|
60
|
+
onChange(null);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (v === 'cron') {
|
|
64
|
+
onChange('0 * * * * *');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
onChange(v);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const locale = languages[localStorage.getItem('NOCOBASE_LOCALE') || 'en-US'];
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<fieldset
|
|
74
|
+
className={css`
|
|
75
|
+
display: flex;
|
|
76
|
+
flex-direction: ${typeValue === 'cron' ? 'column' : 'row'};
|
|
77
|
+
align-items: flex-start;
|
|
78
|
+
gap: 0.5em;
|
|
79
|
+
|
|
80
|
+
.react-js-cron {
|
|
81
|
+
padding: 0.5em 0.5em 0 0.5em;
|
|
82
|
+
border: 1px dashed #ccc;
|
|
83
|
+
|
|
84
|
+
.react-js-cron-field {
|
|
85
|
+
margin-bottom: 0.5em;
|
|
86
|
+
|
|
87
|
+
> span {
|
|
88
|
+
margin: 0 0.5em 0 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
> .react-js-cron-select {
|
|
92
|
+
margin: 0 0.5em 0 0;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
`}
|
|
97
|
+
>
|
|
98
|
+
<Select value={typeValue} onChange={onTypeChange}>
|
|
99
|
+
{RepeatOptions.map((item) => (
|
|
100
|
+
<Select.Option key={item.value} value={item.value}>
|
|
101
|
+
{t(item.text)}
|
|
102
|
+
</Select.Option>
|
|
103
|
+
))}
|
|
104
|
+
</Select>
|
|
105
|
+
{typeof typeValue === 'number' ? <CommonRepeatField value={value} onChange={onChange} /> : null}
|
|
106
|
+
{typeValue === 'cron' ? (
|
|
107
|
+
<Cron
|
|
108
|
+
value={value.trim().split(/\s+/).slice(1).join(' ')}
|
|
109
|
+
setValue={(v) => onChange(`0 ${v}`)}
|
|
110
|
+
clearButton={false}
|
|
111
|
+
locale={locale}
|
|
112
|
+
/>
|
|
113
|
+
) : null}
|
|
114
|
+
</fieldset>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { onFieldValueChange } from '@formily/core';
|
|
2
|
+
import { useForm, useFormEffects, ISchema } from '@formily/react';
|
|
3
|
+
import { css, SchemaComponent } from '@nocobase/client';
|
|
4
|
+
import React, { useState } from 'react';
|
|
5
|
+
import { NAMESPACE } from '../../locale';
|
|
6
|
+
import { appends, collection } from '../../schemas/collection';
|
|
7
|
+
import { SCHEDULE_MODE } from './constants';
|
|
8
|
+
import { EndsByField } from './EndsByField';
|
|
9
|
+
import { OnField } from './OnField';
|
|
10
|
+
import { RepeatField } from './RepeatField';
|
|
11
|
+
|
|
12
|
+
const ModeFieldsets = {
|
|
13
|
+
[SCHEDULE_MODE.STATIC]: {
|
|
14
|
+
startsOn: {
|
|
15
|
+
type: 'datetime',
|
|
16
|
+
title: `{{t("Starts on", { ns: "${NAMESPACE}" })}}`,
|
|
17
|
+
'x-decorator': 'FormItem',
|
|
18
|
+
'x-component': 'DatePicker',
|
|
19
|
+
'x-component-props': {
|
|
20
|
+
showTime: true,
|
|
21
|
+
},
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
repeat: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
title: `{{t("Repeat mode", { ns: "${NAMESPACE}" })}}`,
|
|
27
|
+
'x-decorator': 'FormItem',
|
|
28
|
+
'x-component': 'RepeatField',
|
|
29
|
+
'x-reactions': [
|
|
30
|
+
{
|
|
31
|
+
target: 'endsOn',
|
|
32
|
+
fulfill: {
|
|
33
|
+
state: {
|
|
34
|
+
visible: '{{!!$self.value}}',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
target: 'limit',
|
|
40
|
+
fulfill: {
|
|
41
|
+
state: {
|
|
42
|
+
visible: '{{!!$self.value}}',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
endsOn: {
|
|
49
|
+
type: 'datetime',
|
|
50
|
+
title: `{{t("Ends on", { ns: "${NAMESPACE}" })}}`,
|
|
51
|
+
'x-decorator': 'FormItem',
|
|
52
|
+
'x-component': 'DatePicker',
|
|
53
|
+
'x-component-props': {
|
|
54
|
+
showTime: true,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
limit: {
|
|
58
|
+
type: 'number',
|
|
59
|
+
title: `{{t("Repeat limit", { ns: "${NAMESPACE}" })}}`,
|
|
60
|
+
'x-decorator': 'FormItem',
|
|
61
|
+
'x-component': 'InputNumber',
|
|
62
|
+
'x-component-props': {
|
|
63
|
+
placeholder: `{{t("No limit", { ns: "${NAMESPACE}" })}}`,
|
|
64
|
+
min: 0,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
[SCHEDULE_MODE.COLLECTION_FIELD]: {
|
|
69
|
+
collection: {
|
|
70
|
+
...collection,
|
|
71
|
+
'x-reactions': [
|
|
72
|
+
...collection['x-reactions'],
|
|
73
|
+
{
|
|
74
|
+
// only full path works
|
|
75
|
+
target: 'startsOn',
|
|
76
|
+
fulfill: {
|
|
77
|
+
state: {
|
|
78
|
+
visible: '{{!!$self.value}}',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
startsOn: {
|
|
85
|
+
type: 'object',
|
|
86
|
+
title: `{{t("Starts on", { ns: "${NAMESPACE}" })}}`,
|
|
87
|
+
'x-decorator': 'FormItem',
|
|
88
|
+
'x-component': 'OnField',
|
|
89
|
+
'x-reactions': [
|
|
90
|
+
{
|
|
91
|
+
target: 'repeat',
|
|
92
|
+
fulfill: {
|
|
93
|
+
state: {
|
|
94
|
+
visible: '{{!!$self.value}}',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
required: true,
|
|
100
|
+
},
|
|
101
|
+
repeat: {
|
|
102
|
+
type: 'string',
|
|
103
|
+
title: `{{t("Repeat mode", { ns: "${NAMESPACE}" })}}`,
|
|
104
|
+
'x-decorator': 'FormItem',
|
|
105
|
+
'x-component': 'RepeatField',
|
|
106
|
+
'x-reactions': [
|
|
107
|
+
{
|
|
108
|
+
target: 'endsOn',
|
|
109
|
+
fulfill: {
|
|
110
|
+
state: {
|
|
111
|
+
visible: '{{!!$self.value}}',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
target: 'limit',
|
|
117
|
+
fulfill: {
|
|
118
|
+
state: {
|
|
119
|
+
visible: '{{!!$self.value}}',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
endsOn: {
|
|
126
|
+
type: 'object',
|
|
127
|
+
title: `{{t("Ends on", { ns: "${NAMESPACE}" })}}`,
|
|
128
|
+
'x-decorator': 'FormItem',
|
|
129
|
+
'x-component': 'EndsByField',
|
|
130
|
+
},
|
|
131
|
+
limit: {
|
|
132
|
+
type: 'number',
|
|
133
|
+
title: `{{t("Repeat limit", { ns: "${NAMESPACE}" })}}`,
|
|
134
|
+
'x-decorator': 'FormItem',
|
|
135
|
+
'x-component': 'InputNumber',
|
|
136
|
+
'x-component-props': {
|
|
137
|
+
placeholder: `{{t("No limit", { ns: "${NAMESPACE}" })}}`,
|
|
138
|
+
min: 0,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
appends: {
|
|
142
|
+
...appends,
|
|
143
|
+
'x-reactions': [
|
|
144
|
+
{
|
|
145
|
+
dependencies: ['mode', 'collection'],
|
|
146
|
+
fulfill: {
|
|
147
|
+
state: {
|
|
148
|
+
visible: `{{$deps[0] === ${SCHEDULE_MODE.COLLECTION_FIELD} && $deps[1]}}`,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const scheduleModeOptions = [
|
|
158
|
+
{ value: SCHEDULE_MODE.STATIC, label: `{{t("Based on certain date", { ns: "${NAMESPACE}" })}}` },
|
|
159
|
+
{
|
|
160
|
+
value: SCHEDULE_MODE.COLLECTION_FIELD,
|
|
161
|
+
label: `{{t("Based on date field of collection", { ns: "${NAMESPACE}" })}}`,
|
|
162
|
+
},
|
|
163
|
+
];
|
|
164
|
+
|
|
165
|
+
export const ScheduleConfig = () => {
|
|
166
|
+
const { values = {}, clearFormGraph } = useForm();
|
|
167
|
+
const [mode, setMode] = useState(values.mode);
|
|
168
|
+
useFormEffects(() => {
|
|
169
|
+
onFieldValueChange('mode', (field) => {
|
|
170
|
+
setMode(field.value);
|
|
171
|
+
clearFormGraph('collection');
|
|
172
|
+
clearFormGraph('startsOn');
|
|
173
|
+
clearFormGraph('repeat');
|
|
174
|
+
clearFormGraph('endsOn');
|
|
175
|
+
clearFormGraph('limit');
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<>
|
|
181
|
+
<SchemaComponent
|
|
182
|
+
schema={{
|
|
183
|
+
type: 'number',
|
|
184
|
+
title: `{{t("Trigger mode", { ns: "${NAMESPACE}" })}}`,
|
|
185
|
+
name: 'mode',
|
|
186
|
+
'x-decorator': 'FormItem',
|
|
187
|
+
'x-component': 'Radio.Group',
|
|
188
|
+
'x-component-props': {
|
|
189
|
+
options: scheduleModeOptions,
|
|
190
|
+
},
|
|
191
|
+
required: true,
|
|
192
|
+
default: SCHEDULE_MODE.STATIC,
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
<SchemaComponent
|
|
196
|
+
schema={
|
|
197
|
+
{
|
|
198
|
+
type: 'void',
|
|
199
|
+
properties: {
|
|
200
|
+
[`mode-${mode}`]: {
|
|
201
|
+
type: 'void',
|
|
202
|
+
'x-component': 'fieldset',
|
|
203
|
+
'x-component-props': {
|
|
204
|
+
className: css`
|
|
205
|
+
.ant-input-number {
|
|
206
|
+
width: 4em;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.ant-picker {
|
|
210
|
+
width: auto;
|
|
211
|
+
}
|
|
212
|
+
`,
|
|
213
|
+
},
|
|
214
|
+
properties: ModeFieldsets[mode],
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
} as ISchema
|
|
218
|
+
}
|
|
219
|
+
components={{
|
|
220
|
+
OnField,
|
|
221
|
+
RepeatField,
|
|
222
|
+
EndsByField,
|
|
223
|
+
}}
|
|
224
|
+
/>
|
|
225
|
+
</>
|
|
226
|
+
);
|
|
227
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useCollectionDataSource, SchemaInitializerItemOptions, useCompile, useCollectionManager } from '@nocobase/client';
|
|
2
|
+
|
|
3
|
+
import { ScheduleConfig } from './ScheduleConfig';
|
|
4
|
+
import { SCHEDULE_MODE } from './constants';
|
|
5
|
+
import { NAMESPACE, lang } from '../../locale';
|
|
6
|
+
import { CollectionBlockInitializer } from '../../components/CollectionBlockInitializer';
|
|
7
|
+
import { defaultFieldNames, getCollectionFieldOptions } from '../../variable';
|
|
8
|
+
import { FieldsSelect } from '../../components/FieldsSelect';
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title: `{{t("Schedule event", { ns: "${NAMESPACE}" })}}`,
|
|
12
|
+
type: 'schedule',
|
|
13
|
+
fieldset: {
|
|
14
|
+
config: {
|
|
15
|
+
type: 'void',
|
|
16
|
+
'x-component': 'ScheduleConfig',
|
|
17
|
+
'x-component-props': {},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
scope: {
|
|
21
|
+
useCollectionDataSource,
|
|
22
|
+
},
|
|
23
|
+
components: {
|
|
24
|
+
ScheduleConfig,
|
|
25
|
+
},
|
|
26
|
+
useVariables(config, opts) {
|
|
27
|
+
const compile = useCompile();
|
|
28
|
+
const { getCollectionFields } = useCollectionManager();
|
|
29
|
+
const { fieldNames = defaultFieldNames } = opts;
|
|
30
|
+
const options: any[] = [];
|
|
31
|
+
if (!opts?.types || opts.types.includes('date')) {
|
|
32
|
+
options.push({ key: 'date', value: 'date', label: lang('Trigger time') });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// const depth = config.appends?.length
|
|
36
|
+
// ? config.appends.reduce((max, item) => Math.max(max, item.split('.').length), 1) + 1
|
|
37
|
+
// : 1;
|
|
38
|
+
|
|
39
|
+
if (config.mode === SCHEDULE_MODE.COLLECTION_FIELD) {
|
|
40
|
+
const [fieldOption] = getCollectionFieldOptions({
|
|
41
|
+
// depth,
|
|
42
|
+
...opts,
|
|
43
|
+
fields: [
|
|
44
|
+
{
|
|
45
|
+
collectionName: config.collection,
|
|
46
|
+
name: 'data',
|
|
47
|
+
type: 'hasOne',
|
|
48
|
+
target: config.collection,
|
|
49
|
+
uiSchema: {
|
|
50
|
+
title: lang('Trigger data'),
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
appends: ['data', ...(config.appends?.map((item) => `data.${item}`) || [])],
|
|
55
|
+
compile,
|
|
56
|
+
getCollectionFields,
|
|
57
|
+
});
|
|
58
|
+
if (fieldOption) {
|
|
59
|
+
options.push(fieldOption);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return options;
|
|
63
|
+
},
|
|
64
|
+
useInitializers(config): SchemaInitializerItemOptions | null {
|
|
65
|
+
if (!config.collection) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
type: 'item',
|
|
71
|
+
title: `{{t("Trigger data", { ns: "${NAMESPACE}" })}}`,
|
|
72
|
+
component: CollectionBlockInitializer,
|
|
73
|
+
collection: config.collection,
|
|
74
|
+
dataSource: '{{$context.data}}',
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
initializers: {},
|
|
78
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
everyText: '每',
|
|
3
|
+
emptyMonths: '每月',
|
|
4
|
+
emptyMonthDays: '每日(月)',
|
|
5
|
+
emptyMonthDaysShort: '每日',
|
|
6
|
+
emptyWeekDays: '每天(周)',
|
|
7
|
+
emptyWeekDaysShort: '每天(周)',
|
|
8
|
+
emptyHours: '每小时',
|
|
9
|
+
emptyMinutes: '每分钟',
|
|
10
|
+
emptyMinutesForHourPeriod: '每',
|
|
11
|
+
yearOption: '年',
|
|
12
|
+
monthOption: '月',
|
|
13
|
+
weekOption: '周',
|
|
14
|
+
dayOption: '天',
|
|
15
|
+
hourOption: '小时',
|
|
16
|
+
minuteOption: '分钟',
|
|
17
|
+
rebootOption: '重启',
|
|
18
|
+
prefixPeriod: '每',
|
|
19
|
+
prefixMonths: '的',
|
|
20
|
+
prefixMonthDays: '的',
|
|
21
|
+
prefixWeekDays: '的',
|
|
22
|
+
prefixWeekDaysForMonthAndYearPeriod: '并且',
|
|
23
|
+
prefixHours: '的',
|
|
24
|
+
prefixMinutes: ':',
|
|
25
|
+
prefixMinutesForHourPeriod: '的',
|
|
26
|
+
suffixMinutesForHourPeriod: '分钟',
|
|
27
|
+
errorInvalidCron: '不符合 cron 规则的表达式',
|
|
28
|
+
clearButtonText: '清空',
|
|
29
|
+
weekDays: [
|
|
30
|
+
// Order is important, the index will be used as value
|
|
31
|
+
'周日', // Sunday must always be first, it's "0"
|
|
32
|
+
'周一',
|
|
33
|
+
'周二',
|
|
34
|
+
'周三',
|
|
35
|
+
'周四',
|
|
36
|
+
'周五',
|
|
37
|
+
'周六',
|
|
38
|
+
],
|
|
39
|
+
months: [
|
|
40
|
+
// Order is important, the index will be used as value
|
|
41
|
+
'一月',
|
|
42
|
+
'二月',
|
|
43
|
+
'三月',
|
|
44
|
+
'四月',
|
|
45
|
+
'五月',
|
|
46
|
+
'六月',
|
|
47
|
+
'七月',
|
|
48
|
+
'八月',
|
|
49
|
+
'九月',
|
|
50
|
+
'十月',
|
|
51
|
+
'十一月',
|
|
52
|
+
'十二月',
|
|
53
|
+
],
|
|
54
|
+
altWeekDays: [
|
|
55
|
+
// Order is important, the index will be used as value
|
|
56
|
+
'周日', // Sunday must always be first, it's "0"
|
|
57
|
+
'周一',
|
|
58
|
+
'周二',
|
|
59
|
+
'周三',
|
|
60
|
+
'周四',
|
|
61
|
+
'周五',
|
|
62
|
+
'周六',
|
|
63
|
+
],
|
|
64
|
+
altMonths: [
|
|
65
|
+
// Order is important, the index will be used as value
|
|
66
|
+
'一月',
|
|
67
|
+
'二月',
|
|
68
|
+
'三月',
|
|
69
|
+
'四月',
|
|
70
|
+
'五月',
|
|
71
|
+
'六月',
|
|
72
|
+
'七月',
|
|
73
|
+
'八月',
|
|
74
|
+
'九月',
|
|
75
|
+
'十月',
|
|
76
|
+
'十一月',
|
|
77
|
+
'十二月',
|
|
78
|
+
],
|
|
79
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function linkNodes(nodes): void {
|
|
2
|
+
const nodesMap = new Map();
|
|
3
|
+
nodes.forEach((item) => nodesMap.set(item.id, item));
|
|
4
|
+
for (const node of nodesMap.values()) {
|
|
5
|
+
if (node.upstreamId) {
|
|
6
|
+
node.upstream = nodesMap.get(node.upstreamId);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (node.downstreamId) {
|
|
10
|
+
node.downstream = nodesMap.get(node.downstreamId);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isValidFilter(condition) {
|
|
16
|
+
const group = condition.$and || condition.$or;
|
|
17
|
+
if (!group) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return group.some((item) => {
|
|
22
|
+
if (item.$and || item.$or) {
|
|
23
|
+
return isValidFilter(item);
|
|
24
|
+
}
|
|
25
|
+
const [name] = Object.keys(item);
|
|
26
|
+
if (!name || !item[name]) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const [op] = Object.keys(item[name]);
|
|
30
|
+
if (!op || typeof item[name][op] === 'undefined') {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
}
|