From 1080f4da7c275f52a7f38746df15b1a5402338f4 Mon Sep 17 00:00:00 2001 From: M00rish Date: Thu, 13 Mar 2025 02:23:36 +0100 Subject: [PATCH 1/3] update getReportsFromSelectedTransactions to accpet TransactionListItemType --- src/components/Search/SearchContext.tsx | 40 +++++++++++++++++++------ 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/components/Search/SearchContext.tsx b/src/components/Search/SearchContext.tsx index 73091abf045b..0103e6bfa69b 100644 --- a/src/components/Search/SearchContext.tsx +++ b/src/components/Search/SearchContext.tsx @@ -1,7 +1,7 @@ import React, {useCallback, useContext, useMemo, useState} from 'react'; import type {ReportActionListItemType, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types'; import {isMoneyRequestReport} from '@libs/ReportUtils'; -import {isReportListItemType} from '@libs/SearchUIUtils'; +import {isReportListItemType, isTransactionListItemType} from '@libs/SearchUIUtils'; import CONST from '@src/CONST'; import type ChildrenProps from '@src/types/utils/ChildrenProps'; import type {SearchContext, SelectedTransactions} from './types'; @@ -23,14 +23,36 @@ const defaultSearchContext = { const Context = React.createContext(defaultSearchContext); function getReportsFromSelectedTransactions(data: TransactionListItemType[] | ReportListItemType[] | ReportActionListItemType[], selectedTransactions: SelectedTransactions) { - return (data ?? []) - .filter( - (item): item is ReportListItemType => - isReportListItemType(item) && - isMoneyRequestReport(item) && - item?.transactions?.every((transaction: {keyForList: string | number}) => selectedTransactions[transaction.keyForList]?.isSelected), - ) - .map((item) => ({reportID: item.reportID, action: item.action ?? CONST.SEARCH.ACTION_TYPES.VIEW, total: item.total ?? CONST.DEFAULT_NUMBER_ID, policyID: item.policyID})); + if (!Array.isArray(data) || data.length === 0) { + return []; + } + + if (isReportListItemType(data[0]) || isMoneyRequestReport(data[0])) { + return data + .filter( + (item): item is ReportListItemType => + isReportListItemType(item) && isMoneyRequestReport(item) && item.transactions?.every((transaction) => selectedTransactions[transaction.keyForList]?.isSelected), + ) + .map((item) => ({ + reportID: item.reportID, + action: item.action ?? CONST.SEARCH.ACTION_TYPES.VIEW, + total: item.total ?? CONST.DEFAULT_NUMBER_ID, + policyID: item.policyID, + })); + } + + if (isTransactionListItemType(data[0])) { + return data + .filter((transaction) => transaction.keyForList != null && selectedTransactions[transaction.keyForList]?.isSelected) + .map((transaction) => ({ + reportID: transaction.reportID, + action: 'action' in transaction ? transaction.action ?? CONST.SEARCH.ACTION_TYPES.VIEW : CONST.SEARCH.ACTION_TYPES.VIEW, + total: 'total' in transaction ? transaction.total ?? CONST.DEFAULT_NUMBER_ID : CONST.DEFAULT_NUMBER_ID, + policyID: transaction.policyID, + })); + } + + return []; } function SearchContextProvider({children}: ChildrenProps) { From ce6028e1ec715d4fa3c7306cb339da87390d7eac Mon Sep 17 00:00:00 2001 From: M00rish Date: Sat, 15 Mar 2025 01:47:08 +0000 Subject: [PATCH 2/3] removing isArray check --- src/components/Search/SearchContext.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Search/SearchContext.tsx b/src/components/Search/SearchContext.tsx index 0103e6bfa69b..264e729c01b1 100644 --- a/src/components/Search/SearchContext.tsx +++ b/src/components/Search/SearchContext.tsx @@ -23,7 +23,7 @@ const defaultSearchContext = { const Context = React.createContext(defaultSearchContext); function getReportsFromSelectedTransactions(data: TransactionListItemType[] | ReportListItemType[] | ReportActionListItemType[], selectedTransactions: SelectedTransactions) { - if (!Array.isArray(data) || data.length === 0) { + if (data.length === 0) { return []; } From efd69b18c567cc7bb24484b5ed1fc991e06fc20c Mon Sep 17 00:00:00 2001 From: M00rish Date: Sat, 15 Mar 2025 02:20:45 +0000 Subject: [PATCH 3/3] fix for total is zero for selected transactions --- src/components/Search/SearchContext.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Search/SearchContext.tsx b/src/components/Search/SearchContext.tsx index 264e729c01b1..98165296b604 100644 --- a/src/components/Search/SearchContext.tsx +++ b/src/components/Search/SearchContext.tsx @@ -47,7 +47,7 @@ function getReportsFromSelectedTransactions(data: TransactionListItemType[] | Re .map((transaction) => ({ reportID: transaction.reportID, action: 'action' in transaction ? transaction.action ?? CONST.SEARCH.ACTION_TYPES.VIEW : CONST.SEARCH.ACTION_TYPES.VIEW, - total: 'total' in transaction ? transaction.total ?? CONST.DEFAULT_NUMBER_ID : CONST.DEFAULT_NUMBER_ID, + total: 'amount' in transaction ? transaction.amount ?? CONST.DEFAULT_NUMBER_ID : CONST.DEFAULT_NUMBER_ID, policyID: transaction.policyID, })); }