From 819e1d37c183c333fadb5f3aacc0d69277b5f2fb Mon Sep 17 00:00:00 2001 From: Sophie Aminu Date: Fri, 1 Dec 2023 10:28:46 +0900 Subject: [PATCH 1/3] Fix inconsistent workspace tooltip --- src/libs/ReportUtils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 599963b6a9aa..2d24187b381b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -454,10 +454,12 @@ function getPolicyName(report: OnyxEntry | 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; } @@ -2161,7 +2163,7 @@ function getParentReport(report: OnyxEntry): OnyxEntry | EmptyOb * Returns the root parentReport if the given report is nested. * Uses recursion to iterate any depth of nested reports. */ -function getRootParentReport(report: OnyxEntry): OnyxEntry | EmptyObject { +function getRootParentReport(report: OnyxEntry | undefined | EmptyObject): OnyxEntry | EmptyObject { if (!report) { return {}; } From 384ed2ae257b7ed2d64d7615022f755c70f20087 Mon Sep 17 00:00:00 2001 From: Sophie Aminu <72862115+chie2727@users.noreply.github.com> Date: Wed, 20 Dec 2023 09:30:18 +0900 Subject: [PATCH 2/3] Solve lint error --- src/libs/ReportUtils.ts | 60 ++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 2d24187b381b..79d216c35acd 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -425,6 +425,36 @@ function getChatType(report: OnyxEntry): ValueOf): OnyxEntry | 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 | undefined | EmptyObject): OnyxEntry | 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 {}; @@ -2149,36 +2179,6 @@ function getModifiedExpenseOriginalMessage(oldTransaction: OnyxEntry): OnyxEntry | 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 | undefined | EmptyObject): OnyxEntry | 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. */ From 35d592140b449d4b774e05e9997241a6204aa0d7 Mon Sep 17 00:00:00 2001 From: Sophie Aminu <72862115+chie2727@users.noreply.github.com> Date: Thu, 21 Dec 2023 09:39:54 +0900 Subject: [PATCH 3/3] Solve lint error 2 --- src/libs/ReportUtils.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 79d216c35acd..7c55903d4a2f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -425,6 +425,21 @@ function getChatType(report: OnyxEntry): ValueOf | 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. */ @@ -1012,21 +1027,6 @@ function isOneOnOneChat(report: OnyxEntry): boolean { ); } -/** - * Get the report given a reportID - */ -function getReport(reportID: string | undefined): OnyxEntry | 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 */