Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get all ancestors in a thread #42554

Merged
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: 2 additions & 12 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6322,33 +6322,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();
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,10 +819,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);
Expand Down
Loading