From a0f8b98d25293f95ec116a640f8eff0691c03373 Mon Sep 17 00:00:00 2001 From: truph01 Date: Wed, 24 Dec 2025 03:52:31 +0700 Subject: [PATCH 1/4] fix: copy content in case of report preview --- src/libs/ReportUtils.ts | 5 +++++ src/pages/home/report/ContextMenu/ContextMenuActions.tsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9c8181b47658..339ac4fc5ee6 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -24,6 +24,7 @@ import type {LocaleContextProps} from '@components/LocaleContextProvider'; import type {MoneyRequestAmountInputProps} from '@components/MoneyRequestAmountInput'; import type {TransactionWithOptionalSearchFields} from '@components/TransactionItemRow'; import type PolicyData from '@hooks/usePolicyData/types'; +import {computeReportName} from '@libs/ReportNameUtils'; import type {PolicyTagList} from '@pages/workspace/tags/types'; import type {ThemeColors} from '@styles/theme/types'; import type {IOUAction, IOUType, OnboardingAccounting} from '@src/CONST'; @@ -5154,9 +5155,13 @@ function getReportPreviewMessage( policy?: OnyxInputOrEntry, isForListPreview = false, originalReportAction: OnyxInputOrEntry = iouReportAction, + isCopyAction = false, ): string { const report = typeof reportOrID === 'string' ? getReport(reportOrID, allReports) : reportOrID; const reportActionMessage = getReportActionHtml(iouReportAction); + if (isCopyAction) { + return computeReportName(report as Report) || (originalReportAction?.childReportName ?? ''); + } if (isEmptyObject(report) || !report?.reportID) { // This iouReport may be unavailable for one of the following reasons: diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx index 383c6784a246..9c047be085e6 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.tsx @@ -654,7 +654,7 @@ const ContextMenuActions: ContextMenuAction[] = [ const content = selection || messageHtml; if (isReportPreviewAction) { const iouReportID = getIOUReportIDFromReportActionPreview(reportAction); - const displayMessage = getReportPreviewMessage(iouReportID, reportAction); + const displayMessage = getReportPreviewMessage(iouReportID, reportAction, undefined, undefined, undefined, undefined, undefined, true); Clipboard.setString(displayMessage); } else if (isTaskActionReportActionsUtils(reportAction)) { const {text, html} = getTaskReportActionMessage(reportAction); From 8e1effa7edca6f58a89149ffa1721969b9148772 Mon Sep 17 00:00:00 2001 From: truph01 Date: Wed, 24 Dec 2025 04:13:48 +0700 Subject: [PATCH 2/4] fix: lint --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 339ac4fc5ee6..c38da947f62c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5160,7 +5160,7 @@ function getReportPreviewMessage( const report = typeof reportOrID === 'string' ? getReport(reportOrID, allReports) : reportOrID; const reportActionMessage = getReportActionHtml(iouReportAction); if (isCopyAction) { - return computeReportName(report as Report) || (originalReportAction?.childReportName ?? ''); + return computeReportName(report!) || (originalReportAction?.childReportName ?? ''); } if (isEmptyObject(report) || !report?.reportID) { From c4773d83c661adfcb355275dc3a4a465d6feb518 Mon Sep 17 00:00:00 2001 From: truph01 Date: Wed, 24 Dec 2025 04:19:01 +0700 Subject: [PATCH 3/4] fix: lint --- src/libs/ReportUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c38da947f62c..70dd654c7e40 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5159,8 +5159,8 @@ function getReportPreviewMessage( ): string { const report = typeof reportOrID === 'string' ? getReport(reportOrID, allReports) : reportOrID; const reportActionMessage = getReportActionHtml(iouReportAction); - if (isCopyAction) { - return computeReportName(report!) || (originalReportAction?.childReportName ?? ''); + if (isCopyAction && report) { + return computeReportName(report) || (originalReportAction?.childReportName ?? ''); } if (isEmptyObject(report) || !report?.reportID) { From 33d8e9f078713759f81b8d06f0fd969b84167eba Mon Sep 17 00:00:00 2001 From: truph01 Date: Mon, 5 Jan 2026 11:50:29 +0700 Subject: [PATCH 4/4] fix: add unit test when isCopyAction = true --- tests/unit/ReportUtilsTest.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index e4a4b14b4ab2..d7a3ee6ab378 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -10127,6 +10127,22 @@ describe('ReportUtils', () => { // Then it should return the message from the report action (not the childReportName) expect(result).toBe('payer owes $100'); }); + it('should return expense report name when isCopyAction is true', async () => { + const report = LHNTestUtils.getFakeReport(); + report.reportName = 'Expense Report 2025-01-15'; + const reportAction: ReportAction = { + ...LHNTestUtils.getFakeReportAction(), + actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW, + childReportName: report.reportName, + childMoneyRequestCount: 0, + }; + + // When we call getReportPreviewMessage with isCopyAction = true + const result = getReportPreviewMessage(report, reportAction, false, false, undefined, false, reportAction, true); + + // Then it should return the childReportName instead of "payer owes $0" + expect(result).toBe('Expense Report 2025-01-15'); + }); }); describe('getAvailableReportFields', () => {