-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataFilesExtractModal.jsx
More file actions
81 lines (74 loc) · 2.5 KB
/
DataFilesExtractModal.jsx
File metadata and controls
81 lines (74 loc) · 2.5 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
import React, { useMemo } from 'react';
import { useDispatch } from 'react-redux';
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { Button, InlineMessage } from '_common';
import { useHistory, useLocation } from 'react-router-dom';
import { useSelectedFiles, useFileListing, useModal } from 'hooks/datafiles';
import { useExtract } from 'hooks/datafiles/mutations';
const DataFilesExtractModal = () => {
const history = useHistory();
const location = useLocation();
const dispatch = useDispatch();
const { extract, status, setStatus } = useExtract();
const { toggle: toggleModal, getStatus: getModalStatus } = useModal();
const { params } = useFileListing('FilesListing');
const isOpen = getModalStatus('extract');
const { selectedFiles } = useSelectedFiles();
const selected = useMemo(() => selectedFiles, [isOpen]);
const onOpened = () => {
dispatch({
type: 'FETCH_FILES_MODAL',
payload: { ...params, section: 'modal' },
});
};
const toggle = () => toggleModal({ operation: 'extract', props: {} });
const onClosed = () => {
dispatch({ type: 'DATA_FILES_MODAL_CLOSE' });
if (status) {
setStatus({});
history.push(location.pathname);
}
};
const extractCallback = () => {
extract({ file: selected[0] });
};
return (
<Modal
isOpen={isOpen}
onOpened={onOpened}
onClosed={onClosed}
toggle={toggle}
className="dataFilesModal"
>
<ModalHeader toggle={toggle} charCode="">
Extract Files
</ModalHeader>
<ModalBody>
<p>
A job to extract your file will be submitted on your behalf. You can
check the status of this job on your Dashboard, and your extracted
files will appear in this directory.
</p>
</ModalBody>
<ModalFooter>
<InlineMessage isVisible={status.type === 'SUCCESS'} type="success">
Successfully started extract job
</InlineMessage>
<InlineMessage isVisible={status.type === 'ERROR'} type="error">
{status.message}
</InlineMessage>
<Button
onClick={extractCallback}
disabled={status.type === 'RUNNING' || status.type === 'SUCCESS'}
isLoading={status.type === 'RUNNING'}
type="primary"
size="medium"
iconNameBefore={status.type === 'ERROR' ? 'alert' : null}
>
Extract
</Button>
</ModalFooter>
</Modal>
);
};
export default DataFilesExtractModal;