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: 0 additions & 2 deletions config/oxlint/oxlint.seatbelt.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,6 @@
"../../src/pages/iou/request/step/IOURequestStepConfirmation/index.tsx" "no-restricted-imports" 1
"../../src/pages/iou/request/step/IOURequestStepConfirmation/useConfirmationTransactionPager.ts" "rulesdir/no-onyx-loading-status" 1
"../../src/pages/iou/request/step/IOURequestStepCurrencyModal.tsx" "no-restricted-imports" 1
"../../src/pages/iou/request/step/IOURequestStepDistanceGPS/Waypoints/index.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 2
"../../src/pages/iou/request/step/IOURequestStepDistanceMap.tsx" "react-hooks/set-state-in-effect" 1
"../../src/pages/iou/request/step/IOURequestStepDistanceMap.tsx" "rulesdir/no-onyx-loading-status" 1
"../../src/pages/iou/request/step/IOURequestStepDistanceOdometer.tsx" "rulesdir/no-onyx-loading-status" 1
Expand Down Expand Up @@ -1648,7 +1647,6 @@
"../../src/pages/Travel/DynamicDomainPermissionInfoPage.tsx" "no-restricted-imports" 1
"../../src/pages/Travel/DynamicPublicDomainErrorPage.tsx" "no-restricted-imports" 1
"../../src/pages/Travel/DynamicTravelUpgrade.tsx" "no-restricted-imports" 2
"../../src/pages/Travel/DynamicTripDetailsPage.tsx" "@typescript-eslint/no-deprecated/MenuItem" 2
"../../src/pages/Travel/DynamicTripSummaryPage.tsx" "no-restricted-imports" 1
"../../src/pages/Travel/DynamicWorkspaceConfirmationForTravelPage.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2
"../../src/pages/Travel/EnableTravel/EnableTravelContent.tsx" "no-restricted-imports" 1
Expand Down
4 changes: 4 additions & 0 deletions src/components/MenuItem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import MenuItemHelpText from './leaves/helpText/MenuItemHelpText';
import MenuItemHelpTextHTML from './leaves/helpText/MenuItemHelpTextHTML';
import MenuItemIcon from './leaves/leading/MenuItemIcon';
import MenuItemIconNarrow from './leaves/leading/MenuItemIconNarrow';
import MenuItemSpinner from './leaves/leading/MenuItemSpinner';
import MenuItemSpinnerNarrow from './leaves/leading/MenuItemSpinnerNarrow';
import MenuItemBrickRoadIndicator from './leaves/trailing/icons/MenuItemBrickRoadIndicator';
import MenuItemChevron from './leaves/trailing/icons/MenuItemChevron';
import MenuItemDownCaret from './leaves/trailing/icons/MenuItemDownCaret';
Expand All @@ -61,6 +63,8 @@ const MenuItem = Object.assign(LegacyMenuItem, {
Trailing: MenuItemTrailing,
Icon: MenuItemIcon,
IconNarrow: MenuItemIconNarrow,
Spinner: MenuItemSpinner,
SpinnerNarrow: MenuItemSpinnerNarrow,
Label: MenuItemLabel,
Title: MenuItemTitle,
Description: MenuItemDescription,
Expand Down
14 changes: 14 additions & 0 deletions src/components/MenuItem/leaves/leading/MenuItemSpinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import useThemeStyles from '@hooks/useThemeStyles';

import React from 'react';

import BaseMenuItemSpinner from './base/BaseMenuItemSpinner';

/** A spinner occupying the same slot as MenuItem.Icon. */
function MenuItemSpinner() {
const styles = useThemeStyles();

return <BaseMenuItemSpinner style={styles.popoverMenuIcon} />;
}

export default MenuItemSpinner;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import useThemeStyles from '@hooks/useThemeStyles';

import React from 'react';

import BaseMenuItemSpinner from './base/BaseMenuItemSpinner';

/** A spinner occupying the same slot as MenuItem.IconNarrow. */
function MenuItemSpinnerNarrow() {
const styles = useThemeStyles();

return <BaseMenuItemSpinner style={[styles.popoverMenuIcon, styles.wAuto]} />;
}

export default MenuItemSpinnerNarrow;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ActivityIndicator from '@components/ActivityIndicator';

import useTheme from '@hooks/useTheme';

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

import React from 'react';
import {View} from 'react-native';

type BaseMenuItemSpinnerProps = {
/** Matches the corresponding icon leaf's slot so loading does not shift the content. */
style: StyleProp<ViewStyle>;
};

/** Shared spinner presentation for the leading icon slots. */
function BaseMenuItemSpinner({style}: BaseMenuItemSpinnerProps) {
const theme = useTheme();

return (
<View style={style}>
<ActivityIndicator color={theme.textSupporting} />
</View>
);
}

export default BaseMenuItemSpinner;
56 changes: 34 additions & 22 deletions src/pages/Travel/DynamicTripDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {TravelNavigatorParamList} from '@libs/Navigation/types';
import {formatCancelledDescription, getReservationDetailsFromSequence, getReservationsFromTripReport} from '@libs/TripReservationUtils';

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

import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
Expand All @@ -32,6 +33,7 @@ import type {PersonalDetailsList} from '@src/types/onyx';
import type {StackScreenProps} from '@react-navigation/stack';
import type {OnyxEntry} from 'react-native-onyx';

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

import CarTripDetails from './CarTripDetails';
Expand All @@ -47,7 +49,6 @@ type DynamicTripDetailsPageProps = StackScreenProps<TravelNavigatorParamList, ty

function DynamicTripDetailsPage({route}: DynamicTripDetailsPageProps) {
const icons = useMemoizedLazyExpensifyIcons([
'NewWindow',
'Plane',
'PlaneCircleSlash',
'Bed',
Expand Down Expand Up @@ -75,6 +76,7 @@ function DynamicTripDetailsPage({route}: DynamicTripDetailsPageProps) {
const {transactionID, sequenceIndex, pnr, reportID} = route.params;

const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector});
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionID)}`);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(transaction?.reportID)}`);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID ?? reportID}`);
Expand Down Expand Up @@ -146,37 +148,47 @@ function DynamicTripDetailsPage({route}: DynamicTripDetailsPageProps) {
personalDetails={travelerPersonalDetails}
/>
)}
<MenuItem
<MenuItem.Root
sentryLabel={CONST.SENTRY_LABEL.TRAVEL.TRIP_DETAILS_MODIFY_TRIP}
title={translate('travel.modifyTrip')}
icon={icons.Pencil}
iconRight={icons.NewWindow}
shouldShowRightIcon
onPress={() => {
onPress={callIfAuthenticated(() => {
setIsModifyTripLoading(true);
openTravelDotLink(activePolicyID, CONST.TRIP_ID_PATH(tripID))?.finally(() => {
setIsModifyTripLoading(false);
});
}}
wrapperStyle={styles.mt3}
shouldShowLoadingSpinnerIcon={isModifyTripLoading}
disabled={isModifyTripLoading || isOffline}
/>
<MenuItem
}, session)}
style={styles.mt3}
isDisabled={isModifyTripLoading || isOffline}
>
<MenuItem.Row>
<MenuItem.Leading>{isModifyTripLoading ? <MenuItem.Spinner /> : <MenuItem.Icon src={icons.Pencil} />}</MenuItem.Leading>
<MenuItem.Content>
<MenuItem.Title>{translate('travel.modifyTrip')}</MenuItem.Title>
</MenuItem.Content>
<MenuItem.Trailing>
<MenuItem.NewWindowIcon />
</MenuItem.Trailing>
</MenuItem.Row>
</MenuItem.Root>
<MenuItem.Root
sentryLabel={CONST.SENTRY_LABEL.TRAVEL.TRIP_DETAILS_TRIP_SUPPORT}
title={translate('travel.tripSupport')}
icon={icons.Phone}
iconRight={icons.NewWindow}
shouldShowRightIcon
onPress={() => {
onPress={callIfAuthenticated(() => {
setIsTripSupportLoading(true);
openTravelDotLink(activePolicyID, CONST.TRIP_SUPPORT)?.finally(() => {
setIsTripSupportLoading(false);
});
}}
shouldShowLoadingSpinnerIcon={isTripSupportLoading}
disabled={isTripSupportLoading || isOffline}
/>
}, session)}
isDisabled={isTripSupportLoading || isOffline}
>
<MenuItem.Row>
<MenuItem.Leading>{isTripSupportLoading ? <MenuItem.Spinner /> : <MenuItem.Icon src={icons.Phone} />}</MenuItem.Leading>
<MenuItem.Content>
<MenuItem.Title>{translate('travel.tripSupport')}</MenuItem.Title>
</MenuItem.Content>
<MenuItem.Trailing>
<MenuItem.NewWindowIcon />
</MenuItem.Trailing>
</MenuItem.Row>
</MenuItem.Root>
</ScrollView>
</FullPageNotFoundView>
</ScreenWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import MenuItem from '@components/MenuItem';
import MenuItemField from '@components/MenuItem/presets/MenuItemField';
import ScrollView from '@components/ScrollView';

import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
Expand All @@ -8,6 +9,7 @@ import useThemeStyles from '@hooks/useThemeStyles';

import type {MoneyRequestNavigatorParamList} from '@libs/Navigation/types';

import CONST from '@src/CONST';
import {getEffectiveEndPoint, getFirstGpsPoint, getTotalGpsTripPoints, isTripStopped as isTripStoppedUtil} from '@src/libs/GPSDraftDetailsUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
Expand Down Expand Up @@ -79,25 +81,29 @@ function Waypoints({unit, isInLandscapeMode, action, iouType, transactionID, rep
/>
</View>

<MenuItemWithTopDescription
interactive={false}
description={translate('gps.start')}
shouldShowLoadingSpinnerIcon={shouldShowLoadingStartAddress}
title={shouldShowLoadingStartAddress ? '...' : firstPoint?.address?.value}
icon={icons.DotIndicatorUnfilled}
<MenuItem.Root
sentryLabel={CONST.SENTRY_LABEL.IOU_REQUEST_STEP.WAYPOINT_START_MENU_ITEM}
style={styles.pv3}
shouldIconUseAutoWidthStyle
/>

<MenuItemWithTopDescription
interactive={false}
description={translate('gps.stop')}
shouldShowLoadingSpinnerIcon={shouldShowLoadingEndAddress}
title={getEndAddressTitle()}
icon={icons.Location}
>
<MenuItem.Row>
<MenuItem.Leading>{shouldShowLoadingStartAddress ? <MenuItem.SpinnerNarrow /> : <MenuItem.IconNarrow src={icons.DotIndicatorUnfilled} />}</MenuItem.Leading>
<MenuItemField.Content name={translate('gps.start')}>
<MenuItem.FieldValue>{shouldShowLoadingStartAddress ? '...' : (firstPoint?.address?.value ?? '')}</MenuItem.FieldValue>
</MenuItemField.Content>
</MenuItem.Row>
</MenuItem.Root>

<MenuItem.Root
sentryLabel={CONST.SENTRY_LABEL.IOU_REQUEST_STEP.WAYPOINT_STOP_MENU_ITEM}
style={styles.pv3}
shouldIconUseAutoWidthStyle
/>
>
<MenuItem.Row>
<MenuItem.Leading>{shouldShowLoadingEndAddress ? <MenuItem.SpinnerNarrow /> : <MenuItem.IconNarrow src={icons.Location} />}</MenuItem.Leading>
<MenuItemField.Content name={translate('gps.stop')}>
<MenuItem.FieldValue>{getEndAddressTitle() ?? ''}</MenuItem.FieldValue>
</MenuItemField.Content>
</MenuItem.Row>
</MenuItem.Root>
</Wrapper>
);
}
Expand Down
87 changes: 87 additions & 0 deletions tests/ui/components/MenuItem/MenuItemSpinnerTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/** Verifies that spinner leaves preserve the corresponding icon slots and composed row behavior. */
import {fireEvent, render, renderHook, screen} from '@testing-library/react-native';

import ActivityIndicator from '@components/ActivityIndicator';
import Icon from '@components/Icon';
import {LocaleContextProvider} from '@components/LocaleContextProvider';
import MenuItem from '@components/MenuItem';

import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';

import CONST from '@src/CONST';

import type {PropsWithChildren} from 'react';

import React from 'react';
import {StyleSheet} from 'react-native';

function MockIcon() {
return null;
}
const spinnerLeaves = [
{name: 'Spinner', IconLeaf: MenuItem.Icon, Spinner: MenuItem.Spinner, isNarrow: false},
{name: 'SpinnerNarrow', IconLeaf: MenuItem.IconNarrow, Spinner: MenuItem.SpinnerNarrow, isNarrow: true},
];

function Wrapper({children}: PropsWithChildren) {
return <LocaleContextProvider>{children}</LocaleContextProvider>;
}

describe.each(spinnerLeaves)('MenuItem.$name', ({IconLeaf, Spinner, isNarrow}) => {
it('uses the supporting color and corresponding icon slot styles', () => {
// Given spinner leaves must fit the icon slots they replace
const {result} = renderHook(() => ({styles: useThemeStyles(), theme: useTheme()}));
const slotStyle = StyleSheet.flatten([result.current.styles.popoverMenuIcon, isNarrow && result.current.styles.wAuto]);

// When the caller composes a spinner instead of an icon
render(
<Wrapper>
<MenuItem.Root>
<MenuItem.Row>
<MenuItem.Leading>
<Spinner />
</MenuItem.Leading>
<MenuItem.Content>
<MenuItem.Title>Row title</MenuItem.Title>
</MenuItem.Content>
</MenuItem.Row>
</MenuItem.Root>
</Wrapper>,
);

// Then the spinner preserves the slot styles without rendering an icon alongside it
expect(screen.getByText('Row title')).toBeOnTheScreen();
const spinner = screen.UNSAFE_getByType(ActivityIndicator);
expect(spinner.props.color).toBe(result.current.theme.textSupporting);
expect(StyleSheet.flatten(spinner.parent?.props.style)).toEqual(slotStyle);
expect(screen.UNSAFE_queryByType(Icon)).toBeNull();
});

it('restores the glyph and keeps the row action after loading finishes', async () => {
// Given loading presentation does not itself decide whether a row is disabled
const onPress = jest.fn();
const row = (isLoading: boolean) => (
<Wrapper>
<MenuItem.Root onPress={onPress}>
<MenuItem.Row>
<MenuItem.Leading>{isLoading ? <Spinner /> : <IconLeaf src={MockIcon} />}</MenuItem.Leading>
<MenuItem.Content>
<MenuItem.Title>Open row</MenuItem.Title>
</MenuItem.Content>
</MenuItem.Row>
</MenuItem.Root>
</Wrapper>
);
const {rerender} = render(row(true));

// When loading completes and the row is activated
rerender(row(false));
fireEvent.press(await screen.findByRole(CONST.ROLE.BUTTON, {name: 'Open row'}), {nativeEvent: {}});

// Then the glyph returns without changing the action or leaving a spinner behind
expect(screen.UNSAFE_queryByType(ActivityIndicator)).toBeNull();
expect(screen.UNSAFE_getByType(Icon).props.src).toBe(MockIcon);
expect(onPress).toHaveBeenCalledTimes(1);
});
});
Loading