From ee15e84b1b6d55fa8c655213acad894e846f7410 Mon Sep 17 00:00:00 2001 From: Nicolay Arefyeu Date: Tue, 5 Nov 2024 16:21:14 +0200 Subject: [PATCH] Workspace Feed - add Search for more than 8 export rows --- src/CONST.ts | 1 + src/components/SelectionScreen.tsx | 20 +++++++++++++++++++ ...kspaceCompanyCardAccountSelectCardPage.tsx | 14 +++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index fbe12d1fdfb2..0dc1edd87aff 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3056,6 +3056,7 @@ const CONST = { // Character Limits FORM_CHARACTER_LIMIT: 50, STANDARD_LENGTH_LIMIT: 100, + STANDARD_LIST_ITEM_LIMIT: 8, LEGAL_NAMES_CHARACTER_LIMIT: 150, LOGIN_CHARACTER_LIMIT: 254, CATEGORY_NAME_LIMIT: 256, diff --git a/src/components/SelectionScreen.tsx b/src/components/SelectionScreen.tsx index 8382029bc12f..3538b04ed57f 100644 --- a/src/components/SelectionScreen.tsx +++ b/src/components/SelectionScreen.tsx @@ -93,6 +93,18 @@ type SelectionScreenProps = { /** Whether to update the focused index on a row select */ shouldUpdateFocusedIndex?: boolean; + + /** Whether to show the text input */ + shouldShowTextInput?: boolean; + + /** Label for the text input */ + textInputLabel?: string; + + /** Value for the text input */ + textInputValue?: string; + + /** Callback to fire when the text input changes */ + onChangeText?: (text: string) => void; }; function SelectionScreen({ @@ -117,6 +129,10 @@ function SelectionScreen({ onClose, shouldSingleExecuteRowSelect, headerTitleAlreadyTranslated, + textInputLabel, + textInputValue, + onChangeText, + shouldShowTextInput, shouldUpdateFocusedIndex = false, }: SelectionScreenProps) { const {translate} = useLocalize(); @@ -152,9 +168,13 @@ function SelectionScreen({ sections={sections} ListItem={listItem} showScrollIndicator + onChangeText={onChangeText} shouldShowTooltips={false} initiallyFocusedOptionKey={initiallyFocusedOptionKey} listEmptyContent={listEmptyContent} + textInputLabel={textInputLabel} + textInputValue={textInputValue} + shouldShowTextInput={shouldShowTextInput} listFooterContent={listFooterContent} sectionListStyle={!!sections.length && [styles.flexGrow0]} shouldSingleExecuteRowSelect={shouldSingleExecuteRowSelect} diff --git a/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx b/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx index db3e02a55738..c32cebd7ba18 100644 --- a/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx +++ b/src/pages/workspace/companyCards/WorkspaceCompanyCardAccountSelectCardPage.tsx @@ -1,5 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import React, {useCallback, useMemo} from 'react'; +import React, {useCallback, useMemo, useState} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import BlockingView from '@components/BlockingViews/BlockingView'; @@ -31,12 +31,18 @@ function WorkspaceCompanyCardAccountSelectCardPage({route}: WorkspaceCompanyCard const {policyID, cardID, bank} = route.params; const policy = usePolicy(policyID); const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID); + const [searchText, setSearchText] = useState(''); const [allBankCards] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${bank}`); const card = allBankCards?.[cardID]; const connectedIntegration = PolicyUtils.getConnectedIntegration(policy) ?? CONST.POLICY.CONNECTIONS.NAME.QBO; const exportMenuItem = getExportMenuItem(connectedIntegration, policyID, translate, policy, card); const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); + const shouldShowTextInput = (exportMenuItem?.data?.length ?? 0) >= CONST.STANDARD_LIST_ITEM_LIMIT; + + const searchedListOptions = useMemo(() => { + return exportMenuItem?.data.filter((option) => option.value.toLowerCase().includes(searchText)); + }, [exportMenuItem?.data, searchText]); const listEmptyContent = useMemo( () => ( @@ -87,14 +93,18 @@ function WorkspaceCompanyCardAccountSelectCardPage({route}: WorkspaceCompanyCard } featureName={CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED} displayName={WorkspaceCompanyCardAccountSelectCardPage.displayName} - sections={[{data: exportMenuItem?.data ?? []}]} + sections={[{data: searchedListOptions ?? []}]} listItem={RadioListItem} + textInputLabel={translate('common.search')} + textInputValue={searchText} + onChangeText={setSearchText} onSelectRow={updateExportAccount} initiallyFocusedOptionKey={exportMenuItem?.data?.find((mode) => mode.isSelected)?.keyForList} onBackButtonPress={() => Navigation.goBack(ROUTES.WORKSPACE_COMPANY_CARD_DETAILS.getRoute(policyID, cardID, bank))} headerTitleAlreadyTranslated={exportMenuItem?.description} listEmptyContent={listEmptyContent} connectionName={connectedIntegration} + shouldShowTextInput={shouldShowTextInput} /> ); }