From 880b3f05760a76260b51db3f54133fb79e8c0991 Mon Sep 17 00:00:00 2001 From: Vivek Kumar <35863227+techievivek@users.noreply.github.com> Date: Wed, 2 Jul 2025 20:28:19 +0530 Subject: [PATCH] Revert "Make getReportDetails a pure function - Recreate" --- src/libs/OptionsListUtils.ts | 4 +--- src/libs/ReportUtils.ts | 17 +++++++++++------ src/pages/home/report/PureReportActionItem.tsx | 3 +-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index e5e0bb5ce6fc9..95e31279a8c54 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -781,9 +781,7 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails const properSchemaForModifiedExpenseMessage = ModifiedExpenseMessage.getForReportAction({reportOrID: report?.reportID, reportAction: lastReportAction}); lastMessageTextFromReport = formatReportLastMessageText(properSchemaForModifiedExpenseMessage, true); } else if (isMovedTransactionAction(lastReportAction)) { - const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`]; - const movedIOUReport = isExpenseReport(parentReport) ? parentReport : report; - lastMessageTextFromReport = getMovedTransactionMessage(lastReportAction, movedIOUReport); + lastMessageTextFromReport = getMovedTransactionMessage(lastReportAction); } else if (isTaskAction(lastReportAction)) { lastMessageTextFromReport = formatReportLastMessageText(getTaskReportActionMessage(lastReportAction).text); } else if (isCreatedTaskReportAction(lastReportAction)) { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d3fb7164aa0c9..7a5401690e95f 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -11,7 +11,7 @@ import lodashMaxBy from 'lodash/maxBy'; import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import type {SvgProps} from 'react-native-svg'; -import type {OriginalMessageChangePolicy, OriginalMessageExportIntegration, OriginalMessageModifiedExpense} from 'src/types/onyx/OriginalMessage'; +import type {OriginalMessageChangePolicy, OriginalMessageExportIntegration, OriginalMessageModifiedExpense, OriginalMessageMovedTransaction} from 'src/types/onyx/OriginalMessage'; import type {SetRequired, TupleToUnion, ValueOf} from 'type-fest'; import {FallbackAvatar, IntacctSquare, NetSuiteSquare, QBDSquare, QBOSquare, XeroSquare} from '@components/Icon/Expensicons'; import * as defaultGroupAvatars from '@components/Icon/GroupDefaultAvatars'; @@ -6095,13 +6095,18 @@ function getDeletedTransactionMessage(action: ReportAction) { return message; } -function getReportUrl(reportID?: string) { - return `${environmentURL}/r/${reportID}`; +function getReportDetails(reportID: string): {reportName: string; reportUrl: string} { + const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + return { + reportName: getReportName(report) ?? report?.reportName ?? '', + reportUrl: `${environmentURL}/r/${reportID}`, + }; } -function getMovedTransactionMessage(parentReportAction: OnyxEntry, movedIOUReport?: Report) { - const reportName = getReportName(movedIOUReport, undefined, parentReportAction) ?? movedIOUReport?.reportName ?? ''; - const reportUrl = getReportUrl(movedIOUReport?.reportID); +function getMovedTransactionMessage(action: ReportAction) { + const movedTransactionOriginalMessage = getOriginalMessage(action as ReportAction) ?? {}; + const {toReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction; + const {reportName, reportUrl} = getReportDetails(toReportID); const message = translateLocal('iou.movedTransaction', { reportUrl, reportName, diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx index 0e42ab4faae0e..881d81d8af616 100644 --- a/src/pages/home/report/PureReportActionItem.tsx +++ b/src/pages/home/report/PureReportActionItem.tsx @@ -1064,10 +1064,9 @@ function PureReportActionItem({ } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.DELETED_TRANSACTION) { children = ; } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION) { - const movedIOUReport = isExpenseReport(parentReport) ? parentReport : report; children = ( - ${getMovedTransactionMessage(parentReportAction, movedIOUReport)}`} /> + ${getMovedTransactionMessage(action)}`} /> ); } else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.TRAVEL_UPDATE)) {