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

FIX: Only add inserters in between blocks (not at end) #3485

Closed
wants to merge 1 commit into from

Conversation

ephox-mogran
Copy link
Contributor

Fixes #3433

Description

Stopped rendering a sibling inserter after the last block

How Has This Been Tested?

Manually.

Types of changes

Condition on rendering a SiblingInserter (not in last position in array of blocks).

@@ -218,7 +218,7 @@ class VisualEditorBlockList extends Component {
onSelectionStart={ this.onSelectionStart }
onShiftSelection={ this.onShiftSelection }
/>,
<VisualEditorSiblingInserter
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we are doing a flatmap, we could also just concat to the array of the block with either an empty array (when at last position), or an array containing this inserter. However, if you're happy with this && approach, then it should be fine.

Copy link
Member

Choose a reason for hiding this comment

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

You can also simplify this code by removing the line before flatmap call and moving the Inserter to the first place in the array, in effect always prepend to the existing block.

Copy link
Contributor Author

@ephox-mogran ephox-mogran Nov 15, 2017

Choose a reason for hiding this comment

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

True. That's probably better. Is there any reason that the SiblingInserter isn't added when the default "Write Your Story" block is there?

Copy link
Member

@gziolo gziolo Nov 15, 2017

Choose a reason for hiding this comment

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

It looks like the Write Your Story block isn't a real block but only a placeholder.

Yes, I can confirm this. I inspected Redux state. When you click on Write Your Story, a new block is created for you.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

As suggested in https://github.com/WordPress/gutenberg/pull/3485/files#r151040721, we can simplify this solution a bit. Otherwise, it works as advertised. Nice 👍

@@ -218,7 +218,7 @@ class VisualEditorBlockList extends Component {
onSelectionStart={ this.onSelectionStart }
onShiftSelection={ this.onShiftSelection }
/>,
<VisualEditorSiblingInserter
index < blocks.length - 1 && <VisualEditorSiblingInserter
Copy link
Member

Choose a reason for hiding this comment

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

Lack of parentheses make this a bit ambiguous (similar to no-mixed-operators). Is < considered before or after the subtraction (index < blocks.length)? Is subtraction including the element (1 && <VisualEditorSiblingInserter)?

Maybe:

index < ( blocks-length - 1 ) && (
	<VisualEditorSiblingInserter

I have some similar thoughts here as in #3246 (review) between this approach and allowing the inserter component itself to consider whether it should render itself. Any thoughts? I don't feel strongly either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other approach seems fine to me.

@aduth
Copy link
Member

aduth commented Nov 27, 2017

Related: #3433 (comment)

@youknowriad
Copy link
Contributor

The sibling inserter has been removed in #4539 I'm closing this PR right now, we can reopen if we bring it back.

@gziolo gziolo deleted the fix/remove-duplicate-inserter branch May 7, 2018 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The last sibling inserter is redundant
4 participants