From 8cf947163b7437c9cb3fdcc7af152a69530428b0 Mon Sep 17 00:00:00 2001 From: Adam Grzybowski Date: Tue, 6 Aug 2024 14:25:50 +0200 Subject: [PATCH] fix getAlreadyOpenedSettingsScreen --- .../getMatchingCentralPaneRouteForState.ts | 34 +++---------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/src/libs/Navigation/linkingConfig/getMatchingCentralPaneRouteForState.ts b/src/libs/Navigation/linkingConfig/getMatchingCentralPaneRouteForState.ts index 0788f9309853..0679bfa26285 100644 --- a/src/libs/Navigation/linkingConfig/getMatchingCentralPaneRouteForState.ts +++ b/src/libs/Navigation/linkingConfig/getMatchingCentralPaneRouteForState.ts @@ -31,24 +31,8 @@ const getTopMostReportIDFromRHP = (state: State): string => { return ''; }; -// Check if the given route has a policyID equal to the id provided in the function params -function hasRouteMatchingPolicyID(route: NavigationPartialRoute, policyID?: string) { - if (!route?.params) { - return false; - } - - const params = `params` in route.params ? (route.params.params as Record) : undefined; - - // If params are not defined, then we need to check if the policyID exists - if (!params) { - return !policyID; - } - - return 'policyID' in params && params.policyID === policyID; -} - // Get already opened settings screen within the policy -function getAlreadyOpenedSettingsScreen(rootState?: State, policyID?: string): keyof AuthScreensParamList | undefined { +function getAlreadyOpenedSettingsScreen(rootState?: State): keyof AuthScreensParamList | undefined { if (!rootState) { return undefined; } @@ -56,18 +40,9 @@ function getAlreadyOpenedSettingsScreen(rootState?: State, policyID?: string): k // If one of the screen from TAB_TO_CENTRAL_PANE_MAPPING[SCREENS.SETTINGS.ROOT] is now in the navigation state, we can decide which screen we should display. // A screen from the navigation state can be pushed to the navigation state again only if it has a matching policyID with the currently selected workspace. // Otherwise, when we switch the workspace, we want to display the initial screen in the settings tab. - const alreadyOpenedSettingsTab = rootState.routes - .filter((item) => item.params && 'screen' in item.params && TAB_TO_CENTRAL_PANE_MAPPING[SCREENS.SETTINGS.ROOT].includes(item.name as CentralPaneName)) - .at(-1); - - if (!hasRouteMatchingPolicyID(alreadyOpenedSettingsTab as NavigationPartialRoute, policyID)) { - return undefined; - } - - const settingsScreen = - alreadyOpenedSettingsTab?.params && 'screen' in alreadyOpenedSettingsTab.params ? (alreadyOpenedSettingsTab?.params?.screen as keyof AuthScreensParamList) : undefined; + const alreadyOpenedSettingsScreen = rootState.routes.filter((item) => TAB_TO_CENTRAL_PANE_MAPPING[SCREENS.SETTINGS.ROOT].includes(item.name as CentralPaneName)).at(-1); - return settingsScreen; + return alreadyOpenedSettingsScreen?.name as keyof AuthScreensParamList; } // Get matching central pane route for bottom tab navigator. e.g HOME -> REPORT @@ -82,8 +57,7 @@ function getMatchingCentralPaneRouteForState(state: State, r if (topmostBottomTabRoute.name === SCREENS.SETTINGS.ROOT) { // When we go back to the settings tab without switching the workspace id, we want to return to the previously opened screen - const policyID = topmostBottomTabRoute?.params && 'policyID' in topmostBottomTabRoute.params ? (topmostBottomTabRoute.params.policyID as string) : undefined; - const screen = getAlreadyOpenedSettingsScreen(rootState, policyID) ?? centralPaneName; + const screen = getAlreadyOpenedSettingsScreen(rootState) ?? centralPaneName; return {name: screen as CentralPaneName, params: topmostBottomTabRoute.params}; }