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

Uncollapse widget area when block is dragged over #25992

Merged
merged 7 commits into from Oct 19, 2020

Conversation

@adamziel
Copy link
Contributor

@adamziel adamziel commented Oct 9, 2020

Description

Solves #25243

I wonder if we should add a timeout and some indication that the widget area is about to uncollapse @mapk ?

How has this been tested?

  1. Start dragging a block and move it over a collapsed widget area
  2. Confirm it was uncollapsed

Types of changes

New feature (non-breaking change which adds functionality)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • [] I've updated all React Native files affected by any refactorings/renamings in this PR.
) }
</PanelBody>
</Panel>
<div onDragOver={ openOnDragOver }>

This comment has been minimized.

@adamziel

adamziel Oct 9, 2020
Author Contributor

There are already a few blank <div/> elements in the tree so this shouldn't break anything. An alternative would be to do <Panel onDragOver={ openOnDragOver }> and then update <Panel /> to apply arbitrary properties to its root element, thoughts?

This comment has been minimized.

@talldan

talldan Oct 12, 2020
Contributor

Yep, I think this is ok.

Another alternative would be <Panel openOnDragOver> making the behavior implicit to Panel. Though I think given PanelBody is more of a controlled component it's better to keep it explicit like you have it here.

This comment has been minimized.

@talldan

talldan Oct 13, 2020
Contributor

Actually, I realise there's some block CSS that might need to be adjusted (though it's currently broken anyway)

https://github.com/WordPress/gutenberg/blob/master/packages/edit-widgets/src/blocks/widget-area/editor.scss#L14

@github-actions
Copy link

@github-actions github-actions bot commented Oct 9, 2020

Size Change: +317 B (0%)

Total Size: 1.19 MB

Filename Size Change
build/components/index.js 170 kB +52 B (0%)
build/edit-widgets/index.js 21.8 kB +265 B (1%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.54 kB 0 B
build/api-fetch/index.js 3.35 kB 0 B
build/autop/index.js 2.72 kB 0 B
build/blob/index.js 668 B 0 B
build/block-directory/index.js 8.6 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/index.js 130 kB 0 B
build/block-editor/style-rtl.css 11 kB 0 B
build/block-editor/style.css 10.9 kB 0 B
build/block-library/editor-rtl.css 8.93 kB 0 B
build/block-library/editor.css 8.93 kB 0 B
build/block-library/index.js 144 kB 0 B
build/block-library/style-rtl.css 7.71 kB 0 B
build/block-library/style.css 7.71 kB 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 741 B 0 B
build/block-serialization-default-parser/index.js 1.77 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 47.6 kB 0 B
build/components/style-rtl.css 15.4 kB 0 B
build/components/style.css 15.4 kB 0 B
build/compose/index.js 9.63 kB 0 B
build/core-data/index.js 12.1 kB 0 B
build/data-controls/index.js 683 B 0 B
build/data/index.js 8.63 kB 0 B
build/date/index.js 31.9 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/dom/index.js 4.43 kB 0 B
build/edit-navigation/index.js 10.6 kB 0 B
build/edit-navigation/style-rtl.css 868 B 0 B
build/edit-navigation/style.css 871 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.37 kB 0 B
build/edit-post/style.css 6.35 kB 0 B
build/edit-site/index.js 21.6 kB 0 B
build/edit-site/style-rtl.css 3.8 kB 0 B
build/edit-site/style.css 3.81 kB 0 B
build/edit-widgets/style-rtl.css 3.09 kB 0 B
build/edit-widgets/style.css 3.09 kB 0 B
build/editor/editor-styles-rtl.css 480 B 0 B
build/editor/editor-styles.css 482 B 0 B
build/editor/index.js 42.6 kB 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.84 kB 0 B
build/element/index.js 4.45 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.49 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 1.74 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.54 kB 0 B
build/is-shallow-equal/index.js 709 B 0 B
build/keyboard-shortcuts/index.js 2.38 kB 0 B
build/keycodes/index.js 1.85 kB 0 B
build/list-reusable-blocks/index.js 3.02 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.12 kB 0 B
build/notices/index.js 1.69 kB 0 B
build/nux/index.js 3.27 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.44 kB 0 B
build/primitives/index.js 1.35 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/reusable-blocks/index.js 3.04 kB 0 B
build/rich-text/index.js 13 kB 0 B
build/server-side-render/index.js 2.61 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.24 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.75 kB 0 B
build/warning/index.js 1.13 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@paaljoachim
Copy link
Contributor

@paaljoachim paaljoachim commented Oct 9, 2020

Hey Adam (I am looking at the UI approach.)

This is what I see:
Drag-widget-over-a-closed-widget-area

Dragging the widget over the Footer 2 closed widget area, creates a sudden jerk/push downward of the cursor. Here it would be better to calmly drag a widget over the closed area, and have the area open downward. It should not affect the drag only the area.

Here is the old Widget screen in comparison:
Old-Widget-screen-drag-drop

What is great about the old method is that it does nothing with the drag as it happens.
It only opens the widget areas smoothly with a short delay and shows the space to where one can drop it into. (For the newer version we have the blue line.)
If one decides not to drop it into the new widget area and moves the cursor back to the initial widget area the second area automatically closes. Go for something similar to the old method.

@adamziel
Copy link
Contributor Author

@adamziel adamziel commented Oct 9, 2020

@paaljoachim my thoughts exactly! That's what I meant by asking:

I wonder if we should add a timeout and some indication that the widget area is about to uncollapse @mapk ?

If the user wants to drag the widget from sidebar number 1 to sidebar 8, the current jerk will make it pretty hard so I think we should indicate that the area is about to open, but still give user a chance to keep dragging. I'm not sure how that indication would look like, hence I pinged @mapk :-)

@adamziel
Copy link
Contributor Author

@adamziel adamziel commented Oct 9, 2020

@paaljoachim I think your suggestion to makes collapsing/uncollapsing smooth would make a great feature not just here, but also for the Panel component.

[ clientId ]
);
const { setIsWidgetAreaOpen } = useDispatch( 'core/edit-widgets' );
const openOnDragOver = useCallback( () => {
if ( ! isOpen && isDraggingBlocks ) {

This comment has been minimized.

@talldan

talldan Oct 12, 2020
Contributor

I don't think we should worry about isDraggingBlocks, it should also open for dragged files and HTML so that users can upload/add things like images that way.

) }
</PanelBody>
</Panel>
<div onDragOver={ openOnDragOver }>

This comment has been minimized.

@talldan

talldan Oct 12, 2020
Contributor

Yep, I think this is ok.

Another alternative would be <Panel openOnDragOver> making the behavior implicit to Panel. Though I think given PanelBody is more of a controlled component it's better to keep it explicit like you have it here.

@mapk
Copy link
Contributor

@mapk mapk commented Oct 12, 2020

Hey 👋 there. I really like auto-expanding the area when dragging over it! I do also agree with @paaljoachim's feedback. The jump that occurs right now is confusing.

I wonder if we should add a timeout and some indication that the widget area is about to uncollapse @mapk ?

I don't think we need an indicator necessarily. The expansion of the area seems to be a sufficient. Moving the dragged block into a collapsed area should open it but retain its positioning on screen and not jump to a particular point. Dragging it back out of the area should collapse that area again. I like how it works in the Classic Widget screen that Paal shared. When opening up an area on drag, the blue line drop indicator should appear above any existing widgets in that area if the user is dragging downward from one area to another area below. This should reverse when dragging up from an area below to an area above.

@talldan
Copy link
Contributor

@talldan talldan commented Oct 13, 2020

There is some similar code in the navigation-link block that might be reusable (cc @kevin940726), but still think this works well enough as a first iteration.

@adamziel
Copy link
Contributor Author

@adamziel adamziel commented Oct 13, 2020

I think it's nearly there, the last part is smooth panel animation - let's make it a separate PR.

*
* @return {boolean} Is dragging within the target element.
*/
const useIsDraggingWithin = ( elementRef ) => {

This comment has been minimized.

@adamziel

adamziel Oct 13, 2020
Author Contributor

I just copied that over from edit-navigation - happy to move it to another package if there are any good candidates.

This comment has been minimized.

@talldan

talldan Oct 19, 2020
Contributor

Seems fine to duplicate it for now 👍

// Ref is used so that the effect does not re-run upon scrollAfterOpen changing value
const scrollAfterOpenRef = useRef();
scrollAfterOpenRef.current = scrollAfterOpen;
Comment on lines +51 to +53

This comment has been minimized.

@adamziel

adamziel Oct 13, 2020
Author Contributor

This seems hackish - any better ideas?

This comment has been minimized.

@talldan

talldan Oct 19, 2020
Contributor

Yeah, not sure really. 🤔

} else if ( ! isDraggingWithin && isOpen && openedWhileDragging ) {
timeout = setTimeout( () => {
setOpen( false );
}, 100 );

This comment has been minimized.

@adamziel

adamziel Oct 13, 2020
Author Contributor

Completely arbitrary timeouts

This comment has been minimized.

@talldan

talldan Oct 19, 2020
Contributor

I'm personally finding the delays are unhelpful. The problem is that there's no indication anything is about to happen when I first drag over, and also the way the page scrolls while dragging means it's quite easy to zoom past an area.

The sidebars for the old widget page open immediately, so I think we can replicate that for now and revisit this. I took the liberty of pushing a commit to do that.

@mapk
Copy link
Contributor

@mapk mapk commented Oct 13, 2020

I just gave this a go again! Really close! I'm still noticing a jump when dragging into a longer widget area. Can we just expand the widget area downward without the jump? I also saw that when leaving a widget area that expanded, it doesn't collapse again. Is this possible?

jump

@tellthemachines
Copy link
Contributor

@tellthemachines tellthemachines commented Oct 14, 2020

Testing this, I'm still unable to drag a widget into an empty widget area. Even though the empty now opens when dragged over, there's no drop indicator and dropping a widget on it doesn't work. How easy would it be to fix it in this PR? Or better to open another issue?

@talldan
Copy link
Contributor

@talldan talldan commented Oct 14, 2020

@tellthemachines The fix was only recently merged - #26051

It's either that this PR needs to be rebased, or it might also need to be updated to account for the selectors mentioned here:
#25992 (comment)

@draganescu
Copy link
Contributor

@draganescu draganescu commented Oct 15, 2020

I tested this and for me it did not work.

@paaljoachim
Copy link
Contributor

@paaljoachim paaljoachim commented Oct 18, 2020

I tested again. Either I am not testing correctly as it seems to be showing an older commit.
I use this testing method for testing a commit (I tested the bottom commit):
git fetch origin pull/25992/head
git checkout 83919b51665b6c3fc0732d2e23b1a2c256e02e1c
npm run build

This is what I see:

Drag-Drop-Uncollapse-Widget-area

There is still a jumpiness when dragging from one widget area to another. As it jumps too far down.
I just looked closer at the gif and there seems to be some jumpiness also with the drop zone. I believe it might have to do with holding the cursor close to the top widget/block. As the blue line can come and go.

@talldan talldan force-pushed the update/uncollapse-widget-areas-on-drag branch from 83919b5 to 04ef9a5 Oct 19, 2020
Copy link
Contributor

@talldan talldan left a comment

I've rebased and double-checked the fix from #26051 still works, which it does 👍

I'm personally not seeing any sudden jumps with the latest code, but noticed a separate issue.

The scroll while dragging behavior that the block editor has isn't particularly great with panels. What happens is that when a panel opens while dragging over it, suddenly there's more space that the page can scroll into.

Not sure what to do about that, but it's definitely separate to this.

Let's merge and then iterate to improve it.

@talldan talldan merged commit 9fc1bb6 into master Oct 19, 2020
15 checks passed
15 checks passed
@github-actions
Cancel Previous Runs Cancel Previous Runs
Details
@github-actions
Check Check
Details
@github-actions
build
Details
@github-actions
Admin - 1
Details
@github-actions
Compare performance with master
Details
@github-actions
pull-request-automation
Details
@github-actions
test (gutenberg-editor-gallery)
Details
@github-actions
test (gutenberg-editor-gallery)
Details
@github-actions
JavaScript
Details
@github-actions
Admin - 2
Details
@github-actions
Admin - 3
Details
@github-actions
Mobile
Details
@github-actions
Admin - 4
Details
Block-based Widgets Editor automation moved this from PRs in progress to Done Oct 19, 2020
@talldan talldan deleted the update/uncollapse-widget-areas-on-drag branch Oct 19, 2020
@talldan talldan changed the title [Try] Uncollapse widget area when block is dragged over Uncollapse widget area when block is dragged over Oct 19, 2020
@github-actions github-actions bot added this to the Gutenberg 9.2 milestone Oct 19, 2020
const scrollAfterOpenRef = useRef();
scrollAfterOpenRef.current = scrollAfterOpen;
Comment on lines +52 to +53

This comment has been minimized.

@ZebulanStanphill

ZebulanStanphill Oct 19, 2020
Member

I think this could be simplified to:

Suggested change
const scrollAfterOpenRef = useRef();
scrollAfterOpenRef.current = scrollAfterOpen;
const scrollAfterOpenRef = useRef( scrollAfterOpen );

And yeah, this definitely feels like a code smell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment