Skip to content

Commit e6a731b

Browse files
authored
Merge pull request Expensify#64158 from dmkt9/fix/63338
Fix - Thread on a message in IOU creates an extra level of thread
2 parents 3007396 + f23e8de commit e6a731b

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8569,25 +8569,39 @@ function isMoneyRequestReportPendingDeletion(reportOrID: OnyxEntry<Report> | str
85698569
}
85708570

85718571
function 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

src/pages/home/HeaderView.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ import {
5454
isChatUsedForOnboarding as isChatUsedForOnboardingReportUtils,
5555
isCurrentUserSubmitter,
5656
isDeprecatedGroupDM,
57+
isExpenseReport,
5758
isExpenseRequest,
5859
isGroupChat as isGroupChatReportUtils,
60+
isIOUReport,
5961
isOpenTaskReport,
6062
isPolicyExpenseChat as isPolicyExpenseChatReportUtils,
6163
isSelfDM as isSelfDMReportUtils,
@@ -136,7 +138,11 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
136138
const isChatRoom = isChatRoomReportUtils(report);
137139
const isPolicyExpenseChat = isPolicyExpenseChatReportUtils(report);
138140
const isTaskReport = isTaskReportReportUtils(report);
139-
const reportHeaderData = !isTaskReport && !isChatThread && report?.parentReportID ? parentReport : report;
141+
const [parentOfParentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReport?.parentReportID}`, {canBeMissing: true});
142+
const reportHeaderData =
143+
((!isTaskReport && !isChatThread) || (parentOfParentReport && (isIOUReport(parentOfParentReport) || isExpenseReport(parentOfParentReport)))) && report?.parentReportID
144+
? parentReport
145+
: report;
140146
// Use sorted display names for the title for group chats on native small screen widths
141147
const title = getReportName(reportHeaderData, policy, parentReportAction, personalDetails, invoiceReceiverPolicy);
142148
const subtitle = getChatRoomSubtitle(reportHeaderData);
@@ -302,8 +308,8 @@ function HeaderView({report, parentReportAction, onNavigationMenuButtonClicked,
302308
{!isEmptyObject(parentNavigationSubtitleData) && (
303309
<ParentNavigationSubtitle
304310
parentNavigationSubtitleData={parentNavigationSubtitleData}
305-
parentReportID={report?.parentReportID}
306-
parentReportActionID={report?.parentReportActionID}
311+
parentReportID={reportHeaderData?.parentReportID}
312+
parentReportActionID={reportHeaderData?.parentReportActionID}
307313
pressableStyles={[styles.alignSelfStart, styles.mw100]}
308314
/>
309315
)}

0 commit comments

Comments
 (0)