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: 0 additions & 4 deletions config/oxlint/oxlint.seatbelt.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@
"../../src/components/MoneyRequestConfirmationList/hooks/useSplitParticipants.tsx" "@typescript-eslint/no-deprecated/MoneyRequestAmountInput" 1
"../../src/components/MoneyRequestConfirmationList/hooks/useSplitParticipants.tsx" "no-restricted-imports" 1
"../../src/components/MoneyRequestConfirmationList/hooks/useTransactionReportForConfirmation.ts" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../src/components/MoneyRequestConfirmationList/sections/AmountField.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1
"../../src/components/MoneyRequestConfirmationList/sections/AmountField.tsx" "@typescript-eslint/no-deprecated/NumberWithSymbolForm" 1
"../../src/components/MoneyRequestConfirmationList/sections/AmountField.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../src/components/MoneyRequestConfirmationList/sections/AmountField.tsx" "no-restricted-imports" 1
Expand Down Expand Up @@ -305,7 +304,6 @@
"../../src/components/ProductMarketingWindow/ProductMarketingWindowManager.tsx" "rulesdir/no-onyx-loading-status" 2
"../../src/components/ProductTrainingContext/index.tsx" "rulesdir/no-onyx-loading-status" 4
"../../src/components/PromotedActionsBar.tsx" "no-restricted-imports" 1
"../../src/components/PushRowWithModal/index.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1
"../../src/components/PushRowWithModal/PushRowModal.tsx" "no-restricted-imports" 1
"../../src/components/RadioButtonWithLabel.tsx" "no-restricted-syntax" 1
"../../src/components/Reactions/AddReactionBubble.tsx" "react-hooks/refs" 1
Expand Down Expand Up @@ -417,7 +415,6 @@
"../../src/components/StatePicker/index.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../src/components/StatePicker/StateSelectorModal.tsx" "no-restricted-imports" 1
"../../src/components/SubStepForms/AddressStep.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3
"../../src/components/SubStepForms/ConfirmationStep.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1
"../../src/components/SubStepForms/CountryFullStep.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../src/components/SubStepForms/DateOfBirthStep.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2
"../../src/components/SubStepForms/DateOfBirthStep.tsx" "react-hooks/purity" 2
Expand Down Expand Up @@ -2227,7 +2224,6 @@
"../../tests/ui/NumberWithSymbolFormWithoutTouchScreenTest.tsx" "no-restricted-imports" 1
"../../tests/ui/ProfilePageTest.tsx" "@typescript-eslint/no-unnecessary-type-assertion" 5
"../../tests/ui/PublicProfilePageTest.tsx" "@typescript-eslint/no-unnecessary-type-assertion" 4
"../../tests/ui/PushRowWithModalTest.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1
"../../tests/ui/RecentlyAddedSectionTest.tsx" "@typescript-eslint/no-unnecessary-type-assertion" 1
"../../tests/ui/ReportActionItemTest.tsx" "@typescript-eslint/no-unnecessary-type-assertion" 2
"../../tests/ui/ReportActionItemTest.tsx" "react-hooks/globals" 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import MenuItem from '@components/MenuItem';
import {useConfirmationFields} from '@components/MoneyRequestConfirmationFields/context';
import NumberWithSymbolForm from '@components/NumberWithSymbolForm';
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
Expand Down Expand Up @@ -29,6 +29,7 @@ import {calculateTaxAmount, getTaxCode, getTaxValue, hasAnyManuallyEnteredScanFi
import IOURequestStepCurrencyModal from '@pages/iou/request/step/IOURequestStepCurrencyModal';

import {resetSplitShares, setDraftSplitTransaction, setSplitShares} from '@userActions/IOU/Split';
import {callIfAuthenticated} from '@userActions/Session';

import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
Expand All @@ -40,6 +41,7 @@ import type * as OnyxTypes from '@src/types/onyx';
import type {OnyxEntry} from 'react-native-onyx';

import {useIsFocused, useNavigation} from '@react-navigation/native';
import {authTokenTypeSelector} from '@selectors/Session';
import React, {useEffect, useRef, useState} from 'react';
import {View} from 'react-native';

Expand Down Expand Up @@ -90,6 +92,7 @@ function AmountField({
const {translate, preferredLocale} = useLocalize();
const {getCurrencyDecimals, getCurrencySymbol} = useCurrencyListActions();
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector});
const {splitDraftTransaction, baseTransaction} = useSplitDraftBaseTransaction(transactionID);
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const amountInputRef = useRef<BaseTextInputRef | null>(null);
Expand Down Expand Up @@ -413,23 +416,35 @@ function AmountField({
onPress={openAmountPage}
isDisabled={didConfirm}
isInteractive={canOpenAmountPage}
errorText={shouldDisplayFieldError && amountIsMissing ? translate('common.error.enterAmount') : ''}
errorText={shouldShowAmountMissingError ? translate('common.error.enterAmount') : ''}
sentryLabel={CONST.SENTRY_LABEL.REQUEST_CONFIRMATION_LIST.AMOUNT_FIELD}
/>
) : (
<MenuItemWithTopDescription
shouldShowRightIcon={canOpenAmountPage}
title={formattedAmount}
description={translate('iou.amount')}
interactive={canOpenAmountPage}
onPress={openAmountPage}
<MenuItem.Root
onPress={canOpenAmountPage ? callIfAuthenticated(openAmountPage, session) : undefined}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.moneyRequestConfirmationAmount}
disabled={didConfirm}
brickRoadIndicator={shouldDisplayFieldError && amountIsMissing ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
errorText={shouldDisplayFieldError && amountIsMissing ? translate('common.error.enterAmount') : ''}
isDisabled={didConfirm}
sentryLabel={CONST.SENTRY_LABEL.REQUEST_CONFIRMATION_LIST.AMOUNT_FIELD}
/>
>
<MenuItem.Row>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@MelvinBot can't we simplify with <MenuItemField.Row?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Not without losing the amount’s custom typography. MenuItemField.Row creates its value internally without a style override, while this amount row needs moneyRequestConfirmationAmount.

The error indicator and chevron would work as children; typography is the blocker. I left the explicit composition unchanged to preserve the appearance without expanding the shared API.


view run

<MenuItem.Content>
<MenuItem.FieldName>{translate('iou.amount')}</MenuItem.FieldName>
<MenuItem.FieldValue style={styles.moneyRequestConfirmationAmount}>{formattedAmount}</MenuItem.FieldValue>
</MenuItem.Content>
{(canOpenAmountPage || shouldShowAmountMissingError) && (
<MenuItem.Trailing>
{shouldShowAmountMissingError && <MenuItem.BrickRoadIndicator status={CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR} />}
{canOpenAmountPage && <MenuItem.Chevron />}
</MenuItem.Trailing>
)}
</MenuItem.Row>
{shouldShowAmountMissingError && (
<MenuItem.HelpText
message={translate('common.error.enterAmount')}
isError
/>
)}
</MenuItem.Root>
)}
</View>
{/* The push row carries its own 20px of horizontal padding, so the button is inset to the 16px
Expand Down
46 changes: 31 additions & 15 deletions src/components/PushRowWithModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import MenuItem from '@components/MenuItem';
import MenuItemField from '@components/MenuItem/presets/MenuItemField';

import useOnyx from '@hooks/useOnyx';

import toggleArrayItem from '@libs/toggleArrayItem';

import {callIfAuthenticated} from '@userActions/Session';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import KeyboardUtils from '@src/utils/keyboard';

import type {StyleProp, ViewStyle} from 'react-native';

import {authTokenTypeSelector} from '@selectors/Session';
import React, {useRef, useState} from 'react';

import PushRowModal from './PushRowModal';
Expand Down Expand Up @@ -65,6 +72,7 @@ function PushRowWithModal(props: PushRowWithModalProps) {
const [isModalVisible, setIsModalVisible] = useState(false);
const [pendingSelection, setPendingSelection] = useState<string[]>([]);
const shouldBlurOnCloseRef = useRef(true);
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector});

let selection: string[] = [];
if (props.canSelectMultiple) {
Expand Down Expand Up @@ -111,21 +119,29 @@ function PushRowWithModal(props: PushRowWithModalProps) {

return (
<>
<MenuItemWithTopDescription
description={description}
title={selection
.map((key) => optionsList[key])
.filter(Boolean)
.join(', ')}
shouldShowRightIcon={shouldAllowChange}
onPress={handleModalOpen}
wrapperStyle={wrapperStyles}
interactive={shouldAllowChange}
disabled={disabled}
<MenuItem.Root
onPress={shouldAllowChange ? callIfAuthenticated(handleModalOpen, session) : undefined}
style={wrapperStyles}
isDisabled={disabled}
sentryLabel={CONST.SENTRY_LABEL.PUSH_ROW_WITH_MODAL.OPEN}
brickRoadIndicator={errorText ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
errorText={errorText}
/>
>
<MenuItemField.Row
name={description}
value={selection
.map((key) => optionsList[key])
.filter(Boolean)
.join(', ')}
>
{!!errorText && <MenuItem.BrickRoadIndicator status={CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR} />}
{shouldAllowChange && <MenuItem.Chevron />}
</MenuItemField.Row>
{!!errorText && (
<MenuItem.HelpText
message={errorText}
isError
/>
)}
</MenuItem.Root>
<PushRowModal
isVisible={isModalVisible}
canSelectMultiple={!!props.canSelectMultiple}
Expand Down
41 changes: 28 additions & 13 deletions src/components/SubStepForms/ConfirmationStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@ import Button from '@components/Button';
import ButtonDisabledWhenOffline from '@components/Button/composed/ButtonDisabledWhenOffline';
import DotIndicatorMessage from '@components/DotIndicatorMessage';
import FormAlertWrapper from '@components/FormAlertWrapper';
import MenuItem from '@components/MenuItem';
import MenuItemAvatarNavigation from '@components/MenuItem/presets/MenuItemAvatarNavigation';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import MenuItemField from '@components/MenuItem/presets/MenuItemField';
import RenderHTML from '@components/RenderHTML';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';

import useAccessibilityAnnouncement from '@hooks/useAccessibilityAnnouncement';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useSafeAreaPaddings from '@hooks/useSafeAreaPaddings';
import type {SubPageProps} from '@hooks/useSubPage/types';
import useThemeStyles from '@hooks/useThemeStyles';

import type {ForwardedFSClassProps} from '@libs/Fullstory/types';
import type {BrickRoad} from '@libs/WorkspacesSettingsUtils';

import {callIfAuthenticated} from '@userActions/Session';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

import type {ReactNode} from 'react';

import {authTokenTypeSelector} from '@selectors/Session';
import React, {useState} from 'react';
import {View} from 'react-native';

Expand Down Expand Up @@ -180,6 +186,7 @@ function ConfirmationStep({
}: ConfirmationStepProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector});

const {paddingBottom: safeAreaInsetPaddingBottom} = useSafeAreaPaddings();
const [wasLoading, setWasLoading] = useState(!!isLoading);
Expand Down Expand Up @@ -242,21 +249,29 @@ function ConfirmationStep({
}
const {id, description, title, shouldShowRightIcon, onPress, interactive, disabled, brickRoadIndicator, errorText, testID, accessibilityLabel} = row;
return (
<MenuItemWithTopDescription
<MenuItem.Root
key={id}
pressableTestID={testID ?? id}
description={description}
title={title}
shouldShowRightIcon={shouldShowRightIcon}
onPress={onPress}
interactive={interactive}
disabled={disabled}
testID={testID ?? id}
onPress={interactive !== false ? callIfAuthenticated(onPress, session) : undefined}
isDisabled={disabled}
sentryLabel={CONST.SENTRY_LABEL.CONFIRMATION_STEP.EDIT}
brickRoadIndicator={brickRoadIndicator}
errorText={errorText}
accessibilityLabel={accessibilityLabel}
forwardedFSClass={forwardedFSClass}
/>
>
<MenuItemField.Row
name={description}
value={title}
forwardedFSClass={forwardedFSClass}
>
{!!brickRoadIndicator && <MenuItem.BrickRoadIndicator status={brickRoadIndicator} />}
{shouldShowRightIcon && <MenuItem.Chevron />}
</MenuItemField.Row>
{!!errorText && (
<MenuItem.HelpText
message={errorText}
isError
/>
)}
</MenuItem.Root>
);
};

Expand Down
67 changes: 63 additions & 4 deletions tests/ui/PushRowWithModalTest.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {act, render} from '@testing-library/react-native';

import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import MenuItem from '@components/MenuItem';
import MenuItemField from '@components/MenuItem/presets/MenuItemField';

import PushRowWithModal from '@src/components/PushRowWithModal';
import PushRowModal from '@src/components/PushRowWithModal/PushRowModal';
Expand All @@ -11,7 +12,18 @@ import React from 'react';

import createMock from '../utils/createMock';

jest.mock('@components/MenuItemWithTopDescription', () => jest.fn(() => null));
jest.mock('@components/MenuItem', () => ({
__esModule: true,
default: {
Root: jest.fn(({children}: {children?: React.ReactNode}) => children),
Chevron: () => null,
BrickRoadIndicator: () => null,
HelpText: () => null,
},
}));
jest.mock('@components/MenuItem/presets/MenuItemField', () => ({__esModule: true, default: {Row: jest.fn(() => null)}}));
jest.mock('@hooks/useOnyx', () => () => [undefined]);
jest.mock('@userActions/Session', () => ({callIfAuthenticated: (callback: () => void) => callback}));
jest.mock('@src/components/PushRowWithModal/PushRowModal', () => jest.fn(() => null));
jest.mock('@src/utils/keyboard', () => ({
__esModule: true,
Expand All @@ -21,13 +33,15 @@ jest.mock('@src/utils/keyboard', () => ({
const optionsList = {RETAIL: 'Retail', SERVICES: 'Services', SOFTWARE: 'Software'};

describe('PushRowWithModal', () => {
const mockedRow = jest.mocked(MenuItemWithTopDescription);
const mockedRow = jest.mocked(MenuItem.Root);
const mockedFieldRow = jest.mocked(MenuItemField.Row);
const mockedModal = jest.mocked(PushRowModal);
const getRow = () => mockedRow.mock.lastCall?.[0];
const getModal = () => mockedModal.mock.lastCall?.[0];

beforeEach(() => {
mockedRow.mockClear();
mockedFieldRow.mockClear();
mockedModal.mockClear();
});

Expand All @@ -46,6 +60,51 @@ describe('PushRowWithModal', () => {
);
}

it('keeps an unchangeable answer non-interactive without dimming it', () => {
// Given a field whose saved answer cannot be changed
render(
<PushRowWithModal
value="RETAIL"
shouldAllowChange={false}
optionsList={optionsList}
description="Industry"
modalHeaderTitle="Industry"
searchInputTitle="Industry"
/>,
);

// When the field row is composed
const row = getRow();
const field = mockedFieldRow.mock.lastCall?.[0];

// Then it retains the answer without a press handler or disabled opacity
expect(row?.onPress).toBeUndefined();
expect(row?.isDisabled).toBe(false);
expect(field?.name).toBe('Industry');
expect(field?.value).toBe('Retail');
});

it('passes temporary disabled state to the root while retaining its edit action', () => {
// Given an editable field temporarily unavailable, such as while offline
render(
<PushRowWithModal
disabled
optionsList={optionsList}
description="Industry"
modalHeaderTitle="Industry"
searchInputTitle="Industry"
/>,
);

// When the row is composed
const row = getRow();

// Then the root blocks interaction and dims the row, rather than making the field permanently read-only
expect(row?.isDisabled).toBe(true);
expect(row?.onPress).toEqual(expect.any(Function));
expect(mockedFieldRow.mock.lastCall?.[0].value).toBe('');
});

it('saves the ticked options together when the user presses Save', async () => {
// Given a multi-select row with Retail saved
const onInputChange = jest.fn();
Expand Down Expand Up @@ -81,7 +140,7 @@ describe('PushRowWithModal', () => {
expect(onInputChange).not.toHaveBeenCalled();
expect(onBlur).toHaveBeenCalledTimes(1);
expect(getModal()?.selectedOptions).toEqual(['RETAIL']);
expect(getRow()?.title).toBe('Retail');
expect(mockedFieldRow.mock.lastCall?.[0].value).toBe('Retail');
});

it('drops a saved option missing from the list when the user saves', async () => {
Expand Down
Loading
Loading