From 2e030d9709cf90a886f386c63324b92108e62ea3 Mon Sep 17 00:00:00 2001 From: NikkiWines Date: Fri, 5 Apr 2024 11:30:30 -0700 Subject: [PATCH] move combined reportAction logic into ReportActionUtils --- src/libs/ReportActionsUtils.ts | 22 +++++++++++++++++++++ src/pages/home/report/ReportActionsView.tsx | 14 +------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index e6c63df9d9a9..881aabdd7493 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -231,6 +231,7 @@ function getOneTransactionThreadReportID(reportActions: OnyxEntry (iouRequestTypes.includes(action.originalMessage.type) ?? []) && action.childReportID && // Include deleted IOU reportActions if they have childAactions because we want to display those comments + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing ((action.originalMessage.deleted && action.childVisibleActionCount) || action.originalMessage.IOUTransactionID), ); @@ -279,6 +280,26 @@ function getSortedReportActions(reportActions: ReportAction[] | null, shouldSort return sortedActions; } +/** + * Returns a combined list of report actions for a report and associated transaction thread report + */ +function getCombinedReportActions(reportActions: ReportAction[], transactionThreadReportActions: ReportAction[]): ReportAction[] { + if (isEmptyObject(transactionThreadReportActions)) { + return reportActions; + } + + // Filter out the created action from the transaction thread report actions, since we already have the parent report's created action in `reportActions` + const filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED); + + // 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 actionType = (action as OriginalMessageIOU).originalMessage?.type ?? ''; + return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !isSentMoneyReportAction(action); + }); + + return getSortedReportActions(filteredReportActions, true); +} + /** * Returns the largest gapless range of reportActions including a the provided reportActionID, where a "gap" is defined as a reportAction's `previousReportActionID` not matching the previous reportAction in the sortedReportActions array. * See unit tests for example of inputs and expected outputs. @@ -1077,6 +1098,7 @@ export { isApprovedOrSubmittedReportAction, getReportPreviewAction, getSortedReportActions, + getCombinedReportActions, getSortedReportActionsForDisplay, isConsecutiveActionMadeByPreviousActor, isCreatedAction, diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 43081cf72a33..7c2f15705788 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -138,19 +138,7 @@ function ReportActionsView({ // Get a sorted array of reportActions for both the current report and the transaction thread report associated with this report (if there is one) // so that we display transaction-level and report-level report actions in order in the one-transaction view const combinedReportActions = useMemo(() => { - if (isEmptyObject(transactionThreadReportActions)) { - return allReportActions; - } - - // Filter out the created action from the transaction thread report actions, since we already have the parent report's created action in `reportActions` - const filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED); - - // Filter out request and send money request actions because we don't want to show any preview actions for one transaction reports - const filteredReportActions = [...allReportActions, ...filteredTransactionThreadReportActions].filter((action) => { - const actionType = (action as OnyxTypes.OriginalMessageIOU).originalMessage?.type ?? ''; - return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !ReportActionsUtils.isSentMoneyReportAction(action); - }); - return ReportActionsUtils.getSortedReportActions(filteredReportActions, true); + return ReportActionsUtils.getCombinedReportActions(allReportActions, transactionThreadReportActions); }, [allReportActions, transactionThreadReportActions]); const indexOfLinkedAction = useMemo(() => {