From 3d6b78c57bc251997e12cbd56f0b0b37c7d11424 Mon Sep 17 00:00:00 2001 From: thelullabyy Date: Fri, 13 Jun 2025 17:08:07 +0700 Subject: [PATCH 1/6] fix: LHN not show message sent or system message --- src/libs/OptionsListUtils.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 1b3dd5affacf1..601fa8c8d45a6 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -857,6 +857,14 @@ function getLastMessageTextForReport( lastMessageTextFromReport = getReportActionMessageText(lastReportAction); } + if (reportID) { + const chatReport = getReportOrDraftReport(report.chatReportID); + const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, allSortedReportActions[reportID]); + if (transactionThreadReportID) { + lastMessageTextFromReport = getReportActionMessageText(lastReportAction); + } + } + return lastMessageTextFromReport || (report?.lastMessageText ?? ''); } From 31469aaa12b325c242992dda1472e3856753d330 Mon Sep 17 00:00:00 2001 From: thelullabyy Date: Fri, 13 Jun 2025 17:44:39 +0700 Subject: [PATCH 2/6] add comment --- src/libs/OptionsListUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 601fa8c8d45a6..07298ce8c9f59 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -859,6 +859,7 @@ function getLastMessageTextForReport( if (reportID) { const chatReport = getReportOrDraftReport(report.chatReportID); + // Return message text from last report action if the report is combined report const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, allSortedReportActions[reportID]); if (transactionThreadReportID) { lastMessageTextFromReport = getReportActionMessageText(lastReportAction); From f78bc2cdfb8a5989980858fcbed591388ab9ae1b Mon Sep 17 00:00:00 2001 From: thelullabyy Date: Mon, 16 Jun 2025 15:26:34 +0700 Subject: [PATCH 3/6] add unit test --- src/libs/OptionsListUtils.ts | 2 +- tests/unit/SidebarUtilsTest.ts | 68 +++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 07298ce8c9f59..a67d1c27adf47 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -859,7 +859,7 @@ function getLastMessageTextForReport( if (reportID) { const chatReport = getReportOrDraftReport(report.chatReportID); - // Return message text from last report action if the report is combined report + // If the expense report is the one expense report, get the last message text from the last report action const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, allSortedReportActions[reportID]); if (transactionThreadReportID) { lastMessageTextFromReport = getReportActionMessageText(lastReportAction); diff --git a/tests/unit/SidebarUtilsTest.ts b/tests/unit/SidebarUtilsTest.ts index c7a11a5947004..b497641c48e8b 100644 --- a/tests/unit/SidebarUtilsTest.ts +++ b/tests/unit/SidebarUtilsTest.ts @@ -4,7 +4,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import useReportIsArchived from '@hooks/useReportIsArchived'; import DateUtils from '@libs/DateUtils'; -import {getReportActionMessageText} from '@libs/ReportActionsUtils'; +import {getOriginalMessage, getReportActionMessageText} from '@libs/ReportActionsUtils'; import {getAllReportErrors} from '@libs/ReportUtils'; import SidebarUtils from '@libs/SidebarUtils'; import initOnyxDerivedValues from '@userActions/OnyxDerived'; @@ -13,7 +13,8 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {Policy, Report, ReportAction, ReportActions, Transaction, TransactionViolation, TransactionViolations} from '@src/types/onyx'; import type {ReportCollectionDataSet} from '@src/types/onyx/Report'; import type {TransactionViolationsCollectionDataSet} from '@src/types/onyx/TransactionViolation'; -import {chatReportR14932} from '../../__mocks__/reportData/reports'; +import {actionR14932 as mockIOUAction} from '../../__mocks__/reportData/actions'; +import {chatReportR14932, iouReportR14932} from '../../__mocks__/reportData/reports'; import createRandomPolicy from '../utils/collections/policies'; import createRandomReportAction from '../utils/collections/reportActions'; import createRandomReport from '../utils/collections/reports'; @@ -1125,6 +1126,69 @@ describe('SidebarUtils', () => { oneTransactionThreadReport: undefined, }); + expect(result?.alternateText).toBe(`You: ${getReportActionMessageText(lastAction)}`); + }); + it('returns the last action message as an alternate text if the expense report is the one expense report', async () => { + const IOUTransactionID = `${ONYXKEYS.COLLECTION.TRANSACTION}TRANSACTION_IOU` as const; + + iouReportR14932.reportID = '5'; + chatReportR14932.reportID = '6'; + iouReportR14932.lastActorAccountID = undefined; + + const report: Report = { + ...createRandomReport(1), + chatType: 'policyExpenseChat', + pendingAction: null, + isOwnPolicyExpenseChat: true, + parentReportID: iouReportR14932.reportID, + parentReportActionID: mockIOUAction.reportActionID, + lastActorAccountID: undefined, + }; + + const linkedCreateAction: ReportAction = { + ...mockIOUAction, + originalMessage: {...getOriginalMessage(mockIOUAction), IOUTransactionID}, + childReportID: report.reportID, + reportActionID: '3', + }; + + const lastAction: ReportAction = { + ...createRandomReportAction(1), + message: [ + { + type: 'COMMENT', + html: 'test action', + text: 'test action', + }, + ], + originalMessage: { + whisperedTo: [], + }, + + created: DateUtils.getDBTime(), + lastModified: DateUtils.getDBTime(), + shouldShow: true, + pendingAction: null, + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + actorAccountID: undefined, + }; + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${iouReportR14932.reportID}`, iouReportR14932); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${chatReportR14932.reportID}`, chatReportR14932); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {[lastAction.reportActionID]: lastAction}); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportR14932.reportID}`, {[linkedCreateAction.reportActionID]: linkedCreateAction}); + + const result = SidebarUtils.getOptionData({ + report: iouReportR14932, + reportAttributes: undefined, + reportNameValuePairs: {}, + personalDetails: {}, + policy: undefined, + parentReportAction: undefined, + oneTransactionThreadReport: undefined, + }); + expect(result?.alternateText).toBe(`You: ${getReportActionMessageText(lastAction)}`); }); }); From 59f771dfdbd30453b22b590aef3972a478d7f711 Mon Sep 17 00:00:00 2001 From: thelullabyy Date: Tue, 17 Jun 2025 10:32:17 +0700 Subject: [PATCH 4/6] replace deprecated function getReportOrDraftReport --- src/libs/OptionsListUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index a67d1c27adf47..35489acd81c34 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -858,7 +858,7 @@ function getLastMessageTextForReport( } if (reportID) { - const chatReport = getReportOrDraftReport(report.chatReportID); + const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; // If the expense report is the one expense report, get the last message text from the last report action const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, allSortedReportActions[reportID]); if (transactionThreadReportID) { From f3bee728b3674a2e7c2ab03f85427b7724d6b884 Mon Sep 17 00:00:00 2001 From: thelullabyy Date: Wed, 18 Jun 2025 09:02:56 +0700 Subject: [PATCH 5/6] update comment --- src/libs/OptionsListUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 35489acd81c34..5793a6a9f1278 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -859,7 +859,7 @@ function getLastMessageTextForReport( if (reportID) { const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; - // If the expense report is the one expense report, get the last message text from the last report action + // If the report is combined report, get the last message text from the last report action const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, allSortedReportActions[reportID]); if (transactionThreadReportID) { lastMessageTextFromReport = getReportActionMessageText(lastReportAction); From 5236a8ca14f8c9be9215c2ab9f8849edc39826f4 Mon Sep 17 00:00:00 2001 From: thelullabyy Date: Thu, 19 Jun 2025 11:30:31 +0700 Subject: [PATCH 6/6] update comment --- src/libs/OptionsListUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 5793a6a9f1278..d9ef0be7e9ab1 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -859,7 +859,7 @@ function getLastMessageTextForReport( if (reportID) { const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`]; - // If the report is combined report, get the last message text from the last report action + // If the report is a one-transaction report, get the last message text from combined report actions so the LHN can display modifications to the transaction thread or the report itself const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, allSortedReportActions[reportID]); if (transactionThreadReportID) { lastMessageTextFromReport = getReportActionMessageText(lastReportAction);