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
4 changes: 4 additions & 0 deletions src/components/ButtonWithDropdownMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function ButtonWithDropdownMenu<IValueType>({ref, ...props}: ButtonWithDropdownM
shouldUseModalPaddingStyle = true,
shouldUseShortForm = false,
shouldUseOptionIcon = false,
shouldStayNormalOnDisable = false,
} = props;

const theme = useTheme();
Expand Down Expand Up @@ -169,6 +170,7 @@ function ButtonWithDropdownMenu<IValueType>({ref, ...props}: ButtonWithDropdownM
onPress={handlePress}
text={customText ?? selectedItem?.text ?? ''}
isDisabled={isDisabled || areAllOptionsDisabled}
shouldStayNormalOnDisable={shouldStayNormalOnDisable}
isLoading={isLoading}
shouldRemoveRightBorderRadius
style={isSplitButton ? [styles.flex1, styles.pr0] : {}}
Expand All @@ -192,6 +194,7 @@ function ButtonWithDropdownMenu<IValueType>({ref, ...props}: ButtonWithDropdownM
ref={dropdownAnchor}
success={success}
isDisabled={isDisabled}
shouldStayNormalOnDisable={shouldStayNormalOnDisable}
style={[styles.pl0]}
onPress={() => setIsMenuVisible(!isMenuVisible)}
shouldRemoveLeftBorderRadius
Expand Down Expand Up @@ -232,6 +235,7 @@ function ButtonWithDropdownMenu<IValueType>({ref, ...props}: ButtonWithDropdownM
ref={buttonRef}
pressOnEnter={pressOnEnter}
isDisabled={isDisabled || !!options.at(0)?.disabled}
shouldStayNormalOnDisable={shouldStayNormalOnDisable}
style={[styles.w100, style]}
disabledStyle={disabledStyle}
isLoading={isLoading}
Expand Down
3 changes: 3 additions & 0 deletions src/components/ButtonWithDropdownMenu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ type ButtonWithDropdownMenuProps<TValueType> = {
/** Should the confirmation button be disabled? */
isDisabled?: boolean;

/** Whether the button should stay visually normal even when disabled. */
shouldStayNormalOnDisable?: boolean;

/** Additional styles to add to the component */
style?: StyleProp<ViewStyle>;

Expand Down
22 changes: 16 additions & 6 deletions src/components/SelectionListWithSections/Search/ActionCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type ActionCellProps = {
hash?: number;
amount?: number;
extraSmall?: boolean;
shouldDisablePointerEvents?: boolean;
};

Comment thread
Julesssss marked this conversation as resolved.
function ActionCell({
Expand All @@ -65,6 +66,7 @@ function ActionCell({
hash,
amount,
extraSmall = false,
shouldDisablePointerEvents,
}: ActionCellProps) {
const {translate} = useLocalize();
const theme = useTheme();
Expand Down Expand Up @@ -94,7 +96,11 @@ function ActionCell({

if (!isChildListItem && ((parentAction !== CONST.SEARCH.ACTION_TYPES.PAID && action === CONST.SEARCH.ACTION_TYPES.PAID) || action === CONST.SEARCH.ACTION_TYPES.DONE)) {
return (
<View style={[StyleUtils.getHeight(variables.h20), styles.justifyContentCenter]}>
<View
style={[StyleUtils.getHeight(variables.h20), styles.justifyContentCenter, shouldDisablePointerEvents && styles.pointerEventsNone]}
accessible={!shouldDisablePointerEvents}
accessibilityState={{disabled: shouldDisablePointerEvents}}
>
<Badge
text={text}
icon={action === CONST.SEARCH.ACTION_TYPES.DONE ? Expensicons.Checkbox : Expensicons.Checkmark}
Expand Down Expand Up @@ -126,7 +132,9 @@ function ActionCell({
onPress={goToItem}
small={!extraSmall}
extraSmall={extraSmall}
style={[styles.w100]}
style={[styles.w100, shouldDisablePointerEvents && styles.pointerEventsNone]}
isDisabled={shouldDisablePointerEvents}
shouldStayNormalOnDisable={shouldDisablePointerEvents}
innerStyles={buttonInnerStyles}
link={isChildListItem}
shouldUseDefaultHover={!isChildListItem}
Expand All @@ -152,10 +160,11 @@ function ActionCell({
chatReportID={iouReport?.chatReportID}
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
onPress={(type, payAsBusiness, methodID, paymentMethod) => confirmPayment(type as ValueOf<typeof CONST.IOU.PAYMENT_TYPE>, payAsBusiness, methodID, paymentMethod)}
style={[styles.w100]}
style={[styles.w100, shouldDisablePointerEvents && styles.pointerEventsNone]}
wrapperStyle={[styles.w100]}
shouldShowPersonalBankAccountOption={!policyID && !iouReport?.policyID}
isDisabled={isOffline}
isDisabled={isOffline || shouldDisablePointerEvents}
shouldStayNormalOnDisable={shouldDisablePointerEvents}
isLoading={isLoading}
onlyShowPayElsewhere={shouldOnlyShowElsewhere}
/>
Expand All @@ -169,10 +178,11 @@ function ActionCell({
onPress={goToItem}
small={!extraSmall}
extraSmall={extraSmall}
style={[styles.w100]}
style={[styles.w100, shouldDisablePointerEvents && styles.pointerEventsNone]}
isLoading={isLoading}
success
isDisabled={isOffline}
isDisabled={isOffline || shouldDisablePointerEvents}
shouldStayNormalOnDisable={shouldDisablePointerEvents}
isNested
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ function ReportListItemHeader<TItem extends ListItem>({
currentSearchHash,
reportItem,
() => onSelectRow(reportItem as unknown as TItem),
shouldUseNarrowLayout && !!canSelectMultiple,
snapshotReport,
snapshotPolicy,
lastPaymentMethod,
Expand All @@ -247,6 +246,7 @@ function ReportListItemHeader<TItem extends ListItem>({
handleActionButtonPress={handleOnButtonPress}
shouldShowUserInfo={showUserInfo}
containerStyles={[styles.pr3, styles.mb2]}
isInMobileSelectionMode={shouldUseNarrowLayout && !!canSelectMultiple}
/>
<HeaderFirstRow
report={reportItem}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,13 @@ function TransactionListItem<TItem extends ListItem>({
currentSearchHash,
transactionItem,
() => onSelectRow(item, transactionPreviewData),
shouldUseNarrowLayout && !!canSelectMultiple,
snapshotReport,
snapshotPolicy,
lastPaymentMethod,
currentSearchKey,
onDEWModalOpen,
);
}, [
currentSearchHash,
transactionItem,
transactionPreviewData,
shouldUseNarrowLayout,
canSelectMultiple,
snapshotReport,
snapshotPolicy,
lastPaymentMethod,
currentSearchKey,
onSelectRow,
item,
onDEWModalOpen,
]);
}, [currentSearchHash, transactionItem, transactionPreviewData, snapshotReport, snapshotPolicy, lastPaymentMethod, currentSearchKey, onSelectRow, item, onDEWModalOpen]);

const handleCheckboxPress = useCallback(() => {
onCheckboxPress?.(item);
Expand Down Expand Up @@ -179,6 +165,7 @@ function TransactionListItem<TItem extends ListItem>({
item={transactionItem}
handleActionButtonPress={handleActionButtonPress}
shouldShowUserInfo={!!transactionItem?.from}
isInMobileSelectionMode={shouldUseNarrowLayout && !!canSelectMultiple}
/>
)}
<TransactionItemRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ function UserInfoAndActionButtonRow({
handleActionButtonPress,
shouldShowUserInfo,
containerStyles,
isInMobileSelectionMode,
}: {
item: TransactionReportGroupListItemType | TransactionListItemType;
handleActionButtonPress: () => void;
shouldShowUserInfo: boolean;
containerStyles?: StyleProp<ViewStyle>;
isInMobileSelectionMode: boolean;
}) {
const styles = useThemeStyles();
const {isLargeScreenWidth} = useResponsiveLayout();
Expand All @@ -39,6 +41,7 @@ function UserInfoAndActionButtonRow({
const shouldShowToRecipient = hasFromSender && hasToRecipient && !!item?.to?.accountID && !!isCorrectSearchUserName(participantToDisplayName);

const snapshotReport = useMemo(() => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return (snapshot?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionItem.reportID}`] ?? {}) as SearchReport;
}, [snapshot, transactionItem.reportID]);

Expand Down Expand Up @@ -80,6 +83,7 @@ function UserInfoAndActionButtonRow({
hash={item.hash}
amount={(item as TransactionListItemType)?.amount ?? (item as TransactionReportGroupListItemType)?.total}
extraSmall={!isLargeScreenWidth}
shouldDisablePointerEvents={isInMobileSelectionMode}
/>
</View>
</View>
Expand Down
2 changes: 2 additions & 0 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function SettlementButton({
enablePaymentsRoute,
iouReport,
isDisabled = false,
shouldStayNormalOnDisable = false,
isLoading = false,
formattedAmount = '',
onPress,
Expand Down Expand Up @@ -564,6 +565,7 @@ function SettlementButton({
menuHeaderText={isInvoiceReport ? translate('workspace.invoices.paymentMethods.chooseInvoiceMethod') : undefined}
isSplitButton={shouldUseSplitButton}
isDisabled={isDisabled}
shouldStayNormalOnDisable={shouldStayNormalOnDisable}
isLoading={isLoading}
defaultSelectedIndex={defaultSelectedIndex !== -1 ? defaultSelectedIndex : 0}
onPress={(event, iouPaymentType) => handlePaymentSelection(event, iouPaymentType, triggerKYCFlow)}
Expand Down
3 changes: 3 additions & 0 deletions src/components/SettlementButton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ type SettlementButtonProps = {
/** Whether the button should be disabled */
isDisabled?: boolean;

/** Whether the button should stay visually normal even when disabled. */
shouldStayNormalOnDisable?: boolean;

/** Whether we should show a loading state for the main button */
isLoading?: boolean;

Expand Down
3 changes: 1 addition & 2 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ function handleActionButtonPress(
hash: number,
item: TransactionListItemType | TransactionReportGroupListItemType,
goToItem: () => void,
isInMobileSelectionMode: boolean,
// eslint-disable-next-line @typescript-eslint/no-deprecated
snapshotReport: SearchReport,
snapshotPolicy: Policy,
Expand All @@ -84,7 +83,7 @@ function handleActionButtonPress(
const allReportTransactions = (isTransactionGroupListItemType(item) ? item.transactions : [item]) as SearchTransaction[];
const hasHeldExpense = hasHeldExpenses('', allReportTransactions);

if (hasHeldExpense || isInMobileSelectionMode) {
if (hasHeldExpense) {
goToItem();
return;
}
Expand Down
11 changes: 2 additions & 9 deletions tests/unit/Search/handleActionButtonPressTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,14 @@ describe('handleActionButtonPress', () => {
test('Should navigate to item when report has one transaction on hold', () => {
const goToItem = jest.fn(() => {});
// @ts-expect-error: Allow partial record in snapshot update for testing
handleActionButtonPress(searchHash, mockReportItemWithHold, goToItem, false, snapshotReport, snapshotPolicy, mockLastPaymentMethod);
handleActionButtonPress(searchHash, mockReportItemWithHold, goToItem, snapshotReport, snapshotPolicy, mockLastPaymentMethod);
expect(goToItem).toHaveBeenCalledTimes(1);
});

test('Should not navigate to item when the hold is removed', () => {
const goToItem = jest.fn(() => {});
// @ts-expect-error: Allow partial record in snapshot update for testing
handleActionButtonPress(searchHash, updatedMockReportItem, goToItem, false, snapshotReport, snapshotPolicy, mockLastPaymentMethod);
handleActionButtonPress(searchHash, updatedMockReportItem, goToItem, snapshotReport, snapshotPolicy, mockLastPaymentMethod);
expect(goToItem).toHaveBeenCalledTimes(0);
});

test('Should run goToItem callback when user is in mobile selection mode', () => {
const goToItem = jest.fn(() => {});
// @ts-expect-error: Allow partial record in snapshot update for testing
handleActionButtonPress(searchHash, updatedMockReportItem, goToItem, true, snapshotReport, snapshotPolicy, mockLastPaymentMethod);
expect(goToItem).toHaveBeenCalledTimes(1);
});
Comment thread
Julesssss marked this conversation as resolved.
});
Loading