diff --git a/src/libs/MoneyRequestReportUtils.ts b/src/libs/MoneyRequestReportUtils.ts index 625512b315185..8e637da4959d4 100644 --- a/src/libs/MoneyRequestReportUtils.ts +++ b/src/libs/MoneyRequestReportUtils.ts @@ -154,6 +154,24 @@ const getTotalAmountForIOUReportPreviewButton = (report: OnyxEntry, poli return convertToDisplayString(totalDisplaySpend, report?.currency); }; +/** + * Filters all available transactions and returns the ones that belong to a specific report (by `reportID`). + * It is used as an onyx selector, to make sure that report related views do not process all transactions in onyx. + */ +function selectAllTransactionsForReport(transactions: OnyxCollection, reportID: string | undefined, reportActions: ReportAction[]) { + if (!reportID) { + return []; + } + + return Object.values(transactions ?? {}).filter((transaction): transaction is Transaction => { + if (!transaction) { + return false; + } + const action = getIOUActionForTransactionID(reportActions, transaction.transactionID); + return transaction.reportID === reportID && !isDeletedParentAction(action); + }); +} + export { isActionVisibleOnMoneyRequestReport, getThreadReportIDsForTransactions, @@ -163,4 +181,5 @@ export { isSingleTransactionReport, shouldDisplayReportTableView, shouldWaitForTransactions, + selectAllTransactionsForReport, };