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: Remove editor usage from media blocks. #15548

Conversation

jorgefilipecosta
Copy link
Member

Description

Blocks should not use editor module directly and the editor module may not available in all edition environments (e.g. in the widget screen).

This PR makes sure the mediUpload function used in the image, audio, video, and file blocks is the one provided in the block-editor settings instead of being the one from wordpress/editor.

How has this been tested?

I tried to insert all the changed blocks by dragging files in the editor and I verified thigs worked as expected.

@jorgefilipecosta jorgefilipecosta added [Type] Enhancement A suggestion for improvement. [Feature] Media Anything that impacts the experience of managing media [Feature] Widgets Screen The block-based screen that replaced widgets.php. labels May 9, 2019
@gziolo
Copy link
Member

gziolo commented May 10, 2019

What about Gallery block? It uses mediaUpload in transforms file.

@gziolo
Copy link
Member

gziolo commented May 10, 2019

I personally don't like this pattern in the current shape as I anticipate that it's going to be copied to 3rd party blocks even though we prefix the method with __experimental.

@jorgefilipecosta
Copy link
Member Author

What about Gallery block? It uses mediaUpload in transforms file.

All the blocks changed in this PR had the same change. The gallery bock is a different case, so I will try to address it in a different PR.

I personally don't like this pattern in the current shape as I anticipate that it's going to be copied to 3rd party blocks even though we prefix the method with __experimental.

I think an option is to remove __experimental prefix. Another option is to add the behavior of uploading temporary URLs to MediaPlaceholder or to a new component part of block-editor, so blocks will not have a need to call a mediaUpload function directly.
Not sure what is the best option to follow here. cc @gziolo, @youknowriad.

@youknowriad
Copy link
Contributor

youknowriad commented May 10, 2019

This __experimentalMediaUpload is already existing before this PR. It's still new and for me it should stay this way for some more releases but it raises the question that we should probably do an audit of the experimental APIs and "stabilize" the ones that are here for some time and proved to be good enough.

@jorgefilipecosta
Copy link
Member Author

It is also important to note that while import { mediaUpload } from '@wordpress/editor'; does not contain any experimental flag, third-party blocks may use this option instead of something similar to what I did in this PR (that contains the experimental flag), and if that's the case, we may have a problem as these blocks will not work on the widget screen.

@youknowriad
Copy link
Contributor

we may have a problem as these blocks will not work on the widget screen.

By that time, both the widget screen and this API won't be considered experimental I think

@jorgefilipecosta
Copy link
Member Author

This __experimentalMediaUpload is already existing before this PR. It's still new and for me it should stay this way for some more releases but it raises the question that we should probably do an audit of the experimental APIs and "stabilize" the ones that are here for some time and proved to be good enough.

What about using this __experimentalMediaUpload setting in our own blocks, is it something we are ok with for now? Or should we try to abstract this call inside a new component or inside MediaPlaceholder?

@youknowriad
Copy link
Contributor

I was saying, I'm ok with us using it. For third party blocks, The experimental APIs are documented clearly, why this one should be an exception.

@gziolo
Copy link
Member

gziolo commented May 10, 2019

It’s fine to merge it as a stopgap solution but it would be nice to address it before WordPress 5.3 release.

I think that the biggest downside of this approach is that it introduces a lot of complexity which would be nice to hide for plugin developers as @jorgefilipecosta mentioned thus making it an implementation detail.

@jorgefilipecosta jorgefilipecosta force-pushed the fix/remove-editor-usage-from-some-media-block-edit-components branch from c7338ee to e405fb6 Compare June 3, 2019 16:54
@jorgefilipecosta
Copy link
Member Author

This PR was updated, and now we are also addressing the gallery case, this makes the gallery way of handling file drops in line with the approach used by all other blocks.
I agree with @gziolo that there may be an opportunity to abstract this upload logic and simplify bock code, but I think we can advance with these changes which fix an existing problem and make blocks code more consistent and then we can try to extract this blob upload logic.

@jorgefilipecosta jorgefilipecosta changed the title Fix: Remove editor usage from some media blocks. Fix: Remove editor usage from media blocks. Jun 3, 2019
@jorgefilipecosta jorgefilipecosta added the [Priority] High Used to indicate top priority items that need quick attention label Jun 5, 2019

export default withNotices( AudioEdit );
export default compose( [
withSelect( ( select ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about useSelect ;)

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 I did not use useSelect because these are class components (where hooks could not be used), and most of the cases already had a withSelect usage. I guess if there are some benefits of the usage of the hook, we can create specific PR's with a refactor to hooks before the next block change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense

@youknowriad
Copy link
Contributor

It looks like with this change, the only other parts where we use the "core/editor" store or the editor package in the block library are:

  • The "date" of the post object in the calendar block (this should probably default to "no date" if the store is not available.
  • Reusable blocks APIs, two options here: maybe the solution ehre is to move these to the block editor settings (like mediaUpload).

@jorgefilipecosta jorgefilipecosta merged commit 8f65b7c into master Jun 11, 2019
@jorgefilipecosta jorgefilipecosta deleted the fix/remove-editor-usage-from-some-media-block-edit-components branch June 11, 2019 12:43
@gziolo gziolo added this to the Gutenberg 6.0 milestone Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Media Anything that impacts the experience of managing media [Feature] Widgets Screen The block-based screen that replaced widgets.php. [Priority] High Used to indicate top priority items that need quick attention [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants