|
| 1 | +import { |
| 2 | + Box, |
| 3 | + Button, |
| 4 | + Card, |
| 5 | + CardContent, |
| 6 | + Chip, |
| 7 | + Link, |
| 8 | + Stack, |
| 9 | + Typography, |
| 10 | + Grid, |
| 11 | +} from "@mui/material"; |
| 12 | +import { Colors } from "design/theme"; |
| 13 | +import React from "react"; |
| 14 | +import { useNavigate } from "react-router-dom"; |
| 15 | +import { Row } from "redux/neurojson/types/neurojson.interface"; |
| 16 | +import RoutesEnum from "types/routes.enum"; |
| 17 | + |
| 18 | +interface DatasetPageCardProps { |
| 19 | + doc: Row; |
| 20 | + index: number; |
| 21 | + dbName: string; |
| 22 | + pageSize: number; |
| 23 | + page: number; |
| 24 | +} |
| 25 | + |
| 26 | +const DatasetPageCard: React.FC<DatasetPageCardProps> = ({ |
| 27 | + doc, |
| 28 | + index, |
| 29 | + dbName, |
| 30 | + page, |
| 31 | + pageSize, |
| 32 | +}) => { |
| 33 | + const navigate = useNavigate(); |
| 34 | + const datasetIndex = (page - 1) * pageSize + index + 1; |
| 35 | + return ( |
| 36 | + <Grid item xs={12} sm={6} key={doc.id}> |
| 37 | + <Card |
| 38 | + sx={{ |
| 39 | + position: "relative", |
| 40 | + backgroundColor: Colors.white, |
| 41 | + boxShadow: "0 2px 4px rgba(0,0,0,0.1)", |
| 42 | + height: "100%", |
| 43 | + display: "flex", |
| 44 | + flexDirection: "column", |
| 45 | + }} |
| 46 | + > |
| 47 | + <Box |
| 48 | + sx={{ |
| 49 | + position: "absolute", |
| 50 | + bottom: 8, |
| 51 | + right: 12, |
| 52 | + fontSize: "1rem", |
| 53 | + fontWeight: "bold", |
| 54 | + color: Colors.darkPurple, |
| 55 | + }} |
| 56 | + > |
| 57 | + #{datasetIndex} |
| 58 | + </Box> |
| 59 | + <CardContent sx={{ flex: 1 }}> |
| 60 | + <Button |
| 61 | + onClick={() => |
| 62 | + navigate( |
| 63 | + `${RoutesEnum.DATABASES}/${encodeURIComponent( |
| 64 | + dbName ?? "" |
| 65 | + )}/${encodeURIComponent(doc.id ?? "")}` |
| 66 | + ) |
| 67 | + } |
| 68 | + sx={{ |
| 69 | + fontSize: "1.25rem", |
| 70 | + margin: 0, |
| 71 | + color: Colors.darkPurple, |
| 72 | + textTransform: "none", |
| 73 | + justifyContent: "flex-start", |
| 74 | + width: "100%", |
| 75 | + textAlign: "left", |
| 76 | + "&:hover": { |
| 77 | + textDecoration: "underline", |
| 78 | + color: Colors.purple, |
| 79 | + backgroundColor: "transparent", |
| 80 | + transform: "scale(1.01)", |
| 81 | + }, |
| 82 | + }} |
| 83 | + > |
| 84 | + {doc.value.name || "Untitled"} |
| 85 | + </Button> |
| 86 | + |
| 87 | + <Typography |
| 88 | + color={Colors.textSecondary} |
| 89 | + variant="body2" |
| 90 | + sx={{ mb: 2, marginLeft: 1 }} |
| 91 | + > |
| 92 | + ID: {doc.id} |
| 93 | + </Typography> |
| 94 | + |
| 95 | + <Stack spacing={2} margin={1}> |
| 96 | + <Stack direction="row" spacing={1} flexWrap="wrap" gap={1}> |
| 97 | + {doc.value.subj && ( |
| 98 | + <Chip |
| 99 | + label={`${doc.value.subj.length} subjects`} |
| 100 | + size="small" |
| 101 | + sx={{ backgroundColor: Colors.purple, color: Colors.white }} |
| 102 | + /> |
| 103 | + )} |
| 104 | + {doc.value.modality && |
| 105 | + doc.value.modality.map((mod: string) => ( |
| 106 | + <Chip |
| 107 | + key={mod} |
| 108 | + label={mod} |
| 109 | + size="small" |
| 110 | + sx={{ |
| 111 | + backgroundColor: Colors.purpleGrey, |
| 112 | + color: Colors.white, |
| 113 | + }} |
| 114 | + /> |
| 115 | + ))} |
| 116 | + </Stack> |
| 117 | + |
| 118 | + <Typography variant="body2" color={Colors.textSecondary}> |
| 119 | + <strong>Summary:</strong>{" "} |
| 120 | + {doc.value.readme || "No description available"} |
| 121 | + </Typography> |
| 122 | + |
| 123 | + <Typography variant="body2" color={Colors.textPrimary}> |
| 124 | + <strong>Authors:</strong>{" "} |
| 125 | + {Array.isArray(doc.value.info?.Authors) |
| 126 | + ? doc.value.info.Authors.join(", ") |
| 127 | + : doc.value.info?.Authors || "Unknown"} |
| 128 | + </Typography> |
| 129 | + |
| 130 | + <Stack direction="row" spacing={2} alignItems="center"> |
| 131 | + <Typography variant="body2" color={Colors.textPrimary}> |
| 132 | + <strong>Size:</strong>{" "} |
| 133 | + {doc.value.length |
| 134 | + ? `${(doc.value.length / 1024 / 1024).toFixed(2)} MB` |
| 135 | + : "Unknown"} |
| 136 | + </Typography> |
| 137 | + |
| 138 | + {doc.value.info?.DatasetDOI && ( |
| 139 | + <Link |
| 140 | + href={doc.value.info.DatasetDOI} |
| 141 | + target="_blank" |
| 142 | + rel="noopener" |
| 143 | + > |
| 144 | + <Chip |
| 145 | + label="DOI" |
| 146 | + size="small" |
| 147 | + clickable |
| 148 | + sx={{ backgroundColor: Colors.accent, color: Colors.white }} |
| 149 | + /> |
| 150 | + </Link> |
| 151 | + )} |
| 152 | + </Stack> |
| 153 | + </Stack> |
| 154 | + </CardContent> |
| 155 | + </Card> |
| 156 | + </Grid> |
| 157 | + ); |
| 158 | +}; |
| 159 | + |
| 160 | +export default DatasetPageCard; |
0 commit comments