-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Contributors can not use drag & drop #15054
Fix: Contributors can not use drag & drop #15054
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will render the dropzone and will allow the user to drop an image from the desktop. It won't work, though, because the DropZoneProvider checks whether the DnD type is supported. We should take the DnD type into account in the DropZoneComponent's render method as well.
@@ -116,17 +116,20 @@ class BlockDropZone extends Component { | |||
return null; | |||
} | |||
const isAppender = index === undefined; | |||
|
|||
const dropZone = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was thinking how to improve readability here to better communicate the difference. Some raw thoughts:
- Do not use the
MediaUploadCheck
component but use thehasUploadPermissions
prop:
<DropZone
className={ ... }
onHTMLDrop={ this.onHTMLDrop }
onDrop={ this.onDrop }
onFilesDrop={ hasUploadPermissions ? this.onFilesDrop : null }
/>
- Extract and rename the dropzone components so we return:
return (
<MediaUploadCheck
fallback={ dropZoneWithoutFileDrop }>
dropZoneWithFileDrop
</MediaUploadCheck>
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nosolosw, I updated the code to follow your first suggestion.
c5821e1
to
ee3cc38
Compare
Hi @nosolosw thank you for the review, I applied a code simplification based on your suggestions.
In my tests, I can drag & drop blocks and files in the normal editor, and on the widgets editor (/admin.php?page=gutenberg-widgets) I can drag blocks but not files because uploads are not supported yet. This seems to work exectly as expected I'm probably missing a usage, what is failing in your tests/what are the steps to reproduce the problem? |
These are my testing steps:
In In this branch, it will, although unsuccessfully (an user without upload permissions shouldn't be able to drag anything from the desktop): |
ee3cc38
to
56fc5b7
Compare
Thank you for providing clear steps to reproduce the issue you found @nosolosw 👍 The problem was fixed. |
I still can upload files with the steps above (although the visual indicator isn't rendered). |
56fc5b7
to
9a6ff94
Compare
Hi @nosolosw, I'm not being able to reproduce the problem. For contributor roles, the blue bar does not appear and the upload does not happen if I drag a file over the position the blue bar would appear. Maybe there was a caching issue? Would it be possible to do another try? Thank you in advance! |
9a6ff94
to
8452a32
Compare
8452a32
to
bce23fc
Compare
This PR was rebased and retested and it seems to still be valid. |
I gave it a spin today at this. This is what I've done:
GIF (note how the first time I dropped the image nothing happened, but the second time an invalid block was created): The code for the invalid block:
|
bce23fc
to
0e5dc2d
Compare
Hi @nosolosw thank you for the review! Unfortunately, I was never able to replicate the problem. But from the issue description and gif, it seems for some reason onFilesDrop is being called. I added a check for upload permissions inside onFileDrop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now DnD works for contributors as well!
Currently, if the user has no permission to upload files, the user is not able to use block drag & drop.
This PR fixes the problem.
How has this been tested?
I added some paragraphs in Gutenberg playground.
I hovered with the mouse at the left side of the paragraph until the hand to grab the paragraph appeared. The reason why the block movers don't become visible on the playground is probably another bug that I will try to find the cause.
I changed the paragraph position by dropping it above the blue line in another position.
I tried to drag a file to the playground and verified it was not possible to do it and the blue line to drop never appeared -- in the playground the user is not able to upload files.