Skip to content

Commit

Permalink
Merge pull request Expensify#32325 from chie2727/tooltip-31894
Browse files Browse the repository at this point in the history
Fix inconsistent workspace tooltip
  • Loading branch information
nkuoch authored Jan 3, 2024
2 parents f518ab9 + 654bbf0 commit 53afb94
Showing 1 changed file with 48 additions and 46 deletions.
94 changes: 48 additions & 46 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,51 @@ function getChatType(report: OnyxEntry<Report>): ValueOf<typeof CONST.REPORT.CHA
return report?.chatType;
}

/**
* Get the report given a reportID
*/
function getReport(reportID: string | undefined): OnyxEntry<Report> | EmptyObject {
/**
* Using typical string concatenation here due to performance issues
* with template literals.
*/
if (!allReports) {
return {};
}

return allReports?.[ONYXKEYS.COLLECTION.REPORT + reportID] ?? {};
}

/**
* 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);
}

function getPolicy(policyID: string): Policy | EmptyObject {
if (!allPolicies || !policyID) {
return {};
Expand Down Expand Up @@ -461,10 +506,12 @@ function getPolicyName(report: OnyxEntry<Report> | undefined | EmptyObject, retu
}
const finalPolicy = policy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];

const parentReport = getRootParentReport(report);

// Public rooms send back the policy name with the reportSummary,
// since they can also be accessed by people who aren't in the workspace
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const policyName = finalPolicy?.name || report?.policyName || report?.oldPolicyName || noPolicyFound;
const policyName = finalPolicy?.name || report?.policyName || report?.oldPolicyName || parentReport?.oldPolicyName || noPolicyFound;

return policyName;
}
Expand Down Expand Up @@ -1019,21 +1066,6 @@ function isOneOnOneChat(report: OnyxEntry<Report>): boolean {
);
}

/**
* Get the report given a reportID
*/
function getReport(reportID: string | undefined): OnyxEntry<Report> | EmptyObject {
/**
* Using typical string concatenation here due to performance issues
* with template literals.
*/
if (!allReports) {
return {};
}

return allReports?.[ONYXKEYS.COLLECTION.REPORT + reportID] ?? {};
}

/**
* Get the notification preference given a report
*/
Expand Down Expand Up @@ -2132,36 +2164,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>): 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 53afb94

Please sign in to comment.