Skip to content

Commit

Permalink
chore: refactoring ops utils file (#1590)
Browse files Browse the repository at this point in the history
Co-authored-by: Gitanjli Chopra <[email protected]>
  • Loading branch information
gitanjli525 and Gitanjli Chopra authored Dec 4, 2024
1 parent fcae9bb commit fa199af
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 98 deletions.
2 changes: 1 addition & 1 deletion src/screens/Disputes/Disputes.res
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ let make = () => {
initialFixedFilter
setOffset
customLeftView={<SearchBarFilter
placeholder="Search disptue id" setSearchVal=setSearchText searchVal=searchText
placeholder="Search for any disptue id" setSearchVal=setSearchText searchVal=searchText
/>}
entityName=DISPUTE_FILTERS
title="Disputes"
Expand Down
36 changes: 19 additions & 17 deletions src/screens/Disputes/DisputesUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ let initialFixedFilter = () => [
),
]

let getLabelFromFilterType = (filter: filter) => (filter :> string)

let getValueFromFilterType = (filter: filter) => {
switch filter {
| #connector_label => "merchant_connector_id"
| _ => (filter :> string)
}
}

let getConditionalFilter = (key, dict, filterValues) => {
switch key->getFilterTypeFromString {
| #connector_label =>
Expand Down Expand Up @@ -185,25 +194,23 @@ let itemToObjMapper = dict => {
}

let initialFilters = (json, filtervalues, _, _, _) => {
let connectorFilter = filtervalues->getArrayFromDict("connector", [])->getStrArrayFromJsonArray

let filterDict = json->getDictFromJsonObject
let arr = filterDict->Dict.keysToArray->Array.filter(item => item != "currency")
let filtersArray = filterDict->Dict.keysToArray->Array.filter(item => item != "currency")

let connectorFilter = filtervalues->getArrayFromDict("connector", [])->getStrArrayFromJsonArray
if connectorFilter->Array.length !== 0 {
arr->Array.push("connector_label")
filtersArray->Array.push(#connector_label->getLabelFromFilterType)
}
let filterData = filterDict->itemToObjMapper

let filterArr = filterDict->itemToObjMapper

arr->Array.map((key): EntityType.initialFilters<'t> => {
filtersArray->Array.map((key): EntityType.initialFilters<'t> => {
let title = `Select ${key->snakeToTitle}`

let values = switch key->getFilterTypeFromString {
| #connector => filterArr.connector
| #currency => filterArr.currency
| #dispute_status => filterArr.dispute_status
| #dispute_stage => filterArr.dispute_stage
| #connector => filterData.connector
| #currency => filterData.currency
| #dispute_status => filterData.dispute_status
| #dispute_stage => filterData.dispute_stage
| #connector_label => getConditionalFilter(key, filterDict, filtervalues)
| _ => []
}
Expand All @@ -213,15 +220,10 @@ let initialFilters = (json, filtervalues, _, _, _) => {
| _ => values->FilterSelectBox.makeOptions
}

let name = switch key->getFilterTypeFromString {
| #connector_label => "merchant_connector_id"
| _ => key
}

{
field: FormRenderer.makeFieldInfo(
~label=key,
~name,
~name=getValueFromFilterType(key->getFilterTypeFromString),
~customInput=InputFields.filterMultiSelectInput(
~options,
~buttonText=title,
Expand Down
12 changes: 10 additions & 2 deletions src/screens/HSwitchRemoteFilter.res
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,16 @@ module RemoteTableFilters = {

let getURL = useGetURL()
let {userInfo: transactionEntity} = React.useContext(UserInfoProvider.defaultContext)
let {removeKeys, filterKeys, setfilterKeys} = React.useContext(FilterContext.filterContext)
let {filterValue, updateExistingKeys, filterValueJson, reset} =

let {
filterValue,
updateExistingKeys,
filterValueJson,
reset,
setfilterKeys,
filterKeys,
removeKeys,
} =
FilterContext.filterContext->React.useContext
let defaultFilters = {""->JSON.Encode.string}
let showToast = ToastState.useShowToast()
Expand Down
2 changes: 1 addition & 1 deletion src/screens/OMPSwitch/OrgSwitch.res
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let make = () => {
let customScrollStyle = "bg-blue-840 max-h-72 overflow-scroll px-1 pt-1"
let dropdownContainerStyle = "min-w-[15rem] rounded"

<div className="w-full py-5 px-2 p-[1px]">
<div className="w-full py-3.5 px-2">
<SelectBox.BaseDropdown
allowMultiSelect=false
buttonText=""
Expand Down
108 changes: 61 additions & 47 deletions src/screens/Order/OrderUIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -192,34 +192,42 @@ let filterByData = (txnArr, value) => {
})
}

let getLabelFromFilterType = (filter: filter) => (filter :> string)

let getValueFromFilterType = (filter: filter) => {
switch filter {
| #connector_label => "merchant_connector_id"
| _ => (filter :> string)
}
}

let getConditionalFilter = (key, dict, filterValues) => {
open LogicUtils

let filtersArr = switch key->getFilterTypeFromString {
| #connector_label => {
let arr = filterValues->getArrayFromDict("connector", [])->getStrArrayFromJsonArray
let newArr = arr->Array.flatMap(connector => {
let connectorLabelArr = dict->getDictfromDict("connector")->getArrayFromDict(connector, [])
connectorLabelArr->Array.map(item => {
item->getDictFromJsonObject->getString("connector_label", "")
})
})
newArr
}
| #payment_method_type => {
let arr = filterValues->getArrayFromDict("payment_method", [])->getStrArrayFromJsonArray
let newArr = arr->Array.flatMap(paymentMethod => {
let paymentMethodTypeArr =
dict
->getDictfromDict("payment_method")
->getArrayFromDict(paymentMethod, [])
->getStrArrayFromJsonArray
paymentMethodTypeArr->Array.map(item => {
item
})
| #connector_label =>
filterValues
->getArrayFromDict("connector", [])
->getStrArrayFromJsonArray
->Array.flatMap(connector => {
dict
->getDictfromDict("connector")
->getArrayFromDict(connector, [])
->Array.map(item => {
item->getDictFromJsonObject->getString("connector_label", "")
})
newArr
}
})
| #payment_method_type =>
filterValues
->getArrayFromDict("payment_method", [])
->getStrArrayFromJsonArray
->Array.flatMap(paymentMethod => {
dict
->getDictfromDict("payment_method")
->getArrayFromDict(paymentMethod, [])
->getStrArrayFromJsonArray
->Array.map(item => item)
})
| _ => []
}

Expand All @@ -228,8 +236,10 @@ let getConditionalFilter = (key, dict, filterValues) => {

let getOptionsForOrderFilters = (dict, filterValues) => {
open LogicUtils
let arr = filterValues->getArrayFromDict("connector", [])->getStrArrayFromJsonArray
let newArr = arr->Array.flatMap(connector => {
filterValues
->getArrayFromDict("connector", [])
->getStrArrayFromJsonArray
->Array.flatMap(connector => {
let connectorLabelArr = dict->getDictfromDict("connector")->getArrayFromDict(connector, [])
connectorLabelArr->Array.map(item => {
let label = item->getDictFromJsonObject->getString("connector_label", "")
Expand All @@ -241,7 +251,6 @@ let getOptionsForOrderFilters = (dict, filterValues) => {
option
})
})
newArr
}

let getAllPaymentMethodType = dict => {
Expand Down Expand Up @@ -281,35 +290,39 @@ let itemToObjMapper = dict => {
let initialFilters = (json, filtervalues, removeKeys, filterKeys, setfilterKeys) => {
open LogicUtils

let connectorFilter = filtervalues->getArrayFromDict("connector", [])->getStrArrayFromJsonArray
let filterDict = json->getDictFromJsonObject

let filterArr = filterDict->itemToObjMapper
let arr = filterDict->Dict.keysToArray
let filterData = filterDict->itemToObjMapper
let filtersArray = filterDict->Dict.keysToArray
let onDeleteClick = name => {
[name]->removeKeys
setfilterKeys(_ => filterKeys->Array.filter(item => item !== name))
}

let connectorFilter = filtervalues->getArrayFromDict("connector", [])->getStrArrayFromJsonArray
if connectorFilter->Array.length !== 0 {
arr->Array.push("connector_label")
filtersArray->Array.push(#connector_label->getLabelFromFilterType)
}
arr->Array.push("payment_method_type")
arr->Array.push("customer_id")
arr->Array.push("amount")
arr->Array.map((key): EntityType.initialFilters<'t> => {

let additionalFilters =
[#payment_method_type, #customer_id, #amount]->Array.map(getLabelFromFilterType)

let allFiltersArray = filtersArray->Array.concat(additionalFilters)

allFiltersArray->Array.map((key): EntityType.initialFilters<'t> => {
let values = switch key->getFilterTypeFromString {
| #connector => filterArr.connector
| #payment_method => filterArr.payment_method
| #currency => filterArr.currency
| #authentication_type => filterArr.authentication_type
| #status => filterArr.status
| #connector => filterData.connector
| #payment_method => filterData.payment_method
| #currency => filterData.currency
| #authentication_type => filterData.authentication_type
| #status => filterData.status
| #payment_method_type =>
getConditionalFilter(key, filterDict, filtervalues)->Array.length > 0
? getConditionalFilter(key, filterDict, filtervalues)
: filterArr.payment_method_type
: filterData.payment_method_type
| #connector_label => getConditionalFilter(key, filterDict, filtervalues)
| #card_network => filterArr.card_network
| #customer_id => filterArr.customer_id
| #card_network => filterData.card_network
| #customer_id => filterData.customer_id
| _ => []
}

Expand Down Expand Up @@ -340,10 +353,6 @@ let initialFilters = (json, filtervalues, removeKeys, filterKeys, setfilterKeys)
| _ => values->makeOptions
}

let name = switch key->getFilterTypeFromString {
| #connector_label => "merchant_connector_id"
| _ => key
}
let customInput = switch key->getFilterTypeFromString {
| #customer_id =>
(~input: ReactFinalForm.fieldRenderPropsInput, ~placeholder as _) =>
Expand Down Expand Up @@ -372,7 +381,11 @@ let initialFilters = (json, filtervalues, removeKeys, filterKeys, setfilterKeys)
)
}
{
field: FormRenderer.makeFieldInfo(~label=key, ~name, ~customInput),
field: FormRenderer.makeFieldInfo(
~label=key,
~name=getValueFromFilterType(key->getFilterTypeFromString),
~customInput,
),
localFilter: Some(filterByData),
}
})
Expand Down Expand Up @@ -539,6 +552,7 @@ let orderViewList: OMPSwitchTypes.ompViews = [
let deleteNestedKeys = (dict: Dict.t<'a>, keys: array<string>) => {
keys->Array.forEach(key => dict->Dict.delete(key))
}

let validateForm = values => {
open LogicUtils
let errors = Dict.make()
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Order/Orders.res
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ let make = (~previewOnly=false) => {
setOffset
submitInputOnEnter=true
customLeftView={<SearchBarFilter
placeholder="Search payment id" setSearchVal=setSearchText searchVal=searchText
placeholder="Search for any payment id" setSearchVal=setSearchText searchVal=searchText
/>}
entityName=ORDER_FILTERS
/>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Refunds/Refund.res
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ let make = () => {
initialFixedFilter
setOffset
customLeftView={<SearchBarFilter
placeholder="Search payment id or refund id"
placeholder="Search for any payment id or refund id"
setSearchVal=setSearchText
searchVal=searchText
/>}
Expand Down
Loading

0 comments on commit fa199af

Please sign in to comment.