@@ -42,7 +42,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
4242import useWindowDimensions from '@hooks/useWindowDimensions' ;
4343import { turnOnMobileSelectionMode } from '@libs/actions/MobileSelectionMode' ;
4444import navigationRef from '@libs/Navigation/navigationRef' ;
45- import { getTableMinWidth , isTransactionReportGroupListItemType } from '@libs/SearchUIUtils' ;
45+ import { getTableMinWidth } from '@libs/SearchUIUtils' ;
4646import variables from '@styles/variables' ;
4747import type { TransactionPreviewData } from '@userActions/Search' ;
4848import CONST from '@src/CONST' ;
@@ -196,51 +196,16 @@ function SearchList({
196196 }
197197 return data ;
198198 } , [ data , groupBy , type ] ) ;
199- const emptyReports = useMemo ( ( ) => {
200- if ( type === CONST . SEARCH . DATA_TYPES . EXPENSE_REPORT && isTransactionGroupListItemArray ( data ) ) {
201- return data . filter ( ( item ) => item . transactions . length === 0 ) ;
202- }
203- return [ ] ;
204- } , [ data , type ] ) ;
199+ const flattenedItemsWithoutPendingDelete = useMemo ( ( ) => flattenedItems . filter ( ( t ) => t ?. pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ) , [ flattenedItems ] ) ;
205200
206201 const selectedItemsLength = useMemo ( ( ) => {
207- const selectedTransactionsCount = flattenedItems . reduce ( ( acc , item ) => {
208- const isTransactionSelected = ! ! ( item ?. keyForList && selectedTransactions [ item . keyForList ] ?. isSelected ) ;
209- return acc + ( isTransactionSelected ? 1 : 0 ) ;
210- } , 0 ) ;
211-
212- if ( type === CONST . SEARCH . DATA_TYPES . EXPENSE_REPORT && isTransactionGroupListItemArray ( data ) ) {
213- const selectedEmptyReports = emptyReports . reduce ( ( acc , item ) => {
214- const isEmptyReportSelected = ! ! ( item . keyForList && selectedTransactions [ item . keyForList ] ?. isSelected ) ;
215- return acc + ( isEmptyReportSelected ? 1 : 0 ) ;
216- } , 0 ) ;
217-
218- return selectedEmptyReports + selectedTransactionsCount ;
219- }
220-
221- return selectedTransactionsCount ;
222- } , [ flattenedItems , type , data , emptyReports , selectedTransactions ] ) ;
223-
224- const totalItems = useMemo ( ( ) => {
225- if ( type === CONST . SEARCH . DATA_TYPES . EXPENSE_REPORT && isTransactionGroupListItemArray ( data ) ) {
226- const selectableEmptyReports = emptyReports . filter ( ( item ) => item . pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ) ;
227- const selectableTransactions = flattenedItems . filter ( ( item ) => {
228- if ( 'pendingAction' in item ) {
229- return item . pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ;
230- }
231- return true ;
232- } ) ;
233- return selectableEmptyReports . length + selectableTransactions . length ;
234- }
235-
236- const selectableTransactions = flattenedItems . filter ( ( item ) => {
237- if ( 'pendingAction' in item ) {
238- return item . pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ;
202+ return flattenedItemsWithoutPendingDelete . reduce ( ( acc , item ) => {
203+ if ( item . keyForList && selectedTransactions [ item . keyForList ] ?. isSelected ) {
204+ return acc + 1 ;
239205 }
240- return true ;
241- } ) ;
242- return selectableTransactions . length ;
243- } , [ data , type , flattenedItems , emptyReports ] ) ;
206+ return acc ;
207+ } , 0 ) ;
208+ } , [ flattenedItemsWithoutPendingDelete , selectedTransactions ] ) ;
244209
245210 const itemsWithSelection = useMemo ( ( ) => {
246211 return data . map ( ( item ) => {
@@ -251,16 +216,10 @@ function SearchList({
251216 if ( ! canSelectMultiple ) {
252217 itemWithSelection = { ...item , isSelected : false } ;
253218 } else {
254- const isEmptyReportSelected =
255- item . transactions . length === 0 && isTransactionReportGroupListItemType ( item ) && ! ! ( item . keyForList && selectedTransactions [ item . keyForList ] ?. isSelected ) ;
256-
257- const hasAnySelected = item . transactions . some ( ( t ) => t . keyForList && selectedTransactions [ t . keyForList ] ?. isSelected ) || isEmptyReportSelected ;
219+ const hasAnySelected = item . transactions . some ( ( t ) => t . keyForList && selectedTransactions [ t . keyForList ] ?. isSelected ) ;
258220
259221 if ( ! hasAnySelected ) {
260222 itemWithSelection = { ...item , isSelected : false } ;
261- } else if ( isEmptyReportSelected ) {
262- isSelected = true ;
263- itemWithSelection = { ...item , isSelected} ;
264223 } else {
265224 let allNonDeletedSelected = true ;
266225 let hasNonDeletedTransactions = false ;
@@ -353,7 +312,10 @@ function SearchList({
353312 if ( shouldPreventLongPressRow || ! isSmallScreenWidth || item ?. isDisabled || item ?. isDisabledCheckbox ) {
354313 return ;
355314 }
356-
315+ // disable long press for empty expense reports
316+ if ( 'transactions' in item && item . transactions . length === 0 && ! groupBy ) {
317+ return ;
318+ }
357319 if ( isMobileSelectionModeEnabled ) {
358320 onCheckboxPress ( item , itemTransactions ) ;
359321 return ;
@@ -362,7 +324,7 @@ function SearchList({
362324 setLongPressedItemTransactions ( itemTransactions ) ;
363325 setIsModalVisible ( true ) ;
364326 } ,
365- [ route . key , shouldPreventLongPressRow , isSmallScreenWidth , isMobileSelectionModeEnabled , onCheckboxPress ] ,
327+ [ groupBy , route . key , shouldPreventLongPressRow , isSmallScreenWidth , isMobileSelectionModeEnabled , onCheckboxPress ] ,
366328 ) ;
367329
368330 const turnOnSelectionMode = useCallback ( ( ) => {
@@ -491,7 +453,7 @@ function SearchList({
491453
492454 const tableHeaderVisible = canSelectMultiple || ! ! SearchTableHeader ;
493455 const selectAllButtonVisible = canSelectMultiple && ! SearchTableHeader ;
494- const isSelectAllChecked = selectedItemsLength > 0 && selectedItemsLength === totalItems ;
456+ const isSelectAllChecked = selectedItemsLength > 0 && selectedItemsLength === flattenedItemsWithoutPendingDelete . length ;
495457
496458 const content = (
497459 < View style = { [ styles . flex1 , ! isKeyboardShown && safeAreaPaddingBottomStyle , containerStyle ] } >
@@ -501,7 +463,7 @@ function SearchList({
501463 < Checkbox
502464 accessibilityLabel = { translate ( 'workspace.people.selectAll' ) }
503465 isChecked = { isSelectAllChecked }
504- isIndeterminate = { selectedItemsLength > 0 && selectedItemsLength !== totalItems }
466+ isIndeterminate = { selectedItemsLength > 0 && selectedItemsLength !== flattenedItemsWithoutPendingDelete . length }
505467 onPress = { ( ) => {
506468 onAllCheckboxPress ( ) ;
507469 } }
0 commit comments