@@ -76,14 +76,34 @@ const SearchPage: React.FC = () => {
7676
7777 // for database card
7878 const keywordInput = String ( formData ?. keyword ?? "" ) . trim ( ) ;
79+ const selectedDbId = String ( formData ?. database ?? "" ) . trim ( ) ;
7980 console . log ( "keyword" , keywordInput ) ;
8081
82+ // const registryMatches: RegistryItem[] = React.useMemo(() => {
83+ // if (!Array.isArray(registry) || !keywordInput) return [];
84+ // return (registry as RegistryItem[]).filter((r) =>
85+ // matchesKeyword(r, keywordInput)
86+ // );
87+ // }, [registry, keywordInput]);
88+
8189 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 ] ) ;
90+ if ( ! Array . isArray ( registry ) ) return [ ] ;
91+ const list = registry as RegistryItem [ ] ;
92+
93+ const fromId =
94+ selectedDbId && selectedDbId !== "any"
95+ ? list . filter ( ( r ) => r . id === selectedDbId )
96+ : [ ] ;
97+
98+ const fromKeyword = keywordInput
99+ ? list . filter ( ( r ) => matchesKeyword ( r , keywordInput ) )
100+ : [ ] ;
101+
102+ // merge the db results of selectedDB and keywordInput --> de duplicates
103+ const map = new Map < string , RegistryItem > ( ) ;
104+ [ ...fromId , ...fromKeyword ] . forEach ( ( r ) => map . set ( r . id , r ) ) ;
105+ return Array . from ( map . values ( ) ) ; // return matched registry
106+ } , [ registry , selectedDbId , keywordInput ] ) ;
87107
88108 // to show the applied chips on the top of results
89109 const activeFilters = Object . entries ( appliedFilters ) . filter (
@@ -328,7 +348,8 @@ const SearchPage: React.FC = () => {
328348 ) ;
329349
330350 // check if has database/dataset matches
331- const hasDbMatches = ! ! keywordInput && registryMatches . length > 0 ;
351+ // const hasDbMatches = !!keywordInput && registryMatches.length > 0;
352+ const hasDbMatches = registryMatches . length > 0 ;
332353 const hasDatasetMatches = Array . isArray ( results ) && results . length > 0 ;
333354 // when backend find nothing
334355 const backendEmpty =
@@ -522,7 +543,8 @@ const SearchPage: React.FC = () => {
522543 } }
523544 >
524545 { /* matching databases */ }
525- { keywordInput && registryMatches . length > 0 && (
546+ { /* {keywordInput && registryMatches.length > 0 && ( */ }
547+ { registryMatches . length > 0 && (
526548 < Box
527549 sx = { {
528550 mb : 3 ,
@@ -543,8 +565,8 @@ const SearchPage: React.FC = () => {
543565 { registryMatches . map ( ( db ) => (
544566 < DatabaseCard
545567 key = { db . id }
546- dbName = { db . name }
547- fullName = { db . fullname }
568+ dbId = { db . id }
569+ fullName = { db . fullname ?? db . name }
548570 datasets = { db . datasets }
549571 modalities = { db . datatype }
550572 logo = { db . logo }
0 commit comments