Skip to content

Commit 980cafb

Browse files
tcnichollongshuicy
andauthored
Drag and Drop One or More Files (#935)
* initial commit, add dependency, new class will eventually combine all file uploads * working on adding upload drag and drop * page does not load * drag and drop does not actually work * addign fileinputdrop as independent component * add fileupload drop inside uploadfiledraganddrop * drag and drop does not add files select selects files but misses the first one * drag and drop works now, is overwritten if file selected using button, need to fix * uploads but overwrites, need to fix * works for the select, need to fix other * should work for drop now too * was not an array * delete icon works removing console logs * drag and drop and select means other upload methods no longer needed * removing text in drag and drop * added to styles but not using because it does not work * some changes, not sure how to do rest * fix button * return to dataset * remove unnecessary imports --------- Co-authored-by: Chen Wang <[email protected]>
1 parent 674034e commit 980cafb

File tree

5 files changed

+446
-33
lines changed

5 files changed

+446
-33
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"react-copy-to-clipboard": "^5.1.0",
6363
"react-dom": "^17.0.2",
6464
"react-gravatar": "^2.6.3",
65+
"react-file-drop": "^3.1.6",
6566
"react-json-view": "^1.21.3",
6667
"react-loading-overlay-ts": "^1.0.4",
6768
"react-redux": "^7.2.6",

frontend/src/components/datasets/NewMenu.tsx

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useSelector } from "react-redux";
1414
import { RootState } from "../../types/data";
1515
import { UploadFile } from "../files/UploadFile";
1616
import { UploadFileMultiple } from "../files/UploadFileMultiple";
17+
import {UploadFileDragAndDrop} from "../files/UploadFileDragAndDrop";
1718
import UploadIcon from "@mui/icons-material/Upload";
1819
import { Folder } from "@material-ui/icons";
1920

@@ -29,8 +30,7 @@ export const NewMenu = (props: ActionsMenuProps): JSX.Element => {
2930
const about = useSelector((state: RootState) => state.dataset.about);
3031

3132
const [anchorEl, setAnchorEl] = React.useState<Element | null>(null);
32-
const [createFileOpen, setCreateFileOpen] = React.useState<boolean>(false);
33-
const [createMultipleFileOpen, setCreateMultipleFileOpen] =
33+
const [dragDropFiles, setDragDropFiles] =
3434
React.useState<boolean>(false);
3535
const [newFolder, setNewFolder] = React.useState<boolean>(false);
3636

@@ -47,30 +47,15 @@ export const NewMenu = (props: ActionsMenuProps): JSX.Element => {
4747
return (
4848
<Box>
4949
<Dialog
50-
open={createFileOpen}
50+
open={dragDropFiles}
5151
onClose={() => {
52-
setCreateFileOpen(false);
52+
setDragDropFiles(false);
5353
}}
5454
fullWidth={true}
5555
maxWidth="lg"
5656
aria-labelledby="form-dialog"
5757
>
58-
<UploadFile
59-
selectedDatasetId={datasetId}
60-
selectedDatasetName={about.name}
61-
folderId={folderId}
62-
/>
63-
</Dialog>
64-
<Dialog
65-
open={createMultipleFileOpen}
66-
onClose={() => {
67-
setCreateMultipleFileOpen(false);
68-
}}
69-
fullWidth={true}
70-
maxWidth="lg"
71-
aria-labelledby="form-dialog"
72-
>
73-
<UploadFileMultiple selectedDatasetId={datasetId} folderId={folderId} />
58+
<UploadFileDragAndDrop selectedDatasetId={datasetId} folderId={folderId}/>
7459
</Dialog>
7560

7661
<CreateFolder
@@ -97,25 +82,14 @@ export const NewMenu = (props: ActionsMenuProps): JSX.Element => {
9782
>
9883
<MenuItem
9984
onClick={() => {
100-
setCreateFileOpen(true);
101-
handleOptionClose();
102-
}}
103-
>
104-
<ListItemIcon>
105-
<UploadIcon fontSize="small" />
106-
</ListItemIcon>
107-
<ListItemText>Upload File</ListItemText>
108-
</MenuItem>
109-
<MenuItem
110-
onClick={() => {
111-
setCreateMultipleFileOpen(true);
85+
setDragDropFiles(true);
11286
handleOptionClose();
11387
}}
11488
>
11589
<ListItemIcon>
11690
<UploadIcon fontSize="small" />
11791
</ListItemIcon>
118-
<ListItemText>Upload Multiple Files</ListItemText>
92+
<ListItemText>Upload Files</ListItemText>
11993
</MenuItem>
12094
<MenuItem
12195
onClick={() => {
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import React from "react";
2+
import { FileDrop } from "react-file-drop";
3+
import { Box, IconButton, Typography } from "@mui/material";
4+
import DeleteIcon from "@material-ui/icons/Delete";
5+
import { FileDropGroup, FileDropInput } from "../../styles/Styles";
6+
import { makeStyles } from "@material-ui/core/styles";
7+
import { theme } from "../../theme";
8+
9+
const useStyles = makeStyles({
10+
fileDrop: {
11+
boxSizing: "border-box",
12+
height: "176px",
13+
width: "100%",
14+
border: "1px dashed #00619D",
15+
backgroundColor: "#FFFFFF",
16+
margin: "27px auto 0 auto",
17+
display: "block",
18+
},
19+
fileDropInput: {
20+
width: "95px",
21+
},
22+
fileDropText: {
23+
height: "54px",
24+
width: "92px",
25+
color: "#8798AD",
26+
fontSize: "15px",
27+
fontWeight: 500,
28+
letterSpacing: 0,
29+
lineHeight: "18px",
30+
textAlign: "center",
31+
},
32+
fileDropGroup: {
33+
width: "92px",
34+
margin: "50px auto 0 auto",
35+
display: "block",
36+
},
37+
displayFile: {
38+
boxSizing: "border-box",
39+
width: "100%",
40+
border: "1px solid #00619D",
41+
backgroundColor: "#FFFFFF",
42+
margin: "5px auto 0 auto",
43+
display: "block",
44+
},
45+
displayFileItem: {
46+
width: "100%",
47+
height: "37px",
48+
},
49+
displayFilename: {
50+
height: "18px",
51+
color: theme.palette.primary.main,
52+
fontSize: "15px",
53+
fontWeight: 500,
54+
letterSpacing: 0,
55+
lineHeight: "18px",
56+
padding: "9px 17px",
57+
float: "left",
58+
},
59+
deleteFileIcon: {
60+
height: "24px",
61+
width: "24px",
62+
float: "right",
63+
margin: "6px",
64+
"&:hover": {
65+
color: theme.palette.secondary.main,
66+
},
67+
},
68+
});
69+
70+
type FileUploadDropProps = {
71+
onDrop: any;
72+
onFileInputChange: any;
73+
fileInputRef: any;
74+
onDeleteClick: any;
75+
selectedFiles: File[] | [];
76+
};
77+
78+
export default function FileUploadDrop(props: FileUploadDropProps) {
79+
const {
80+
onDrop,
81+
onFileInputChange,
82+
fileInputRef,
83+
onDeleteClick,
84+
selectedFiles,
85+
} = props;
86+
87+
const classes = useStyles();
88+
89+
return (
90+
<div>
91+
<FileDrop onDrop={onDrop} className={classes.fileDrop}>
92+
<div style={FileDropGroup}>
93+
<input
94+
onChange={onFileInputChange}
95+
ref={fileInputRef}
96+
type="file"
97+
style={FileDropInput}
98+
multiple
99+
/>
100+
<Typography className={classes.fileDropText}>
101+
<br></br>
102+
</Typography>
103+
</div>
104+
</FileDrop>
105+
{selectedFiles !== undefined && selectedFiles.length > 0 ? (
106+
<Box className={classes.displayFile}>
107+
{selectedFiles.map((file) => {
108+
return (
109+
<div className={classes.displayFileItem} key={file.name}>
110+
<Typography className={classes.displayFilename}>
111+
{file.name}
112+
</Typography>
113+
<IconButton
114+
aria-label="delete"
115+
className={classes.deleteFileIcon}
116+
onClick={() => {
117+
onDeleteClick(file);
118+
}}
119+
>
120+
<DeleteIcon />
121+
</IconButton>
122+
</div>
123+
);
124+
})}
125+
</Box>
126+
) : (
127+
<></>
128+
)}
129+
</div>
130+
);
131+
}

0 commit comments

Comments
 (0)