Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3056,6 +3056,7 @@ const CONST = {
// Character Limits
FORM_CHARACTER_LIMIT: 50,
STANDARD_LENGTH_LIMIT: 100,
STANDARD_LIST_ITEM_LIMIT: 8,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding such const it should be good to also updated all the applicable usages to use it, maybe you can do it in another PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - today will add it with upcoming PR.

LEGAL_NAMES_CHARACTER_LIMIT: 150,
LOGIN_CHARACTER_LIMIT: 254,
CATEGORY_NAME_LIMIT: 256,
Expand Down
20 changes: 20 additions & 0 deletions src/components/SelectionScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ type SelectionScreenProps<T = string> = {

/** 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<T = string>({
Expand All @@ -117,6 +129,10 @@ function SelectionScreen<T = string>({
onClose,
shouldSingleExecuteRowSelect,
headerTitleAlreadyTranslated,
textInputLabel,
textInputValue,
onChangeText,
shouldShowTextInput,
shouldUpdateFocusedIndex = false,
}: SelectionScreenProps<T>) {
const {translate} = useLocalize();
Expand Down Expand Up @@ -152,9 +168,13 @@ function SelectionScreen<T = string>({
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}
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(
() => (
Expand Down Expand Up @@ -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}
/>
);
}
Expand Down