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
2 changes: 1 addition & 1 deletion src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function BaseSelectionList<TItem extends ListItem>({
const debouncedScrollToIndex = useDebounce(scrollToIndex, CONST.TIMING.LIST_SCROLLING_DEBOUNCE_TIME, {leading: true, trailing: true});

const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({
initialFocusedIndex: data.findIndex((item) => item.keyForList === initiallyFocusedItemKey),
initialFocusedIndex,
maxIndex: data.length - 1,
disabledIndexes: dataDetails.disabledArrowKeyIndexes,
isActive: isFocused,
Expand Down
14 changes: 7 additions & 7 deletions src/pages/iou/request/step/IOURequestStepDistanceRate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import SelectionList from '@components/SelectionListWithSections';
import RadioListItem from '@components/SelectionListWithSections/RadioListItem';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/ListItem/RadioListItem';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -63,7 +63,7 @@ function IOURequestStepDistanceRate({
Navigation.goBack(backTo);
};

const sections = sortedRates.map((rate) => {
const options = sortedRates.map((rate) => {
const unit = transaction?.comment?.customUnit?.customUnitRateID === rate.customUnitRateID ? DistanceRequestUtils.getDistanceUnit(transaction, rate) : rate.unit;
const isSelected = currentRateID
? currentRateID === rate.customUnitRateID
Expand All @@ -72,7 +72,7 @@ function IOURequestStepDistanceRate({
return {
text: rate.name ?? rateForDisplay,
alternateText: rate.name ? rateForDisplay : '',
keyForList: rate.customUnitRateID,
keyForList: rate.customUnitRateID ?? rateForDisplay,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

May I ask why is this fallback needed?

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.

Before keyForList wasn't required for a list item, but it makes much more sense if keyForList is required so it is in the new list item, so I had to add fallback as rate.customUnitRateID can be undefined.

value: rate.customUnitRateID,
isDisabled: !rate.enabled,
isSelected,
Expand All @@ -81,7 +81,7 @@ function IOURequestStepDistanceRate({
// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundPage = useShowNotFoundPageInIOUStep(action, iouType, reportActionID, report, transaction);

const initiallyFocusedOption = sections.find((item) => item.isSelected)?.keyForList;
const initiallyFocusedOption = options.find((item) => item.isSelected)?.keyForList;

function selectDistanceRate(customUnitRateID: string) {
let taxAmount;
Expand Down Expand Up @@ -119,11 +119,11 @@ function IOURequestStepDistanceRate({
<Text style={[styles.mh5, styles.mv4]}>{translate('iou.chooseARate')}</Text>

<SelectionList
sections={[{data: sections}]}
data={options}
ListItem={RadioListItem}
onSelectRow={({value}) => selectDistanceRate(value ?? '')}
shouldSingleExecuteRowSelect
initiallyFocusedOptionKey={initiallyFocusedOption}
initiallyFocusedItemKey={initiallyFocusedOption}
/>
</StepScreenWrapper>
);
Expand Down
Loading