From f62a3238bfbf15b3315b836cdaf7d7ba7319fc81 Mon Sep 17 00:00:00 2001 From: Sagar Naik Date: Thu, 14 Dec 2023 16:19:38 +0530 Subject: [PATCH] feat: added session history --- src/context/FilterContext.res | 25 ++++++++++++++++++- .../hyperswitch/HyperSwitchApp.res | 12 ++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/context/FilterContext.res b/src/context/FilterContext.res index b9cd47a62..30cd20e08 100644 --- a/src/context/FilterContext.res +++ b/src/context/FilterContext.res @@ -1,3 +1,11 @@ +type sessionStorage = { + getItem: (. string) => Js.Nullable.t, + setItem: (. string, string) => unit, + removeItem: (. string) => unit, +} + +@val external sessionStorage: sessionStorage = "sessionStorage" + type filterUpdater = { query: string, filterValue: Js.Dict.t, @@ -23,7 +31,7 @@ module Provider = { } @react.component -let make = (~children) => { +let make = (~index: string, ~children) => { open FilterUtils let (query, setQuery) = React.useState(_ => "") let searcParamsToDict = query->parseFilterString @@ -102,5 +110,20 @@ let make = (~children) => { } }, (filterDict, setfilterDict)) + React.useEffect0(() => { + switch sessionStorage.getItem(. index)->Js.Nullable.toOption { + | Some(value) => value->FilterUtils.parseFilterString->updateFilter.updateExistingKeys + | None => () + } + None + }) + + React.useEffect1(() => { + if !(query->Js.String2.length < 1) { + sessionStorage.setItem(. index, query) + } + None + }, [query]) + children } diff --git a/src/entryPoints/hyperswitch/HyperSwitchApp.res b/src/entryPoints/hyperswitch/HyperSwitchApp.res index b1a331c68..c06a6e6f3 100644 --- a/src/entryPoints/hyperswitch/HyperSwitchApp.res +++ b/src/entryPoints/hyperswitch/HyperSwitchApp.res @@ -247,7 +247,7 @@ let make = () => { renderShow={_ => } /> | list{"payments", ...remainingPath} => - + { /> | list{"refunds", ...remainingPath} => - + { renderShow={_ => } /> | list{"analytics-payments"} => - + | list{"analytics-refunds"} => - + | list{"analytics-user-journey"} => - + | list{"monitoring"} => comingSoonPage @@ -308,7 +308,7 @@ let make = () => { Js.String2.includes("internal_") && featureFlagDetails.systemMetrics}> - +