@@ -12,7 +12,7 @@ import type {SelectionListHandle} from '@components/SelectionList/types';
1212import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton' ;
1313import { useWideRHPActions } from '@components/WideRHPContextProvider' ;
1414import useActionLoadingReportIDs from '@hooks/useActionLoadingReportIDs' ;
15- import useArchivedReportsIdSet from '@hooks/useArchivedReportsIdSet ' ;
15+ import useArchivedReportsIDSet from '@hooks/useArchivedReportsIDSet ' ;
1616import { useCurrencyListActions } from '@hooks/useCurrencyList' ;
1717import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' ;
1818import useEnvironment from '@hooks/useEnvironment' ;
@@ -67,6 +67,7 @@ import {
6767 shouldShowEmptyState ,
6868 shouldShowYear as shouldShowYearUtil ,
6969} from '@libs/SearchUIUtils' ;
70+ import type { ArchivedReportsIDSet } from '@libs/SearchUIUtils' ;
7071import { cancelSpan , endSpanWithAttributes , getSpan , startSpan } from '@libs/telemetry/activeSpans' ;
7172import {
7273 cancelNavigateToReportsSpans ,
@@ -126,18 +127,33 @@ type HoldMenuCallback = (item: TransactionReportGroupListItemType, requestType:
126127
127128const hashToString = ( queryHash ?: number ) => ( queryHash || queryHash === 0 ? String ( queryHash ) : undefined ) ;
128129
129- function mapTransactionItemToSelectedEntry (
130- item : TransactionListItemType ,
131- itemTransaction : OnyxEntry < Transaction > ,
132- originalItemTransaction : OnyxEntry < Transaction > ,
133- currentUserLogin : string ,
134- currentUserAccountID : number ,
135- outstandingReportsByPolicyID : OutstandingReportsByPolicyIDDerivedValue | undefined ,
136- allowNegativeAmount : boolean ,
137- parentReport : OnyxEntry < Report > | undefined ,
138- selfDMReport : OnyxEntry < Report > | undefined ,
139- isProduction : boolean ,
140- ) : [ string , SelectedTransactionInfo ] {
130+ type MapTransactionItemToSelectedEntryParams = {
131+ item : TransactionListItemType ;
132+ itemTransaction : OnyxEntry < Transaction > ;
133+ originalItemTransaction : OnyxEntry < Transaction > ;
134+ currentUserLogin : string ;
135+ currentUserAccountID : number ;
136+ archivedReportsIDSet : ArchivedReportsIDSet ;
137+ outstandingReportsByPolicyID : OutstandingReportsByPolicyIDDerivedValue | undefined ;
138+ selfDMReport : OnyxEntry < Report > ;
139+ isProduction : boolean ;
140+ allowNegativeAmount : boolean ;
141+ parentReport : OnyxEntry < Report > | undefined ;
142+ } ;
143+
144+ function mapTransactionItemToSelectedEntry ( {
145+ item,
146+ itemTransaction,
147+ originalItemTransaction,
148+ currentUserLogin,
149+ currentUserAccountID,
150+ archivedReportsIDSet,
151+ outstandingReportsByPolicyID,
152+ selfDMReport,
153+ isProduction,
154+ allowNegativeAmount,
155+ parentReport,
156+ } : MapTransactionItemToSelectedEntryParams ) : [ string , SelectedTransactionInfo ] {
141157 const { canHoldRequest, canUnholdRequest} = canHoldUnholdReportAction ( item . report , item . reportAction , item . holdReportAction , item , item . policy , currentUserAccountID ) ;
142158 const canRejectRequest = item . report ? canRejectReportAction ( currentUserLogin , item . report ) : false ;
143159 const amount = hasValidModifiedAmount ( item ) ? Number ( item . modifiedAmount ) : item . amount ;
@@ -162,6 +178,7 @@ function mapTransactionItemToSelectedEntry(
162178 transaction : item ,
163179 report : item . report ,
164180 policy : item . policy ,
181+ archivedReportsIDSet,
165182 } ) ,
166183 action : item . action ,
167184 groupCurrency : item . groupCurrency ,
@@ -229,36 +246,52 @@ function mapEmptyReportToSelectedEntry(item: TransactionReportGroupListItemType
229246 ] ;
230247}
231248
232- function prepareTransactionsList (
233- item : TransactionListItemType ,
234- itemTransaction : OnyxEntry < Transaction > ,
235- originalItemTransaction : OnyxEntry < Transaction > ,
236- selectedTransactions : SelectedTransactions ,
237- currentUserLogin : string ,
238- currentUserAccountID : number ,
239- outstandingReportsByPolicyID : OutstandingReportsByPolicyIDDerivedValue | undefined ,
240- parentReport : OnyxEntry < Report > | undefined ,
241- selfDMReport : OnyxEntry < Report > | undefined ,
242- isProduction : boolean ,
243- ) {
249+ type PrepareTransactionsListParams = {
250+ item : TransactionListItemType ;
251+ itemTransaction : OnyxEntry < Transaction > ;
252+ originalItemTransaction : OnyxEntry < Transaction > ;
253+ selectedTransactions : SelectedTransactions ;
254+ currentUserLogin : string ;
255+ currentUserAccountID : number ;
256+ archivedReportsIDSet : ArchivedReportsIDSet ;
257+ outstandingReportsByPolicyID : OutstandingReportsByPolicyIDDerivedValue | undefined ;
258+ selfDMReport : OnyxEntry < Report > ;
259+ isProduction : boolean ;
260+ parentReport : OnyxEntry < Report > | undefined ;
261+ } ;
262+
263+ function prepareTransactionsList ( {
264+ item,
265+ itemTransaction,
266+ originalItemTransaction,
267+ selectedTransactions,
268+ currentUserLogin,
269+ currentUserAccountID,
270+ archivedReportsIDSet,
271+ outstandingReportsByPolicyID,
272+ selfDMReport,
273+ isProduction,
274+ parentReport,
275+ } : PrepareTransactionsListParams ) {
244276 if ( selectedTransactions [ item . keyForList ] ?. isSelected ) {
245277 const { [ item . keyForList ] : omittedTransaction , ...transactions } = selectedTransactions ;
246278
247279 return transactions ;
248280 }
249281
250- const [ key , selectedInfo ] = mapTransactionItemToSelectedEntry (
282+ const [ key , selectedInfo ] = mapTransactionItemToSelectedEntry ( {
251283 item,
252284 itemTransaction,
253285 originalItemTransaction,
254286 currentUserLogin,
255287 currentUserAccountID,
288+ archivedReportsIDSet,
256289 outstandingReportsByPolicyID,
257- false ,
258- parentReport ,
259290 selfDMReport,
260291 isProduction,
261- ) ;
292+ allowNegativeAmount : false ,
293+ parentReport,
294+ } ) ;
262295
263296 return {
264297 ...selectedTransactions ,
@@ -333,7 +366,7 @@ function Search({
333366
334367 const isExpenseReportType = type === CONST . SEARCH . DATA_TYPES . EXPENSE_REPORT ;
335368
336- const archivedReportsIdSet = useArchivedReportsIdSet ( ) ;
369+ const archivedReportsIDSet = useArchivedReportsIDSet ( ) ;
337370
338371 const [ exportReportActions ] = useOnyx < typeof ONYXKEYS . COLLECTION . REPORT_ACTIONS , Record < string , ReportAction [ ] > | undefined > ( ONYXKEYS . COLLECTION . REPORT_ACTIONS , {
339372 selector : selectFilteredReportActions ,
@@ -566,7 +599,7 @@ function Search({
566599 groupBy : validGroupBy ,
567600 reportActions : exportReportActions ,
568601 currentSearch : currentSearchKey ,
569- archivedReportsIDList : archivedReportsIdSet ,
602+ archivedReportsIDList : archivedReportsIDSet ,
570603 queryJSON,
571604 isActionLoadingSet,
572605 cardFeeds,
@@ -597,7 +630,7 @@ function Search({
597630 searchDataWithOptimisticTransaction ,
598631 searchResults ,
599632 type ,
600- archivedReportsIdSet ,
633+ archivedReportsIDSet ,
601634 translate ,
602635 formatPhoneNumber ,
603636 accountID ,
@@ -1062,18 +1095,19 @@ function Search({
10621095 const itemTransaction = transactions ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ item . transactionID } ` ] as OnyxEntry < Transaction > ;
10631096 const originalItemTransaction = transactions ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ itemTransaction ?. comment ?. originalTransactionID } ` ] ;
10641097 const itemParentReport = searchResults ?. data ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ item . report ?. parentReportID } ` ] as OnyxEntry < Report > ;
1065- const updatedTransactions = prepareTransactionsList (
1098+ const updatedTransactions = prepareTransactionsList ( {
10661099 item,
10671100 itemTransaction,
10681101 originalItemTransaction,
10691102 selectedTransactions,
1070- email ?? '' ,
1071- accountID ,
1103+ currentUserLogin : email ?? '' ,
1104+ currentUserAccountID : accountID ,
1105+ archivedReportsIDSet,
10721106 outstandingReportsByPolicyID,
1073- itemParentReport ,
10741107 selfDMReport,
10751108 isProduction,
1076- ) ;
1109+ parentReport : itemParentReport ,
1110+ } ) ;
10771111
10781112 // Tag individual transactions with their parent group key so export filtering can derive the group when needed.
10791113 if ( areItemsGrouped ) {
@@ -1145,18 +1179,19 @@ function Search({
11451179 searchResults ?. data ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ itemTransaction ?. comment ?. originalTransactionID } ` ] ??
11461180 transactions ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ itemTransaction ?. comment ?. originalTransactionID } ` ] ;
11471181 const itemParentReport = searchResults ?. data ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ transactionItem . report ?. parentReportID } ` ] as OnyxEntry < Report > ;
1148- const [ key , entry ] = mapTransactionItemToSelectedEntry (
1149- transactionItem ,
1182+ const [ key , entry ] = mapTransactionItemToSelectedEntry ( {
1183+ item : transactionItem ,
11501184 itemTransaction,
11511185 originalItemTransaction,
1152- email ?? '' ,
1153- accountID ,
1186+ currentUserLogin : email ?? '' ,
1187+ currentUserAccountID : accountID ,
1188+ archivedReportsIDSet,
11541189 outstandingReportsByPolicyID,
1155- true ,
1156- itemParentReport ,
11571190 selfDMReport,
11581191 isProduction,
1159- ) ;
1192+ allowNegativeAmount : true ,
1193+ parentReport : itemParentReport ,
1194+ } ) ;
11601195 return [ key , { ...entry , groupKey : item . keyForList } ] ;
11611196 } ) ,
11621197 ) ,
@@ -1172,6 +1207,7 @@ function Search({
11721207 searchResults ?. data ,
11731208 email ,
11741209 accountID ,
1210+ archivedReportsIDSet ,
11751211 outstandingReportsByPolicyID ,
11761212 selfDMReport ,
11771213 isProduction ,
@@ -1492,18 +1528,19 @@ function Search({
14921528 const itemTransaction = transactions ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionItem . transactionID } ` ] as OnyxEntry < Transaction > ;
14931529 const originalItemTransaction = transactions ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ itemTransaction ?. comment ?. originalTransactionID } ` ] ;
14941530 const itemParentReport = searchResults ?. data ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ transactionItem . report ?. parentReportID } ` ] as OnyxEntry < Report > ;
1495- const [ key , entry ] = mapTransactionItemToSelectedEntry (
1496- transactionItem ,
1531+ const [ key , entry ] = mapTransactionItemToSelectedEntry ( {
1532+ item : transactionItem ,
14971533 itemTransaction,
14981534 originalItemTransaction,
1499- email ?? '' ,
1500- accountID ,
1535+ currentUserLogin : email ?? '' ,
1536+ currentUserAccountID : accountID ,
1537+ archivedReportsIDSet,
15011538 outstandingReportsByPolicyID,
1502- true ,
1503- itemParentReport ,
15041539 selfDMReport,
15051540 isProduction,
1506- ) ;
1541+ allowNegativeAmount : true ,
1542+ parentReport : itemParentReport ,
1543+ } ) ;
15071544 return [ key , { ...entry , groupKey : item . keyForList } ] as [ string , SelectedTransactionInfo ] ;
15081545 } ) ;
15091546 } ) ;
@@ -1517,18 +1554,19 @@ function Search({
15171554 const itemTransaction = searchResults ?. data ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionItem . transactionID } ` ] as OnyxEntry < Transaction > ;
15181555 const originalItemTransaction = searchResults ?. data ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ itemTransaction ?. comment ?. originalTransactionID } ` ] ;
15191556 const itemParentReport = searchResults ?. data ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ transactionItem . report ?. parentReportID } ` ] as OnyxEntry < Report > ;
1520- return mapTransactionItemToSelectedEntry (
1521- transactionItem ,
1557+ return mapTransactionItemToSelectedEntry ( {
1558+ item : transactionItem ,
15221559 itemTransaction,
15231560 originalItemTransaction,
1524- email ?? '' ,
1525- accountID ,
1561+ currentUserLogin : email ?? '' ,
1562+ currentUserAccountID : accountID ,
1563+ archivedReportsIDSet,
15261564 outstandingReportsByPolicyID,
1527- true ,
1528- itemParentReport ,
15291565 selfDMReport,
15301566 isProduction,
1531- ) ;
1567+ allowNegativeAmount : true ,
1568+ parentReport : itemParentReport ,
1569+ } ) ;
15321570 } ) ,
15331571 ) ;
15341572 }
@@ -1542,10 +1580,11 @@ function Search({
15421580 updateSelectAllMatchingItemsState ,
15431581 clearSelectedTransactions ,
15441582 transactions ,
1583+ searchResults ?. data ,
15451584 email ,
15461585 accountID ,
1586+ archivedReportsIDSet ,
15471587 outstandingReportsByPolicyID ,
1548- searchResults ?. data ,
15491588 selfDMReport ,
15501589 isProduction ,
15511590 ] ) ;
0 commit comments