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 31652f23e..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")) || []
);
@@ -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);
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 b4fd01d22..48b313506 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";
@@ -13,15 +13,19 @@ 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" : ""}`
);
}
};
-
- return [openListItem];
}
export default useListOption;