Skip to content

Commit f14cffe

Browse files
committed
feat: add participants preview table for better readability
1 parent 237ae9a commit f14cffe

File tree

5 files changed

+150
-10
lines changed

5 files changed

+150
-10
lines changed

src/components/DatasetDetailPage/MetaDataPanel.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ParticipantsPreview from "./ParticipantsPreview";
12
import ArrowCircleRightIcon from "@mui/icons-material/ArrowCircleRight";
23
import {
34
Box,
@@ -190,13 +191,23 @@ const MetaDataPanel: React.FC<Props> = ({
190191
})()}
191192
</Typography>
192193
</Box>
193-
<Box>
194-
<Typography sx={{ color: Colors.darkPurple, fontWeight: "600" }}>
195-
Subjects
196-
</Typography>
197-
<Typography sx={{ color: "text.secondary" }}>
198-
{dbViewInfo?.rows?.[0]?.value?.subj?.length ?? "N/A"}
199-
</Typography>
194+
<Box
195+
sx={{
196+
display: "flex",
197+
flexDirection: "row",
198+
gap: 2,
199+
alignItems: "flex-start",
200+
}}
201+
>
202+
<Box>
203+
<Typography sx={{ color: Colors.darkPurple, fontWeight: "600" }}>
204+
Subjects
205+
</Typography>
206+
<Typography sx={{ color: "text.secondary" }}>
207+
{dbViewInfo?.rows?.[0]?.value?.subj?.length ?? "N/A"}
208+
</Typography>
209+
</Box>
210+
<ParticipantsPreview datasetDocument={datasetDocument} />
200211
</Box>
201212
<Box>
202213
<Typography sx={{ color: Colors.darkPurple, fontWeight: "600" }}>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { makeParticipantsTable } from "../../utils/DatasetDetailPageFunctions/participants";
2+
import {
3+
Box,
4+
Button,
5+
Dialog,
6+
DialogContent,
7+
DialogTitle,
8+
Table,
9+
TableBody,
10+
TableCell,
11+
TableContainer,
12+
TableHead,
13+
TableRow,
14+
Paper,
15+
} from "@mui/material";
16+
import { Colors } from "design/theme";
17+
import React, { useMemo, useState } from "react";
18+
19+
type Props = {
20+
datasetDocument: any;
21+
};
22+
23+
const ParticipantsPreview: React.FC<Props> = ({ datasetDocument }) => {
24+
const [open, setOpen] = useState(false);
25+
26+
const table = useMemo(() => {
27+
const part = datasetDocument?.["participants.tsv"];
28+
return makeParticipantsTable(part);
29+
}, [datasetDocument]);
30+
31+
if (!table) return null; // No participants.tsv found
32+
33+
return (
34+
<>
35+
<Box>
36+
<Button
37+
variant="outlined"
38+
size="small"
39+
onClick={() => setOpen(true)}
40+
sx={{
41+
color: Colors.purple,
42+
borderColor: Colors.purple,
43+
"&:hover": {
44+
color: Colors.secondaryPurple,
45+
transform: "scale(1.01)",
46+
borderColor: Colors.purple,
47+
},
48+
}}
49+
>
50+
Participants Table Preview
51+
</Button>
52+
</Box>
53+
54+
<Dialog
55+
open={open}
56+
onClose={() => setOpen(false)}
57+
maxWidth="md"
58+
fullWidth
59+
>
60+
<DialogTitle>participants.tsv</DialogTitle>
61+
<DialogContent dividers>
62+
<TableContainer component={Paper}>
63+
<Table size="small">
64+
<TableHead>
65+
<TableRow>
66+
{table.columns.map((col) => (
67+
<TableCell
68+
key={col}
69+
sx={{
70+
fontWeight: "bold",
71+
backgroundColor: Colors.darkPurple,
72+
color: Colors.white,
73+
}}
74+
>
75+
{col.replace(/_/g, " ")}
76+
</TableCell>
77+
))}
78+
</TableRow>
79+
</TableHead>
80+
<TableBody>
81+
{table.rows.map((row, rowIdx) => (
82+
<TableRow key={rowIdx}>
83+
{table.columns.map((col) => (
84+
<TableCell key={col}>{row[col]}</TableCell>
85+
))}
86+
</TableRow>
87+
))}
88+
</TableBody>
89+
</Table>
90+
</TableContainer>
91+
</DialogContent>
92+
</Dialog>
93+
</>
94+
);
95+
};
96+
97+
export default ParticipantsPreview;

src/components/SearchPage/DatabaseCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const DatabaseCard: React.FC<Props> = ({
3939
}) => {
4040
const dispatch = useAppDispatch();
4141
const dbInfo = useAppSelector((state: RootState) => state.neurojson.dbInfo);
42-
console.log("dbInfo", dbInfo);
42+
// console.log("dbInfo", dbInfo);
4343
useEffect(() => {
4444
if (dbId) {
4545
dispatch(fetchDbInfo(dbId.toLowerCase()));

src/pages/UpdatedDatasetDetailPage.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,8 +966,6 @@ const UpdatedDatasetDetailPage: React.FC = () => {
966966
<FileTree
967967
title={treeTitle}
968968
tree={treeData}
969-
// filesCount={filesCount}
970-
// totalBytes={totalBytes}
971969
onPreview={handlePreview} // pass the function down to FileTree
972970
getInternalByPath={getInternalByPath}
973971
getJsonByPath={getJsonByPath}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export type ParticipantsTable = { columns: string[]; rows: any[] };
2+
3+
export function makeParticipantsTable(part: any): ParticipantsTable | null {
4+
if (!part || typeof part !== "object") return null;
5+
6+
// Case A: object-of-arrays
7+
// const cols = Object.keys(part);
8+
// const isObjOfArrays =
9+
// cols.length > 0 && cols.every((k) => Array.isArray(part[k]));
10+
const arrayCols = Object.keys(part).filter((k) => Array.isArray(part[k]));
11+
12+
if (arrayCols.length > 0) {
13+
const n = Math.max(...arrayCols.map((k) => part[k].length));
14+
const rows = Array.from({ length: n }, (_, i) => {
15+
const r: any = { id: i + 1 };
16+
arrayCols.forEach((k) => (r[k] = part[k][i] ?? ""));
17+
return r;
18+
});
19+
return { columns: arrayCols, rows };
20+
}
21+
22+
// Case B: array-of-objects fallback
23+
if (Array.isArray(part)) {
24+
const allCols = new Set<string>();
25+
part.forEach((r: any) =>
26+
Object.keys(r || {}).forEach((k) => allCols.add(k))
27+
);
28+
const columns = Array.from(allCols);
29+
const rows = part.map((r: any, i: number) => ({ id: i + 1, ...(r || {}) }));
30+
return { columns, rows };
31+
}
32+
33+
return null;
34+
}

0 commit comments

Comments
 (0)