-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Workspace feeds] Add search bar if cards assignment list has 8+ cards #51955
Changes from all commits
9a98fec
5bac1ab
aaabf8b
1da4eae
a3e9c13
b46bc0c
952c0f0
8082a9a
a9bdbe2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,8 @@ function BaseSelectionList<TItem extends ListItem>( | |
textInputIconLeft, | ||
sectionTitleStyles, | ||
textInputAutoFocus = true, | ||
shouldShowTextInputAfterHeader = false, | ||
includeSafeAreaPaddingBottom = true, | ||
shouldTextInputInterceptSwipe = false, | ||
listHeaderContent, | ||
onEndReached = () => {}, | ||
|
@@ -500,6 +502,48 @@ function BaseSelectionList<TItem extends ListItem>( | |
return null; | ||
}; | ||
|
||
const renderInput = () => { | ||
return ( | ||
<View style={[styles.ph5, styles.pb3]}> | ||
<TextInput | ||
ref={(element) => { | ||
innerTextInputRef.current = element as RNTextInput; | ||
|
||
if (!textInputRef) { | ||
return; | ||
} | ||
|
||
if (typeof textInputRef === 'function') { | ||
textInputRef(element as RNTextInput); | ||
} else { | ||
// eslint-disable-next-line no-param-reassign | ||
textInputRef.current = element as RNTextInput; | ||
} | ||
}} | ||
onFocus={() => (isTextInputFocusedRef.current = true)} | ||
onBlur={() => (isTextInputFocusedRef.current = false)} | ||
label={textInputLabel} | ||
accessibilityLabel={textInputLabel} | ||
hint={textInputHint} | ||
role={CONST.ROLE.PRESENTATION} | ||
value={textInputValue} | ||
placeholder={textInputPlaceholder} | ||
maxLength={textInputMaxLength} | ||
onChangeText={onChangeText} | ||
inputMode={inputMode} | ||
selectTextOnFocus | ||
spellCheck={false} | ||
iconLeft={textInputIconLeft} | ||
onSubmitEditing={selectFocusedOption} | ||
blurOnSubmit={!!flattenedSections.allOptions.length} | ||
isLoading={isLoadingNewOptions} | ||
testID="selection-list-text-input" | ||
shouldInterceptSwipe={shouldTextInputInterceptSwipe} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
const scrollToFocusedIndexOnFirstRender = useCallback( | ||
(nativeEvent: LayoutChangeEvent) => { | ||
if (shouldUseDynamicMaxToRenderPerBatch) { | ||
|
@@ -676,46 +720,8 @@ function BaseSelectionList<TItem extends ListItem>( | |
return ( | ||
<SafeAreaConsumer> | ||
{({safeAreaPaddingBottomStyle}) => ( | ||
<View style={[styles.flex1, (!isKeyboardShown || !!footerContent || showConfirmButton) && safeAreaPaddingBottomStyle, containerStyle]}> | ||
{shouldShowTextInput && ( | ||
<View style={[styles.ph5, styles.pb3]}> | ||
<TextInput | ||
ref={(element) => { | ||
innerTextInputRef.current = element as RNTextInput; | ||
|
||
if (!textInputRef) { | ||
return; | ||
} | ||
|
||
if (typeof textInputRef === 'function') { | ||
textInputRef(element as RNTextInput); | ||
} else { | ||
// eslint-disable-next-line no-param-reassign | ||
textInputRef.current = element as RNTextInput; | ||
} | ||
}} | ||
onFocus={() => (isTextInputFocusedRef.current = true)} | ||
onBlur={() => (isTextInputFocusedRef.current = false)} | ||
label={textInputLabel} | ||
accessibilityLabel={textInputLabel} | ||
hint={textInputHint} | ||
role={CONST.ROLE.PRESENTATION} | ||
value={textInputValue} | ||
placeholder={textInputPlaceholder} | ||
maxLength={textInputMaxLength} | ||
onChangeText={onChangeText} | ||
inputMode={inputMode} | ||
selectTextOnFocus | ||
spellCheck={false} | ||
iconLeft={textInputIconLeft} | ||
onSubmitEditing={selectFocusedOption} | ||
blurOnSubmit={!!flattenedSections.allOptions.length} | ||
isLoading={isLoadingNewOptions} | ||
testID="selection-list-text-input" | ||
shouldInterceptSwipe={shouldTextInputInterceptSwipe} | ||
/> | ||
</View> | ||
)} | ||
<View style={[styles.flex1, (!isKeyboardShown || !!footerContent || showConfirmButton) && includeSafeAreaPaddingBottom && safeAreaPaddingBottomStyle, containerStyle]}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dukenv0307 @VickyStash, let's be on the lookout for any bugs related to these. Changing the base components is like pandora box |
||
{shouldShowTextInput && !shouldShowTextInputAfterHeader && renderInput()} | ||
{/* If we are loading new options we will avoid showing any header message. This is mostly because one of the header messages says there are no options. */} | ||
{/* This is misleading because we might be in the process of loading fresh options from the server. */} | ||
{(!isLoadingNewOptions || headerMessage !== translate('common.noResultsFound') || (flattenedSections.allOptions.length === 0 && !showLoadingPlaceholder)) && | ||
|
@@ -759,7 +765,16 @@ function BaseSelectionList<TItem extends ListItem>( | |
testID="selection-list" | ||
onLayout={onSectionListLayout} | ||
style={[(!maxToRenderPerBatch || (shouldHideListOnInitialRender && isInitialSectionListRender)) && styles.opacity0, sectionListStyle]} | ||
ListHeaderComponent={listHeaderContent} | ||
ListHeaderComponent={ | ||
shouldShowTextInput && shouldShowTextInputAfterHeader ? ( | ||
<> | ||
{listHeaderContent} | ||
{renderInput()} | ||
</> | ||
) : ( | ||
listHeaderContent | ||
) | ||
} | ||
ListFooterComponent={listFooterContent ?? ShowMoreButtonInstance} | ||
onEndReached={onEndReached} | ||
onEndReachedThreshold={onEndReachedThreshold} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import React, {useState} from 'react'; | ||
import React, {useMemo, useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton'; | ||
import Icon from '@components/Icon'; | ||
import * as Illustrations from '@components/Icon/Illustrations'; | ||
import InteractiveStepSubHeader from '@components/InteractiveStepSubHeader'; | ||
import InteractiveStepWrapper from '@components/InteractiveStepWrapper'; | ||
import SelectionList from '@components/SelectionList'; | ||
import RadioListItem from '@components/SelectionList/RadioListItem'; | ||
|
@@ -36,6 +37,7 @@ function CardSelectionStep({feed, policyID}: CardSelectionStepProps) { | |
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
const {environmentURL} = useEnvironment(); | ||
const [searchText, setSearchText] = useState(''); | ||
const [assignCard] = useOnyx(ONYXKEYS.ASSIGN_CARD); | ||
const [list] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${feed}`); | ||
const [cardFeeds] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`); | ||
|
@@ -117,12 +119,14 @@ function CardSelectionStep({feed, policyID}: CardSelectionStepProps) { | |
|
||
const listOptions = accountCardList?.length > 0 ? accountCardListOptions : cardListOptions; | ||
|
||
const searchedListOptions = useMemo(() => { | ||
return listOptions.filter((option) => option.text.toLowerCase().includes(searchText)); | ||
}, [searchText, listOptions]); | ||
|
||
return ( | ||
<InteractiveStepWrapper | ||
wrapperID={CardSelectionStep.displayName} | ||
handleBackButtonPress={handleBackButtonPress} | ||
startStepIndex={listOptions.length ? 1 : undefined} | ||
stepNames={listOptions.length ? CONST.COMPANY_CARD.STEP_NAMES : undefined} | ||
headerTitle={translate('workspace.companyCards.assignCard')} | ||
headerSubtitle={assigneeDisplayName} | ||
> | ||
|
@@ -147,18 +151,35 @@ function CardSelectionStep({feed, policyID}: CardSelectionStepProps) { | |
</View> | ||
) : ( | ||
<> | ||
<Text style={[styles.textHeadlineLineHeightXXL, styles.ph5, styles.mt3]}>{translate('workspace.companyCards.chooseCard')}</Text> | ||
<Text style={[styles.textSupporting, styles.ph5, styles.mv3]}> | ||
{translate('workspace.companyCards.chooseCardFor', { | ||
assignee: assigneeDisplayName, | ||
feed: CardUtils.getCardFeedName(feed), | ||
})} | ||
</Text> | ||
<SelectionList | ||
sections={[{data: listOptions}]} | ||
sections={[{data: searchedListOptions}]} | ||
shouldShowTextInput={listOptions.length > CONST.COMPANY_CARDS.CARD_LIST_THRESHOLD} | ||
textInputLabel={translate('common.search')} | ||
textInputValue={searchText} | ||
onChangeText={setSearchText} | ||
ListItem={RadioListItem} | ||
onSelectRow={({value}) => handleSelectCard(value)} | ||
initiallyFocusedOptionKey={cardSelected} | ||
listHeaderContent={ | ||
<View> | ||
<View style={[styles.ph5, styles.mb5, styles.mt3, {height: CONST.BANK_ACCOUNT.STEPS_HEADER_HEIGHT}]}> | ||
<InteractiveStepSubHeader | ||
startStepIndex={1} | ||
stepNames={CONST.COMPANY_CARD.STEP_NAMES} | ||
/> | ||
</View> | ||
<Text style={[styles.textHeadlineLineHeightXXL, styles.ph5, styles.mt3]}>{translate('workspace.companyCards.chooseCard')}</Text> | ||
<Text style={[styles.textSupporting, styles.ph5, styles.mv3]}> | ||
{translate('workspace.companyCards.chooseCardFor', { | ||
assignee: assigneeDisplayName, | ||
feed: CardUtils.getCardFeedName(feed), | ||
})} | ||
</Text> | ||
</View> | ||
} | ||
shouldShowTextInputAfterHeader | ||
includeSafeAreaPaddingBottom={false} | ||
shouldShowListEmptyContent={false} | ||
shouldUpdateFocusedIndex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should implement empty content instead of setting it to false here to make the UI consistent with other places. More details at: #56078 (comment) |
||
/> | ||
<FormAlertWithSubmitButton | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make a generic const for this, any list like this should turn into a searchable list if it has more than 8 elements