From c28c854b41ba62053e7ac5f81dd97065d96de3f4 Mon Sep 17 00:00:00 2001 From: "Yauheni Horbach (via MelvinBot)" Date: Fri, 21 Aug 2026 19:35:36 +0000 Subject: [PATCH 1/9] Always open Export submenu on Search even with a single option Co-authored-by: Yauheni Horbach --- src/hooks/useSearchBulkActions.ts | 35 +++++++++++-------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index 14c48ce3dd68..6ea13f0c0c11 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -2083,29 +2083,18 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { }; const subMenuItems = getExportOptions(); - const singleExportSubMenuItem = subMenuItems.length === 1 ? subMenuItems.at(0) : undefined; - - const exportButtonOption: DropdownOption & Pick = singleExportSubMenuItem - ? { - icon: expensifyIcons.Export, - text: singleExportSubMenuItem.text, - value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, - shouldCloseModalOnSelect: singleExportSubMenuItem.shouldCloseModalOnSelect ?? true, - shouldCallAfterModalHide: singleExportSubMenuItem.shouldCallAfterModalHide, - onSelected: () => singleExportSubMenuItem.onSelected?.(), - description: singleExportSubMenuItem.description, - displayInDefaultIconColor: singleExportSubMenuItem.displayInDefaultIconColor, - additionalIconStyles: singleExportSubMenuItem.additionalIconStyles, - } - : { - icon: expensifyIcons.Export, - rightIcon: expensifyIcons.ArrowRight, - text: translate('common.export'), - backButtonText: translate('common.export'), - value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, - shouldCloseModalOnSelect: true, - subMenuItems, - }; + + // Always open the Export submenu, even when there is only one option, so the user keeps the context that + // they are entering an export flow instead of being navigated straight into the single option. + const exportButtonOption: DropdownOption & Pick = { + icon: expensifyIcons.Export, + rightIcon: expensifyIcons.ArrowRight, + text: translate('common.export'), + backButtonText: translate('common.export'), + value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, + shouldCloseModalOnSelect: true, + subMenuItems, + }; if (areAllMatchingItemsSelected) { return [exportButtonOption]; From ba2924646da44cf2663fa4033ba509eb5d0f6624 Mon Sep 17 00:00:00 2001 From: "Yauheni Horbach (via MelvinBot)" Date: Fri, 21 Aug 2026 19:44:04 +0000 Subject: [PATCH 2/9] Add regression test for single-option Export submenu on Search Co-authored-by: Yauheni Horbach --- .../hooks/useSearchBulkActionsExportTest.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/unit/hooks/useSearchBulkActionsExportTest.ts b/tests/unit/hooks/useSearchBulkActionsExportTest.ts index bd32afb4805f..9ab40d90d15d 100644 --- a/tests/unit/hooks/useSearchBulkActionsExportTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsExportTest.ts @@ -399,7 +399,7 @@ function getExportOptionTexts(headerButtonsOptions: ReturnType item.text) ?? (exportOption ? [exportOption.text] : []); } -/** The export menu collapses into a single top-level option when it holds only one item, so look in both shapes. */ +/** Export options live inside the Export submenu, but tolerate a flat top-level shape too so callers stay robust. */ function getExportOptionByText(headerButtonsOptions: ReturnType['headerButtonsOptions'], text: string) { const exportOption = headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); if (!exportOption) { @@ -1145,6 +1145,28 @@ describe('useSearchBulkActions - export options', () => { expect(getExportOptionTexts(result.current.headerButtonsOptions)).not.toContain('export.basicExport'); }); + it('keeps the Export entry as a submenu even when only one export option is available', async () => { + // Regression test for https://github.com/Expensify/App/issues/98779: a full group selection offers a single + // export option ('export.currentView'). The Export entry must still open the Export submenu (keeping its + // generic label and subMenuItems) rather than collapsing straight into that single option. + mockSelectedTransactions = { + tx1: makeSelectedTransaction({ + groupKey: `${CONST.SEARCH.GROUP_PREFIX}category`, + isSelectedViaGroup: true, + }), + }; + + const {result} = renderHook(() => useSearchBulkActions({queryJSON: groupedExpenseQueryJSON}), {wrapper: OnyxListItemProvider}); + + await waitFor(() => { + expect(getExportOptionTexts(result.current.headerButtonsOptions)).toEqual(['export.currentView']); + }); + + const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + expect(exportOption?.subMenuItems).toHaveLength(1); + expect(exportOption?.text).toBe('common.export'); + }); + it('exports the current view of a grouped search with the default expense columns', async () => { mockSelectedTransactions = {tx1: makeSelectedTransaction()}; From f5d77afdb12aedb18227b22e35b3c6ea061cdc4c Mon Sep 17 00:00:00 2001 From: "Yauheni Horbach (via MelvinBot)" Date: Fri, 21 Aug 2026 19:59:45 +0000 Subject: [PATCH 3/9] Fix useSearchBulkActionsTest: select the sole Export submenu item (currentView) Co-authored-by: Yauheni Horbach --- tests/unit/hooks/useSearchBulkActionsTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/hooks/useSearchBulkActionsTest.ts b/tests/unit/hooks/useSearchBulkActionsTest.ts index 4ea9bdd5099d..e902dab296da 100644 --- a/tests/unit/hooks/useSearchBulkActionsTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsTest.ts @@ -278,7 +278,7 @@ describe('useSearchBulkActions - CSV export flow', () => { const exportOption = result.current.headerButtonsOptions.find((o) => o.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); expect(exportOption).toBeDefined(); - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.basicExport')?.onSelected ?? exportOption?.onSelected; + const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; await act(async () => { onSelected?.(); @@ -444,7 +444,7 @@ describe('useSearchBulkActions - CSV export flow', () => { }); const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.basicExport')?.onSelected ?? exportOption?.onSelected; + const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; await act(async () => { onSelected?.(); From 3c765a6a4e4c66cff67cf84c581769695f7cd826 Mon Sep 17 00:00:00 2001 From: MelvinBot Date: Tue, 1 Sep 2026 07:45:56 +0000 Subject: [PATCH 4/9] Open the bulk-action dropdown directly onto the export options when Export is the only action There is no main menu to return to in that case, so nesting the options behind an Export row would render a back arrow that leads nowhere. Co-authored-by: Yauheni Horbach --- src/hooks/useSearchBulkActions.ts | 30 ++++++- .../hooks/useSearchBulkActionsExportTest.ts | 78 +++++++++++++++---- tests/unit/hooks/useSearchBulkActionsTest.ts | 34 ++++---- 3 files changed, 106 insertions(+), 36 deletions(-) diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index 6ea13f0c0c11..9f23a2396180 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -422,6 +422,13 @@ function getChatReportForBulkPay( return getReportFromSearchSnapshot(resolvedChatReportID, searchData, allReports) ?? getReportOrDraftReport(resolvedChatReportID); } +/** + * A single export option. It is typed as a dropdown option rather than a plain menu item because it is rendered at + * either level of the bulk-action dropdown: nested inside the Export submenu, or directly at the top level when + * Export is the only bulk action available. + */ +type ExportMenuItem = DropdownOption & Pick; + function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const {translate, localeCompare} = useLocalize(); const styles = useThemeStyles(); @@ -1781,7 +1788,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { ? defaultTemplates.filter((template) => template.templateName === CONST.REPORT.EXPORT_OPTIONS.DOWNLOAD_CSV) : defaultTemplates; - const exportOptions: PopoverMenuItem[] = []; + const exportOptions: ExportMenuItem[] = []; const isReportsTab = isExpenseReportType; const includesGroupExport = isGroupedSearch && Object.entries(selectedTransactions).some(([key, selectedTransaction]) => isGroupSelection(key, selectedTransaction)); @@ -1992,6 +1999,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const handleExportAction = buildIntegrationHandleExportAction(exportableReportIDs, integration, integrationGroupSize, true, connectionNameFriendly); exportOptions.push({ text: connectionNameFriendly, + value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: integrationIcon, onSelected: () => handleExportAction(() => exportToIntegrationOnSearch(hash, exportableReportIDs, integration, integrationPolicy, currentSearchKey)), shouldCloseModalOnSelect: true, @@ -2009,6 +2017,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const handleMarkAction = buildIntegrationHandleExportAction(reportIDsToMark, integration, integrationGroupSize, false, connectionNameFriendly); exportOptions.push({ text: translate('workspace.common.markAsExported'), + value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, // Every integration's "Mark as exported" option shares the same visible text and differs only by icon, // which screen readers can't announce. Append the integration name so assistive tech can distinguish them. accessibilityLabel: `${translate('workspace.common.markAsExported')}, ${connectionNameFriendly}`, @@ -2025,6 +2034,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { // "Current view" is pinned directly under the accounting actions. exportOptions.push({ text: translate('export.currentView'), + value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: expensifyIcons.Table, onSelected: () => { handleExportCurrentView(); @@ -2037,11 +2047,12 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { if (!allSelectedAreDeleted && !includesGroupExport) { // Builds a single export sub-menu item for a template. `isDefaultTemplate` picks the icon and `addSeparatorBefore` draws the divider at the top of each group. - const buildExportOption = (template: ExportTemplate, isDefaultTemplate: boolean, addSeparatorBefore: boolean): PopoverMenuItem => { + const buildExportOption = (template: ExportTemplate, isDefaultTemplate: boolean, addSeparatorBefore: boolean): ExportMenuItem => { // The basic export is a plain CSV download, so it uses its own handler rather than the template export flow const isBasicExport = template.templateName === CONST.REPORT.EXPORT_OPTIONS.DOWNLOAD_CSV; return { text: template.name, + value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: isDefaultTemplate ? expensifyIcons.Table : expensifyIcons.TablePencil, description: template.description, onSelected: () => { @@ -2068,6 +2079,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { // The templates aren't available for this selection, but the basic export (a plain CSV download) still is exportOptions.push({ text: translate('export.basicExport'), + value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: expensifyIcons.Table, onSelected: () => { handleBasicExport(); @@ -2096,8 +2108,18 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { subMenuItems, }; + /** + * Export is sometimes the only bulk action available (most commonly under "select all"). There is no main menu + * to go back to then, so the dropdown opens directly onto the export options rather than nesting them behind + * an "Export" row whose submenu would render a back arrow leading nowhere. + */ + const openExportOptionsDirectlyIfSoleAction = (builtOptions: Array>): Array> => { + const isExportTheOnlyAction = builtOptions.length === 1 && builtOptions.at(0)?.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT; + return isExportTheOnlyAction && subMenuItems.length > 0 ? subMenuItems : builtOptions; + }; + if (areAllMatchingItemsSelected) { - return [exportButtonOption]; + return openExportOptionsDirectlyIfSoleAction([exportButtonOption]); } if (allSelectedAreDeleted) { @@ -2706,7 +2728,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { }); } - return options; + return openExportOptionsDirectlyIfSoleAction(options); }, [ selectedTransactionsKeys, hash, diff --git a/tests/unit/hooks/useSearchBulkActionsExportTest.ts b/tests/unit/hooks/useSearchBulkActionsExportTest.ts index 9ab40d90d15d..72a193eab369 100644 --- a/tests/unit/hooks/useSearchBulkActionsExportTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsExportTest.ts @@ -390,22 +390,27 @@ function makeSearchResults(reports: Report[], reportActionsByReportID: Record['headerButtonsOptions']) { - return headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)?.subMenuItems; +/** + * The export options take one of two shapes: normally they sit inside the Export entry's `subMenuItems`, but when + * Export is the only bulk action available the dropdown opens straight onto them, so they sit at the top level of + * `headerButtonsOptions` with the EXPORT value on each one. + */ +function getExportMenuItems(headerButtonsOptions: ReturnType['headerButtonsOptions']) { + const exportOptions = headerButtonsOptions.filter((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + return exportOptions.at(0)?.subMenuItems ?? exportOptions; } function getExportOptionTexts(headerButtonsOptions: ReturnType['headerButtonsOptions']) { - const exportOption = headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - return exportOption?.subMenuItems?.map((item) => item.text) ?? (exportOption ? [exportOption.text] : []); + return getExportMenuItems(headerButtonsOptions).map((item) => item.text); } -/** Export options live inside the Export submenu, but tolerate a flat top-level shape too so callers stay robust. */ function getExportOptionByText(headerButtonsOptions: ReturnType['headerButtonsOptions'], text: string) { - const exportOption = headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - if (!exportOption) { - return undefined; - } - return exportOption.subMenuItems?.find((item) => item.text === text) ?? (exportOption.text === text ? exportOption : undefined); + return getExportMenuItems(headerButtonsOptions).find((item) => item.text === text); +} + +/** The Export entry's nested submenu items. Only valid for selections where Export is not the only bulk action. */ +function getExportSubMenuItems(headerButtonsOptions: ReturnType['headerButtonsOptions']) { + return headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)?.subMenuItems; } /** The parameters the last plain-CSV export sent to the backend, with the serialized query parsed back. */ @@ -515,10 +520,9 @@ describe('useSearchBulkActions - export options', () => { expect(result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)).toBeDefined(); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const subMenuItems = exportOption?.subMenuItems ?? []; - expect(subMenuItems.some((item) => item.text === NETSUITE_FRIENDLY_NAME)).toBe(false); - expect(subMenuItems.some((item) => item.text === 'workspace.common.markAsExported')).toBe(false); + const exportMenuItems = getExportMenuItems(result.current.headerButtonsOptions); + expect(exportMenuItems.some((item) => item.text === NETSUITE_FRIENDLY_NAME)).toBe(false); + expect(exportMenuItems.some((item) => item.text === 'workspace.common.markAsExported')).toBe(false); }); it('offers per-integration export options when reports span workspaces connected to different integrations', async () => { @@ -1147,12 +1151,14 @@ describe('useSearchBulkActions - export options', () => { it('keeps the Export entry as a submenu even when only one export option is available', async () => { // Regression test for https://github.com/Expensify/App/issues/98779: a full group selection offers a single - // export option ('export.currentView'). The Export entry must still open the Export submenu (keeping its - // generic label and subMenuItems) rather than collapsing straight into that single option. + // export option ('export.currentView'). While other bulk actions sit alongside it (Hold here), the Export + // entry must still open the Export submenu (keeping its generic label and subMenuItems) rather than + // collapsing straight into that single option. mockSelectedTransactions = { tx1: makeSelectedTransaction({ groupKey: `${CONST.SEARCH.GROUP_PREFIX}category`, isSelectedViaGroup: true, + canHold: true, }), }; @@ -1167,6 +1173,46 @@ describe('useSearchBulkActions - export options', () => { expect(exportOption?.text).toBe('common.export'); }); + it('opens directly onto the single export option when Export is the only bulk action', async () => { + // Export is the only bulk action offered under select all, so there is no main menu to go back to. The one + // export option is surfaced directly instead of behind an "Export" row whose submenu would render a back + // arrow leading nowhere. + mockAreAllMatchingItemsSelected = true; + mockSelectedTransactions = { + tx1: makeSelectedTransaction({ + groupKey: `${CONST.SEARCH.GROUP_PREFIX}category`, + isSelectedViaGroup: true, + }), + }; + + const {result} = renderHook(() => useSearchBulkActions({queryJSON: groupedExpenseQueryJSON}), {wrapper: OnyxListItemProvider}); + + await waitFor(() => { + expect(result.current.headerButtonsOptions.map((option) => option.text)).toEqual(['export.currentView']); + }); + + const soleOption = result.current.headerButtonsOptions.at(0); + expect(soleOption?.value).toBe(CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + expect(soleOption?.subMenuItems).toBeUndefined(); + expect(soleOption?.backButtonText).toBeUndefined(); + }); + + it('opens directly onto every export option when Export is the only bulk action', async () => { + mockAreAllMatchingItemsSelected = true; + mockSelectedTransactions = {tx1: makeSelectedTransaction()}; + + const {result} = renderHook(() => useSearchBulkActions({queryJSON: groupedExpenseQueryJSON}), {wrapper: OnyxListItemProvider}); + + await waitFor(() => { + expect(result.current.headerButtonsOptions.length).toBeGreaterThan(1); + }); + + // Every entry is an export option itself — there is no "Export" row wrapping them and so no back arrow. + expect(result.current.headerButtonsOptions.every((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)).toBe(true); + expect(result.current.headerButtonsOptions.some((option) => option.text === 'common.export')).toBe(false); + expect(result.current.headerButtonsOptions.some((option) => !!option.subMenuItems)).toBe(false); + }); + it('exports the current view of a grouped search with the default expense columns', async () => { mockSelectedTransactions = {tx1: makeSelectedTransaction()}; diff --git a/tests/unit/hooks/useSearchBulkActionsTest.ts b/tests/unit/hooks/useSearchBulkActionsTest.ts index e902dab296da..6df44e8b30c6 100644 --- a/tests/unit/hooks/useSearchBulkActionsTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsTest.ts @@ -241,6 +241,16 @@ function hasSearchFlatFilters(value: unknown): value is {flatFilters: SearchQuer return typeof value === 'object' && value !== null && 'flatFilters' in value && Array.isArray(value.flatFilters); } +/** + * The export options take one of two shapes: normally they sit inside the Export entry's `subMenuItems`, but when + * Export is the only bulk action available the dropdown opens straight onto them, so they sit at the top level of + * `headerButtonsOptions` with the EXPORT value on each one. + */ +function getExportMenuItems(headerButtonsOptions: ReturnType['headerButtonsOptions']) { + const exportOptions = headerButtonsOptions.filter((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + return exportOptions.at(0)?.subMenuItems ?? exportOptions; +} + describe('useSearchBulkActions - CSV export flow', () => { beforeAll(() => { Onyx.init({keys: ONYXKEYS}); @@ -275,10 +285,8 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((o) => o.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - expect(exportOption).toBeDefined(); - - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; + const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; + expect(onSelected).toBeDefined(); await act(async () => { onSelected?.(); @@ -307,8 +315,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; + const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; await act(async () => { onSelected?.(); @@ -360,8 +367,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; + const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; await act(async () => { onSelected?.(); @@ -400,8 +406,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; + const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; await act(async () => { onSelected?.(); @@ -443,8 +448,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; + const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; await act(async () => { onSelected?.(); @@ -483,8 +487,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((o) => o.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const templateSubItem = exportOption?.subMenuItems?.find((item) => item.text !== 'export.basicExport' && item.text !== 'export.currentView'); + const templateSubItem = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text !== 'export.basicExport' && item.text !== 'export.currentView'); expect(templateSubItem).toBeDefined(); act(() => { @@ -519,8 +522,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const exportItems = exportOption?.subMenuItems ?? []; + const exportItems = getExportMenuItems(result.current.headerButtonsOptions); expect(exportItems.some((item) => item.text === 'Custom template')).toBe(false); expect(exportItems.some((item) => item.text === 'Default template')).toBe(false); From 2d31a80df86a1d0ef9d01119754bbd0537775088 Mon Sep 17 00:00:00 2001 From: MelvinBot Date: Tue, 1 Sep 2026 10:57:10 +0000 Subject: [PATCH 5/9] Auto-expand a single-entry dropdown into its submenu in PopoverMenu Replaces the Search-specific flattening with a shouldAutoExpandSingleSubMenu prop on PopoverMenu/ButtonWithDropdownMenu, so any dropdown whose top level collapses to one submenu-only entry opens directly onto that submenu. The auto-expanded submenu is the effective root, so it renders no back button. Co-authored-by: Yauheni Horbach --- .../ButtonWithDropdownMenu/index.tsx | 2 + .../ButtonWithDropdownMenu/types.ts | 6 + src/components/PopoverMenu/index.tsx | 59 +++++++--- .../Search/SearchBulkActionsButton.tsx | 2 + src/hooks/useSearchBulkActions.ts | 30 +---- tests/ui/components/PopoverMenu.tsx | 109 ++++++++++++++++++ .../hooks/useSearchBulkActionsExportTest.ts | 78 +++---------- tests/unit/hooks/useSearchBulkActionsTest.ts | 34 +++--- 8 files changed, 200 insertions(+), 120 deletions(-) diff --git a/src/components/ButtonWithDropdownMenu/index.tsx b/src/components/ButtonWithDropdownMenu/index.tsx index 54bba0bf798a..4c1019970e12 100644 --- a/src/components/ButtonWithDropdownMenu/index.tsx +++ b/src/components/ButtonWithDropdownMenu/index.tsx @@ -62,6 +62,7 @@ function ButtonWithDropdownMenu({ref, ...props}: ButtonWithDropdownM isDisabled = false, pressOnEnter = false, shouldAlwaysShowDropdownMenu = false, + shouldAutoExpandSingleSubMenu = false, menuHeaderText = '', customText, style, @@ -325,6 +326,7 @@ function ButtonWithDropdownMenu({ref, ...props}: ButtonWithDropdownM {(shouldAlwaysShowDropdownMenu || options.length > 1) && !!popoverAnchorPosition && ( { setIsMenuVisible(false); onOptionsMenuHide?.(); diff --git a/src/components/ButtonWithDropdownMenu/types.ts b/src/components/ButtonWithDropdownMenu/types.ts index 58197b6fe639..72e42cb8da32 100644 --- a/src/components/ButtonWithDropdownMenu/types.ts +++ b/src/components/ButtonWithDropdownMenu/types.ts @@ -130,6 +130,12 @@ type ButtonWithDropdownMenuProps = WithSentryLabel & { /** Whether the dropdown menu should be shown even if it has only one option */ shouldAlwaysShowDropdownMenu?: boolean; + /** + * When the dropdown collapses to a single option that only leads to a submenu (no choice of its own), + * open directly into that submenu instead of making the user select the single option first. + */ + shouldAutoExpandSingleSubMenu?: boolean; + /** Additional style to add to the wrapper */ wrapperStyle?: StyleProp; diff --git a/src/components/PopoverMenu/index.tsx b/src/components/PopoverMenu/index.tsx index f6b51c0c7f5b..9305d6608034 100644 --- a/src/components/PopoverMenu/index.tsx +++ b/src/components/PopoverMenu/index.tsx @@ -128,6 +128,12 @@ type PopoverMenuProps = Partial & { /** Menu items to be rendered on the list */ menuItems: PopoverMenuItem[]; + /** + * When the top level collapses to a single entry that only leads to a submenu (no choice of its own), + * open directly into that submenu instead of making the user select the single entry first. + */ + shouldAutoExpandSingleSubMenu?: boolean; + /** Optional non-interactive text to display as a header for any create menu */ headerText?: string; @@ -308,6 +314,23 @@ function resolveIndexPathByKeyPath(root: PopoverMenuItem[], keyPath: string[]) { return {found: true as const, indexes, itemsAtLeaf: level}; } +/** + * When the top level of the menu collapses to a single entry that itself just leads to a submenu (e.g. an "Export" + * button that is the only bulk action available), that entry point carries no choice of its own — forcing the user + * to open it before they can see any real options. In that case, land directly on the submenu (as if the user had + * already selected that single entry) so opening the menu goes one level deeper instead of two. + * + * The returned `indexes` length doubles as the depth of the menu's effective root: everything the user sees at that + * depth is the top level, so no back button and no header belong there. + */ +function getInitialMenuState(menuItems: PopoverMenuItem[], shouldAutoExpandSingleSubMenu?: boolean): {items: PopoverMenuItem[]; indexes: readonly number[]} { + const soleItem = menuItems.length === 1 ? menuItems.at(0) : undefined; + if (shouldAutoExpandSingleSubMenu && soleItem?.subMenuItems?.length) { + return {items: soleItem.subMenuItems, indexes: [0]}; + } + return {items: menuItems, indexes: CONST.EMPTY_ARRAY}; +} + function PopoverMenu(props: PopoverMenuProps) { const wasVisible = usePrevious(props.isVisible); // Do not render the PopoverMenu before it gets opened. Until then both values are false @@ -319,6 +342,7 @@ function PopoverMenu(props: PopoverMenuProps) { function BasePopoverMenu({ menuItems, + shouldAutoExpandSingleSubMenu, onItemSelected, isVisible, anchorPosition, @@ -368,9 +392,12 @@ function BasePopoverMenu({ // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth const {isSmallScreenWidth, isInLandscapeMode} = useResponsiveLayout(); const {windowHeight} = useWindowDimensions(); - const [currentMenuItems, setCurrentMenuItems] = useState(menuItems); + const [currentMenuItems, setCurrentMenuItems] = useState(() => getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu).items); const currentMenuItemsFocusedIndex = getSelectedItemIndex(currentMenuItems); - const [enteredSubMenuIndexes, setEnteredSubMenuIndexes] = useState(CONST.EMPTY_ARRAY); + const [enteredSubMenuIndexes, setEnteredSubMenuIndexes] = useState(() => getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu).indexes); + // Depth of the menu's effective root. It is 0 normally, and 1 once a single-entry top level has been auto-expanded + // into its submenu — at that depth the user is looking at the top level, so there is nothing to go back to. + const rootDepth = getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu).indexes.length; const isWeb = getPlatform() === CONST.PLATFORM.WEB; const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({ initialFocusedIndex: currentMenuItemsFocusedIndex, @@ -400,7 +427,7 @@ function BasePopoverMenu({ return currentItems; }; - const isRadioButtonMode = enteredSubMenuIndexes.length === 0 ? shouldShowRadioButton : !!getPreviousSubMenu().at(enteredSubMenuIndexes.at(-1) ?? -1)?.shouldShowRadioButton; + const isRadioButtonMode = enteredSubMenuIndexes.length === rootDepth ? shouldShowRadioButton : !!getPreviousSubMenu().at(enteredSubMenuIndexes.at(-1) ?? -1)?.shouldShowRadioButton; // In radio-button mode, suppress the visual highlight until the user starts navigating, // even though the selected item is already focused (for immediate Enter/arrow support). @@ -558,7 +585,7 @@ function BasePopoverMenu({ }); const renderHeaderText = () => { - if (!headerText || enteredSubMenuIndexes.length !== 0) { + if (!headerText || enteredSubMenuIndexes.length !== rootDepth) { return; } return ( @@ -626,10 +653,11 @@ function BasePopoverMenu({ const keyPath = buildKeyPathFromIndexPath(prevMenuItems ?? menuItems, enteredSubMenuIndexes); if (keyPath.length === 0) { - setEnteredSubMenuIndexes(CONST.EMPTY_ARRAY); - setCurrentMenuItems(menuItems); + const initialMenuState = getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu); + setEnteredSubMenuIndexes(initialMenuState.indexes); + setCurrentMenuItems(initialMenuState.items); if (!isVisible) { - setFocusedIndex(getSelectedItemIndex(menuItems)); + setFocusedIndex(getSelectedItemIndex(initialMenuState.items)); } return; } @@ -645,10 +673,11 @@ function BasePopoverMenu({ return; } - setEnteredSubMenuIndexes(CONST.EMPTY_ARRAY); - setCurrentMenuItems(menuItems); + const initialMenuState = getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu); + setEnteredSubMenuIndexes(initialMenuState.indexes); + setCurrentMenuItems(initialMenuState.items); if (!isVisible) { - setFocusedIndex(getSelectedItemIndex(menuItems)); + setFocusedIndex(getSelectedItemIndex(initialMenuState.items)); } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -709,8 +738,9 @@ function BasePopoverMenu({ anchorRef={anchorRef} anchorAlignment={anchorAlignment} onClose={() => { - setCurrentMenuItems(menuItems); - setEnteredSubMenuIndexes(CONST.EMPTY_ARRAY); + const initialMenuState = getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu); + setCurrentMenuItems(initialMenuState.items); + setEnteredSubMenuIndexes(initialMenuState.indexes); onClose(); }} isVisible={isVisible} @@ -751,7 +781,7 @@ function BasePopoverMenu({ addBottomSafeAreaPadding={enableEdgeToEdgeBottomSafeAreaPadding} > {renderHeaderText()} - {enteredSubMenuIndexes.length > 0 && renderBackButtonItem()} + {enteredSubMenuIndexes.length > rootDepth && renderBackButtonItem()} {renderedMenuItems} @@ -782,7 +812,8 @@ export default React.memo( prevProps.shouldEnableNewFocusManagement === nextProps.shouldEnableNewFocusManagement && prevProps.shouldReturnFocus === nextProps.shouldReturnFocus && prevProps.restoreFocusType === nextProps.restoreFocusType && - prevProps.shouldSetModalVisibility === nextProps.shouldSetModalVisibility, + prevProps.shouldSetModalVisibility === nextProps.shouldSetModalVisibility && + prevProps.shouldAutoExpandSingleSubMenu === nextProps.shouldAutoExpandSingleSubMenu, ); export type {PopoverMenuItem, PopoverMenuProps}; export {getItemKey, buildKeyPathFromIndexPath, resolveIndexPathByKeyPath}; diff --git a/src/components/Search/SearchBulkActionsButton.tsx b/src/components/Search/SearchBulkActionsButton.tsx index d3752eda834e..762db8bb0f4c 100644 --- a/src/components/Search/SearchBulkActionsButton.tsx +++ b/src/components/Search/SearchBulkActionsButton.tsx @@ -226,6 +226,7 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) { customText={selectionButtonText} isLoading={isAllMatchingItemsCountLoading} shouldAlwaysShowDropdownMenu + shouldAutoExpandSingleSubMenu isDisabled={headerButtonsOptions.length === 0} onPress={() => null} shouldPopoverUseScrollView={popoverUseScrollView} @@ -247,6 +248,7 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) { variant={CONST.BUTTON_VARIANT.SUCCESS} onPress={() => null} shouldAlwaysShowDropdownMenu + shouldAutoExpandSingleSubMenu customText={selectionButtonText} isLoading={isAllMatchingItemsCountLoading} options={headerButtonsOptions} diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index 1fc2d6252dc8..c7c298a6c43a 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -420,13 +420,6 @@ function getChatReportForBulkPay( return getReportFromSearchSnapshot(resolvedChatReportID, searchData, allReports) ?? getReportOrDraftReport(resolvedChatReportID); } -/** - * A single export option. It is typed as a dropdown option rather than a plain menu item because it is rendered at - * either level of the bulk-action dropdown: nested inside the Export submenu, or directly at the top level when - * Export is the only bulk action available. - */ -type ExportMenuItem = DropdownOption & Pick; - function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const {translate, localeCompare} = useLocalize(); const styles = useThemeStyles(); @@ -1794,7 +1787,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { ? defaultTemplates.filter((template) => template.templateName === CONST.REPORT.EXPORT_OPTIONS.DOWNLOAD_CSV) : defaultTemplates; - const exportOptions: ExportMenuItem[] = []; + const exportOptions: PopoverMenuItem[] = []; const isReportsTab = isExpenseReportType; const includesGroupExport = isGroupedSearch && Object.entries(selectedTransactions).some(([key, selectedTransaction]) => isGroupSelection(key, selectedTransaction)); @@ -2005,7 +1998,6 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const handleExportAction = buildIntegrationHandleExportAction(exportableReportIDs, integration, integrationGroupSize, true, connectionNameFriendly); exportOptions.push({ text: connectionNameFriendly, - value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: integrationIcon, onSelected: () => handleExportAction(() => exportToIntegrationOnSearch(hash, exportableReportIDs, integration, integrationPolicy, currentSearchKey)), shouldCloseModalOnSelect: true, @@ -2023,7 +2015,6 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const handleMarkAction = buildIntegrationHandleExportAction(reportIDsToMark, integration, integrationGroupSize, false, connectionNameFriendly); exportOptions.push({ text: translate('workspace.common.markAsExported'), - value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, // Every integration's "Mark as exported" option shares the same visible text and differs only by icon, // which screen readers can't announce. Append the integration name so assistive tech can distinguish them. accessibilityLabel: `${translate('workspace.common.markAsExported')}, ${connectionNameFriendly}`, @@ -2040,7 +2031,6 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { // "Current view" is pinned directly under the accounting actions. exportOptions.push({ text: translate('export.currentView'), - value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: expensifyIcons.Table, onSelected: () => { handleExportCurrentView(); @@ -2053,12 +2043,11 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { if (!allSelectedAreDeleted && !includesGroupExport) { // Builds a single export sub-menu item for a template. `isDefaultTemplate` picks the icon and `addSeparatorBefore` draws the divider at the top of each group. - const buildExportOption = (template: ExportTemplate, isDefaultTemplate: boolean, addSeparatorBefore: boolean): ExportMenuItem => { + const buildExportOption = (template: ExportTemplate, isDefaultTemplate: boolean, addSeparatorBefore: boolean): PopoverMenuItem => { // The basic export is a plain CSV download, so it uses its own handler rather than the template export flow const isBasicExport = template.templateName === CONST.REPORT.EXPORT_OPTIONS.DOWNLOAD_CSV; return { text: template.name, - value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: isDefaultTemplate ? expensifyIcons.Table : expensifyIcons.TablePencil, description: template.description, onSelected: () => { @@ -2085,7 +2074,6 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { // The templates aren't available for this selection, but the basic export (a plain CSV download) still is exportOptions.push({ text: translate('export.basicExport'), - value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: expensifyIcons.Table, onSelected: () => { handleBasicExport(); @@ -2114,18 +2102,8 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { subMenuItems, }; - /** - * Export is sometimes the only bulk action available (most commonly under "select all"). There is no main menu - * to go back to then, so the dropdown opens directly onto the export options rather than nesting them behind - * an "Export" row whose submenu would render a back arrow leading nowhere. - */ - const openExportOptionsDirectlyIfSoleAction = (builtOptions: Array>): Array> => { - const isExportTheOnlyAction = builtOptions.length === 1 && builtOptions.at(0)?.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT; - return isExportTheOnlyAction && subMenuItems.length > 0 ? subMenuItems : builtOptions; - }; - if (areAllMatchingItemsSelected) { - return openExportOptionsDirectlyIfSoleAction([exportButtonOption]); + return [exportButtonOption]; } if (allSelectedAreDeleted) { @@ -2735,7 +2713,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { }); } - return openExportOptionsDirectlyIfSoleAction(options); + return options; }, [ selectedTransactionsKeys, hash, diff --git a/tests/ui/components/PopoverMenu.tsx b/tests/ui/components/PopoverMenu.tsx index 91c301523ddd..805f95631d17 100644 --- a/tests/ui/components/PopoverMenu.tsx +++ b/tests/ui/components/PopoverMenu.tsx @@ -358,6 +358,115 @@ describe('PopoverMenu integration — submenu open/close behaviors', () => { }); }); +describe('PopoverMenu integration — shouldAutoExpandSingleSubMenu', () => { + const soleItemMenu: PopoverMenuItem[] = [ + { + text: 'Export', + key: 'Export', + backButtonText: 'Export', + subMenuItems: [{text: 'Current view', key: 'CurrentView'}], + }, + ]; + + const multiItemMenu: PopoverMenuItem[] = [ + { + text: 'Export', + key: 'Export', + subMenuItems: [{text: 'Current view', key: 'CurrentView'}], + }, + {text: 'Delete', key: 'Delete'}, + ]; + + const nestedSoleItemMenu: PopoverMenuItem[] = [ + { + text: 'Export', + key: 'Export', + backButtonText: 'Export', + subMenuItems: [ + { + text: 'Templates', + key: 'Templates', + backButtonText: 'Templates', + subMenuItems: [{text: 'Template A', key: 'TemplateA'}], + }, + ], + }, + ]; + + const anchorRef = React.createRef(); + const anchorPosition = {horizontal: 0, vertical: 0}; + + const renderPopover = (menuItems: PopoverMenuItem[], shouldAutoExpandSingleSubMenu?: boolean) => + render( + {}} + anchorPosition={anchorPosition} + anchorRef={anchorRef} + />, + ); + + it('opens directly onto the submenu when the top level is a single item with subMenuItems', async () => { + renderPopover(soleItemMenu, true); + + // The submenu item is already visible, no click on "Export" needed + await waitFor(() => { + expect(screen.getByTestId('PopoverMenuItem-Current view')).toBeTruthy(); + }); + expect(screen.queryByTestId('PopoverMenuItem-Export')).toBeNull(); + }); + + it('does not render a back button on the auto-expanded submenu', async () => { + renderPopover(soleItemMenu, true); + + await waitFor(() => { + expect(screen.getByTestId('PopoverMenuItem-Current view')).toBeTruthy(); + }); + + // The auto-expanded submenu IS the top level, so there is no main menu to go back to. The back button would + // be titled with the sole item's backButtonText, so no "Export" text may appear anywhere. + expect(screen.queryByText('Export')).toBeNull(); + }); + + it('renders a back button once the user navigates deeper than the auto-expanded level', async () => { + renderPopover(nestedSoleItemMenu, true); + + await waitFor(() => { + expect(screen.getByTestId('PopoverMenuItem-Templates')).toBeTruthy(); + }); + + fireEvent.press(screen.getByTestId('PopoverMenuItem-Templates')); + + await waitFor(() => { + expect(screen.getByTestId('PopoverMenuItem-Template A')).toBeTruthy(); + }); + + // "Templates" is no longer a menu row here, so this text can only come from the back button + expect(screen.getByText('Templates')).toBeTruthy(); + }); + + it('does not auto-expand when the prop is not set', async () => { + renderPopover(soleItemMenu); + + await waitFor(() => { + expect(screen.getByTestId('PopoverMenuItem-Export')).toBeTruthy(); + }); + expect(screen.queryByTestId('PopoverMenuItem-Current view')).toBeNull(); + }); + + it('does not auto-expand when there is more than one top-level item', async () => { + renderPopover(multiItemMenu, true); + + await waitFor(() => { + expect(screen.getByTestId('PopoverMenuItem-Export')).toBeTruthy(); + expect(screen.getByTestId('PopoverMenuItem-Delete')).toBeTruthy(); + }); + expect(screen.queryByTestId('PopoverMenuItem-Current view')).toBeNull(); + }); +}); + describe('PopoverMenu integration — focus policy and close lifecycle', () => { const anchorRef = React.createRef(); const anchorPosition = {horizontal: 0, vertical: 0}; diff --git a/tests/unit/hooks/useSearchBulkActionsExportTest.ts b/tests/unit/hooks/useSearchBulkActionsExportTest.ts index 72a193eab369..9ab40d90d15d 100644 --- a/tests/unit/hooks/useSearchBulkActionsExportTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsExportTest.ts @@ -390,27 +390,22 @@ function makeSearchResults(reports: Report[], reportActionsByReportID: Record['headerButtonsOptions']) { - const exportOptions = headerButtonsOptions.filter((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - return exportOptions.at(0)?.subMenuItems ?? exportOptions; +function getExportSubMenuItems(headerButtonsOptions: ReturnType['headerButtonsOptions']) { + return headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)?.subMenuItems; } function getExportOptionTexts(headerButtonsOptions: ReturnType['headerButtonsOptions']) { - return getExportMenuItems(headerButtonsOptions).map((item) => item.text); + const exportOption = headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + return exportOption?.subMenuItems?.map((item) => item.text) ?? (exportOption ? [exportOption.text] : []); } +/** Export options live inside the Export submenu, but tolerate a flat top-level shape too so callers stay robust. */ function getExportOptionByText(headerButtonsOptions: ReturnType['headerButtonsOptions'], text: string) { - return getExportMenuItems(headerButtonsOptions).find((item) => item.text === text); -} - -/** The Export entry's nested submenu items. Only valid for selections where Export is not the only bulk action. */ -function getExportSubMenuItems(headerButtonsOptions: ReturnType['headerButtonsOptions']) { - return headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)?.subMenuItems; + const exportOption = headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + if (!exportOption) { + return undefined; + } + return exportOption.subMenuItems?.find((item) => item.text === text) ?? (exportOption.text === text ? exportOption : undefined); } /** The parameters the last plain-CSV export sent to the backend, with the serialized query parsed back. */ @@ -520,9 +515,10 @@ describe('useSearchBulkActions - export options', () => { expect(result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)).toBeDefined(); }); - const exportMenuItems = getExportMenuItems(result.current.headerButtonsOptions); - expect(exportMenuItems.some((item) => item.text === NETSUITE_FRIENDLY_NAME)).toBe(false); - expect(exportMenuItems.some((item) => item.text === 'workspace.common.markAsExported')).toBe(false); + const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + const subMenuItems = exportOption?.subMenuItems ?? []; + expect(subMenuItems.some((item) => item.text === NETSUITE_FRIENDLY_NAME)).toBe(false); + expect(subMenuItems.some((item) => item.text === 'workspace.common.markAsExported')).toBe(false); }); it('offers per-integration export options when reports span workspaces connected to different integrations', async () => { @@ -1151,14 +1147,12 @@ describe('useSearchBulkActions - export options', () => { it('keeps the Export entry as a submenu even when only one export option is available', async () => { // Regression test for https://github.com/Expensify/App/issues/98779: a full group selection offers a single - // export option ('export.currentView'). While other bulk actions sit alongside it (Hold here), the Export - // entry must still open the Export submenu (keeping its generic label and subMenuItems) rather than - // collapsing straight into that single option. + // export option ('export.currentView'). The Export entry must still open the Export submenu (keeping its + // generic label and subMenuItems) rather than collapsing straight into that single option. mockSelectedTransactions = { tx1: makeSelectedTransaction({ groupKey: `${CONST.SEARCH.GROUP_PREFIX}category`, isSelectedViaGroup: true, - canHold: true, }), }; @@ -1173,46 +1167,6 @@ describe('useSearchBulkActions - export options', () => { expect(exportOption?.text).toBe('common.export'); }); - it('opens directly onto the single export option when Export is the only bulk action', async () => { - // Export is the only bulk action offered under select all, so there is no main menu to go back to. The one - // export option is surfaced directly instead of behind an "Export" row whose submenu would render a back - // arrow leading nowhere. - mockAreAllMatchingItemsSelected = true; - mockSelectedTransactions = { - tx1: makeSelectedTransaction({ - groupKey: `${CONST.SEARCH.GROUP_PREFIX}category`, - isSelectedViaGroup: true, - }), - }; - - const {result} = renderHook(() => useSearchBulkActions({queryJSON: groupedExpenseQueryJSON}), {wrapper: OnyxListItemProvider}); - - await waitFor(() => { - expect(result.current.headerButtonsOptions.map((option) => option.text)).toEqual(['export.currentView']); - }); - - const soleOption = result.current.headerButtonsOptions.at(0); - expect(soleOption?.value).toBe(CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - expect(soleOption?.subMenuItems).toBeUndefined(); - expect(soleOption?.backButtonText).toBeUndefined(); - }); - - it('opens directly onto every export option when Export is the only bulk action', async () => { - mockAreAllMatchingItemsSelected = true; - mockSelectedTransactions = {tx1: makeSelectedTransaction()}; - - const {result} = renderHook(() => useSearchBulkActions({queryJSON: groupedExpenseQueryJSON}), {wrapper: OnyxListItemProvider}); - - await waitFor(() => { - expect(result.current.headerButtonsOptions.length).toBeGreaterThan(1); - }); - - // Every entry is an export option itself — there is no "Export" row wrapping them and so no back arrow. - expect(result.current.headerButtonsOptions.every((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)).toBe(true); - expect(result.current.headerButtonsOptions.some((option) => option.text === 'common.export')).toBe(false); - expect(result.current.headerButtonsOptions.some((option) => !!option.subMenuItems)).toBe(false); - }); - it('exports the current view of a grouped search with the default expense columns', async () => { mockSelectedTransactions = {tx1: makeSelectedTransaction()}; diff --git a/tests/unit/hooks/useSearchBulkActionsTest.ts b/tests/unit/hooks/useSearchBulkActionsTest.ts index bf7e20e6b0d6..d93434449e18 100644 --- a/tests/unit/hooks/useSearchBulkActionsTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsTest.ts @@ -241,16 +241,6 @@ function hasSearchFlatFilters(value: unknown): value is {flatFilters: SearchQuer return typeof value === 'object' && value !== null && 'flatFilters' in value && Array.isArray(value.flatFilters); } -/** - * The export options take one of two shapes: normally they sit inside the Export entry's `subMenuItems`, but when - * Export is the only bulk action available the dropdown opens straight onto them, so they sit at the top level of - * `headerButtonsOptions` with the EXPORT value on each one. - */ -function getExportMenuItems(headerButtonsOptions: ReturnType['headerButtonsOptions']) { - const exportOptions = headerButtonsOptions.filter((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - return exportOptions.at(0)?.subMenuItems ?? exportOptions; -} - describe('useSearchBulkActions - CSV export flow', () => { beforeAll(() => { Onyx.init({keys: ONYXKEYS}); @@ -285,8 +275,10 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; - expect(onSelected).toBeDefined(); + const exportOption = result.current.headerButtonsOptions.find((o) => o.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + expect(exportOption).toBeDefined(); + + const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; await act(async () => { onSelected?.(); @@ -314,7 +306,8 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; + const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; await act(async () => { onSelected?.(); @@ -366,7 +359,8 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; + const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; await act(async () => { onSelected?.(); @@ -405,7 +399,8 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; + const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; await act(async () => { onSelected?.(); @@ -447,7 +442,8 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; + const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; await act(async () => { onSelected?.(); @@ -485,7 +481,8 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const templateSubItem = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text !== 'export.basicExport' && item.text !== 'export.currentView'); + const exportOption = result.current.headerButtonsOptions.find((o) => o.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + const templateSubItem = exportOption?.subMenuItems?.find((item) => item.text !== 'export.basicExport' && item.text !== 'export.currentView'); expect(templateSubItem).toBeDefined(); act(() => { @@ -519,7 +516,8 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportItems = getExportMenuItems(result.current.headerButtonsOptions); + const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + const exportItems = exportOption?.subMenuItems ?? []; expect(exportItems.some((item) => item.text === 'Custom template')).toBe(false); expect(exportItems.some((item) => item.text === 'Default template')).toBe(false); From f01734fbb1aff9723e6b065daf5643a1a0a58525 Mon Sep 17 00:00:00 2001 From: MelvinBot Date: Tue, 1 Sep 2026 11:32:47 +0000 Subject: [PATCH 6/9] Revert the universal PopoverMenu auto-expand in favour of the Search-specific flattening This reverts commit 2d31a80df86a1d0ef9d01119754bbd0537775088, restoring the useSearchBulkActions approach: the hook surfaces the export options directly when Export is the only bulk action, instead of PopoverMenu auto-expanding a sole submenu entry. Co-authored-by: Yauheni Horbach --- .../ButtonWithDropdownMenu/index.tsx | 2 - .../ButtonWithDropdownMenu/types.ts | 6 - src/components/PopoverMenu/index.tsx | 59 +++------- .../Search/SearchBulkActionsButton.tsx | 2 - src/hooks/useSearchBulkActions.ts | 30 ++++- tests/ui/components/PopoverMenu.tsx | 109 ------------------ .../hooks/useSearchBulkActionsExportTest.ts | 78 ++++++++++--- tests/unit/hooks/useSearchBulkActionsTest.ts | 34 +++--- 8 files changed, 120 insertions(+), 200 deletions(-) diff --git a/src/components/ButtonWithDropdownMenu/index.tsx b/src/components/ButtonWithDropdownMenu/index.tsx index 4c1019970e12..54bba0bf798a 100644 --- a/src/components/ButtonWithDropdownMenu/index.tsx +++ b/src/components/ButtonWithDropdownMenu/index.tsx @@ -62,7 +62,6 @@ function ButtonWithDropdownMenu({ref, ...props}: ButtonWithDropdownM isDisabled = false, pressOnEnter = false, shouldAlwaysShowDropdownMenu = false, - shouldAutoExpandSingleSubMenu = false, menuHeaderText = '', customText, style, @@ -326,7 +325,6 @@ function ButtonWithDropdownMenu({ref, ...props}: ButtonWithDropdownM {(shouldAlwaysShowDropdownMenu || options.length > 1) && !!popoverAnchorPosition && ( { setIsMenuVisible(false); onOptionsMenuHide?.(); diff --git a/src/components/ButtonWithDropdownMenu/types.ts b/src/components/ButtonWithDropdownMenu/types.ts index 72e42cb8da32..58197b6fe639 100644 --- a/src/components/ButtonWithDropdownMenu/types.ts +++ b/src/components/ButtonWithDropdownMenu/types.ts @@ -130,12 +130,6 @@ type ButtonWithDropdownMenuProps = WithSentryLabel & { /** Whether the dropdown menu should be shown even if it has only one option */ shouldAlwaysShowDropdownMenu?: boolean; - /** - * When the dropdown collapses to a single option that only leads to a submenu (no choice of its own), - * open directly into that submenu instead of making the user select the single option first. - */ - shouldAutoExpandSingleSubMenu?: boolean; - /** Additional style to add to the wrapper */ wrapperStyle?: StyleProp; diff --git a/src/components/PopoverMenu/index.tsx b/src/components/PopoverMenu/index.tsx index 9305d6608034..f6b51c0c7f5b 100644 --- a/src/components/PopoverMenu/index.tsx +++ b/src/components/PopoverMenu/index.tsx @@ -128,12 +128,6 @@ type PopoverMenuProps = Partial & { /** Menu items to be rendered on the list */ menuItems: PopoverMenuItem[]; - /** - * When the top level collapses to a single entry that only leads to a submenu (no choice of its own), - * open directly into that submenu instead of making the user select the single entry first. - */ - shouldAutoExpandSingleSubMenu?: boolean; - /** Optional non-interactive text to display as a header for any create menu */ headerText?: string; @@ -314,23 +308,6 @@ function resolveIndexPathByKeyPath(root: PopoverMenuItem[], keyPath: string[]) { return {found: true as const, indexes, itemsAtLeaf: level}; } -/** - * When the top level of the menu collapses to a single entry that itself just leads to a submenu (e.g. an "Export" - * button that is the only bulk action available), that entry point carries no choice of its own — forcing the user - * to open it before they can see any real options. In that case, land directly on the submenu (as if the user had - * already selected that single entry) so opening the menu goes one level deeper instead of two. - * - * The returned `indexes` length doubles as the depth of the menu's effective root: everything the user sees at that - * depth is the top level, so no back button and no header belong there. - */ -function getInitialMenuState(menuItems: PopoverMenuItem[], shouldAutoExpandSingleSubMenu?: boolean): {items: PopoverMenuItem[]; indexes: readonly number[]} { - const soleItem = menuItems.length === 1 ? menuItems.at(0) : undefined; - if (shouldAutoExpandSingleSubMenu && soleItem?.subMenuItems?.length) { - return {items: soleItem.subMenuItems, indexes: [0]}; - } - return {items: menuItems, indexes: CONST.EMPTY_ARRAY}; -} - function PopoverMenu(props: PopoverMenuProps) { const wasVisible = usePrevious(props.isVisible); // Do not render the PopoverMenu before it gets opened. Until then both values are false @@ -342,7 +319,6 @@ function PopoverMenu(props: PopoverMenuProps) { function BasePopoverMenu({ menuItems, - shouldAutoExpandSingleSubMenu, onItemSelected, isVisible, anchorPosition, @@ -392,12 +368,9 @@ function BasePopoverMenu({ // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth const {isSmallScreenWidth, isInLandscapeMode} = useResponsiveLayout(); const {windowHeight} = useWindowDimensions(); - const [currentMenuItems, setCurrentMenuItems] = useState(() => getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu).items); + const [currentMenuItems, setCurrentMenuItems] = useState(menuItems); const currentMenuItemsFocusedIndex = getSelectedItemIndex(currentMenuItems); - const [enteredSubMenuIndexes, setEnteredSubMenuIndexes] = useState(() => getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu).indexes); - // Depth of the menu's effective root. It is 0 normally, and 1 once a single-entry top level has been auto-expanded - // into its submenu — at that depth the user is looking at the top level, so there is nothing to go back to. - const rootDepth = getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu).indexes.length; + const [enteredSubMenuIndexes, setEnteredSubMenuIndexes] = useState(CONST.EMPTY_ARRAY); const isWeb = getPlatform() === CONST.PLATFORM.WEB; const [focusedIndex, setFocusedIndex] = useArrowKeyFocusManager({ initialFocusedIndex: currentMenuItemsFocusedIndex, @@ -427,7 +400,7 @@ function BasePopoverMenu({ return currentItems; }; - const isRadioButtonMode = enteredSubMenuIndexes.length === rootDepth ? shouldShowRadioButton : !!getPreviousSubMenu().at(enteredSubMenuIndexes.at(-1) ?? -1)?.shouldShowRadioButton; + const isRadioButtonMode = enteredSubMenuIndexes.length === 0 ? shouldShowRadioButton : !!getPreviousSubMenu().at(enteredSubMenuIndexes.at(-1) ?? -1)?.shouldShowRadioButton; // In radio-button mode, suppress the visual highlight until the user starts navigating, // even though the selected item is already focused (for immediate Enter/arrow support). @@ -585,7 +558,7 @@ function BasePopoverMenu({ }); const renderHeaderText = () => { - if (!headerText || enteredSubMenuIndexes.length !== rootDepth) { + if (!headerText || enteredSubMenuIndexes.length !== 0) { return; } return ( @@ -653,11 +626,10 @@ function BasePopoverMenu({ const keyPath = buildKeyPathFromIndexPath(prevMenuItems ?? menuItems, enteredSubMenuIndexes); if (keyPath.length === 0) { - const initialMenuState = getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu); - setEnteredSubMenuIndexes(initialMenuState.indexes); - setCurrentMenuItems(initialMenuState.items); + setEnteredSubMenuIndexes(CONST.EMPTY_ARRAY); + setCurrentMenuItems(menuItems); if (!isVisible) { - setFocusedIndex(getSelectedItemIndex(initialMenuState.items)); + setFocusedIndex(getSelectedItemIndex(menuItems)); } return; } @@ -673,11 +645,10 @@ function BasePopoverMenu({ return; } - const initialMenuState = getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu); - setEnteredSubMenuIndexes(initialMenuState.indexes); - setCurrentMenuItems(initialMenuState.items); + setEnteredSubMenuIndexes(CONST.EMPTY_ARRAY); + setCurrentMenuItems(menuItems); if (!isVisible) { - setFocusedIndex(getSelectedItemIndex(initialMenuState.items)); + setFocusedIndex(getSelectedItemIndex(menuItems)); } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -738,9 +709,8 @@ function BasePopoverMenu({ anchorRef={anchorRef} anchorAlignment={anchorAlignment} onClose={() => { - const initialMenuState = getInitialMenuState(menuItems, shouldAutoExpandSingleSubMenu); - setCurrentMenuItems(initialMenuState.items); - setEnteredSubMenuIndexes(initialMenuState.indexes); + setCurrentMenuItems(menuItems); + setEnteredSubMenuIndexes(CONST.EMPTY_ARRAY); onClose(); }} isVisible={isVisible} @@ -781,7 +751,7 @@ function BasePopoverMenu({ addBottomSafeAreaPadding={enableEdgeToEdgeBottomSafeAreaPadding} > {renderHeaderText()} - {enteredSubMenuIndexes.length > rootDepth && renderBackButtonItem()} + {enteredSubMenuIndexes.length > 0 && renderBackButtonItem()} {renderedMenuItems} @@ -812,8 +782,7 @@ export default React.memo( prevProps.shouldEnableNewFocusManagement === nextProps.shouldEnableNewFocusManagement && prevProps.shouldReturnFocus === nextProps.shouldReturnFocus && prevProps.restoreFocusType === nextProps.restoreFocusType && - prevProps.shouldSetModalVisibility === nextProps.shouldSetModalVisibility && - prevProps.shouldAutoExpandSingleSubMenu === nextProps.shouldAutoExpandSingleSubMenu, + prevProps.shouldSetModalVisibility === nextProps.shouldSetModalVisibility, ); export type {PopoverMenuItem, PopoverMenuProps}; export {getItemKey, buildKeyPathFromIndexPath, resolveIndexPathByKeyPath}; diff --git a/src/components/Search/SearchBulkActionsButton.tsx b/src/components/Search/SearchBulkActionsButton.tsx index 762db8bb0f4c..d3752eda834e 100644 --- a/src/components/Search/SearchBulkActionsButton.tsx +++ b/src/components/Search/SearchBulkActionsButton.tsx @@ -226,7 +226,6 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) { customText={selectionButtonText} isLoading={isAllMatchingItemsCountLoading} shouldAlwaysShowDropdownMenu - shouldAutoExpandSingleSubMenu isDisabled={headerButtonsOptions.length === 0} onPress={() => null} shouldPopoverUseScrollView={popoverUseScrollView} @@ -248,7 +247,6 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) { variant={CONST.BUTTON_VARIANT.SUCCESS} onPress={() => null} shouldAlwaysShowDropdownMenu - shouldAutoExpandSingleSubMenu customText={selectionButtonText} isLoading={isAllMatchingItemsCountLoading} options={headerButtonsOptions} diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index c7c298a6c43a..1fc2d6252dc8 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -420,6 +420,13 @@ function getChatReportForBulkPay( return getReportFromSearchSnapshot(resolvedChatReportID, searchData, allReports) ?? getReportOrDraftReport(resolvedChatReportID); } +/** + * A single export option. It is typed as a dropdown option rather than a plain menu item because it is rendered at + * either level of the bulk-action dropdown: nested inside the Export submenu, or directly at the top level when + * Export is the only bulk action available. + */ +type ExportMenuItem = DropdownOption & Pick; + function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const {translate, localeCompare} = useLocalize(); const styles = useThemeStyles(); @@ -1787,7 +1794,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { ? defaultTemplates.filter((template) => template.templateName === CONST.REPORT.EXPORT_OPTIONS.DOWNLOAD_CSV) : defaultTemplates; - const exportOptions: PopoverMenuItem[] = []; + const exportOptions: ExportMenuItem[] = []; const isReportsTab = isExpenseReportType; const includesGroupExport = isGroupedSearch && Object.entries(selectedTransactions).some(([key, selectedTransaction]) => isGroupSelection(key, selectedTransaction)); @@ -1998,6 +2005,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const handleExportAction = buildIntegrationHandleExportAction(exportableReportIDs, integration, integrationGroupSize, true, connectionNameFriendly); exportOptions.push({ text: connectionNameFriendly, + value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: integrationIcon, onSelected: () => handleExportAction(() => exportToIntegrationOnSearch(hash, exportableReportIDs, integration, integrationPolicy, currentSearchKey)), shouldCloseModalOnSelect: true, @@ -2015,6 +2023,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const handleMarkAction = buildIntegrationHandleExportAction(reportIDsToMark, integration, integrationGroupSize, false, connectionNameFriendly); exportOptions.push({ text: translate('workspace.common.markAsExported'), + value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, // Every integration's "Mark as exported" option shares the same visible text and differs only by icon, // which screen readers can't announce. Append the integration name so assistive tech can distinguish them. accessibilityLabel: `${translate('workspace.common.markAsExported')}, ${connectionNameFriendly}`, @@ -2031,6 +2040,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { // "Current view" is pinned directly under the accounting actions. exportOptions.push({ text: translate('export.currentView'), + value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: expensifyIcons.Table, onSelected: () => { handleExportCurrentView(); @@ -2043,11 +2053,12 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { if (!allSelectedAreDeleted && !includesGroupExport) { // Builds a single export sub-menu item for a template. `isDefaultTemplate` picks the icon and `addSeparatorBefore` draws the divider at the top of each group. - const buildExportOption = (template: ExportTemplate, isDefaultTemplate: boolean, addSeparatorBefore: boolean): PopoverMenuItem => { + const buildExportOption = (template: ExportTemplate, isDefaultTemplate: boolean, addSeparatorBefore: boolean): ExportMenuItem => { // The basic export is a plain CSV download, so it uses its own handler rather than the template export flow const isBasicExport = template.templateName === CONST.REPORT.EXPORT_OPTIONS.DOWNLOAD_CSV; return { text: template.name, + value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: isDefaultTemplate ? expensifyIcons.Table : expensifyIcons.TablePencil, description: template.description, onSelected: () => { @@ -2074,6 +2085,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { // The templates aren't available for this selection, but the basic export (a plain CSV download) still is exportOptions.push({ text: translate('export.basicExport'), + value: CONST.SEARCH.BULK_ACTION_TYPES.EXPORT, icon: expensifyIcons.Table, onSelected: () => { handleBasicExport(); @@ -2102,8 +2114,18 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { subMenuItems, }; + /** + * Export is sometimes the only bulk action available (most commonly under "select all"). There is no main menu + * to go back to then, so the dropdown opens directly onto the export options rather than nesting them behind + * an "Export" row whose submenu would render a back arrow leading nowhere. + */ + const openExportOptionsDirectlyIfSoleAction = (builtOptions: Array>): Array> => { + const isExportTheOnlyAction = builtOptions.length === 1 && builtOptions.at(0)?.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT; + return isExportTheOnlyAction && subMenuItems.length > 0 ? subMenuItems : builtOptions; + }; + if (areAllMatchingItemsSelected) { - return [exportButtonOption]; + return openExportOptionsDirectlyIfSoleAction([exportButtonOption]); } if (allSelectedAreDeleted) { @@ -2713,7 +2735,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { }); } - return options; + return openExportOptionsDirectlyIfSoleAction(options); }, [ selectedTransactionsKeys, hash, diff --git a/tests/ui/components/PopoverMenu.tsx b/tests/ui/components/PopoverMenu.tsx index 805f95631d17..91c301523ddd 100644 --- a/tests/ui/components/PopoverMenu.tsx +++ b/tests/ui/components/PopoverMenu.tsx @@ -358,115 +358,6 @@ describe('PopoverMenu integration — submenu open/close behaviors', () => { }); }); -describe('PopoverMenu integration — shouldAutoExpandSingleSubMenu', () => { - const soleItemMenu: PopoverMenuItem[] = [ - { - text: 'Export', - key: 'Export', - backButtonText: 'Export', - subMenuItems: [{text: 'Current view', key: 'CurrentView'}], - }, - ]; - - const multiItemMenu: PopoverMenuItem[] = [ - { - text: 'Export', - key: 'Export', - subMenuItems: [{text: 'Current view', key: 'CurrentView'}], - }, - {text: 'Delete', key: 'Delete'}, - ]; - - const nestedSoleItemMenu: PopoverMenuItem[] = [ - { - text: 'Export', - key: 'Export', - backButtonText: 'Export', - subMenuItems: [ - { - text: 'Templates', - key: 'Templates', - backButtonText: 'Templates', - subMenuItems: [{text: 'Template A', key: 'TemplateA'}], - }, - ], - }, - ]; - - const anchorRef = React.createRef(); - const anchorPosition = {horizontal: 0, vertical: 0}; - - const renderPopover = (menuItems: PopoverMenuItem[], shouldAutoExpandSingleSubMenu?: boolean) => - render( - {}} - anchorPosition={anchorPosition} - anchorRef={anchorRef} - />, - ); - - it('opens directly onto the submenu when the top level is a single item with subMenuItems', async () => { - renderPopover(soleItemMenu, true); - - // The submenu item is already visible, no click on "Export" needed - await waitFor(() => { - expect(screen.getByTestId('PopoverMenuItem-Current view')).toBeTruthy(); - }); - expect(screen.queryByTestId('PopoverMenuItem-Export')).toBeNull(); - }); - - it('does not render a back button on the auto-expanded submenu', async () => { - renderPopover(soleItemMenu, true); - - await waitFor(() => { - expect(screen.getByTestId('PopoverMenuItem-Current view')).toBeTruthy(); - }); - - // The auto-expanded submenu IS the top level, so there is no main menu to go back to. The back button would - // be titled with the sole item's backButtonText, so no "Export" text may appear anywhere. - expect(screen.queryByText('Export')).toBeNull(); - }); - - it('renders a back button once the user navigates deeper than the auto-expanded level', async () => { - renderPopover(nestedSoleItemMenu, true); - - await waitFor(() => { - expect(screen.getByTestId('PopoverMenuItem-Templates')).toBeTruthy(); - }); - - fireEvent.press(screen.getByTestId('PopoverMenuItem-Templates')); - - await waitFor(() => { - expect(screen.getByTestId('PopoverMenuItem-Template A')).toBeTruthy(); - }); - - // "Templates" is no longer a menu row here, so this text can only come from the back button - expect(screen.getByText('Templates')).toBeTruthy(); - }); - - it('does not auto-expand when the prop is not set', async () => { - renderPopover(soleItemMenu); - - await waitFor(() => { - expect(screen.getByTestId('PopoverMenuItem-Export')).toBeTruthy(); - }); - expect(screen.queryByTestId('PopoverMenuItem-Current view')).toBeNull(); - }); - - it('does not auto-expand when there is more than one top-level item', async () => { - renderPopover(multiItemMenu, true); - - await waitFor(() => { - expect(screen.getByTestId('PopoverMenuItem-Export')).toBeTruthy(); - expect(screen.getByTestId('PopoverMenuItem-Delete')).toBeTruthy(); - }); - expect(screen.queryByTestId('PopoverMenuItem-Current view')).toBeNull(); - }); -}); - describe('PopoverMenu integration — focus policy and close lifecycle', () => { const anchorRef = React.createRef(); const anchorPosition = {horizontal: 0, vertical: 0}; diff --git a/tests/unit/hooks/useSearchBulkActionsExportTest.ts b/tests/unit/hooks/useSearchBulkActionsExportTest.ts index 9ab40d90d15d..72a193eab369 100644 --- a/tests/unit/hooks/useSearchBulkActionsExportTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsExportTest.ts @@ -390,22 +390,27 @@ function makeSearchResults(reports: Report[], reportActionsByReportID: Record['headerButtonsOptions']) { - return headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)?.subMenuItems; +/** + * The export options take one of two shapes: normally they sit inside the Export entry's `subMenuItems`, but when + * Export is the only bulk action available the dropdown opens straight onto them, so they sit at the top level of + * `headerButtonsOptions` with the EXPORT value on each one. + */ +function getExportMenuItems(headerButtonsOptions: ReturnType['headerButtonsOptions']) { + const exportOptions = headerButtonsOptions.filter((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + return exportOptions.at(0)?.subMenuItems ?? exportOptions; } function getExportOptionTexts(headerButtonsOptions: ReturnType['headerButtonsOptions']) { - const exportOption = headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - return exportOption?.subMenuItems?.map((item) => item.text) ?? (exportOption ? [exportOption.text] : []); + return getExportMenuItems(headerButtonsOptions).map((item) => item.text); } -/** Export options live inside the Export submenu, but tolerate a flat top-level shape too so callers stay robust. */ function getExportOptionByText(headerButtonsOptions: ReturnType['headerButtonsOptions'], text: string) { - const exportOption = headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - if (!exportOption) { - return undefined; - } - return exportOption.subMenuItems?.find((item) => item.text === text) ?? (exportOption.text === text ? exportOption : undefined); + return getExportMenuItems(headerButtonsOptions).find((item) => item.text === text); +} + +/** The Export entry's nested submenu items. Only valid for selections where Export is not the only bulk action. */ +function getExportSubMenuItems(headerButtonsOptions: ReturnType['headerButtonsOptions']) { + return headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)?.subMenuItems; } /** The parameters the last plain-CSV export sent to the backend, with the serialized query parsed back. */ @@ -515,10 +520,9 @@ describe('useSearchBulkActions - export options', () => { expect(result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)).toBeDefined(); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const subMenuItems = exportOption?.subMenuItems ?? []; - expect(subMenuItems.some((item) => item.text === NETSUITE_FRIENDLY_NAME)).toBe(false); - expect(subMenuItems.some((item) => item.text === 'workspace.common.markAsExported')).toBe(false); + const exportMenuItems = getExportMenuItems(result.current.headerButtonsOptions); + expect(exportMenuItems.some((item) => item.text === NETSUITE_FRIENDLY_NAME)).toBe(false); + expect(exportMenuItems.some((item) => item.text === 'workspace.common.markAsExported')).toBe(false); }); it('offers per-integration export options when reports span workspaces connected to different integrations', async () => { @@ -1147,12 +1151,14 @@ describe('useSearchBulkActions - export options', () => { it('keeps the Export entry as a submenu even when only one export option is available', async () => { // Regression test for https://github.com/Expensify/App/issues/98779: a full group selection offers a single - // export option ('export.currentView'). The Export entry must still open the Export submenu (keeping its - // generic label and subMenuItems) rather than collapsing straight into that single option. + // export option ('export.currentView'). While other bulk actions sit alongside it (Hold here), the Export + // entry must still open the Export submenu (keeping its generic label and subMenuItems) rather than + // collapsing straight into that single option. mockSelectedTransactions = { tx1: makeSelectedTransaction({ groupKey: `${CONST.SEARCH.GROUP_PREFIX}category`, isSelectedViaGroup: true, + canHold: true, }), }; @@ -1167,6 +1173,46 @@ describe('useSearchBulkActions - export options', () => { expect(exportOption?.text).toBe('common.export'); }); + it('opens directly onto the single export option when Export is the only bulk action', async () => { + // Export is the only bulk action offered under select all, so there is no main menu to go back to. The one + // export option is surfaced directly instead of behind an "Export" row whose submenu would render a back + // arrow leading nowhere. + mockAreAllMatchingItemsSelected = true; + mockSelectedTransactions = { + tx1: makeSelectedTransaction({ + groupKey: `${CONST.SEARCH.GROUP_PREFIX}category`, + isSelectedViaGroup: true, + }), + }; + + const {result} = renderHook(() => useSearchBulkActions({queryJSON: groupedExpenseQueryJSON}), {wrapper: OnyxListItemProvider}); + + await waitFor(() => { + expect(result.current.headerButtonsOptions.map((option) => option.text)).toEqual(['export.currentView']); + }); + + const soleOption = result.current.headerButtonsOptions.at(0); + expect(soleOption?.value).toBe(CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + expect(soleOption?.subMenuItems).toBeUndefined(); + expect(soleOption?.backButtonText).toBeUndefined(); + }); + + it('opens directly onto every export option when Export is the only bulk action', async () => { + mockAreAllMatchingItemsSelected = true; + mockSelectedTransactions = {tx1: makeSelectedTransaction()}; + + const {result} = renderHook(() => useSearchBulkActions({queryJSON: groupedExpenseQueryJSON}), {wrapper: OnyxListItemProvider}); + + await waitFor(() => { + expect(result.current.headerButtonsOptions.length).toBeGreaterThan(1); + }); + + // Every entry is an export option itself — there is no "Export" row wrapping them and so no back arrow. + expect(result.current.headerButtonsOptions.every((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)).toBe(true); + expect(result.current.headerButtonsOptions.some((option) => option.text === 'common.export')).toBe(false); + expect(result.current.headerButtonsOptions.some((option) => !!option.subMenuItems)).toBe(false); + }); + it('exports the current view of a grouped search with the default expense columns', async () => { mockSelectedTransactions = {tx1: makeSelectedTransaction()}; diff --git a/tests/unit/hooks/useSearchBulkActionsTest.ts b/tests/unit/hooks/useSearchBulkActionsTest.ts index d93434449e18..bf7e20e6b0d6 100644 --- a/tests/unit/hooks/useSearchBulkActionsTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsTest.ts @@ -241,6 +241,16 @@ function hasSearchFlatFilters(value: unknown): value is {flatFilters: SearchQuer return typeof value === 'object' && value !== null && 'flatFilters' in value && Array.isArray(value.flatFilters); } +/** + * The export options take one of two shapes: normally they sit inside the Export entry's `subMenuItems`, but when + * Export is the only bulk action available the dropdown opens straight onto them, so they sit at the top level of + * `headerButtonsOptions` with the EXPORT value on each one. + */ +function getExportMenuItems(headerButtonsOptions: ReturnType['headerButtonsOptions']) { + const exportOptions = headerButtonsOptions.filter((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); + return exportOptions.at(0)?.subMenuItems ?? exportOptions; +} + describe('useSearchBulkActions - CSV export flow', () => { beforeAll(() => { Onyx.init({keys: ONYXKEYS}); @@ -275,10 +285,8 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((o) => o.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - expect(exportOption).toBeDefined(); - - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; + const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; + expect(onSelected).toBeDefined(); await act(async () => { onSelected?.(); @@ -306,8 +314,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; + const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; await act(async () => { onSelected?.(); @@ -359,8 +366,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; + const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; await act(async () => { onSelected?.(); @@ -399,8 +405,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; + const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; await act(async () => { onSelected?.(); @@ -442,8 +447,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const onSelected = exportOption?.subMenuItems?.find((item) => item.text === 'export.currentView')?.onSelected ?? exportOption?.onSelected; + const onSelected = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text === 'export.currentView')?.onSelected; await act(async () => { onSelected?.(); @@ -481,8 +485,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((o) => o.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const templateSubItem = exportOption?.subMenuItems?.find((item) => item.text !== 'export.basicExport' && item.text !== 'export.currentView'); + const templateSubItem = getExportMenuItems(result.current.headerButtonsOptions).find((item) => item.text !== 'export.basicExport' && item.text !== 'export.currentView'); expect(templateSubItem).toBeDefined(); act(() => { @@ -516,8 +519,7 @@ describe('useSearchBulkActions - CSV export flow', () => { expect(result.current.headerButtonsOptions.length).toBeGreaterThan(0); }); - const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); - const exportItems = exportOption?.subMenuItems ?? []; + const exportItems = getExportMenuItems(result.current.headerButtonsOptions); expect(exportItems.some((item) => item.text === 'Custom template')).toBe(false); expect(exportItems.some((item) => item.text === 'Default template')).toBe(false); From 915ffe849421c833949eb33b8d8f27d214615cae Mon Sep 17 00:00:00 2001 From: "Yauheni Horbach (via MelvinBot)" Date: Wed, 2 Sep 2026 06:52:56 +0000 Subject: [PATCH 7/9] Keep the Export header above the directly-opened export options When Export is the only bulk action the dropdown opens straight onto the export options. Without the Export row above them it was not clear what the options referred to, so surface Export as a plain popover header while still leaving out the back caret. Co-authored-by: Yauheni Horbach --- src/components/Search/SearchBulkActionsButton.tsx | 3 +++ src/hooks/useSearchBulkActions.ts | 11 ++++++++++- tests/unit/hooks/useSearchBulkActionsExportTest.ts | 7 ++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/Search/SearchBulkActionsButton.tsx b/src/components/Search/SearchBulkActionsButton.tsx index d3752eda834e..3b615bac6a98 100644 --- a/src/components/Search/SearchBulkActionsButton.tsx +++ b/src/components/Search/SearchBulkActionsButton.tsx @@ -70,6 +70,7 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) { const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const { headerButtonsOptions, + bulkActionsMenuHeaderText, selectedPolicyIDs, selectedTransactionReportIDs, selectedReportIDs, @@ -223,6 +224,7 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) { payBulkSelectedItem(subItem, triggerKYCFlow)} isSplitButton={false} diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index 1fc2d6252dc8..3915e0665fb3 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -2117,7 +2117,8 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { /** * Export is sometimes the only bulk action available (most commonly under "select all"). There is no main menu * to go back to then, so the dropdown opens directly onto the export options rather than nesting them behind - * an "Export" row whose submenu would render a back arrow leading nowhere. + * an "Export" row whose submenu would render a back arrow leading nowhere. The "Export" label is not lost: + * `bulkActionsMenuHeaderText` below puts it back as a plain (non-interactive) header above the options. */ const openExportOptionsDirectlyIfSoleAction = (builtOptions: Array>): Array> => { const isExportTheOnlyAction = builtOptions.length === 1 && builtOptions.at(0)?.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT; @@ -2824,6 +2825,13 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { shouldCalculateTotalsOnRefresh, ]); + // When the export options are surfaced directly there is no "Export" row above them, so on its own the list gives + // no clue what the options refer to. Put "Export" back as a plain header — it reads the same as the label the back + // button normally carries, minus the caret, since there is no menu to go back to. + const isShowingExportOptionsDirectly = + headerButtonsOptions.length > 0 && headerButtonsOptions.every((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT && !option.subMenuItems); + const bulkActionsMenuHeaderText = isShowingExportOptionsDirectly ? translate('common.export') : undefined; + const handleOfflineModalClose = useCallback(() => { setIsOfflineModalVisible(false); }, [setIsOfflineModalVisible]); @@ -2872,6 +2880,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { return { headerButtonsOptions, + bulkActionsMenuHeaderText, selectedPolicyIDs, selectedTransactionReportIDs, selectedReportIDs, diff --git a/tests/unit/hooks/useSearchBulkActionsExportTest.ts b/tests/unit/hooks/useSearchBulkActionsExportTest.ts index 72a193eab369..106986abbcda 100644 --- a/tests/unit/hooks/useSearchBulkActionsExportTest.ts +++ b/tests/unit/hooks/useSearchBulkActionsExportTest.ts @@ -1171,12 +1171,14 @@ describe('useSearchBulkActions - export options', () => { const exportOption = result.current.headerButtonsOptions.find((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); expect(exportOption?.subMenuItems).toHaveLength(1); expect(exportOption?.text).toBe('common.export'); + // The Export row itself labels the submenu here, so the dropdown must not also carry an "Export" header. + expect(result.current.bulkActionsMenuHeaderText).toBeUndefined(); }); it('opens directly onto the single export option when Export is the only bulk action', async () => { // Export is the only bulk action offered under select all, so there is no main menu to go back to. The one // export option is surfaced directly instead of behind an "Export" row whose submenu would render a back - // arrow leading nowhere. + // arrow leading nowhere, with "Export" kept as a plain dropdown header so the option still has context. mockAreAllMatchingItemsSelected = true; mockSelectedTransactions = { tx1: makeSelectedTransaction({ @@ -1195,6 +1197,7 @@ describe('useSearchBulkActions - export options', () => { expect(soleOption?.value).toBe(CONST.SEARCH.BULK_ACTION_TYPES.EXPORT); expect(soleOption?.subMenuItems).toBeUndefined(); expect(soleOption?.backButtonText).toBeUndefined(); + expect(result.current.bulkActionsMenuHeaderText).toBe('common.export'); }); it('opens directly onto every export option when Export is the only bulk action', async () => { @@ -1211,6 +1214,8 @@ describe('useSearchBulkActions - export options', () => { expect(result.current.headerButtonsOptions.every((option) => option.value === CONST.SEARCH.BULK_ACTION_TYPES.EXPORT)).toBe(true); expect(result.current.headerButtonsOptions.some((option) => option.text === 'common.export')).toBe(false); expect(result.current.headerButtonsOptions.some((option) => !!option.subMenuItems)).toBe(false); + // "Export" moves to the dropdown header instead, so the options are still labeled without a back caret. + expect(result.current.bulkActionsMenuHeaderText).toBe('common.export'); }); it('exports the current view of a grouped search with the default expense columns', async () => { From d10d8eda781f063f4d01a7d2f4b533bc7ab51a9e Mon Sep 17 00:00:00 2001 From: "Yauheni Horbach (via MelvinBot)" Date: Wed, 2 Sep 2026 17:34:47 +0000 Subject: [PATCH 8/9] Freeze the clock in the monthly-on-the-2nd next step test The test derived its expected ETA from getNextNthOfMonth, which always skips to next month, while buildOptimisticNextStep treats an offset landing on today as due today. The two only disagree when the suite runs on the 2nd, so the test failed for every PR on that day. Pin the system time to a day that is not the 2nd to make it deterministic. Co-authored-by: Yauheni Horbach --- tests/unit/NextStepUtilsTest.ts | 71 +++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index 0f98d46ec8f8..1e452c80f907 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -281,37 +281,48 @@ describe('libs/NextStepUtils', () => { }); test('monthly on the 2nd', () => { - // Waiting for userSubmitter's expense(s) to automatically submit on the 2nd of each month - const expectedResult: ReportNextStep = { - messageKey: CONST.NEXT_STEP.MESSAGE_KEY.WAITING_FOR_AUTOMATIC_SUBMIT, - icon: CONST.NEXT_STEP.ICONS.HOURGLASS, - actorAccountID: currentUserAccountID, - eta: { - dateTime: format(DateUtils.getNextNthOfMonth(2), 'yyyy-MM-dd'), - }, - }; - const result = buildOptimisticNextStep({ - report, - policy: { - ...policy, - autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MONTHLY, - autoReportingOffset: 2, - harvesting: { - enabled: true, + // `buildOptimisticNextStep` treats an offset landing on today as due today, while + // `getNextNthOfMonth` always skips to next month, so the two only disagree when the suite runs on + // the 2nd itself. Freeze the clock on a day that is not the 2nd so this stays deterministic. + jest.useFakeTimers(); + jest.setSystemTime(new Date(2026, 0, 15)); + + try { + // Waiting for userSubmitter's expense(s) to automatically submit on the 2nd of each month + const expectedResult: ReportNextStep = { + messageKey: CONST.NEXT_STEP.MESSAGE_KEY.WAITING_FOR_AUTOMATIC_SUBMIT, + icon: CONST.NEXT_STEP.ICONS.HOURGLASS, + actorAccountID: currentUserAccountID, + eta: { + dateTime: format(DateUtils.getNextNthOfMonth(2), 'yyyy-MM-dd'), }, - }, - currentUserAccountIDParam: currentUserAccountID, - currentUserEmailParam: currentUserEmail, - hasViolations: false, - isASAPSubmitBetaEnabled: false, - predictedNextStatus: CONST.REPORT.STATUS_NUM.OPEN, - shouldFixViolations: false, - isUnapprove: false, - isReopen: false, - isTrackIntentUser: false, - }); - - expect(result).toMatchObject(expectedResult); + }; + const result = buildOptimisticNextStep({ + report, + policy: { + ...policy, + autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MONTHLY, + autoReportingOffset: 2, + harvesting: { + enabled: true, + }, + }, + currentUserAccountIDParam: currentUserAccountID, + currentUserEmailParam: currentUserEmail, + hasViolations: false, + isASAPSubmitBetaEnabled: false, + predictedNextStatus: CONST.REPORT.STATUS_NUM.OPEN, + shouldFixViolations: false, + isUnapprove: false, + isReopen: false, + isTrackIntentUser: false, + }); + + expect(result).toMatchObject(expectedResult); + } finally { + // Restore real timers even when the assertion fails, so later tests are unaffected. + jest.useRealTimers(); + } }); test('monthly on the last day', () => { From 22ba626635d35d4ffee53f5f2832bda5a9998aaa Mon Sep 17 00:00:00 2001 From: "Yauheni Horbach (via MelvinBot)" Date: Wed, 2 Sep 2026 17:55:00 +0000 Subject: [PATCH 9/9] Revert "Freeze the clock in the monthly-on-the-2nd next step test" This reverts commit d10d8eda781f063f4d01a7d2f4b533bc7ab51a9e. --- tests/unit/NextStepUtilsTest.ts | 71 ++++++++++++++------------------- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index 1e452c80f907..0f98d46ec8f8 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -281,48 +281,37 @@ describe('libs/NextStepUtils', () => { }); test('monthly on the 2nd', () => { - // `buildOptimisticNextStep` treats an offset landing on today as due today, while - // `getNextNthOfMonth` always skips to next month, so the two only disagree when the suite runs on - // the 2nd itself. Freeze the clock on a day that is not the 2nd so this stays deterministic. - jest.useFakeTimers(); - jest.setSystemTime(new Date(2026, 0, 15)); - - try { - // Waiting for userSubmitter's expense(s) to automatically submit on the 2nd of each month - const expectedResult: ReportNextStep = { - messageKey: CONST.NEXT_STEP.MESSAGE_KEY.WAITING_FOR_AUTOMATIC_SUBMIT, - icon: CONST.NEXT_STEP.ICONS.HOURGLASS, - actorAccountID: currentUserAccountID, - eta: { - dateTime: format(DateUtils.getNextNthOfMonth(2), 'yyyy-MM-dd'), - }, - }; - const result = buildOptimisticNextStep({ - report, - policy: { - ...policy, - autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MONTHLY, - autoReportingOffset: 2, - harvesting: { - enabled: true, - }, + // Waiting for userSubmitter's expense(s) to automatically submit on the 2nd of each month + const expectedResult: ReportNextStep = { + messageKey: CONST.NEXT_STEP.MESSAGE_KEY.WAITING_FOR_AUTOMATIC_SUBMIT, + icon: CONST.NEXT_STEP.ICONS.HOURGLASS, + actorAccountID: currentUserAccountID, + eta: { + dateTime: format(DateUtils.getNextNthOfMonth(2), 'yyyy-MM-dd'), + }, + }; + const result = buildOptimisticNextStep({ + report, + policy: { + ...policy, + autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MONTHLY, + autoReportingOffset: 2, + harvesting: { + enabled: true, }, - currentUserAccountIDParam: currentUserAccountID, - currentUserEmailParam: currentUserEmail, - hasViolations: false, - isASAPSubmitBetaEnabled: false, - predictedNextStatus: CONST.REPORT.STATUS_NUM.OPEN, - shouldFixViolations: false, - isUnapprove: false, - isReopen: false, - isTrackIntentUser: false, - }); - - expect(result).toMatchObject(expectedResult); - } finally { - // Restore real timers even when the assertion fails, so later tests are unaffected. - jest.useRealTimers(); - } + }, + currentUserAccountIDParam: currentUserAccountID, + currentUserEmailParam: currentUserEmail, + hasViolations: false, + isASAPSubmitBetaEnabled: false, + predictedNextStatus: CONST.REPORT.STATUS_NUM.OPEN, + shouldFixViolations: false, + isUnapprove: false, + isReopen: false, + isTrackIntentUser: false, + }); + + expect(result).toMatchObject(expectedResult); }); test('monthly on the last day', () => {