@@ -8569,25 +8569,39 @@ function isMoneyRequestReportPendingDeletion(reportOrID: OnyxEntry<Report> | str
85698569}
85708570
85718571function navigateToLinkedReportAction ( ancestor : Ancestor , isInNarrowPaneModal : boolean , canUserPerformWrite : boolean | undefined , isOffline : boolean ) {
8572+ const parentReport = getReportOrDraftReport ( ancestor . report . parentReportID ) ;
8573+ const parentReportAction = getReportAction ( ancestor . report . parentReportID , ancestor . report . parentReportActionID ) ;
8574+
8575+ let newAncestor = ancestor ;
8576+ // If `parentReport` is an IOU or Expense report, navigate directly to `parentReport`,
8577+ // preventing redundant navigation when threading back to the parent chat thread
8578+ if ( parentReport && parentReportAction && ( isIOUReport ( parentReport ) || isExpenseReport ( parentReport ) ) ) {
8579+ newAncestor = {
8580+ ...ancestor ,
8581+ report : parentReport ,
8582+ reportAction : parentReportAction ,
8583+ } ;
8584+ }
8585+
85728586 if ( isInNarrowPaneModal ) {
85738587 Navigation . navigate (
85748588 ROUTES . SEARCH_REPORT . getRoute ( {
8575- reportID : ancestor . report . reportID ,
8576- reportActionID : ancestor . reportAction . reportActionID ,
8589+ reportID : newAncestor . report . reportID ,
8590+ reportActionID : newAncestor . reportAction . reportActionID ,
85778591 backTo : SCREENS . SEARCH . REPORT_RHP ,
85788592 } ) ,
85798593 ) ;
85808594 return ;
85818595 }
85828596
85838597 // Pop the thread report screen before navigating to the chat report.
8584- Navigation . goBack ( ROUTES . REPORT_WITH_ID . getRoute ( ancestor . report . reportID ) ) ;
8598+ Navigation . goBack ( ROUTES . REPORT_WITH_ID . getRoute ( newAncestor . report . reportID ) ) ;
85858599
8586- const isVisibleAction = shouldReportActionBeVisible ( ancestor . reportAction , ancestor . reportAction . reportActionID , canUserPerformWrite ) ;
8600+ const isVisibleAction = shouldReportActionBeVisible ( newAncestor . reportAction , newAncestor . reportAction . reportActionID , canUserPerformWrite ) ;
85878601
85888602 if ( isVisibleAction && ! isOffline ) {
85898603 // Pop the chat report screen before navigating to the linked report action.
8590- Navigation . goBack ( ROUTES . REPORT_WITH_ID . getRoute ( ancestor . report . reportID , ancestor . reportAction . reportActionID ) ) ;
8604+ Navigation . goBack ( ROUTES . REPORT_WITH_ID . getRoute ( newAncestor . report . reportID , newAncestor . reportAction . reportActionID ) ) ;
85918605 }
85928606}
85938607
0 commit comments