@@ -14,6 +14,7 @@ import { useTheme } from "@mui/material/styles";
1414import useMediaQuery from "@mui/material/useMediaQuery" ;
1515import Form from "@rjsf/mui" ;
1616import validator from "@rjsf/validator-ajv8" ;
17+ import DatabaseCard from "components/SearchPage/DatabaseCard" ;
1718import DatasetCard from "components/SearchPage/DatasetCard" ;
1819import SubjectCard from "components/SearchPage/SubjectCard" ;
1920import { Colors } from "design/theme" ;
@@ -30,6 +31,25 @@ import { RootState } from "redux/store";
3031import { generateUiSchema } from "utils/SearchPageFunctions/generateUiSchema" ;
3132import { modalityValueToEnumLabel } from "utils/SearchPageFunctions/modalityLabels" ;
3233
34+ type RegistryItem = {
35+ id : string ;
36+ name ?: string ;
37+ fullname ?: string ;
38+ datatype ?: string [ ] ;
39+ datasets ?: number ;
40+ logo ?: string ;
41+ } ;
42+
43+ const matchesKeyword = ( item : RegistryItem , keyword : string ) => {
44+ if ( ! keyword ) return false ;
45+ const needle = keyword . toLowerCase ( ) ;
46+ return (
47+ item . name ?. toLowerCase ( ) . includes ( needle ) ||
48+ item . fullname ?. toLowerCase ( ) . includes ( needle ) ||
49+ item . datatype ?. some ( ( dt ) => dt . toLowerCase ( ) . includes ( needle ) )
50+ ) ;
51+ } ;
52+
3353const SearchPage : React . FC = ( ) => {
3454 const dispatch = useAppDispatch ( ) ;
3555 const [ hasSearched , setHasSearched ] = useState ( false ) ;
@@ -54,6 +74,17 @@ const SearchPage: React.FC = () => {
5474 const theme = useTheme ( ) ;
5575 const isMobile = useMediaQuery ( theme . breakpoints . down ( "sm" ) ) ;
5676
77+ // for database card
78+ const keywordInput = String ( formData ?. keyword ?? "" ) . trim ( ) ;
79+ console . log ( "keyword" , keywordInput ) ;
80+
81+ const registryMatches : RegistryItem [ ] = React . useMemo ( ( ) => {
82+ if ( ! Array . isArray ( registry ) || ! keywordInput ) return [ ] ;
83+ return ( registry as RegistryItem [ ] ) . filter ( ( r ) =>
84+ matchesKeyword ( r , keywordInput )
85+ ) ;
86+ } , [ registry , keywordInput ] ) ;
87+
5788 // to show the applied chips on the top of results
5889 const activeFilters = Object . entries ( appliedFilters ) . filter (
5990 ( [ key , value ] ) =>
@@ -298,13 +329,14 @@ const SearchPage: React.FC = () => {
298329
299330 return (
300331 < Container
332+ maxWidth = { false }
301333 style = { {
302334 marginTop : "2rem" ,
303335 marginBottom : "2rem" ,
304336 backgroundColor : Colors . white ,
305337 padding : "2rem" ,
306338 borderRadius : 4 ,
307- width : "100 %" ,
339+ width : "95 %" ,
308340 } }
309341 >
310342 < Box // box for title and show filters button(mobile version)
@@ -465,6 +497,30 @@ const SearchPage: React.FC = () => {
465497 </ Box >
466498 ) }
467499
500+ { /* matching databases */ }
501+ { keywordInput && registryMatches . length > 0 && (
502+ < Box sx = { { mb : 3 } } >
503+ < Typography
504+ variant = "h6"
505+ sx = { { mb : 1.5 , mt : 1.5 , fontWeight : "600" } }
506+ >
507+ Matching Databases
508+ </ Typography >
509+ { registryMatches . map ( ( db ) => (
510+ < DatabaseCard
511+ key = { db . id }
512+ dbName = { db . name }
513+ fullName = { db . fullname }
514+ datasets = { db . datasets }
515+ modalities = { db . datatype }
516+ logo = { db . logo }
517+ keyword = { formData . keyword } // for keyword highlight
518+ onChipClick = { handleChipClick }
519+ />
520+ ) ) }
521+ </ Box >
522+ ) }
523+
468524 { /* results */ }
469525 { hasSearched && (
470526 < Box mt = { 4 } >
0 commit comments