-
Notifications
You must be signed in to change notification settings - Fork 67
/
DataStoreForm.tsx
111 lines (102 loc) 路 3.67 KB
/
DataStoreForm.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
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
import {Button, Form, Space, Typography} from 'antd';
import {useCallback, useEffect, useMemo} from 'react';
import AllowButton, {Operation} from 'components/AllowButton';
import DataStoreIcon from 'components/DataStoreIcon/DataStoreIcon';
import DataStoreService from 'services/DataStore.service';
import {TDraftDataStore, TDataStoreForm, SupportedDataStores} from 'types/DataStore.types';
import DataStoreConfig from 'models/DataStoreConfig.model';
import {DataStoreSelection} from 'components/Inputs';
import {SupportedDataStoresToName} from 'constants/DataStore.constants';
import DataStoreComponentFactory from '../DataStorePlugin/DataStoreComponentFactory';
import * as S from './DataStoreForm.styled';
export const FORM_ID = 'data-store';
interface IProps {
form: TDataStoreForm;
dataStoreConfig: DataStoreConfig;
onSubmit(values: TDraftDataStore): Promise<void>;
onIsFormValid(isValid: boolean): void;
onTestConnection(): void;
isTestConnectionLoading: boolean;
isLoading: boolean;
isFormValid: boolean;
}
const DataStoreForm = ({
form,
onSubmit,
dataStoreConfig,
onIsFormValid,
onTestConnection,
isTestConnectionLoading,
isLoading,
isFormValid,
}: IProps) => {
const configuredDataStoreType = dataStoreConfig.defaultDataStore.type as SupportedDataStores;
const initialValues = useMemo(
() => DataStoreService.getInitialValues(dataStoreConfig, configuredDataStoreType),
[configuredDataStoreType, dataStoreConfig]
);
const dataStoreType = Form.useWatch('dataStoreType', form);
useEffect(() => {
form.setFieldsValue({
dataStore: {name: '', type: SupportedDataStores.JAEGER, ...initialValues.dataStore},
});
}, [dataStoreType, form, initialValues.dataStore]);
const onValidation = useCallback(
async (_: any, draft: TDraftDataStore) => {
try {
const isValid = await DataStoreService.validateDraft(draft);
onIsFormValid(isValid);
} catch (e) {
onIsFormValid(false);
}
},
[onIsFormValid]
);
return (
<Form<TDraftDataStore>
autoComplete="off"
form={form}
layout="vertical"
name={FORM_ID}
onFinish={onSubmit}
onValuesChange={onValidation}
initialValues={initialValues}
>
<S.FormContainer>
<Form.Item name="dataStoreType">
<DataStoreSelection />
</Form.Item>
<S.FactoryContainer>
<S.TopContainer>
<Space>
<DataStoreIcon dataStoreType={dataStoreType ?? SupportedDataStores.JAEGER} width="22" height="22" />
<Typography.Title level={2}>
{SupportedDataStoresToName[dataStoreType ?? SupportedDataStores.JAEGER]}
</Typography.Title>
</Space>
<S.Description>
Tracetest needs configuration information to be able to retrieve your trace from your distributed tracing
solution. Select your Tracing Backend and enter the configuration info.
</S.Description>
{dataStoreType && <DataStoreComponentFactory dataStoreType={dataStoreType} />}
</S.TopContainer>
<S.ButtonsContainer>
<Button loading={isTestConnectionLoading} type="primary" ghost onClick={onTestConnection}>
Test Connection
</Button>
<AllowButton
operation={Operation.Configure}
disabled={!isFormValid}
loading={isLoading}
type="primary"
onClick={() => form.submit()}
>
Save and Set as DataStore
</AllowButton>
</S.ButtonsContainer>
</S.FactoryContainer>
</S.FormContainer>
</Form>
);
};
export default DataStoreForm;