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
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
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