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

Refactor the draggable component to avoid passing around unnecessary props #18756

Merged
merged 3 commits into from
Dec 5, 2019

Conversation

youknowriad
Copy link
Contributor

This PR is extracted from #18685

It does a few things:

  • Remove unnecessary indirection: The DragIcon component.
  • Move all Dragging related checks to the BlockDraggable component.
  • Avoid passing Dragging related component from the Block component down to its actual usage.

I also think this PR makes it easier to support multiple blocks dragging in the future if needed.

Testing instructions

  • Is the refactor worth it?
  • Is dragging blocks still working as intended.

@youknowriad youknowriad self-assigned this Nov 26, 2019
@youknowriad youknowriad added the [Feature] Drag and Drop Drag and drop functionality when working with blocks label Nov 26, 2019
@@ -196,7 +196,6 @@ class BlockList extends Component {
blockClientIds,
rootClientId,
__experimentalMoverDirection: moverDirection = 'vertical',
isDraggable,
Copy link
Member

Choose a reason for hiding this comment

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

This prop was available so alternative editor implementations could hide the drag icon if they needed (mobile?). Perhaps it's fine to remove, but wanted to flag in case it's not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How successful was that? Any editor you know ever used it?

@@ -19,7 +19,7 @@ import { withInstanceId, compose } from '@wordpress/compose';
*/
import { getBlockMoverDescription } from './mover-description';
import { leftArrow, rightArrow, upArrow, downArrow, dragHandle } from './icons';
import { IconDragHandle } from './drag-handle';
Copy link
Member

Choose a reason for hiding this comment

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

It's on! :trollface:

Not a blocker and would definitely go with what you think is better given that I'm not very active lately. However, I still think IconDragHandle has a place here to hide how the DnD logic works and to maintain the same level of abstraction than the other icons. I find it more useful and fitting now that we've removed the onDragStart / onDragEnd boilerplate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that it's not all good or bad no matter what we do here.

Personally, while working on it, I find the indirection unnecessary as I was forced to jump between three components (DragHandle, BlockDraggable and the Mover).

maintain the same level of abstraction than the other icons

What other icons you're talking about, I personally find it a bit more consistent this way as the Mover is rendering all its buttons in the same way (directly usiung <IconButton>)

Copy link
Member

Choose a reason for hiding this comment

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

What other icons you're talking about, I personally find it a bit more consistent this way as the Mover is rendering all its buttons in the same way (directly usiung )

I wish that was the case! But I can't help but feeling that the "children as function" pattern is still odd and IconDragHandle is a nice way to hide it from readers (until they are ready or need to dig in).

However, my concerns are lessened by the fact that, whatever drag component we use, it is not meant to be widely reusable, so I'm ok with this approach.

Copy link
Member

@oandregal oandregal left a comment

Choose a reason for hiding this comment

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

Tested this for top-level and children blocks, with fixed toolbar and spotlight mode, with admin and contributors roles. Everything worked as before.

Code-wise, this refactor improves the overall readability: good call on moving the isDragging logic to the Redux state!

I believe the removal of the isDragging prop merits a Breaking change notice in the CHANGELOG, though.

@youknowriad youknowriad added the Needs Dev Note Requires a developer note for a major WordPress release cycle label Dec 4, 2019
@youknowriad
Copy link
Contributor Author

Added a potential dev note about the removal of isDraggable.

@youknowriad youknowriad merged commit 9fa7ee3 into master Dec 5, 2019
@youknowriad youknowriad deleted the refactor/draggable-component branch December 5, 2019 13:41
@youknowriad youknowriad added this to the Gutenberg 7.1 milestone Dec 9, 2019
@jorgefilipecosta jorgefilipecosta mentioned this pull request Feb 12, 2020
23 tasks
@youknowriad youknowriad removed the Needs Dev Note Requires a developer note for a major WordPress release cycle label Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Drag and Drop Drag and drop functionality when working with blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants