Repository navigation
Add dividers to More menu actions #90097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
558f65b
Add dividers to More menu actions
aswin-s 599d67e
Add tests for PopoverMenuSections utility
aswin-s 562ec26
Add RECEIVED_PAYMENT to report menu section map
aswin-s 8122fb2
Fix type error in PopoverMenuSectionsTest
aswin-s a1160b8
Remove RECEIVED_PAYMENT references
aswin-s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| const REPORT_SECONDARY_ACTIONS = CONST.REPORT.SECONDARY_ACTIONS; | ||
| const TRANSACTION_SECONDARY_ACTIONS = CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS; | ||
| const UNRECOGNIZED_SECTION = Number.MAX_SAFE_INTEGER; | ||
|
|
||
| const REPORT_MORE_MENU_SECTIONS = [ | ||
| [ | ||
| REPORT_SECONDARY_ACTIONS.PAY, | ||
| REPORT_SECONDARY_ACTIONS.ADD_EXPENSE, | ||
| REPORT_SECONDARY_ACTIONS.HOLD, | ||
| REPORT_SECONDARY_ACTIONS.REMOVE_HOLD, | ||
| REPORT_SECONDARY_ACTIONS.SUBMIT, | ||
| REPORT_SECONDARY_ACTIONS.RETRACT, | ||
| REPORT_SECONDARY_ACTIONS.REOPEN, | ||
| REPORT_SECONDARY_ACTIONS.REJECT, | ||
| REPORT_SECONDARY_ACTIONS.APPROVE, | ||
| REPORT_SECONDARY_ACTIONS.UNAPPROVE, | ||
| REPORT_SECONDARY_ACTIONS.CANCEL_PAYMENT, | ||
| ], | ||
| [REPORT_SECONDARY_ACTIONS.SPLIT, REPORT_SECONDARY_ACTIONS.MERGE, REPORT_SECONDARY_ACTIONS.DUPLICATE_EXPENSE, REPORT_SECONDARY_ACTIONS.MOVE_EXPENSE], | ||
| [REPORT_SECONDARY_ACTIONS.DUPLICATE_REPORT, REPORT_SECONDARY_ACTIONS.CHANGE_WORKSPACE, REPORT_SECONDARY_ACTIONS.CHANGE_APPROVER], | ||
| [REPORT_SECONDARY_ACTIONS.EXPORT, REPORT_SECONDARY_ACTIONS.DOWNLOAD_PDF, REPORT_SECONDARY_ACTIONS.PRINT], | ||
| [REPORT_SECONDARY_ACTIONS.VIEW_DETAILS, REPORT_SECONDARY_ACTIONS.DELETE], | ||
| ]; | ||
|
|
||
| const TRANSACTION_MORE_MENU_SECTIONS = [ | ||
| [ | ||
| TRANSACTION_SECONDARY_ACTIONS.HOLD, | ||
| TRANSACTION_SECONDARY_ACTIONS.REMOVE_HOLD, | ||
| TRANSACTION_SECONDARY_ACTIONS.REJECT, | ||
| TRANSACTION_SECONDARY_ACTIONS.SPLIT, | ||
| TRANSACTION_SECONDARY_ACTIONS.MERGE, | ||
| ], | ||
| [TRANSACTION_SECONDARY_ACTIONS.DUPLICATE, TRANSACTION_SECONDARY_ACTIONS.MOVE_EXPENSE], | ||
| [TRANSACTION_SECONDARY_ACTIONS.VIEW_DETAILS, TRANSACTION_SECONDARY_ACTIONS.DELETE], | ||
| ]; | ||
|
|
||
| function buildSectionOrder(sectionDefinitions: ReadonlyArray<readonly string[]>) { | ||
| return new Map(sectionDefinitions.flatMap((section, sectionIndex) => section.map((action) => [action, sectionIndex]))); | ||
| } | ||
|
|
||
| function sortAndSectionPopoverMenuItems<TValue extends string, TItem extends DropdownOption<TValue>>(items: TItem[], sectionDefinitions: ReadonlyArray<readonly string[]>): TItem[] { | ||
| const sectionOrder = buildSectionOrder(sectionDefinitions); | ||
| const sortedItems = items | ||
| .map((item, originalIndex) => ({item, originalIndex, sectionIndex: sectionOrder.get(item.value) ?? UNRECOGNIZED_SECTION})) | ||
| .sort((firstItem, secondItem) => firstItem.sectionIndex - secondItem.sectionIndex || firstItem.originalIndex - secondItem.originalIndex); | ||
|
|
||
| let lastSectionIndex: number | undefined; | ||
| return sortedItems.map(({item, sectionIndex}) => { | ||
| const shouldAddSeparator = lastSectionIndex !== undefined && sectionIndex !== lastSectionIndex; | ||
|
|
||
| lastSectionIndex = sectionIndex; | ||
|
|
||
| if (!shouldAddSeparator) { | ||
| return item; | ||
| } | ||
|
|
||
| return {...item, addSeparatorBefore: true}; | ||
| }); | ||
| } | ||
|
|
||
| export {REPORT_MORE_MENU_SECTIONS, TRANSACTION_MORE_MENU_SECTIONS, sortAndSectionPopoverMenuItems}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types'; | ||
| import {sortAndSectionPopoverMenuItems} from '@libs/PopoverMenuSections'; | ||
|
|
||
| function makeItem(value: string): DropdownOption<string> { | ||
| return {text: value, value}; | ||
| } | ||
|
|
||
| describe('sortAndSectionPopoverMenuItems', () => { | ||
| const sections = [['A', 'B', 'C'], ['D', 'E'], ['F']]; | ||
|
|
||
| it('adds separators between sections', () => { | ||
| const items = [makeItem('A'), makeItem('D'), makeItem('F')]; | ||
| const result = sortAndSectionPopoverMenuItems(items, sections); | ||
|
|
||
| expect(result).toHaveLength(3); | ||
| expect(result.at(0)?.addSeparatorBefore).toBeUndefined(); | ||
| expect(result.at(1)?.addSeparatorBefore).toBe(true); | ||
| expect(result.at(2)?.addSeparatorBefore).toBe(true); | ||
| }); | ||
|
|
||
| it('does not add separator when all items are in the same section', () => { | ||
| const items = [makeItem('A'), makeItem('B'), makeItem('C')]; | ||
| const result = sortAndSectionPopoverMenuItems(items, sections); | ||
|
|
||
| expect(result.every((i) => !i.addSeparatorBefore)).toBe(true); | ||
| }); | ||
|
|
||
| it('sorts items by section order while preserving original order within sections', () => { | ||
| const items = [makeItem('F'), makeItem('B'), makeItem('D'), makeItem('A')]; | ||
| const result = sortAndSectionPopoverMenuItems(items, sections); | ||
|
|
||
| expect(result.map((i) => i.value)).toEqual(['B', 'A', 'D', 'F']); | ||
| }); | ||
|
|
||
| it('places unrecognized items at the end', () => { | ||
| const items = [makeItem('UNKNOWN'), makeItem('A'), makeItem('D')]; | ||
| const result = sortAndSectionPopoverMenuItems(items, sections); | ||
|
|
||
| expect(result.map((i) => i.value)).toEqual(['A', 'D', 'UNKNOWN']); | ||
| expect(result.at(2)?.addSeparatorBefore).toBe(true); | ||
| }); | ||
|
|
||
| it('returns empty array for empty input', () => { | ||
| expect(sortAndSectionPopoverMenuItems([], sections)).toEqual([]); | ||
| }); | ||
|
|
||
| it('handles single item without separator', () => { | ||
| const result = sortAndSectionPopoverMenuItems([makeItem('D')], sections); | ||
|
|
||
| expect(result).toEqual([{text: 'D', value: 'D'}]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getSecondaryReportActions()can emitREPORT_SECONDARY_ACTIONS.RECEIVED_PAYMENT(seesrc/libs/ReportSecondaryActionUtils.ts), but this action is missing fromREPORT_MORE_MENU_SECTIONS. BecausesortAndSectionPopoverMenuItems()sends unrecognized actions to the last section,Received paymentis moved below utility/destructive items and gets an extra separator, which regresses the intended grouping/order whenever that action is available.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aswin-s The review comment seems reasonable. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rojiphil
RECEIVED_PAYMENTwas added in PR #86174 but subsequently reverted in PR #90159. It no longer exists in CONST.REPORT.SECONDARY_ACTIONS on main, so there's nothing to map.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RECEIVED_PAYMENT got added later which we added in #91928