-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[ActionMenu] Add support for explicit item order #2057
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
Conversation
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.
I mentioned this IRL, but I think it would be interesting to explore an API that maps to the flexbox order
property. As you said, this could even map directly to that property in the implementation, using flexbox to reorder these as specified. This would also probably simplify the code a good bit, and might be a positive for accessibility.
Quick update: This was initially done in and following an adhoc pairing session and will be prioritized next week. |
I think there was a mixup when I spoke briefly about this work during show and tell. The reason I named the property The |
6b3d749
to
8ace217
Compare
8ace217
to
e104532
Compare
38cf66f
to
5bfd938
Compare
Hey @chloerice, any update on when this will be ready to go? |
82c6e6f
to
eb4e39c
Compare
f3b37c0
to
7668662
Compare
@brandon-yetman This is ready to go! Codecov is still fighting me, though. @AndrewMusgrave looking at the diff in codecov vs the tests I have here, do you see any obvious holes in tests? It's driving me nuts 😣 |
Thanks so much for your hard work on this @chloerice !! |
const {activeMenuGroup} = this.state; | ||
const menuActions = [...actions, ...groups]; | ||
|
||
if (menuActions.length === 0) { |
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.
This branch was never executing because we're returning early in the render method
index: number; | ||
}; | ||
|
||
export function sortAndOverrideActionOrder( |
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.
Here we're filtering out the descriptors without index, so we're never hitting the edges cases below.
That should bump codecov to 100% but I'll check back after lunch. Here're my changes, I left some comments. Let me know if you have any questions 😄 |
💯 |
Thank you so much @AndrewMusgrave!!! 🙏 🙌 |
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.
🎩 and code looks great!
One detail of note is that the rollup menu (i.e. on a mobile display) does not take into account the explicit item order, but this is a) not explicitly required for the use-case that brought about this PR, and b) potentially undesireable.
Thanks again @chloerice !
]; | ||
|
||
sortedActionsWithOverrides.forEach((action) => { | ||
overriddenActions.splice(action.index, 0, action); |
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.
Very elegant solution 👍
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.
LGTM 🎩 ✅ Left a few comments about type safety. We also should add a readme example, but it shouldn't delay this getting shipped 😄
@@ -1,60 +1,19 @@ | |||
# Unreleased changes | |||
|
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.
A rebase might be needed 😄
? groups.map(({title, ...rest}, index) => ( | ||
const actionMarkup = overriddenActions.map((action, index) => { | ||
if (Object.hasOwnProperty.call(action, 'title')) { | ||
const {title, actions, ...rest} = action as MenuGroupDescriptor; |
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.
The in
keyword works as a type guard for narrowing.
if ('title' in action) {
const {title, actions, ...rest} = action;
{groupsMarkup} | ||
</div> | ||
) : null; | ||
const {content, ...rest} = action as MenuActionDescriptor; |
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.
With the guard above we can remove this cast as well!
) { | ||
const actionsWithOverrides = actions.filter( | ||
(action) => action.index !== undefined, | ||
) as MenuDescriptorWithIndex[]; |
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.
If we wanted type safety we could approach it like this.
...
const actionsWithOverrides = actions.filter(
(action) => action.index !== undefined,
); // Cast removed
if (isMenuDescriptionWithIndex(actionsWithOverrides)) { // reversed logic
...
}
return actions;
}
function isMenuDescriptionWithIndex( // narrowing function
actions: (MenuActionDescriptor | MenuGroupDescriptor)[],
): actions is MenuDescriptorWithIndex[] {
return actions.length !== 0;
}
Thanks @brandon-yetman! The rollup menu wasn't included in these changes because there would need to be a redesign of |
5c84213
to
6ada143
Compare
Yeah I figured it's out of scope for this PR anyways, just wanted to make sure it was noted. Thanks 🙌 |
574a5ea
to
934e587
Compare
WHY are these changes introduced?
The Orders team needs to be able to specify the order of their
Page
actions because one of their actions varies from being asecondaryAction
or anactionGroup
depending on the status of the order.WHAT is this pull request doing?
Adds support for overriding the order of actions in the action menu.
How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
Copy-paste this code in
playground/Playground.tsx
:🎩 checklist
README.md
with documentation changes