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

File block: Handle drag-and-drop errors #8066

Merged
merged 1 commit into from
Jul 23, 2018

Conversation

noisysocks
Copy link
Member

Description

Fixes #8025.

Handle any errors that occur when a File block is created via a files transform. That is, when a file is drag-and-dropped into the editor.

How has this been tested?

  1. Drag an unsupported file (e.g. .js, .diff, .json, .exe) into the editor
  2. Insert a File block and drag an unsupported file onto the block
  3. Drag a supported file (e.g. .zip, .pdf) into the editor
  4. Insert a File block and drag a supported file onto the block

Screenshots

drag-and-drop

Handle any errors that occur when a File block is created via a files
transform. That is, when a file is drag-and-dropped into the editor.
@noisysocks noisysocks added [Type] Bug An existing feature does not function as intended [Feature] Blocks Overall functionality of blocks labels Jul 20, 2018
@@ -59,6 +61,10 @@ class FileEdit extends Component {
allowedType: '*',
filesList: [ file ],
onFileChange: ( [ media ] ) => this.onSelectFile( media ),
onError: ( message ) => {
this.setState( { hasError: true } );
Copy link
Member Author

@noisysocks noisysocks Jul 20, 2018

Choose a reason for hiding this comment

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

I had to use local state here instead of setAttributes( { href: undefined } ) because we don't support calling setAttributes() in componentDidMount.

(Also, we probably shouldn't be using attributes for this anyway—see #3553.)

@talldan talldan removed their assignment Jul 20, 2018
@talldan talldan self-requested a review July 20, 2018 08:38
Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

Looks good. 👍

I did wonder if isMatch could be used to disallow the transform, but I think showing an appropriate error and the behaviour being similar to when using the MediaPlaceholder are benefits to this approach.

@talldan
Copy link
Contributor

talldan commented Jul 23, 2018

Actually - I did spot an issue. Not caused by this, but related.

If you drag an unsupported file type, then update the post and refresh you see a message that the block has encountered an error. Looks like the blob is revoked but the href is still set as an attribute, so it goes through the whole editorMediaUpload call again when mounting, but fails:
https://github.com/WordPress/gutenberg/blob/master/core-blocks/file/edit.js#L55

I can create it as a separate issue if you want to get this PR merged. (edit, issue here #8155)

@noisysocks
Copy link
Member Author

Good spotting! There's a whole lot of bugs that exist because we store blob URLs in blocks attributes. We definitely should move away from doing this. #8119 was created as an umbrella issue for this.

@noisysocks
Copy link
Member Author

I did wonder if isMatch could be used to disallow the transform, but I think showing an appropriate error and the behaviour being similar to when using the MediaPlaceholder are benefits to this approach.

Yeah, totally. I experimented with not allowing the drag-and-drop at all if it's an invalid transform, but decided against it because it makes it feel like the browser is not responsive.

@noisysocks noisysocks merged commit 7aacd2d into master Jul 23, 2018
@noisysocks noisysocks deleted the fix/file-block-unallowed-file-types branch July 23, 2018 23:47
@noisysocks noisysocks added this to the 3.4 milestone Jul 23, 2018
@oandregal oandregal added the [Feature] Drag and Drop Drag and drop functionality when working with blocks label Aug 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Feature] Drag and Drop Drag and drop functionality when working with blocks [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants