Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Remove 'OptionsSelector' component #41077

Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e3e9e7b
wip
war-in Apr 23, 2024
0ab6923
wip....
war-in Apr 23, 2024
3f1c13c
show tick next to payee
war-in Apr 23, 2024
7cd7718
show amount
war-in Apr 26, 2024
0eff692
Merge branch 'refs/heads/main' into war-in/options-selector-removal
war-in Apr 26, 2024
b05192b
align items
war-in Apr 26, 2024
1e65a85
remove optionsSelector
war-in Apr 26, 2024
affc169
fix typecheck
war-in Apr 26, 2024
1ad6d78
styling
war-in Apr 26, 2024
3db3fb4
add correct styling
war-in Apr 26, 2024
f5148ed
use ScrollView
war-in Apr 29, 2024
115be37
add second ScrollView to get rid of error
war-in Apr 29, 2024
01840ca
styling
war-in Apr 29, 2024
04b9907
use SelectionList as main component
war-in Apr 29, 2024
dadec41
Merge branch 'refs/heads/main' into war-in/options-selector-removal
war-in Apr 29, 2024
b34b47e
fix lint
war-in Apr 29, 2024
08b162e
move children to `listFooterContent`
war-in Apr 29, 2024
1259b8d
Merge branch 'refs/heads/main' into war-in/options-selector-removal
war-in Apr 29, 2024
3eb6751
Merge branch 'refs/heads/main' into war-in/options-selector-removal
war-in Apr 30, 2024
eb8d61e
prettier
war-in Apr 30, 2024
830d71c
Merge branch 'refs/heads/main' into war-in/options-selector-removal
war-in May 6, 2024
48d9fdd
review suggestions
war-in May 7, 2024
3d36eb2
add styles and do not show ✅
war-in May 7, 2024
838ebdf
Merge branch 'refs/heads/main' into war-in/options-selector-removal
war-in May 7, 2024
6adda9c
wip
war-in May 7, 2024
fbb7b60
almost done (there are still some bugs)
war-in May 7, 2024
f2ba6c4
fix errors
war-in May 10, 2024
0ad9d3a
fix typecheck
war-in May 10, 2024
d673fc0
Merge branch 'refs/heads/main' into war-in/options-selector-removal
war-in May 13, 2024
492ea96
Merge branch 'refs/heads/main' into war-in/options-selector-removal
war-in May 13, 2024
c274163
remove ArrowKeyFocusManager.js
war-in May 13, 2024
d9a5d2f
show non-editable amount when needed
war-in May 13, 2024
de9138d
Merge branch 'refs/heads/main' into war-in/options-selector-removal
war-in May 13, 2024
dcc0582
Merge branch 'refs/heads/main' into war-in/options-selector-removal
war-in May 14, 2024
929d7f1
fix padding
war-in May 14, 2024
720900d
Merge branch 'refs/heads/main' into war-in/options-selector-removal
war-in May 14, 2024
8cc152c
padding -> margin
war-in May 14, 2024
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
Prev Previous commit
Next Next commit
Merge branch 'refs/heads/main' into war-in/options-selector-removal
# Conflicts:
#	src/components/MoneyRequestConfirmationList.tsx
war-in committed May 13, 2024
commit de9138d691ae654b938482ae7cec0cb8a51d5d75
198 changes: 51 additions & 147 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import Str from 'expensify-common/lib/str';
import React, {useCallback, useEffect, useMemo, useReducer, useState} from 'react';
import type {TextStyle} from 'react-native';
import {View} from 'react-native';
import type {TextStyle} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
@@ -50,13 +49,12 @@ import FormHelpMessage from './FormHelpMessage';
import MenuItem from './MenuItem';
import MenuItemWithTopDescription from './MenuItemWithTopDescription';
import MoneyRequestAmountInput from './MoneyRequestAmountInput';
import type {MoneyRequestAmountInputProps} from './MoneyRequestAmountInput';
import PDFThumbnail from './PDFThumbnail';
import {PressableWithFeedback} from './Pressable';
import ReceiptEmptyState from './ReceiptEmptyState';
import ReceiptImage from './ReceiptImage';
import SelectionList from './SelectionList';
import type {ListItem, SectionListDataType, SectionWithIndexOffset} from './SelectionList/types';
import type {SectionListDataType} from './SelectionList/types';
import UserListItem from './SelectionList/UserListItem';
import SettlementButton from './SettlementButton';
import ShowMoreButton from './ShowMoreButton';
@@ -178,12 +176,7 @@ type MoneyRequestConfirmationListProps = MoneyRequestConfirmationListOnyxProps &
action?: IOUAction;
};

type IouListItem = {
descriptiveText?: string;
shouldShowAmountInput?: boolean;
amountInputProps?: MoneyRequestAmountInputProps;
tabIndex?: number;
} & ListItem;
type MoneyRequestConfirmationListItem = Participant | ReportUtils.OptionData;

const getTaxAmount = (transaction: OnyxEntry<OnyxTypes.Transaction>, policy: OnyxEntry<OnyxTypes.Policy>) => {
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction) ?? '';
@@ -466,7 +459,7 @@ function MoneyRequestConfirmationList({
const payeePersonalDetails = useMemo(() => payeePersonalDetailsProp ?? currentUserPersonalDetails, [payeePersonalDetailsProp, currentUserPersonalDetails]);
const shouldShowReadOnlySplits = useMemo(() => isPolicyExpenseChat || isReadOnly || isScanRequest, [isPolicyExpenseChat, isReadOnly, isScanRequest]);

const splitParticipants: IouListItem[] | undefined = useMemo(() => {
const splitParticipants = useMemo(() => {
if (!isTypeSplit) {
return [];
}
@@ -501,16 +494,26 @@ function MoneyRequestConfirmationList({
return [payeeOption, ...selectedParticipants].map((participantOption: Participant) => ({
...participantOption,
tabIndex: -1,
shouldShowAmountInput: true,
amountInputProps: {
amount: transaction?.splitShares?.[participantOption.accountID ?? 0]?.amount,
currency: iouCurrencyCode,
prefixCharacter: currencySymbol,
containerStyle: [amountWidth],
inputStyle: [amountWidth as TextStyle],
maxLength: formattedTotalAmount.length,
onAmountChange: (value: string) => onSplitShareChange(participantOption.accountID ?? 0, Number(value)),
},
isSelected: false,
rightElement: (
<MoneyRequestAmountInput
amount={transaction?.splitShares?.[participantOption.accountID ?? 0]?.amount}
currency={iouCurrencyCode}
prefixCharacter={currencySymbol}
disableKeyboard={false}
isCurrencyPressable={false}
hideFocusedState={false}
hideCurrencySymbol
formatAmountOnBlur
prefixContainerStyle={[styles.pv0]}
inputStyle={
[styles.optionRowAmountInput, StyleUtils.getPaddingLeft(StyleUtils.getCharacterPadding(currencySymbol ?? '') + styles.pl1.paddingLeft), amountWidth] as TextStyle[]
}
containerStyle={[styles.textInputContainer]}
onAmountChange={(value: string) => onSplitShareChange(participantOption.accountID ?? 0, Number(value))}
maxLength={formattedTotalAmount.length}
/>
),
}));
}, [
isTypeSplit,
@@ -540,13 +543,15 @@ function MoneyRequestConfirmationList({
return Object.keys(transaction.splitShares).some((key) => transaction.splitShares?.[Number(key) ?? -1]?.isModified);
}, [transaction?.splitShares]);

const SplitAmountSectionHeader = useCallback(
(sectionWithIndex: {section: SectionWithIndexOffset<IouListItem>}) => (
<View style={[styles.optionsListSectionHeader, styles.flexRow, styles.justifyContentBetween]}>
<Text style={[styles.ph5, styles.textLabelSupporting]}>{sectionWithIndex.section.title}</Text>
const getSplitSectionHeader = useCallback(
() => (
<View style={[styles.mt2, styles.mb1, styles.flexRow, styles.justifyContentBetween]}>
<Text style={[styles.ph5, styles.textLabelSupporting]}>{translate('moneyRequestConfirmationList.splitAmounts')}</Text>
{!shouldShowReadOnlySplits && isSplitModified && (
<PressableWithFeedback
onPress={() => IOU.resetSplitShares(transaction)}
onPress={() => {
IOU.resetSplitShares(transaction);
}}
accessibilityLabel={CONST.ROLE.BUTTON}
role={CONST.ROLE.BUTTON}
shouldUseAutoHitSlop
@@ -562,7 +567,8 @@ function MoneyRequestConfirmationList({
styles.flexRow,
styles.justifyContentBetween,
styles.link,
styles.optionsListSectionHeader,
styles.mb1,
styles.mt2,
styles.ph5,
styles.pr5,
styles.textLabelSupporting,
@@ -571,8 +577,8 @@ function MoneyRequestConfirmationList({
],
);

const selectionListSections = useMemo(() => {
const sections: Array<SectionListDataType<IouListItem>> = [];
const sections = useMemo(() => {
const options: Array<SectionListDataType<MoneyRequestConfirmationListItem>> = [];
if (isTypeSplit) {
options.push(
...[
@@ -582,38 +588,8 @@ function MoneyRequestConfirmationList({
shouldShow: true,
},
{
title: translate('moneyRequestConfirmationList.splitAmounts'),
CustomSectionHeader: SplitAmountSectionHeader,
data:
splitParticipants?.map((participant) => ({
...participant,
rightElement:
participant.shouldShowAmountInput && participant.amountInputProps ? (
<MoneyRequestAmountInput
amount={participant.amountInputProps.amount}
currency={participant.amountInputProps.currency}
prefixCharacter={participant.amountInputProps.prefixCharacter}
disableKeyboard={false}
isCurrencyPressable={false}
hideFocusedState={false}
hideCurrencySymbol
formatAmountOnBlur
prefixContainerStyle={[styles.pv0]}
containerStyle={[styles.textInputContainer]}
inputStyle={[
styles.optionRowAmountInput,
StyleUtils.getPaddingLeft(
StyleUtils.getCharacterPadding(participant.amountInputProps.prefixCharacter ?? '') + styles.pl1.paddingLeft,
) as TextStyle,
participant.amountInputProps.inputStyle,
]}
onAmountChange={participant.amountInputProps.onAmountChange}
maxLength={participant.amountInputProps.maxLength}
/>
) : (
<Text style={[styles.textLabel]}>{participant.descriptiveText}</Text>
),
})) ?? [],
CustomSectionHeader: getSplitSectionHeader,
data: splitParticipants,
shouldShow: true,
},
],
@@ -631,21 +607,9 @@ function MoneyRequestConfirmationList({
shouldShow: true,
});
}
return sections;
}, [
selectedParticipants,
isTypeSplit,
translate,
splitParticipants,
payeePersonalDetails,
StyleUtils,
styles.optionRowAmountInput,
styles.pl1.paddingLeft,
styles.pv0,
SplitAmountSectionHeader,
styles.textInputContainer,
styles.textLabel,
]);

return options;
}, [isTypeSplit, translate, payeePersonalDetails, getSplitSectionHeader, splitParticipants, selectedParticipants]);

useEffect(() => {
if (!isDistanceRequest || isMovingTransactionFromTrackExpense) {
@@ -704,14 +668,19 @@ function MoneyRequestConfirmationList({
}
// Keep 'transaction' out to ensure that we autoselect the option only once
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [policyTagLists, policyTags, canUseViolations]);
}, [policyTagLists, policyTags]);

/**
* Navigate to report details or profile of selected user
*/
const navigateToReportOrUserDetail = (option: IouListItem) => {
const navigateToReportOrUserDetail = (option: MoneyRequestConfirmationListItem) => {
const activeRoute = Navigation.getActiveRouteWithoutParams();

if (option.isSelfDM) {
Navigation.navigate(ROUTES.PROFILE.getRoute(currentUserPersonalDetails.accountID, activeRoute));
return;
}

if (option.accountID) {
Navigation.navigate(ROUTES.PROFILE.getRoute(option.accountID, activeRoute));
} else if (option.reportID) {
@@ -1255,79 +1224,14 @@ function MoneyRequestConfirmationList({
);

return (
<SelectionList
sections={selectionListSections}
<SelectionList<MoneyRequestConfirmationListItem>
sections={sections}
ListItem={UserListItem}
onSelectRow={navigateToReportOrUserDetail}
shouldShowTooltips
sectionTitleStyles={styles.sidebarLinkTextBold}
showScrollIndicator
canSelectMultiple={false}
shouldPreventDefaultFocusOnSelectRow
footerContent={footerContent}
rightHandSideComponent={<View />}
listFooterContent={
<>
{isDistanceRequest && (
<View style={styles.confirmationListMapItem}>
<ConfirmedRoute transaction={transaction ?? ({} as OnyxTypes.Transaction)} />
</View>
)}
{isTypeInvoice && (
<MenuItem
key={translate('workspace.invoices.sendFrom')}
shouldShowRightIcon={!isReadOnly && canUpdateSenderWorkspace}
title={senderWorkspace?.name}
icon={senderWorkspace?.avatarURL ? senderWorkspace?.avatarURL : getDefaultWorkspaceAvatar(senderWorkspace?.name)}
iconType={CONST.ICON_TYPE_WORKSPACE}
description={translate('workspace.common.workspace')}
label={translate('workspace.invoices.sendFrom')}
isLabelHoverable={false}
interactive={!isReadOnly && canUpdateSenderWorkspace}
onPress={() => {
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_SEND_FROM.getRoute(iouType, transaction?.transactionID ?? '', reportID, Navigation.getActiveRouteWithoutParams()),
);
}}
style={styles.moneyRequestMenuItem}
labelStyle={styles.mt2}
titleStyle={styles.flex1}
disabled={didConfirm || !canUpdateSenderWorkspace}
/>
)}
{!isDistanceRequest &&
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
(receiptImage || receiptThumbnail
? receiptThumbnailContent
: // The empty receipt component should only show for IOU Requests of a paid policy ("Team" or "Corporate")
PolicyUtils.isPaidGroupPolicy(policy) &&
!isDistanceRequest &&
iouType === CONST.IOU.TYPE.SUBMIT && (
<ReceiptEmptyState
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(CONST.IOU.ACTION.CREATE, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()),
)
}
/>
))}
{primaryFields}
{!shouldShowAllFields && (
<ShowMoreButton
containerStyle={[styles.mt1, styles.mb2]}
onPress={toggleShouldExpandFields}
/>
)}
{shouldShowAllFields && supplementaryFields}
<ConfirmModal
title={translate('attachmentPicker.wrongFileType')}
onConfirm={navigateBack}
onCancel={navigateBack}
isVisible={isAttachmentInvalid}
prompt={translate('attachmentPicker.protectedPDFNotSupported')}
confirmText={translate('common.close')}
shouldShowCancelButton={false}
/>
</>
}
listFooterContent={listFooterContent}
/>
);
}
You are viewing a condensed version of this merge commit. You can view the full changes here.