/
AddCorrelationForm.tsx
62 lines (52 loc) · 2.06 KB
/
AddCorrelationForm.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
import { css } from '@emotion/css';
import React, { useEffect } from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { PanelContainer, useStyles2 } from '@grafana/ui';
import { CloseButton } from 'app/core/components/CloseButton/CloseButton';
import { Wizard } from '../components/Wizard';
import { useCorrelations } from '../useCorrelations';
import { ConfigureCorrelationBasicInfoForm } from './ConfigureCorrelationBasicInfoForm';
import { ConfigureCorrelationSourceForm } from './ConfigureCorrelationSourceForm';
import { ConfigureCorrelationTargetForm } from './ConfigureCorrelationTargetForm';
import { CorrelationFormNavigation } from './CorrelationFormNavigation';
import { CorrelationsFormContextProvider } from './correlationsFormContext';
import { FormDTO } from './types';
const getStyles = (theme: GrafanaTheme2) => ({
panelContainer: css`
position: relative;
padding: ${theme.spacing(1)};
margin-bottom: ${theme.spacing(2)};
`,
infoBox: css`
margin-top: 20px; // give space for close button
`,
});
interface Props {
onClose: () => void;
onCreated: () => void;
}
export const AddCorrelationForm = ({ onClose, onCreated }: Props) => {
const styles = useStyles2(getStyles);
const {
create: { execute, loading, error, value },
} = useCorrelations();
useEffect(() => {
if (!error && !loading && value) {
onCreated();
}
}, [error, loading, value, onCreated]);
const defaultValues: Partial<FormDTO> = { config: { type: 'query', target: { title: '', url: '' }, field: '' } };
return (
<PanelContainer className={styles.panelContainer}>
<CloseButton onClick={onClose} />
<CorrelationsFormContextProvider data={{ loading, readOnly: false, correlation: undefined }}>
<Wizard<FormDTO>
defaultValues={defaultValues}
pages={[ConfigureCorrelationBasicInfoForm, ConfigureCorrelationTargetForm, ConfigureCorrelationSourceForm]}
navigation={CorrelationFormNavigation}
onSubmit={execute}
/>
</CorrelationsFormContextProvider>
</PanelContainer>
);
};