Skip to content

Commit 3de04fc

Browse files
committed
feat: add DatasetCard component to display dataset-level search results
1 parent 31e8324 commit 3de04fc

File tree

8 files changed

+115
-134
lines changed

8 files changed

+115
-134
lines changed

public/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
/> -->
5151

5252
<title>NeuroJSON.io - Free Data Worth Sharing</title>
53-
<script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script>
5453
</head>
5554
<body>
5655
<noscript>You need to enable JavaScript to run this app.</noscript>

src/components/Routes.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import DatabasePage from "pages/DatabasePage";
33
import DatasetDetailPage from "pages/DatasetDetailPage";
44
import DatasetPage from "pages/DatasetPage";
55
import Home from "pages/Home";
6-
import SearchForm from "pages/SearchForm";
76
import SearchPage from "pages/SearchPage";
87
import React from "react";
98
import { Navigate, Route, Routes as RouterRoutes } from "react-router-dom";
@@ -32,7 +31,6 @@ const Routes = () => (
3231

3332
{/* Search Page */}
3433
<Route path={RoutesEnum.SEARCH} element={<SearchPage />} />
35-
{/* <Route path={RoutesEnum.SEARCH} element={<SearchForm />} /> */}
3634
</Route>
3735
</RouterRoutes>
3836
);
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import {
2+
Box,
3+
Typography,
4+
Card,
5+
CardContent,
6+
Stack,
7+
Chip,
8+
Grid,
9+
Link,
10+
} from "@mui/material";
11+
import { Colors } from "design/theme";
12+
import React from "react";
13+
14+
interface DatasetCardProps {
15+
dbname: string;
16+
dsname: string;
17+
parsedJson: {
18+
key: string;
19+
value: {
20+
name?: string;
21+
readme?: string;
22+
modality?: string[];
23+
subj?: string[];
24+
info?: {
25+
Authors?: string[];
26+
DatasetDOI?: string;
27+
};
28+
};
29+
};
30+
}
31+
32+
const DatasetCard: React.FC<DatasetCardProps> = ({
33+
dbname,
34+
dsname,
35+
parsedJson,
36+
}) => {
37+
const { name, readme, modality, subj, info } = parsedJson.value;
38+
39+
// prepare DOI URL
40+
const rawDOI = info?.DatasetDOI?.replace(/^doi:/, "");
41+
const doiLink = rawDOI ? `https://doi.org/${rawDOI}` : null;
42+
43+
return (
44+
<Card sx={{ mb: 3 }}>
45+
<CardContent>
46+
<Typography variant="h6" sx={{ color: "#6C6C8E", fontWeight: 600 }}>
47+
{name || "Untitled Dataset"}
48+
</Typography>
49+
50+
<Typography variant="body2" color="text.secondary" gutterBottom>
51+
ID: {dsname}
52+
</Typography>
53+
54+
<Stack>
55+
{subj && <Chip label={`${subj.length} subjects`} color="primary" />}
56+
{modality?.map((mod, idx) => (
57+
<Chip key={idx} label={mod} color="info" />
58+
))}
59+
</Stack>
60+
61+
{readme && (
62+
<Typography variant="body2" paragraph>
63+
<strong>Summary:</strong> {readme}
64+
</Typography>
65+
)}
66+
67+
{info?.Authors?.length && (
68+
<Typography>
69+
<strong>Authors:</strong> {info?.Authors?.join(", ")}
70+
</Typography>
71+
)}
72+
73+
{doiLink && (
74+
<Stack mt={1}>
75+
<Chip
76+
label="DOI"
77+
component="a"
78+
href={doiLink}
79+
target="_blank"
80+
rel="noopener noreferrer"
81+
clickable
82+
sx={{ backgroundColor: "#c9a636", color: "white" }}
83+
/>
84+
</Stack>
85+
)}
86+
</CardContent>
87+
</Card>
88+
);
89+
};
90+
91+
export default DatasetCard;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Box, Card, CardContent, Grid, Link } from "@mui/material";
2+
import { Colors } from "design/theme";
3+
4+
const SubjectCard: React.FC = () => {
5+
return <></>;
6+
};
7+
8+
export default SubjectCard;

src/pages/SearchForm.tsx

Lines changed: 0 additions & 108 deletions
This file was deleted.

src/pages/SearchPage.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { generateSchemaWithDatabaseEnum } from "./searchformSchema";
2-
// schema
32
import { Typography, Container, Box } from "@mui/material";
43
import Form from "@rjsf/mui";
54
import validator from "@rjsf/validator-ajv8";
@@ -8,7 +7,6 @@ import { useAppDispatch } from "hooks/useAppDispatch";
87
import { useAppSelector } from "hooks/useAppSelector";
98
import React from "react";
109
import { useState, useEffect, useMemo } from "react";
11-
// useEffect useMemo
1210
import { Link } from "react-router-dom";
1311
import {
1412
fetchMetadataSearchResults,
@@ -27,14 +25,26 @@ const SearchPage: React.FC = () => {
2725
(state: RootState) => state.neurojson.registry
2826
);
2927

30-
console.log("registry:", registry);
3128
console.log("result:", searchResults);
29+
if (Array.isArray(searchResults)) {
30+
searchResults.forEach((item, idx) => {
31+
// console.log(`Raw item #${idx}:`, item);
32+
try {
33+
const parsed = JSON.parse(item.json);
34+
console.log(`Result #${idx}:`, { ...item, parsedJson: parsed });
35+
} catch (e) {
36+
console.error(`Failed to parse JSON for item #${idx}`, e);
37+
}
38+
});
39+
} else {
40+
console.warn("searchResults is not an array:", searchResults);
41+
}
3242

3343
useEffect(() => {
3444
dispatch(fetchRegistry());
3545
}, [dispatch]);
3646

37-
// dynamic add database enum to schema
47+
// dynamically add database enum to schema
3848
const schema = useMemo(() => {
3949
const dbList = registry?.length
4050
? [...registry.map((item: any) => item.id), "any"]
@@ -49,7 +59,6 @@ const SearchPage: React.FC = () => {
4959

5060
return (
5161
<Container
52-
// maxWidth="md"
5362
style={{
5463
marginTop: "2rem",
5564
// backgroundColor: "rgba(97, 109, 243, 0.4)",
@@ -62,18 +71,13 @@ const SearchPage: React.FC = () => {
6271
>
6372
<Box
6473
sx={{
65-
// backgroundColor: "white",
66-
// p: 3,
67-
// borderRadius: 2,
68-
// boxShadow: 1,
6974
display: "flex",
7075
gap: 3,
7176
alignItems: "flex-start",
7277
}}
7378
>
7479
<Box
7580
sx={{
76-
// flex: "0 0 300px", // fixed width
7781
flex: 1,
7882
backgroundColor: "white",
7983
p: 3,
@@ -85,7 +89,7 @@ const SearchPage: React.FC = () => {
8589
schema={schema}
8690
onSubmit={handleSubmit}
8791
validator={validator}
88-
liveValidate
92+
// liveValidate
8993
/>
9094
</Box>
9195

src/pages/searchformSchema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export const baseSchema: JSONSchema7 = {
137137
// default: false,
138138
// },
139139
},
140+
required: ["keyword"],
140141
};
141142

142143
// Helper to inject dynamic "database" enum

src/types/json-editor.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)