Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Multi filters support #79

Merged
merged 56 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
8025deb
basic filter changes
sagarnaikjuspay Dec 3, 2023
1b339c1
added helper funtions
sagarnaikjuspay Dec 3, 2023
afb3984
code refactor
sagarnaikjuspay Dec 3, 2023
4bade11
intitial filters settings
sagarnaikjuspay Dec 3, 2023
9f030a6
update component fix
sagarnaikjuspay Dec 3, 2023
f7ec1bb
code refactor
sagarnaikjuspay Dec 3, 2023
e8263be
orders refactor
sagarnaikjuspay Dec 3, 2023
7fbc0ee
remote filters fix
sagarnaikjuspay Dec 4, 2023
d387826
analytics filters fix
sagarnaikjuspay Dec 4, 2023
546d3ef
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 7, 2023
ae5bcb1
filter dict fix
sagarnaikjuspay Dec 7, 2023
72d6afc
basic version
sagarnaikjuspay Dec 7, 2023
e825959
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 7, 2023
53244c7
code refactor
sagarnaikjuspay Dec 7, 2023
3f01f88
merged main
sagarnaikjuspay Dec 7, 2023
e96a1f5
code refactor
sagarnaikjuspay Dec 7, 2023
5743dde
more code refactor
sagarnaikjuspay Dec 7, 2023
7379a37
more code refactor
sagarnaikjuspay Dec 7, 2023
13aefa2
init filter change
sagarnaikjuspay Dec 7, 2023
3dc42cf
code refactor
sagarnaikjuspay Dec 8, 2023
28611c2
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 10, 2023
6fbcdbd
chore: code refactor
sagarnaikjuspay Dec 10, 2023
17b9106
chore: code refactor
sagarnaikjuspay Dec 10, 2023
a1c1f98
chore: code refactor
sagarnaikjuspay Dec 10, 2023
47990ad
chore: removed auto apply for remote filters
sagarnaikjuspay Dec 10, 2023
e1cf266
chore: code refactor
sagarnaikjuspay Dec 10, 2023
32a6d06
chore: merged latest code
sagarnaikjuspay Dec 11, 2023
fb177bd
chore: code refactor
sagarnaikjuspay Dec 11, 2023
10115d2
chore: code refactor
sagarnaikjuspay Dec 11, 2023
90be0f1
chore: some code
sagarnaikjuspay Dec 11, 2023
e08549c
chore: fixed the clear filters
sagarnaikjuspay Dec 11, 2023
c06d751
chore: filters reload isseu fixed
sagarnaikjuspay Dec 11, 2023
c6a6b7b
chore: merged latest code
sagarnaikjuspay Dec 14, 2023
292726f
refactor: removed unused code
sagarnaikjuspay Dec 14, 2023
7818e82
Merge branch 'multi-filters-support' of github.com:juspay/hyperswitch…
sagarnaikjuspay Dec 14, 2023
79603b5
chore: fixed the bug
sagarnaikjuspay Dec 14, 2023
f62a323
feat: added session history
sagarnaikjuspay Dec 14, 2023
37aca6e
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 19, 2023
02a6964
refactor: removed dead code
sagarnaikjuspay Dec 19, 2023
c9b047d
chore: merged latest main
sagarnaikjuspay Dec 20, 2023
313db53
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 20, 2023
b3a7274
chore: disable session storage
sagarnaikjuspay Dec 21, 2023
ed68a32
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 21, 2023
129b23d
chore: merged latest branch
sagarnaikjuspay Dec 27, 2023
ab6bde9
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 27, 2023
2bc1629
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 27, 2023
6d4e335
chore: code refactor
sagarnaikjuspay Dec 27, 2023
ea69695
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 28, 2023
4d96e8b
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 28, 2023
fcf67c1
Merge branch 'multi-filters-support' of github.com:juspay/hyperswitch…
sagarnaikjuspay Dec 28, 2023
69b6fff
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 28, 2023
409912a
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Dec 28, 2023
a311bfe
chore: some code refactor
sagarnaikjuspay Dec 28, 2023
3704f20
Merge branch 'main' into multi-filters-support
sagarnaikjuspay Jan 2, 2024
91c7340
chore: merged latest branch
sagarnaikjuspay Jan 2, 2024
ae03d50
chore: merged latest branch
sagarnaikjuspay Jan 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/DynamicChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ let make = (
}

let currentTheme = ThemeProvider.useTheme()
let {filterValue} = React.useContext(AnalyticsUrlUpdaterContext.urlUpdaterContext)
let {filterValue} = React.useContext(FilterContext.filterContext)
let (_switchToMobileView, setSwitchToMobileView) = React.useState(_ => false)
let (selectedTabState, setSelectedTabState) = React.useState(_ => selectedTab)

Expand Down
5 changes: 3 additions & 2 deletions src/components/DynamicFilter.res
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ let make = (
let defaultFilters = ""->Js.Json.string
let (showModal, setShowModal) = React.useState(_ => false)

let {updateExistingKeys, filterValue, removeKeys} = React.useContext(
AnalyticsUrlUpdaterContext.urlUpdaterContext,
let {index, updateExistingKeys, filterValue, removeKeys} = React.useContext(
FilterContext.filterContext,
)

let currentCustomFilterValue =
Expand Down Expand Up @@ -219,6 +219,7 @@ let make = (

<div className="flex-1 ml-1">
<RemoteFilter
index
defaultFilters
fixedFilters=initialFixedFilters
requiredSearchFieldsList=[]
Expand Down
3 changes: 2 additions & 1 deletion src/components/DynamicSingleStat.res
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ let make = (
~statThreshold=?,
~wrapperClass=?,
) => {
let {filterValueJson} = React.useContext(FilterContext.filterContext)
let fetchApi = AuthHooks.useApiFetcher()
let getAllFilter = UrlUtils.useGetFilterDictFromUrl("")
let getAllFilter = filterValueJson
let isMobileView = MatchMedia.useMobileChecker()
let (showStats, setShowStats) = React.useState(_ => false)

Expand Down
2 changes: 2 additions & 0 deletions src/components/DynamicTable.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let useRemoteFilter = (~searchParams, ~remoteFilters, ~remoteOptions, ~mandatory

@react.component
let make = (
~index,
~entity: EntityType.entityType<'colType, 't>,
~title,
~titleSize: NewThemeUtils.headingSize=Large,
Expand Down Expand Up @@ -375,6 +376,7 @@ let make = (
<UIUtils.RenderIf condition=showRemoteFilter>
<LabelVisibilityContext showLabel=false>
<RemoteFilter
index
defaultFilters=entity.defaultFilters
requiredSearchFieldsList=entity.requiredSearchFieldsList
setOffset
Expand Down
1 change: 1 addition & 0 deletions src/components/DynamicTable.resi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let useRemoteFilter: (
) => Js.Json.t
@react.component
let make: (
~index: string,
~entity: EntityType.entityType<'colType, 't>,
~title: Js.String.t,
~titleSize: NewThemeUtils.headingSize=?,
Expand Down
69 changes: 69 additions & 0 deletions src/components/FilterUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,72 @@ let updateURLWithDefaultFilter = (~path, ~filterParam, ~filterString) => {
RescriptReactRouter.replace(finalUrl)
}
}
sagarnaikjuspay marked this conversation as resolved.
Show resolved Hide resolved

let useFiltersObject = () => {
open HyperswitchAtom
filtersAtom
->Recoil.useRecoilValueFromAtom
sagarnaikjuspay marked this conversation as resolved.
Show resolved Hide resolved
->LogicUtils.safeParse
->Js.Json.decodeObject
->Belt.Option.getWithDefault(Js.Dict.empty())
}

let useFiltersValue = (~index) => {
open LogicUtils
open HyperswitchAtom
filtersAtom
->Recoil.useRecoilValueFromAtom
->safeParse
->Js.Json.decodeObject
->Belt.Option.getWithDefault(Js.Dict.empty())
->Js.Dict.get(index)
->Belt.Option.getWithDefault(""->Js.Json.string)
->getStringFromJson("")
}

let useAddFilters = (~index) => {
open HyperswitchAtom
let filters = useFiltersObject()
let setFilters = filtersAtom->Recoil.useSetRecoilState

value => {
filters->Js.Dict.set(index, value->Js.Json.string)
setFilters(._ => filters->Js.Json.object_->Js.Json.stringify)
}
}

let parseUrl = 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.Dict.fromArray
}

let useUpdateFilterObject = (~index: string) => {
let filters = useFiltersValue(~index)
let setFilters = useAddFilters(~index)

let updateFilter = (~dict: Js.Dict.t<string>) => {
let currentSearchParamsDict = filters->parseUrl

let searchParam =
dict
->Js.Dict.entries
->Js.Array2.map(item => {
let (key, value) = item
`${key}=${value}`
})
->Js.Array2.joinWith("&")

if !DictionaryUtils.equalDicts(currentSearchParamsDict, dict) {
setFilters(searchParam)
}
}
updateFilter
}
27 changes: 15 additions & 12 deletions src/components/RemoteFilter.res
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,18 @@ module ModalUI = {
}

module ClearFilters = {
open FilterUtils
@react.component
let make = (
~index,
~filterButtonStyle,
~defaultFilterKeys=[],
~clearFilters=?,
~count,
~isCountRequired=true,
~outsidefilter=false,
) => {
let url = RescriptReactRouter.useUrl()
let setFilters = useAddFilters(~index)
let isMobileView = MatchMedia.useMobileChecker()
let outerClass = if isMobileView {
"flex items-center justify-end"
Expand Down Expand Up @@ -162,8 +164,7 @@ module ClearFilters = {
})
->Js.Array2.joinWith("&")

let path = url.path->Belt.List.toArray->Js.Array2.joinWith("/")
RescriptReactRouter.replace(`/${path}?${searchStr}`)
setFilters(searchStr)
}
}

Expand Down Expand Up @@ -197,9 +198,10 @@ module ClearFilters = {
}

module AnalyticsClearFilters = {
open FilterUtils
@react.component
let make = (~defaultFilterKeys=[], ~clearFilters=?, ~outsidefilter=false) => {
let url = RescriptReactRouter.useUrl()
let make = (~index, ~defaultFilterKeys=[], ~clearFilters=?, ~outsidefilter=false) => {
let setFilters = useAddFilters(~index)
let formState: ReactFinalForm.formState = ReactFinalForm.useFormState(
ReactFinalForm.useFormSubscription(["values", "initialValues"])->Js.Nullable.return,
)
Expand Down Expand Up @@ -233,8 +235,7 @@ module AnalyticsClearFilters = {
})
->Js.Array2.joinWith("&")

let path = url.path->Belt.List.toArray->Js.Array2.joinWith("/")
RescriptReactRouter.replace(`/${path}?${searchStr}`)
setFilters(searchStr)
}
}

Expand Down Expand Up @@ -521,6 +522,7 @@ module FilterModal = {

@react.component
let make = (
~index,
~defaultFilters,
~fixedFilters: array<EntityType.initialFilters<'t>>=[],
~requiredSearchFieldsList,
Expand Down Expand Up @@ -590,17 +592,15 @@ let make = (
}, [updatedSelectedList->Js.Json.stringify])

let getNewQuery = DateRefreshHooks.useConstructQueryOnBasisOfOpt()
let url = RescriptReactRouter.useUrl()
let (isButtonDisabled, setIsButtonDisabled) = React.useState(_ => false)
let queryStr = url.search
let queryStr = FilterUtils.useFiltersValue(~index)

let totalFilters = selectedFiltersList->Js.Array2.length + localOptions->Js.Array2.length
let (checkedFilters, setCheckedFilters) = React.useState(_ => [])
let (clearFilterAfterRefresh, setClearFilterAfterRefresh) = React.useState(_ => false)
let (count, setCount) = React.useState(_ => initalCount)

let url = RescriptReactRouter.useUrl()
let searchParams = disableURIdecode ? url.search : url.search->Js.Global.decodeURI
let searchParams = disableURIdecode ? queryStr : queryStr->Js.Global.decodeURI

let isMobileView = MatchMedia.useMobileChecker()

Expand Down Expand Up @@ -918,6 +918,7 @@ let make = (
<UIUtils.RenderIf
condition={!hideFilters && fixedFilters->Js.Array2.length === 0 && showClearFilter}>
<ClearFilters
index
filterButtonStyle
defaultFilterKeys
?clearFilters
Expand Down Expand Up @@ -1011,7 +1012,7 @@ let make = (
/>
<UIUtils.RenderIf condition={count > 0 && filterHovered}>
<AnalyticsClearFilters
defaultFilterKeys ?clearFilters outsidefilter={initalCount > 0}
index defaultFilterKeys ?clearFilters outsidefilter={initalCount > 0}
/>
</UIUtils.RenderIf>
</div>
Expand Down Expand Up @@ -1062,6 +1063,7 @@ let make = (
}}
{if !clearFilterAfterRefresh && hideFilters && count > 0 && !revampedFilter {
<ClearFilters
index
filterButtonStyle
defaultFilterKeys
?clearFilters
Expand Down Expand Up @@ -1135,6 +1137,7 @@ let make = (
/>
{if showClearFilterButton && !hideFilters && count > 0 {
<ClearFilters
index
filterButtonStyle
defaultFilterKeys
?clearFilters
Expand Down
4 changes: 2 additions & 2 deletions src/context/ChartContext.res
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ let make = (~children, ~chartEntity: DynamicChart.entity, ~chartId="", ~defaultF
let (bottomChartDataLegendData, setBottomChartDataLegendData) = React.useState(_ => Loading)

let getGranularity = LineChartUtils.getGranularityNewStr
let {filterValue} = React.useContext(AnalyticsUrlUpdaterContext.urlUpdaterContext)
let {filterValue} = React.useContext(FilterContext.filterContext)
let (currentTopMatrix, currentBottomMetrix) = chartEntity.currentMetrics
let (startTimeFilterKey, endTimeFilterKey) = chartEntity.dateFilterKeys
let defaultFilters = [startTimeFilterKey, endTimeFilterKey]
Expand Down Expand Up @@ -615,7 +615,7 @@ module SDKAnalyticsChartContext = {
let bottomChartDataLegendData = Loading

let getGranularity = LineChartUtils.getGranularityNewStr
let {filterValue} = React.useContext(AnalyticsUrlUpdaterContext.urlUpdaterContext)
let {filterValue} = React.useContext(FilterContext.filterContext)
let (currentTopMatrix, currentBottomMetrix) = chartEntity.currentMetrics
let (startTimeFilterKey, endTimeFilterKey) = chartEntity.dateFilterKeys
let defaultFilters = [startTimeFilterKey, endTimeFilterKey]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,37 @@
let defaultValue: Js.Dict.t<string> = Js.Dict.empty()
let setDefaultValue: Js.Dict.t<string> => unit = _dict => ()
let nameSpace: string = ""
let setDefaultNameSpace: string => unit = _ => ()

type urlUpdater = {
type filterUpdater = {
index: string,
filterValue: Js.Dict.t<string>,
updateExistingKeys: Js.Dict.t<string> => unit,
removeKeys: array<string> => unit,
filterValueJson: Js.Dict.t<Js.Json.t>,
reset: unit => unit,
}

let urlUpdater = {
let filterUpdater = {
index: "",
filterValue: Js.Dict.empty(),
updateExistingKeys: _dict => (),
removeKeys: _arr => (),
filterValueJson: Js.Dict.empty(),
reset: () => (),
}

let urlUpdaterContext = React.createContext(urlUpdater)
let filterContext = React.createContext(filterUpdater)

module Provider = {
let make = React.Context.provider(urlUpdaterContext)
let make = React.Context.provider(filterContext)
}

@react.component
let make = (~children) => {
let url = RescriptReactRouter.useUrl()
let searcParamsToDict =
url.search
->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.Dict.fromArray
let make = (~index, ~children) => {
open FilterUtils
let filterString = useFiltersValue(~index)
let searcParamsToDict = filterString->parseUrl

let (urlDict, setUrlDict) = React.useState(_ => searcParamsToDict)
let updateUrl = React.useMemo2(() => {
let updateUrl = (dict: Js.Dict.t<string>) => {
setUrlDict(prev => {
let (filterDict, setfilterDict) = React.useState(_ => searcParamsToDict)
let updateFilter = React.useMemo2(() => {
let updateFilter = (dict: Js.Dict.t<string>) => {
setfilterDict(prev => {
let prevDictArr =
prev
->Js.Dict.entries
Expand Down Expand Up @@ -76,11 +64,11 @@ let make = (~children) => {
}

let reset = () => {
setUrlDict(_ => Js.Dict.empty())
setfilterDict(_ => Js.Dict.empty())
}

let removeKeys = (arr: array<string>) => {
setUrlDict(prev => {
setfilterDict(prev => {
let updatedDict =
prev->Js.Dict.entries->Js.Array2.copy->Js.Dict.fromArray->DictionaryUtils.deleteKeys(arr)
if DictionaryUtils.equalDicts(updatedDict, prev) {
Expand All @@ -91,10 +79,11 @@ let make = (~children) => {
})
}
{
filterValue: urlDict,
updateExistingKeys: updateUrl,
index,
filterValue: filterDict,
updateExistingKeys: updateFilter,
removeKeys,
filterValueJson: urlDict
filterValueJson: filterDict
->Js.Dict.entries
->Js.Array2.map(item => {
let (key, value) = item
Expand All @@ -103,7 +92,7 @@ let make = (~children) => {
->Js.Dict.fromArray,
reset,
}
}, (urlDict, setUrlDict))
}, (filterDict, setfilterDict))

<Provider value={updateUrl}> children </Provider>
<Provider value={updateFilter}> children </Provider>
}
Loading