From 57557b1837719187e7eec2b54ba185f6df0411e9 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 29 Apr 2025 17:24:43 +0200 Subject: [PATCH 01/17] add getter for popState variable (still needs rename) --- src/libs/Navigation/Navigation.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index b82f64e037bb..0359d774463b 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -62,6 +62,14 @@ function setShouldPopAllStateOnUP(shouldPopAllStateFlag: boolean) { shouldPopAllStateOnUP = shouldPopAllStateFlag; } +/** + * Returns shouldPopAllStateOnUp variable used to determine whether should we pop all state back to LHN + * @returns shouldPopAllStateOnUp + */ +function getShouldPopAllStateOnUp() { + return shouldPopAllStateOnUP; +} + /** * Checks if the navigationRef is ready to perform a method. */ @@ -632,6 +640,7 @@ function removeScreenByKey(key: string) { export default { setShouldPopAllStateOnUP, + getShouldPopAllStateOnUp, navigate, setParams, dismissModal, From 64f289c147a46df72b1f8efddaaa205a261a605e Mon Sep 17 00:00:00 2001 From: borys3kk Date: Wed, 7 May 2025 15:55:13 +0200 Subject: [PATCH 02/17] start working on refactor --- src/libs/Navigation/Navigation.ts | 71 ++++++++++++++----- src/libs/Navigation/NavigationRoot.tsx | 6 +- src/libs/actions/Report.ts | 3 +- src/libs/navigateAfterJoinRequest.ts | 8 ++- src/pages/TeachersUnite/SaveTheWorldPage.tsx | 2 +- src/pages/home/ReportScreen.tsx | 23 ++++-- src/pages/settings/AboutPage/AboutPage.tsx | 2 +- .../settings/Preferences/PreferencesPage.tsx | 2 +- src/pages/settings/Profile/ProfilePage.tsx | 8 ++- .../Security/SecuritySettingsPage.tsx | 2 +- .../Subscription/SubscriptionSettingsPage.tsx | 8 ++- .../Troubleshoot/TroubleshootPage.tsx | 2 +- .../settings/Wallet/WalletPage/WalletPage.tsx | 2 +- src/pages/workspace/WorkspaceJoinUserPage.tsx | 8 ++- 14 files changed, 112 insertions(+), 35 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 4e8cd40ce3e8..e79b7662d17b 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -36,6 +36,7 @@ import switchPolicyID from './helpers/switchPolicyID'; import {linkingConfig} from './linkingConfig'; import navigationRef from './navigationRef'; import type {NavigationPartialRoute, NavigationRoute, NavigationStateRoute, RootNavigatorParamList, State} from './types'; +import { SPLIT_TO_SIDEBAR } from './linkingConfig/RELATIONS'; // Routes which are part of the flow to set up 2FA const SET_UP_2FA_ROUTES: Route[] = [ @@ -73,13 +74,22 @@ const navigationIsReadyPromise = new Promise((resolve) => { let pendingRoute: Route | null = null; -let shouldPopAllStateOnUP = false; +let shouldPopToSidebar = false; /** * Inform the navigation that next time user presses UP we should pop all the state back to LHN. + * TODO change content of comment */ -function setShouldPopAllStateOnUP(shouldPopAllStateFlag: boolean) { - shouldPopAllStateOnUP = shouldPopAllStateFlag; +function setShouldPopToSidebar(shouldPopAllStateFlag: boolean) { + shouldPopToSidebar = shouldPopAllStateFlag; +} + +/** + * Returns shouldPopToSidebar variable used to determine whether should we pop all state back to LHN + * @returns shouldPopToSidebar + */ +function getShouldPopToSidebar() { + return shouldPopToSidebar; } type CanNavigateParams = { @@ -268,7 +278,7 @@ type GoBackOptions = { /** * Specifies whether goBack should pop to top when invoked. - * Additionaly, to execute popToTop, set the value of the global variable ShouldPopAllStateOnUP to true using the setShouldPopAllStateOnUP function. + * Additionaly, to execute popToTop, set the value of the global variable shouldPopToSidebar to true using the setShouldPopToSidebar function. */ shouldPopToTop?: boolean; }; @@ -344,13 +354,12 @@ function goBack(backToRoute?: Route, options?: GoBackOptions) { return; } - if (options?.shouldPopToTop) { - if (shouldPopAllStateOnUP) { - shouldPopAllStateOnUP = false; - navigationRef.current?.dispatch(StackActions.popToTop()); - return; - } - } + // if (options?.shouldPopToTop) { + // if (shouldPopToSidebar) { + // popToSidebar(); + // return; + // } + // } if (backToRoute) { goUp(backToRoute, options); @@ -365,6 +374,35 @@ function goBack(backToRoute?: Route, options?: GoBackOptions) { navigationRef.current?.goBack(); } +function popToSidebar() { + setShouldPopToSidebar(false); + + const rootState = navigationRef.current?.getRootState(); + const topRoute = rootState?.routes.at(0); + const lastRoute = rootState?.routes.at(-1); + + console.log("Pop to sidebar const: \n", rootState, topRoute, lastRoute); + + if (!(lastRoute?.name in SPLIT_TO_SIDEBAR)){ + console.log("popToSIdebar not work"); + Log.hmmm('[popToSidebar] must be invoked only from SplitNavigator') + return; + } + + console.log("Split to sidebar: ", topRoute?.name, lastRoute?.name, SPLIT_TO_SIDEBAR[topRoute?.name]); + + if (topRoute?.name !== SPLIT_TO_SIDEBAR[lastRoute.name]){ + // replace so we have sidebar + // navigationRef.current?.dispatch(StackActions.replace) + // goBack(SPLIT_TO_SIDEBAR[lastRoute.name] as Route); + console.log("replacing"); + goBack(ROUTES.SETTINGS); + return; + } + console.log("popping all state"); + navigationRef.current?.dispatch(StackActions.popToTop()); +} + /** * Reset the navigation state to Home page. */ @@ -616,15 +654,15 @@ const dismissModalWithReport = (navigateToReportPayload: NavigateToReportWithPol }; /** - * Returns to the first screen in the stack, dismissing all the others, only if the global variable shouldPopAllStateOnUP is set to true. + * Returns to the first screen in the stack, dismissing all the others, only if the global variable shouldPopToSidebar is set to true. */ function popToTop() { - if (!shouldPopAllStateOnUP) { + if (!shouldPopToSidebar) { goBack(); return; } - shouldPopAllStateOnUP = false; + shouldPopToSidebar = false; navigationRef.current?.dispatch(StackActions.popToTop()); } @@ -671,8 +709,9 @@ function isOnboardingFlow() { } export default { - setShouldPopAllStateOnUP, - getShouldPopAllStateOnUp, + setShouldPopToSidebar, + getShouldPopToSidebar, + popToSidebar, navigate, setParams, dismissModal, diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 93e2d9c82d6f..07f759c90839 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -169,14 +169,15 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N return; } - // After resizing the screen from wide to narrow, if we have visited multiple central screens, we want to go back to the LHN screen, so we set shouldPopAllStateOnUP to true. + // After resizing the screen from wide to narrow, if we have visited multiple central screens, we want to go back to the LHN screen, so we set shouldPopToSidebar to true. // Now when this value is true, Navigation.goBack with the option {shouldPopToTop: true} will remove all visited central screens in the given tab from the navigation stack and go back to the LHN. // More context here: https://github.com/Expensify/App/pull/59300 if (!shouldUseNarrowLayout) { return; } - Navigation.setShouldPopAllStateOnUP(true); + Navigation.setShouldPopToSidebar(true); + console.log('shouldPopToSidebar: ', Navigation.getShouldPopToSidebar()); }, [shouldUseNarrowLayout]); useEffect(() => { @@ -222,6 +223,7 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N }, 0); parseAndLogRoute(state); + console.log('state', state); // We want to clean saved scroll offsets for screens that aren't anymore in the state. cleanStaleScrollOffsets(state); cleanPreservedNavigatorStates(state); diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 9d0f51c8321c..0b47dd0e3b07 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2896,8 +2896,7 @@ function deleteReport(reportID: string | undefined, shouldDeleteChildReports = f function navigateToConciergeChatAndDeleteReport(reportID: string | undefined, shouldPopToTop = false, shouldDeleteChildReports = false) { // Dismiss the current report screen and replace it with Concierge Chat if (shouldPopToTop) { - Navigation.setShouldPopAllStateOnUP(true); - Navigation.goBack(undefined, {shouldPopToTop: true}); + Navigation.popToSidebar(); // it can break because of redirection to settings main } else { Navigation.goBack(); } diff --git a/src/libs/navigateAfterJoinRequest.ts b/src/libs/navigateAfterJoinRequest.ts index 3e99948ca85d..74b9773afb38 100644 --- a/src/libs/navigateAfterJoinRequest.ts +++ b/src/libs/navigateAfterJoinRequest.ts @@ -2,7 +2,13 @@ import ROUTES from '@src/ROUTES'; import Navigation from './Navigation/Navigation'; const navigateAfterJoinRequest = () => { - Navigation.goBack(undefined, {shouldPopToTop: true}); + // Navigation.goBack(undefined, {shouldPopToTop: true}); + if (Navigation.getShouldPopToSidebar()) { + Navigation.popToSidebar(); + } + else { + Navigation.goBack(); + } Navigation.setNavigationActionToMicrotaskQueue(() => { Navigation.navigate(ROUTES.SETTINGS_WORKSPACES.route); }); diff --git a/src/pages/TeachersUnite/SaveTheWorldPage.tsx b/src/pages/TeachersUnite/SaveTheWorldPage.tsx index ce4c8b230f3c..c1c04bb25327 100644 --- a/src/pages/TeachersUnite/SaveTheWorldPage.tsx +++ b/src/pages/TeachersUnite/SaveTheWorldPage.tsx @@ -57,7 +57,7 @@ function SaveTheWorldPage() { title={translate('sidebarScreen.saveTheWorld')} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.goBack(undefined, {shouldPopToTop: true})} + onBackButtonPress={() => Navigation.popToSidebar()} // shouldpoptotop icon={Illustrations.TeachersUnite} shouldUseHeadlineHeader /> diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index fa77921cb446..b69f22b2403b 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -324,17 +324,31 @@ function ReportScreen({route, navigation}: ReportScreenProps) { wasReportAccessibleRef.current = true; }, [report]); - const backTo = route?.params?.backTo as string; + const backTo = route?.params?.backTo as string; // here too const onBackButtonPress = useCallback(() => { + console.log('something happening here'); + console.log('shouldPopToSidebar', Navigation.getShouldPopToSidebar()); + if (isInNarrowPaneModal && backTo !== SCREENS.SEARCH.REPORT_RHP) { + // TODO not good Navigation.dismissModal(); return; } if (backTo) { - Navigation.goBack(backTo as Route, {shouldPopToTop: true}); + // Navigation.goBack(backTo as Route, {shouldPopToTop: true}); + if (Navigation.getShouldPopToSidebar()) { + Navigation.popToSidebar(); + return; + } + Navigation.goBack(backTo as Route); + return; + } + // Navigation.goBack(undefined, {shouldPopToTop: true}); + if (Navigation.getShouldPopToSidebar()) { + Navigation.popToSidebar(); return; } - Navigation.goBack(undefined, {shouldPopToTop: true}); + Navigation.goBack(); }, [isInNarrowPaneModal, backTo]); let headerView = ( @@ -600,9 +614,8 @@ function ReportScreen({route, navigation}: ReportScreenProps) { } Navigation.dismissModal(); if (Navigation.getTopmostReportId() === prevOnyxReportID) { - Navigation.setShouldPopAllStateOnUP(true); Navigation.isNavigationReady().then(() => { - Navigation.goBack(undefined, {shouldPopToTop: true}); + Navigation.popToSidebar(); // shouldpoptotop }); } if (prevReport?.parentReportID) { diff --git a/src/pages/settings/AboutPage/AboutPage.tsx b/src/pages/settings/AboutPage/AboutPage.tsx index a0f86c2c2e26..cdc5ed465161 100644 --- a/src/pages/settings/AboutPage/AboutPage.tsx +++ b/src/pages/settings/AboutPage/AboutPage.tsx @@ -142,7 +142,7 @@ function AboutPage() { title={translate('initialSettingsPage.about')} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS, {shouldPopToTop: true})} + onBackButtonPress={() => Navigation.popToSidebar()} // shouldpoptotop icon={Illustrations.PalmTree} shouldUseHeadlineHeader /> diff --git a/src/pages/settings/Preferences/PreferencesPage.tsx b/src/pages/settings/Preferences/PreferencesPage.tsx index 2a24f657fbca..29803e1cd1e3 100755 --- a/src/pages/settings/Preferences/PreferencesPage.tsx +++ b/src/pages/settings/Preferences/PreferencesPage.tsx @@ -53,7 +53,7 @@ function PreferencesPage() { shouldUseHeadlineHeader shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.goBack(undefined, {shouldPopToTop: true})} + onBackButtonPress={() => Navigation.popToSidebar()} // shouldpoptotop /> diff --git a/src/pages/settings/Profile/ProfilePage.tsx b/src/pages/settings/Profile/ProfilePage.tsx index e57fc99d5711..ab791406ddf6 100755 --- a/src/pages/settings/Profile/ProfilePage.tsx +++ b/src/pages/settings/Profile/ProfilePage.tsx @@ -152,7 +152,13 @@ function ProfilePage() { > Navigation.goBack(route.params?.backTo, {shouldPopToTop: true})} + onBackButtonPress={() => { + if (Navigation.getShouldPopToSidebar()) { + Navigation.popToSidebar(); + return; + } + Navigation.goBack(route.params?.backTo); + }} // sprawdzenie zmiennej i handlowanie shouldpoptotop shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter icon={Illustrations.Profile} diff --git a/src/pages/settings/Security/SecuritySettingsPage.tsx b/src/pages/settings/Security/SecuritySettingsPage.tsx index 9ec999949fef..058a5d5b2409 100644 --- a/src/pages/settings/Security/SecuritySettingsPage.tsx +++ b/src/pages/settings/Security/SecuritySettingsPage.tsx @@ -265,7 +265,7 @@ function SecuritySettingsPage() { Navigation.goBack(undefined, {shouldPopToTop: true})} + onBackButtonPress={() => Navigation.popToSidebar()} // shouldpoptotop icon={Illustrations.LockClosed} shouldUseHeadlineHeader shouldDisplaySearchRouter diff --git a/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx b/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx index 05bc55f6c0ba..a113f21388d1 100644 --- a/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx +++ b/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx @@ -49,7 +49,13 @@ function SubscriptionSettingsPage({route}: SubscriptionSettingsPageProps) { > Navigation.goBack(backTo, {shouldPopToTop: true})} + onBackButtonPress={() => { + if (Navigation.getShouldPopToSidebar()) { + Navigation.popToSidebar(); + return; + } + Navigation.goBack(backTo); + }} // tu sprawdzic globalna zmienna i powrot na backto shouldpoptotop shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter icon={Illustrations.CreditCardsNew} diff --git a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx index d23348bcad9d..119a3a32f00c 100644 --- a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx +++ b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx @@ -108,7 +108,7 @@ function TroubleshootPage() { title={translate('initialSettingsPage.aboutPage.troubleshoot')} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS, {shouldPopToTop: true})} + onBackButtonPress={() => Navigation.popToSidebar()} // tylko shouldpoptotop icon={Illustrations.Lightbulb} shouldUseHeadlineHeader /> diff --git a/src/pages/settings/Wallet/WalletPage/WalletPage.tsx b/src/pages/settings/Wallet/WalletPage/WalletPage.tsx index c2bb15df44b7..c8be575bca3d 100644 --- a/src/pages/settings/Wallet/WalletPage/WalletPage.tsx +++ b/src/pages/settings/Wallet/WalletPage/WalletPage.tsx @@ -389,7 +389,7 @@ function WalletPage({shouldListenForResize = false}: WalletPageProps) { shouldUseHeadlineHeader shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.goBack(undefined, {shouldPopToTop: true})} + onBackButtonPress={() => Navigation.popToSidebar()} // shouldpoptotop /> ); diff --git a/src/pages/workspace/WorkspaceJoinUserPage.tsx b/src/pages/workspace/WorkspaceJoinUserPage.tsx index 32da53dfa2c8..65fe1181080e 100644 --- a/src/pages/workspace/WorkspaceJoinUserPage.tsx +++ b/src/pages/workspace/WorkspaceJoinUserPage.tsx @@ -32,7 +32,13 @@ function WorkspaceJoinUserPage({route}: WorkspaceJoinUserPageProps) { } if (!isEmptyObject(policy) && !policy?.isJoinRequestPending && !isPendingDeletePolicy(policy)) { Navigation.isNavigationReady().then(() => { - Navigation.goBack(undefined, {shouldPopToTop: true}); + if (Navigation.getShouldPopToSidebar()) { + Navigation.popToSidebar(); + return; + } + Navigation.goBack(); + // Navigation.goBack(undefined, {shouldPopToTop: true}); + // Navigation.popToSidebar(); // shouldpoptotop Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); }); return; From b0611cb23f8e77974c74902a93b1eb95b27ac5be Mon Sep 17 00:00:00 2001 From: borys3kk Date: Thu, 8 May 2025 14:14:39 +0200 Subject: [PATCH 03/17] Add popToSidebar function, replace where shouldpoptotop was used --- src/libs/Navigation/Navigation.ts | 33 +++++++++---------- .../goBackFromWorkspaceCentralScreen.ts | 2 +- src/pages/home/ReportScreen.tsx | 8 ++--- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index e79b7662d17b..73eb6446910c 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -24,7 +24,7 @@ import originalCloseRHPFlow from './helpers/closeRHPFlow'; import getPolicyIDFromState from './helpers/getPolicyIDFromState'; import getStateFromPath from './helpers/getStateFromPath'; import getTopmostReportParams from './helpers/getTopmostReportParams'; -import {isFullScreenName, isOnboardingFlowName} from './helpers/isNavigatorName'; +import {isFullScreenName, isOnboardingFlowName, isSplitNavigatorName} from './helpers/isNavigatorName'; import isReportOpenInRHP from './helpers/isReportOpenInRHP'; import isSideModalNavigator from './helpers/isSideModalNavigator'; import linkTo from './helpers/linkTo'; @@ -34,9 +34,9 @@ import replaceWithSplitNavigator from './helpers/replaceWithSplitNavigator'; import setNavigationActionToMicrotaskQueue from './helpers/setNavigationActionToMicrotaskQueue'; import switchPolicyID from './helpers/switchPolicyID'; import {linkingConfig} from './linkingConfig'; +import {SPLIT_TO_SIDEBAR} from './linkingConfig/RELATIONS'; import navigationRef from './navigationRef'; import type {NavigationPartialRoute, NavigationRoute, NavigationStateRoute, RootNavigatorParamList, State} from './types'; -import { SPLIT_TO_SIDEBAR } from './linkingConfig/RELATIONS'; // Routes which are part of the flow to set up 2FA const SET_UP_2FA_ROUTES: Route[] = [ @@ -378,28 +378,25 @@ function popToSidebar() { setShouldPopToSidebar(false); const rootState = navigationRef.current?.getRootState(); - const topRoute = rootState?.routes.at(0); - const lastRoute = rootState?.routes.at(-1); + const currentRoute = rootState?.routes.at(-1); - console.log("Pop to sidebar const: \n", rootState, topRoute, lastRoute); - - if (!(lastRoute?.name in SPLIT_TO_SIDEBAR)){ - console.log("popToSIdebar not work"); - Log.hmmm('[popToSidebar] must be invoked only from SplitNavigator') + if (!isSplitNavigatorName(currentRoute?.name)) { + Log.hmmm('[popToSidebar] must be invoked only from SplitNavigator'); return; } + const topRoute = currentRoute.state?.routes.at(0); + const lastRoute = currentRoute.state?.routes.at(-1); + + if (topRoute?.name !== SPLIT_TO_SIDEBAR[currentRoute?.name]) { + const params = currentRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR ? {...lastRoute?.params} : undefined; - console.log("Split to sidebar: ", topRoute?.name, lastRoute?.name, SPLIT_TO_SIDEBAR[topRoute?.name]); - - if (topRoute?.name !== SPLIT_TO_SIDEBAR[lastRoute.name]){ - // replace so we have sidebar - // navigationRef.current?.dispatch(StackActions.replace) - // goBack(SPLIT_TO_SIDEBAR[lastRoute.name] as Route); - console.log("replacing"); - goBack(ROUTES.SETTINGS); + const currentRouteName = currentRoute?.name as keyof typeof SPLIT_TO_SIDEBAR; + const sidebarName = SPLIT_TO_SIDEBAR[currentRouteName]; + + navigationRef.dispatch({payload: {name: sidebarName, params}, type: CONST.NAVIGATION.ACTION_TYPE.REPLACE}); return; } - console.log("popping all state"); + navigationRef.current?.dispatch(StackActions.popToTop()); } diff --git a/src/libs/Navigation/helpers/goBackFromWorkspaceCentralScreen.ts b/src/libs/Navigation/helpers/goBackFromWorkspaceCentralScreen.ts index 5324bff9be0e..d7deb845af43 100644 --- a/src/libs/Navigation/helpers/goBackFromWorkspaceCentralScreen.ts +++ b/src/libs/Navigation/helpers/goBackFromWorkspaceCentralScreen.ts @@ -18,7 +18,7 @@ function goBackFromWorkspaceCentralScreen(policyID: string | undefined) { } if (lastRoute.state?.routes && lastRoute.state.routes.length > 1) { - Navigation.goBack(undefined, {shouldPopToTop: true}); + Navigation.popToSidebar(); return; } diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index b69f22b2403b..aa2153d12a56 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -324,18 +324,13 @@ function ReportScreen({route, navigation}: ReportScreenProps) { wasReportAccessibleRef.current = true; }, [report]); - const backTo = route?.params?.backTo as string; // here too + const backTo = route?.params?.backTo as string; const onBackButtonPress = useCallback(() => { - console.log('something happening here'); - console.log('shouldPopToSidebar', Navigation.getShouldPopToSidebar()); - if (isInNarrowPaneModal && backTo !== SCREENS.SEARCH.REPORT_RHP) { - // TODO not good Navigation.dismissModal(); return; } if (backTo) { - // Navigation.goBack(backTo as Route, {shouldPopToTop: true}); if (Navigation.getShouldPopToSidebar()) { Navigation.popToSidebar(); return; @@ -345,6 +340,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) { } // Navigation.goBack(undefined, {shouldPopToTop: true}); if (Navigation.getShouldPopToSidebar()) { + // need further investigation whether we can just pop to sidebar Navigation.popToSidebar(); return; } From cf9f0de95d089c32fdc5d03e6ac8668fa1d632af Mon Sep 17 00:00:00 2001 From: borys3kk Date: Thu, 8 May 2025 16:04:49 +0200 Subject: [PATCH 04/17] fix prettier lintchanged typecheck --- src/libs/Navigation/Navigation.ts | 6 ++++++ src/libs/Navigation/NavigationRoot.tsx | 2 -- src/libs/navigateAfterJoinRequest.ts | 3 +-- src/pages/settings/Profile/ProfilePage.tsx | 8 ++++---- src/pages/settings/Security/SecuritySettingsPage.tsx | 2 +- .../settings/Subscription/SubscriptionSettingsPage.tsx | 2 +- src/pages/settings/Troubleshoot/TroubleshootPage.tsx | 4 ++-- src/pages/workspace/WorkspaceJoinUserPage.tsx | 2 +- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 73eb6446910c..643ba3049840 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -380,10 +380,16 @@ function popToSidebar() { const rootState = navigationRef.current?.getRootState(); const currentRoute = rootState?.routes.at(-1); + if (!currentRoute) { + Log.hmmm("There's no current root in navigator"); + return; + } + if (!isSplitNavigatorName(currentRoute?.name)) { Log.hmmm('[popToSidebar] must be invoked only from SplitNavigator'); return; } + const topRoute = currentRoute.state?.routes.at(0); const lastRoute = currentRoute.state?.routes.at(-1); diff --git a/src/libs/Navigation/NavigationRoot.tsx b/src/libs/Navigation/NavigationRoot.tsx index 07f759c90839..87b558a21265 100644 --- a/src/libs/Navigation/NavigationRoot.tsx +++ b/src/libs/Navigation/NavigationRoot.tsx @@ -177,7 +177,6 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N } Navigation.setShouldPopToSidebar(true); - console.log('shouldPopToSidebar: ', Navigation.getShouldPopToSidebar()); }, [shouldUseNarrowLayout]); useEffect(() => { @@ -223,7 +222,6 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N }, 0); parseAndLogRoute(state); - console.log('state', state); // We want to clean saved scroll offsets for screens that aren't anymore in the state. cleanStaleScrollOffsets(state); cleanPreservedNavigatorStates(state); diff --git a/src/libs/navigateAfterJoinRequest.ts b/src/libs/navigateAfterJoinRequest.ts index 74b9773afb38..e245e31bb6b1 100644 --- a/src/libs/navigateAfterJoinRequest.ts +++ b/src/libs/navigateAfterJoinRequest.ts @@ -5,8 +5,7 @@ const navigateAfterJoinRequest = () => { // Navigation.goBack(undefined, {shouldPopToTop: true}); if (Navigation.getShouldPopToSidebar()) { Navigation.popToSidebar(); - } - else { + } else { Navigation.goBack(); } Navigation.setNavigationActionToMicrotaskQueue(() => { diff --git a/src/pages/settings/Profile/ProfilePage.tsx b/src/pages/settings/Profile/ProfilePage.tsx index ab791406ddf6..eaaf397368f2 100755 --- a/src/pages/settings/Profile/ProfilePage.tsx +++ b/src/pages/settings/Profile/ProfilePage.tsx @@ -45,11 +45,11 @@ function ProfilePage() { const {shouldUseNarrowLayout} = useResponsiveLayout(); const {safeAreaPaddingBottomStyle} = useSafeAreaPaddings(); const scrollEnabled = useScrollEnabled(); - const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST); - const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS); + const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST, {canBeMissing: true}); + const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS, {canBeMissing: true}); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const route = useRoute>(); - const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP); + const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); const getPronouns = (): string => { const pronounsKey = currentUserPersonalDetails?.pronouns?.replace(CONST.PRONOUNS.PREFIX, '') ?? ''; @@ -64,7 +64,7 @@ function ProfilePage() { const privateDetails = privatePersonalDetails ?? {}; const legalName = `${privateDetails.legalFirstName ?? ''} ${privateDetails.legalLastName ?? ''}`.trim(); - const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => !!account?.delegatedAccess?.delegate}); + const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: (account) => !!account?.delegatedAccess?.delegate, canBeMissing: true}); const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false); const publicOptions = [ diff --git a/src/pages/settings/Security/SecuritySettingsPage.tsx b/src/pages/settings/Security/SecuritySettingsPage.tsx index 058a5d5b2409..7c091a8b2570 100644 --- a/src/pages/settings/Security/SecuritySettingsPage.tsx +++ b/src/pages/settings/Security/SecuritySettingsPage.tsx @@ -52,7 +52,7 @@ function SecuritySettingsPage() { const personalDetails = usePersonalDetails(); const {canUseMergeAccounts} = usePermissions(); - const [account] = useOnyx(ONYXKEYS.ACCOUNT); + const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true}); const delegateButtonRef = useRef(null); const [shouldShowDelegatePopoverMenu, setShouldShowDelegatePopoverMenu] = useState(false); diff --git a/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx b/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx index a113f21388d1..5a1832eba977 100644 --- a/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx +++ b/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx @@ -33,7 +33,7 @@ function SubscriptionSettingsPage({route}: SubscriptionSettingsPageProps) { useEffect(() => { openSubscriptionPage(); }, []); - const [isAppLoading] = useOnyx(ONYXKEYS.IS_LOADING_APP); + const [isAppLoading] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true}); if (!subscriptionPlan && isAppLoading) { return ; diff --git a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx index 119a3a32f00c..aa4d6a2882d0 100644 --- a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx +++ b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx @@ -52,8 +52,8 @@ function TroubleshootPage() { const {shouldUseNarrowLayout} = useResponsiveLayout(); const illustrationStyle = getLightbulbIllustrationStyle(); const [isLoading, setIsLoading] = useState(false); - const [shouldStoreLogs] = useOnyx(ONYXKEYS.SHOULD_STORE_LOGS); - const [shouldMaskOnyxState = true] = useOnyx(ONYXKEYS.SHOULD_MASK_ONYX_STATE); + const [shouldStoreLogs] = useOnyx(ONYXKEYS.SHOULD_STORE_LOGS, {canBeMissing: true}); + const [shouldMaskOnyxState = true] = useOnyx(ONYXKEYS.SHOULD_MASK_ONYX_STATE, {canBeMissing: true}); const {resetOptions} = useOptionsList({shouldInitialize: false}); const exportOnyxState = useCallback(() => { diff --git a/src/pages/workspace/WorkspaceJoinUserPage.tsx b/src/pages/workspace/WorkspaceJoinUserPage.tsx index 65fe1181080e..b8406fb03ab9 100644 --- a/src/pages/workspace/WorkspaceJoinUserPage.tsx +++ b/src/pages/workspace/WorkspaceJoinUserPage.tsx @@ -21,7 +21,7 @@ type WorkspaceJoinUserPageProps = WorkspaceJoinUserPageRoute; function WorkspaceJoinUserPage({route}: WorkspaceJoinUserPageProps) { const styles = useThemeStyles(); const policyID = route?.params?.policyID; - const [policy, policyResult] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); + const [policy, policyResult] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: true}); const isPolicyLoading = isLoadingOnyxValue(policyResult); const inviterEmail = route?.params?.email; const isUnmounted = useRef(false); From 5a8967900b2476db47341b6508ef4265d2911296 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Thu, 8 May 2025 16:13:49 +0200 Subject: [PATCH 05/17] fix typecheck v2 --- src/libs/Navigation/Navigation.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 643ba3049840..fb1c2d4329e6 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -393,10 +393,10 @@ function popToSidebar() { const topRoute = currentRoute.state?.routes.at(0); const lastRoute = currentRoute.state?.routes.at(-1); - if (topRoute?.name !== SPLIT_TO_SIDEBAR[currentRoute?.name]) { + const currentRouteName = currentRoute?.name as keyof typeof SPLIT_TO_SIDEBAR; + if (topRoute?.name !== SPLIT_TO_SIDEBAR[currentRouteName]) { const params = currentRoute.name === NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR ? {...lastRoute?.params} : undefined; - const currentRouteName = currentRoute?.name as keyof typeof SPLIT_TO_SIDEBAR; const sidebarName = SPLIT_TO_SIDEBAR[currentRouteName]; navigationRef.dispatch({payload: {name: sidebarName, params}, type: CONST.NAVIGATION.ACTION_TYPE.REPLACE}); From 68078f3f7dae1859a77a5d8564a0c8f5405d08a4 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Fri, 9 May 2025 14:25:31 +0200 Subject: [PATCH 06/17] add popToSidebar tests --- tests/navigation/PopToSidebarTests.tsx | 127 +++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 tests/navigation/PopToSidebarTests.tsx diff --git a/tests/navigation/PopToSidebarTests.tsx b/tests/navigation/PopToSidebarTests.tsx new file mode 100644 index 000000000000..5232d131a363 --- /dev/null +++ b/tests/navigation/PopToSidebarTests.tsx @@ -0,0 +1,127 @@ +import {act, render} from '@testing-library/react-native'; +import React from 'react'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import getIsNarrowLayout from '@libs/getIsNarrowLayout'; +import Navigation from '@libs/Navigation/Navigation'; +import navigationRef from '@libs/Navigation/navigationRef'; +import CONST from '@src/CONST'; +import NAVIGATORS from '@src/NAVIGATORS'; +import ROUTES from '@src/ROUTES'; +import SCREENS from '@src/SCREENS'; +import TestNavigationContainer from '../utils/TestNavigationContainer'; + +jest.mock('@hooks/useResponsiveLayout', () => jest.fn()); +jest.mock('@libs/getIsNarrowLayout', () => jest.fn()); + +jest.mock('@pages/home/sidebar/NavigationTabBarAvatar'); +jest.mock('@src/components/Navigation/TopLevelNavigationTabBar'); +jest.mock('@components/ConfirmedRoute.tsx'); + +const mockedGetIsNarrowLayout = getIsNarrowLayout as jest.MockedFunction; +const mockedUseResponsiveLayout = useResponsiveLayout as jest.MockedFunction; + +describe('Pop to sidebar after resize from wide to narrow layout', () => { + beforeEach(() => { + mockedGetIsNarrowLayout.mockReturnValue(true); + mockedUseResponsiveLayout.mockReturnValue({...CONST.NAVIGATION_TESTS.DEFAULT_USE_RESPONSIVE_LAYOUT_VALUE, shouldUseNarrowLayout: true}); + }); + + describe('After clicking a few tabs in settings screen', () => { + it('Should pop all visited tabs and get back to settings root screen', () => { + render( + , + ); + + const settingsSplitBeforePopToSidebar = navigationRef.current?.getRootState().routes.at(-1); + expect(settingsSplitBeforePopToSidebar?.state?.index).toBe(3); + + // When we pop with LHN on top of stack + act(() => { + Navigation.popToSidebar(); + }); + + const settingsSplitAfterPopToSidebar = navigationRef.current?.getRootState().routes.at(-1); + expect(settingsSplitAfterPopToSidebar?.state?.index).toBe(0); + expect(settingsSplitAfterPopToSidebar?.state?.routes.at(-1)?.name).toBe(SCREENS.SETTINGS.ROOT); + }); + }); + + describe('After navigating to settings tabs from chat through link', () => { + it('Should replace the route with LHN', () => { + render( + , + ); + + const lastSplitBeforeNavigate = navigationRef.current?.getRootState().routes.at(-1); + expect(lastSplitBeforeNavigate?.name).toBe(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR); + + act(() => { + Navigation.navigate(ROUTES.SETTINGS_ABOUT); + }); + + const lastSplitAfterNavigate = navigationRef.current?.getRootState().routes.at(-1); + expect(lastSplitAfterNavigate?.name).toBe(NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR); + expect(lastSplitAfterNavigate?.state?.index).toBe(0); + expect(lastSplitAfterNavigate?.state?.routes.at(-1)?.name).toBe(SCREENS.SETTINGS.ABOUT); + + act(() => { + Navigation.popToSidebar(); + }); + + const lastSplitAfterPopToSidebar = navigationRef.current?.getRootState().routes.at(-1); + expect(lastSplitAfterPopToSidebar?.state?.index).toBe(0); + expect(lastSplitAfterPopToSidebar?.state?.routes.at(-1)?.name).toBe(SCREENS.SETTINGS.ROOT); + }); + }); +}); From 87219f3390891422ef55324c6decb72fa4d9ff6a Mon Sep 17 00:00:00 2001 From: borys3kk Date: Mon, 12 May 2025 09:33:20 +0200 Subject: [PATCH 07/17] add TestWorkspaceSplitNavigator to TestNavigationContainer --- tests/utils/TestNavigationContainer.tsx | 36 ++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/utils/TestNavigationContainer.tsx b/tests/utils/TestNavigationContainer.tsx index 518ab8205d8c..28319e86f67d 100644 --- a/tests/utils/TestNavigationContainer.tsx +++ b/tests/utils/TestNavigationContainer.tsx @@ -4,7 +4,13 @@ import React from 'react'; import createRootStackNavigator from '@libs/Navigation/AppNavigator/createRootStackNavigator'; import createSplitNavigator from '@libs/Navigation/AppNavigator/createSplitNavigator'; import navigationRef from '@libs/Navigation/navigationRef'; -import type {AuthScreensParamList, ReportsSplitNavigatorParamList, SearchFullscreenNavigatorParamList, SettingsSplitNavigatorParamList} from '@libs/Navigation/types'; +import type { + AuthScreensParamList, + ReportsSplitNavigatorParamList, + SearchFullscreenNavigatorParamList, + SettingsSplitNavigatorParamList, + WorkspaceSplitNavigatorParamList, +} from '@libs/Navigation/types'; import createPlatformStackNavigator from '@navigation/PlatformStackNavigation/createPlatformStackNavigator'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; @@ -14,11 +20,35 @@ const RootStack = createRootStackNavigator(); const ReportsSplit = createSplitNavigator(); const SettingsSplit = createSplitNavigator(); const SearchStack = createPlatformStackNavigator(); +const WorkspaceSplit = createSplitNavigator(); const getEmptyComponent = () => jest.fn(); type TestNavigationContainerProps = {initialState: InitialState}; +function TestWorkspaceSplitNavigator() { + return ( + + + + + + ); +} + function TestReportsSplitNavigator() { return ( + Date: Mon, 12 May 2025 09:33:43 +0200 Subject: [PATCH 08/17] add tests for popToSidebar --- tests/navigation/PopToSidebarTests.tsx | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/navigation/PopToSidebarTests.tsx b/tests/navigation/PopToSidebarTests.tsx index 5232d131a363..2134d12a8bbe 100644 --- a/tests/navigation/PopToSidebarTests.tsx +++ b/tests/navigation/PopToSidebarTests.tsx @@ -124,4 +124,57 @@ describe('Pop to sidebar after resize from wide to narrow layout', () => { expect(lastSplitAfterPopToSidebar?.state?.routes.at(-1)?.name).toBe(SCREENS.SETTINGS.ROOT); }); }); + + describe('After navigating to workspace tab from chat through link', () => { + it('Should replace the route with LHN', () => { + render( + , + ); + + const lastSplitBeforeNavigate = navigationRef.current?.getRootState().routes.at(-1); + expect(lastSplitBeforeNavigate?.name).toBe(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR); + + act(() => { + Navigation.navigate(ROUTES.WORKSPACE_MEMBERS.getRoute('1')); + }); + + const lastSplitAfterNavigate = navigationRef.current?.getRootState().routes.at(-1); + expect(lastSplitAfterNavigate?.name).toBe(NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR); + expect(lastSplitAfterNavigate?.state?.index).toBe(0); + expect(lastSplitAfterNavigate?.state?.routes.at(0)?.name).toBe(SCREENS.WORKSPACE.CATEGORIES); + + act(() => { + Navigation.popToSidebar(); + }); + + const lastSplitAfterPopToSidebar = navigationRef.current?.getRootState().routes.at(-1); + expect(lastSplitAfterPopToSidebar?.state?.index).toBe(0); + expect(lastSplitAfterPopToSidebar?.state?.routes.at(-1)?.name).toBe(SCREENS.WORKSPACE.INITIAL); + }); + }); }); From ce0303f0cee783943b8dda8eef50310ccf9f0a8f Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 13 May 2025 13:52:00 +0200 Subject: [PATCH 09/17] fix poptosidebard tests / update testnavigationcontainer --- tests/navigation/PopToSidebarTests.tsx | 6 +++++- tests/utils/TestNavigationContainer.tsx | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/navigation/PopToSidebarTests.tsx b/tests/navigation/PopToSidebarTests.tsx index 2134d12a8bbe..a8bb6b3d5b0f 100644 --- a/tests/navigation/PopToSidebarTests.tsx +++ b/tests/navigation/PopToSidebarTests.tsx @@ -20,6 +20,8 @@ jest.mock('@components/ConfirmedRoute.tsx'); const mockedGetIsNarrowLayout = getIsNarrowLayout as jest.MockedFunction; const mockedUseResponsiveLayout = useResponsiveLayout as jest.MockedFunction; +const TEST_POLICY_ID = 'E81FCF5643E6F01A'; + describe('Pop to sidebar after resize from wide to narrow layout', () => { beforeEach(() => { mockedGetIsNarrowLayout.mockReturnValue(true); @@ -160,7 +162,7 @@ describe('Pop to sidebar after resize from wide to narrow layout', () => { expect(lastSplitBeforeNavigate?.name).toBe(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR); act(() => { - Navigation.navigate(ROUTES.WORKSPACE_MEMBERS.getRoute('1')); + Navigation.navigate(ROUTES.WORKSPACE_CATEGORIES.getRoute(TEST_POLICY_ID)); }); const lastSplitAfterNavigate = navigationRef.current?.getRootState().routes.at(-1); @@ -175,6 +177,8 @@ describe('Pop to sidebar after resize from wide to narrow layout', () => { const lastSplitAfterPopToSidebar = navigationRef.current?.getRootState().routes.at(-1); expect(lastSplitAfterPopToSidebar?.state?.index).toBe(0); expect(lastSplitAfterPopToSidebar?.state?.routes.at(-1)?.name).toBe(SCREENS.WORKSPACE.INITIAL); + expect(lastSplitAfterNavigate) }); }); }); + diff --git a/tests/utils/TestNavigationContainer.tsx b/tests/utils/TestNavigationContainer.tsx index 28319e86f67d..31551bd4912c 100644 --- a/tests/utils/TestNavigationContainer.tsx +++ b/tests/utils/TestNavigationContainer.tsx @@ -33,6 +33,10 @@ function TestWorkspaceSplitNavigator() { defaultCentralScreen={SCREENS.WORKSPACE.PROFILE} parentRoute={CONST.NAVIGATION_TESTS.DEFAULT_PARENT_ROUTE} > + Date: Tue, 13 May 2025 14:03:01 +0200 Subject: [PATCH 10/17] clean up code --- src/libs/Navigation/Navigation.ts | 7 ---- tests/navigation/PopToSidebarTests.tsx | 57 -------------------------- 2 files changed, 64 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index fb1c2d4329e6..232e27fa246d 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -354,13 +354,6 @@ function goBack(backToRoute?: Route, options?: GoBackOptions) { return; } - // if (options?.shouldPopToTop) { - // if (shouldPopToSidebar) { - // popToSidebar(); - // return; - // } - // } - if (backToRoute) { goUp(backToRoute, options); return; diff --git a/tests/navigation/PopToSidebarTests.tsx b/tests/navigation/PopToSidebarTests.tsx index a8bb6b3d5b0f..5232d131a363 100644 --- a/tests/navigation/PopToSidebarTests.tsx +++ b/tests/navigation/PopToSidebarTests.tsx @@ -20,8 +20,6 @@ jest.mock('@components/ConfirmedRoute.tsx'); const mockedGetIsNarrowLayout = getIsNarrowLayout as jest.MockedFunction; const mockedUseResponsiveLayout = useResponsiveLayout as jest.MockedFunction; -const TEST_POLICY_ID = 'E81FCF5643E6F01A'; - describe('Pop to sidebar after resize from wide to narrow layout', () => { beforeEach(() => { mockedGetIsNarrowLayout.mockReturnValue(true); @@ -126,59 +124,4 @@ describe('Pop to sidebar after resize from wide to narrow layout', () => { expect(lastSplitAfterPopToSidebar?.state?.routes.at(-1)?.name).toBe(SCREENS.SETTINGS.ROOT); }); }); - - describe('After navigating to workspace tab from chat through link', () => { - it('Should replace the route with LHN', () => { - render( - , - ); - - const lastSplitBeforeNavigate = navigationRef.current?.getRootState().routes.at(-1); - expect(lastSplitBeforeNavigate?.name).toBe(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR); - - act(() => { - Navigation.navigate(ROUTES.WORKSPACE_CATEGORIES.getRoute(TEST_POLICY_ID)); - }); - - const lastSplitAfterNavigate = navigationRef.current?.getRootState().routes.at(-1); - expect(lastSplitAfterNavigate?.name).toBe(NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR); - expect(lastSplitAfterNavigate?.state?.index).toBe(0); - expect(lastSplitAfterNavigate?.state?.routes.at(0)?.name).toBe(SCREENS.WORKSPACE.CATEGORIES); - - act(() => { - Navigation.popToSidebar(); - }); - - const lastSplitAfterPopToSidebar = navigationRef.current?.getRootState().routes.at(-1); - expect(lastSplitAfterPopToSidebar?.state?.index).toBe(0); - expect(lastSplitAfterPopToSidebar?.state?.routes.at(-1)?.name).toBe(SCREENS.WORKSPACE.INITIAL); - expect(lastSplitAfterNavigate) - }); - }); }); - From 42c1f76f6d7772c6a652da211918a9f99833a68f Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 13 May 2025 14:07:44 +0200 Subject: [PATCH 11/17] delete goBackFromWorkspaceCentralScreen / replace usages with popToSidebar --- .../goBackFromWorkspaceCentralScreen.ts | 28 ------------------- src/pages/workspace/WorkspaceMembersPage.tsx | 3 +- .../workspace/WorkspaceMoreFeaturesPage.tsx | 3 +- src/pages/workspace/WorkspaceOverviewPage.tsx | 3 +- .../workspace/WorkspacePageWithSections.tsx | 3 +- .../accounting/PolicyAccountingPage.tsx | 3 +- .../categories/WorkspaceCategoriesPage.tsx | 3 +- .../distanceRates/PolicyDistanceRatesPage.tsx | 3 +- .../WorkspaceExpensifyCardListPage.tsx | 3 +- .../perDiem/WorkspacePerDiemPage.tsx | 3 +- .../WorkspaceReportFieldsPage.tsx | 3 +- .../workspace/tags/WorkspaceTagsPage.tsx | 3 +- .../workspace/taxes/WorkspaceTaxesPage.tsx | 3 +- 13 files changed, 12 insertions(+), 52 deletions(-) delete mode 100644 src/libs/Navigation/helpers/goBackFromWorkspaceCentralScreen.ts diff --git a/src/libs/Navigation/helpers/goBackFromWorkspaceCentralScreen.ts b/src/libs/Navigation/helpers/goBackFromWorkspaceCentralScreen.ts deleted file mode 100644 index d7deb845af43..000000000000 --- a/src/libs/Navigation/helpers/goBackFromWorkspaceCentralScreen.ts +++ /dev/null @@ -1,28 +0,0 @@ -import Log from '@libs/Log'; -import Navigation from '@libs/Navigation/Navigation'; -import navigationRef from '@libs/Navigation/navigationRef'; -import NAVIGATORS from '@src/NAVIGATORS'; -import ROUTES from '@src/ROUTES'; - -/** - * If there are already other screens open in WorkspaceSplitNavigator, we return to the previous one. - * If not, from the central screen in WorkspaceSplitNavigator we should return to the WorkspaceInitialPage. - */ -function goBackFromWorkspaceCentralScreen(policyID: string | undefined) { - const rootState = navigationRef.getRootState(); - const lastRoute = rootState.routes.at(-1); - - if (lastRoute?.name !== NAVIGATORS.WORKSPACE_SPLIT_NAVIGATOR) { - Log.hmmm('[goBackFromWorkspaceCentralScreen] goBackFromWorkspaceCentralScreen was called from a different navigator than WorkspaceSplitNavigator.'); - return; - } - - if (lastRoute.state?.routes && lastRoute.state.routes.length > 1) { - Navigation.popToSidebar(); - return; - } - - Navigation.goBack(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); -} - -export default goBackFromWorkspaceCentralScreen; diff --git a/src/pages/workspace/WorkspaceMembersPage.tsx b/src/pages/workspace/WorkspaceMembersPage.tsx index f0b6f4a0a16b..a757953bd53e 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -47,7 +47,6 @@ import {removeApprovalWorkflow as removeApprovalWorkflowAction, updateApprovalWo import {canUseTouchScreen} from '@libs/DeviceCapabilities'; import {formatPhoneNumber as formatPhoneNumberUtil} from '@libs/LocalePhoneNumber'; import Log from '@libs/Log'; -import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; @@ -710,7 +709,7 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson turnOffMobileSelectionMode(); return; } - goBackFromWorkspaceCentralScreen(policyID); + Navigation.popToSidebar(); }} > {() => ( diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index 39f4ea535bab..22992d16784c 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -16,7 +16,6 @@ import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; import {filterInactiveCards, getAllCardsForWorkspace, getCompanyFeeds, isSmartLimitEnabled as isSmartLimitEnabledUtil} from '@libs/CardUtils'; import {getLatestErrorField} from '@libs/ErrorUtils'; -import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; @@ -470,7 +469,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro shouldUseHeadlineHeader title={translate('workspace.common.moreFeatures')} shouldShowBackButton={shouldUseNarrowLayout} - onBackButtonPress={() => goBackFromWorkspaceCentralScreen(policyID)} + onBackButtonPress={() => Navigation.popToSidebar()} /> diff --git a/src/pages/workspace/WorkspaceOverviewPage.tsx b/src/pages/workspace/WorkspaceOverviewPage.tsx index 7091094906e6..a9fb42aa682a 100644 --- a/src/pages/workspace/WorkspaceOverviewPage.tsx +++ b/src/pages/workspace/WorkspaceOverviewPage.tsx @@ -34,7 +34,6 @@ import { } from '@libs/actions/Policy/Policy'; import {filterInactiveCards} from '@libs/CardUtils'; import {getLatestErrorField} from '@libs/ErrorUtils'; -import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen'; import resetPolicyIDInNavigationState from '@libs/Navigation/helpers/resetPolicyIDInNavigationState'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; @@ -222,7 +221,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa return; } - goBackFromWorkspaceCentralScreen(policy?.id); + Navigation.popToSidebar(); }} addBottomSafeAreaPadding > diff --git a/src/pages/workspace/WorkspacePageWithSections.tsx b/src/pages/workspace/WorkspacePageWithSections.tsx index a3f8a94d29e6..39ac54165fb5 100644 --- a/src/pages/workspace/WorkspacePageWithSections.tsx +++ b/src/pages/workspace/WorkspacePageWithSections.tsx @@ -16,7 +16,6 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import {openWorkspaceView} from '@libs/actions/BankAccounts'; import BankAccount from '@libs/models/BankAccount'; -import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen'; import Navigation from '@libs/Navigation/Navigation'; import {isPendingDeletePolicy, isPolicyAdmin, shouldShowPolicy as shouldShowPolicyUtil} from '@libs/PolicyUtils'; import CONST from '@src/CONST'; @@ -183,7 +182,7 @@ function WorkspacePageWithSections({ return; } - goBackFromWorkspaceCentralScreen(policyID); + Navigation.popToSidebar(); }; return ( diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index f2f2c9d82b7f..0fb827f85e52 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -32,7 +32,6 @@ import {isAuthenticationError, isConnectionInProgress, isConnectionUnverified, r import {shouldShowQBOReimbursableExportDestinationAccountError} from '@libs/actions/connections/QuickbooksOnline'; import {getAssignedSupportData} from '@libs/actions/Policy/Policy'; import {isExpensifyCardFullySetUp} from '@libs/CardUtils'; -import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen'; import { areSettingsInErrorFields, findCurrentXeroOrganization, @@ -542,7 +541,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { icon={Illustrations.Accounting} shouldUseHeadlineHeader threeDotsAnchorPosition={threeDotsAnchorPosition} - onBackButtonPress={() => goBackFromWorkspaceCentralScreen(policyID)} + onBackButtonPress={() => Navigation.popToSidebar()} /> {!shouldUseNarrowLayout && headerButtons} diff --git a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx index f12c6508ab4e..9319ef301b51 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx @@ -21,7 +21,6 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import {clearDeletePaymentMethodError} from '@libs/actions/PaymentMethods'; import {sortCardsByCardholderName} from '@libs/CardUtils'; -import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import {getDescriptionForPolicyDomainCard, getMemberAccountIDsForWorkspace} from '@libs/PolicyUtils'; import Navigation from '@navigation/Navigation'; @@ -158,7 +157,7 @@ function WorkspaceExpensifyCardListPage({route, cardsList, fundID}: WorkspaceExp shouldUseHeadlineHeader title={translate('workspace.common.expensifyCard')} shouldShowBackButton={shouldUseNarrowLayout} - onBackButtonPress={() => goBackFromWorkspaceCentralScreen(policyID)} + onBackButtonPress={() => Navigation.popToSidebar()} > {!shouldShowSelector && !shouldUseNarrowLayout && isBankAccountVerified && getHeaderButtons()} diff --git a/src/pages/workspace/perDiem/WorkspacePerDiemPage.tsx b/src/pages/workspace/perDiem/WorkspacePerDiemPage.tsx index 521214465888..2d4ec56fb09f 100644 --- a/src/pages/workspace/perDiem/WorkspacePerDiemPage.tsx +++ b/src/pages/workspace/perDiem/WorkspacePerDiemPage.tsx @@ -34,7 +34,6 @@ import useThreeDotsAnchorPosition from '@hooks/useThreeDotsAnchorPosition'; import {convertAmountToDisplayString} from '@libs/CurrencyUtils'; import {canUseTouchScreen} from '@libs/DeviceCapabilities'; import localeCompare from '@libs/LocaleCompare'; -import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; @@ -389,7 +388,7 @@ function WorkspacePerDiemPage({route}: WorkspacePerDiemPageProps) { return; } - goBackFromWorkspaceCentralScreen(policyID); + Navigation.popToSidebar(); }} shouldShowThreeDotsButton threeDotsMenuItems={threeDotsMenuItems} diff --git a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx index 294ada570e37..a19397c4f142 100644 --- a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx +++ b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx @@ -36,7 +36,6 @@ import {isConnectionInProgress, isConnectionUnverified} from '@libs/actions/conn import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode'; import {canUseTouchScreen} from '@libs/DeviceCapabilities'; import localeCompare from '@libs/LocaleCompare'; -import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; @@ -264,7 +263,7 @@ function WorkspaceReportFieldsPage({ turnOffMobileSelectionMode(); return; } - goBackFromWorkspaceCentralScreen(policyID); + Navigation.popToSidebar(); }} > {!shouldUseNarrowLayout && !hasReportAccountingConnections && getHeaderButtons()} diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 3ec448e9bd9f..00d05c14cec0 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -38,7 +38,6 @@ import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode'; import {clearPolicyTagErrors, deletePolicyTags, downloadTagsCSV, openPolicyTagsPage, setPolicyTagsRequired, setWorkspaceTagEnabled} from '@libs/actions/Policy/Tag'; import {canUseTouchScreen} from '@libs/DeviceCapabilities'; import localeCompare from '@libs/LocaleCompare'; -import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; @@ -460,7 +459,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { return; } - goBackFromWorkspaceCentralScreen(policyID); + Navigation.popToSidebar(); }} shouldShowThreeDotsButton={!policy?.hasMultipleTagLists} threeDotsMenuItems={threeDotsMenuItems} diff --git a/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx b/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx index 3e50c1aa5950..78461e940271 100644 --- a/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx +++ b/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx @@ -30,7 +30,6 @@ import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode'; import {clearTaxRateError, deletePolicyTaxes, setPolicyTaxesEnabled} from '@libs/actions/TaxRate'; import {canUseTouchScreen} from '@libs/DeviceCapabilities'; import {getLatestErrorFieldForAnyField} from '@libs/ErrorUtils'; -import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import { @@ -363,7 +362,7 @@ function WorkspaceTaxesPage({ turnOffMobileSelectionMode(); return; } - goBackFromWorkspaceCentralScreen(policyID); + Navigation.popToSidebar(); }} > {!shouldUseNarrowLayout && headerButtons} From d22cbfe93a6af12fc64c881d66e191691702a5c7 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 13 May 2025 14:52:03 +0200 Subject: [PATCH 12/17] refactor workspaceReportFieldsPage to comply with popToSidebar --- src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx index 83b0584d21a7..24c0909277b4 100644 --- a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx +++ b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx @@ -176,6 +176,9 @@ function WorkspaceReportFieldsPage({ title={translate('common.reports')} shouldUseHeadlineHeader shouldShowBackButton={shouldUseNarrowLayout} + onBackButtonPress={() => { + Navigation.popToSidebar(); + }} /> {isLoading && ( Date: Tue, 13 May 2025 15:21:53 +0200 Subject: [PATCH 13/17] remove comments --- src/libs/Navigation/Navigation.ts | 7 ------- src/pages/TeachersUnite/SaveTheWorldPage.tsx | 2 +- src/pages/home/ReportScreen.tsx | 4 +--- src/pages/settings/AboutPage/AboutPage.tsx | 2 +- src/pages/settings/Preferences/PreferencesPage.tsx | 2 +- src/pages/settings/Profile/ProfilePage.tsx | 2 +- src/pages/settings/Security/SecuritySettingsPage.tsx | 2 +- .../settings/Subscription/SubscriptionSettingsPage.tsx | 2 +- src/pages/settings/Troubleshoot/TroubleshootPage.tsx | 2 +- src/pages/settings/Wallet/WalletPage/WalletPage.tsx | 2 +- src/pages/workspace/WorkspaceJoinUserPage.tsx | 6 ++---- 11 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 232e27fa246d..d0a8914f32c8 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -275,17 +275,10 @@ type GoBackOptions = { * In that case we want to goUp to a country picker with any params so we don't compare them. */ compareParams?: boolean; - - /** - * Specifies whether goBack should pop to top when invoked. - * Additionaly, to execute popToTop, set the value of the global variable shouldPopToSidebar to true using the setShouldPopToSidebar function. - */ - shouldPopToTop?: boolean; }; const defaultGoBackOptions: Required = { compareParams: true, - shouldPopToTop: false, }; /** diff --git a/src/pages/TeachersUnite/SaveTheWorldPage.tsx b/src/pages/TeachersUnite/SaveTheWorldPage.tsx index c1c04bb25327..1bea138854de 100644 --- a/src/pages/TeachersUnite/SaveTheWorldPage.tsx +++ b/src/pages/TeachersUnite/SaveTheWorldPage.tsx @@ -57,7 +57,7 @@ function SaveTheWorldPage() { title={translate('sidebarScreen.saveTheWorld')} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.popToSidebar()} // shouldpoptotop + onBackButtonPress={() => Navigation.popToSidebar()} icon={Illustrations.TeachersUnite} shouldUseHeadlineHeader /> diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 2011291b3aad..82ed69b2f67d 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -343,9 +343,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) { Navigation.goBack(backTo as Route); return; } - // Navigation.goBack(undefined, {shouldPopToTop: true}); if (Navigation.getShouldPopToSidebar()) { - // need further investigation whether we can just pop to sidebar Navigation.popToSidebar(); return; } @@ -618,7 +616,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) { Navigation.dismissModal(); if (Navigation.getTopmostReportId() === prevOnyxReportID) { Navigation.isNavigationReady().then(() => { - Navigation.popToSidebar(); // shouldpoptotop + Navigation.popToSidebar(); }); } if (prevReport?.parentReportID) { diff --git a/src/pages/settings/AboutPage/AboutPage.tsx b/src/pages/settings/AboutPage/AboutPage.tsx index cdc5ed465161..c3e076df4f8f 100644 --- a/src/pages/settings/AboutPage/AboutPage.tsx +++ b/src/pages/settings/AboutPage/AboutPage.tsx @@ -142,7 +142,7 @@ function AboutPage() { title={translate('initialSettingsPage.about')} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.popToSidebar()} // shouldpoptotop + onBackButtonPress={() => Navigation.popToSidebar()} icon={Illustrations.PalmTree} shouldUseHeadlineHeader /> diff --git a/src/pages/settings/Preferences/PreferencesPage.tsx b/src/pages/settings/Preferences/PreferencesPage.tsx index 29803e1cd1e3..803493398c14 100755 --- a/src/pages/settings/Preferences/PreferencesPage.tsx +++ b/src/pages/settings/Preferences/PreferencesPage.tsx @@ -53,7 +53,7 @@ function PreferencesPage() { shouldUseHeadlineHeader shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.popToSidebar()} // shouldpoptotop + onBackButtonPress={() => Navigation.popToSidebar()} /> diff --git a/src/pages/settings/Profile/ProfilePage.tsx b/src/pages/settings/Profile/ProfilePage.tsx index eaaf397368f2..2882c7e69445 100755 --- a/src/pages/settings/Profile/ProfilePage.tsx +++ b/src/pages/settings/Profile/ProfilePage.tsx @@ -158,7 +158,7 @@ function ProfilePage() { return; } Navigation.goBack(route.params?.backTo); - }} // sprawdzenie zmiennej i handlowanie shouldpoptotop + }} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter icon={Illustrations.Profile} diff --git a/src/pages/settings/Security/SecuritySettingsPage.tsx b/src/pages/settings/Security/SecuritySettingsPage.tsx index 7c091a8b2570..56a6dccc3084 100644 --- a/src/pages/settings/Security/SecuritySettingsPage.tsx +++ b/src/pages/settings/Security/SecuritySettingsPage.tsx @@ -265,7 +265,7 @@ function SecuritySettingsPage() { Navigation.popToSidebar()} // shouldpoptotop + onBackButtonPress={() => Navigation.popToSidebar()} icon={Illustrations.LockClosed} shouldUseHeadlineHeader shouldDisplaySearchRouter diff --git a/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx b/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx index 5a1832eba977..5b5e9df05abd 100644 --- a/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx +++ b/src/pages/settings/Subscription/SubscriptionSettingsPage.tsx @@ -55,7 +55,7 @@ function SubscriptionSettingsPage({route}: SubscriptionSettingsPageProps) { return; } Navigation.goBack(backTo); - }} // tu sprawdzic globalna zmienna i powrot na backto shouldpoptotop + }} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter icon={Illustrations.CreditCardsNew} diff --git a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx index aa4d6a2882d0..6210975e969d 100644 --- a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx +++ b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx @@ -108,7 +108,7 @@ function TroubleshootPage() { title={translate('initialSettingsPage.aboutPage.troubleshoot')} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.popToSidebar()} // tylko shouldpoptotop + onBackButtonPress={() => Navigation.popToSidebar()} icon={Illustrations.Lightbulb} shouldUseHeadlineHeader /> diff --git a/src/pages/settings/Wallet/WalletPage/WalletPage.tsx b/src/pages/settings/Wallet/WalletPage/WalletPage.tsx index b1c6fa33e123..528d778feb11 100644 --- a/src/pages/settings/Wallet/WalletPage/WalletPage.tsx +++ b/src/pages/settings/Wallet/WalletPage/WalletPage.tsx @@ -389,7 +389,7 @@ function WalletPage({shouldListenForResize = false}: WalletPageProps) { shouldUseHeadlineHeader shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.popToSidebar()} // shouldpoptotop + onBackButtonPress={() => Navigation.popToSidebar()} /> ); diff --git a/src/pages/workspace/WorkspaceJoinUserPage.tsx b/src/pages/workspace/WorkspaceJoinUserPage.tsx index b8406fb03ab9..a708c33cc0c2 100644 --- a/src/pages/workspace/WorkspaceJoinUserPage.tsx +++ b/src/pages/workspace/WorkspaceJoinUserPage.tsx @@ -34,11 +34,9 @@ function WorkspaceJoinUserPage({route}: WorkspaceJoinUserPageProps) { Navigation.isNavigationReady().then(() => { if (Navigation.getShouldPopToSidebar()) { Navigation.popToSidebar(); - return; + } else { + Navigation.goBack(); } - Navigation.goBack(); - // Navigation.goBack(undefined, {shouldPopToTop: true}); - // Navigation.popToSidebar(); // shouldpoptotop Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policyID)); }); return; From b042805725c0dfe4a5d677b4cd6b012f1fa05e56 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Tue, 13 May 2025 16:13:45 +0200 Subject: [PATCH 14/17] removed last goBackFromWorkspaceCentralScreen --- .../workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx index d7267b16acb2..d3737be0907e 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceExpensifyCardListPage.tsx @@ -24,7 +24,6 @@ import useSearchResults from '@hooks/useSearchResults'; import useThemeStyles from '@hooks/useThemeStyles'; import {clearDeletePaymentMethodError} from '@libs/actions/PaymentMethods'; import {filterCardsByPersonalDetails, getCardsByCardholderName, sortCardsByCardholderName} from '@libs/CardUtils'; -import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFromWorkspaceCentralScreen'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import {getDescriptionForPolicyDomainCard, getMemberAccountIDsForWorkspace} from '@libs/PolicyUtils'; import Navigation from '@navigation/Navigation'; From fe7d4e8d6743bbc85264895353c2ed10b401137c Mon Sep 17 00:00:00 2001 From: borys3kk Date: Wed, 14 May 2025 12:10:45 +0200 Subject: [PATCH 15/17] add then/when in tests / remove unnecessary comments / simplify logic in reportScreen onBackButtonPress --- src/libs/Navigation/Navigation.ts | 3 +-- src/libs/navigateAfterJoinRequest.ts | 1 - src/pages/home/ReportScreen.tsx | 12 ++++-------- tests/navigation/PopToSidebarTests.tsx | 9 ++++++--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index d0a8914f32c8..d4a4f6f54d59 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -78,7 +78,6 @@ let shouldPopToSidebar = false; /** * Inform the navigation that next time user presses UP we should pop all the state back to LHN. - * TODO change content of comment */ function setShouldPopToSidebar(shouldPopAllStateFlag: boolean) { shouldPopToSidebar = shouldPopAllStateFlag; @@ -367,7 +366,7 @@ function popToSidebar() { const currentRoute = rootState?.routes.at(-1); if (!currentRoute) { - Log.hmmm("There's no current root in navigator"); + Log.hmmm('[popToSidebar] Unable to pop to sidebar, no current root found in navigator'); return; } diff --git a/src/libs/navigateAfterJoinRequest.ts b/src/libs/navigateAfterJoinRequest.ts index e245e31bb6b1..6605de8ee656 100644 --- a/src/libs/navigateAfterJoinRequest.ts +++ b/src/libs/navigateAfterJoinRequest.ts @@ -2,7 +2,6 @@ import ROUTES from '@src/ROUTES'; import Navigation from './Navigation/Navigation'; const navigateAfterJoinRequest = () => { - // Navigation.goBack(undefined, {shouldPopToTop: true}); if (Navigation.getShouldPopToSidebar()) { Navigation.popToSidebar(); } else { diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 82ed69b2f67d..91536b795dd5 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -335,18 +335,14 @@ function ReportScreen({route, navigation}: ReportScreenProps) { Navigation.dismissModal(); return; } - if (backTo) { - if (Navigation.getShouldPopToSidebar()) { - Navigation.popToSidebar(); - return; - } - Navigation.goBack(backTo as Route); - return; - } if (Navigation.getShouldPopToSidebar()) { Navigation.popToSidebar(); return; } + if (backTo) { + Navigation.goBack(backTo as Route); + return; + } Navigation.goBack(); }, [isInNarrowPaneModal, backTo]); diff --git a/tests/navigation/PopToSidebarTests.tsx b/tests/navigation/PopToSidebarTests.tsx index 5232d131a363..a45d03fd8bff 100644 --- a/tests/navigation/PopToSidebarTests.tsx +++ b/tests/navigation/PopToSidebarTests.tsx @@ -26,8 +26,8 @@ describe('Pop to sidebar after resize from wide to narrow layout', () => { mockedUseResponsiveLayout.mockReturnValue({...CONST.NAVIGATION_TESTS.DEFAULT_USE_RESPONSIVE_LAYOUT_VALUE, shouldUseNarrowLayout: true}); }); - describe('After clicking a few tabs in settings screen', () => { - it('Should pop all visited tabs and get back to settings root screen', () => { + describe('After opening several screens in the settings tab', () => { + it('Should pop all visited screens and go back to the settings sidebar screen', () => { render( { Navigation.popToSidebar(); }); + // Then all screens should be popped of the stack and only settings root left const settingsSplitAfterPopToSidebar = navigationRef.current?.getRootState().routes.at(-1); expect(settingsSplitAfterPopToSidebar?.state?.index).toBe(0); expect(settingsSplitAfterPopToSidebar?.state?.routes.at(-1)?.name).toBe(SCREENS.SETTINGS.ROOT); }); }); - describe('After navigating to settings tabs from chat through link', () => { + describe('After navigating to the central screen in the settings tab from the chat', () => { it('Should replace the route with LHN', () => { render( { expect(lastSplitAfterNavigate?.state?.index).toBe(0); expect(lastSplitAfterNavigate?.state?.routes.at(-1)?.name).toBe(SCREENS.SETTINGS.ABOUT); + // When we pop to sidebar without LHN on top of stack act(() => { Navigation.popToSidebar(); }); + // Then the top screen should be replaced with LHN const lastSplitAfterPopToSidebar = navigationRef.current?.getRootState().routes.at(-1); expect(lastSplitAfterPopToSidebar?.state?.index).toBe(0); expect(lastSplitAfterPopToSidebar?.state?.routes.at(-1)?.name).toBe(SCREENS.SETTINGS.ROOT); From 8d236f8b5d0eec8a0ee8f48886ad24ed59d30081 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Wed, 14 May 2025 13:09:04 +0200 Subject: [PATCH 16/17] remove comment - this case is handled by popToSidebar --- src/libs/actions/Report.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index d543d2e79d25..3da30b5d584e 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2899,7 +2899,7 @@ function deleteReport(reportID: string | undefined, shouldDeleteChildReports = f function navigateToConciergeChatAndDeleteReport(reportID: string | undefined, shouldPopToTop = false, shouldDeleteChildReports = false) { // Dismiss the current report screen and replace it with Concierge Chat if (shouldPopToTop) { - Navigation.popToSidebar(); // it can break because of redirection to settings main + Navigation.popToSidebar(); } else { Navigation.goBack(); } From c27843e1c5247bbbcb065f9dc079433bd5739b14 Mon Sep 17 00:00:00 2001 From: borys3kk Date: Thu, 15 May 2025 08:55:44 +0200 Subject: [PATCH 17/17] refactor according to comments --- src/pages/TeachersUnite/SaveTheWorldPage.tsx | 2 +- src/pages/settings/AboutPage/AboutPage.tsx | 2 +- src/pages/settings/Preferences/PreferencesPage.tsx | 2 +- src/pages/settings/Security/SecuritySettingsPage.tsx | 2 +- src/pages/settings/Troubleshoot/TroubleshootPage.tsx | 2 +- src/pages/settings/Wallet/WalletPage/WalletPage.tsx | 2 +- src/pages/workspace/WorkspaceMoreFeaturesPage.tsx | 2 +- src/pages/workspace/accounting/PolicyAccountingPage.tsx | 2 +- .../expensifyCard/WorkspaceExpensifyCardListPage.tsx | 2 +- .../workspace/reportFields/WorkspaceReportFieldsPage.tsx | 4 +--- 10 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/pages/TeachersUnite/SaveTheWorldPage.tsx b/src/pages/TeachersUnite/SaveTheWorldPage.tsx index 1bea138854de..dcdab230d899 100644 --- a/src/pages/TeachersUnite/SaveTheWorldPage.tsx +++ b/src/pages/TeachersUnite/SaveTheWorldPage.tsx @@ -57,7 +57,7 @@ function SaveTheWorldPage() { title={translate('sidebarScreen.saveTheWorld')} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.popToSidebar()} + onBackButtonPress={Navigation.popToSidebar} icon={Illustrations.TeachersUnite} shouldUseHeadlineHeader /> diff --git a/src/pages/settings/AboutPage/AboutPage.tsx b/src/pages/settings/AboutPage/AboutPage.tsx index c3e076df4f8f..b045e66e107f 100644 --- a/src/pages/settings/AboutPage/AboutPage.tsx +++ b/src/pages/settings/AboutPage/AboutPage.tsx @@ -142,7 +142,7 @@ function AboutPage() { title={translate('initialSettingsPage.about')} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.popToSidebar()} + onBackButtonPress={Navigation.popToSidebar} icon={Illustrations.PalmTree} shouldUseHeadlineHeader /> diff --git a/src/pages/settings/Preferences/PreferencesPage.tsx b/src/pages/settings/Preferences/PreferencesPage.tsx index 803493398c14..53ff9f71c643 100755 --- a/src/pages/settings/Preferences/PreferencesPage.tsx +++ b/src/pages/settings/Preferences/PreferencesPage.tsx @@ -53,7 +53,7 @@ function PreferencesPage() { shouldUseHeadlineHeader shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.popToSidebar()} + onBackButtonPress={Navigation.popToSidebar} /> diff --git a/src/pages/settings/Security/SecuritySettingsPage.tsx b/src/pages/settings/Security/SecuritySettingsPage.tsx index 56a6dccc3084..cf44d1864ff8 100644 --- a/src/pages/settings/Security/SecuritySettingsPage.tsx +++ b/src/pages/settings/Security/SecuritySettingsPage.tsx @@ -265,7 +265,7 @@ function SecuritySettingsPage() { Navigation.popToSidebar()} + onBackButtonPress={Navigation.popToSidebar} icon={Illustrations.LockClosed} shouldUseHeadlineHeader shouldDisplaySearchRouter diff --git a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx index 6210975e969d..ccd292db3a89 100644 --- a/src/pages/settings/Troubleshoot/TroubleshootPage.tsx +++ b/src/pages/settings/Troubleshoot/TroubleshootPage.tsx @@ -108,7 +108,7 @@ function TroubleshootPage() { title={translate('initialSettingsPage.aboutPage.troubleshoot')} shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.popToSidebar()} + onBackButtonPress={Navigation.popToSidebar} icon={Illustrations.Lightbulb} shouldUseHeadlineHeader /> diff --git a/src/pages/settings/Wallet/WalletPage/WalletPage.tsx b/src/pages/settings/Wallet/WalletPage/WalletPage.tsx index 528d778feb11..200bc21ded5d 100644 --- a/src/pages/settings/Wallet/WalletPage/WalletPage.tsx +++ b/src/pages/settings/Wallet/WalletPage/WalletPage.tsx @@ -389,7 +389,7 @@ function WalletPage({shouldListenForResize = false}: WalletPageProps) { shouldUseHeadlineHeader shouldShowBackButton={shouldUseNarrowLayout} shouldDisplaySearchRouter - onBackButtonPress={() => Navigation.popToSidebar()} + onBackButtonPress={Navigation.popToSidebar} /> ); diff --git a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx index 1cc2a4e44a6c..5561ee1172f6 100644 --- a/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx +++ b/src/pages/workspace/WorkspaceMoreFeaturesPage.tsx @@ -441,7 +441,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro shouldUseHeadlineHeader title={translate('workspace.common.moreFeatures')} shouldShowBackButton={shouldUseNarrowLayout} - onBackButtonPress={() => Navigation.popToSidebar()} + onBackButtonPress={Navigation.popToSidebar} /> diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 0fb827f85e52..b6eaa0eebdc1 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -541,7 +541,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { icon={Illustrations.Accounting} shouldUseHeadlineHeader threeDotsAnchorPosition={threeDotsAnchorPosition} - onBackButtonPress={() => Navigation.popToSidebar()} + onBackButtonPress={Navigation.popToSidebar} /> Navigation.popToSidebar()} + onBackButtonPress={Navigation.popToSidebar} > {!shouldShowSelector && !shouldUseNarrowLayout && isBankAccountVerified && getHeaderButtons()} diff --git a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx index 24c0909277b4..205e62704f42 100644 --- a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx +++ b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx @@ -176,9 +176,7 @@ function WorkspaceReportFieldsPage({ title={translate('common.reports')} shouldUseHeadlineHeader shouldShowBackButton={shouldUseNarrowLayout} - onBackButtonPress={() => { - Navigation.popToSidebar(); - }} + onBackButtonPress={Navigation.popToSidebar} /> {isLoading && (