@@ -38,11 +38,7 @@ type ExpenseReportRouteParams = {
3838 backTo : string | undefined ;
3939} ;
4040
41- /**
42- * The report a `backTo` points at, whatever route shape it uses. The same report is reachable as `r/`, `e/`,
43- * `search/view/` and `search/r/`, so the path alone cannot be compared - resolving it the way the navigator itself
44- * would avoids hard-coding that list.
45- */
41+ /** The report a `backTo` points at. Resolved through the navigator because the same report is reachable as `r/`, `e/`, `search/view/` and `search/r/`. */
4642function getBackToReportID ( backTo : Route ) : string | undefined {
4743 const focusedRoute = findFocusedRoute ( getStateFromPath ( backTo ) ) ;
4844 const params = focusedRoute ?. params ;
@@ -55,22 +51,17 @@ function getExpenseReportRoute({routeName, reportID, referrer, backTo}: ExpenseR
5551 return ROUTES . REPORT_WITH_ID . getRoute ( reportID , undefined , referrer , backTo ) ;
5652 }
5753
58- // Clicking the expense of a single-expense report in Search opens the report on this same RHP route rather than a
59- // money request report one, so staying here and swapping the report is what the user would have got by clicking it.
6054 if ( isSearchTopmostFullScreenRoute ( ) ) {
6155 return ROUTES . SEARCH_REPORT . getRoute ( { reportID, backTo} ) ;
6256 }
6357
64- // Outside Search an expense report belongs in the RHP, which is full screen on a narrow layout anyway. Swapping
65- // one RHP route for another keeps the redirect inside the navigator it started in - replacing it with the central
66- // pane `r/` route instead leaves the back stack straddling two navigators.
58+ // Swapping one RHP route for another keeps the redirect inside the navigator it started in.
6759 return ROUTES . EXPENSE_REPORT_RHP . getRoute ( { reportID, backTo} ) ;
6860}
6961
7062/**
7163 * Renders nothing. A single-expense report renders its only expense inline (see `shouldDisplayReportTableView`), so
72- * that expense's transaction thread duplicates the report. This replaces such a route with the report itself - the
73- * route-level backstop for entry points that don't check the transaction count themselves.
64+ * that expense's transaction thread duplicates the report. This replaces such a route with the report itself.
7465 */
7566function OneTransactionThreadRedirectHandler ( ) {
7667 const route = useRoute < ReportScreenRoute > ( ) ;
@@ -84,20 +75,16 @@ function OneTransactionThreadRedirectHandler() {
8475 // check below, so gate on the count the server keeps on the report itself first.
8576 const [ isParentOneTransactionReport ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT } ${ parentReportID } ` , { selector : isOneTransactionReport } ) ;
8677
87- // The same definition `HeaderView` and `SidebarUtils` use, so the redirect and the thread's own views agree.
8878 // Passing `undefined` keeps the call inert, so plain comment threads don't subscribe to their chat's action list.
8979 const isOneTransactionThread = useIsOneTransactionThread ( isParentOneTransactionReport ? report : undefined ) ;
9080
91- // The prev/next arrows only exist in a thread's header, so the flows that seed a sibling set to step through
92- // expenses (Home "Recently added", "Review N flagged expenses", the duplicate review list) would dead-end
93- // mid-review if we redirected out of the thread.
81+ // The prev/next arrows only exist in a thread's header, so redirecting out of a thread that is part of a sibling
82+ // set (Home "Recently added", "Review N flagged expenses", the duplicate review list) would dead-end mid-review.
9483 const [ isSteppingThroughExpenses ] = useOnyx ( ONYXKEYS . TRANSACTION_THREAD_NAVIGATION_TRANSACTION_IDS , { selector : selectIsSteppingThroughExpenses } ) ;
9584
9685 // A message deep link points at an action inside the thread, so dropping the thread route would drop its anchor.
9786 const hasLinkedReportAction = ! ! route . params ?. reportActionID ;
9887
99- // `referrer=notification` is what lets `useMarkAsRead` mark the report read without waiting on window focus, so it
100- // has to survive the redirect.
10188 const referrer = route . name === SCREENS . REPORT ? route . params ?. referrer : undefined ;
10289 const backTo = route . params ?. backTo ;
10390
@@ -108,15 +95,12 @@ function OneTransactionThreadRedirectHandler() {
10895 return ;
10996 }
11097
111- // A thread opened from its own report carries that report as `backTo`. Handing it back to the report would
112- // point the report at itself, which `linkTo` refuses to navigate to at all on a wide layout, and which sends
113- // Back round in circles between the report's two route shapes on a narrow one. Inherit the report's own
114- // nested `backTo` instead - where it would have returned to had the user opened it directly.
98+ // A thread opened from its own report carries that report as `backTo`, which would point the report at itself.
99+ // Inherit that route's own nested `backTo` instead.
115100 const isBackToParentReport = ! ! backTo && getBackToReportID ( backTo ) === parentReportID ;
116101 const resolvedBackTo = isBackToParentReport ? ( getSearchParamFromPath ( backTo ?? '' , 'backTo' ) ?? undefined ) : backTo ;
117102
118- // Replacing rather than pushing keeps the thread we are leaving out of the history, so going back doesn't
119- // land on it again.
103+ // Replace rather than push, so going back doesn't land on the thread again.
120104 Navigation . navigate ( getExpenseReportRoute ( { routeName : route . name , reportID : parentReportID , referrer, backTo : resolvedBackTo } ) , { forceReplace : true } ) ;
121105 } , [ backTo , isFocused , parentReportID , referrer , route . name , shouldRedirectToParentReport ] ) ;
122106
0 commit comments