Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6457,23 +6457,33 @@ 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 (!parentReport || !parentReportAction || ReportActionsUtils.isTransactionThread(parentReportAction) || ReportActionsUtils.isReportPreviewAction(parentReportAction)) {
if (!parentReportAction || ReportActionsUtils.isTransactionThread(parentReportAction) || ReportActionsUtils.isReportPreviewAction(parentReportAction)) {
break;
}

const isParentReportActionUnread = ReportActionsUtils.isCurrentActionUnread(parentReport ?? {}, parentReportAction);
allAncestors.push({
report: parentReport,
report: currentReport,
reportAction: parentReportAction,
shouldDisplayNewMarker: isParentReportActionUnread,
});

if (!parentReport) {
break;
}

parentReportID = parentReport?.parentReportID;
parentReportActionID = parentReport?.parentReportActionID;
if (!isEmptyObject(parentReport)) {
currentReport = parentReport;
}
}

return allAncestors.reverse();
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,10 @@ describe('ReportUtils', () => {

it('should return correctly all ancestors of a thread report', () => {
const resultAncestors = [
{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},
{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},
];

expect(ReportUtils.getAllAncestorReportActions(reports[4])).toEqual(resultAncestors);
Expand Down