Skip to content

Commit

Permalink
refactor: unused routing Types and utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jainlokesh318 committed Jan 15, 2024
1 parent 819b31f commit 719ed25
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 157 deletions.
155 changes: 0 additions & 155 deletions src/screens/HyperSwitch/Routing/RoutingUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -41,54 +41,6 @@ let routingTypeName = routingType => {
}
}

let itemGateWayObjMapper = (
dict,
_connectorList: option<array<ConnectorTypes.connectorPayload>>,
) => {
let connectorId = dict->getDictfromDict("connector")->getString("merchant_connector_id", "")
[
("distribution", dict->getFloat("split", 0.00)->Js.Json.number),
("disableFallback", dict->getBool("disableFallback", false)->Js.Json.boolean),
("gateway_name", connectorId->Js.Json.string),
]->Dict.fromArray
}

let itemBodyGateWayObjMapper = (
dict,
connectorList: option<array<ConnectorTypes.connectorPayload>>,
) => {
let merchantConnectorId =
dict->getDictfromDict("connector")->getString("merchant_connector_id", "")
let name =
connectorList
->Belt.Option.getWithDefault([Dict.make()->ConnectorTableUtils.getProcessorPayloadType])
->ConnectorTableUtils.getConnectorNameViaId(merchantConnectorId)
let newDict =
[
("connector", name.connector_name->Js.Json.string),
("merchant_connector_id", merchantConnectorId->Js.Json.string),
]
->Dict.fromArray
->Js.Json.object_
[("split", dict->getFloat("split", 0.00)->Js.Json.number), ("connector", newDict)]->Dict.fromArray
}

let connectorPayload = (routingType, arr) => {
switch routingType->routingTypeMapper {
| VOLUME_SPLIT => {
let connectorData = arr->Array.reduce([], (acc, routingObj) => {
let routingDict = routingObj->getDictFromJsonObject
acc->Array.push(getString(routingDict, "connector", ""))
acc
})
connectorData
}

| PRIORITY => arr->Js.Json.array->getStrArryFromJson
| _ => []
}
}

let getRoutingPayload = (data, routingType, name, description, profileId) => {
let connectorsOrder =
[("data", data->Js.Json.array), ("type", routingType->Js.Json.string)]->Dict.fromArray
Expand All @@ -101,89 +53,6 @@ let getRoutingPayload = (data, routingType, name, description, profileId) => {
]->Dict.fromArray
}

let getWasmKeyType = (wasm, value) => {
try {
switch wasm {
| Some(res) => res.getKeyType(value)
| None => ""
}
} catch {
| _ => ""
}
}

let getWasmVariantValues = (wasm, value) => {
try {
switch wasm {
| Some(res) => res.getVariantValues(value)
| None => []
}
} catch {
| _ => []
}
}

let getWasmGateway = wasm => {
try {
switch wasm {
| Some(res) => res.getAllConnectors()
| None => []
}
} catch {
| _ => []
}
}

let getVolumeSplit = (
dict_arr,
objMapper,
connectorList: option<array<ConnectorTypes.connectorPayload>>,
) => {
dict_arr->Array.reduce([], (acc, routingObj) => {
let value = [routingObj->getDictFromJsonObject->objMapper(connectorList)->Js.Json.object_]
acc->Array.concat(value)->Array.map(value => value)
})
}

let checkIfValuePresesent = valueRes => {
// to check if the value is present only then add to the statement
let conditionMatched = switch Js.Json.classify(valueRes) {
| JSONArray(arr) => arr->Array.length > 0
| JSONString(str) => str->String.length > 0
| JSONNumber(num) => num > Belt.Int.toFloat(0)
| _ => false
}
conditionMatched
}

let getDefaultSelection = dict => {
[
("data", dict->getArrayFromDict("default_gateways", [])->Js.Json.array),
("type", "priority"->Js.Json.string),
]->Dict.fromArray
}
let generateRuleObject = (index, connectorSelection, statement) => {
let ruleObj = Dict.fromArray([
("name", `rule_${string_of_int(index + 1)}`->Js.Json.string),
("statements", statement->Js.Json.array),
("connectorSelection", connectorSelection->Js.Json.object_),
])
ruleObj
}
let constuctAlgorithm = (dict, rules, metadata) => {
let body =
[
("defaultSelection", getDefaultSelection(dict)->Js.Json.object_),
("rules", rules->Js.Json.array),
("metadata", metadata->Js.Json.object_),
]->Dict.fromArray

let algorithm =
[("type", "advanced"->Js.Json.string), ("data", body->Js.Json.object_)]->Dict.fromArray

algorithm
}

let getModalObj = (routingType, text) => {
switch routingType {
| ADVANCED => {
Expand Down Expand Up @@ -299,12 +168,6 @@ let constructNameDescription = routingType => {
])
}

let manipulateInitialValueJson = initialValueJson => {
let manipulatedJson = ADVANCED->constructNameDescription
manipulatedJson->Dict.set("code", initialValueJson->getString("code", "")->Js.Json.string)
manipulatedJson->Dict.set("json", initialValueJson->getObj("json", Dict.make())->Js.Json.object_)
manipulatedJson
}
let currentTabNameRecoilAtom = Recoil.atom(. "currentTabName", "ActiveTab")

module SaveAndActivateButton = {
Expand Down Expand Up @@ -344,24 +207,6 @@ module SaveAndActivateButton = {
/>
}
}
module ConfigureRuleButton = {
@react.component
let make = (~setShowModal, ~isConfigButtonEnabled) => {
let formState: ReactFinalForm.formState = ReactFinalForm.useFormState(
ReactFinalForm.useFormSubscription(["values"])->Js.Nullable.return,
)

<Button
text={"Configure Rule"}
buttonType=Primary
buttonState={!formState.hasValidationErrors && isConfigButtonEnabled ? Normal : Disabled}
onClick={_ => {
setShowModal(_ => true)
}}
customButtonStyle="w-1/5"
/>
}
}

let validateNameAndDescription = (~dict, ~errors) => {
["name", "description"]->Array.forEach(field => {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Routing/VolumeSplitRouting.res
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module VolumeRoutingView = {
dropDownButtonText="Add Processors"
connectorList
/>
<ConfigureRuleButton setShowModal isConfigButtonEnabled />
<AdvancedRoutingUIUtils.ConfigureRuleButton setShowModal isConfigButtonEnabled />
<CustomModal.RoutingCustomModal
showModal
setShowModal
Expand Down
4 changes: 3 additions & 1 deletion src/screens/HyperSwitch/RoutingRevamp/AdvancedRouting.res
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,9 @@ let make = (~routingRuleId, ~isActive, ~setCurrentRouting) => {
</UIUtils.RenderIf>
</div>
| Create =>
<RoutingUtils.ConfigureRuleButton setShowModal isConfigButtonEnabled />
<AdvancedRoutingUIUtils.ConfigureRuleButton
setShowModal isConfigButtonEnabled
/>
| _ => React.null
}}
</div>
Expand Down
19 changes: 19 additions & 0 deletions src/screens/HyperSwitch/RoutingRevamp/AdvancedRoutingUIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,22 @@ let descriptionInput = makeFieldInfo(
),
(),
)

module ConfigureRuleButton = {
@react.component
let make = (~setShowModal, ~isConfigButtonEnabled) => {
let formState: ReactFinalForm.formState = ReactFinalForm.useFormState(
ReactFinalForm.useFormSubscription(["values"])->Js.Nullable.return,
)

<Button
text={"Configure Rule"}
buttonType=Primary
buttonState={!formState.hasValidationErrors && isConfigButtonEnabled ? Normal : Disabled}
onClick={_ => {
setShowModal(_ => true)
}}
customButtonStyle="w-1/5"
/>
}
}

0 comments on commit 719ed25

Please sign in to comment.