Skip to content

Commit

Permalink
Solve lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
chie2727 authored Dec 20, 2023
1 parent 819e1d3 commit 384ed2a
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,36 @@ function getChatType(report: OnyxEntry<Report>): ValueOf<typeof CONST.REPORT.CHA
return report?.chatType;
}

/**
* Returns the parentReport if the given report is a thread.
*/
function getParentReport(report: OnyxEntry<Report>): OnyxEntry<Report> | EmptyObject {
if (!report?.parentReportID) {
return {};
}
return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`] ?? {};
}

/**
* Returns the root parentReport if the given report is nested.
* Uses recursion to iterate any depth of nested reports.
*/
function getRootParentReport(report: OnyxEntry<Report> | undefined | EmptyObject): OnyxEntry<Report> | EmptyObject {
if (!report) {
return {};
}

Check failure on line 445 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / lint

'getReport' was used before it was defined

// Returns the current report as the root report, because it does not have a parentReportID
if (!report?.parentReportID) {
return report;
}

const parentReport = getReport(report?.parentReportID);

// Runs recursion to iterate a parent report
return getRootParentReport(isNotEmptyObject(parentReport) ? parentReport : null);
}

function getPolicy(policyID: string): Policy | EmptyObject {
if (!allPolicies || !policyID) {
return {};
Expand Down Expand Up @@ -2149,36 +2179,6 @@ function getModifiedExpenseOriginalMessage(oldTransaction: OnyxEntry<Transaction
return originalMessage;
}

/**
* Returns the parentReport if the given report is a thread.
*/
function getParentReport(report: OnyxEntry<Report>): OnyxEntry<Report> | EmptyObject {
if (!report?.parentReportID) {
return {};
}
return allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`] ?? {};
}

/**
* Returns the root parentReport if the given report is nested.
* Uses recursion to iterate any depth of nested reports.
*/
function getRootParentReport(report: OnyxEntry<Report> | undefined | EmptyObject): OnyxEntry<Report> | EmptyObject {
if (!report) {
return {};
}

// Returns the current report as the root report, because it does not have a parentReportID
if (!report?.parentReportID) {
return report;
}

const parentReport = getReport(report?.parentReportID);

// Runs recursion to iterate a parent report
return getRootParentReport(isNotEmptyObject(parentReport) ? parentReport : null);
}

/**
* Get the title for a report.
*/
Expand Down

0 comments on commit 384ed2a

Please sign in to comment.