From 2abcf727f390493c1b65086b5c269232cedd6da8 Mon Sep 17 00:00:00 2001 From: Carlos Barros <765936+barros001@users.noreply.github.com> Date: Wed, 28 Feb 2024 10:28:58 -0500 Subject: [PATCH 1/5] when getting the navigation subtitle, do not recursively go through parents, but rather always use the immediate parent --- src/libs/ReportUtils.ts | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0f8656adfa51..520a76306047 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2558,19 +2558,14 @@ function getReportName(report: OnyxEntry, policy: OnyxEntry = nu } /** - * Recursively navigates through thread parents to get the root report and workspace name. - * The recursion stops when we find a non thread or money request report, whichever comes first. + * Get the report name and workspace name for a report based on the type of the report */ -function getRootReportAndWorkspaceName(report: OnyxEntry): ReportAndWorkspaceName { +function getReportAndWorkspaceName(report: OnyxEntry): ReportAndWorkspaceName { if (!report) { return { rootReportName: '', }; } - if (isChildReport(report) && !isMoneyRequestReport(report) && !isTaskReport(report)) { - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; - return getRootReportAndWorkspaceName(parentReport); - } if (isIOURequest(report)) { return { @@ -2617,16 +2612,17 @@ function getChatRoomSubtitle(report: OnyxEntry): string | undefined { * Gets the parent navigation subtitle for the report */ function getParentNavigationSubtitle(report: OnyxEntry): ParentNavigationSummaryParams { - if (isThread(report)) { - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; - const {rootReportName, workspaceName} = getRootReportAndWorkspaceName(parentReport); - if (!rootReportName) { - return {}; - } + if (!isThread(report)) { + return {}; + } - return {rootReportName, workspaceName}; + const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; + const {rootReportName, workspaceName} = getReportAndWorkspaceName(parentReport); + if (!rootReportName) { + return {}; } - return {}; + + return {rootReportName, workspaceName}; } /** From 4d9846a4f0ed0775ecdb3622f6003e5938c7c56c Mon Sep 17 00:00:00 2001 From: Carlos Barros <765936+barros001@users.noreply.github.com> Date: Wed, 28 Feb 2024 10:35:47 -0500 Subject: [PATCH 2/5] combine getParentNavigationSubtitle and getReportAndWorkspaceName --- src/libs/ReportUtils.ts | 54 ++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 520a76306047..867e1e3f5a12 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -98,11 +98,6 @@ type SpendBreakdown = { type ParticipantDetails = [number, string, UserUtils.AvatarSource, UserUtils.AvatarSource]; -type ReportAndWorkspaceName = { - rootReportName: string; - workspaceName?: string; -}; - type OptimisticAddCommentReportAction = Pick< ReportAction, | 'reportActionID' @@ -2557,34 +2552,6 @@ function getReportName(report: OnyxEntry, policy: OnyxEntry = nu return participantsWithoutCurrentUser.map((accountID) => getDisplayNameForParticipant(accountID, isMultipleParticipantReport)).join(', '); } -/** - * Get the report name and workspace name for a report based on the type of the report - */ -function getReportAndWorkspaceName(report: OnyxEntry): ReportAndWorkspaceName { - if (!report) { - return { - rootReportName: '', - }; - } - - if (isIOURequest(report)) { - return { - rootReportName: getReportName(report), - }; - } - if (isExpenseRequest(report)) { - return { - rootReportName: getReportName(report), - workspaceName: isIOUReport(report) ? CONST.POLICY.OWNER_EMAIL_FAKE : getPolicyName(report, true), - }; - } - - return { - rootReportName: getReportName(report), - workspaceName: getPolicyName(report, true), - }; -} - /** * Get either the policyName or domainName the chat is tied to */ @@ -2617,12 +2584,27 @@ function getParentNavigationSubtitle(report: OnyxEntry): ParentNavigatio } const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; - const {rootReportName, workspaceName} = getReportAndWorkspaceName(parentReport); - if (!rootReportName) { + if (!parentReport) { return {}; } - return {rootReportName, workspaceName}; + if (isIOURequest(parentReport)) { + return { + rootReportName: getReportName(parentReport), + }; + } + + if (isExpenseRequest(parentReport)) { + return { + rootReportName: getReportName(parentReport), + workspaceName: isIOUReport(parentReport) ? CONST.POLICY.OWNER_EMAIL_FAKE : getPolicyName(parentReport, true), + }; + } + + return { + rootReportName: getReportName(parentReport), + workspaceName: getPolicyName(parentReport, true), + }; } /** From 610ce2667f7b4104ecb157a8c399249a15ff91cf Mon Sep 17 00:00:00 2001 From: Carlos Barros <765936+barros001@users.noreply.github.com> Date: Wed, 28 Feb 2024 10:39:52 -0500 Subject: [PATCH 3/5] renamed rootReportName to reportNameon ParentNavigationSummaryParams type --- src/components/ParentNavigationSubtitle.tsx | 6 +++--- src/languages/en.ts | 2 +- src/languages/es.ts | 2 +- src/languages/types.ts | 2 +- src/libs/ReportUtils.ts | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/ParentNavigationSubtitle.tsx b/src/components/ParentNavigationSubtitle.tsx index 2816715dae2c..3109453ca6b0 100644 --- a/src/components/ParentNavigationSubtitle.tsx +++ b/src/components/ParentNavigationSubtitle.tsx @@ -21,7 +21,7 @@ type ParentNavigationSubtitleProps = { function ParentNavigationSubtitle({parentNavigationSubtitleData, parentReportID = '', pressableStyles}: ParentNavigationSubtitleProps) { const styles = useThemeStyles(); - const {workspaceName, rootReportName} = parentNavigationSubtitleData; + const {workspaceName, reportName} = parentNavigationSubtitleData; const {translate} = useLocalize(); @@ -30,7 +30,7 @@ function ParentNavigationSubtitle({parentNavigationSubtitleData, parentReportID onPress={() => { Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(parentReportID)); }} - accessibilityLabel={translate('threads.parentNavigationSummary', {rootReportName, workspaceName})} + accessibilityLabel={translate('threads.parentNavigationSummary', {reportName, workspaceName})} role={CONST.ROLE.LINK} style={pressableStyles} > @@ -39,7 +39,7 @@ function ParentNavigationSubtitle({parentNavigationSubtitleData, parentReportID numberOfLines={1} > {`${translate('threads.from')} `} - {rootReportName} + {reportName} {Boolean(workspaceName) && {` ${translate('threads.in')} ${workspaceName}`}} diff --git a/src/languages/en.ts b/src/languages/en.ts index cf8823f5b2be..35b9dd9a18d1 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -2171,7 +2171,7 @@ export default { reply: 'Reply', from: 'From', in: 'in', - parentNavigationSummary: ({rootReportName, workspaceName}: ParentNavigationSummaryParams) => `From ${rootReportName}${workspaceName ? ` in ${workspaceName}` : ''}`, + parentNavigationSummary: ({reportName, workspaceName}: ParentNavigationSummaryParams) => `From ${reportName}${workspaceName ? ` in ${workspaceName}` : ''}`, }, qrCodes: { copy: 'Copy URL', diff --git a/src/languages/es.ts b/src/languages/es.ts index b3a8eef73d7c..398010caf656 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -2659,7 +2659,7 @@ export default { reply: 'Respuesta', from: 'De', in: 'en', - parentNavigationSummary: ({rootReportName, workspaceName}: ParentNavigationSummaryParams) => `De ${rootReportName}${workspaceName ? ` en ${workspaceName}` : ''}`, + parentNavigationSummary: ({reportName, workspaceName}: ParentNavigationSummaryParams) => `De ${reportName}${workspaceName ? ` en ${workspaceName}` : ''}`, }, qrCodes: { copy: 'Copiar URL', diff --git a/src/languages/types.ts b/src/languages/types.ts index bb56d5c38cd3..ed82bcd99a92 100644 --- a/src/languages/types.ts +++ b/src/languages/types.ts @@ -195,7 +195,7 @@ type OOOEventSummaryFullDayParams = {summary: string; dayCount: number; date: st type OOOEventSummaryPartialDayParams = {summary: string; timePeriod: string; date: string}; -type ParentNavigationSummaryParams = {rootReportName?: string; workspaceName?: string}; +type ParentNavigationSummaryParams = {reportName?: string; workspaceName?: string}; type SetTheRequestParams = {valueName: string; newValueToDisplay: string}; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 867e1e3f5a12..97b4d93790c7 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2590,19 +2590,19 @@ function getParentNavigationSubtitle(report: OnyxEntry): ParentNavigatio if (isIOURequest(parentReport)) { return { - rootReportName: getReportName(parentReport), + reportName: getReportName(parentReport), }; } if (isExpenseRequest(parentReport)) { return { - rootReportName: getReportName(parentReport), + reportName: getReportName(parentReport), workspaceName: isIOUReport(parentReport) ? CONST.POLICY.OWNER_EMAIL_FAKE : getPolicyName(parentReport, true), }; } return { - rootReportName: getReportName(parentReport), + reportName: getReportName(parentReport), workspaceName: getPolicyName(parentReport, true), }; } From 46ecf2449c8a3cc09fbcc9f505220a11219f3300 Mon Sep 17 00:00:00 2001 From: Carlos Barros <765936+barros001@users.noreply.github.com> Date: Wed, 28 Feb 2024 14:50:54 -0500 Subject: [PATCH 4/5] simplified getParentNavigationSubtitle logic --- src/libs/ReportUtils.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 97b4d93790c7..3eea36727ea0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2579,12 +2579,8 @@ function getChatRoomSubtitle(report: OnyxEntry): string | undefined { * Gets the parent navigation subtitle for the report */ function getParentNavigationSubtitle(report: OnyxEntry): ParentNavigationSummaryParams { - if (!isThread(report)) { - return {}; - } - - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; - if (!parentReport) { + const parentReport = getParentReport(report); + if (isEmptyObject(parentReport)) { return {}; } @@ -2594,13 +2590,6 @@ function getParentNavigationSubtitle(report: OnyxEntry): ParentNavigatio }; } - if (isExpenseRequest(parentReport)) { - return { - reportName: getReportName(parentReport), - workspaceName: isIOUReport(parentReport) ? CONST.POLICY.OWNER_EMAIL_FAKE : getPolicyName(parentReport, true), - }; - } - return { reportName: getReportName(parentReport), workspaceName: getPolicyName(parentReport, true), From 663eb40fe11126d083df2b858872ba848fa0a1d3 Mon Sep 17 00:00:00 2001 From: Carlos Barros <765936+barros001@users.noreply.github.com> Date: Wed, 28 Feb 2024 15:28:30 -0500 Subject: [PATCH 5/5] removed unnecessary if block that was removing the policy name from header when it was not supposed to. --- src/libs/ReportUtils.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ee2dcf5d02d6..be75f6c28909 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2585,12 +2585,6 @@ function getParentNavigationSubtitle(report: OnyxEntry): ParentNavigatio return {}; } - if (isIOURequest(parentReport)) { - return { - reportName: getReportName(parentReport), - }; - } - return { reportName: getReportName(parentReport), workspaceName: getPolicyName(parentReport, true),