@nocobase/plugin-workflow-manual 1.0.0-alpha.2 → 1.0.0-alpha.3
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/dist/client/WorkflowTodo.d.ts +8 -0
- package/dist/client/WorkflowTodoBlockInitializer.d.ts +8 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +9 -0
- package/dist/client/instruction/AssigneesSelect.d.ts +8 -0
- package/dist/client/instruction/FormBlockInitializer.d.ts +8 -0
- package/dist/client/instruction/FormBlockProvider.d.ts +8 -0
- package/dist/client/instruction/ModeConfig.d.ts +8 -0
- package/dist/client/instruction/SchemaConfig.d.ts +8 -0
- package/dist/client/instruction/createManualFormBlockUISchema.d.ts +8 -0
- package/dist/client/instruction/forms/create.d.ts +8 -0
- package/dist/client/instruction/forms/custom.d.ts +8 -0
- package/dist/client/instruction/forms/update.d.ts +8 -0
- package/dist/client/instruction/index.d.ts +8 -0
- package/dist/client/instruction/utils.d.ts +8 -0
- package/dist/externalVersion.js +18 -9
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/locale/index.d.ts +8 -0
- package/dist/locale/index.js +9 -0
- package/dist/server/ManualInstruction.d.ts +8 -0
- package/dist/server/ManualInstruction.js +9 -0
- package/dist/server/Plugin.d.ts +8 -0
- package/dist/server/Plugin.js +9 -0
- package/dist/server/actions.d.ts +8 -0
- package/dist/server/actions.js +9 -0
- package/dist/server/collections/1-users_jobs.d.ts +8 -0
- package/dist/server/collections/1-users_jobs.js +9 -0
- package/dist/server/collections/2-jobs.d.ts +8 -0
- package/dist/server/collections/2-jobs.js +9 -0
- package/dist/server/collections/3-users.d.ts +8 -0
- package/dist/server/collections/3-users.js +9 -0
- package/dist/server/forms/create.d.ts +8 -0
- package/dist/server/forms/create.js +9 -0
- package/dist/server/forms/index.d.ts +8 -0
- package/dist/server/forms/index.js +9 -0
- package/dist/server/forms/update.d.ts +8 -0
- package/dist/server/forms/update.js +9 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +9 -0
- package/dist/server/migrations/20240325213145-fix-schema.d.ts +8 -0
- package/dist/server/migrations/20240325213145-fix-schema.js +9 -0
- package/package.json +2 -2
- package/src/client/WorkflowTodo.tsx +0 -647
- package/src/client/WorkflowTodoBlockInitializer.tsx +0 -32
- package/src/client/__e2e__/assignees.test.ts +0 -0
- package/src/client/__e2e__/createRecordForm.test.ts +0 -2287
- package/src/client/__e2e__/customFormBlocks.test.ts +0 -1933
- package/src/client/__e2e__/datablocks.test.ts +0 -1208
- package/src/client/__e2e__/updateRecordForm.test.ts +0 -2338
- package/src/client/__e2e__/workflowTodo.test.ts +0 -242
- package/src/client/index.ts +0 -51
- package/src/client/instruction/AssigneesSelect.tsx +0 -39
- package/src/client/instruction/FormBlockInitializer.tsx +0 -79
- package/src/client/instruction/FormBlockProvider.tsx +0 -92
- package/src/client/instruction/ModeConfig.tsx +0 -85
- package/src/client/instruction/SchemaConfig.tsx +0 -659
- package/src/client/instruction/createManualFormBlockUISchema.ts +0 -5
- package/src/client/instruction/forms/create.tsx +0 -123
- package/src/client/instruction/forms/custom.tsx +0 -439
- package/src/client/instruction/forms/update.tsx +0 -167
- package/src/client/instruction/index.tsx +0 -160
- package/src/client/instruction/utils.ts +0 -19
- package/src/index.ts +0 -2
- package/src/locale/en-US.json +0 -30
- package/src/locale/index.ts +0 -14
- package/src/locale/ko_KR.json +0 -32
- package/src/locale/zh-CN.json +0 -32
- package/src/server/ManualInstruction.ts +0 -157
- package/src/server/Plugin.ts +0 -43
- package/src/server/__tests__/assignees.test.ts +0 -153
- package/src/server/__tests__/collections/categories.ts +0 -15
- package/src/server/__tests__/collections/comments.ts +0 -24
- package/src/server/__tests__/collections/posts.ts +0 -40
- package/src/server/__tests__/collections/replies.ts +0 -9
- package/src/server/__tests__/collections/tags.ts +0 -15
- package/src/server/__tests__/data-source.test.ts +0 -223
- package/src/server/__tests__/form.test.ts +0 -637
- package/src/server/__tests__/mode.test.ts +0 -561
- package/src/server/actions.ts +0 -103
- package/src/server/collections/1-users_jobs.ts +0 -52
- package/src/server/collections/2-jobs.ts +0 -19
- package/src/server/collections/3-users.ts +0 -17
- package/src/server/forms/create.ts +0 -30
- package/src/server/forms/index.ts +0 -13
- package/src/server/forms/update.ts +0 -30
- package/src/server/index.ts +0 -1
- package/src/server/migrations/20240325213145-fix-schema.ts +0 -82
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import React, { useMemo, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
GeneralSchemaDesigner,
|
|
5
|
-
SchemaSettingsBlockTitleItem,
|
|
6
|
-
SchemaSettingsDataTemplates,
|
|
7
|
-
SchemaSettingsDivider,
|
|
8
|
-
SchemaSettingsLinkageRules,
|
|
9
|
-
SchemaSettingsRemove,
|
|
10
|
-
useCollection_deprecated,
|
|
11
|
-
useGetSchemaInitializerMenuItems,
|
|
12
|
-
useMenuSearch,
|
|
13
|
-
} from '@nocobase/client';
|
|
14
|
-
|
|
15
|
-
import _ from 'lodash';
|
|
16
|
-
import { NAMESPACE } from '../../../locale';
|
|
17
|
-
import { FormBlockInitializer } from '../FormBlockInitializer';
|
|
18
|
-
import { ManualFormType } from '../SchemaConfig';
|
|
19
|
-
import { findSchema } from '../utils';
|
|
20
|
-
|
|
21
|
-
function CreateFormDesigner() {
|
|
22
|
-
const { name, title } = useCollection_deprecated();
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<GeneralSchemaDesigner title={title || name}>
|
|
26
|
-
<SchemaSettingsBlockTitleItem />
|
|
27
|
-
<SchemaSettingsLinkageRules collectionName={name} />
|
|
28
|
-
<SchemaSettingsDataTemplates collectionName={name} />
|
|
29
|
-
<SchemaSettingsDivider />
|
|
30
|
-
<SchemaSettingsRemove
|
|
31
|
-
removeParentsIfNoChildren
|
|
32
|
-
breakRemoveOn={{
|
|
33
|
-
'x-component': 'Grid',
|
|
34
|
-
}}
|
|
35
|
-
/>
|
|
36
|
-
</GeneralSchemaDesigner>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default {
|
|
41
|
-
title: `{{t("Create record form", { ns: "${NAMESPACE}" })}}`,
|
|
42
|
-
config: {
|
|
43
|
-
useInitializer({ allCollections }) {
|
|
44
|
-
const childItems = useMemo(
|
|
45
|
-
() =>
|
|
46
|
-
allCollections.map(({ key, displayName, collections }) => ({
|
|
47
|
-
key: key,
|
|
48
|
-
name: key,
|
|
49
|
-
label: displayName,
|
|
50
|
-
type: 'subMenu',
|
|
51
|
-
children: collections.map((item) => ({
|
|
52
|
-
name: _.camelCase(`createRecordForm-child-${item.name}`),
|
|
53
|
-
type: 'item',
|
|
54
|
-
title: item.title || item.tableName,
|
|
55
|
-
schema: {
|
|
56
|
-
collection: item.name,
|
|
57
|
-
dataSource: key,
|
|
58
|
-
title: `{{t("Create record", { ns: "${NAMESPACE}" })}}`,
|
|
59
|
-
formType: 'create',
|
|
60
|
-
'x-designer': 'CreateFormDesigner',
|
|
61
|
-
},
|
|
62
|
-
Component: FormBlockInitializer,
|
|
63
|
-
})),
|
|
64
|
-
})),
|
|
65
|
-
[allCollections],
|
|
66
|
-
);
|
|
67
|
-
const [openMenuKeys, setOpenMenuKeys] = useState([]);
|
|
68
|
-
const searchedChildren = useMenuSearch({ data: childItems, openKeys: openMenuKeys });
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
name: 'createRecordForm',
|
|
72
|
-
key: 'createRecordForm',
|
|
73
|
-
type: 'subMenu',
|
|
74
|
-
title: `{{t("Create record form", { ns: "${NAMESPACE}" })}}`,
|
|
75
|
-
componentProps: {
|
|
76
|
-
onOpenChange(keys) {
|
|
77
|
-
setOpenMenuKeys(keys);
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
children: searchedChildren,
|
|
81
|
-
} as any;
|
|
82
|
-
},
|
|
83
|
-
initializers: {
|
|
84
|
-
// AddCustomFormField
|
|
85
|
-
},
|
|
86
|
-
components: {
|
|
87
|
-
CreateFormDesigner,
|
|
88
|
-
},
|
|
89
|
-
parseFormOptions(root) {
|
|
90
|
-
const forms = {};
|
|
91
|
-
const formBlocks: any[] = findSchema(
|
|
92
|
-
root,
|
|
93
|
-
(item) => item['x-decorator'] === 'FormBlockProvider' && item['x-decorator-props'].formType === 'create',
|
|
94
|
-
);
|
|
95
|
-
formBlocks.forEach((formBlock) => {
|
|
96
|
-
const [formKey] = Object.keys(formBlock.properties);
|
|
97
|
-
const formSchema = formBlock.properties[formKey];
|
|
98
|
-
//获取actionBar的schemakey
|
|
99
|
-
const actionKey =
|
|
100
|
-
Object.entries(formSchema.properties).find(([key, f]) => f['x-component'] === 'ActionBar')?.[0] || 'actions';
|
|
101
|
-
forms[formKey] = {
|
|
102
|
-
type: 'create',
|
|
103
|
-
title: formBlock['x-component-props']?.title || formKey,
|
|
104
|
-
actions: findSchema(formSchema.properties[actionKey], (item) => item['x-component'] === 'Action').map(
|
|
105
|
-
(item) => ({
|
|
106
|
-
status: item['x-decorator-props'].value,
|
|
107
|
-
values: item['x-action-settings']?.assignedValues?.values,
|
|
108
|
-
key: item.name,
|
|
109
|
-
}),
|
|
110
|
-
),
|
|
111
|
-
collection: formBlock['x-decorator-props'].collection,
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
return forms;
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
block: {
|
|
118
|
-
scope: {
|
|
119
|
-
// useFormBlockProps
|
|
120
|
-
},
|
|
121
|
-
components: {},
|
|
122
|
-
},
|
|
123
|
-
} as ManualFormType;
|
|
@@ -1,439 +0,0 @@
|
|
|
1
|
-
import React, { useContext, useMemo, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import { ArrayTable } from '@formily/antd-v5';
|
|
4
|
-
import { Field, createForm } from '@formily/core';
|
|
5
|
-
import { useField, useFieldSchema, useForm } from '@formily/react';
|
|
6
|
-
import { cloneDeep, pick, set } from 'lodash';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
ActionContextProvider,
|
|
10
|
-
CollectionProvider_deprecated,
|
|
11
|
-
CompatibleSchemaInitializer,
|
|
12
|
-
FormBlockContext,
|
|
13
|
-
RecordProvider,
|
|
14
|
-
SchemaComponent,
|
|
15
|
-
SchemaInitializerItem,
|
|
16
|
-
SchemaInitializerItemType,
|
|
17
|
-
SchemaInitializerItems,
|
|
18
|
-
gridRowColWrap,
|
|
19
|
-
useCollectionManager_deprecated,
|
|
20
|
-
useCollection_deprecated,
|
|
21
|
-
useRecord,
|
|
22
|
-
useSchemaInitializer,
|
|
23
|
-
useSchemaInitializerItem,
|
|
24
|
-
} from '@nocobase/client';
|
|
25
|
-
import { JOB_STATUS } from '@nocobase/plugin-workflow/client';
|
|
26
|
-
import { merge, uid } from '@nocobase/utils/client';
|
|
27
|
-
|
|
28
|
-
import { NAMESPACE, useLang } from '../../../locale';
|
|
29
|
-
import { ManualFormType } from '../SchemaConfig';
|
|
30
|
-
import { findSchema } from '../utils';
|
|
31
|
-
|
|
32
|
-
function CustomFormBlockProvider(props) {
|
|
33
|
-
const [fields, setCollectionFields] = useState(props.collection?.fields ?? []);
|
|
34
|
-
const userJob = useRecord();
|
|
35
|
-
const field = useField();
|
|
36
|
-
const fieldSchema = useFieldSchema();
|
|
37
|
-
const [formKey] = Object.keys(fieldSchema.toJSON().properties ?? {});
|
|
38
|
-
const values = userJob?.result?.[formKey];
|
|
39
|
-
|
|
40
|
-
const form = useMemo(
|
|
41
|
-
() =>
|
|
42
|
-
createForm({
|
|
43
|
-
initialValues: values,
|
|
44
|
-
}),
|
|
45
|
-
[values],
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
return !userJob.status || values ? (
|
|
49
|
-
<CollectionProvider_deprecated
|
|
50
|
-
collection={{
|
|
51
|
-
...props.collection,
|
|
52
|
-
fields,
|
|
53
|
-
}}
|
|
54
|
-
>
|
|
55
|
-
<RecordProvider record={values} parent={null}>
|
|
56
|
-
<FormBlockContext.Provider
|
|
57
|
-
value={{
|
|
58
|
-
form,
|
|
59
|
-
field,
|
|
60
|
-
setCollectionFields,
|
|
61
|
-
}}
|
|
62
|
-
>
|
|
63
|
-
{props.children}
|
|
64
|
-
</FormBlockContext.Provider>
|
|
65
|
-
</RecordProvider>
|
|
66
|
-
</CollectionProvider_deprecated>
|
|
67
|
-
) : null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function CustomFormBlockInitializer() {
|
|
71
|
-
const { insert } = useSchemaInitializer();
|
|
72
|
-
const itemConfig = useSchemaInitializerItem();
|
|
73
|
-
return (
|
|
74
|
-
<SchemaInitializerItem
|
|
75
|
-
{...itemConfig}
|
|
76
|
-
onClick={() => {
|
|
77
|
-
insert({
|
|
78
|
-
type: 'void',
|
|
79
|
-
'x-decorator': 'CustomFormBlockProvider',
|
|
80
|
-
'x-decorator-props': {
|
|
81
|
-
collection: {
|
|
82
|
-
name: uid(),
|
|
83
|
-
fields: [],
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
'x-component': 'CardItem',
|
|
87
|
-
'x-component-props': {
|
|
88
|
-
title: '{{t("Form")}}',
|
|
89
|
-
},
|
|
90
|
-
'x-designer': 'SimpleDesigner',
|
|
91
|
-
'x-designer-props': {
|
|
92
|
-
type: 'customForm',
|
|
93
|
-
},
|
|
94
|
-
properties: {
|
|
95
|
-
[uid()]: {
|
|
96
|
-
type: 'void',
|
|
97
|
-
'x-component': 'FormV2',
|
|
98
|
-
'x-use-component-props': 'useFormBlockProps',
|
|
99
|
-
properties: {
|
|
100
|
-
grid: {
|
|
101
|
-
type: 'void',
|
|
102
|
-
'x-component': 'Grid',
|
|
103
|
-
'x-initializer': 'workflowManual:customForm:configureFields',
|
|
104
|
-
},
|
|
105
|
-
actions: {
|
|
106
|
-
type: 'void',
|
|
107
|
-
'x-decorator': 'ActionBarProvider',
|
|
108
|
-
'x-component': 'ActionBar',
|
|
109
|
-
'x-component-props': {
|
|
110
|
-
layout: 'one-column',
|
|
111
|
-
style: {
|
|
112
|
-
marginTop: '1.5em',
|
|
113
|
-
flexWrap: 'wrap',
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
'x-initializer': 'workflowManual:form:configureActions',
|
|
117
|
-
properties: {
|
|
118
|
-
resolve: {
|
|
119
|
-
type: 'void',
|
|
120
|
-
title: `{{t("Continue the process", { ns: "${NAMESPACE}" })}}`,
|
|
121
|
-
'x-decorator': 'ManualActionStatusProvider',
|
|
122
|
-
'x-decorator-props': {
|
|
123
|
-
value: JOB_STATUS.RESOLVED,
|
|
124
|
-
},
|
|
125
|
-
'x-component': 'Action',
|
|
126
|
-
'x-component-props': {
|
|
127
|
-
type: 'primary',
|
|
128
|
-
useAction: '{{ useSubmit }}',
|
|
129
|
-
},
|
|
130
|
-
'x-designer': 'ManualActionDesigner',
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
}}
|
|
139
|
-
/>
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const GroupLabels = {
|
|
144
|
-
basic: '{{t("Basic")}}',
|
|
145
|
-
choices: '{{t("Choices")}}',
|
|
146
|
-
media: '{{t("Media")}}',
|
|
147
|
-
datetime: '{{t("Date & Time")}}',
|
|
148
|
-
relation: '{{t("Relation")}}',
|
|
149
|
-
advanced: '{{t("Advanced type")}}',
|
|
150
|
-
systemInfo: '{{t("System info")}}',
|
|
151
|
-
others: '{{t("Others")}}',
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
function getOptions(interfaces) {
|
|
155
|
-
const fields = {};
|
|
156
|
-
|
|
157
|
-
Object.keys(interfaces).forEach((type) => {
|
|
158
|
-
const schema = interfaces[type];
|
|
159
|
-
const { group = 'others' } = schema;
|
|
160
|
-
fields[group] = fields[group] || {};
|
|
161
|
-
set(fields, [group, type], schema);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
return Object.keys(GroupLabels)
|
|
165
|
-
.filter((groupName) => ['basic', 'choices', 'datetime', 'media'].includes(groupName))
|
|
166
|
-
.map((groupName) => ({
|
|
167
|
-
title: GroupLabels[groupName],
|
|
168
|
-
children: Object.keys(fields[groupName] || {})
|
|
169
|
-
.map((type) => {
|
|
170
|
-
const field = fields[groupName][type];
|
|
171
|
-
return {
|
|
172
|
-
value: type,
|
|
173
|
-
title: field.title,
|
|
174
|
-
name: type,
|
|
175
|
-
...fields[groupName][type],
|
|
176
|
-
};
|
|
177
|
-
})
|
|
178
|
-
.sort((a, b) => a.order - b.order),
|
|
179
|
-
}));
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function useCommonInterfaceInitializers(): SchemaInitializerItemType[] {
|
|
183
|
-
const { interfaces } = useCollectionManager_deprecated();
|
|
184
|
-
const options = getOptions(interfaces);
|
|
185
|
-
|
|
186
|
-
return options.map((group) => ({
|
|
187
|
-
name: group.title,
|
|
188
|
-
type: 'itemGroup',
|
|
189
|
-
title: group.title,
|
|
190
|
-
children: group.children.map((item) => ({
|
|
191
|
-
name: item.name,
|
|
192
|
-
type: 'item',
|
|
193
|
-
title: item.title,
|
|
194
|
-
Component: CustomFormFieldInitializer,
|
|
195
|
-
fieldInterface: item.name,
|
|
196
|
-
})),
|
|
197
|
-
}));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const AddCustomFormFieldButtonContext = React.createContext<any>({});
|
|
201
|
-
|
|
202
|
-
const CustomItemsComponent = (props) => {
|
|
203
|
-
const [interfaceOptions, setInterface] = useState<any>(null);
|
|
204
|
-
const [insert, setCallback] = useState<any>();
|
|
205
|
-
const items = useCommonInterfaceInitializers();
|
|
206
|
-
const collection = useCollection_deprecated();
|
|
207
|
-
const { setCollectionFields } = useContext(FormBlockContext);
|
|
208
|
-
const form = useMemo(() => createForm(), [interfaceOptions]);
|
|
209
|
-
|
|
210
|
-
return (
|
|
211
|
-
<AddCustomFormFieldButtonContext.Provider
|
|
212
|
-
value={{
|
|
213
|
-
onAddField(item) {
|
|
214
|
-
const fieldInterface: Record<string, any> = pick(item, [
|
|
215
|
-
'name',
|
|
216
|
-
'group',
|
|
217
|
-
'title',
|
|
218
|
-
'default',
|
|
219
|
-
'validateSchema',
|
|
220
|
-
]);
|
|
221
|
-
const {
|
|
222
|
-
properties: { unique, type, layout, autoIncrement, ...properties },
|
|
223
|
-
} = item;
|
|
224
|
-
fieldInterface.properties = properties;
|
|
225
|
-
const result = cloneDeep(fieldInterface);
|
|
226
|
-
delete result.properties.name['x-disabled'];
|
|
227
|
-
setInterface(result);
|
|
228
|
-
},
|
|
229
|
-
setCallback,
|
|
230
|
-
}}
|
|
231
|
-
>
|
|
232
|
-
<SchemaInitializerItems {...props} items={items} />
|
|
233
|
-
<ActionContextProvider
|
|
234
|
-
value={{
|
|
235
|
-
visible: Boolean(interfaceOptions),
|
|
236
|
-
setVisible(v) {
|
|
237
|
-
if (!v) {
|
|
238
|
-
setInterface(null);
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
}}
|
|
242
|
-
>
|
|
243
|
-
{interfaceOptions ? (
|
|
244
|
-
<SchemaComponent
|
|
245
|
-
schema={{
|
|
246
|
-
type: 'void',
|
|
247
|
-
name: 'drawer',
|
|
248
|
-
title: '{{t("Configure field")}}',
|
|
249
|
-
'x-decorator': 'FormV2',
|
|
250
|
-
'x-decorator-props': {
|
|
251
|
-
form,
|
|
252
|
-
},
|
|
253
|
-
'x-component': 'Action.Drawer',
|
|
254
|
-
properties: {
|
|
255
|
-
...interfaceOptions.properties,
|
|
256
|
-
footer: {
|
|
257
|
-
type: 'void',
|
|
258
|
-
'x-component': 'Action.Drawer.Footer',
|
|
259
|
-
properties: {
|
|
260
|
-
cancel: {
|
|
261
|
-
type: 'void',
|
|
262
|
-
title: '{{t("Cancel")}}',
|
|
263
|
-
'x-component': 'Action',
|
|
264
|
-
'x-component-props': {
|
|
265
|
-
useAction() {
|
|
266
|
-
const form = useForm();
|
|
267
|
-
return {
|
|
268
|
-
async run() {
|
|
269
|
-
setCallback(null);
|
|
270
|
-
setInterface(null);
|
|
271
|
-
form.reset();
|
|
272
|
-
},
|
|
273
|
-
};
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
submit: {
|
|
278
|
-
type: 'void',
|
|
279
|
-
title: '{{t("Submit")}}',
|
|
280
|
-
'x-component': 'Action',
|
|
281
|
-
'x-component-props': {
|
|
282
|
-
type: 'primary',
|
|
283
|
-
useAction() {
|
|
284
|
-
const { values, query, reset } = useForm();
|
|
285
|
-
const messages = [useLang('Field name existed in form')];
|
|
286
|
-
return {
|
|
287
|
-
async run() {
|
|
288
|
-
const { default: options } = interfaceOptions;
|
|
289
|
-
const defaultName = uid();
|
|
290
|
-
options.name = values.name ?? defaultName;
|
|
291
|
-
options.uiSchema.title = values.uiSchema?.title ?? defaultName;
|
|
292
|
-
options.interface = interfaceOptions.name;
|
|
293
|
-
const existed = collection.fields?.find((item) => item.name === options.name);
|
|
294
|
-
if (existed) {
|
|
295
|
-
const field = query('name').take() as Field;
|
|
296
|
-
field.setFeedback({
|
|
297
|
-
type: 'error',
|
|
298
|
-
// code: 'FormulaError',
|
|
299
|
-
messages,
|
|
300
|
-
});
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
const newField = merge(options, values) as any;
|
|
304
|
-
setCollectionFields([...collection.fields, newField]);
|
|
305
|
-
|
|
306
|
-
insert({
|
|
307
|
-
name: options.name,
|
|
308
|
-
type: options.uiSchema.type,
|
|
309
|
-
'x-decorator': 'FormItem',
|
|
310
|
-
'x-component': 'CollectionField',
|
|
311
|
-
'x-component-props': {
|
|
312
|
-
field: newField,
|
|
313
|
-
},
|
|
314
|
-
'x-collection-field': `${collection.name}.${options.name}`,
|
|
315
|
-
// 'x-designer': 'FormItem.Designer',
|
|
316
|
-
'x-toolbar': 'FormItemSchemaToolbar',
|
|
317
|
-
'x-settings': 'fieldSettings:FormItem',
|
|
318
|
-
});
|
|
319
|
-
reset();
|
|
320
|
-
setCallback(null);
|
|
321
|
-
setInterface(null);
|
|
322
|
-
},
|
|
323
|
-
};
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
},
|
|
327
|
-
},
|
|
328
|
-
},
|
|
329
|
-
},
|
|
330
|
-
}}
|
|
331
|
-
components={{
|
|
332
|
-
ArrayTable,
|
|
333
|
-
}}
|
|
334
|
-
/>
|
|
335
|
-
) : null}
|
|
336
|
-
</ActionContextProvider>
|
|
337
|
-
</AddCustomFormFieldButtonContext.Provider>
|
|
338
|
-
);
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* @deprecated
|
|
343
|
-
* use `addCustomFormField` instead
|
|
344
|
-
*/
|
|
345
|
-
export const addCustomFormField_deprecated = new CompatibleSchemaInitializer({
|
|
346
|
-
name: 'AddCustomFormField',
|
|
347
|
-
wrap: gridRowColWrap,
|
|
348
|
-
insertPosition: 'beforeEnd',
|
|
349
|
-
title: "{{t('Configure fields')}}",
|
|
350
|
-
ItemsComponent: CustomItemsComponent,
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
export const addCustomFormField = new CompatibleSchemaInitializer(
|
|
354
|
-
{
|
|
355
|
-
name: 'workflowManual:customForm:configureFields',
|
|
356
|
-
wrap: gridRowColWrap,
|
|
357
|
-
insertPosition: 'beforeEnd',
|
|
358
|
-
title: "{{t('Configure fields')}}",
|
|
359
|
-
ItemsComponent: CustomItemsComponent,
|
|
360
|
-
},
|
|
361
|
-
addCustomFormField_deprecated,
|
|
362
|
-
);
|
|
363
|
-
|
|
364
|
-
function CustomFormFieldInitializer() {
|
|
365
|
-
const itemConfig = useSchemaInitializerItem();
|
|
366
|
-
const { insert, setVisible } = useSchemaInitializer();
|
|
367
|
-
const { onAddField, setCallback } = useContext(AddCustomFormFieldButtonContext);
|
|
368
|
-
const { getInterface } = useCollectionManager_deprecated();
|
|
369
|
-
|
|
370
|
-
const interfaceOptions = getInterface(itemConfig.fieldInterface);
|
|
371
|
-
|
|
372
|
-
return (
|
|
373
|
-
<SchemaInitializerItem
|
|
374
|
-
key={itemConfig.fieldInterface}
|
|
375
|
-
onClick={() => {
|
|
376
|
-
setCallback(() => insert);
|
|
377
|
-
onAddField(interfaceOptions);
|
|
378
|
-
setVisible(false);
|
|
379
|
-
}}
|
|
380
|
-
{...itemConfig}
|
|
381
|
-
/>
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
export default {
|
|
386
|
-
title: `{{t("Custom form", { ns: "${NAMESPACE}" })}}`,
|
|
387
|
-
config: {
|
|
388
|
-
useInitializer() {
|
|
389
|
-
return {
|
|
390
|
-
name: 'customForm',
|
|
391
|
-
type: 'item',
|
|
392
|
-
title: `{{t("Custom form", { ns: "${NAMESPACE}" })}}`,
|
|
393
|
-
Component: CustomFormBlockInitializer,
|
|
394
|
-
};
|
|
395
|
-
},
|
|
396
|
-
initializers: {},
|
|
397
|
-
components: {
|
|
398
|
-
CustomFormBlockProvider,
|
|
399
|
-
},
|
|
400
|
-
parseFormOptions(root) {
|
|
401
|
-
const forms = {};
|
|
402
|
-
const formBlocks: any[] = findSchema(root, (item) => item['x-decorator'] === 'CustomFormBlockProvider');
|
|
403
|
-
formBlocks.forEach((formBlock) => {
|
|
404
|
-
const [formKey] = Object.keys(formBlock.properties);
|
|
405
|
-
const formSchema = formBlock.properties[formKey];
|
|
406
|
-
const fields = findSchema(
|
|
407
|
-
formSchema.properties.grid,
|
|
408
|
-
(item) => item['x-component'] === 'CollectionField',
|
|
409
|
-
true,
|
|
410
|
-
);
|
|
411
|
-
formBlock['x-decorator-props'].collection.fields = fields.map(
|
|
412
|
-
(field) => field['x-component-props']?.field ?? field['x-interface-options'],
|
|
413
|
-
);
|
|
414
|
-
//获取actionBar的schemakey
|
|
415
|
-
const actionKey =
|
|
416
|
-
Object.entries(formSchema.properties).find(([key, f]) => f['x-component'] === 'ActionBar')?.[0] || 'actions';
|
|
417
|
-
forms[formKey] = {
|
|
418
|
-
type: 'custom',
|
|
419
|
-
title: formBlock['x-component-props']?.title || formKey,
|
|
420
|
-
actions: findSchema(formSchema.properties[actionKey], (item) => item['x-component'] === 'Action').map(
|
|
421
|
-
(item) => ({
|
|
422
|
-
status: item['x-decorator-props'].value,
|
|
423
|
-
values: item['x-action-settings']?.assignedValues?.values,
|
|
424
|
-
key: item.name,
|
|
425
|
-
}),
|
|
426
|
-
),
|
|
427
|
-
collection: formBlock['x-decorator-props'].collection,
|
|
428
|
-
};
|
|
429
|
-
});
|
|
430
|
-
return forms;
|
|
431
|
-
},
|
|
432
|
-
},
|
|
433
|
-
block: {
|
|
434
|
-
scope: {},
|
|
435
|
-
components: {
|
|
436
|
-
CustomFormBlockProvider,
|
|
437
|
-
},
|
|
438
|
-
},
|
|
439
|
-
} as ManualFormType;
|