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 inconsistent workspace tooltip #32325

Merged
merged 4 commits into from
Jan 3, 2024
Merged
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
94 changes: 48 additions & 46 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,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

This comment was marked as outdated.

* with template literals.
*/
Comment on lines +438 to +441

This comment was marked as outdated.

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}`] ?? {};

This comment was marked as outdated.

}

/**
* Returns the root parentReport if the given report is nested.

This comment was marked as outdated.

* Uses recursion to iterate any depth of nested reports.

This comment was marked as outdated.

*/
function getRootParentReport(report: OnyxEntry<Report> | undefined | EmptyObject): OnyxEntry<Report> | EmptyObject {

This comment was marked as outdated.

if (!report) {
return {};
}

// Returns the current report as the root report, because it does not have a parentReportID

This comment was marked as outdated.

if (!report?.parentReportID) {
return report;
}

const parentReport = getReport(report?.parentReportID);

// Runs recursion to iterate a parent report

This comment was marked as outdated.

return getRootParentReport(isNotEmptyObject(parentReport) ? parentReport : null);
}

function getPolicy(policyID: string): Policy | EmptyObject {
if (!allPolicies || !policyID) {
return {};
Expand Down Expand Up @@ -460,10 +505,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 @@ -1018,21 +1065,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 @@ -2129,36 +2161,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
Loading