Skip to content

Commit 3c4c2aa

Browse files
committed
feat: make modalities in detadatapanel clickable to run a search for selected modality; closes #97
1 parent d9e7dce commit 3c4c2aa

2 files changed

Lines changed: 64 additions & 2 deletions

File tree

src/components/DatasetDetailPage/MetaDataPanel.tsx

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import {
1111
Tooltip,
1212
} from "@mui/material";
1313
import { Colors } from "design/theme";
14+
import pako from "pako";
1415
import React, { useMemo, useState } from "react";
16+
import { modalityValueToEnumLabel } from "utils/SearchPageFunctions/modalityLabels";
1517

1618
type Props = {
1719
dbViewInfo: any;
@@ -63,6 +65,19 @@ const MetaDataPanel: React.FC<Props> = ({
6365
// const [revIdx, setRevIdx] = useState(0);
6466
// const selected = revs[revIdx];
6567

68+
// builds /search#query=<deflated-base64>
69+
const buildSearchUrl = (query: Record<string, any>) => {
70+
const deflated = pako.deflate(JSON.stringify(query));
71+
const encoded = btoa(String.fromCharCode(...deflated));
72+
return `${window.location.origin}/search#query=${encoded}`;
73+
};
74+
75+
const openSearchForModality = (mod: string) => {
76+
const normalized = modalityValueToEnumLabel[mod] || mod;
77+
const url = buildSearchUrl({ modality: normalized });
78+
window.open(url, "_blank", "noopener,noreferrer");
79+
};
80+
6681
return (
6782
<Box
6883
sx={{
@@ -90,9 +105,54 @@ const MetaDataPanel: React.FC<Props> = ({
90105
<Typography sx={{ color: Colors.darkPurple, fontWeight: "600" }}>
91106
Modalities
92107
</Typography>
93-
<Typography sx={{ color: "text.secondary" }}>
108+
109+
{(() => {
110+
const mods = Array.isArray(dbViewInfo?.rows?.[0]?.value?.modality)
111+
? [...new Set(dbViewInfo.rows[0].value.modality as string[])]
112+
: [];
113+
114+
if (mods.length === 0) {
115+
return (
116+
<Typography sx={{ color: "text.secondary" }}>N/A</Typography>
117+
);
118+
}
119+
120+
return (
121+
<Box sx={{ display: "flex", flexWrap: "wrap", gap: 1, mt: 0.5 }}>
122+
{mods.map((m) => (
123+
<Chip
124+
key={m}
125+
label={m}
126+
clickable
127+
onClick={() => openSearchForModality(m)}
128+
variant="outlined"
129+
sx={{
130+
"& .MuiChip-label": {
131+
paddingX: "7px",
132+
fontSize: "0.8rem",
133+
},
134+
height: "24px",
135+
color: Colors.white,
136+
border: `1px solid ${Colors.orange}`,
137+
fontWeight: "bold",
138+
transition: "all 0.2s ease",
139+
backgroundColor: `${Colors.orange} !important`,
140+
"&:hover": {
141+
backgroundColor: `${Colors.darkOrange} !important`,
142+
color: "white",
143+
borderColor: Colors.darkOrange,
144+
paddingX: "8px",
145+
fontSize: "1rem",
146+
},
147+
}}
148+
/>
149+
))}
150+
</Box>
151+
);
152+
})()}
153+
{/* <Typography sx={{ color: "text.secondary" }}>
94154
{dbViewInfo?.rows?.[0]?.value?.modality?.join(", ") ?? "N/A"}
95-
</Typography>
155+
</Typography> */}
96156
</Box>
97157
<Box>
98158
<Typography sx={{ color: Colors.darkPurple, fontWeight: "600" }}>

src/pages/SearchPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ const SearchPage: React.FC = () => {
170170
const requestData = { ...parsed, skip: 0, limit: 50 };
171171
setSkip(0);
172172
setHasSearched(true);
173+
setShowSubjectFilters(true); // expand the subject-level section
174+
setShowDatasetFilters(true); // expand the dataset-level section
173175
dispatch(fetchMetadataSearchResults(requestData)).then((res: any) => {
174176
if (res.payload) {
175177
setResults(res.payload);

0 commit comments

Comments
 (0)