diff --git a/src/components/LHNOptionsList/types.ts b/src/components/LHNOptionsList/types.ts index 2c3637fa5c8e..036f0968e9dd 100644 --- a/src/components/LHNOptionsList/types.ts +++ b/src/components/LHNOptionsList/types.ts @@ -71,7 +71,12 @@ type OptionRowLHNDataProps = { /** Array of report actions for this report */ reportActions: OnyxEntry; - /** Array of report actions of IOU report related to this report last action */ + /** + * Array of report actions for the IOU report related to the last action of this report. + * If the last action is a report action preview, the last message of the report depends on + * the report actions of the IOU report linked to the report action preview. + * Changes in the IOU report report actions will affect the last message of this report. + */ iouReportReportActions: OnyxEntry; /** List of transaction violation */ diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 033f92b914f1..7711b96433d9 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -289,7 +289,7 @@ Onyx.connect({ const lastReportActions: ReportActions = {}; const allSortedReportActions: Record = {}; let allReportActions: OnyxCollection; -const visibleReportActionItems: ReportActions = {}; +const lastVisibleReportActions: ReportActions = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, waitForCollectionCallback: true, @@ -327,7 +327,7 @@ Onyx.connect({ reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !ReportActionUtils.isResolvedActionTrackExpense(reportAction), ); - visibleReportActionItems[reportID] = reportActionsForDisplay[0]; + lastVisibleReportActions[reportID] = reportActionsForDisplay[0]; }); }, }); @@ -669,7 +669,7 @@ function getIOUReportIDOfLastAction(report: OnyxEntry): string | undefin if (!report?.reportID) { return; } - const lastAction = visibleReportActionItems[report.reportID]; + const lastAction = lastVisibleReportActions[report.reportID]; if (!ReportActionUtils.isReportPreviewAction(lastAction)) { return; } @@ -681,7 +681,7 @@ function getIOUReportIDOfLastAction(report: OnyxEntry): string | undefin */ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails: Partial | null, policy?: OnyxEntry): string { const reportID = report?.reportID ?? '-1'; - const lastReportAction = visibleReportActionItems[reportID] ?? null; + const lastReportAction = lastVisibleReportActions[reportID] ?? null; // some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action const lastOriginalReportAction = lastReportActions[reportID] ?? null; @@ -852,7 +852,7 @@ function createOption( const lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails); let lastMessageText = lastMessageTextFromReport; - const lastAction = visibleReportActionItems[report.reportID]; + const lastAction = lastVisibleReportActions[report.reportID]; const shouldDisplayLastActorName = lastAction && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU; if (shouldDisplayLastActorName && lastActorDisplayName && lastMessageTextFromReport) {