Skip to content

Commit

Permalink
more code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarnaikjuspay committed Dec 7, 2023
1 parent e96a1f5 commit 5743dde
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 28 deletions.
5 changes: 2 additions & 3 deletions src/components/DynamicSingleStat.res
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ let deltaTimeRangeMapper: array<Js.Json.t> => deltaRange = (arrJson: array<Js.Js
// till here
@react.component
let make = (
~index,
~entity: entityType<'colType, 't, 't2>,
~modeKey=?,
~filterKeys,
Expand All @@ -127,9 +126,9 @@ let make = (
~statThreshold=?,
~wrapperClass=?,
) => {
open FilterUtils
let {filterValueJson} = React.useContext(FilterContext.filterContext)
let fetchApi = AuthHooks.useApiFetcher()
let getAllFilter = useFiltersValue(~index)->parseUrlString
let getAllFilter = filterValueJson
let isMobileView = MatchMedia.useMobileChecker()
let (showStats, setShowStats) = React.useState(_ => false)

Expand Down
13 changes: 0 additions & 13 deletions src/components/FilterUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,6 @@ let parseUrl = url => {
->Js.Dict.fromArray
}

let parseUrlString = url => {
url
->Js.Global.decodeURI
->Js.String2.split("&")
->Belt.Array.keepMap(str => {
let arr = str->Js.String2.split("=")
let key = arr->Belt.Array.get(0)->Belt.Option.getWithDefault("-")
let val = arr->Belt.Array.sliceToEnd(1)->Js.Array2.joinWith("=")
key === "" || val === "" ? None : Some((key, val->Js.Json.string))
})
->Js.Dict.fromArray
}

let useUpdateFilterObject = (~index: string) => {
let filters = useFiltersValue(~index)
let setFilters = useAddFilters(~index)
Expand Down
14 changes: 6 additions & 8 deletions src/screens/HyperSwitch/Analytics/Analytics.res
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,8 @@ module TableWrapper = {
~distributionArray=None,
) => {
let customFilter = Recoil.useRecoilValueFromAtom(AnalyticsAtoms.customFilterAtom)
let {index} = React.useContext(FilterContext.filterContext)
open FilterUtils
let filterValueString = useFiltersValue(~index)
let filterValueDict = filterValueString->parseUrlString
let filterValueDict = filterValueDict
let {filterValueJson} = React.useContext(FilterContext.filterContext)
let filterValueDict = filterValueJson
let fetchDetails = APIUtils.useUpdateMethod()
let (_, setDefaultFilter) = Recoil.useRecoilState(AnalyticsHooks.defaultFilter)
let (showTable, setShowTable) = React.useState(_ => false)
Expand Down Expand Up @@ -529,7 +526,9 @@ let make = (
->LogicUtils.safeParse
->FeatureFlagUtils.featureFlagType
let analyticsType = moduleName->getAnalyticsType
let {index, filterValue, updateExistingKeys} = React.useContext(FilterContext.filterContext)
let {index, filterValue, updateExistingKeys, filterValueJson} = React.useContext(
FilterContext.filterContext,
)
let filterValueString = useFiltersValue(~index)
let (_totalVolume, setTotalVolume) = React.useState(_ => 0)
let defaultFilters = [startTimeFilterKey, endTimeFilterKey]
Expand All @@ -543,7 +542,7 @@ let make = (
| None => None
}

let filterValueDict = filterValueString->parseUrlString
let filterValueDict = filterValueJson
let getFilterData = AnalyticsHooks.useGetFiltersData(~index)

let (activeTav, setActiveTab) = React.useState(_ =>
Expand Down Expand Up @@ -721,7 +720,6 @@ let make = (
<div>
<div className="mt-5">
<DynamicSingleStat
index
entity=singleStatEntity
startTimeFilterKey
endTimeFilterKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ module SystemMetricsInsights = {
let dateDict = HSwitchRemoteFilter.getDateFilteredObject()

<DynamicSingleStat
index
entity={singleStatEntity}
startTimeFilterKey
endTimeFilterKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ let make = (~index) => {
let dateDict = HSwitchRemoteFilter.getDateFilteredObject()

<DynamicSingleStat
index
entity={singleStatEntity}
startTimeFilterKey
endTimeFilterKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ module ConnectorLatency = {
let dateDict = HSwitchRemoteFilter.getDateFilteredObject()

<DynamicSingleStat
index
entity={singleStatEntity}
startTimeFilterKey
endTimeFilterKey
Expand Down Expand Up @@ -420,7 +419,6 @@ module SystemMetricsAnalytics = {
</div>
<APITableInfo />
<DynamicSingleStat
index
entity=singleStatEntity
startTimeFilterKey
endTimeFilterKey
Expand Down

0 comments on commit 5743dde

Please sign in to comment.