-
Notifications
You must be signed in to change notification settings - Fork 67
/
BaseClient.tsx
36 lines (32 loc) 路 1.16 KB
/
BaseClient.tsx
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
import {Col, Form, Radio, Row} from 'antd';
import {SupportedClientTypes, SupportedDataStores, TDraftDataStore} from 'types/DataStore.types';
import GrpcClient from '../GrpcClient';
import HttpClient from '../HttpClient';
const FieldsFormMap = {
[SupportedClientTypes.GRPC]: GrpcClient,
[SupportedClientTypes.HTTP]: HttpClient,
} as const;
const BaseClient = () => {
const form = Form.useFormInstance<TDraftDataStore>();
const dataStoreType = form.getFieldValue('dataStoreType') as SupportedDataStores;
const baseName = ['dataStore', dataStoreType];
const type = (Form.useWatch([...baseName, 'type'], form) || SupportedClientTypes.GRPC) as SupportedClientTypes;
const Component = FieldsFormMap[type];
return (
<>
<Row gutter={[16, 16]}>
<Col span={12}>
Connection type:
<Form.Item name={[...baseName, 'type']}>
<Radio.Group defaultValue={type}>
<Radio value={SupportedClientTypes.GRPC}>gRPC</Radio>
<Radio value={SupportedClientTypes.HTTP}>Http</Radio>
</Radio.Group>
</Form.Item>
</Col>
</Row>
<Component />
</>
);
};
export default BaseClient;