From ffa354f7641c5ade550c19cffc22e5f9795083f5 Mon Sep 17 00:00:00 2001 From: dominictb Date: Mon, 8 Jul 2024 15:39:43 +0700 Subject: [PATCH 1/3] fix: update logic of filtering created actions from transaction thread report in getCombinedReportActions function Signed-off-by: dominictb --- src/libs/ReportActionsUtils.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index e8e7b89e34f2..02144a2c4115 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -376,12 +376,25 @@ function getCombinedReportActions( return reportActions; } - // Filter out request money actions because we don't want to show any preview actions for one transaction reports - const filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED); + // Usually, we filter out the created action from the transaction thread report actions, since we already have the parent report's created action in `reportActions` + // However, in the case of moving track expense, the transaction thread will be created first in a track expense, thus we should keep the CREATED of the transaction thread and filter out CREATED action of the IOU + // This makes sense because in a combined report action list, whichever CREATED is first need to be retained. + const transactionThreadCreatedAction = transactionThreadReportActions?.find((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED); + const parentReportCreatedAction = reportActions?.find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); + + let filteredTransactionThreadReportActions = transactionThreadReportActions; + let filteredParentReportActions = reportActions; + + if (transactionThreadCreatedAction && parentReportCreatedAction && transactionThreadCreatedAction.created < parentReportCreatedAction.created) { + filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED); + } else { + filteredParentReportActions = reportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED); + } + const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; const isSelfDM = report?.chatType === CONST.REPORT.CHAT_TYPE.SELF_DM; // Filter out request and send money request actions because we don't want to show any preview actions for one transaction reports - const filteredReportActions = [...reportActions, ...filteredTransactionThreadReportActions].filter((action) => { + const filteredReportActions = [...filteredParentReportActions, ...filteredTransactionThreadReportActions].filter((action) => { if (!isMoneyRequestAction(action)) { return true; } From b685ff0b29f291f7e1cc0c6db1415d7309a4b13d Mon Sep 17 00:00:00 2001 From: Dominic <165644294+dominictb@users.noreply.github.com> Date: Wed, 10 Jul 2024 17:22:04 +0700 Subject: [PATCH 2/3] fix: update ReportActionsUtils.ts Co-authored-by: c3024 <102477862+c3024@users.noreply.github.com> --- src/libs/ReportActionsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 80e76439ecab..3d12cb999de7 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -371,7 +371,7 @@ function getCombinedReportActions( // Usually, we filter out the created action from the transaction thread report actions, since we already have the parent report's created action in `reportActions` // However, in the case of moving track expense, the transaction thread will be created first in a track expense, thus we should keep the CREATED of the transaction thread and filter out CREATED action of the IOU // This makes sense because in a combined report action list, whichever CREATED is first need to be retained. - const transactionThreadCreatedAction = transactionThreadReportActions?.find((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED); + const transactionThreadCreatedAction = transactionThreadReportActions?.find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); const parentReportCreatedAction = reportActions?.find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); let filteredTransactionThreadReportActions = transactionThreadReportActions; From 07816cfe99c65627a838dddb1caeb8d3010d1d81 Mon Sep 17 00:00:00 2001 From: Dominic <165644294+dominictb@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:54:00 +0700 Subject: [PATCH 3/3] fix: keep the CREATED action which is created first Co-authored-by: c3024 <102477862+c3024@users.noreply.github.com> --- src/libs/ReportActionsUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 3d12cb999de7..c7f7b198ab5a 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -377,7 +377,7 @@ function getCombinedReportActions( let filteredTransactionThreadReportActions = transactionThreadReportActions; let filteredParentReportActions = reportActions; - if (transactionThreadCreatedAction && parentReportCreatedAction && transactionThreadCreatedAction.created < parentReportCreatedAction.created) { + if (transactionThreadCreatedAction && parentReportCreatedAction && transactionThreadCreatedAction.created > parentReportCreatedAction.created) { filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED); } else { filteredParentReportActions = reportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED);