-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataset.tsx
More file actions
360 lines (339 loc) · 12.3 KB
/
Dataset.tsx
File metadata and controls
360 lines (339 loc) · 12.3 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
import React, {useEffect, useState} from "react";
import {makeStyles} from "@material-ui/core/styles";
import {
AppBar,
Box,
Button,
Dialog,
DialogTitle,
Grid,
ListItem,
Menu,
MenuItem,
Tab,
Tabs,
Typography
} from "@material-ui/core";
import DescriptionIcon from "@material-ui/icons/Description";
import ArrowDropDownIcon from "@material-ui/icons/ArrowDropDown";
import UploadFile from "../files/UploadFile";
import DeleteOutlineIcon from "@material-ui/icons/DeleteOutline";
import StarBorderIcon from "@material-ui/icons/StarBorder";
import CloudDownloadOutlinedIcon from "@material-ui/icons/CloudDownloadOutlined";
import {downloadDataset} from "../../utils/dataset";
import {downloadFile, fetchFileMetadata} from "../../utils/file";
import {useDispatch, useSelector} from "react-redux";
import {deleteFile as deleteFileAction} from "../../actions/file";
import {deleteDataset as deleteDatasetAction, fetchDatasetAbout, fetchFilesInDataset} from "../../actions/dataset";
import {useNavigate, useParams} from "react-router";
import {downloadThumbnail} from "../../utils/thumbnail";
import {Link as RouterLink} from "react-router-dom";
import TopBar from "../navigation/TopBar";
import {BreadCrumb} from "../navigation/BreadCrumb";
const useStyles = makeStyles((theme) => ({
appBar: {
background: "#FFFFFF",
boxShadow: "none",
},
tab: {
fontStyle: "normal",
fontWeight: "normal",
fontSize: "16px",
color: "#495057",
textTransform: "capitalize",
maxWidth: "50px",
},
fileCardOuterBox: {
position: "relative"
},
fileCard: {
background: "#FFFFFF",
border: "1px solid #DFDFDF",
boxSizing: "border-box",
borderRadius: "4px",
margin: "20px auto",
"& > .MuiGrid-item": {
padding: 0,
height: "150px",
}
},
fileCardImg: {
height: "50%",
margin: "40px auto",
display: "block"
},
fileCardText: {
padding: "40px 20px",
fontSize: "16px",
fontWeight: "normal",
color: "#212529"
},
fileCardActionBox: {
position: "absolute",
right: "5%",
top: "40px",
},
fileCardActionItem: {
display: "block"
},
optionButton: {
float: "right",
padding: "6px 12px",
width: "100px",
background: "#6C757D",
borderRadius: "4px",
color: "white",
textTransform: "capitalize"
},
optionMenuItem: {
fontWeight: "normal",
fontSize: "14px",
color: "#212529",
marginTop: "8px",
}
}));
export default function Dataset() {
const classes = useStyles();
const history = useNavigate();
// path parameter
const {datasetId} = useParams();
const dispatch = useDispatch();
const listFilesInDataset = (datasetId:string|undefined) => dispatch(fetchFilesInDataset(datasetId));
const listDatasetAbout = (datasetId:string|undefined) => dispatch(fetchDatasetAbout(datasetId));
const deleteFile = (fileId:string|undefined) => dispatch(deleteFileAction(fileId));
const deleteDataset = (datasetId:string|undefined|null) => dispatch(deleteDatasetAction(datasetId));
const filesInDataset = useSelector((state) => state.dataset.files);
const datasetAbout = useSelector((state) => state.dataset.about);
const [selectedTabIndex, setSelectedTabIndex] = useState(0);
const [open, setOpen] = React.useState(false);
const [anchorEl, setAnchorEl] = React.useState(null);
const [fileThumbnailList, setFileThumbnailList] = useState([]);
useEffect(() => {
listFilesInDataset(datasetId);
listDatasetAbout(datasetId);
}, []);
// get metadata of each files; because we need the thumbnail of each file!!!
useEffect(() => {
(async () => {
if (filesInDataset !== undefined && filesInDataset.length > 0) {
let fileThumbnailListTemp = [];
await Promise.all(filesInDataset.map(async (fileInDataset) => {
let fileMetadata = await fetchFileMetadata(fileInDataset["id"]);
// add thumbnails
if (fileMetadata["thumbnail"] !== null && fileMetadata["thumbnail"] !== undefined) {
let thumbnailURL = await downloadThumbnail(fileMetadata["thumbnail"]);
fileThumbnailListTemp.push({"id": fileInDataset["id"], "thumbnail": thumbnailURL})
}
}));
setFileThumbnailList(fileThumbnailListTemp);
}
})();
}, [filesInDataset])
const handleTabChange = (_event: any, newTabIndex:number) => {
setSelectedTabIndex(newTabIndex);
};
const handleOptionClick = (event: { currentTarget: React.SetStateAction<null>; }) => {
setAnchorEl(event.currentTarget);
};
const handleOptionClose = () => {
setAnchorEl(null);
};
const paths = [
{
"name": "Explore",
"url": "/"
},
{
"name": datasetAbout["name"],
"url": `/datasets/${datasetId}`
}
]
return (
<>
<TopBar/>
<div className="outer-container">
<BreadCrumb paths={paths}/>
<div className="inner-container">
<Grid container spacing={4}>
<Grid item lg={8} xl={8} md={8} sm={8} xs={12}>
<AppBar className={classes.appBar} position="static">
{/*Tabs*/}
<Tabs value={selectedTabIndex} onChange={handleTabChange} aria-label="dataset tabs">
<Tab className={classes.tab} label="Files" {...a11yProps(0)} />
{/*<Tab className={classes.tab} label="Metadata" {...a11yProps(1)} />*/}
{/*<Tab className={classes.tab} label="Extractions" {...a11yProps(2)} />*/}
{/*<Tab className={classes.tab} label="Visualizations" {...a11yProps(3)} />*/}
{/*<Tab className={classes.tab} label="Comments" {...a11yProps(4)} />*/}
</Tabs>
{/*option menus*/}
<Box>
<Button aria-haspopup="true" onClick={handleOptionClick}
className={classes.optionButton} endIcon={<ArrowDropDownIcon/>}>
Options
</Button>
<Menu
id="simple-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleOptionClose}
>
<MenuItem className={classes.optionMenuItem}
onClick={() => {
setOpen(true);
handleOptionClose();
}}>
Add Files
</MenuItem>
<MenuItem className={classes.optionMenuItem}
onClick={() => {
downloadDataset(datasetId, datasetAbout["name"]).then();
handleOptionClose();
}}>
Download All
</MenuItem>
<MenuItem onClick={() => {
deleteDataset(datasetId);
handleOptionClose();
history("/")
}
} className={classes.optionMenuItem}>Delete</MenuItem>
{/*<MenuItem onClick={handleOptionClose} className={classes.optionMenuItem}>Follow</MenuItem>*/}
{/*<MenuItem onClick={handleOptionClose} className={classes.optionMenuItem}>Collaborators</MenuItem>*/}
{/*<MenuItem onClick={handleOptionClose} className={classes.optionMenuItem}>Extraction</MenuItem>*/}
</Menu>
</Box>
</AppBar>
<TabPanel value={selectedTabIndex} index={0}>
{
filesInDataset !== undefined && fileThumbnailList !== undefined ?
filesInDataset.map((file) => {
let thumbnailComp = <DescriptionIcon className={classes.fileCardImg}
style={{fontSize: "5em"}}/>;
fileThumbnailList.map((thumbnail) => {
if (file["id"] !== undefined && thumbnail["id"] !== undefined &&
thumbnail["thumbnail"] !== null && thumbnail["thumbnail"] !== undefined &&
file["id"] === thumbnail["id"]) {
thumbnailComp = <img src={thumbnail["thumbnail"]} alt="thumbnail"
className={classes.fileCardImg}/>;
}
});
return (
<Box className={classes.fileCardOuterBox}>
<ListItem component={RouterLink}
to={`/files/${file["id"]}?datasetId=${datasetId}`}
className={classes.fileCard}
key={file["id"]}>
<Grid item xl={2} lg={2} md={2} sm={2} xs={12}>
{thumbnailComp}
</Grid>
<Grid item xl={8} lg={8} md={8} sm={8} xs={12}>
<Box className={classes.fileCardText}>
<Typography>File name: {file["filename"]}</Typography>
<Typography>File size: {file["size"]}</Typography>
<Typography>Created on: {file["date-created"]}</Typography>
<Typography>Content type: {file["contentType"]}</Typography>
</Box>
</Grid>
</ListItem>
<Box className={classes.fileCardActionBox}>
<Box className={classes.fileCardActionItem}>
<Button startIcon={<DeleteOutlineIcon/>}
onClick={() => {deleteFile(file["id"]);}}>Delete</Button>
</Box>
<Box className={classes.fileCardActionItem}>
<Button startIcon={<StarBorderIcon/>}
disabled={true}>Follow</Button>
</Box>
<Box className={classes.fileCardActionItem}>
<Button startIcon={<CloudDownloadOutlinedIcon/>}
onClick={() => {downloadFile(file["id"], file["filename"]);}}>
Download</Button>
</Box>
</Box>
</Box>
);
})
:
<></>
}
</TabPanel>
{/*<TabPanel value={selectedTabIndex} index={1}></TabPanel>*/}
{/*<TabPanel value={selectedTabIndex} index={2}></TabPanel>*/}
{/*<TabPanel value={selectedTabIndex} index={3}></TabPanel>*/}
{/*<TabPanel value={selectedTabIndex} index={4}></TabPanel>*/}
</Grid>
<Grid item lg={4} md={4} xl={4} sm={4} xs={12}>
{
datasetAbout !== undefined ?
<Box className="infoCard">
<Typography className="title">About</Typography>
<Typography className="content">Name: {datasetAbout["name"]}</Typography>
<Typography className="content">Dataset ID: {datasetAbout["id"]}</Typography>
<Typography className="content">Owner: {datasetAbout["authorId"]}</Typography>
<Typography className="content">Description: {datasetAbout["description"]}</Typography>
<Typography className="content">Created on: {datasetAbout["created"]}</Typography>
{/*/!*TODO use this to get thumbnail*!/*/}
<Typography className="content">Thumbnail: {datasetAbout["thumbnail"]}</Typography>
{/*<Typography className="content">Belongs to spaces: {datasetAbout["authorId"]}</Typography>*/}
{/*/!*TODO not sure how to use this info*!/*/}
{/*<Typography className="content">Resource type: {datasetAbout["resource_type"]}</Typography>*/}
</Box> : <></>
}
{/*<Divider light/>*/}
{/*<Box className="infoCard">*/}
{/* <Typography className="title">Statistics</Typography>*/}
{/* <Typography className="content">Views: 10</Typography>*/}
{/* <Typography className="content">Last viewed: Jun 07, 2021 21:49:09</Typography>*/}
{/* <Typography className="content">Downloads: 0</Typography>*/}
{/* <Typography className="content">Last downloaded: Never</Typography>*/}
{/*</Box>*/}
{/*<Divider light/>*/}
{/*<Box className="infoCard">*/}
{/* <Typography className="title">Tags</Typography>*/}
{/* <Grid container spacing={4}>*/}
{/* <Grid item lg={8} sm={8} xl={8} xs={12}>*/}
{/* <ClowderInput defaultValue="Tag"/>*/}
{/* </Grid>*/}
{/* <Grid item lg={4} sm={4} xl={4} xs={12}>*/}
{/* <ClowderButton>Search</ClowderButton>*/}
{/* </Grid>*/}
{/* </Grid>*/}
{/*</Box>*/}
{/*<Divider light/>*/}
</Grid>
</Grid>
<Dialog open={open} onClose={() => {setOpen(false);}} fullWidth={true} aria-labelledby="form-dialog">
<DialogTitle id="form-dialog-title">Add Files</DialogTitle>
{/*pass select to uploader so once upload succeeded, can jump to that dataset/file page*/}
<UploadFile selectedDatasetId={datasetId} setOpen={setOpen}/>
</Dialog>
</div>
</div>
</>
);
}
function TabPanel(props:any) {
const {children, value, index, ...other} = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`dataset-tabpanel-${index}`}
aria-labelledby={`dataset-tab-${index}`}
{...other}
>
{value === index && (
<Box p={3}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
function a11yProps(index:number) {
return {
id: `dataset-tab-${index}`,
"aria-controls": `dataset-tabpanel-${index}`,
};
}