Skip to content

Commit

Permalink
feat: global search filters ux enhancements (#1977)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarnaikjuspay authored Dec 27, 2024
1 parent 356e3a8 commit cde0b70
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 150 deletions.
57 changes: 39 additions & 18 deletions src/screens/Analytics/GlobalSearch/GlobalSearchBar.res
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ let make = () => {
let {userHasAccess} = GroupACLHooks.useUserGroupACLHook()
let isShowRemoteResults = globalSearch && userHasAccess(~groupAccess=OperationsView) === Access
let mixpanelEvent = MixpanelHook.useSendEvent()
let inputRef = React.useRef(Nullable.null)
let filtersEnabled = globalSearchFilters

let redirectOnSelect = element => {
Expand Down Expand Up @@ -111,7 +112,11 @@ let make = () => {
React.useEffect(_ => {
let results = []

if searchText->isNonEmptyString && searchText->getSearchValidation {
if (
searchText->isNonEmptyString &&
searchText->getSearchValidation &&
!(searchText->validateQuery)
) {
setState(_ => Loading)
let localResults: resultType = searchText->getLocalMatchedResults(hswitchTabs)

Expand Down Expand Up @@ -165,7 +170,7 @@ let make = () => {
}

React.useEffect(() => {
if userHasAccess(~groupAccess=AnalyticsView) === Access && filtersEnabled {
if userHasAccess(~groupAccess=AnalyticsView) === Access {
getCategoryOptions()->ignore
}

Expand All @@ -178,8 +183,7 @@ let make = () => {
}

let setGlobalSearchText = ReactDebounce.useDebounced(value => {
let text = filtersEnabled ? value : value->String.trim
setSearchText(_ => text)
setSearchText(_ => value)
}, ~wait=500)

let onFilterClicked = category => {
Expand All @@ -194,6 +198,8 @@ let make = () => {
setLocalSearchText(_ => `${searchText} ${newFilter}:`)
setFilterText(newFilter)
}

revertFocus(~inputRef)
}

let onSuggestionClicked = option => {
Expand All @@ -207,6 +213,8 @@ let make = () => {
let saparater = searchText->getEndChar == filterSeparator ? "" : filterSeparator
setLocalSearchText(_ => `${key}${saparater}${option}`)
setFilterText("")

revertFocus(~inputRef)
}

React.useEffect(() => {
Expand All @@ -227,14 +235,16 @@ let make = () => {
</div>
}

let viewType = getViewType(~state, ~searchResults, ~searchText, ~filtersEnabled)
let viewType = getViewType(~state, ~searchResults)
let categorySuggestions = {getCategorySuggestions(categorieSuggestionResponse)}

<div className="w-max">
<SearchBox openModalOnClickHandler />
<RenderIf condition={showModal}>
<ModalWrapper showModal setShowModal>
<div className="w-full">
<ModalSearchBox
inputRef
leftIcon
setShowModal
setFilterText
Expand All @@ -253,26 +263,37 @@ let make = () => {
onSuggestionClicked
/>
{switch viewType {
| Load =>
<div className="mb-24">
<Loader />
</div>
| Results =>
| Results | Load | EmptyResult =>
<SearchResultsComponent
searchResults searchText setShowModal selectedOption redirectOnSelect
/>
| FiltersSugsestions =>
<FilterResultsComponent
categorySuggestions={getCategorySuggestions(categorieSuggestionResponse)}
activeFilter
searchResults
searchText
setShowModal
selectedOption
redirectOnSelect
categorySuggestions
activeFilter
setAllFilters
selectedFilter
setSelectedFilter
onFilterClicked
onSuggestionClicked
setSelectedFilter
viewType
prefix
filtersEnabled
/>
| EmptyResult => <EmptyResult prefix searchText />
| FiltersSugsestions =>
<RenderIf condition={filtersEnabled}>
<FilterResultsComponent
categorySuggestions
activeFilter
searchText
setAllFilters
selectedFilter
onFilterClicked
onSuggestionClicked
setSelectedFilter
/>
</RenderIf>
}}
</div>
</ModalWrapper>
Expand Down
Loading

0 comments on commit cde0b70

Please sign in to comment.