@@ -4,6 +4,7 @@ import ActivityIndicator from '@components/ActivityIndicator';
44import { usePersonalDetails } from '@components/OnyxListItemProvider' ;
55import CardListItem from '@components/SelectionList/ListItem/CardListItem' ;
66import SelectionListWithSections from '@components/SelectionList/SelectionListWithSections' ;
7+ import type { Section } from '@components/SelectionList/SelectionListWithSections/types' ;
78import { useCompanyCardFeedIcons } from '@hooks/useCompanyCardIcons' ;
89import useDebouncedState from '@hooks/useDebouncedState' ;
910import useLocalize from '@hooks/useLocalize' ;
@@ -38,8 +39,7 @@ function CardSelectPopup({isExpanded, updateFilterForm, closeOverlay}: CardSelec
3839 const illustrations = useThemeIllustrations ( ) ;
3940 const companyCardFeedIcons = useCompanyCardFeedIcons ( ) ;
4041 const { windowHeight} = useWindowDimensions ( ) ;
41- // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
42- const { isSmallScreenWidth, isInLandscapeMode} = useResponsiveLayout ( ) ;
42+ const { shouldUseNarrowLayout, isInLandscapeMode} = useResponsiveLayout ( ) ;
4343
4444 const [ areCardsLoaded ] = useOnyx ( ONYXKEYS . IS_SEARCH_FILTERS_CARD_DATA_LOADED ) ;
4545 const [ userCardList , userCardListMetadata ] = useOnyx ( ONYXKEYS . CARD_LIST ) ;
@@ -100,31 +100,42 @@ function CardSelectPopup({isExpanded, updateFilterForm, closeOverlay}: CardSelec
100100 ! ! item . cardName ?. toLocaleLowerCase ( ) . includes ( debouncedSearchTerm . toLocaleLowerCase ( ) ) ||
101101 ( item . isVirtual && translate ( 'workspace.expensifyCard.virtual' ) . toLocaleLowerCase ( ) . includes ( debouncedSearchTerm . toLocaleLowerCase ( ) ) ) ;
102102
103- const sections =
104- searchAdvancedFiltersForm === undefined
105- ? [ ]
106- : [
107- {
108- title : undefined ,
109- data : [ ...cardFeedsSectionData . selected , ...individualCardsSectionData . selected , ...closedCardsSectionData . selected ] . filter ( searchFunction ) ,
110- sectionIndex : 0 ,
111- } ,
112- {
113- title : translate ( 'search.filters.card.cardFeeds' ) ,
114- data : cardFeedsSectionData . unselected . filter ( searchFunction ) ,
115- sectionIndex : 1 ,
116- } ,
117- {
118- title : translate ( 'search.filters.card.individualCards' ) ,
119- data : individualCardsSectionData . unselected . filter ( searchFunction ) ,
120- sectionIndex : 2 ,
121- } ,
122- {
123- title : translate ( 'search.filters.card.closedCards' ) ,
124- data : closedCardsSectionData . unselected . filter ( searchFunction ) ,
125- sectionIndex : 3 ,
126- } ,
127- ] ;
103+ let sections : Array < Section < CardFilterItem > > = [ ] ;
104+ let itemCount ;
105+ let sectionHeaderCount = 0 ;
106+
107+ if ( searchAdvancedFiltersForm ) {
108+ const selectedData = [ ...cardFeedsSectionData . selected , ...individualCardsSectionData . selected , ...closedCardsSectionData . selected ] . filter ( searchFunction ) ;
109+ const unselectedCardFeedsData = cardFeedsSectionData . unselected . filter ( searchFunction ) ;
110+ const unselectedIndividualCardsData = individualCardsSectionData . unselected . filter ( searchFunction ) ;
111+ const unselectedClosedCardsData = closedCardsSectionData . unselected . filter ( searchFunction ) ;
112+
113+ itemCount = selectedData . length + unselectedCardFeedsData . length + unselectedIndividualCardsData . length + unselectedClosedCardsData . length ;
114+ sectionHeaderCount = [ unselectedCardFeedsData . length , unselectedIndividualCardsData . length , unselectedClosedCardsData . length ] . filter ( Boolean ) . length ;
115+
116+ sections = [
117+ {
118+ title : undefined ,
119+ data : selectedData ,
120+ sectionIndex : 0 ,
121+ } ,
122+ {
123+ title : translate ( 'search.filters.card.cardFeeds' ) ,
124+ data : unselectedCardFeedsData ,
125+ sectionIndex : 1 ,
126+ } ,
127+ {
128+ title : translate ( 'search.filters.card.individualCards' ) ,
129+ data : unselectedIndividualCardsData ,
130+ sectionIndex : 2 ,
131+ } ,
132+ {
133+ title : translate ( 'search.filters.card.closedCards' ) ,
134+ data : unselectedClosedCardsData ,
135+ sectionIndex : 3 ,
136+ } ,
137+ ] ;
138+ }
128139
129140 const applyChanges = ( ) => {
130141 const feeds = cardFeedsSectionData . selected . map ( ( feed ) => feed . cardFeedKey ) ;
@@ -174,6 +185,8 @@ function CardSelectPopup({isExpanded, updateFilterForm, closeOverlay}: CardSelec
174185 onApply = { applyChanges }
175186 resetSentryLabel = { CONST . SENTRY_LABEL . SEARCH . FILTER_POPUP_RESET_CARD }
176187 applySentryLabel = { CONST . SENTRY_LABEL . SEARCH . FILTER_POPUP_APPLY_CARD }
188+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- we want to fallback to 1 when it's 0
189+ style = { styles . getCardSelectionListPopoverHeight ( itemCount || 1 , sectionHeaderCount , windowHeight , shouldUseNarrowLayout , isInLandscapeMode , shouldShowSearchInput ) }
177190 >
178191 { ! ! shouldShowLoadingState && (
179192 < View style = { [ styles . flex1 , styles . flexColumn , styles . justifyContentCenter , styles . alignItemsCenter ] } >
@@ -186,28 +199,16 @@ function CardSelectPopup({isExpanded, updateFilterForm, closeOverlay}: CardSelec
186199 </ View >
187200 ) }
188201 { ! shouldShowLoadingState && (
189- < View
190- style = { [
191- styles . getSelectionListPopoverHeight (
192- sections . flatMap ( ( section ) => section . data ) . length || 1 ,
193- windowHeight ,
194- shouldShowSearchInput ,
195- isInLandscapeMode ,
196- isSmallScreenWidth ,
197- ) ,
198- ] }
199- >
200- < SelectionListWithSections < CardFilterItem >
201- sections = { sections }
202- ListItem = { CardListItem }
203- onSelectRow = { updateNewCards }
204- shouldPreventDefaultFocusOnSelectRow = { false }
205- shouldShowTextInput = { shouldShowSearchInput }
206- textInputOptions = { textInputOptions }
207- shouldStopPropagation
208- canSelectMultiple
209- />
210- </ View >
202+ < SelectionListWithSections < CardFilterItem >
203+ sections = { sections }
204+ ListItem = { CardListItem }
205+ onSelectRow = { updateNewCards }
206+ shouldPreventDefaultFocusOnSelectRow = { false }
207+ shouldShowTextInput = { shouldShowSearchInput }
208+ textInputOptions = { textInputOptions }
209+ shouldStopPropagation
210+ canSelectMultiple
211+ />
211212 ) }
212213 </ BasePopup >
213214 ) ;
0 commit comments