-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetaDataPanel.tsx
More file actions
290 lines (275 loc) · 8.79 KB
/
MetaDataPanel.tsx
File metadata and controls
290 lines (275 loc) · 8.79 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
import ArrowCircleRightIcon from "@mui/icons-material/ArrowCircleRight";
import {
Box,
Typography,
FormControl,
InputLabel,
Select,
MenuItem,
Chip,
IconButton,
Tooltip,
} from "@mui/material";
import { Colors } from "design/theme";
import React, { useMemo, useState } from "react";
type Props = {
dbViewInfo: any;
datasetDocument: any;
dbName: string | undefined;
docId: string | undefined;
// NEW:
currentRev?: string; // from URL (?rev=...)
onChangeRev?: (rev?: string | null) => void; // to update URL
revsList?: { rev: string }[];
};
type RevInfo = { rev: string };
const MetaDataPanel: React.FC<Props> = ({
dbViewInfo,
datasetDocument,
dbName,
docId,
currentRev,
onChangeRev,
revsList = [], // default empty
}) => {
// const revs: RevInfo[] = useMemo(
// () =>
// Array.isArray(datasetDocument?.["_revs_info"])
// ? (datasetDocument!["_revs_info"] as RevInfo[])
// : [],
// [datasetDocument]
// );
const revs = revsList;
// derive index from currentRev; fallback to 0 (latest)
const deriveIdx = React.useCallback((revList: RevInfo[], cur?: string) => {
if (!revList.length) return 0;
if (!cur) return 0;
const idx = revList.findIndex((r) => r.rev === cur);
return idx >= 0 ? idx : 0;
}, []);
const [revIdx, setRevIdx] = useState<number>(deriveIdx(revs, currentRev));
// keep local idx synced when URL rev or list changes
React.useEffect(() => {
setRevIdx(deriveIdx(revs, currentRev));
}, [revs, currentRev, deriveIdx]);
const selected = revs[revIdx];
// const [revIdx, setRevIdx] = useState(0);
// const selected = revs[revIdx];
return (
<Box
sx={{
backgroundColor: "#fff",
borderRadius: "8px",
display: "flex",
flexDirection: "column",
overflow: "hidden",
height: "100%",
minHeight: 0,
}}
>
<Box
sx={{
flex: 1,
minHeight: 0, // <-- for scroller
overflowY: "auto", // <-- keep the scroller here
p: 2,
display: "flex",
flexDirection: "column",
gap: 1,
}}
>
<Box>
<Typography sx={{ color: Colors.darkPurple, fontWeight: "600" }}>
Modalities
</Typography>
<Typography sx={{ color: "text.secondary" }}>
{dbViewInfo?.rows?.[0]?.value?.modality?.join(", ") ?? "N/A"}
</Typography>
</Box>
<Box>
<Typography sx={{ color: Colors.darkPurple, fontWeight: "600" }}>
DOI
</Typography>
<Typography sx={{ color: "text.secondary" }}>
{(() => {
const doi =
datasetDocument?.["dataset_description.json"]?.DatasetDOI ||
datasetDocument?.["dataset_description.json"]?.ReferenceDOI;
if (!doi) return "N/A";
// Normalize into a clickable URL
let url = doi;
if (/^10\./.test(doi)) {
url = `https://doi.org/${doi}`;
} else if (/^doi:/.test(doi)) {
url = `https://doi.org/${doi.replace(/^doi:/, "")}`;
}
return (
<a
href={url}
target="_blank"
rel="noopener noreferrer"
style={{
color: "inherit",
textDecoration: "underline",
}}
>
{url}
</a>
);
})()}
</Typography>
</Box>
<Box>
<Typography sx={{ color: Colors.darkPurple, fontWeight: "600" }}>
Subjects
</Typography>
<Typography sx={{ color: "text.secondary" }}>
{dbViewInfo?.rows?.[0]?.value?.subj?.length ?? "N/A"}
</Typography>
</Box>
<Box>
<Typography sx={{ color: Colors.darkPurple, fontWeight: "600" }}>
License
</Typography>
<Typography sx={{ color: "text.secondary" }}>
{datasetDocument?.["dataset_description.json"]?.License ?? "N/A"}
</Typography>
</Box>
<Box>
<Typography sx={{ color: Colors.darkPurple, fontWeight: "600" }}>
BIDS Version
</Typography>
<Typography sx={{ color: "text.secondary" }}>
{datasetDocument?.["dataset_description.json"]?.BIDSVersion ??
"N/A"}
</Typography>
</Box>
<Box>
<Typography sx={{ color: Colors.darkPurple, fontWeight: "600" }}>
References and Links
</Typography>
<Typography sx={{ color: "text.secondary" }}>
{Array.isArray(
datasetDocument?.["dataset_description.json"]?.ReferencesAndLinks
)
? datasetDocument["dataset_description.json"].ReferencesAndLinks
.length > 0
? datasetDocument[
"dataset_description.json"
].ReferencesAndLinks.join(", ")
: "N/A"
: datasetDocument?.["dataset_description.json"]
?.ReferencesAndLinks ?? "N/A"}
</Typography>
</Box>
{revs.length > 0 && (
<Box
sx={{
mt: 2,
p: 2,
border: `1px solid ${Colors.lightGray}`,
borderRadius: 1,
}}
>
<Typography
// variant="subtitle1"
sx={{ mb: 1, fontWeight: 600, color: Colors.darkPurple }}
>
Revisions
</Typography>
<FormControl
fullWidth
size="small"
sx={{
mb: 1,
"& .MuiOutlinedInput-root": {
"& fieldset": {
borderColor: Colors.green,
},
"&:hover fieldset": {
borderColor: Colors.green,
},
"&.Mui-focused fieldset": {
borderColor: Colors.green,
},
},
"& .MuiInputLabel-root.Mui-focused": {
color: Colors.green,
},
}}
>
<InputLabel id="rev-select-label">Select revision</InputLabel>
<Select
labelId="rev-select-label"
label="Select revision"
value={revIdx}
onChange={(e) => {
const idx = Number(e.target.value);
setRevIdx(idx);
const chosen = revs[idx]?.rev;
// update URL -> parent will refetch with ?rev=chosen
onChangeRev?.(chosen || null);
}}
// onChange={(e) => setRevIdx(Number(e.target.value))}
>
{revs.map((r, idx) => {
const [verNum, hash] = r.rev.split("-", 2);
return (
<MenuItem key={r.rev} value={idx}>
<Typography component="span">
Revision {verNum} ({r.rev.slice(0, 8)}…{r.rev.slice(-4)}
)
</Typography>
</MenuItem>
);
})}
</Select>
</FormControl>
{selected && (
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
gap: 1,
}}
>
<Box sx={{ minWidth: 0 }}>
<Typography variant="body2" sx={{ color: "text.secondary" }}>
Selected rev:
</Typography>
<Typography
variant="body2"
sx={{ fontFamily: "monospace", wordBreak: "break-all" }}
title={selected.rev}
>
{selected.rev}
</Typography>
</Box>
<Tooltip title="Open this revision in NeuroJSON.io">
<IconButton
size="small"
onClick={() =>
window.open(
`https://neurojson.io:7777/${dbName}/${docId}?rev=${selected.rev}`,
"_blank"
)
}
>
<ArrowCircleRightIcon
fontSize="small"
sx={{
color: Colors.green,
}}
/>
</IconButton>
</Tooltip>
</Box>
)}
</Box>
)}
</Box>
</Box>
);
};
export default MetaDataPanel;