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 don't show hover effect if the ancestor of a block is multi-selected #7613

Merged
merged 1 commit into from
Jun 29, 2018

Conversation

jorgefilipecosta
Copy link
Member

Description

Fixes: #7361

Before even if a parent block was multi-selected we still showed the hover effect on the children. This PR's corrects that.

How has this been tested?

I added some paragraphs and images and columns block. Added some blocks inside the columns. I multi-selected the columns and some blocks. I verified the hover effect does not appear on the children of the columns. But still appears in other blocks.

@jorgefilipecosta jorgefilipecosta self-assigned this Jun 28, 2018
let isMultiSelected = false;
while ( ancestorUid && ! isMultiSelected ) {
ancestorUid = getBlockRootUID( state, ancestorUid );
isMultiSelected = isBlockMultiSelected( state, ancestorUid );
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we need some recursivity here in case we have more than one ancestor?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @youknowriad, yes we need to iterate over all the ancestors. We are doing it with the while ( ancestorUid && ! isMultiSelected ). The while cycle will only stop when we have no more ancestors or when we found a multi-selected ancestor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh gotcha missed it, I guess I was expecting a call to isAncestorMultiSelected

const { isHovered } = this.state;

if ( isHovered || isMultiSelected || isSelected ||
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we can drop this.props.isMultiSelecting entirely and replace it with isPartOfMultiSelection. Is there a use-case where we need both?

Copy link
Member Author

Choose a reason for hiding this comment

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

The isMultiSelecting condition is required to avoid the hover effect when dragging the mouse to multi-select. There is a moment when adding a new block to a multi-selection where the block is not yet multi-selected and we are with the mouse over it without thus the hover would appear. The isMultiSelecting flag may be true while isPartOfMultiSelection maybe false.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that's true because isPartOfMultiSelection = isMultiSelected || somethingElse I was not taking about isMultiSelecting

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, you mean dropping isMultiSelected entirely. If that's case in function maybeHover we are already doing it and we don't use isMultiSelected. But for other functions e.g: related to the block focus we should continue to use isMultiSelected because they want to check if the specific block is selected and not if the block or one ancestor is selected.

Copy link
Contributor

Choose a reason for hiding this comment

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

I took a look at the other tests and I believe isPartOfMultiSelection probably makes more sense there as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for watching the use cases in detail. I applied your suggestion and I made some tests and the result looks great :)

@jorgefilipecosta jorgefilipecosta force-pushed the fix/hover-on-multiselected-nested-blocks branch from b6aa978 to 6a062c1 Compare June 29, 2018 11:17
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.

LGTM 👍

We might want to run npm run docs:build (rebase first) each time we add a selector/action

@jorgefilipecosta
Copy link
Member Author

Hi @youknowriad, unfortunately, I think our doc generation is not generating docs when createSelector is used, e.g: we don't have docs for getEditedPostContent. So in this case executing the command does not add the docs for the selector we are adding.

@youknowriad
Copy link
Contributor

@jorgefilipecosta Good catch, I'm limiting it to functions, I guess we can add also add the docs if it's a constant using createSelector it should be possible but let's leave this for a separate PR.

@jorgefilipecosta jorgefilipecosta merged commit eb95525 into master Jun 29, 2018
@jorgefilipecosta jorgefilipecosta deleted the fix/hover-on-multiselected-nested-blocks branch June 29, 2018 14:27
@jorgefilipecosta jorgefilipecosta added this to the 3.2 milestone Jul 5, 2018
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.

None yet

2 participants