From 34d64035a939d776350b57ff03fd746b1ca2b418 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Thu, 14 Nov 2024 15:12:23 +0100 Subject: [PATCH 1/9] Cleanup ActiveWorkspaceProvider --- .../ActiveWorkspaceProvider/index.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/ActiveWorkspaceProvider/index.tsx b/src/components/ActiveWorkspaceProvider/index.tsx index a0decb667504..b9e5f34d5389 100644 --- a/src/components/ActiveWorkspaceProvider/index.tsx +++ b/src/components/ActiveWorkspaceProvider/index.tsx @@ -22,17 +22,19 @@ function ActiveWorkspaceContextProvider({children}: ChildrenProps) { return; } - if (queryFromRouteParam) { - const queryJSON = SearchQueryUtils.buildSearchQueryJSON(queryFromRouteParam); - if (!queryJSON) { - setActiveWorkspaceID(undefined); - return; - } - setActiveWorkspaceID(SearchQueryUtils.getPolicyIDFromSearchQuery(queryJSON)); + if (!queryFromRouteParam) { + setActiveWorkspaceID(undefined); return; } - setActiveWorkspaceID(undefined); + const queryJSON = SearchQueryUtils.buildSearchQueryJSON(queryFromRouteParam); + + if (!queryJSON) { + setActiveWorkspaceID(undefined); + return; + } + + setActiveWorkspaceID(SearchQueryUtils.getPolicyIDFromSearchQuery(queryJSON)); }, [policyIDFromRouteParam, queryFromRouteParam, setActiveWorkspaceID]); const value = useMemo( From 0cd11da6abb58d10d76c5dfed251e722c7c0bdcf Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Fri, 15 Nov 2024 11:15:14 +0100 Subject: [PATCH 2/9] Fix animationTypeForReplace for RHP screens --- .../AppNavigator/ModalStackNavigators/useModalScreenOptions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/useModalScreenOptions.ts b/src/libs/Navigation/AppNavigator/ModalStackNavigators/useModalScreenOptions.ts index 2193dcb2bf6b..64457fa5a42e 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/useModalScreenOptions.ts +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/useModalScreenOptions.ts @@ -25,6 +25,7 @@ function useModalScreenOptions(getScreenOptions?: (styles: ThemeStyles) => Stack cardStyle: styles.navigationScreenCardStyle, headerShown: false, cardStyleInterpolator, + animationTypeForReplace: 'pop', }), [styles, cardStyleInterpolator], ); From 5d978e3e6d8d2a9bf2e50d55c27d6acc23e2ac89 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Fri, 15 Nov 2024 15:03:14 +0100 Subject: [PATCH 3/9] Add GetStateForActionHandlers --- src/CONST.ts | 3 + .../CustomRouter.ts | 166 ++++-------------- .../GetStateForActionHandlers.ts | 155 ++++++++++++++++ .../createCustomStackNavigator/types.ts | 35 +++- src/libs/Navigation/Navigation.ts | 4 +- 5 files changed, 228 insertions(+), 135 deletions(-) create mode 100644 src/libs/Navigation/AppNavigator/createCustomStackNavigator/GetStateForActionHandlers.ts diff --git a/src/CONST.ts b/src/CONST.ts index f41eab6318e4..3df06347cd97 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -4538,7 +4538,10 @@ const CONST = { REPLACE: 'REPLACE', PUSH: 'PUSH', NAVIGATE: 'NAVIGATE', + + /** These action types are custom for RootNavigator */ SWITCH_POLICY_ID: 'SWITCH_POLICY_ID', + DISMISS_MODAL: 'DISMISS_MODAL', }, }, TIME_PERIOD: { diff --git a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts index 4b1882747e20..bec622f1a953 100644 --- a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts +++ b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts @@ -1,35 +1,36 @@ import type {CommonActions, RouterConfigOptions, StackActionType, StackNavigationState} from '@react-navigation/native'; -import {findFocusedRoute, StackActions, StackRouter} from '@react-navigation/native'; +import {findFocusedRoute, StackRouter} from '@react-navigation/native'; import type {ParamListBase} from '@react-navigation/routers'; import useActiveWorkspace from '@hooks/useActiveWorkspace'; import * as Localize from '@libs/Localize'; -import Log from '@libs/Log'; -import getPolicyIDFromState from '@libs/Navigation/getPolicyIDFromState'; import isSideModalNavigator from '@libs/Navigation/isSideModalNavigator'; -import type {RootStackParamList, State} from '@libs/Navigation/types'; import {isOnboardingFlowName} from '@libs/NavigationUtils'; -import * as SearchQueryUtils from '@libs/SearchQueryUtils'; import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; +import * as GetStateForActionHandlers from './GetStateForActionHandlers'; import syncBrowserHistory from './syncBrowserHistory'; -import type {ResponsiveStackNavigatorRouterOptions} from './types'; - -const MODAL_ROUTES_TO_DISMISS: string[] = [ - NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, - NAVIGATORS.LEFT_MODAL_NAVIGATOR, - NAVIGATORS.RIGHT_MODAL_NAVIGATOR, - NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR, - NAVIGATORS.FEATURE_TRANING_MODAL_NAVIGATOR, - SCREENS.NOT_FOUND, - SCREENS.ATTACHMENTS, - SCREENS.TRANSACTION_RECEIPT, - SCREENS.PROFILE_AVATAR, - SCREENS.WORKSPACE_AVATAR, - SCREENS.REPORT_AVATAR, - SCREENS.CONCIERGE, -]; +import type { + CustomRouterActionType, + CustomRouterAction, + DismissModalActionType, + PushActionType, + SwitchPolicyIdActionType, + ResponsiveStackNavigatorRouterOptions, +} from './types'; + +function isSwitchPolicyIdAction(action: CustomRouterAction): action is SwitchPolicyIdActionType { + return action.type === CONST.NAVIGATION.ACTION_TYPE.SWITCH_POLICY_ID; +} + +function isPushAction(action: CustomRouterAction): action is PushActionType { + return action.type === CONST.NAVIGATION.ACTION_TYPE.PUSH; +} + +function isDismissModalAction(action: CustomRouterAction): action is DismissModalActionType { + return action.type === CONST.NAVIGATION.ACTION_TYPE.DISMISS_MODAL; +} function shouldPreventReset(state: StackNavigationState, action: CommonActions.Action | StackActionType) { if (action.type !== CONST.NAVIGATION_ACTIONS.RESET || !action?.payload) { @@ -59,19 +60,9 @@ function shouldDismissSideModalNavigator(state: StackNavigationState, action: CommonActions.Action | StackActionType | CustomRootStackActionType, configOptions: RouterConfigOptions) { - if (action.type === CONST.NAVIGATION.ACTION_TYPE.SWITCH_POLICY_ID) { - const lastRoute = state.routes.at(-1); - if (lastRoute?.name === SCREENS.SEARCH.CENTRAL_PANE) { - const currentParams = lastRoute.params as RootStackParamList[typeof SCREENS.SEARCH.CENTRAL_PANE]; - const queryJSON = SearchQueryUtils.buildSearchQueryJSON(currentParams.q); - if (!queryJSON) { - return null; - } - - if (action.payload.policyID) { - queryJSON.policyID = action.payload.policyID; - } else { - delete queryJSON.policyID; - } - - const newAction = StackActions.push(SCREENS.SEARCH.CENTRAL_PANE, { - ...currentParams, - q: SearchQueryUtils.buildSearchQueryString(queryJSON), - }); - - setActiveWorkspaceID(action.payload.policyID); - return stackRouter.getStateForAction(state, newAction, configOptions); - } - if (lastRoute?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR) { - const newAction = StackActions.push(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, {policyID: action.payload.policyID}); - - setActiveWorkspaceID(action.payload.policyID); - return stackRouter.getStateForAction(state, newAction, configOptions); - } - - // We don't have other navigators that should handle switch policy action. - return null; + getStateForAction(state: StackNavigationState, action: CustomRouterAction, configOptions: RouterConfigOptions) { + if (isSwitchPolicyIdAction(action)) { + return GetStateForActionHandlers.handleSwitchPolicyID(state, action, configOptions, stackRouter, setActiveWorkspaceID); } - if (action.type === 'DISMISS_MODAL') { - const lastRoute = state.routes.at(-1); - const newAction = StackActions.pop(); + if (isDismissModalAction(action)) { + return GetStateForActionHandlers.handleDismissModalAction(state, action, configOptions, stackRouter); + } - if (!lastRoute?.name || !MODAL_ROUTES_TO_DISMISS.includes(lastRoute?.name)) { - Log.hmmm('[Navigation] dismissModal failed because there is no modal stack to dismiss'); - return null; + if (isPushAction(action)) { + if (action.payload.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR) { + return GetStateForActionHandlers.handlePushReportAction(state, action, configOptions, stackRouter, setActiveWorkspaceID); } - return stackRouter.getStateForAction(state, newAction, configOptions); + if (action.payload.name === SCREENS.SEARCH.CENTRAL_PANE) { + return GetStateForActionHandlers.handlePushSearchPageAction(state, action, configOptions, stackRouter, setActiveWorkspaceID); + } } // Don't let the user navigate back to a non-onboarding screen if they are currently on an onboarding screen and it's not finished. @@ -132,65 +95,6 @@ function CustomRouter(options: ResponsiveStackNavigatorRouterOptions) { return state; } - if (action.type === 'PUSH' && action.payload.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR) { - const haveParamsPolicyID = action.payload.params && 'policyID' in action.payload.params; - let policyID; - - if (haveParamsPolicyID) { - policyID = (action.payload.params as Record)?.policyID; - setActiveWorkspaceID(policyID); - } else { - policyID = getPolicyIDFromState(state as State); - } - - const modifiedAction = { - ...action, - payload: { - ...action.payload, - params: { - ...action.payload.params, - policyID, - }, - }, - }; - - return stackRouter.getStateForAction(state, modifiedAction, configOptions); - } - - if (action.type === 'PUSH' && action.payload.name === SCREENS.SEARCH.CENTRAL_PANE) { - const currentParams = action.payload.params as RootStackParamList[typeof SCREENS.SEARCH.CENTRAL_PANE]; - const queryJSON = SearchQueryUtils.buildSearchQueryJSON(currentParams.q); - - if (!queryJSON) { - return null; - } - - if (!queryJSON.policyID) { - const policyID = getPolicyIDFromState(state as State); - - if (policyID) { - queryJSON.policyID = policyID; - } else { - delete queryJSON.policyID; - } - } else { - setActiveWorkspaceID(queryJSON.policyID); - } - - const modifiedAction = { - ...action, - payload: { - ...action.payload, - params: { - ...action.payload.params, - q: SearchQueryUtils.buildSearchQueryString(queryJSON), - }, - }, - }; - - return stackRouter.getStateForAction(state, modifiedAction, configOptions); - } - if (shouldDismissSideModalNavigator(state, action)) { const modifiedState = {...state, routes: state.routes.slice(0, -1), index: state.index !== 0 ? state.index - 1 : 0}; return stackRouter.getStateForAction(modifiedState, action, configOptions); @@ -202,4 +106,4 @@ function CustomRouter(options: ResponsiveStackNavigatorRouterOptions) { } export default CustomRouter; -export type {CustomRootStackActionType}; +export type {CustomRouterActionType}; diff --git a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/GetStateForActionHandlers.ts b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/GetStateForActionHandlers.ts new file mode 100644 index 000000000000..54542819b569 --- /dev/null +++ b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/GetStateForActionHandlers.ts @@ -0,0 +1,155 @@ +import type {CommonActions, RouterConfigOptions, StackActionType, StackNavigationState} from '@react-navigation/native'; +import {StackActions} from '@react-navigation/native'; +import type {ParamListBase, Router} from '@react-navigation/routers'; +import Log from '@libs/Log'; +import getPolicyIDFromState from '@libs/Navigation/getPolicyIDFromState'; +import type {RootStackParamList, State} from '@libs/Navigation/types'; +import * as SearchQueryUtils from '@libs/SearchQueryUtils'; +import NAVIGATORS from '@src/NAVIGATORS'; +import SCREENS from '@src/SCREENS'; +import type {DismissModalActionType, PushActionType, SwitchPolicyIdActionType} from './types'; + +const MODAL_ROUTES_TO_DISMISS: string[] = [ + NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR, + NAVIGATORS.LEFT_MODAL_NAVIGATOR, + NAVIGATORS.RIGHT_MODAL_NAVIGATOR, + NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR, + NAVIGATORS.FEATURE_TRANING_MODAL_NAVIGATOR, + SCREENS.NOT_FOUND, + SCREENS.ATTACHMENTS, + SCREENS.TRANSACTION_RECEIPT, + SCREENS.PROFILE_AVATAR, + SCREENS.WORKSPACE_AVATAR, + SCREENS.REPORT_AVATAR, + SCREENS.CONCIERGE, +]; + +function handleSwitchPolicyID( + state: StackNavigationState, + action: SwitchPolicyIdActionType, + configOptions: RouterConfigOptions, + stackRouter: Router, CommonActions.Action | StackActionType>, + setActiveWorkspaceID: (workspaceID: string | undefined) => void, +) { + const lastRoute = state.routes.at(-1); + if (lastRoute?.name === SCREENS.SEARCH.CENTRAL_PANE) { + const currentParams = lastRoute.params as RootStackParamList[typeof SCREENS.SEARCH.CENTRAL_PANE]; + const queryJSON = SearchQueryUtils.buildSearchQueryJSON(currentParams.q); + if (!queryJSON) { + return null; + } + + if (action.payload.policyID) { + queryJSON.policyID = action.payload.policyID; + } else { + delete queryJSON.policyID; + } + + const newAction = StackActions.push(SCREENS.SEARCH.CENTRAL_PANE, { + ...currentParams, + q: SearchQueryUtils.buildSearchQueryString(queryJSON), + }); + + setActiveWorkspaceID(action.payload.policyID); + return stackRouter.getStateForAction(state, newAction, configOptions); + } + if (lastRoute?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR) { + const newAction = StackActions.push(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, {policyID: action.payload.policyID}); + + setActiveWorkspaceID(action.payload.policyID); + return stackRouter.getStateForAction(state, newAction, configOptions); + } + + // We don't have other navigators that should handle switch policy action. + return null; +} + +function handlePushReportAction( + state: StackNavigationState, + action: PushActionType, + configOptions: RouterConfigOptions, + stackRouter: Router, CommonActions.Action | StackActionType>, + setActiveWorkspaceID: (workspaceID: string | undefined) => void, +) { + const haveParamsPolicyID = action.payload.params && 'policyID' in action.payload.params; + let policyID; + + if (haveParamsPolicyID) { + policyID = (action.payload.params as Record)?.policyID; + setActiveWorkspaceID(policyID); + } else { + policyID = getPolicyIDFromState(state as State); + } + + const modifiedAction = { + ...action, + payload: { + ...action.payload, + params: { + ...action.payload.params, + policyID, + }, + }, + }; + + return stackRouter.getStateForAction(state, modifiedAction, configOptions); +} + +function handlePushSearchPageAction( + state: StackNavigationState, + action: PushActionType, + configOptions: RouterConfigOptions, + stackRouter: Router, CommonActions.Action | StackActionType>, + setActiveWorkspaceID: (workspaceID: string | undefined) => void, +) { + const currentParams = action.payload.params as RootStackParamList[typeof SCREENS.SEARCH.CENTRAL_PANE]; + const queryJSON = SearchQueryUtils.buildSearchQueryJSON(currentParams.q); + + if (!queryJSON) { + return null; + } + + if (!queryJSON.policyID) { + const policyID = getPolicyIDFromState(state as State); + + if (policyID) { + queryJSON.policyID = policyID; + } else { + delete queryJSON.policyID; + } + } else { + setActiveWorkspaceID(queryJSON.policyID); + } + + const modifiedAction = { + ...action, + payload: { + ...action.payload, + params: { + ...action.payload.params, + q: SearchQueryUtils.buildSearchQueryString(queryJSON), + }, + }, + }; + + return stackRouter.getStateForAction(state, modifiedAction, configOptions); +} + +function handleDismissModalAction( + state: StackNavigationState, + action: DismissModalActionType, + configOptions: RouterConfigOptions, + stackRouter: Router, CommonActions.Action | StackActionType>, +) { + const lastRoute = state.routes.at(-1); + const newAction = StackActions.pop(); + action; + if (!lastRoute?.name || !MODAL_ROUTES_TO_DISMISS.includes(lastRoute?.name)) { + Log.hmmm('[Navigation] dismissModal failed because there is no modal stack to dismiss'); + return null; + } + + return stackRouter.getStateForAction(state, newAction, configOptions); +} + +export {handleDismissModalAction, handlePushReportAction, handlePushSearchPageAction, handleSwitchPolicyID}; diff --git a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/types.ts b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/types.ts index 09d35e2a1680..9f19ede081cd 100644 --- a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/types.ts +++ b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/types.ts @@ -1,5 +1,25 @@ -import type {DefaultNavigatorOptions, ParamListBase, StackNavigationState, StackRouterOptions} from '@react-navigation/native'; +import type {CommonActions, DefaultNavigatorOptions, ParamListBase, StackActionType, StackNavigationState, StackRouterOptions} from '@react-navigation/native'; import type {StackNavigationEventMap, StackNavigationOptions} from '@react-navigation/stack'; +import type CONST from '@src/CONST'; + +type CustomRouterActionType = + | { + type: typeof CONST.NAVIGATION.ACTION_TYPE.SWITCH_POLICY_ID; + payload: { + policyID: string; + }; + } + | {type: typeof CONST.NAVIGATION.ACTION_TYPE.DISMISS_MODAL}; + +type SwitchPolicyIdActionType = CustomRouterActionType & { + type: typeof CONST.NAVIGATION.ACTION_TYPE.SWITCH_POLICY_ID; +}; + +type PushActionType = StackActionType & {type: typeof CONST.NAVIGATION.ACTION_TYPE.PUSH}; + +type DismissModalActionType = CustomRouterActionType & { + type: typeof CONST.NAVIGATION.ACTION_TYPE.DISMISS_MODAL; +}; type ResponsiveStackNavigatorConfig = { isSmallScreenWidth: boolean; @@ -10,4 +30,15 @@ type ResponsiveStackNavigatorRouterOptions = StackRouterOptions; type ResponsiveStackNavigatorProps = DefaultNavigatorOptions, StackNavigationOptions, StackNavigationEventMap> & ResponsiveStackNavigatorConfig; -export type {ResponsiveStackNavigatorRouterOptions, ResponsiveStackNavigatorProps, ResponsiveStackNavigatorConfig}; +type CustomRouterAction = CommonActions.Action | StackActionType | CustomRouterActionType; + +export type { + SwitchPolicyIdActionType, + PushActionType, + DismissModalActionType, + CustomRouterAction, + CustomRouterActionType, + ResponsiveStackNavigatorRouterOptions, + ResponsiveStackNavigatorProps, + ResponsiveStackNavigatorConfig, +}; diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 99ccf6d91bd1..f816085f5325 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -239,7 +239,7 @@ function goUp(fallbackRoute: Route, options?: GoUpOptions) { // If we need to pop more than one route from rootState, we replace the current route to not lose visited routes from the navigation state if (indexOfFallbackRoute === -1 || (isRootNavigatorState(targetState) && distanceToPop > 1)) { - const replaceAction = {...minimalAction, type: 'REPLACE'} as NavigationAction; + const replaceAction = {...minimalAction, type: CONST.NAVIGATION.ACTION_TYPE.REPLACE} as NavigationAction; navigationRef.current.dispatch(replaceAction); return; } @@ -456,7 +456,7 @@ function navigateToReportWithPolicyCheck({report, reportID, reportActionID, refe // @TODO In places where we use dismissModal with report arg we should do dismiss modal and then navigate to the report. // We left it here to limit the number of changed files. const dismissModal = (reportID?: string, ref = navigationRef) => { - ref.dispatch({type: 'DISMISS_MODAL'}); + ref.dispatch({type: CONST.NAVIGATION.ACTION_TYPE.DISMISS_MODAL}); if (!reportID) { return; } From 061f2cae805912d80859bf26bf04a1754b88ed35 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 18 Nov 2024 11:36:11 +0100 Subject: [PATCH 4/9] Fix types in RELATIONS and getAdaptedStateFromPath --- .../Navigation/linkingConfig/RELATIONS/SETTINGS_TO_RHP.ts | 3 ++- .../Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts | 5 +++-- .../Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts | 3 ++- src/libs/Navigation/linkingConfig/RELATIONS/index.ts | 3 +-- .../Navigation/linkingConfig/getAdaptedStateFromPath.ts | 7 +++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/SETTINGS_TO_RHP.ts b/src/libs/Navigation/linkingConfig/RELATIONS/SETTINGS_TO_RHP.ts index b4afc15366d3..6e7c15ce3a16 100755 --- a/src/libs/Navigation/linkingConfig/RELATIONS/SETTINGS_TO_RHP.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/SETTINGS_TO_RHP.ts @@ -1,7 +1,8 @@ +import type {SettingsSplitNavigatorParamList} from '@libs/Navigation/types'; import SCREENS from '@src/SCREENS'; // This file is used to define relation between settings split navigator's central screens and RHP screens. -const CENTRAL_PANE_TO_RHP_MAPPING: Record = { +const CENTRAL_PANE_TO_RHP_MAPPING: Partial> = { [SCREENS.SETTINGS.PROFILE.ROOT]: [ SCREENS.SETTINGS.PROFILE.DISPLAY_NAME, SCREENS.SETTINGS.PROFILE.CONTACT_METHODS, diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts b/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts index 246c9d29a664..a07ef3b8b9ac 100644 --- a/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/SIDEBAR_TO_RHP.ts @@ -1,8 +1,9 @@ +import type {SplitNavigatorLHNScreen} from '@libs/Navigation/types'; import SCREENS from '@src/SCREENS'; // This file is used to define the relationship between the sidebar (LHN) and the right hand pane (RHP) screen. -// Those screens doesn't care about the split navigator's central screen and are in relation directly to the sidebar. -const SIDEBAR_TO_RHP: Record = { +// These screens don't care about the split navigator's central screen and are in relation directly to the sidebar. +const SIDEBAR_TO_RHP: Partial> = { [SCREENS.SETTINGS.ROOT]: [ SCREENS.SETTINGS.SHARE_CODE, SCREENS.SETTINGS.PROFILE.STATUS, diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts b/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts index 39062de76510..fd492cd85800 100755 --- a/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/WORKSPACE_TO_RHP.ts @@ -1,7 +1,8 @@ +import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; import SCREENS from '@src/SCREENS'; // This file is used to define relation between workspace split navigator's central screens and RHP screens. -const WORKSPACE_TO_RHP: Record = { +const WORKSPACE_TO_RHP: Partial> = { [SCREENS.WORKSPACE.PROFILE]: [SCREENS.WORKSPACE.NAME, SCREENS.WORKSPACE.ADDRESS, SCREENS.WORKSPACE.CURRENCY, SCREENS.WORKSPACE.DESCRIPTION, SCREENS.WORKSPACE.SHARE], [SCREENS.WORKSPACE.MEMBERS]: [ SCREENS.WORKSPACE.INVITE, diff --git a/src/libs/Navigation/linkingConfig/RELATIONS/index.ts b/src/libs/Navigation/linkingConfig/RELATIONS/index.ts index 4e3e6d7543e2..90865784f68c 100644 --- a/src/libs/Navigation/linkingConfig/RELATIONS/index.ts +++ b/src/libs/Navigation/linkingConfig/RELATIONS/index.ts @@ -4,8 +4,7 @@ import SIDEBAR_TO_RHP from './SIDEBAR_TO_RHP'; import SIDEBAR_TO_SPLIT from './SIDEBAR_TO_SPLIT'; import WORKSPACE_TO_RHP from './WORKSPACE_TO_RHP'; -// @TODO: fix types -function createInverseRelation(relations: Record): Record { +function createInverseRelation(relations: Partial>): Record { const reversedRelations = {} as Record; Object.entries(relations).forEach(([key, values]) => { diff --git a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts index d7728f35ba5f..1f9c6e83876d 100644 --- a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts @@ -70,10 +70,9 @@ function getMatchingFullScreenRoute(route: NavigationPartialRoute, policyID?: st } if (RELATIONS.RHP_TO_SIDEBAR[route.name]) { - // @TODO: Figure out better types for this. return createSplitNavigator( { - name: RELATIONS.RHP_TO_SIDEBAR[route.name] as typeof SCREENS.HOME, + name: RELATIONS.RHP_TO_SIDEBAR[route.name], }, undefined, policyID ? {policyID} : undefined, @@ -90,7 +89,7 @@ function getMatchingFullScreenRoute(route: NavigationPartialRoute, policyID?: st params: paramsFromRoute.length > 0 ? pick(route.params, paramsFromRoute) : undefined, }, { - name: RELATIONS.RHP_TO_WORKSPACE[route.name] as keyof WorkspaceSplitNavigatorParamList, + name: RELATIONS.RHP_TO_WORKSPACE[route.name], params: paramsFromRoute.length > 0 ? pick(route.params, paramsFromRoute) : undefined, }, ); @@ -104,7 +103,7 @@ function getMatchingFullScreenRoute(route: NavigationPartialRoute, policyID?: st name: SCREENS.SETTINGS.ROOT, }, { - name: RELATIONS.RHP_TO_SETTINGS[route.name] as keyof SettingsSplitNavigatorParamList, + name: RELATIONS.RHP_TO_SETTINGS[route.name], params: paramsFromRoute.length > 0 ? pick(route.params, paramsFromRoute) : undefined, }, ); From 3659ad019a679d58f648c8f16e11164675491729 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 18 Nov 2024 11:51:37 +0100 Subject: [PATCH 5/9] Remove @todo comment from getAdaptedStateFromPath --- src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts index 1f9c6e83876d..decb1ae483d3 100644 --- a/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts +++ b/src/libs/Navigation/linkingConfig/getAdaptedStateFromPath.ts @@ -79,7 +79,6 @@ function getMatchingFullScreenRoute(route: NavigationPartialRoute, policyID?: st ); } - // @TODO We can think about handling it in one condition. if (RELATIONS.RHP_TO_WORKSPACE[route.name]) { const paramsFromRoute = getParamsFromRoute(RELATIONS.RHP_TO_WORKSPACE[route.name]); From 62b1cda0cfee44f661f7a880e5a9fee3600f66df Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 18 Nov 2024 12:39:35 +0100 Subject: [PATCH 6/9] Remove NAVIGATION.TYPE.UP --- src/CONST.ts | 3 --- src/libs/actions/Report.ts | 4 ++-- src/pages/EnablePayments/EnablePaymentsPage.tsx | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 3df06347cd97..370cf5bd8977 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -4531,9 +4531,6 @@ const CONST = { SF_COORDINATES: [-122.4194, 37.7749], NAVIGATION: { - TYPE: { - UP: 'UP', - }, ACTION_TYPE: { REPLACE: 'REPLACE', PUSH: 'PUSH', diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 1673a84cde51..c139f7e37826 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1391,7 +1391,7 @@ function handleReportChanged(report: OnyxEntry) { const currCallback = callback; callback = () => { currCallback(); - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.preexistingReportID ?? '-1'), CONST.NAVIGATION.TYPE.UP); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.preexistingReportID ?? '-1'), CONST.NAVIGATION.ACTION_TYPE.REPLACE); }; // The report screen will listen to this event and transfer the draft comment to the existing report @@ -2795,7 +2795,7 @@ function navigateToMostRecentReport(currentReport: OnyxEntry) { Navigation.goBack(); } - navigateToConciergeChat(false, () => true, CONST.NAVIGATION.TYPE.UP); + navigateToConciergeChat(false, () => true, CONST.NAVIGATION.ACTION_TYPE.REPLACE); } } diff --git a/src/pages/EnablePayments/EnablePaymentsPage.tsx b/src/pages/EnablePayments/EnablePaymentsPage.tsx index 1384875fe031..4268b4cfd575 100644 --- a/src/pages/EnablePayments/EnablePaymentsPage.tsx +++ b/src/pages/EnablePayments/EnablePaymentsPage.tsx @@ -40,7 +40,7 @@ function EnablePaymentsPage({userWallet}: EnablePaymentsPageProps) { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing if (isPendingOnfidoResult || hasFailedOnfido) { - Navigation.navigate(ROUTES.SETTINGS_WALLET, CONST.NAVIGATION.TYPE.UP); + Navigation.navigate(ROUTES.SETTINGS_WALLET, CONST.NAVIGATION.ACTION_TYPE.REPLACE); return; } From 20efb77279abb8724630baa196c201d9c510870a Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 18 Nov 2024 14:13:21 +0100 Subject: [PATCH 7/9] Remove passing CONST.NAVIGATION.ACTION_TYPE.PUSH as a type param to Navigation.navigate --- src/libs/actions/Report.ts | 2 +- .../settings/Wallet/Card/GetPhysicalCardConfirm.tsx | 9 ++++----- .../workflows/approvals/ApprovalWorkflowEditor.tsx | 9 +++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index c139f7e37826..519f8429ecd6 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2761,7 +2761,7 @@ function openReportFromDeepLink(url: string) { return; } - Navigation.navigate(route as Route, CONST.NAVIGATION.ACTION_TYPE.PUSH); + Navigation.navigate(route as Route); }; // We need skip deeplinking if the user hasn't completed the guided setup flow. diff --git a/src/pages/settings/Wallet/Card/GetPhysicalCardConfirm.tsx b/src/pages/settings/Wallet/Card/GetPhysicalCardConfirm.tsx index 15354c3cdfb8..17c726ca2b10 100644 --- a/src/pages/settings/Wallet/Card/GetPhysicalCardConfirm.tsx +++ b/src/pages/settings/Wallet/Card/GetPhysicalCardConfirm.tsx @@ -1,7 +1,7 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React from 'react'; -import {withOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; +import {withOnyx} from 'react-native-onyx'; import * as Expensicons from '@components/Icon/Expensicons'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import Text from '@components/Text'; @@ -10,7 +10,6 @@ import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; import type {SettingsNavigatorParamList} from '@navigation/types'; -import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; @@ -18,15 +17,15 @@ import type {GetPhysicalCardForm} from '@src/types/form'; import BaseGetPhysicalCard from './BaseGetPhysicalCard'; const goToGetPhysicalCardName = (domain: string) => { - Navigation.navigate(ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_NAME.getRoute(domain), CONST.NAVIGATION.ACTION_TYPE.PUSH); + Navigation.navigate(ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_NAME.getRoute(domain)); }; const goToGetPhysicalCardPhone = (domain: string) => { - Navigation.navigate(ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_PHONE.getRoute(domain), CONST.NAVIGATION.ACTION_TYPE.PUSH); + Navigation.navigate(ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_PHONE.getRoute(domain)); }; const goToGetPhysicalCardAddress = (domain: string) => { - Navigation.navigate(ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_ADDRESS.getRoute(domain), CONST.NAVIGATION.ACTION_TYPE.PUSH); + Navigation.navigate(ROUTES.SETTINGS_WALLET_CARD_GET_PHYSICAL_ADDRESS.getRoute(domain)); }; type GetPhysicalCardConfirmOnyxProps = { diff --git a/src/pages/workspace/workflows/approvals/ApprovalWorkflowEditor.tsx b/src/pages/workspace/workflows/approvals/ApprovalWorkflowEditor.tsx index 5241b6671e26..1ac3f6789993 100644 --- a/src/pages/workspace/workflows/approvals/ApprovalWorkflowEditor.tsx +++ b/src/pages/workspace/workflows/approvals/ApprovalWorkflowEditor.tsx @@ -97,13 +97,13 @@ function ApprovalWorkflowEditor({approvalWorkflow, removeApprovalWorkflow, polic const editMembers = useCallback(() => { const backTo = approvalWorkflow.action === CONST.APPROVAL_WORKFLOW.ACTION.CREATE ? ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(policyID) : undefined; - Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(policyID, backTo), CONST.NAVIGATION.ACTION_TYPE.PUSH); + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_EXPENSES_FROM.getRoute(policyID, backTo)); }, [approvalWorkflow.action, policyID]); const editApprover = useCallback( (approverIndex: number) => { const backTo = approvalWorkflow.action === CONST.APPROVAL_WORKFLOW.ACTION.CREATE ? ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(policyID) : undefined; - Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approverIndex, backTo), CONST.NAVIGATION.ACTION_TYPE.PUSH); + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approverIndex, backTo)); }, [approvalWorkflow.action, policyID], ); @@ -114,10 +114,7 @@ function ApprovalWorkflowEditor({approvalWorkflow, removeApprovalWorkflow, polic Navigation.navigate(ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.approvals.alias, Navigation.getActiveRoute())); return; } - Navigation.navigate( - ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approverCount, ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(policyID)), - CONST.NAVIGATION.ACTION_TYPE.PUSH, - ); + Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_APPROVER.getRoute(policyID, approverCount, ROUTES.WORKSPACE_WORKFLOWS_APPROVALS_NEW.getRoute(policyID))); }, [approverCount, policy, policyID]); return ( From 2df2704865d7adf0922ffae796dc26f59f3fe4b6 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 18 Nov 2024 14:35:39 +0100 Subject: [PATCH 8/9] Fix lint in CustomRouter.ts --- .../createCustomStackNavigator/CustomRouter.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts index bec622f1a953..31caba3b2e24 100644 --- a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts +++ b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts @@ -11,14 +11,7 @@ import NAVIGATORS from '@src/NAVIGATORS'; import SCREENS from '@src/SCREENS'; import * as GetStateForActionHandlers from './GetStateForActionHandlers'; import syncBrowserHistory from './syncBrowserHistory'; -import type { - CustomRouterActionType, - CustomRouterAction, - DismissModalActionType, - PushActionType, - SwitchPolicyIdActionType, - ResponsiveStackNavigatorRouterOptions, -} from './types'; +import type {CustomRouterAction, CustomRouterActionType, DismissModalActionType, PushActionType, ResponsiveStackNavigatorRouterOptions, SwitchPolicyIdActionType} from './types'; function isSwitchPolicyIdAction(action: CustomRouterAction): action is SwitchPolicyIdActionType { return action.type === CONST.NAVIGATION.ACTION_TYPE.SWITCH_POLICY_ID; From 4849fb70128ed515075e611b7219962f27c90999 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 18 Nov 2024 15:30:51 +0100 Subject: [PATCH 9/9] Rename shouldDismissSideModalNavigator to isNavigatingToModalFromModal --- .../AppNavigator/createCustomStackNavigator/CustomRouter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts index 31caba3b2e24..f678425e2ec5 100644 --- a/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts +++ b/src/libs/Navigation/AppNavigator/createCustomStackNavigator/CustomRouter.ts @@ -41,7 +41,7 @@ function shouldPreventReset(state: StackNavigationState, action: return false; } -function shouldDismissSideModalNavigator(state: StackNavigationState, action: CommonActions.Action | StackActionType) { +function isNavigatingToModalFromModal(state: StackNavigationState, action: CommonActions.Action | StackActionType) { if (action.type !== CONST.NAVIGATION.ACTION_TYPE.PUSH) { return false; } @@ -88,7 +88,7 @@ function CustomRouter(options: ResponsiveStackNavigatorRouterOptions) { return state; } - if (shouldDismissSideModalNavigator(state, action)) { + if (isNavigatingToModalFromModal(state, action)) { const modifiedState = {...state, routes: state.routes.slice(0, -1), index: state.index !== 0 ? state.index - 1 : 0}; return stackRouter.getStateForAction(modifiedState, action, configOptions); }