Skip to content

Commit

Permalink
feat: global search categories suggestions (#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarnaikjuspay authored Nov 25, 2024
1 parent a8ce191 commit 735c74a
Show file tree
Hide file tree
Showing 11 changed files with 969 additions and 400 deletions.
351 changes: 97 additions & 254 deletions src/screens/Analytics/GlobalSearch/GlobalSearchBar.res

Large diffs are not rendered by default.

474 changes: 474 additions & 0 deletions src/screens/Analytics/GlobalSearch/GlobalSearchBarHelper.res

Large diffs are not rendered by default.

376 changes: 297 additions & 79 deletions src/screens/Analytics/GlobalSearch/GlobalSearchBarUtils.res

Large diffs are not rendered by default.

58 changes: 47 additions & 11 deletions src/screens/Analytics/GlobalSearch/GlobalSearchTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ type section =
| PaymentIntents
| PaymentAttempts
| Refunds
| Disputes
| SessionizerPaymentAttempts
| SessionizerPaymentIntents
| SessionizerPaymentRefunds
| SessionizerPaymentDisputes
| Disputes
| Others
| Default

Expand All @@ -25,16 +25,12 @@ type resultType = {
let getSectionHeader = section => {
switch section {
| Local => "Go To"
| PaymentIntents => "Payment Intents"
| PaymentAttempts => "Payment Attempts"
| Refunds => "Refunds"
| PaymentIntents | SessionizerPaymentIntents => "Payment Intents"
| PaymentAttempts | SessionizerPaymentAttempts => "Payment Attempts"
| Refunds | SessionizerPaymentRefunds => "Refunds"
| Disputes | SessionizerPaymentDisputes => "Disputes"
| Others => "Others"
| Disputes => "Disputes"
| Default
| SessionizerPaymentAttempts
| SessionizerPaymentIntents
| SessionizerPaymentRefunds
| SessionizerPaymentDisputes => ""
| Default => ""
}
}

Expand All @@ -52,6 +48,20 @@ let getSectionVariant = string => {
}
}

let getSectionIndex = string => {
switch string {
| PaymentAttempts => "payment_attempts"
| PaymentIntents => "payment_intents"
| Refunds => "refunds"
| Disputes => "disputes"
| SessionizerPaymentAttempts => "sessionizer_payment_attempts"
| SessionizerPaymentIntents => "sessionizer_payment_intents"
| SessionizerPaymentRefunds => "sessionizer_refunds"
| SessionizerPaymentDisputes => "sessionizer_disputes"
| _ => ""
}
}

type remoteResult = {
count: int,
hits: array<JSON.t>,
Expand All @@ -64,4 +74,30 @@ type defaultResult = {
searchText: string,
}

type state = Loading | Loaded | Failed | Idle
type state = Loading | Loaded | Idle

type category =
| Payment_Method
| Payment_Method_Type
| Connector
| Customer_Email
| Card_Network
| Last_4
| Date
| Currency
| Authentication_type
| Status
| Client_source
| Client_version

type categoryOption = {
categoryType: category,
options: array<string>,
placeholder: string,
}

type viewType =
| Load
| Results
| FiltersSugsestions
| EmptyResult
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ let make = () => {
let setPageDetails = Recoil.useSetRecoilState(LoadedTable.table_pageDetails)
let (offset, setOffset) = React.useState(_ => pageDetail.offset)
let searchText = UrlUtils.useGetFilterDictFromUrl("")->LogicUtils.getString("query", "")
let path = UrlUtils.useGetFilterDictFromUrl("")->LogicUtils.getString("domain", "")

let clearPageDetails = () => {
let newDict = pageDetailDict->Dict.toArray->Dict.fromArray
Expand All @@ -70,12 +71,7 @@ let make = () => {
setScreenState(_ => PageLoaderWrapper.Loading)

try {
let (data, total) = await fetchTableData(
~updateDetails,
~offset,
~query={searchText},
~path=domain,
)
let (data, total) = await fetchTableData(~updateDetails, ~offset, ~query={searchText}, ~path)

let arr = Array.make(~length=offset, Dict.make())
if total <= offset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ let make = () => {
let pageDetail = pageDetailDict->Dict.get(domain)->Option.getOr(defaultValue)
let (offset, setOffset) = React.useState(_ => pageDetail.offset)
let searchText = UrlUtils.useGetFilterDictFromUrl("")->LogicUtils.getString("query", "")
let path = UrlUtils.useGetFilterDictFromUrl("")->LogicUtils.getString("domain", "")

let clearPageDetails = () => {
let newDict = pageDetailDict->Dict.toArray->Dict.fromArray
Expand All @@ -70,12 +71,7 @@ let make = () => {
setScreenState(_ => PageLoaderWrapper.Loading)

try {
let (data, total) = await fetchTableData(
~updateDetails,
~offset,
~query={searchText},
~path=domain,
)
let (data, total) = await fetchTableData(~updateDetails, ~offset, ~query={searchText}, ~path)

let arr = Array.make(~length=offset, Dict.make())
if total <= offset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ let make = () => {
let pageDetail = pageDetailDict->Dict.get(domain)->Option.getOr(defaultValue)
let (offset, setOffset) = React.useState(_ => pageDetail.offset)
let searchText = UrlUtils.useGetFilterDictFromUrl("")->LogicUtils.getString("query", "")
let path = UrlUtils.useGetFilterDictFromUrl("")->LogicUtils.getString("domain", "")

let clearPageDetails = () => {
let newDict = pageDetailDict->Dict.toArray->Dict.fromArray
Expand All @@ -70,12 +71,7 @@ let make = () => {
setScreenState(_ => PageLoaderWrapper.Loading)

try {
let (data, total) = await fetchTableData(
~updateDetails,
~offset,
~query={searchText},
~path=domain,
)
let (data, total) = await fetchTableData(~updateDetails, ~offset, ~query={searchText}, ~path)

let arr = Array.make(~length=offset, Dict.make())
if total <= offset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ let make = () => {
let setPageDetails = Recoil.useSetRecoilState(LoadedTable.table_pageDetails)
let (offset, setOffset) = React.useState(_ => pageDetail.offset)
let searchText = UrlUtils.useGetFilterDictFromUrl("")->LogicUtils.getString("query", "")
let path = UrlUtils.useGetFilterDictFromUrl("")->LogicUtils.getString("domain", "")

let clearPageDetails = () => {
let newDict = pageDetailDict->Dict.toArray->Dict.fromArray
Expand All @@ -70,12 +71,7 @@ let make = () => {
setScreenState(_ => PageLoaderWrapper.Loading)

try {
let (data, total) = await fetchTableData(
~updateDetails,
~offset,
~query={searchText},
~path=domain,
)
let (data, total) = await fetchTableData(~updateDetails, ~offset, ~query={searchText}, ~path)

let arr = Array.make(~length=offset, Dict.make())
if total <= offset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ let tableBorderClass = "border-collapse border border-jp-gray-940 border-solid b

let useGetData = () => {
open LogicUtils
let body = Dict.make()
let {userInfo: {merchantId}} = React.useContext(UserInfoProvider.defaultContext)
let getURL = APIUtils.useGetURL()
async (
~updateDetails: (
Expand All @@ -18,17 +16,9 @@ let useGetData = () => {
~query,
~path,
) => {
let body = query->GlobalSearchBarUtils.generateQuery
body->Dict.set("offset", offset->Int.toFloat->JSON.Encode.float)
body->Dict.set("count", 10->Int.toFloat->JSON.Encode.float)
body->Dict.set("query", query->JSON.Encode.string)

if !(query->CommonAuthUtils.isValidEmail) {
let filters = [("customer_email", [query->JSON.Encode.string]->JSON.Encode.array)]
body->Dict.set("filters", filters->getJsonFromArrayOfJson)
body->Dict.set("query", merchantId->JSON.Encode.string)
} else {
body->Dict.set("query", query->JSON.Encode.string)
}

try {
let url = getURL(~entityName=GLOBAL_SEARCH, ~methodType=Post, ~id=Some(path))
Expand Down
30 changes: 14 additions & 16 deletions src/screens/Analytics/GlobalSearchResults/SearchResultsPage.res
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ module RenderSearchResultBody = {
</div>
})
->React.array
| PaymentIntents => <PaymentIntentTable.PreviewTable data={section.results} />
| PaymentAttempts => <PaymentAttemptTable.PreviewTable data={section.results} />
| Refunds => <RefundsTable.PreviewTable data={section.results} />
| Disputes => <DisputeTable.PreviewTable data={section.results} />
| PaymentIntents | SessionizerPaymentIntents =>
<PaymentIntentTable.PreviewTable data={section.results} />
| PaymentAttempts | SessionizerPaymentAttempts =>
<PaymentAttemptTable.PreviewTable data={section.results} />
| Refunds | SessionizerPaymentRefunds => <RefundsTable.PreviewTable data={section.results} />
| Disputes | SessionizerPaymentDisputes => <DisputeTable.PreviewTable data={section.results} />
| Others | Default => "Not implemented"->React.string
| SessionizerPaymentAttempts
| SessionizerPaymentIntents
| SessionizerPaymentRefunds
| SessionizerPaymentDisputes =>
""->React.string
}
}
}
Expand All @@ -66,7 +63,7 @@ module SearchResultsComponent = {
<div className="text-lightgray_background font-bold text-lg pb-2">
{section.section->getSectionHeader->React.string}
</div>
<GlobalSearchBarUtils.ShowMoreLink
<GlobalSearchBarHelper.ShowMoreLink
section textStyleClass="text-sm pt-2 font-medium text-blue-900" searchText
/>
</div>
Expand Down Expand Up @@ -97,14 +94,15 @@ let make = () => {
let query = UrlUtils.useGetFilterDictFromUrl("")->getString("query", "")
let {globalSearch} = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom
let {userHasAccess} = GroupACLHooks.useUserGroupACLHook()
let {userInfo: {merchantId}} = React.useContext(UserInfoProvider.defaultContext)
let isShowRemoteResults = globalSearch && userHasAccess(~groupAccess=OperationsView) === Access
let fallBackQuery = UrlUtils.useGetFilterDictFromUrl("")->LogicUtils.getString("query", "")

let getSearchResults = async results => {
try {
let url = getURL(~entityName=GLOBAL_SEARCH, ~methodType=Post)
let body = generateSearchBody(~searchText={query}, ~merchant_id={merchantId})
let response = await fetchDetails(url, body, Post)
let query = searchText->isNonEmptyString ? searchText : fallBackQuery
let body = query->generateQuery
let response = await fetchDetails(url, body->JSON.Encode.object, Post)

let local_results = []
results->Array.forEach((item: resultType) => {
Expand All @@ -129,7 +127,7 @@ let make = () => {

setState(_ => Loaded)
} catch {
| _ => setState(_ => Failed)
| _ => setState(_ => Loaded)
}
}

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

None
}, (query, url.search))
}, [query, url.search])

<div>
<PageUtils.PageHeading title="Search results" />
Expand All @@ -176,7 +174,7 @@ let make = () => {
</div>
| _ =>
if searchResults->Array.length === 0 {
<GlobalSearchBar.EmptyResult prefix searchText />
<GlobalSearchBarHelper.EmptyResult prefix searchText />
} else {
<SearchResultsComponent searchResults searchText={query} />
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ let getSearchresults = (result: GlobalSearchTypes.defaultResult) => {
})
}

let data = Dict.make()

result.remote_results->Array.forEach(value => {
let remoteResults = value.hits->Array.map(item => {
{
Expand All @@ -19,13 +21,37 @@ let getSearchresults = (result: GlobalSearchTypes.defaultResult) => {
})

if remoteResults->Array.length > 0 {
results->Array.push({
section: value.index->getSectionVariant,
results: remoteResults,
total_results: value.count,
})
data->Dict.set(
value.index,
{
section: value.index->getSectionVariant,
results: remoteResults,
total_results: value.count,
},
)
}
})

open GlobalSearchBarUtils
// intents
let key1 = PaymentIntents->getSectionIndex
let key2 = SessionizerPaymentIntents->getSectionIndex
getItemFromArray(results, key1, key2, data)

// Attempts
let key1 = PaymentAttempts->getSectionIndex
let key2 = SessionizerPaymentAttempts->getSectionIndex
getItemFromArray(results, key1, key2, data)

// Refunds
let key1 = Refunds->getSectionIndex
let key2 = SessionizerPaymentRefunds->getSectionIndex
getItemFromArray(results, key1, key2, data)

// Disputes
let key1 = Disputes->getSectionIndex
let key2 = SessionizerPaymentDisputes->getSectionIndex
getItemFromArray(results, key1, key2, data)

(results, result.searchText)
}

0 comments on commit 735c74a

Please sign in to comment.