From 36831b0623a88cc9757fd365c99b6ed05990dca9 Mon Sep 17 00:00:00 2001 From: Riya Sinha Date: Sat, 23 Mar 2024 16:10:43 -0700 Subject: [PATCH 1/3] fix: fix search in genetics dev --- .../GlobalSearch/GlobalSearchList.jsx | 39 ++++++++++--------- .../components/GlobalSearch/SearchContext.tsx | 2 +- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/ui/src/components/GlobalSearch/GlobalSearchList.jsx b/packages/ui/src/components/GlobalSearch/GlobalSearchList.jsx index 31652f23e..921cb9af7 100644 --- a/packages/ui/src/components/GlobalSearch/GlobalSearchList.jsx +++ b/packages/ui/src/components/GlobalSearch/GlobalSearchList.jsx @@ -128,25 +128,26 @@ function GlobalSearchList({ inputValue }) { setRecentItems(JSON.parse(localStorage.getItem("search-history")) || []); } - const SearchSuggestionEl = ( - - - - {searchSuggestions.map(item => ( - - ))} - - - ); + const SearchSuggestionEl = + searchSuggestions.length > 0 ? ( + + + + {searchSuggestions.map(item => ( + + ))} + + + ) : null; useEffect(() => { focusOnItem(); diff --git a/packages/ui/src/components/GlobalSearch/SearchContext.tsx b/packages/ui/src/components/GlobalSearch/SearchContext.tsx index d0534adf2..35e0fcc99 100644 --- a/packages/ui/src/components/GlobalSearch/SearchContext.tsx +++ b/packages/ui/src/components/GlobalSearch/SearchContext.tsx @@ -30,7 +30,7 @@ export function SearchProvider({ children, searchQuery, searchPlaceholder = "Search...", - searchSuggestions, + searchSuggestions = [], }: GlobalSearchProviderProps) { const [open, setOpen] = useState(false); From 5d2b033e0c58dcbd1fd0d53ee5d7ae5c1e5866ed Mon Sep 17 00:00:00 2001 From: Riya Sinha Date: Sat, 23 Mar 2024 19:05:59 -0700 Subject: [PATCH 2/3] refactor: useListOption doesn't need to return function in list --- .../src/components/GlobalSearch/GlobalSearchFreeListItem.jsx | 2 +- packages/ui/src/components/GlobalSearch/GlobalSearchList.jsx | 2 +- packages/ui/src/hooks/useListOption.js | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/components/GlobalSearch/GlobalSearchFreeListItem.jsx b/packages/ui/src/components/GlobalSearch/GlobalSearchFreeListItem.jsx index 519ca4162..6d6889a6b 100644 --- a/packages/ui/src/components/GlobalSearch/GlobalSearchFreeListItem.jsx +++ b/packages/ui/src/components/GlobalSearch/GlobalSearchFreeListItem.jsx @@ -35,7 +35,7 @@ function GlobalSearchFreeListItem() { const { inputValue } = useContext(SearchInputContext); const { setOpen } = useContext(SearchContext); - const [openListItem] = useListOption(); + const openListItem = useListOption(); const freeSearchTermObject = { symbol: `Search for: ${inputValue}`, diff --git a/packages/ui/src/components/GlobalSearch/GlobalSearchList.jsx b/packages/ui/src/components/GlobalSearch/GlobalSearchList.jsx index 921cb9af7..b11488d52 100644 --- a/packages/ui/src/components/GlobalSearch/GlobalSearchList.jsx +++ b/packages/ui/src/components/GlobalSearch/GlobalSearchList.jsx @@ -25,7 +25,7 @@ function GlobalSearchList({ inputValue }) { const [loading, setLoading] = useState(false); const { searchQuery, setOpen, searchSuggestions } = useContext(SearchContext); const [getSearchData] = useLazyQuery(searchQuery); - const [openListItem] = useListOption(); + const openListItem = useListOption(); const [recentItems, setRecentItems] = useState( JSON.parse(localStorage.getItem("search-history")) || [] ); diff --git a/packages/ui/src/hooks/useListOption.js b/packages/ui/src/hooks/useListOption.js index b4fd01d22..8c52f9abb 100644 --- a/packages/ui/src/hooks/useListOption.js +++ b/packages/ui/src/hooks/useListOption.js @@ -4,7 +4,7 @@ import { addSearchToLocalStorage } from "../components/GlobalSearch/utils/search function useListOption() { const history = useHistory(); - const openListItem = option => { + return option => { if (!option) return; const newOption = { ...option }; newOption.type = "recent"; @@ -20,8 +20,6 @@ function useListOption() { ); } }; - - return [openListItem]; } export default useListOption; From b3687662f1554e7eb874e21eea496e06fe8f3bb2 Mon Sep 17 00:00:00 2001 From: Riya Sinha Date: Sat, 23 Mar 2024 20:14:53 -0700 Subject: [PATCH 3/3] fix: fix searching by using proper entity names in search for Genetics --- .../ui/src/components/GlobalSearch/utils/searchUtils.js | 7 ++++--- packages/ui/src/hooks/useListOption.js | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/ui/src/components/GlobalSearch/utils/searchUtils.js b/packages/ui/src/components/GlobalSearch/utils/searchUtils.js index 93edbba59..c50657e78 100644 --- a/packages/ui/src/components/GlobalSearch/utils/searchUtils.js +++ b/packages/ui/src/components/GlobalSearch/utils/searchUtils.js @@ -53,14 +53,16 @@ export const formatSearchData = unformattedData => { Object.entries(unformattedData).forEach(([key, value]) => { const typesArray = []; + // OpenTargets Genetics search format if (isArray(value)) { value.map(i => typesArray.push({ - type: key === "topHit" ? "topHit" : key, - entity: key, + type: key === "topHit" ? "topHit" : i.__typename.toLowerCase(), + entity: i.__typename.toLowerCase(), ...flattenObj(i), }) ); + // OpenTargets Platform search format } else if (isArray(value.hits)) { value.hits.map(i => typesArray.push({ @@ -72,7 +74,6 @@ export const formatSearchData = unformattedData => { } if (typesArray.length > 0) formattedData[key] = typesArray; }); - return formattedData; }; diff --git a/packages/ui/src/hooks/useListOption.js b/packages/ui/src/hooks/useListOption.js index 8c52f9abb..48b313506 100644 --- a/packages/ui/src/hooks/useListOption.js +++ b/packages/ui/src/hooks/useListOption.js @@ -13,7 +13,13 @@ function useListOption() { if (newOption.entity === "search") { history.push(`/search?q=${newOption.name}&page=1`); } else if (newOption.entity === "study") { - history.push(`/${newOption.entity}/${newOption.studyId}`); + if (newOption.studyId) { + history.push(`/${newOption.entity}/${newOption.studyId}`); + } else { + history.push(`/${newOption.entity}/${newOption.id}`); + } + } else if (["gene", "variant"].includes(newOption.entity)) { + history.push(`/${newOption.entity}/${newOption.id}`); } else { history.push( `/${newOption.entity}/${newOption.id}${newOption.entity !== "drug" ? "/associations" : ""}`