@@ -406,8 +406,8 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
406406 return [ ] ;
407407 }
408408
409- return getSections ( type , searchResults . data , accountID , formatPhoneNumber , groupBy , exportReportActions , searchKey , archivedReportsIdSet ) ;
410- } , [ searchKey , exportReportActions , groupBy , isDataLoaded , searchResults , type , archivedReportsIdSet , formatPhoneNumber , accountID ] ) ;
409+ return getSections ( type , searchResults . data , accountID , formatPhoneNumber , groupBy , exportReportActions , searchKey , archivedReportsIdSet , queryJSON ) ;
410+ } , [ searchKey , exportReportActions , groupBy , isDataLoaded , searchResults , type , archivedReportsIdSet , formatPhoneNumber , accountID , queryJSON ] ) ;
411411
412412 useEffect ( ( ) => {
413413 /** We only want to display the skeleton for the status filters the first time we load them for a specific data type */
@@ -543,7 +543,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
543543 } , [ isFocused , data , searchResults ?. search ?. hasMoreResults , selectedTransactions , selectAllMatchingItems , shouldShowSelectAllMatchingItems , groupBy ] ) ;
544544
545545 const toggleTransaction = useCallback (
546- ( item : SearchListItem ) => {
546+ ( item : SearchListItem , itemTransactions ?: TransactionListItemType [ ] ) => {
547547 if ( isReportActionListItemType ( item ) ) {
548548 return ;
549549 }
@@ -561,10 +561,11 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
561561 return ;
562562 }
563563
564- if ( item . transactions . some ( ( transaction ) => selectedTransactions [ transaction . keyForList ] ?. isSelected ) ) {
564+ const currentTransactions = itemTransactions ?? item . transactions ;
565+ if ( currentTransactions . some ( ( transaction ) => selectedTransactions [ transaction . keyForList ] ?. isSelected ) ) {
565566 const reducedSelectedTransactions : SelectedTransactions = { ...selectedTransactions } ;
566567
567- item . transactions . forEach ( ( transaction ) => {
568+ currentTransactions . forEach ( ( transaction ) => {
568569 delete reducedSelectedTransactions [ transaction . keyForList ] ;
569570 } ) ;
570571
@@ -576,7 +577,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
576577 {
577578 ...selectedTransactions ,
578579 ...Object . fromEntries (
579- item . transactions
580+ currentTransactions
580581 . filter ( ( t ) => ! isTransactionPendingDelete ( t ) )
581582 . map ( ( transactionItem ) => mapTransactionItemToSelectedEntry ( transactionItem , reportActionsArray , outstandingReportsByPolicyID ) ) ,
582583 ) ,
@@ -587,7 +588,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
587588 [ data , reportActionsArray , selectedTransactions , outstandingReportsByPolicyID , setSelectedTransactions ] ,
588589 ) ;
589590
590- const openReport = useCallback (
591+ const onSelectRow = useCallback (
591592 ( item : SearchListItem ) => {
592593 if ( isMobileSelectionModeEnabled ) {
593594 toggleTransaction ( item ) ;
@@ -599,7 +600,11 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
599600 newFlatFilters . push ( { key : CONST . SEARCH . SYNTAX_FILTER_KEYS . FROM , filters : [ { operator : CONST . SEARCH . SYNTAX_OPERATORS . EQUAL_TO , value : item . accountID } ] } ) ;
600601 const newQueryJSON : SearchQueryJSON = { ...queryJSON , groupBy : undefined , flatFilters : newFlatFilters } ;
601602 const newQuery = buildSearchQueryString ( newQueryJSON ) ;
602- Navigation . navigate ( ROUTES . SEARCH_ROOT . getRoute ( { query : newQuery } ) ) ;
603+ const newQueryJSONWithHash = buildSearchQueryJSON ( newQuery ) ;
604+ if ( ! newQueryJSONWithHash ) {
605+ return ;
606+ }
607+ handleSearch ( { queryJSON : newQueryJSONWithHash , searchKey, offset : 0 , shouldCalculateTotals : false } ) ;
603608 return ;
604609 }
605610
@@ -608,7 +613,11 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
608613 newFlatFilters . push ( { key : CONST . SEARCH . SYNTAX_FILTER_KEYS . CARD_ID , filters : [ { operator : CONST . SEARCH . SYNTAX_OPERATORS . EQUAL_TO , value : item . cardID } ] } ) ;
609614 const newQueryJSON : SearchQueryJSON = { ...queryJSON , groupBy : undefined , flatFilters : newFlatFilters } ;
610615 const newQuery = buildSearchQueryString ( newQueryJSON ) ;
611- Navigation . navigate ( ROUTES . SEARCH_ROOT . getRoute ( { query : newQuery } ) ) ;
616+ const newQueryJSONWithHash = buildSearchQueryJSON ( newQuery ) ;
617+ if ( ! newQueryJSONWithHash ) {
618+ return ;
619+ }
620+ handleSearch ( { queryJSON : newQueryJSONWithHash , searchKey, offset : 0 , shouldCalculateTotals : false } ) ;
612621 return ;
613622 }
614623
@@ -617,7 +626,11 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
617626 newFlatFilters . push ( { key : CONST . SEARCH . SYNTAX_FILTER_KEYS . WITHDRAWAL_ID , filters : [ { operator : CONST . SEARCH . SYNTAX_OPERATORS . EQUAL_TO , value : item . entryID } ] } ) ;
618627 const newQueryJSON : SearchQueryJSON = { ...queryJSON , groupBy : undefined , flatFilters : newFlatFilters } ;
619628 const newQuery = buildSearchQueryString ( newQueryJSON ) ;
620- Navigation . navigate ( ROUTES . SEARCH_ROOT . getRoute ( { query : newQuery } ) ) ;
629+ const newQueryJSONWithHash = buildSearchQueryJSON ( newQuery ) ;
630+ if ( ! newQueryJSONWithHash ) {
631+ return ;
632+ }
633+ handleSearch ( { queryJSON : newQueryJSONWithHash , searchKey, offset : 0 , shouldCalculateTotals : false } ) ;
621634 return ;
622635 }
623636
@@ -662,7 +675,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
662675
663676 Navigation . navigate ( ROUTES . SEARCH_REPORT . getRoute ( { reportID, backTo} ) ) ;
664677 } ,
665- [ hash , isMobileSelectionModeEnabled , toggleTransaction , queryJSON , reportActionsArray ] ,
678+ [ isMobileSelectionModeEnabled , toggleTransaction , queryJSON , handleSearch , searchKey , reportActionsArray , hash ] ,
666679 ) ;
667680
668681 const currentColumns = useMemo ( ( ) => {
@@ -700,13 +713,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
700713
701714 const isChat = type === CONST . SEARCH . DATA_TYPES . CHAT ;
702715 const isTask = type === CONST . SEARCH . DATA_TYPES . TASK ;
703- const canSelectMultiple =
704- ! isChat &&
705- ! isTask &&
706- ( ! isSmallScreenWidth || isMobileSelectionModeEnabled ) &&
707- groupBy !== CONST . SEARCH . GROUP_BY . FROM &&
708- groupBy !== CONST . SEARCH . GROUP_BY . CARD &&
709- groupBy !== CONST . SEARCH . GROUP_BY . WITHDRAWAL_ID ;
716+ const canSelectMultiple = ! isChat && ! isTask && ( ! isSmallScreenWidth || isMobileSelectionModeEnabled ) && groupBy !== CONST . SEARCH . GROUP_BY . WITHDRAWAL_ID ;
710717 const ListItem = getListItem ( type , status , groupBy ) ;
711718
712719 const sortedSelectedData = useMemo (
@@ -853,7 +860,8 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
853860 const shouldShowYear = shouldShowYearUtil ( searchResults ?. data ) ;
854861 const { shouldShowAmountInWideColumn, shouldShowTaxAmountInWideColumn} = getWideAmountIndicators ( searchResults ?. data ) ;
855862 const shouldShowSorting = ! groupBy ;
856- const shouldShowTableHeader = isLargeScreenWidth && ! isChat ;
863+ const shouldShowTableHeader = isLargeScreenWidth && ! isChat && ! groupBy ;
864+ const tableHeaderVisible = ( canSelectMultiple || shouldShowTableHeader ) && ( ! groupBy || groupBy === CONST . SEARCH . GROUP_BY . REPORTS ) ;
857865
858866 return (
859867 < SearchScopeProvider isOnSearch >
@@ -862,7 +870,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
862870 ref = { searchListRef }
863871 data = { sortedSelectedData }
864872 ListItem = { ListItem }
865- onSelectRow = { openReport }
873+ onSelectRow = { onSelectRow }
866874 onCheckboxPress = { toggleTransaction }
867875 onAllCheckboxPress = { toggleAllTransactions }
868876 canSelectMultiple = { canSelectMultiple }
@@ -873,21 +881,21 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
873881 < SearchTableHeader
874882 canSelectMultiple = { canSelectMultiple }
875883 columns = { columnsToShow }
876- metadata = { searchResults ?. search }
884+ type = { searchResults ?. search . type }
877885 onSortPress = { onSortPress }
878886 sortOrder = { sortOrder }
879887 sortBy = { sortBy }
880888 shouldShowYear = { shouldShowYear }
881889 isAmountColumnWide = { shouldShowAmountInWideColumn }
882890 isTaxAmountColumnWide = { shouldShowTaxAmountInWideColumn }
883891 shouldShowSorting = { shouldShowSorting }
884- groupBy = { groupBy }
885892 areAllOptionalColumnsHidden = { areAllOptionalColumnsHidden }
893+ groupBy = { groupBy }
886894 />
887895 )
888896 }
889897 contentContainerStyle = { { ...contentContainerStyle , ...styles . pb3 } }
890- containerStyle = { [ styles . pv0 , type === CONST . SEARCH . DATA_TYPES . CHAT && ! isSmallScreenWidth && styles . pt3 ] }
898+ containerStyle = { [ styles . pv0 , ! tableHeaderVisible && ! isSmallScreenWidth && styles . pt3 ] }
891899 shouldPreventDefaultFocusOnSelectRow = { ! canUseTouchScreen ( ) }
892900 onScroll = { onSearchListScroll }
893901 onEndReachedThreshold = { 0.75 }
0 commit comments