-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.tsx
More file actions
242 lines (225 loc) · 8.45 KB
/
File.tsx
File metadata and controls
242 lines (225 loc) · 8.45 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
import React, {useEffect, useState} from "react";
import config from "../../app.config";
import {AppBar, Box, Grid, Tab, Tabs, Typography} from "@material-ui/core"
import {makeStyles} from "@material-ui/core/styles";
import Audio from "../previewers/Audio";
import Video from "../previewers/Video";
import {downloadResource} from "../../utils/common";
import Thumbnail from "../previewers/Thumbnail";
import Html from "../previewers/Html";
import {useDispatch, useSelector} from "react-redux";
import {useParams} from "react-router";
import {fetchFileMetadata, fetchFileMetadataJsonld, fetchFilePreviews} from "../../actions/file";
import TopBar from "../navigation/TopBar";
import {BreadCrumb} from "../navigation/BreadCrumb";
import {fetchDatasetAbout} from "../../actions/dataset";
import {useSearchParams} from "react-router-dom";
const useStyles = makeStyles(() => ({
appBar: {
background: "#FFFFFF",
boxShadow: "none",
},
tab: {
fontStyle: "normal",
fontWeight: "normal",
fontSize: "16px",
color: "#495057",
textTransform: "capitalize",
}
}));
export default function File() {
const classes = useStyles();
// path parameter
const {fileId} = useParams();
// search parameters
let [searchParams, _] = useSearchParams();
const datasetId = searchParams.get("datasetId");
const dispatch = useDispatch();
const listFileMetadata = (fileId:string|undefined) => dispatch((fetchFileMetadata(fileId)));
const listFileMetadataJsonld = (fileId:string|undefined) => dispatch((fetchFileMetadataJsonld(fileId)));
const listFilePreviews = (fileId:string|undefined) => dispatch((fetchFilePreviews(fileId)));
const listDatasetAbout = (datasetId:string|undefined) => dispatch(fetchDatasetAbout(datasetId));
const fileMetadata = useSelector((state) => state.file.metadata);
const fileMetadataJsonld = useSelector((state) => state.file.metadataJsonld);
const filePreviews = useSelector((state) => state.file.previews);
const datasetAbout = useSelector((state) => state.dataset.about);
const [selectedTabIndex, setSelectedTabIndex] = useState(0);
const [previews, setPreviews] = useState([]);
useEffect(() => {
listFileMetadata(fileId);
listFileMetadataJsonld(fileId);
listFilePreviews(fileId);
listDatasetAbout(datasetId);// get dataset name
}, []);
useEffect(() => {
(async () => {
if (filePreviews !== undefined && filePreviews.length > 0 && filePreviews[0].previews !== undefined) {
let previewsTemp = [];
await Promise.all(filePreviews[0].previews.map(async (filePreview) => {
// download resources
let Configuration = {};
Configuration.previewType = filePreview["p_id"].replace(" ", "-").toLowerCase();
Configuration.url = `${config.hostname}${filePreview["pv_route"]}?superAdmin=true`;
Configuration.fileid = filePreview["pv_id"];
Configuration.previewer = `/public${filePreview["p_path"]}/`;
Configuration.fileType = filePreview["pv_contenttype"];
// TODO need to fix on clowder v1: sometimes pv_route return the non-API routes
// /clowder/file vs clowder/api/file
// TODO Temp fix insert /api/
let pv_routes = filePreview["pv_route"];
if (!pv_routes.includes("/api/")) {
pv_routes = `${pv_routes.slice(0, 9)}api/${pv_routes.slice(9, pv_routes.length)}`
}
let resourceURL = `${config.hostname}${pv_routes}?superAdmin=true`;
Configuration.resource = await downloadResource(resourceURL);
previewsTemp.push(Configuration);
}));
setPreviews(previewsTemp);
}
})();
}, [filePreviews]);
const handleTabChange = (event, newTabIndex) => {
setSelectedTabIndex(newTabIndex);
};
const paths = [
{
"name": "Explore",
"url": "/"
},
{
"name": datasetAbout["name"],
"url": `/datasets/${datasetId}`
},
{
"name": fileMetadata["filename"],
"url": `/files/${fileId}?datasetId=${datasetId}`
}
]
return (
<>
<TopBar/>
<div className="outer-container">
<BreadCrumb paths={paths}/>
<div className="inner-container">
<Grid container spacing={4}>
<Grid item lg={8} sm={8} xl={8} xs={12}>
<AppBar className={classes.appBar} position="static">
<Tabs value={selectedTabIndex} onChange={handleTabChange} aria-label="file tabs">
<Tab className={classes.tab} label="Previews" {...a11yProps(0)} />
<Tab className={classes.tab} label="Metadata" {...a11yProps(2)} />
{/*<Tab className={classes.tab} label="Sections" {...a11yProps(1)} />*/}
{/*<Tab className={classes.tab} label="Extractions" {...a11yProps(3)} />*/}
{/*<Tab className={classes.tab} label="Comments" {...a11yProps(4)} />*/}
</Tabs>
</AppBar>
<TabPanel value={selectedTabIndex} index={0}>
{
previews.map((preview) => {
if (preview["previewType"] === "audio") {
return <Audio fileId={preview["fileid"]} audioSrc={preview["resource"]}/>;
} else if (preview["previewType"] === "video") {
return <Video fileId={preview["fileid"]} videoSrc={preview["resource"]}/>;
} else if (preview["previewType"] === "thumbnail") {
return <Thumbnail fileId={preview["fileid"]} fileType={preview["fileType"]}
imgSrc={preview["resource"]}/>;
} else if (preview["previewType"] === "html") {
return <Html fileId={preview["fileid"]}
htmlSrc={preview["resource"]}/>;
}
})
}
</TabPanel>
<TabPanel value={selectedTabIndex} index={1}>
{
fileMetadataJsonld !== undefined && fileMetadataJsonld.length > 0 ?
fileMetadataJsonld.map((item) => {
return Object.keys(item["content"]).map((key) => {
return (<p>{key} - {JSON.stringify(item["content"][key])}</p>);
}
);
}) : <></>
}
</TabPanel>
{/*<TabPanel value={selectedTabIndex} index={1}>*/}
{/* NA*/}
{/*</TabPanel>*/}
{/*<TabPanel value={selectedTabIndex} index={3}>*/}
{/* Extractions*/}
{/*</TabPanel>*/}
{/*<TabPanel value={selectedTabIndex} index={4}>*/}
{/* Comments*/}
{/*</TabPanel>*/}
</Grid>
<Grid item lg={4} sm={4} xl={4} xs={12}>
{
fileMetadata !== undefined ?
<Box className="infoCard">
<Typography className="title">About</Typography>
<Typography
className="content">File ID: {fileMetadata["id"]}</Typography>
<Typography
className="content">Type: {fileMetadata["content-type"]}</Typography>
<Typography className="content">File
size: {fileMetadata["size"]}</Typography>
<Typography className="content">Uploaded
on: {fileMetadata["date-created"]}</Typography>
<Typography className="content">Uploaded
as: {fileMetadata["filename"]}</Typography>
<Typography className="content">Uploaded
by: {fileMetadata["authorId"]}</Typography>
<Typography
className="content">Status: {fileMetadata["status"]}</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>
</div>
</div>
</>
);
}
function TabPanel(props) {
const {children, value, index, ...other} = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`file-tabpanel-${index}`}
aria-labelledby={`file-tab-${index}`}
{...other}
>
{value === index && (
<Box p={3}>
<Typography>{children}</Typography>
</Box>
)}
</div>
);
}
function a11yProps(index) {
return {
id: `file-tab-${index}`,
"aria-controls": `file-tabpanel-${index}`,
};
}