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
Next Next commit
wip
war-in committed Apr 23, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
kmbcook Kevin Cook
commit e3e9e7be96ab68fa80757efe4f975f9fffd085ae
126 changes: 78 additions & 48 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
@@ -2,10 +2,14 @@ import {useIsFocused} from '@react-navigation/native';
import {format} from 'date-fns';
import Str from 'expensify-common/lib/str';
import React, {useCallback, useEffect, useMemo, useReducer, useState} from 'react';
import {View} from 'react-native';
import {type SectionListData, View} from 'react-native';
import type {StyleProp, ViewStyle} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import SelectionList from '@components/SelectionList';
import InviteMemberListItem from '@components/SelectionList/InviteMemberListItem';
import RadioListItem from '@components/SelectionList/RadioListItem';
import TableListItem from '@components/SelectionList/TableListItem';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
@@ -21,6 +25,7 @@ import Log from '@libs/Log';
import * as MoneyRequestUtils from '@libs/MoneyRequestUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import {PayeePersonalDetails} from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import {isTaxTrackingEnabled} from '@libs/PolicyUtils';
import * as ReceiptUtils from '@libs/ReceiptUtils';
@@ -47,6 +52,7 @@ import OptionsSelector from './OptionsSelector';
import PDFThumbnail from './PDFThumbnail';
import ReceiptEmptyState from './ReceiptEmptyState';
import ReceiptImage from './ReceiptImage';
import {ListItem, type Section} from './SelectionList/types';
import SettlementButton from './SettlementButton';
import ShowMoreButton from './ShowMoreButton';
import Switch from './Switch';
@@ -173,6 +179,13 @@ type MoneyRequestConfirmationListProps = MoneyRequestConfirmationListOnyxProps &
action?: IOUAction;
};

type MemberSection = {
title: string | undefined;
shouldShow: boolean;
data: (PayeePersonalDetails | Participant | ReportUtils.OptionData)[];
isDisabled: boolean;
};

const getTaxAmount = (transaction: OnyxEntry<OnyxTypes.Transaction>, defaultTaxValue: string) => {
const percentage = (transaction?.taxRate ? transaction?.taxRate?.data?.value : defaultTaxValue) ?? '';
return TransactionUtils.calculateTaxAmount(percentage, transaction?.amount ?? 0);
@@ -219,6 +232,7 @@ function MoneyRequestConfirmationList({
lastSelectedDistanceRates,
action = CONST.IOU.ACTION.CREATE,
}: MoneyRequestConfirmationListProps) {
console.log('ttuaj');
const theme = useTheme();
const styles = useThemeStyles();
const {translate, toLocaleDigit} = useLocalize();
@@ -418,7 +432,7 @@ function MoneyRequestConfirmationList({
const canModifyParticipants = !isReadOnly && canModifyParticipantsProp && hasMultipleParticipants;
const shouldDisablePaidBySection = canModifyParticipants;
const optionSelectorSections = useMemo(() => {
const sections = [];
const sections: MemberSection[] = [];
const unselectedParticipants = selectedParticipantsProp.filter((participant) => !participant.selected);
if (hasMultipleParticipants) {
const formattedSelectedParticipants = getParticipantsWithAmount(selectedParticipants);
@@ -448,6 +462,7 @@ function MoneyRequestConfirmationList({
title: translate('moneyRequestConfirmationList.splitWith'),
data: formattedParticipantsList,
shouldShow: true,
isDisabled: false,
},
);
} else {
@@ -459,6 +474,7 @@ function MoneyRequestConfirmationList({
title: translate('common.to'),
data: formattedSelectedParticipants,
shouldShow: true,
isDisabled: false,
});
}
return sections;
@@ -951,53 +967,47 @@ function MoneyRequestConfirmationList({
const resolvedThumbnail = isLocalFile ? receiptThumbnail : tryResolveUrlFromApiRoot(receiptThumbnail ?? '');
const resolvedReceiptImage = isLocalFile ? receiptImage : tryResolveUrlFromApiRoot(receiptImage ?? '');

const receiptThumbnailContent = useMemo(
() =>
isLocalFile && Str.isPDF(receiptFilename) ? (
<PDFThumbnail
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
previewSourceURL={resolvedReceiptImage as string}
style={styles.moneyRequestImage}
// We don't support scaning password protected PDF receipt
enabled={!isAttachmentInvalid}
onPassword={() => setIsAttachmentInvalid(true)}
/>
) : (
<ReceiptImage
style={styles.moneyRequestImage}
isThumbnail={isThumbnail}
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
source={resolvedThumbnail || resolvedReceiptImage || ''}
// AuthToken is required when retrieving the image from the server
// but we don't need it to load the blob:// or file:// image when starting an expense/split
// So if we have a thumbnail, it means we're retrieving the image from the server
isAuthTokenRequired={!!receiptThumbnail}
fileExtension={fileExtension}
/>
),
[isLocalFile, receiptFilename, resolvedThumbnail, styles.moneyRequestImage, isAttachmentInvalid, isThumbnail, resolvedReceiptImage, receiptThumbnail, fileExtension],
);
const receiptThumbnailContent = useMemo(() => {
console.log('dupsko');

return isLocalFile && Str.isPDF(receiptFilename) ? (
<PDFThumbnail
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
previewSourceURL={resolvedReceiptImage as string}
style={styles.moneyRequestImage}
// We don't support scaning password protected PDF receipt
enabled={!isAttachmentInvalid}
onPassword={() => setIsAttachmentInvalid(true)}
/>
) : (
<ReceiptImage
style={styles.moneyRequestImage}
isThumbnail={isThumbnail}
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
source={resolvedThumbnail || resolvedReceiptImage || ''}
// AuthToken is required when retrieving the image from the server
// but we don't need it to load the blob:// or file:// image when starting an expense/split
// So if we have a thumbnail, it means we're retrieving the image from the server
isAuthTokenRequired={!!receiptThumbnail}
fileExtension={fileExtension}
/>
);
}, [isLocalFile, receiptFilename, resolvedThumbnail, styles.moneyRequestImage, isAttachmentInvalid, isThumbnail, resolvedReceiptImage, receiptThumbnail, fileExtension]);

console.log('uuu');
console.log(isAttachmentInvalid);
console.log(isDistanceRequest);
console.log(receiptImage);
console.log(receiptThumbnail);

return (
// @ts-expect-error This component is deprecated and will not be migrated to TypeScript (context: https://expensify.slack.com/archives/C01GTK53T8Q/p1709232289899589?thread_ts=1709156803.359359&cid=C01GTK53T8Q)
<OptionsSelector
sections={optionSelectorSections}
onSelectRow={canModifyParticipants ? selectParticipant : navigateToReportOrUserDetail}
onAddToSelection={selectParticipant}
onConfirmSelection={confirm}
selectedOptions={selectedOptions}
canSelectMultipleOptions={canModifyParticipants}
disableArrowKeysActions={!canModifyParticipants}
boldStyle
showTitleTooltip
shouldTextInputAppearBelowOptions
shouldShowTextInput={false}
shouldUseStyleForChildren={false}
optionHoveredStyle={canModifyParticipants ? styles.hoveredComponentBG : {}}
footerContent={footerContent}
listStyles={listStyles}
shouldAllowScrollingChildren
>
<View style={listStyles}>
<SelectionList
canSelectMultiple={canModifyParticipants}
sections={optionSelectorSections}
ListItem={InviteMemberListItem}
onSelectRow={selectParticipant}
/>
{isDistanceRequest && (
<View style={styles.confirmationListMapItem}>
<ConfirmedRoute transaction={transaction ?? ({} as OnyxTypes.Transaction)} />
@@ -1036,7 +1046,27 @@ function MoneyRequestConfirmationList({
confirmText={translate('common.close')}
shouldShowCancelButton={false}
/>
</OptionsSelector>
{footerContent}
</View>
// <OptionsSelector
// sections={optionSelectorSections}
// onSelectRow={canModifyParticipants ? selectParticipant : navigateToReportOrUserDetail}
// onAddToSelection={selectParticipant}
// onConfirmSelection={confirm}
// selectedOptions={selectedOptions}
// canSelectMultipleOptions={canModifyParticipants}
// disableArrowKeysActions={!canModifyParticipants}
// boldStyle
// showTitleTooltip
// shouldTextInputAppearBelowOptions
// shouldShowTextInput={false}
// shouldUseStyleForChildren={false}
// optionHoveredStyle={canModifyParticipants ? styles.hoveredComponentBG : {}}
// footerContent={!isEditingSplitBill && footerContent}
// listStyles={listStyles}
// shouldAllowScrollingChildren
// >
// </OptionsSelector>
);
}