Skip to content
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

Remove block switcher from header, add to multi block controls #7891

Merged
merged 6 commits into from
Jul 13, 2018

Conversation

notnownikki
Copy link
Member

Description

Removed the block switcher from the header, and made it appear when selecting multiple blocks.

How has this been tested?

Select multiple blocks and check the switcher is there.

@notnownikki notnownikki requested a review from mtias July 11, 2018 14:23
aria-label={ __( 'Block Toolbar' ) }
key="toolbar"
>
<BlockSwitcher uids={ multiSelectedBlockUids } />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a more appropriate place would be to move to the BlockToolbar component which will make it appear at the right position depending on the preference Fix toolbar to top

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! This required that the BlockToolbar became aware of multi-block selection, but it cut down on the repeated toolbars, and is a good point to insert multi-block toolbar controls :)

@@ -34,7 +33,6 @@ function HeaderToolbar( { hasFixedToolbar, isLargeViewport } ) {
<EditorHistoryUndo />
<EditorHistoryRedo />
<TableOfContents />
<MultiBlocksSwitcher />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this MultiBlocksSwitcher is already handling showing the switcher only for multi selection.

We should:

  • Delete this component since you duplicated its logic in block-toolbar
  • Or Use it in block-toolbar directly

function BlockToolbar( { block, mode } ) {
if ( ! block || ! block.isValid || mode !== 'visual' ) {
function BlockToolbar( { block, mode, selectedBlockUIDs } ) {
if ( selectedBlockUIDs.length < 2 && ( ! block || ! block.isValid || 'visual' !== mode ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Should we also render nothing if the selectedBlockUIDs is empty?
  • Instead of passing the whole block object. It seems we can just get the isValid flag instead as a prop that way this component will only rerender if the flag changes and not other block properties (performance tip)

return null;
}

return (
<div className="editor-block-toolbar">
<BlockSwitcher uids={ [ block.uid ] } />
<BlockSwitcher uids={ selectedBlockUIDs.length > 1 ? selectedBlockUIDs : [ block.uid ] } />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can't normalize this selectedBlockUIDs and block prop with a unique selectedBlockUIDs which would contain the selected blocks (multi-selection or not)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make things a lot cleaner. Thanks!

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for the updates

return null;
}

return (
<div className="editor-block-toolbar">
<BlockSwitcher uids={ [ block.uid ] } />
<BlockSwitcher uids={ blockUIDs } />
<BlockControls.Slot />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to keep the slots in case we want to show multi-selection controls or something like that in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we do, and I'm working on that next week in another PR :) So I'll be rebasing to use these changes in that PR

@notnownikki notnownikki merged commit 7fe26e0 into master Jul 13, 2018
@youknowriad youknowriad deleted the update/block-switcher-in-toolbar branch July 13, 2018 13:45
@designsimply designsimply added the [Feature] Block Multi Selection The ability to select and manipulate multiple blocks label Jul 18, 2018
@mtias mtias added this to the 3.3 milestone Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Multi Selection The ability to select and manipulate multiple blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants