Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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';
Expand Down Expand Up @@ -5051,9 +5052,13 @@ function getReportPreviewMessage(
policy?: OnyxInputOrEntry<Policy>,
isForListPreview = false,
originalReportAction: OnyxInputOrEntry<ReportAction> = iouReportAction,
isCopyAction = false,
): string {
const report = typeof reportOrID === 'string' ? getReport(reportOrID, allReports) : reportOrID;
const reportActionMessage = getReportActionHtml(iouReportAction);
if (isCopyAction && report) {
return computeReportName(report) || (originalReportAction?.childReportName ?? '');
}
Comment thread
mountiny marked this conversation as resolved.
Resolved

if (isEmptyObject(report) || !report?.reportID) {
// This iouReport may be unavailable for one of the following reasons:
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,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);
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down