From a1646a5bafb0c1ae913c0ddb6661e2d9f3a05d1b Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 7 Jan 2025 17:22:02 +0800 Subject: [PATCH 1/4] fix chat doesn't scroll when splitting expense --- src/libs/actions/IOU.ts | 2 ++ tests/actions/IOUTest.ts | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index bdf2e49e6ddc..90190f8a879f 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -847,6 +847,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR value: { ...chat.report, lastReadTime: DateUtils.getDBTime(), + ...(shouldCreateNewMoneyRequestReport ? {lastVisibleActionCreated: chat.reportPreviewAction.created} : {}), iouReportID: iou.report.reportID, ...outstandingChildRequest, ...(isNewChatReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}), @@ -1106,6 +1107,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR value: { iouReportID: chat.report?.iouReportID, lastReadTime: chat.report?.lastReadTime, + lastVisibleActionCreated: chat.report?.lastVisibleActionCreated, pendingFields: null, hasOutstandingChildRequest: chat.report?.hasOutstandingChildRequest, ...(isNewChatReport diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index f82290f91cfc..30b423dc11f4 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1704,6 +1704,50 @@ describe('actions/IOU', () => { }), ); }); + + it('should update split chat report lastVisibleActionCreated to the report preview action', async () => { + // Given a workspace chat with no expenses + const workspaceReportID = '1'; + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`, {reportID: workspaceReportID, isOwnPolicyExpenseChat: true}); + + // When the user split bill on the workspace + IOU.splitBill({ + participants: [{reportID: workspaceReportID}], + currentUserLogin: RORY_EMAIL, + currentUserAccountID: RORY_ACCOUNT_ID, + comment: '', + amount: 100, + currency: CONST.CURRENCY.USD, + merchant: 'test', + created: '', + existingSplitChatReportID: workspaceReportID, + }); + + await waitForBatchedUpdates(); + + // Then the workspace chat lastVisibleActionCreated should be updated to the report preview action created + const reportPreviewAction = await new Promise>((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceReportID}`, + callback: (reportActions) => { + Onyx.disconnect(connection); + resolve(Object.values(reportActions ?? {}).find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW)); + }, + }); + }); + + await new Promise>((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`, + callback: (report) => { + Onyx.disconnect(connection); + console.log(report); + expect(report?.lastVisibleActionCreated).toBe(reportPreviewAction?.created); + resolve(report); + }, + }); + }); + }); }); describe('payMoneyRequestElsewhere', () => { From 1ce89c9726eb11c90dbd84e6dc95b4abace246b7 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 7 Jan 2025 17:52:07 +0800 Subject: [PATCH 2/4] remove log --- tests/actions/IOUTest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 30b423dc11f4..651fa604995a 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1741,7 +1741,6 @@ describe('actions/IOU', () => { key: `${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`, callback: (report) => { Onyx.disconnect(connection); - console.log(report); expect(report?.lastVisibleActionCreated).toBe(reportPreviewAction?.created); resolve(report); }, From cce0e1bba3ba9d1e47ca2ccef7e3ede12446923d Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Tue, 21 Jan 2025 23:38:12 +0800 Subject: [PATCH 3/4] lint --- tests/actions/IOUTest.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index d2c2a7cfa4c9..7002571ccda2 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1745,7 +1745,7 @@ describe('actions/IOU', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`, {reportID: workspaceReportID, isOwnPolicyExpenseChat: true}); // When the user split bill on the workspace - IOU.splitBill({ + splitBill({ participants: [{reportID: workspaceReportID}], currentUserLogin: RORY_EMAIL, currentUserAccountID: RORY_ACCOUNT_ID, @@ -1760,7 +1760,7 @@ describe('actions/IOU', () => { await waitForBatchedUpdates(); // Then the workspace chat lastVisibleActionCreated should be updated to the report preview action created - const reportPreviewAction = await new Promise>((resolve) => { + const reportPreviewAction = await new Promise>((resolve) => { const connection = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceReportID}`, callback: (reportActions) => { @@ -1770,7 +1770,7 @@ describe('actions/IOU', () => { }); }); - await new Promise>((resolve) => { + await new Promise>((resolve) => { const connection = Onyx.connect({ key: `${ONYXKEYS.COLLECTION.REPORT}${workspaceReportID}`, callback: (report) => { From 1e92119312b931d8c0c305f3381c96a7bb4cc4e0 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 25 Jan 2025 02:26:58 +0800 Subject: [PATCH 4/4] fix chat doesn't scroll down when split bill --- src/pages/home/report/ReportActionsList.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 7eb3711ec637..9856ccb3b462 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -466,7 +466,7 @@ function ReportActionsList({ (isFromCurrentUser: boolean) => { // If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where // they are now in the list. - if (!isFromCurrentUser || scrollingVerticalOffset.current === 0 || !isReportScreenTopmostCentralPane()) { + if (!isFromCurrentUser || !isReportScreenTopmostCentralPane()) { return; } if (!hasNewestReportActionRef.current) { @@ -485,7 +485,7 @@ function ReportActionsList({ ); useEffect(() => { - if (!pendingBottomScroll || scrollingVerticalOffset.current === 0) { + if (!pendingBottomScroll) { return; }