Skip to content

Commit 10abb36

Browse files
committed
feat: make database card datatypes conditionally clickable based on modality allowlist; #81
1 parent 37b3d3a commit 10abb36

File tree

3 files changed

+243
-170
lines changed

3 files changed

+243
-170
lines changed

src/components/SearchPage/DatabaseCard.tsx

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Colors } from "design/theme";
1111
import React from "react";
1212
import { Link } from "react-router-dom";
1313
import RoutesEnum from "types/routes.enum";
14+
import { modalityValueToEnumLabel } from "utils/SearchPageFunctions/modalityLabels";
1415

1516
type Props = {
1617
dbName?: string;
@@ -59,6 +60,47 @@ const DatabaseCard: React.FC<Props> = ({
5960
);
6061
};
6162

63+
// for datatype rendering
64+
const isClickableModality = (raw: string) =>
65+
!!modalityValueToEnumLabel[raw.toLowerCase()];
66+
67+
const renderDatatype = (raw: string, idx: number) => {
68+
const key = raw.toLowerCase();
69+
const label = modalityValueToEnumLabel[key];
70+
71+
if (label) {
72+
// Clickable modality → drives the "modality" filter
73+
return (
74+
<Chip
75+
key={`${key}-${idx}`}
76+
label={key}
77+
variant="outlined"
78+
onClick={() => onChipClick("modality", key)} // pass normalized key
79+
sx={{
80+
"& .MuiChip-label": { px: "6px", fontSize: "0.8rem" },
81+
height: 24,
82+
color: Colors.darkPurple,
83+
border: `1px solid ${Colors.darkPurple}`,
84+
fontWeight: "bold",
85+
transition: "all 0.2s ease",
86+
"&:hover": {
87+
backgroundColor: `${Colors.purple} !important`,
88+
color: "white",
89+
borderColor: Colors.purple,
90+
},
91+
}}
92+
/>
93+
);
94+
}
95+
96+
// Not a modality → render as plain text (or a disabled/outlined chip if you prefer)
97+
return (
98+
<Typography key={`${key}-${idx}`} variant="body2" sx={{ mt: 1, mr: 1 }}>
99+
{raw}
100+
</Typography>
101+
);
102+
};
103+
62104
return (
63105
<Card sx={{ mb: 3, position: "relative" }}>
64106
<CardContent>
@@ -115,35 +157,38 @@ const DatabaseCard: React.FC<Props> = ({
115157
alignItems="center"
116158
>
117159
<Typography variant="body2" mt={1}>
118-
<strong>Modalities:</strong>
160+
<strong>Data Type:</strong>
119161
</Typography>
120162

121163
{Array.isArray(modalities) && modalities.length > 0 ? (
122-
modalities.map((mod, idx) => (
123-
<Chip
124-
key={idx}
125-
label={mod}
126-
variant="outlined"
127-
onClick={() => onChipClick("modality", mod)}
128-
sx={{
129-
"& .MuiChip-label": {
130-
paddingX: "6px",
131-
fontSize: "0.8rem",
132-
},
133-
height: "24px",
134-
color: Colors.darkPurple,
135-
border: `1px solid ${Colors.darkPurple}`,
136-
fontWeight: "bold",
137-
transition: "all 0.2s ease",
138-
"&:hover": {
139-
backgroundColor: `${Colors.purple} !important`,
140-
color: "white",
141-
borderColor: Colors.purple,
142-
},
143-
}}
144-
/>
145-
))
164+
modalities.map(renderDatatype)
146165
) : (
166+
// (
167+
// modalities.map((mod, idx) => (
168+
// <Chip
169+
// key={idx}
170+
// label={mod}
171+
// variant="outlined"
172+
// onClick={() => onChipClick("modality", mod)}
173+
// sx={{
174+
// "& .MuiChip-label": {
175+
// paddingX: "6px",
176+
// fontSize: "0.8rem",
177+
// },
178+
// height: "24px",
179+
// color: Colors.darkPurple,
180+
// border: `1px solid ${Colors.darkPurple}`,
181+
// fontWeight: "bold",
182+
// transition: "all 0.2s ease",
183+
// "&:hover": {
184+
// backgroundColor: `${Colors.purple} !important`,
185+
// color: "white",
186+
// borderColor: Colors.purple,
187+
// },
188+
// }}
189+
// />
190+
// ))
191+
// )
147192
<Typography variant="body2" mt={1}>
148193
N/A
149194
</Typography>

0 commit comments

Comments
 (0)