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: 2 additions & 0 deletions src/components/ButtonWithDropdownMenu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type DropdownOption<TValueType> = WithSentryLabel & {
shouldShow?: boolean;
/** Whether to show a loading spinner for this option */
shouldShowLoadingSpinnerIcon?: boolean;
/** Whether to render a divider before this option */
addSeparatorBefore?: boolean;
/** The type of brick road indicator to show */
brickRoadIndicator?: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS>;
/** Whether selecting this option should bypass the delete confirmation modal */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import Navigation from '@libs/Navigation/Navigation';
import type {KYCFlowEvent, TriggerKYCFlow, WorkspacePolicyPaymentOption} from '@libs/PaymentUtils';
import {selectPaymentType} from '@libs/PaymentUtils';
import {sortPoliciesByName} from '@libs/PolicyUtils';
import {REPORT_MORE_MENU_SECTIONS, sortAndSectionPopoverMenuItems} from '@libs/PopoverMenuSections';
import {getFilteredReportActionsForReportView, hasRequestFromCurrentAccount} from '@libs/ReportActionsUtils';
import {getSecondaryReportActions} from '@libs/ReportSecondaryActionUtils';
import {
Expand Down Expand Up @@ -361,9 +362,10 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
},
};

const applicableSecondaryActions = secondaryActions
.map((action) => secondaryActionsImplementation[action])
.filter((action) => action?.shouldShow !== false && action?.value !== primaryAction);
const applicableSecondaryActions = sortAndSectionPopoverMenuItems(
secondaryActions.map((action) => secondaryActionsImplementation[action]).filter((action) => action?.shouldShow !== false && action?.value !== primaryAction),
REPORT_MORE_MENU_SECTIONS,
);

const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, allTransactionViolations, accountID, email ?? '');

Expand Down
6 changes: 5 additions & 1 deletion src/components/MoneyRequestHeaderSecondaryActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {getExistingTransactionID} from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {ReportsSplitNavigatorParamList, RightModalNavigatorParamList} from '@libs/Navigation/types';
import {sortAndSectionPopoverMenuItems, TRANSACTION_MORE_MENU_SECTIONS} from '@libs/PopoverMenuSections';
import {getOriginalMessage, isMoneyRequestAction, isTrackExpenseAction} from '@libs/ReportActionsUtils';
import {getTransactionThreadPrimaryAction} from '@libs/ReportPrimaryActionUtils';
import {getSecondaryTransactionThreadActions} from '@libs/ReportSecondaryActionUtils';
Expand Down Expand Up @@ -533,7 +534,10 @@ function MoneyRequestHeaderSecondaryActions({reportID, onBackButtonPress}: Money
},
};

const applicableSecondaryActions = secondaryActions.map((action) => secondaryActionsImplementation[action]).filter((action): action is NonNullable<typeof action> => !!action);
const applicableSecondaryActions = sortAndSectionPopoverMenuItems(
secondaryActions.map((action) => secondaryActionsImplementation[action]).filter((action): action is NonNullable<typeof action> => !!action),
TRANSACTION_MORE_MENU_SECTIONS,
);

if (!applicableSecondaryActions.length) {
return null;
Expand Down
91 changes: 48 additions & 43 deletions src/components/PopoverMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ type PopoverMenuItem = MenuItemProps & {
/** Whether to close the modal on select */
shouldCloseModalOnSelect?: boolean;

/** Whether to render a divider before this menu item */
addSeparatorBefore?: boolean;

/** Additional data for the menu item */
additionalData?: Record<string, unknown>;
};
Expand Down Expand Up @@ -440,6 +443,7 @@ function BasePopoverMenu({
testID: menuItemTestID,
shouldShowLoadingSpinnerIcon,
badgeText,
addSeparatorBefore,
...menuItemProps
} = item;
const icon = typeof item.icon === 'string' ? expensifyIcons[item.icon as keyof typeof expensifyIcons] : item.icon;
Expand All @@ -448,49 +452,50 @@ function BasePopoverMenu({
// In radio-button mode, suppress visual focus highlight until the user starts keyboard navigation.
const isVisuallyFocused = focusedIndex === menuIndex && (!isRadioButtonMode || hasKeyBeenPressed);
return (
<OfflineWithFeedback
key={reactKey}
pendingAction={item.pendingAction}
>
<FocusableMenuItem
key={reactKey}
pressableTestID={menuItemTestID ?? `PopoverMenuItem-${item.text}`}
title={text}
onPress={(event) => selectItem(menuIndex, event)}
focused={isVisuallyFocused}
shouldCheckActionAllowedOnPress={false}
iconRight={item.rightIcon}
shouldShowRightIcon={!!item.rightIcon}
brickRoadIndicator={item.brickRoadIndicator}
onFocus={() => {
if (!shouldUpdateFocusedIndex) {
return;
}
setFocusedIndex(menuIndex);
}}
badgeText={badgeText}
badgeStyle={StyleSheet.flatten(badgeStyle)}
wrapperStyle={[
StyleUtils.getItemBackgroundColorStyle(
!isRadioButtonMode && !!item.isSelected,
isVisuallyFocused,
item.disabled ?? false,
theme.activeComponentBG,
theme.hoverComponentBG,
),
shouldUseScrollView && !shouldUseModalPaddingStyle && StyleUtils.getOptionMargin(menuIndex, currentMenuItems.length - 1),
]}
shouldRemoveHoverBackground={item.isSelected}
titleStyle={StyleSheet.flatten([styles.flex1, item.titleStyle])}
icon={icon}
role={CONST.ROLE.BUTTON}
// Spread other props dynamically
{...menuItemProps}
shouldShowRadioButton={isRadioButtonMode}
hasSubMenuItems={!!subMenuItems?.length}
shouldShowLoadingSpinnerIcon={shouldShowLoadingSpinnerIcon}
/>
</OfflineWithFeedback>
<React.Fragment key={reactKey}>
{/* Compact popovers need tighter divider spacing than full-page sections. */}
{addSeparatorBefore === true && menuIndex > 0 && <View style={[styles.sectionDividerLine, styles.mh4, styles.mv2]} />}
<OfflineWithFeedback pendingAction={item.pendingAction}>
<FocusableMenuItem
key={reactKey}
pressableTestID={menuItemTestID ?? `PopoverMenuItem-${item.text}`}
title={text}
onPress={(event) => selectItem(menuIndex, event)}
focused={isVisuallyFocused}
shouldCheckActionAllowedOnPress={false}
iconRight={item.rightIcon}
shouldShowRightIcon={!!item.rightIcon}
brickRoadIndicator={item.brickRoadIndicator}
onFocus={() => {
if (!shouldUpdateFocusedIndex) {
return;
}
setFocusedIndex(menuIndex);
}}
badgeText={badgeText}
badgeStyle={StyleSheet.flatten(badgeStyle)}
wrapperStyle={[
StyleUtils.getItemBackgroundColorStyle(
!isRadioButtonMode && !!item.isSelected,
isVisuallyFocused,
item.disabled ?? false,
theme.activeComponentBG,
theme.hoverComponentBG,
),
shouldUseScrollView && !shouldUseModalPaddingStyle && StyleUtils.getOptionMargin(menuIndex, currentMenuItems.length - 1),
]}
shouldRemoveHoverBackground={item.isSelected}
titleStyle={StyleSheet.flatten([styles.flex1, item.titleStyle])}
icon={icon}
role={CONST.ROLE.BUTTON}
// Spread other props dynamically
{...menuItemProps}
shouldShowRadioButton={isRadioButtonMode}
hasSubMenuItems={!!subMenuItems?.length}
shouldShowLoadingSpinnerIcon={shouldShowLoadingSpinnerIcon}
/>
</OfflineWithFeedback>
</React.Fragment>
);
});

Expand Down
64 changes: 64 additions & 0 deletions src/libs/PopoverMenuSections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types';
import CONST from '@src/CONST';

const REPORT_SECONDARY_ACTIONS = CONST.REPORT.SECONDARY_ACTIONS;
const TRANSACTION_SECONDARY_ACTIONS = CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS;
const UNRECOGNIZED_SECTION = Number.MAX_SAFE_INTEGER;

const REPORT_MORE_MENU_SECTIONS = [
[
REPORT_SECONDARY_ACTIONS.PAY,
REPORT_SECONDARY_ACTIONS.ADD_EXPENSE,
REPORT_SECONDARY_ACTIONS.HOLD,
REPORT_SECONDARY_ACTIONS.REMOVE_HOLD,
REPORT_SECONDARY_ACTIONS.SUBMIT,
REPORT_SECONDARY_ACTIONS.RETRACT,
REPORT_SECONDARY_ACTIONS.REOPEN,
REPORT_SECONDARY_ACTIONS.REJECT,
REPORT_SECONDARY_ACTIONS.APPROVE,
REPORT_SECONDARY_ACTIONS.UNAPPROVE,
REPORT_SECONDARY_ACTIONS.CANCEL_PAYMENT,
Comment on lines +16 to +20

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include receivedPayment in report menu section map

getSecondaryReportActions() can emit REPORT_SECONDARY_ACTIONS.RECEIVED_PAYMENT (see src/libs/ReportSecondaryActionUtils.ts), but this action is missing from REPORT_MORE_MENU_SECTIONS. Because sortAndSectionPopoverMenuItems() sends unrecognized actions to the last section, Received payment is moved below utility/destructive items and gets an extra separator, which regresses the intended grouping/order whenever that action is available.

Useful? React with 👍 / 👎.

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.

@aswin-s The review comment seems reasonable. What do you think?

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.

@rojiphil RECEIVED_PAYMENT was added in PR #86174 but subsequently reverted in PR #90159. It no longer exists in CONST.REPORT.SECONDARY_ACTIONS on main, so there's nothing to map.

@rojiphil rojiphil Jul 23, 2026 •

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.

RECEIVED_PAYMENT got added later which we added in #91928

],
[REPORT_SECONDARY_ACTIONS.SPLIT, REPORT_SECONDARY_ACTIONS.MERGE, REPORT_SECONDARY_ACTIONS.DUPLICATE_EXPENSE, REPORT_SECONDARY_ACTIONS.MOVE_EXPENSE],
[REPORT_SECONDARY_ACTIONS.DUPLICATE_REPORT, REPORT_SECONDARY_ACTIONS.CHANGE_WORKSPACE, REPORT_SECONDARY_ACTIONS.CHANGE_APPROVER],
[REPORT_SECONDARY_ACTIONS.EXPORT, REPORT_SECONDARY_ACTIONS.DOWNLOAD_PDF, REPORT_SECONDARY_ACTIONS.PRINT],
[REPORT_SECONDARY_ACTIONS.VIEW_DETAILS, REPORT_SECONDARY_ACTIONS.DELETE],
];

const TRANSACTION_MORE_MENU_SECTIONS = [
[
TRANSACTION_SECONDARY_ACTIONS.HOLD,
TRANSACTION_SECONDARY_ACTIONS.REMOVE_HOLD,
TRANSACTION_SECONDARY_ACTIONS.REJECT,
TRANSACTION_SECONDARY_ACTIONS.SPLIT,
TRANSACTION_SECONDARY_ACTIONS.MERGE,
],
[TRANSACTION_SECONDARY_ACTIONS.DUPLICATE, TRANSACTION_SECONDARY_ACTIONS.MOVE_EXPENSE],
[TRANSACTION_SECONDARY_ACTIONS.VIEW_DETAILS, TRANSACTION_SECONDARY_ACTIONS.DELETE],
];

function buildSectionOrder(sectionDefinitions: ReadonlyArray<readonly string[]>) {
return new Map(sectionDefinitions.flatMap((section, sectionIndex) => section.map((action) => [action, sectionIndex])));
}

function sortAndSectionPopoverMenuItems<TValue extends string, TItem extends DropdownOption<TValue>>(items: TItem[], sectionDefinitions: ReadonlyArray<readonly string[]>): TItem[] {
const sectionOrder = buildSectionOrder(sectionDefinitions);
const sortedItems = items
.map((item, originalIndex) => ({item, originalIndex, sectionIndex: sectionOrder.get(item.value) ?? UNRECOGNIZED_SECTION}))
.sort((firstItem, secondItem) => firstItem.sectionIndex - secondItem.sectionIndex || firstItem.originalIndex - secondItem.originalIndex);

let lastSectionIndex: number | undefined;
return sortedItems.map(({item, sectionIndex}) => {
const shouldAddSeparator = lastSectionIndex !== undefined && sectionIndex !== lastSectionIndex;

lastSectionIndex = sectionIndex;

if (!shouldAddSeparator) {
return item;
}

return {...item, addSeparatorBefore: true};
});
}

export {REPORT_MORE_MENU_SECTIONS, TRANSACTION_MORE_MENU_SECTIONS, sortAndSectionPopoverMenuItems};
52 changes: 52 additions & 0 deletions tests/unit/libs/PopoverMenuSectionsTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types';
import {sortAndSectionPopoverMenuItems} from '@libs/PopoverMenuSections';

function makeItem(value: string): DropdownOption<string> {
return {text: value, value};
}

describe('sortAndSectionPopoverMenuItems', () => {
const sections = [['A', 'B', 'C'], ['D', 'E'], ['F']];

it('adds separators between sections', () => {
const items = [makeItem('A'), makeItem('D'), makeItem('F')];
const result = sortAndSectionPopoverMenuItems(items, sections);

expect(result).toHaveLength(3);
expect(result.at(0)?.addSeparatorBefore).toBeUndefined();
expect(result.at(1)?.addSeparatorBefore).toBe(true);
expect(result.at(2)?.addSeparatorBefore).toBe(true);
});

it('does not add separator when all items are in the same section', () => {
const items = [makeItem('A'), makeItem('B'), makeItem('C')];
const result = sortAndSectionPopoverMenuItems(items, sections);

expect(result.every((i) => !i.addSeparatorBefore)).toBe(true);
});

it('sorts items by section order while preserving original order within sections', () => {
const items = [makeItem('F'), makeItem('B'), makeItem('D'), makeItem('A')];
const result = sortAndSectionPopoverMenuItems(items, sections);

expect(result.map((i) => i.value)).toEqual(['B', 'A', 'D', 'F']);
});

it('places unrecognized items at the end', () => {
const items = [makeItem('UNKNOWN'), makeItem('A'), makeItem('D')];
const result = sortAndSectionPopoverMenuItems(items, sections);

expect(result.map((i) => i.value)).toEqual(['A', 'D', 'UNKNOWN']);
expect(result.at(2)?.addSeparatorBefore).toBe(true);
});

it('returns empty array for empty input', () => {
expect(sortAndSectionPopoverMenuItems([], sections)).toEqual([]);
});

it('handles single item without separator', () => {
const result = sortAndSectionPopoverMenuItems([makeItem('D')], sections);

expect(result).toEqual([{text: 'D', value: 'D'}]);
});
});
Loading