From fc407e85fecbac09a73d9a778ac1f9043404b645 Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 2 Jul 2026 15:38:52 +0700 Subject: [PATCH] refactor getParentNavigationSubtitle function to use translate param --- src/components/AvatarWithDisplayName.tsx | 2 +- src/libs/ReportUtils.ts | 9 +++++---- src/pages/DynamicReportDetailsPage.tsx | 2 +- src/pages/ShareCodePage.tsx | 2 +- src/pages/inbox/HeaderView.tsx | 2 +- tests/unit/ReportUtilsTest.ts | 16 ++++++++-------- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/components/AvatarWithDisplayName.tsx b/src/components/AvatarWithDisplayName.tsx index 57fdddabb0c7..6b2676536a17 100644 --- a/src/components/AvatarWithDisplayName.tsx +++ b/src/components/AvatarWithDisplayName.tsx @@ -203,7 +203,7 @@ function AvatarWithDisplayName({ const title = getReportName(report, reportAttributes); const isParentReportArchived = useReportIsArchived(report?.parentReportID); const subtitle = getChatRoomSubtitle(report, policy, conciergeReportID, translate, true, isReportArchived); - const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, isParentReportArchived, reportAttributes); + const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, translate, isParentReportArchived, reportAttributes); const isMoneyRequestOrReport = isMoneyRequestReport(report) || isMoneyRequest(report) || isTrackExpenseReport(report) || isInvoiceReport(report); const ownerPersonalDetails = getPersonalDetailsForAccountIDs(report?.ownerAccountID ? [report.ownerAccountID] : [], personalDetails); const displayNamesWithTooltips = getDisplayNamesWithTooltips(Object.values(ownerPersonalDetails), false, localeCompare, formatPhoneNumber); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a768fd0e6716..b6ea8f325c6f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6009,6 +6009,7 @@ function getParentNavigationSubtitle( report: OnyxEntry, policy: OnyxEntry, conciergeReportID: string | undefined, + translate: LocalizedTranslate, isParentReportArchived = false, reportAttributes?: ReportAttributesDerivedValue['reports'], ): ParentNavigationSummaryParams { @@ -6023,8 +6024,8 @@ function getParentNavigationSubtitle( if (isExpenseReport(report)) { return { - reportName: translateLocal('workspace.common.policyExpenseChatName', reportOwnerDisplayName ?? ''), - workspaceName: getPolicyName({report, policy}), + reportName: translate('workspace.common.policyExpenseChatName', reportOwnerDisplayName ?? ''), + workspaceName: getPolicyName({report, policy, unavailableTranslation: translate('workspace.common.unavailable')}), }; } if (isIOUReport(report)) { @@ -6034,7 +6035,7 @@ function getParentNavigationSubtitle( } if (isInvoiceReport(report) || isInvoiceRoom(parentReport)) { - const senderWorkspaceName = getPolicyName({report: parentReport, policy}); + const senderWorkspaceName = getPolicyName({report: parentReport, policy, unavailableTranslation: translate('workspace.common.unavailable')}); const invoiceReceiverPolicyID = getInvoiceReceiverPolicyID(parentReport); const invoiceReceiverPolicy = invoiceReceiverPolicyID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiverPolicyID}`] : undefined; const isCurrentUserReceiver = isCurrentUserInvoiceReceiver(parentReport); @@ -6046,7 +6047,7 @@ function getParentNavigationSubtitle( } if (isArchivedNonExpenseReport(parentReport, isParentReportArchived)) { - reportName += ` (${translateLocal('common.archived')})`; + reportName += ` (${translate('common.archived')})`; } return { diff --git a/src/pages/DynamicReportDetailsPage.tsx b/src/pages/DynamicReportDetailsPage.tsx index 799c8c268a0f..d495875802a9 100644 --- a/src/pages/DynamicReportDetailsPage.tsx +++ b/src/pages/DynamicReportDetailsPage.tsx @@ -247,7 +247,7 @@ function DynamicReportDetailsPage({policy, report, route, reportMetadata, report const isReportArchived = useReportIsArchived(report?.reportID); const isArchivedRoom = useMemo(() => isArchivedNonExpenseReport(report, isReportArchived), [report, isReportArchived]); const shouldDisableRename = useMemo(() => shouldDisableRenameUtil(report, isReportArchived), [report, isReportArchived]); - const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, isParentReportArchived); + const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, translate, isParentReportArchived); const base62ReportID = getBase62ReportID(Number(report.reportID)); const ancestors = useAncestors(report); diff --git a/src/pages/ShareCodePage.tsx b/src/pages/ShareCodePage.tsx index 3754af75f5ae..780ef3cb54c3 100644 --- a/src/pages/ShareCodePage.tsx +++ b/src/pages/ShareCodePage.tsx @@ -99,7 +99,7 @@ function ShareCodePage({report, policy, backTo}: ShareCodePageProps) { } return ( - getParentNavigationSubtitle(report, policy, conciergeReportID, isParentReportArchived).workspaceName ?? + getParentNavigationSubtitle(report, policy, conciergeReportID, translate, isParentReportArchived).workspaceName ?? getChatRoomSubtitle(report, policy, conciergeReportID, translate, false, isReportArchived) ); } diff --git a/src/pages/inbox/HeaderView.tsx b/src/pages/inbox/HeaderView.tsx index 78fda0816ff0..bfeda6384a19 100644 --- a/src/pages/inbox/HeaderView.tsx +++ b/src/pages/inbox/HeaderView.tsx @@ -165,7 +165,7 @@ function HeaderView({onNavigationMenuButtonClicked, reportID}: HeaderViewProps) ? getReportStatusTooltipTranslation({stateNum: reportHeaderData?.stateNum, statusNum: reportHeaderData?.statusNum, translate}) : undefined; const isParentReportHeaderDataArchived = useReportIsArchived(reportHeaderData?.parentReportID); - const parentNavigationSubtitleData = getParentNavigationSubtitle(parentNavigationReport, policy, conciergeReportID, isParentReportHeaderDataArchived); + const parentNavigationSubtitleData = getParentNavigationSubtitle(parentNavigationReport, policy, conciergeReportID, translate, isParentReportHeaderDataArchived); const humanAgentAccountID = getHumanAgentAccountIDFromReportAction(parentReportAction); const humanAgentName = getHumanAgentFirstName(parentReportAction, personalDetails); const reportDescription = StringUtils.lineBreaksToSpaces(Parser.htmlToText(getReportDescription(report))); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 4bd706dad4ea..839fbe73e7c6 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -3180,13 +3180,13 @@ describe('ReportUtils', () => { }); it('should return the correct parent navigation subtitle for the archived invoice report', () => { - const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, true); + const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal, true); const normalizedActual = {...actual, reportName: actual.reportName?.replaceAll('\u00A0', ' ')}; expect(normalizedActual).toEqual({reportName: 'A workspace & Ragnar Lothbrok (archived)'}); }); it('should return the correct parent navigation subtitle for the non archived invoice report', () => { - const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, false); + const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal, false); const normalizedActual = {...actual, reportName: actual.reportName?.replaceAll('\u00A0', ' ')}; expect(normalizedActual).toEqual({reportName: 'A workspace & Ragnar Lothbrok'}); }); @@ -3205,7 +3205,7 @@ describe('ReportUtils', () => { role: CONST.POLICY.ROLE.ADMIN, }); - const actual = getParentNavigationSubtitle(expenseReport, testPolicy, undefined); + const actual = getParentNavigationSubtitle(expenseReport, testPolicy, undefined, translateLocal); expect(actual.workspaceName).toBe('Direct Policy Name'); }); @@ -3233,14 +3233,14 @@ describe('ReportUtils', () => { }; return Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}200`, parentInvoiceRoom).then(() => { - const actual = getParentNavigationSubtitle(invoiceReport, testPolicy, undefined); + const actual = getParentNavigationSubtitle(invoiceReport, testPolicy, undefined, translateLocal); const normalizedActual = {...actual, reportName: actual.reportName?.replaceAll('\u00A0', ' ')}; expect(normalizedActual.reportName).toContain('Invoice Policy'); }); }); it('should fall back to allPolicies when policy parameter is undefined', () => { - const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined); + const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal); const normalizedActual = {...actual, reportName: actual.reportName?.replaceAll('\u00A0', ' ')}; // Should still resolve via Onyx-connected allPolicies or report.policyName expect(normalizedActual.reportName).toContain('A workspace'); @@ -3253,7 +3253,7 @@ describe('ReportUtils', () => { reportName: 'Chat Report', type: CONST.REPORT.TYPE.CHAT, }; - const actual = getParentNavigationSubtitle(chatReport, undefined, undefined); + const actual = getParentNavigationSubtitle(chatReport, undefined, undefined, translateLocal); expect(actual).toEqual({}); }); @@ -3280,13 +3280,13 @@ describe('ReportUtils', () => { }) .then(waitForBatchedUpdates) .then(() => { - const actual = getParentNavigationSubtitle(childReport, undefined, conciergeReportID); + const actual = getParentNavigationSubtitle(childReport, undefined, conciergeReportID, translateLocal); expect(actual.reportName).toBe('Concierge'); }); }); it('should return reportName and workspaceName when parent report exists and conciergeReportID is undefined', () => { - const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, false); + const actual = getParentNavigationSubtitle(baseArchivedPolicyExpenseChat, undefined, undefined, translateLocal); expect(actual).toHaveProperty('reportName'); }); });