From 9f2a7e3e9dae7b800921efc636215c801b30dd68 Mon Sep 17 00:00:00 2001 From: Rory Abraham <47436092+roryabraham@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:42:38 -0700 Subject: [PATCH] Merge pull request #38968 from Expensify/Rory-IncorrectReportActionChainForOptimisticDelete Make getContinuousReportActionChain consider any optimistic action (cherry picked from commit 525b1ba90f47cc98aa5983b04773a82fa0fd16b4) --- src/libs/ReportActionsUtils.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 1df59508257a..b2c8397e0c6b 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -263,9 +263,14 @@ function getContinuousReportActionChain(sortedReportActions: ReportAction[], id? let index; if (id) { - index = sortedReportActions.findIndex((obj) => obj.reportActionID === id); + index = sortedReportActions.findIndex((reportAction) => reportAction.reportActionID === id); } else { - index = sortedReportActions.findIndex((obj) => obj.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); + index = sortedReportActions.findIndex( + (reportAction) => + reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD && + reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && + !reportAction.isOptimisticAction, + ); } if (index === -1) { @@ -299,6 +304,9 @@ function getContinuousReportActionChain(sortedReportActions: ReportAction[], id? while ( (startIndex > 0 && sortedReportActions[startIndex].reportActionID === sortedReportActions[startIndex - 1].previousReportActionID) || sortedReportActions[startIndex - 1]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || + sortedReportActions[startIndex - 1]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + sortedReportActions[startIndex - 1]?.isOptimisticAction || sortedReportActions[startIndex - 1]?.actionName === CONST.REPORT.ACTIONS.TYPE.ROOMCHANGELOG.INVITE_TO_ROOM ) { startIndex--;