Skip to content
Draft
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
12 changes: 5 additions & 7 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ function BaseSelectionList<TItem extends ListItem>({
rightHandSideComponent,
alternateNumberOfSupportedLines,
selectedItems = CONST.EMPTY_ARRAY,
listStyle,
listItemTitleStyles,
listItemWrapperStyle,
style,
isSelected,
isSmallScreenWidth,
isLoadingNewOptions,
Expand Down Expand Up @@ -311,8 +309,8 @@ function BaseSelectionList<TItem extends ListItem>({
isAlternateTextMultilineSupported={!!alternateNumberOfSupportedLines}
alternateTextNumberOfLines={alternateNumberOfSupportedLines}
shouldIgnoreFocus={shouldIgnoreFocus}
wrapperStyle={listItemWrapperStyle}
titleStyles={listItemTitleStyles}
wrapperStyle={style?.listItemWrapperStyle}
titleStyles={style?.listItemTitleStyles}
singleExecution={singleExecution}
/>
);
Expand Down Expand Up @@ -365,7 +363,7 @@ function BaseSelectionList<TItem extends ListItem>({

useImperativeHandle(ref, () => ({scrollAndHighlightItem, scrollToIndex}), [scrollAndHighlightItem, scrollToIndex]);
return (
<View style={styles.flex1}>
<View style={[styles.flex1, style?.containerStyle]}>
{textInputComponent({shouldBeInsideList: false})}
{data.length === 0 ? (
renderListEmptyContent()
Expand All @@ -391,7 +389,7 @@ function BaseSelectionList<TItem extends ListItem>({
showsVerticalScrollIndicator={showScrollIndicator}
onEndReached={onEndReached}
onEndReachedThreshold={onEndReachedThreshold}
style={listStyle as ViewStyle}
style={style?.listStyle as ViewStyle}
initialScrollIndex={initialFocusedIndex}
onScrollBeginDrag={onScrollBeginDrag}
ListHeaderComponent={
Expand Down
17 changes: 11 additions & 6 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ type SelectionListProps<TItem extends ListItem> = {
/** Array of selected item keys */
selectedItems?: readonly string[];

/** Styles to apply to the list */
listStyle?: StyleProp<ViewStyle>;
style?: {
/** Styles to apply to the list */
listStyle?: StyleProp<ViewStyle>;

/** Styles applied for the title of the list item */
listItemTitleStyles?: StyleProp<TextStyle>;
/** Styles applied for the title of the list item */
listItemTitleStyles?: StyleProp<TextStyle>;

/** Styles for the list item wrapper */
listItemWrapperStyle?: StyleProp<ViewStyle>;
/** Styles for the list item wrapper */
listItemWrapperStyle?: StyleProp<ViewStyle>;

/** Styles to apply to the list container */
containerStyle?: StyleProp<ViewStyle>;
};

/** Function that determines if an item is selected */
isSelected?: (item: TItem) => boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type {ValueOf} from 'type-fest';
import ConnectionLayout from '@components/ConnectionLayout';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import SelectionList from '@components/SelectionListWithSections';
import RadioListItem from '@components/SelectionListWithSections/RadioListItem';
import type {ListItem} from '@components/SelectionListWithSections/types';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/ListItem/RadioListItem';
import type {ListItem} from '@components/SelectionList/types';
import type {SelectorType} from '@components/SelectionScreen';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -40,7 +40,7 @@ function NetSuiteInvoiceItemPreferenceSelectPage({policy}: WithPolicyConnections

const selectedValue = Object.values(CONST.NETSUITE_INVOICE_ITEM_PREFERENCE).find((value) => value === config?.invoiceItemPreference) ?? CONST.NETSUITE_INVOICE_ITEM_PREFERENCE.CREATE;

const data: MenuListItem[] = Object.values(CONST.NETSUITE_INVOICE_ITEM_PREFERENCE).map((postingPreference) => ({
const options: MenuListItem[] = Object.values(CONST.NETSUITE_INVOICE_ITEM_PREFERENCE).map((postingPreference) => ({
value: postingPreference,
text: translate(`workspace.netsuite.invoiceItem.values.${postingPreference}.label`),
keyForList: postingPreference,
Expand Down Expand Up @@ -85,13 +85,13 @@ function NetSuiteInvoiceItemPreferenceSelectPage({policy}: WithPolicyConnections
contentContainerStyle={[styles.flexGrow1, styles.flexShrink1]}
>
<SelectionList
data={options}
onSelectRow={(selection: SelectorType) => selectInvoicePreference(selection as MenuListItem)}
sections={[{data}]}
ListItem={RadioListItem}
showScrollIndicator
shouldUpdateFocusedIndex
initiallyFocusedOptionKey={data.find((mode) => mode.isSelected)?.keyForList}
containerStyle={[styles.flexReset, styles.flexGrow1, styles.flexShrink1, styles.pb0]}
initiallyFocusedItemKey={options.find((mode) => mode.isSelected)?.keyForList}
style={{containerStyle: [styles.flexReset, styles.flexGrow1, styles.flexShrink1, styles.pb0]}}
/>
</OfflineWithFeedback>
{config?.invoiceItemPreference === CONST.NETSUITE_INVOICE_ITEM_PREFERENCE.SELECT && (
Expand Down
43 changes: 24 additions & 19 deletions src/pages/workspace/categories/CategoryDefaultTaxRatePage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, {useCallback, useMemo} from 'react';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionListWithSections';
import RadioListItem from '@components/SelectionListWithSections/RadioListItem';
import type {ListItem} from '@components/SelectionListWithSections/types';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/ListItem/RadioListItem';
import type {ListItem} from '@components/SelectionList/types';
import useLocalize from '@hooks/useLocalize';
import usePolicy from '@hooks/usePolicy';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -48,6 +48,23 @@ function CategoryDefaultTaxRatePage({
.sort((a, b) => localeCompare(a.text ?? a.keyForList ?? '', b.text ?? b.keyForList ?? ''));
}, [policy, selectedTaxRate, textForDefault, localeCompare]);

const handleSelectRow = useCallback(
(item: ListItem) => {
if (!item.keyForList) {
return;
}

if (item.keyForList === selectedTaxRate) {
Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(policyID, categoryName));
return;
}

setPolicyCategoryTax(policyID, categoryName, item.keyForList);
Navigation.setNavigationActionToMicrotaskQueue(() => Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(policyID, categoryName)));
},
[policyID, categoryName, selectedTaxRate],
);

return (
<AccessOrNotFoundWrapper
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.CONTROL]}
Expand All @@ -65,25 +82,13 @@ function CategoryDefaultTaxRatePage({
onBackButtonPress={() => Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(policyID, categoryName))}
/>
<SelectionList
sections={[{data: taxesList}]}
data={taxesList}
ListItem={RadioListItem}
onSelectRow={(item) => {
if (!item.keyForList) {
return;
}

if (item.keyForList === selectedTaxRate) {
Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(policyID, categoryName));
return;
}

setPolicyCategoryTax(policyID, categoryName, item.keyForList);
Navigation.setNavigationActionToMicrotaskQueue(() => Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(policyID, categoryName)));
}}
onSelectRow={handleSelectRow}
shouldSingleExecuteRowSelect
containerStyle={[styles.pt3]}
initiallyFocusedOptionKey={selectedTaxRate}
addBottomSafeAreaPadding
initiallyFocusedItemKey={selectedTaxRate}
style={{containerStyle: styles.pt3}}
/>
</ScreenWrapper>
</AccessOrNotFoundWrapper>
Expand Down
Loading