Skip to content

Commit 203738a

Browse files
authored
Merge pull request Expensify#78409 from truph01/fix/77158
fix: copy content in case of report preview
2 parents 4c8fe90 + 33d8e9f commit 203738a

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/libs/ReportUtils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {LocaleContextProps} from '@components/LocaleContextProvider';
2323
import type {MoneyRequestAmountInputProps} from '@components/MoneyRequestAmountInput';
2424
import type {TransactionWithOptionalSearchFields} from '@components/TransactionItemRow';
2525
import type PolicyData from '@hooks/usePolicyData/types';
26+
import {computeReportName} from '@libs/ReportNameUtils';
2627
import type {PolicyTagList} from '@pages/workspace/tags/types';
2728
import type {ThemeColors} from '@styles/theme/types';
2829
import type {IOUAction, IOUType, OnboardingAccounting} from '@src/CONST';
@@ -5057,9 +5058,13 @@ function getReportPreviewMessage(
50575058
policy?: OnyxInputOrEntry<Policy>,
50585059
isForListPreview = false,
50595060
originalReportAction: OnyxInputOrEntry<ReportAction> = iouReportAction,
5061+
isCopyAction = false,
50605062
): string {
50615063
const report = typeof reportOrID === 'string' ? getReport(reportOrID, allReports) : reportOrID;
50625064
const reportActionMessage = getReportActionHtml(iouReportAction);
5065+
if (isCopyAction && report) {
5066+
return computeReportName(report) || (originalReportAction?.childReportName ?? '');
5067+
}
50635068

50645069
if (isEmptyObject(report) || !report?.reportID) {
50655070
// This iouReport may be unavailable for one of the following reasons:

src/pages/home/report/ContextMenu/ContextMenuActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ const ContextMenuActions: ContextMenuAction[] = [
617617
const content = selection || messageHtml;
618618
if (isReportPreviewAction) {
619619
const iouReportID = getIOUReportIDFromReportActionPreview(reportAction);
620-
const displayMessage = getReportPreviewMessage(iouReportID, reportAction);
620+
const displayMessage = getReportPreviewMessage(iouReportID, reportAction, undefined, undefined, undefined, undefined, undefined, true);
621621
Clipboard.setString(displayMessage);
622622
} else if (isTaskActionReportActionsUtils(reportAction)) {
623623
const {text, html} = getTaskReportActionMessage(reportAction);

tests/unit/ReportUtilsTest.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10519,6 +10519,22 @@ describe('ReportUtils', () => {
1051910519
// Then it should return the message from the report action (not the childReportName)
1052010520
expect(result).toBe('payer owes $100');
1052110521
});
10522+
it('should return expense report name when isCopyAction is true', async () => {
10523+
const report = LHNTestUtils.getFakeReport();
10524+
report.reportName = 'Expense Report 2025-01-15';
10525+
const reportAction: ReportAction = {
10526+
...LHNTestUtils.getFakeReportAction(),
10527+
actionName: CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW,
10528+
childReportName: report.reportName,
10529+
childMoneyRequestCount: 0,
10530+
};
10531+
10532+
// When we call getReportPreviewMessage with isCopyAction = true
10533+
const result = getReportPreviewMessage(report, reportAction, false, false, undefined, false, reportAction, true);
10534+
10535+
// Then it should return the childReportName instead of "payer owes $0"
10536+
expect(result).toBe('Expense Report 2025-01-15');
10537+
});
1052210538
});
1052310539

1052410540
describe('getAvailableReportFields', () => {

0 commit comments

Comments
 (0)