diff --git a/src/screens/Analytics/GlobalSearch/GlobalSearchBar.res b/src/screens/Analytics/GlobalSearch/GlobalSearchBar.res index 8c54299eb..5d6370621 100644 --- a/src/screens/Analytics/GlobalSearch/GlobalSearchBar.res +++ b/src/screens/Analytics/GlobalSearch/GlobalSearchBar.res @@ -125,6 +125,22 @@ module SearchResultsComponent = { open UIUtils @react.component let make = (~searchResults, ~searchText, ~redirectOnSelect, ~setShowModal) => { + React.useEffect0(() => { + let onKeyPress = event => { + let keyPressed = event->ReactEvent.Keyboard.key + + if keyPressed == "Enter" { + let redirectLink = `/search?query=${searchText}` + if redirectLink->isNonEmptyString { + setShowModal(_ => false) + GlobalVars.appendDashboardPath(~url=redirectLink)->RescriptReactRouter.push + } + } + } + Window.addEventListener("keydown", onKeyPress) + Some(() => Window.removeEventListener("keydown", onKeyPress)) + }) + {searchResults ->Array.mapWithIndex((section: resultType, index) => { @@ -216,7 +232,14 @@ let make = () => { let getSearchResults = async results => { try { let url = getURL(~entityName=GLOBAL_SEARCH, ~methodType=Post, ()) - let body = [("query", searchText->JSON.Encode.string)]->LogicUtils.getJsonFromArrayOfJson + + let body = if !(searchText->CommonAuthUtils.isValidEmail) { + let filters = [("email", searchText->JSON.Encode.string)]->LogicUtils.getJsonFromArrayOfJson + [("query", ""->JSON.Encode.string), ("filters", filters)]->LogicUtils.getJsonFromArrayOfJson + } else { + [("query", searchText->JSON.Encode.string)]->LogicUtils.getJsonFromArrayOfJson + } + let response = await fetchDetails(url, body, Post, ()) let local_results = []