Skip to content

Commit

Permalink
feat: [IOPLT-724] Split up the backend status for better handling (#6296
Browse files Browse the repository at this point in the history
)

## Short description
This PR aims to split the `backendStatus` reducer and store section into
4 different reducers

## List of changes proposed in this pull request
- Removed `backendStatus` reducer
- Created `remoteConfig`, `sectionStatus`, `backendInfo`,
`statusMessages` reducers

## How to test
Anything should work properly as usual after changes.

---------

Co-authored-by: Andrea <[email protected]>
  • Loading branch information
CrisTofani and Vangaorth authored Nov 5, 2024
1 parent 0881665 commit 1b07349
Show file tree
Hide file tree
Showing 125 changed files with 1,144 additions and 1,443 deletions.
74 changes: 35 additions & 39 deletions ts/components/SectionStatus/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import configureMockStore from "redux-mock-store";
import { IOColors } from "@pagopa/io-app-design-system";
import * as pot from "@pagopa/ts-commons/lib/pot";
import { ToolEnum } from "../../../../definitions/content/AssistanceToolConfig";
import { BackendStatus } from "../../../../definitions/content/BackendStatus";
import { Config } from "../../../../definitions/content/Config";
import {
LevelEnum,
SectionStatus
} from "../../../../definitions/content/SectionStatus";
import I18n, { setLocale } from "../../../i18n";
import { SectionStatusKey } from "../../../store/reducers/backendStatus";
import { SectionStatusKey } from "../../../store/reducers/backendStatus/sectionStatus";
import { renderScreenWithNavigationStoreContext } from "../../../utils/testWrapper";
import { openWebUrl } from "../../../utils/url";
import SectionStatusComponent from "../index";
Expand All @@ -22,6 +21,7 @@ import { TrialSystemState } from "../../../features/trialSystem/store/reducers";
import { PersistedFeaturesState } from "../../../features/common/store/reducers";
import { ItwLifecycleState } from "../../../features/itwallet/lifecycle/store/reducers";
import { ItWalletState } from "../../../features/itwallet/common/store/reducers";
import { GlobalState } from "../../../store/reducers/types";

jest.mock("../../../utils/url");

Expand All @@ -40,41 +40,38 @@ const sectionStatus: SectionStatus = {

const mockSectionStatusState = (
sectionKey: SectionStatusKey,
sectionStatus: SectionStatus
) => ({
backendStatus: {
status: O.some({
sections: { [sectionKey]: sectionStatus },
config: {
assistanceTool: { tool: ToolEnum.none },
cgn: { enabled: true },
newPaymentSection: {
enabled: false,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
},
fims: { enabled: true },
itw: {
enabled: true,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
status: SectionStatus
) =>
({
sectionStatus: O.some({ [sectionKey]: status }),
remoteConfig: O.some({
assistanceTool: { tool: ToolEnum.none },
cgn: { enabled: true },
newPaymentSection: {
enabled: false,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
} as Config
} as BackendStatus)
},
features: {
itWallet: {
lifecycle: ItwLifecycleState.ITW_LIFECYCLE_INSTALLED
} as ItWalletState
} as PersistedFeaturesState,
trialSystem: {
[itwTrialId]: pot.some(SubscriptionStateEnum.UNSUBSCRIBED)
} as TrialSystemState
});
},
fims: { enabled: true },
itw: {
enabled: true,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
}
} as Config),
features: {
itWallet: {
lifecycle: ItwLifecycleState.ITW_LIFECYCLE_INSTALLED
} as ItWalletState
} as PersistedFeaturesState,
trialSystem: {
[itwTrialId]: pot.some(SubscriptionStateEnum.UNSUBSCRIBED)
} as TrialSystemState
} as unknown as GlobalState);

const mockStore = configureMockStore();

Expand Down Expand Up @@ -186,9 +183,8 @@ describe("Section Status Component should return null", () => {
const component = getComponent(
"messages",
mockStore({
backendStatus: {
status: O.none
},
remoteConfig: O.none,
sectionStatus: O.none,
trialSystem: {
[itwTrialId]: pot.some(SubscriptionStateEnum.UNSUBSCRIBED)
} as TrialSystemState,
Expand Down
2 changes: 1 addition & 1 deletion ts/components/SectionStatus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
messageForSectionSelector,
SectionStatusKey,
webUrlForSectionSelector
} from "../../store/reducers/backendStatus";
} from "../../store/reducers/backendStatus/sectionStatus";
import { getFullLocale } from "../../utils/locale";
import { openWebUrl } from "../../utils/url";
import { useIOSelector } from "../../store/hooks";
Expand Down
2 changes: 1 addition & 1 deletion ts/components/SectionStatus/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
messageForSectionSelector,
SectionStatusKey,
webUrlForSectionSelector
} from "../../../store/reducers/backendStatus";
} from "../../../store/reducers/backendStatus/sectionStatus";
import { getFullLocale } from "../../../utils/locale";
import { openWebUrl } from "../../../utils/url";
import { useIOSelector } from "../../../store/hooks";
Expand Down
2 changes: 1 addition & 1 deletion ts/components/screens/BaseHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useFocusEffect } from "@react-navigation/native";
import I18n from "../../i18n";
import { navigateBack } from "../../store/actions/navigation";
import { Dispatch } from "../../store/actions/types";
import { assistanceToolConfigSelector } from "../../store/reducers/backendStatus";
import { assistanceToolConfigSelector } from "../../store/reducers/backendStatus/remoteConfig";
import { isSearchEnabledSelector } from "../../store/reducers/search";
import { GlobalState } from "../../store/reducers/types";
import variables from "../../theme/variables";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import React from "react";
import { Store } from "redux";
import configureMockStore from "redux-mock-store";
import { ToolEnum } from "../../../../../definitions/content/AssistanceToolConfig";
import { BackendStatus } from "../../../../../definitions/content/BackendStatus";
import { Config } from "../../../../../definitions/content/Config";
import * as zendeskActions from "../../../../features/zendesk/store/actions";
import { applicationChangeState } from "../../../../store/actions/application";
import { appReducer } from "../../../../store/reducers";
import { BackendStatusState } from "../../../../store/reducers/backendStatus";
import { GlobalState } from "../../../../store/reducers/types";
import { renderScreenWithNavigationStoreContext } from "../../../../utils/testWrapper";

import BaseScreenComponent, { Props } from "../index";
import { MESSAGES_ROUTES } from "../../../../features/messages/navigation/routes";
import { RemoteConfigState } from "../../../../store/reducers/backendStatus/remoteConfig";

jest.useFakeTimers();

Expand All @@ -28,13 +27,9 @@ describe("BaseScreenComponent", () => {
const mockStore = configureMockStore<GlobalState>();
const state = {
...globalState,
backendStatus: {
status: O.some({
config: {
assistanceTool: { tool: ToolEnum.none }
} as Config
} as BackendStatus)
} as BackendStatusState
remoteConfig: O.some({
assistanceTool: { tool: ToolEnum.none }
} as Config) as RemoteConfigState
};

it.each`
Expand All @@ -49,29 +44,25 @@ describe("BaseScreenComponent", () => {
defaultProps,
mockStore({
...state,
backendStatus: {
status: O.some({
config: {
assistanceTool: { tool },
cgn: { enabled: true },
newPaymentSection: {
enabled: false,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
},
fims: { enabled: true },
itw: {
enabled: true,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
}
} as Config
} as BackendStatus)
} as BackendStatusState
remoteConfig: O.some({
assistanceTool: { tool },
cgn: { enabled: true },
newPaymentSection: {
enabled: false,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
},
fims: { enabled: true },
itw: {
enabled: true,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
}
} as Config) as RemoteConfigState
})
);
expect(component.queryByTestId("helpButton")).toBeNull();
Expand All @@ -83,29 +74,25 @@ describe("BaseScreenComponent", () => {
defaultProps,
mockStore({
...state,
backendStatus: {
status: O.some({
config: {
assistanceTool: { tool: ToolEnum.zendesk },
cgn: { enabled: true },
newPaymentSection: {
enabled: false,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
},
fims: { enabled: true },
itw: {
enabled: true,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
}
} as Config
} as BackendStatus)
} as BackendStatusState
remoteConfig: O.some({
assistanceTool: { tool: ToolEnum.zendesk },
cgn: { enabled: true },
newPaymentSection: {
enabled: false,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
},
fims: { enabled: true },
itw: {
enabled: true,
min_app_version: {
android: "0.0.0.0",
ios: "0.0.0.0"
}
}
} as Config) as RemoteConfigState
})
);
const helpButton = component.queryByTestId("helpButton");
Expand Down
2 changes: 1 addition & 1 deletion ts/components/screens/BaseScreenComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TranslationKeys } from "../../../../locales/locales";
import { zendeskSupportStart } from "../../../features/zendesk/store/actions";
import { useIODispatch, useIOSelector } from "../../../store/hooks";
import { canShowHelpSelector } from "../../../store/reducers/assistanceTools";
import { assistanceToolConfigSelector } from "../../../store/reducers/backendStatus";
import { assistanceToolConfigSelector } from "../../../store/reducers/backendStatus/remoteConfig";
import { currentRouteSelector } from "../../../store/reducers/navigation";
import { FAQsCategoriesType } from "../../../utils/faq";
import {
Expand Down
19 changes: 9 additions & 10 deletions ts/components/wallet/PaymentMethodsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { BackendStatus } from "../../../definitions/content/BackendStatus";
import { LevelEnum } from "../../../definitions/content/SectionStatus";
import I18n from "../../i18n";
import {
backendStatusSelector,
SectionStatusKey
} from "../../store/reducers/backendStatus";
SectionStatusKey,
sectionStatusSelector
} from "../../store/reducers/backendStatus/sectionStatus";
import { GlobalState } from "../../store/reducers/types";
import { getFullLocale } from "../../utils/locale";
import { IOBadge, IOBadgeOutlineColors } from "../core/IOBadge";
Expand Down Expand Up @@ -78,11 +78,11 @@ export const showPaymentMethodIncomingAlert = () =>
* if it is critical status, it returns also an alert function, undefined otherwise
* the alert display a title (section.badge) and a message (section.message) with default dismiss button
* @param paymentMethod
* @param backendStatus
* @param sectionStatus
*/
const getBadgeStatus = (
paymentMethod: IPaymentMethod,
backendStatus: O.Option<BackendStatus>
sectionStatus: O.Option<BackendStatus["sections"]>
): null | { badge: React.ReactNode; alert?: () => void } => {
const itemSection = paymentMethod.section;

Expand All @@ -97,8 +97,7 @@ const getBadgeStatus = (
return null;
}
return pipe(
backendStatus,
O.chainNullableK(bs => bs.sections),
sectionStatus,
O.fold(
() => null,
sections => {
Expand Down Expand Up @@ -134,11 +133,11 @@ const getBadgeStatus = (

const renderListItem = (
itemInfo: ListRenderItemInfo<IPaymentMethod>,
backendStatus: O.Option<BackendStatus>
sectionStatus: O.Option<BackendStatus["sections"]>
) => {
switch (itemInfo.item.status) {
case "implemented": {
const badgeStatus = getBadgeStatus(itemInfo.item, backendStatus);
const badgeStatus = getBadgeStatus(itemInfo.item, sectionStatus);
return (
<Pressable
accessibilityRole="button"
Expand Down Expand Up @@ -225,7 +224,7 @@ const PaymentMethodsList: React.FunctionComponent<Props> = (props: Props) => (
</View>
);
const mapStateToProps = (state: GlobalState) => ({
sectionStatus: backendStatusSelector(state)
sectionStatus: sectionStatusSelector(state)
});
export default connect(mapStateToProps)(
withLightModalContext(PaymentMethodsList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
} from "../../../navigation/params/AppParamsList";
import { useIODispatch, useIOSelector } from "../../../store/hooks";
import { canShowHelpSelector } from "../../../store/reducers/assistanceTools";
import { assistanceToolConfigSelector } from "../../../store/reducers/backendStatus";
import { assistanceToolConfigSelector } from "../../../store/reducers/backendStatus/remoteConfig";
import { currentRouteSelector } from "../../../store/reducers/navigation";
import { FAQsCategoriesType } from "../../../utils/faq";
import { isAndroid } from "../../../utils/platform";
Expand Down
2 changes: 1 addition & 1 deletion ts/features/barcode/screens/BarcodeScanScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useIODispatch, useIOSelector } from "../../../store/hooks";
import {
barcodesScannerConfigSelector,
isIdPayEnabledSelector
} from "../../../store/reducers/backendStatus";
} from "../../../store/reducers/backendStatus/remoteConfig";
import { emptyContextualHelp } from "../../../utils/emptyContextualHelp";
import { useIOBottomSheetAutoresizableModal } from "../../../utils/hooks/bottomSheet";
import { IdPayPaymentRoutes } from "../../idpay/payment/navigation/routes";
Expand Down
2 changes: 1 addition & 1 deletion ts/features/bonus/cgn/screens/CgnDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { useIOSelector } from "../../../../store/hooks";
import {
cgnMerchantVersionSelector,
isCGNEnabledSelector
} from "../../../../store/reducers/backendStatus";
} from "../../../../store/reducers/backendStatus/remoteConfig";
import { profileSelector } from "../../../../store/reducers/profile";
import { GlobalState } from "../../../../store/reducers/types";
import { formatDateAsShortFormat } from "../../../../utils/dates";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Alert } from "react-native";
import { connect } from "react-redux";
import { Dispatch } from "redux";
import I18n from "../../../../../i18n";
import { isCGNEnabledSelector } from "../../../../../store/reducers/backendStatus";
import { isCGNEnabledSelector } from "../../../../../store/reducers/backendStatus/remoteConfig";
import { GlobalState } from "../../../../../store/reducers/types";
import { useActionOnFocus } from "../../../../../utils/hooks/useOnFocus";
import { ID_CGN_TYPE } from "../../../common/utils";
Expand Down
2 changes: 1 addition & 1 deletion ts/features/bonus/common/screens/AvailableBonusScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { Dispatch } from "../../../../store/actions/types";
import {
isCGNEnabledSelector,
isCdcEnabledSelector
} from "../../../../store/reducers/backendStatus";
} from "../../../../store/reducers/backendStatus/remoteConfig";
import { GlobalState } from "../../../../store/reducers/types";
import { storeUrl } from "../../../../utils/appVersion";
import { loadServiceDetail } from "../../../services/details/store/actions/details";
Expand Down
Loading

0 comments on commit 1b07349

Please sign in to comment.