Skip to content

Commit 9304387

Browse files
authored
Merge pull request #16 from factly/feat/support-directory-upload
Added support for upload via file directory
2 parents 5e6f5f8 + 5ca6c50 commit 9304387

File tree

6 files changed

+91
-40
lines changed

6 files changed

+91
-40
lines changed

studio/src/components/expectationcard.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DownloadOutlined } from '@ant-design/icons';
55
import { Typography } from 'antd';
66
import { CSVLink } from 'react-csv';
77
const { Link } = Typography;
8-
function ExpectationCard(Expectation) {
8+
function ExpectationCard({ Expectation , fileName }) {
99
const { Expectation_name } = Expectation;
1010
const [show, setShow] = React.useState(false);
1111
const isResultNested = () => {
@@ -144,6 +144,7 @@ function ExpectationCard(Expectation) {
144144
hideOnSinglePage: true,
145145
}}
146146
scroll={{ x: 1000, y: 500 }}
147+
title={() => <b>{fileName}</b>}
147148
/>
148149
</>
149150
) : (

studio/src/components/googleSheets.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { CloudUploadOutlined } from '@ant-design/icons';
88
import { getGoogleSheetsValidations } from '../actions/metafactsValidly';
99
// import { setFormErrors } from '../utils/form';
1010

11-
function GoogleSheetsForm({ style, ...props }) {
11+
function GoogleSheetsForm({ loading , style, ...props }) {
1212
const dispatch = useDispatch();
1313
const [form] = Form.useForm();
1414
const [showModal, setShowModal] = useState(false);
@@ -73,7 +73,7 @@ function GoogleSheetsForm({ style, ...props }) {
7373
span: 16,
7474
}}
7575
>
76-
<Button type="primary" htmlType="submit">
76+
<Button type="primary" loading={loading} htmlType="submit">
7777
Submit
7878
</Button>
7979
</Form.Item>

studio/src/components/s3metafacts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getMetaTableDataFromS3 } from '../actions/metafacts';
88
import { CloudUploadOutlined } from '@ant-design/icons';
99
import { setFormErrors } from '../utils/form';
1010

11-
function S3metafactsForm({ style, ...props }) {
11+
function S3metafactsForm({ loading , style, ...props }) {
1212
const dispatch = useDispatch();
1313
const [form] = Form.useForm();
1414
const [showModal, setShowModal] = useState(false);
@@ -73,7 +73,7 @@ function S3metafactsForm({ style, ...props }) {
7373
span: 16,
7474
}}
7575
>
76-
<Button type="primary" htmlType="submit">
76+
<Button type="primary" loading={loading} htmlType="submit">
7777
Submit
7878
</Button>
7979
</Form.Item>

studio/src/components/upload.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Form, Radio } from 'antd';
2+
import React, { useState } from 'react';
3+
4+
function useUploadForm() {
5+
const [isDirectory, setIsDirectory] = useState(false);
6+
7+
const onChange = (e) => {
8+
setIsDirectory(e.target.value);
9+
};
10+
11+
function UploadForm() {
12+
return (
13+
<Form
14+
name="basic"
15+
labelCol={{ span: 0 }}
16+
wrapperCol={{ span: 24 }}
17+
>
18+
<Form.Item label="Upload by">
19+
<Radio.Group onChange={onChange} value={isDirectory}>
20+
<Radio value={false}>Files</Radio>
21+
<Radio value={true}>Directory</Radio>
22+
</Radio.Group>
23+
</Form.Item>
24+
</Form>
25+
);
26+
}
27+
28+
return [UploadForm, isDirectory];
29+
}
30+
31+
export default useUploadForm;

studio/src/pages/metafacts/index.js

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { CSVLink } from 'react-csv';
66
import { useHistory } from 'react-router-dom';
77
import { addFiles, getMetaTableData, setUploadButton } from '../../actions/metafacts';
88
import S3metafactsForm from '../../components/s3metafacts';
9+
import useUploadForm from '../../components/upload';
910
function Metafacts() {
1011
const dispatch = useDispatch();
1112
const history = useHistory();
@@ -25,41 +26,41 @@ function Metafacts() {
2526
};
2627
const columns = [
2728
{
28-
title: 'formats_available',
29-
dataIndex: 'formats_available',
30-
key: 'formats_available',
29+
"title": "output_file_name",
30+
"dataIndex": "output_file_name",
31+
"key": "output_file_name"
3132
},
3233
{
33-
title: 'granularity',
34-
dataIndex: 'granularity',
35-
key: 'granularity',
34+
"title": "units",
35+
"dataIndex": "units",
36+
"key": "units"
3637
},
3738
{
38-
title: 'is_public',
39-
dataIndex: 'is_public',
40-
key: 'is_public',
39+
"title": "temporal_coverage",
40+
"dataIndex": "temporal_coverage",
41+
"key": "temporal_coverage"
4142
},
4243
{
43-
title: 'output_file_name',
44-
dataIndex: 'output_file_name',
45-
key: 'output_file_name',
44+
"title": "granularity",
45+
"dataIndex": "granularity",
46+
"key": "granularity"
4647
},
4748
{
48-
title: 'spatial_coverage',
49-
dataIndex: 'spatial_coverage',
50-
key: 'spatial_coverage',
49+
"title": "spatial_coverage",
50+
"dataIndex": "spatial_coverage",
51+
"key": "spatial_coverage"
5152
},
5253
{
53-
title: 'temporal_coverage',
54-
dataIndex: 'temporal_coverage',
55-
key: 'temporal_coverage',
54+
"title": "formats_available",
55+
"dataIndex": "formats_available",
56+
"key": "formats_available"
5657
},
5758
{
58-
title: 'units',
59-
dataIndex: 'units',
60-
key: 'units',
61-
},
62-
];
59+
"title": "is_public",
60+
"dataIndex": "is_public",
61+
"key": "is_public"
62+
}
63+
]
6364
// const columnsDynamic = Object.entries(metaTabledata).map((filenameValuePair, index) => {
6465
// const columns = Object.entries(filenameValuePair[1]).map((columnValuePair, index) => {
6566
// return {
@@ -88,17 +89,25 @@ function Metafacts() {
8889
dispatch(getMetaTableData(validlyDatasets));
8990
}
9091
}, [validlyDatasets, dispatch, metafactsDatasets.length]);
92+
93+
const [UploadForm, isDirectory] = useUploadForm();
94+
const uploadProps = {
95+
showUploadList: false,
96+
...(isDirectory ? { directory: true } : {}),
97+
accept: "text/csv",
98+
beforeUpload: (file, fileList) => {
99+
dispatch(addFiles(fileList));
100+
dispatch(setUploadButton(true));
101+
return false;
102+
},
103+
multiple: true,
104+
};
91105
return (
92106
<>
107+
<UploadForm></UploadForm>
93108
<Space size={'small'}>
94109
<Upload
95-
showUploadList={false}
96-
beforeUpload={(file, fileList) => {
97-
dispatch(addFiles(fileList));
98-
dispatch(setUploadButton(true));
99-
return false;
100-
}}
101-
multiple
110+
{...uploadProps}
102111
>
103112
<Button icon={<UploadOutlined />}>Select Local Files</Button>
104113
<Button>
@@ -112,7 +121,7 @@ function Metafacts() {
112121
{' '}
113122
Upload Local Files{' '}
114123
</Button>
115-
<S3metafactsForm style={{ marginLeft: '75px' }} />
124+
<S3metafactsForm loading={loading} style={{ marginLeft: '75px' }} />
116125
</Space>
117126
{showTable ? (
118127
<Button style={{ marginBottom: '10px', float: 'right' }} type="primary">

studio/src/pages/validly/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '../../actions/validly';
88
import React from 'react';
99
import 'antd/dist/antd.css';
10-
import { Upload, Button, Collapse, Card, Row, Col, Spin } from 'antd';
10+
import { Upload, Button, Collapse, Card, Row, Col, Spin, Radio, Form } from 'antd';
1111
import customExpandIcon from '../../components/customexpandicon';
1212
import ExpectationCard from '../../components/expectationcard';
1313
import { Space } from 'antd';
@@ -19,6 +19,7 @@ import {
1919
getMetaFactsValidationData,
2020
setMetaFactsUploadButton,
2121
} from '../../actions/metafactsValidly';
22+
import useUploadForm from '../../components/upload';
2223
const { Panel } = Collapse;
2324
function Validly({ mode = 'datasets' }) {
2425
const dispatch = useDispatch();
@@ -58,10 +59,19 @@ function Validly({ mode = 'datasets' }) {
5859
}
5960
dispatch(addExpectationCard(updateExpectationsArray(expectations, expectation, index)));
6061
};
62+
const [UploadForm, isDirectory] = useUploadForm();
63+
const uploadProps = {
64+
showUploadList: false,
65+
beforeUpload: handleUpload,
66+
multiple: true,
67+
accept : "text/csv",
68+
...(isDirectory ? { directory: true } : {}),
69+
};
6170
return (
6271
<div className="App">
72+
<UploadForm></UploadForm>
6373
<Space size={'small'}>
64-
<Upload showUploadList={false} beforeUpload={handleUpload} multiple>
74+
<Upload {...uploadProps}>
6575
<Button icon={<UploadOutlined />}>Select Files</Button>
6676
<Button>
6777
{' '}
@@ -74,7 +84,7 @@ function Validly({ mode = 'datasets' }) {
7484
{' '}
7585
Start Upload{' '}
7686
</Button>
77-
{mode === 'metafacts' ? <GoogleSheetsForm /> : null}
87+
{mode === 'metafacts' ? <GoogleSheetsForm loading={loading}/> : null}
7888
</Space>
7989
{loading ? (
8090
<Spin size="default" style={{ display: 'block', marginTop: '15%' }} />
@@ -133,7 +143,7 @@ function Validly({ mode = 'datasets' }) {
133143
</Col>
134144
<Col span={16}>
135145
{expectations[index] ? (
136-
<ExpectationCard {...expectations[index]}></ExpectationCard>
146+
<ExpectationCard Expectation={{...expectations[index]}} fileName={file.filename.split('/').pop().split('.')[0]} ></ExpectationCard>
137147
) : null}
138148
</Col>
139149
</Row>

0 commit comments

Comments
 (0)