balibabu
commited on
Commit
·
2e208d4
1
Parent(s):
c3b184f
feat: Add complex dynamic form to SwitchForm #1739 (#2001)
Browse files### What problem does this PR solve?
feat: Add complex dynamic form to SwitchForm #1739
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
web/src/locales/en.ts
CHANGED
@@ -807,6 +807,7 @@ The above is the content you need to summarize.`,
|
|
807 |
port: 'Port',
|
808 |
password: 'Password',
|
809 |
switch: 'Switch',
|
|
|
810 |
},
|
811 |
footer: {
|
812 |
profile: 'All rights reserved @ React',
|
|
|
807 |
port: 'Port',
|
808 |
password: 'Password',
|
809 |
switch: 'Switch',
|
810 |
+
logicalOperator: 'Logical operator',
|
811 |
},
|
812 |
footer: {
|
813 |
profile: 'All rights reserved @ React',
|
web/src/locales/zh-traditional.ts
CHANGED
@@ -765,6 +765,7 @@ export default {
|
|
765 |
port: '端口',
|
766 |
password: '密碼',
|
767 |
switch: '條件',
|
|
|
768 |
},
|
769 |
footer: {
|
770 |
profile: '“保留所有權利 @ react”',
|
|
|
765 |
port: '端口',
|
766 |
password: '密碼',
|
767 |
switch: '條件',
|
768 |
+
logicalOperator: '操作符',
|
769 |
},
|
770 |
footer: {
|
771 |
profile: '“保留所有權利 @ react”',
|
web/src/locales/zh.ts
CHANGED
@@ -783,6 +783,7 @@ export default {
|
|
783 |
port: '端口',
|
784 |
password: '密码',
|
785 |
switch: '条件',
|
|
|
786 |
},
|
787 |
footer: {
|
788 |
profile: 'All rights reserved @ React',
|
|
|
783 |
port: '端口',
|
784 |
password: '密码',
|
785 |
switch: '条件',
|
786 |
+
logicalOperator: '操作符',
|
787 |
},
|
788 |
footer: {
|
789 |
profile: 'All rights reserved @ React',
|
web/src/pages/flow/constant.tsx
CHANGED
@@ -388,7 +388,7 @@ export const initialExeSqlValues = {
|
|
388 |
top_n: 30,
|
389 |
};
|
390 |
|
391 |
-
export const initialSwitchValues = {};
|
392 |
|
393 |
export const CategorizeAnchorPointPositions = [
|
394 |
{ top: 1, right: 34 },
|
|
|
388 |
top_n: 30,
|
389 |
};
|
390 |
|
391 |
+
export const initialSwitchValues = { conditions: [{}] };
|
392 |
|
393 |
export const CategorizeAnchorPointPositions = [
|
394 |
{ top: 1, right: 34 },
|
web/src/pages/flow/switch-form/index.tsx
CHANGED
@@ -1,5 +1,142 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
};
|
4 |
|
5 |
export default SwitchForm;
|
|
|
1 |
+
import { CloseOutlined } from '@ant-design/icons';
|
2 |
+
import { Button, Card, Form, Input, Typography } from 'antd';
|
3 |
+
import React from 'react';
|
4 |
+
import { useTranslation } from 'react-i18next';
|
5 |
+
import { IOperatorForm } from '../interface';
|
6 |
+
|
7 |
+
const subLabelCol = {
|
8 |
+
span: 7,
|
9 |
+
};
|
10 |
+
|
11 |
+
const subWrapperCol = {
|
12 |
+
span: 17,
|
13 |
+
};
|
14 |
+
|
15 |
+
const SwitchForm: React.FC = ({ form, onValuesChange }: IOperatorForm) => {
|
16 |
+
const { t } = useTranslation();
|
17 |
+
|
18 |
+
return (
|
19 |
+
<Form
|
20 |
+
labelCol={{ span: 8 }}
|
21 |
+
wrapperCol={{ span: 16 }}
|
22 |
+
form={form}
|
23 |
+
name="dynamic_form_complex"
|
24 |
+
autoComplete="off"
|
25 |
+
initialValues={{ conditions: [{}] }}
|
26 |
+
onValuesChange={onValuesChange}
|
27 |
+
>
|
28 |
+
<Form.Item label={t('flow.to')} name={['end_cpn_id']}>
|
29 |
+
<Input />
|
30 |
+
</Form.Item>
|
31 |
+
<Form.Item label={t('flow.no')} name={['no']}>
|
32 |
+
<Input />
|
33 |
+
</Form.Item>
|
34 |
+
<Form.List name="conditions">
|
35 |
+
{(fields, { add, remove }) => (
|
36 |
+
<div style={{ display: 'flex', rowGap: 16, flexDirection: 'column' }}>
|
37 |
+
{fields.map((field) => (
|
38 |
+
<Card
|
39 |
+
size="small"
|
40 |
+
title={`Item ${field.name + 1}`}
|
41 |
+
key={field.key}
|
42 |
+
extra={
|
43 |
+
<CloseOutlined
|
44 |
+
onClick={() => {
|
45 |
+
remove(field.name);
|
46 |
+
}}
|
47 |
+
/>
|
48 |
+
}
|
49 |
+
>
|
50 |
+
<Form.Item
|
51 |
+
label={t('flow.logicalOperator')}
|
52 |
+
name={[field.name, 'logical_operator']}
|
53 |
+
>
|
54 |
+
<Input />
|
55 |
+
</Form.Item>
|
56 |
+
|
57 |
+
<Form.Item label={t('flow.to')} name={[field.name, 'to']}>
|
58 |
+
<Input />
|
59 |
+
</Form.Item>
|
60 |
+
{/* Nest Form.List */}
|
61 |
+
<Form.Item label="Items">
|
62 |
+
<Form.List name={[field.name, 'items']}>
|
63 |
+
{(subFields, subOpt) => (
|
64 |
+
<div
|
65 |
+
style={{
|
66 |
+
display: 'flex',
|
67 |
+
flexDirection: 'column',
|
68 |
+
rowGap: 16,
|
69 |
+
}}
|
70 |
+
>
|
71 |
+
{subFields.map((subField) => (
|
72 |
+
<Card
|
73 |
+
key={subField.key}
|
74 |
+
title={null}
|
75 |
+
size="small"
|
76 |
+
extra={
|
77 |
+
<CloseOutlined
|
78 |
+
onClick={() => {
|
79 |
+
subOpt.remove(subField.name);
|
80 |
+
}}
|
81 |
+
/>
|
82 |
+
}
|
83 |
+
>
|
84 |
+
<Form.Item
|
85 |
+
label={'cpn_id'}
|
86 |
+
name={[subField.name, 'cpn_id']}
|
87 |
+
labelCol={subLabelCol}
|
88 |
+
wrapperCol={subWrapperCol}
|
89 |
+
>
|
90 |
+
<Input placeholder="cpn_id" />
|
91 |
+
</Form.Item>
|
92 |
+
<Form.Item
|
93 |
+
label={'operator'}
|
94 |
+
name={[subField.name, 'operator']}
|
95 |
+
labelCol={subLabelCol}
|
96 |
+
wrapperCol={subWrapperCol}
|
97 |
+
>
|
98 |
+
<Input placeholder="operator" />
|
99 |
+
</Form.Item>
|
100 |
+
<Form.Item
|
101 |
+
label={'value'}
|
102 |
+
name={[subField.name, 'value']}
|
103 |
+
labelCol={subLabelCol}
|
104 |
+
wrapperCol={subWrapperCol}
|
105 |
+
>
|
106 |
+
<Input placeholder="value" />
|
107 |
+
</Form.Item>
|
108 |
+
</Card>
|
109 |
+
))}
|
110 |
+
<Button
|
111 |
+
type="dashed"
|
112 |
+
onClick={() => subOpt.add()}
|
113 |
+
block
|
114 |
+
>
|
115 |
+
+ Add Sub Item
|
116 |
+
</Button>
|
117 |
+
</div>
|
118 |
+
)}
|
119 |
+
</Form.List>
|
120 |
+
</Form.Item>
|
121 |
+
</Card>
|
122 |
+
))}
|
123 |
+
|
124 |
+
<Button type="dashed" onClick={() => add()} block>
|
125 |
+
+ Add Item
|
126 |
+
</Button>
|
127 |
+
</div>
|
128 |
+
)}
|
129 |
+
</Form.List>
|
130 |
+
|
131 |
+
<Form.Item noStyle shouldUpdate>
|
132 |
+
{() => (
|
133 |
+
<Typography>
|
134 |
+
<pre>{JSON.stringify(form?.getFieldsValue(), null, 2)}</pre>
|
135 |
+
</Typography>
|
136 |
+
)}
|
137 |
+
</Form.Item>
|
138 |
+
</Form>
|
139 |
+
);
|
140 |
};
|
141 |
|
142 |
export default SwitchForm;
|