configComponent.tsx
4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import React, {
useContext,
memo,
useState,
useEffect,
useImperativeHandle,
} from 'react';
import { Checkbox, Form, Input, Radio, Space, Tooltip } from 'antd';
import type { CheckboxChangeEvent, RadioChangeEvent } from 'antd/es/checkbox';
import type { IConfigComponent } from '@qx/flow';
import { QxParameterSetting } from '@qx/common';
import { QxIcon } from '@/components';
import _ from 'lodash';
import { isolationList, propagationList } from '../../setting-configs/start';
interface PropagationSettingProps {
value: string;
onChange: (val: string) => void;
optionsList: {
value: string;
label: string;
tips: string;
}[];
}
const PropagationSetting: React.FC<PropagationSettingProps> = (props) => {
const { value, onChange, optionsList } = props;
return (
<Radio.Group
onChange={(e: RadioChangeEvent) => {
onChange(e.target.value);
}}
value={value}
>
<Space direction="vertical">
{(optionsList || []).map(
(_options: { value: string; label: string; tips: string }) => {
return (
<Radio value={_options.value}>
<span>{_options.label}</span>
<Tooltip placement="right" title={_options.tips}>
<QxIcon
className={'qx-data-flow-tooltip-opt'}
type={'icon-frame-help'}
/>
</Tooltip>
</Radio>
);
},
)}
</Space>
</Radio.Group>
);
};
const StartConfigComponent: React.FC<StartConfigComponentProps> =
React.forwardRef((props, ref) => {
const [form] = Form.useForm();
useImperativeHandle(ref, () => ({
validateFields: form.validateFields,
}));
const [values, setValues] = useState<{
params: any[];
enablePropagation: boolean;
propagation: string;
isolation: string;
}>({
params: [],
enablePropagation: false,
propagation: 'REQUIRED',
isolation: 'REPEATABLE_READ',
});
useEffect(() => {
if (_.isEmpty(props?.node?.data)) {
return;
}
if (_.isEqual(props?.node?.data, values)) {
return;
}
setValues(props?.node?.data);
}, [props?.node?.data]);
const onCheckedChange = (e: CheckboxChangeEvent) => {
const _cloneVal = _.cloneDeep(values);
setValues({
..._cloneVal,
enablePropagation: e.target.checked,
});
};
useEffect(() => {
if (_.isEqual(props?.node?.data, values)) {
return;
}
props.onChange(values);
}, [values]);
return (
<Form
form={form}
layout="vertical"
initialValues={{
enablePropagation: false,
propagation: 'REQUIRED',
isolation: 'REPEATABLE_READ',
}}
>
<Form.Item name="params">
<h3 className={'qx-flow-form__label-title'}>入参设置</h3>
<p className={'qx-flow-form__label-tips'}>
参数可以被后面的所有数据流节点使用
</p>
<QxParameterSetting
value={values.params}
onChange={(_v: any) => {
console.log('参数 === ', _v);
}}
/>
</Form.Item>
<Form.Item name="enablePropagation">
<h3 className={'qx-flow-form__label-title'}>事务控制</h3>
<Checkbox
checked={values.enablePropagation}
onChange={onCheckedChange}
>
设置事务的传播行为和隔离级别
</Checkbox>
</Form.Item>
<Form.Item
hidden={!values.enablePropagation}
label="事务传播行为"
name="propagation"
>
<PropagationSetting
optionsList={propagationList}
value={'REQUIRED'}
onChange={(_v: string) => {
const _cloneVal = _.cloneDeep(values);
setValues({
..._cloneVal,
propagation: _v,
});
}}
/>
</Form.Item>
<Form.Item
hidden={!values.enablePropagation}
label="事务隔离级别"
name="isolation"
>
<PropagationSetting
optionsList={isolationList}
value={'REPEATABLE_READ'}
onChange={(_v: string) => {
const _cloneVal = _.cloneDeep(values);
setValues({
..._cloneVal,
isolation: _v,
});
}}
/>
</Form.Item>
</Form>
);
});
interface StartConfigComponentProps extends IConfigComponent {
onChange: (values: any) => void;
}
export default memo(StartConfigComponent);