11import React , { useMemo } from 'react' ;
2- import type { SectionListData } from 'react-native' ;
32import useDebouncedState from '@hooks/useDebouncedState' ;
43import { useMemoizedLazyIllustrations } from '@hooks/useLazyAsset' ;
54import useLocalize from '@hooks/useLocalize' ;
@@ -13,15 +12,14 @@ import variables from '@styles/variables';
1312import CONST from '@src/CONST' ;
1413import ONYXKEYS from '@src/ONYXKEYS' ;
1514import type { Policy } from '@src/types/onyx' ;
16- import type { Icon } from '@src/types/onyx/OnyxCommon' ;
1715import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
1816import BlockingView from './BlockingViews/BlockingView' ;
1917import FullPageNotFoundView from './BlockingViews/FullPageNotFoundView' ;
2018import HeaderWithBackButton from './HeaderWithBackButton' ;
2119import ScreenWrapper from './ScreenWrapper' ;
22- import SelectionList from './SelectionListWithSections ' ;
23- import InviteMemberListItem from './SelectionListWithSections /InviteMemberListItem' ;
24- import type { Section } from './SelectionListWithSections /types' ;
20+ import SelectionList from './SelectionList ' ;
21+ import InviteMemberListItem from './SelectionList/ListItem /InviteMemberListItem' ;
22+ import type { ListItem } from './SelectionList /types' ;
2523
2624type ApproverSelectionListPageProps = {
2725 testID : string ;
@@ -42,21 +40,13 @@ type ApproverSelectionListPageProps = {
4240 onSelectApprover ?: ( approvers : SelectionListApprover [ ] ) => void ;
4341 shouldShowLoadingPlaceholder ?: boolean ;
4442 shouldEnableHeaderMaxHeight ?: boolean ;
43+ shouldUpdateFocusedIndex ?: boolean ;
4544} ;
4645
47- type SelectionListApprover = {
48- text : string ;
49- alternateText : string ;
50- keyForList : string ;
51- isSelected : boolean ;
52- login : string ;
53- rightElement ?: React . ReactNode ;
54- icons : Icon [ ] ;
46+ type SelectionListApprover = ListItem & {
5547 value ?: number ;
5648} ;
5749
58- type ApproverSection = SectionListData < SelectionListApprover , Section < SelectionListApprover > > ;
59-
6050function ApproverSelectionList ( {
6151 testID,
6252 headerTitle,
@@ -76,6 +66,7 @@ function ApproverSelectionList({
7666 onSelectApprover,
7767 shouldShowLoadingPlaceholder,
7868 shouldEnableHeaderMaxHeight,
69+ shouldUpdateFocusedIndex = true ,
7970} : ApproverSelectionListPageProps ) {
8071 const styles = useThemeStyles ( ) ;
8172 const { translate, localeCompare} = useLocalize ( ) ;
@@ -89,23 +80,16 @@ function ApproverSelectionList({
8980 // eslint-disable-next-line rulesdir/no-negated-variables
9081 const shouldShowNotFoundView = ( isEmptyObject ( policy ) && ! isLoadingReportData ) || ! isPolicyAdmin ( policy ) || isPendingDeletePolicy ( policy ) || shouldShowNotFoundViewProp ;
9182
92- const sections : ApproverSection [ ] = useMemo ( ( ) => {
83+ const data = useMemo ( ( ) => {
9384 const filteredApprovers =
9485 debouncedSearchTerm !== ''
9586 ? tokenizedSearch ( allApprovers , getSearchValueForPhoneOrEmail ( debouncedSearchTerm , countryCode ) , ( option ) => [ option . text ?? '' , option . login ?? '' ] )
9687 : allApprovers ;
9788
98- const data = sortAlphabetically ( filteredApprovers , 'text' , localeCompare ) ;
99- return [
100- {
101- title : undefined ,
102- data,
103- shouldShow : true ,
104- } ,
105- ] ;
89+ return sortAlphabetically ( filteredApprovers , 'text' , localeCompare ) ;
10690 } , [ allApprovers , debouncedSearchTerm , countryCode , localeCompare ] ) ;
10791
108- const shouldShowListEmptyContent = ! debouncedSearchTerm && ! sections . at ( 0 ) ?. data . length && shouldShowListEmptyContentProp ;
92+ const shouldShowListEmptyContent = ! debouncedSearchTerm && ! data . length && shouldShowListEmptyContentProp ;
10993
11094 const toggleApprover = ( member : SelectionListApprover ) => {
11195 const isAlreadySelected = selectedMembers . some ( ( selectedOption ) => selectedOption . login === member . login ) ;
@@ -122,8 +106,6 @@ function ApproverSelectionList({
122106 }
123107 } ;
124108
125- const headerMessage = useMemo ( ( ) => ( searchTerm && ! sections . at ( 0 ) ?. data ?. length ? translate ( 'common.noResultsFound' ) : '' ) , [ searchTerm , sections , translate ] ) ;
126-
127109 const listEmptyContent = useMemo (
128110 ( ) => (
129111 < BlockingView
@@ -140,6 +122,16 @@ function ApproverSelectionList({
140122 [ translate , listEmptyContentSubtitle , styles . textSupporting , styles . pb10 , lazyIllustrations . TurtleInShell ] ,
141123 ) ;
142124
125+ const textInputOptions = useMemo (
126+ ( ) => ( {
127+ label : shouldShowListEmptyContent ? undefined : translate ( 'selectionList.findMember' ) ,
128+ value : searchTerm ,
129+ onChangeText : setSearchTerm ,
130+ headerMessage : searchTerm && ! data ?. length ? translate ( 'common.noResultsFound' ) : '' ,
131+ } ) ,
132+ [ shouldShowListEmptyContent , translate , searchTerm , setSearchTerm , data ?. length ] ,
133+ ) ;
134+
143135 return (
144136 < ScreenWrapper
145137 testID = { testID }
@@ -160,24 +152,21 @@ function ApproverSelectionList({
160152 />
161153 { subtitle }
162154 < SelectionList
163- canSelectMultiple = { allowMultipleSelection }
164- sections = { sections }
165- ListItem = { InviteMemberListItem }
166- textInputLabel = { shouldShowListEmptyContent ? undefined : translate ( 'selectionList.findMember' ) }
167- textInputValue = { searchTerm }
168- onChangeText = { setSearchTerm }
169- headerMessage = { headerMessage }
155+ data = { data }
170156 onSelectRow = { toggleApprover }
171- showScrollIndicator
157+ ListItem = { InviteMemberListItem }
158+ textInputOptions = { textInputOptions }
159+ canSelectMultiple = { allowMultipleSelection }
172160 shouldPreventDefaultFocusOnSelectRow = { ! canUseTouchScreen ( ) }
173161 listEmptyContent = { listEmptyContent }
174- shouldShowListEmptyContent = { shouldShowListEmptyContent }
175- initiallyFocusedOptionKey = { initiallyFocusedOptionKey }
176- shouldUpdateFocusedIndex
162+ showListEmptyContent = { shouldShowListEmptyContent }
163+ initiallyFocusedItemKey = { initiallyFocusedOptionKey }
177164 shouldShowTextInput = { shouldShowTextInput }
178- addBottomSafeAreaPadding
179165 showLoadingPlaceholder = { shouldShowLoadingPlaceholder }
180166 footerContent = { footerContent }
167+ addBottomSafeAreaPadding
168+ shouldUpdateFocusedIndex = { shouldUpdateFocusedIndex }
169+ showScrollIndicator
181170 />
182171 </ FullPageNotFoundView >
183172 </ ScreenWrapper >
0 commit comments