-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[BulkActions] - Allowing promoted actions to be rendered as menus #4266
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
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
39 changes: 39 additions & 0 deletions
39
src/components/BulkActions/components/BulkActionMenu/BulkActionMenu.tsx
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,39 @@ | ||
| import React from 'react'; | ||
|
|
||
| import {Popover} from '../../../Popover'; | ||
| import {ActionList} from '../../../ActionList'; | ||
| import {BulkActionButton} from '../BulkActionButton'; | ||
| import {useToggle} from '../../../../utilities/use-toggle'; | ||
| import type {MenuGroupDescriptor} from '../../../../types'; | ||
|
|
||
| export interface BulkActionsMenuProps extends MenuGroupDescriptor { | ||
| isNewBadgeInBadgeActions: boolean; | ||
| } | ||
|
|
||
| export function BulkActionMenu({ | ||
| title, | ||
| actions, | ||
| isNewBadgeInBadgeActions, | ||
| }: BulkActionsMenuProps) { | ||
| const {value: isVisible, toggle: toggleMenuVisibility} = useToggle(false); | ||
|
|
||
| return ( | ||
| <> | ||
| <Popover | ||
| active={isVisible} | ||
| activator={ | ||
| <BulkActionButton | ||
| disclosure | ||
| onAction={toggleMenuVisibility} | ||
| content={title} | ||
| indicator={isNewBadgeInBadgeActions} | ||
| /> | ||
| } | ||
| onClose={toggleMenuVisibility} | ||
| preferInputActivator | ||
| > | ||
| <ActionList items={actions} onActionAnyItem={toggleMenuVisibility} /> | ||
| </Popover> | ||
| </> | ||
| ); | ||
| } | ||
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 @@ | ||
| export * from './BulkActionMenu'; |
73 changes: 73 additions & 0 deletions
73
src/components/BulkActions/components/BulkActionMenu/tests/BulkActionMenu.test.tsx
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,73 @@ | ||
| import React from 'react'; | ||
| import {Popover, ActionList} from 'components'; | ||
| import {mountWithApp} from 'test-utilities'; | ||
|
|
||
| import {BulkActionMenu, BulkActionsMenuProps, BulkActionButton} from '../..'; | ||
|
|
||
| const defaultProps: BulkActionsMenuProps = { | ||
| title: 'New promoted action', | ||
| actions: [{content: 'Action1', onAction: jest.fn}], | ||
| isNewBadgeInBadgeActions: false, | ||
| }; | ||
|
|
||
| describe('BulkActionMenu', () => { | ||
| describe('initial render', () => { | ||
| it('renders an inactive Popover', () => { | ||
| const bulkActionMenu = mountWithApp(<BulkActionMenu {...defaultProps} />); | ||
|
|
||
| expect(bulkActionMenu).toContainReactComponent(Popover, { | ||
| active: false, | ||
| }); | ||
| }); | ||
|
|
||
| it('does not render an ActionList', () => { | ||
| const bulkActionMenu = mountWithApp(<BulkActionMenu {...defaultProps} />); | ||
|
|
||
| expect(bulkActionMenu).not.toContainReactComponent(ActionList); | ||
| }); | ||
|
|
||
| it('renders a BulkActionButton as the Popover activator with the right props', () => { | ||
| const bulkActionMenu = mountWithApp(<BulkActionMenu {...defaultProps} />); | ||
|
|
||
| expect(bulkActionMenu).toContainReactComponent(BulkActionButton, { | ||
| indicator: defaultProps.isNewBadgeInBadgeActions, | ||
| disclosure: true, | ||
| content: defaultProps.title, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('upon click', () => { | ||
| it('renders an active Popover', () => { | ||
| const bulkActionMenu = mountWithApp(<BulkActionMenu {...defaultProps} />); | ||
| const bulkActionButton = bulkActionMenu.find(BulkActionButton); | ||
| bulkActionButton!.trigger('onAction'); | ||
|
|
||
| expect(bulkActionMenu).toContainReactComponent(Popover, { | ||
| active: true, | ||
| }); | ||
| }); | ||
|
|
||
| it('renders an ActionList with the supplied actions', () => { | ||
| const bulkActionMenu = mountWithApp(<BulkActionMenu {...defaultProps} />); | ||
| const bulkActionButton = bulkActionMenu.find(BulkActionButton); | ||
| bulkActionButton!.trigger('onAction'); | ||
|
|
||
| expect(bulkActionMenu).toContainReactComponent(ActionList, { | ||
| items: defaultProps.actions, | ||
| }); | ||
| }); | ||
|
|
||
| it('closes the Popover when an action is clicked', () => { | ||
| const bulkActionMenu = mountWithApp(<BulkActionMenu {...defaultProps} />); | ||
| const bulkActionButton = bulkActionMenu.find(BulkActionButton); | ||
| bulkActionButton!.trigger('onAction'); | ||
| const actionList = bulkActionMenu.find(ActionList); | ||
| actionList!.trigger('onActionAnyItem'); | ||
|
|
||
| expect(bulkActionMenu).toContainReactComponent(Popover, { | ||
| active: false, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from './BulkActionButton'; | ||
| export * from './BulkActionMenu'; |
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.
It shouldn't need a lot, but would you mind adding a few tests 🙏