|
| 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; |
0 commit comments