-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDashbard.tsx
More file actions
266 lines (245 loc) · 9.15 KB
/
Dashbard.tsx
File metadata and controls
266 lines (245 loc) · 9.15 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
import React, {useEffect, useState} from "react";
import {makeStyles} from "@material-ui/core/styles";
import {AppBar, Box, Button, Dialog, DialogTitle, Grid, Link, ListItem, Tab, Tabs, Typography} from "@material-ui/core";
import {Link as RouterLink} from "react-router-dom";
import BusinessCenterIcon from "@material-ui/icons/BusinessCenter";
import DeleteOutlineIcon from "@material-ui/icons/DeleteOutline";
import StarBorderIcon from "@material-ui/icons/StarBorder";
import CloudDownloadOutlinedIcon from "@material-ui/icons/CloudDownloadOutlined";
import CreateDataset from "./datasets/CreateDataset";
import {downloadDataset} from "../utils/dataset";
import {useDispatch, useSelector} from "react-redux";
import {deleteDataset as deleteDatasetAction, fetchDatasets} from "../actions/dataset";
import {downloadThumbnail} from "../utils/thumbnail";
import TopBar from "./navigation/TopBar";
import {BreadCrumb} from "./navigation/BreadCrumb";
const useStyles = makeStyles(() => ({
appBar: {
background: "#FFFFFF",
boxShadow: "none",
},
tab: {
fontStyle: "normal",
fontWeight: "normal",
fontSize: "16px",
color: "#495057",
textTransform: "capitalize",
},
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"
}
}));
export default function Dashboard() {
const classes = useStyles();
const dispatch = useDispatch();
const deleteDataset = (datasetId:string) => dispatch(deleteDatasetAction(datasetId));
const listDatasets = (when:string|null, date:string|null, limit:number|undefined) => dispatch(fetchDatasets(when, date, limit));
const datasets = useSelector((state) => state.dataset.datasets);
const [lastDataset, setLastDataset] = useState([]);
const [firstDataset, setFirstDataset] = useState([]);
const [limit, _] = useState(5);
const [selectedTabIndex, setSelectedTabIndex] = useState(0);
const [open, setOpen] = React.useState(false);
const [datasetThumbnailList, setDatasetThumbnailList] = useState([]);
// component did mount
useEffect(() => {
listDatasets(null, null, limit);
}, []);
useEffect(() => {
(async () => {
if (datasets !== undefined && datasets.length > 0) {
let datasetThumbnailListTemp = [];
await Promise.all(datasets.map(async (dataset) => {
// add thumbnails
if (dataset["thumbnail"] !== null && dataset["thumbnail"] !== undefined) {
let thumbnailURL = await downloadThumbnail(dataset["thumbnail"]);
datasetThumbnailListTemp.push({"id": dataset["id"], "thumbnail": thumbnailURL})
}
}));
setDatasetThumbnailList(datasetThumbnailListTemp);
// find last and first dataset for pagination
setFirstDataset(datasets[0])
setLastDataset(datasets[datasets.length - 1]);
}
})();
}, [datasets])
const previous = () => {
let date = firstDataset["created"] !== undefined ? new Date(firstDataset["created"]) : null;
if (date) listDatasets("b", date.toISOString(), limit);
}
const next = () => {
let date = lastDataset["created"] !== undefined ? new Date(lastDataset["created"]) : null;
if (date) listDatasets("a", date.toISOString(), limit);
}
const handleTabChange = (event, newTabIndex:number) => {
setSelectedTabIndex(newTabIndex);
};
const paths = [
{
"name": "Explore",
"url": "/"
},
];
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 value={selectedTabIndex} onChange={handleTabChange} aria-label="dashboard tabs">
<Tab className={classes.tab} label="Datasets" {...a11yProps(0)} />
<Tab className={classes.tab} label="Activity" {...a11yProps(1)} />
<Tab className={classes.tab} label="Collections" {...a11yProps(2)} />
<Tab className={classes.tab} label="Spaces" {...a11yProps(3)} />
<Tab className={classes.tab} label="API Keys" {...a11yProps(4)} />
</Tabs>
</AppBar>
<TabPanel value={selectedTabIndex} index={0}>
{
datasets !== undefined && datasetThumbnailList !== undefined ?
datasets.map((dataset) => {
let thumbnailComp = <BusinessCenterIcon className={classes.fileCardImg}
style={{fontSize: "5em"}}/>;
datasetThumbnailList.map((thumbnail) => {
if (dataset["id"] !== undefined && thumbnail["id"] !== undefined &&
thumbnail["thumbnail"] !== null && thumbnail["thumbnail"] !== undefined &&
dataset["id"] === thumbnail["id"]) {
thumbnailComp = <img src={thumbnail["thumbnail"]} alt="thumbnail"
className={classes.fileCardImg}/>;
}
});
return (
<Box className={classes.fileCardOuterBox}>
<ListItem component={RouterLink}
to={`/datasets/${dataset["id"]}`}
className={classes.fileCard}
key={dataset["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>Dataset name: {dataset["name"]}</Typography>
<Typography>Description: {dataset["description"]}</Typography>
<Typography>Created on: {dataset["created"]}</Typography>
</Box>
</Grid>
</ListItem>
<Box className={classes.fileCardActionBox}>
<Box className={classes.fileCardActionItem}>
<Button startIcon={<DeleteOutlineIcon/>}
onClick={() => {deleteDataset(dataset["id"]);}}>
Delete</Button>
</Box>
<Box className={classes.fileCardActionItem}>
<Button startIcon={<StarBorderIcon/>}
disabled={true}>Follow</Button>
</Box>
<Box className={classes.fileCardActionItem}>
<Button startIcon={<CloudDownloadOutlinedIcon/>}
onClick={() => {downloadDataset(dataset["id"], dataset["name"]);}}>
Download</Button>
</Box>
</Box>
</Box>
);
})
:
<></>
}
<Button onClick={previous}>Prev</Button>
<Button onClick={next}>Next</Button>
</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}>
<Box className="actionCard">
<Typography className="title">Create your dataset</Typography>
<Typography className="content">Some quick example text to tell users why they should upload
their own data</Typography>
<Link className="link" onClick={() => {setOpen(true);}}>Create Dataset</Link>
</Box>
<Box className="actionCard">
<Typography className="title">Explore more dataset</Typography>
<Typography className="content">Some quick example text to tell users why they should follow
more people</Typography>
<Link href="" className="link">Go to Explore</Link>
</Box>
<Box className="actionCard">
<Typography className="title">Want to learn more about Clowder?</Typography>
<Typography className="content">Some quick example text to tell users why they should read
the tutorial</Typography>
<Link href="" className="link">Show me Tutorial</Link>
</Box>
</Grid>
</Grid>
<Dialog open={open} onClose={() => {setOpen(false);}} fullWidth={true} aria-labelledby="create-dataset">
<DialogTitle id="form-dialog-title">Create New Dataset</DialogTitle>
{/*pass select to uploader so once upload succeeded, can jump to that dataset/file page*/}
<CreateDataset setOpen={setOpen}/>
</Dialog>
</div>
</div>
</>
);
}
function TabPanel(props) {
const {children, value, index, ...other} = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`dashboard-tabpanel-${index}`}
aria-labelledby={`dashboard-tab-${index}`}
{...other}
>
{value === index && (
<Box p={3}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
function a11yProps(index:number) {
return {
id: `dashboard-tab-${index}`,
"aria-controls": `dashboard-tabpanel-${index}`,
};
}