diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index f30137894d91..decf23597c39 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6446,33 +6446,23 @@ function getAllAncestorReportActions(report: Report | null | undefined): Ancesto let parentReportID = report.parentReportID; let parentReportActionID = report.parentReportActionID; - // Store the child of parent report - let currentReport = report; - while (parentReportID) { const parentReport = getReport(parentReportID); const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, parentReportActionID ?? '0'); - if (!parentReportAction || ReportActionsUtils.isTransactionThread(parentReportAction) || ReportActionsUtils.isReportPreviewAction(parentReportAction)) { + if (!parentReport || !parentReportAction || ReportActionsUtils.isTransactionThread(parentReportAction) || ReportActionsUtils.isReportPreviewAction(parentReportAction)) { break; } const isParentReportActionUnread = ReportActionsUtils.isCurrentActionUnread(parentReport ?? {}, parentReportAction); allAncestors.push({ - report: currentReport, + report: parentReport, reportAction: parentReportAction, shouldDisplayNewMarker: isParentReportActionUnread, }); - if (!parentReport) { - break; - } - parentReportID = parentReport?.parentReportID; parentReportActionID = parentReport?.parentReportActionID; - if (!isEmptyObject(parentReport)) { - currentReport = parentReport; - } } return allAncestors.reverse(); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 81d8bd8357f0..1e822f9d2cbb 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -812,10 +812,10 @@ describe('ReportUtils', () => { it('should return correctly all ancestors of a thread report', () => { const resultAncestors = [ - {report: reports[1], reportAction: reportActions[0], shouldDisplayNewMarker: false}, - {report: reports[2], reportAction: reportActions[1], shouldDisplayNewMarker: false}, - {report: reports[3], reportAction: reportActions[2], shouldDisplayNewMarker: false}, - {report: reports[4], reportAction: reportActions[3], shouldDisplayNewMarker: false}, + {report: reports[0], reportAction: reportActions[0], shouldDisplayNewMarker: false}, + {report: reports[1], reportAction: reportActions[1], shouldDisplayNewMarker: false}, + {report: reports[2], reportAction: reportActions[2], shouldDisplayNewMarker: false}, + {report: reports[3], reportAction: reportActions[3], shouldDisplayNewMarker: false}, ]; expect(ReportUtils.getAllAncestorReportActions(reports[4])).toEqual(resultAncestors);