-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathIngestionCsvMapperTestDialog.tsx
150 lines (143 loc) · 5.04 KB
/
IngestionCsvMapperTestDialog.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
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
import { graphql, useMutation } from 'react-relay';
import React, { FunctionComponent, useState } from 'react';
import Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import DialogContent from '@mui/material/DialogContent';
import Button from '@mui/material/Button';
import Box from '@mui/material/Box';
import CodeBlock from '@components/common/CodeBlock';
import Alert from '@mui/material/Alert';
import { Option } from '@components/common/form/ReferenceField';
import { IngestionCsvMapperTestDialogMutation$data } from '@components/data/ingestionCsv/__generated__/IngestionCsvMapperTestDialogMutation.graphql';
import Loader, { LoaderVariant } from '../../../../components/Loader';
import { useFormatter } from '../../../../components/i18n';
import { handleError } from '../../../../relay/environment';
const ingestionCsvMapperTestMutation = graphql`
mutation IngestionCsvMapperTestDialogMutation($input: IngestionCsvAddInput!) {
ingestionCsvTester(input: $input) {
nbEntities
nbRelationships
objects
}
}
`;
interface IngestionCsvMapperTestDialogProps {
open: boolean
onClose: () => void
values: {
name: string,
description?: string | null,
authentication_type: string,
authentication_value?: string | null,
current_state_date: Date | null,
uri: string,
ingestion_running?: boolean | null,
csv_mapper_id: string | Option,
user_id: string | Option
}
setIsCreateDisabled?: React.Dispatch<React.SetStateAction<boolean>>
}
const IngestionCsvMapperTestDialog: FunctionComponent<IngestionCsvMapperTestDialogProps> = ({
open,
onClose,
values,
setIsCreateDisabled,
}) => {
const { t_i18n } = useFormatter();
const [result, setResult] = useState<IngestionCsvMapperTestDialogMutation$data | undefined>(undefined);
const [commitTest] = useMutation(ingestionCsvMapperTestMutation);
const [loading, setLoading] = useState<boolean>(false);
const handleClose = () => {
setResult(undefined);
onClose();
};
const onTest = () => {
setLoading(true);
commitTest({
variables: {
input: {
name: values.name,
description: values.description,
authentication_type: values.authentication_type,
authentication_value: values.authentication_value,
current_state_date: values.current_state_date,
uri: values.uri,
ingestion_running: values.ingestion_running,
user_id: typeof values.user_id === 'string' ? values.user_id : values.user_id.value,
csv_mapper_id: typeof values.csv_mapper_id === 'string' ? values.csv_mapper_id : values.csv_mapper_id.value,
},
},
onCompleted: (data) => {
const resultTest = (data as IngestionCsvMapperTestDialogMutation$data);
if (resultTest) {
setResult(resultTest);
if (setIsCreateDisabled) {
setIsCreateDisabled(resultTest.ingestionCsvTester?.nbEntities === 0);
}
}
setLoading(false);
},
onError: (error) => {
handleError(error);
setLoading(false);
},
});
};
return (
<Dialog open={open} onClose={handleClose} PaperProps={{ elevation: 1 }}>
<DialogTitle>{t_i18n('Testing csv mapper')}</DialogTitle>
<DialogContent>
<Box>
<div style={{ width: '100%', marginTop: 10 }}>
<Alert
severity="info"
variant="outlined"
style={{ padding: '0px 10px 0px 10px' }}
>
{t_i18n('Please, note that the test will be run on the 50 first lines')}
</Alert>
</div>
</Box>
<Box
sx={{ display: 'inline-flex', textAlign: 'center', marginTop: '8px', alignItems: 'baseline' }}
>
<Button
variant="contained"
color={result?.ingestionCsvTester?.nbEntities ? 'primary' : 'secondary'}
onClick={() => onTest()}
>
{t_i18n('Test')}
</Button>
{loading && (
<Box sx={{ marginLeft: '8px' }}>
<Loader variant={LoaderVariant.inElement}/>
</Box>
)}
{result
&& <Box
sx={{
paddingTop: '8px',
marginLeft: '12px',
fontSize: '1rem',
gap: '8px',
justifyContent: 'center',
display: 'flex',
}}
>
<span>{t_i18n('Objects found')} : </span>
<span><strong>{result?.ingestionCsvTester?.nbEntities} </strong> {t_i18n('Entities')}</span>
<span><strong>{result?.ingestionCsvTester?.nbRelationships}</strong> {t_i18n('Relationships')}</span>
</Box>
}
</Box>
<Box sx={{ marginTop: '8px' }}>
<CodeBlock
code={result?.ingestionCsvTester?.objects || t_i18n('You will find here the result in JSON format.')}
language={'json'}
/>
</Box>
</DialogContent>
</Dialog>
);
};
export default IngestionCsvMapperTestDialog;