Cart i2: view switcher shared to children #4817
Conversation
Size Change: +52 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
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.
Does what it says
{ | ||
view: 'filledCart', | ||
label: __( 'Filled Cart', 'woo-gutenberg-products-block' ), | ||
icon: <Icon srcElement={ filledCart } />, | ||
default: true, | ||
}, | ||
] |
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.
Nitpick, given this is the default option, can it be the first one? When opening the switcher, the first item is focused, It makes it confusing because emptyCart
is focused and looks like it's selected.
title: view.label, | ||
onClick: () => { | ||
setCurrentView( view ); | ||
selectBlock( clientId ); |
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.
Can we not select the parent Cart block and just select the current one? So, filled or empty cart block?
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.
How will we get the client ID?
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.
selectBlock( getBlock( clientId ).innerBlocks.find(block => block.name === 'woocommerce/filled-cart-block').clientId )
But like prettier and not a single line.
Do you want me to pick up this issue @mikejolley ? |
@senadir nah Ill wrap it up soon. |
a9ee915
to
df53745
Compare
@senadir do you want a final look? I made those changes and simplified the API a bit so we map view -> block Name. Makes selection easier too. |
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.
Works like a charm, thanks for working on this Mike.
Implements
__experimentalExposeToChildren
so that the view switcher is passed down to all children toolbars. When switching, the view is changed and the parent is selected to avoid the selection of a non-visible block.Fixes #4812
NOTE: Only the top 2 levels of inner blocks will show the toolbar item, unless you first implement WordPress/gutenberg#35078 This makes it so all levels show the toolbar item.
How to test the changes in this Pull Request: