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

External Media: Don't append to Coblocks replace button #17493

Merged
merged 1 commit into from
Nov 9, 2020

Conversation

obenland
Copy link
Member

@obenland obenland commented Oct 15, 2020

Fixes #17476.

Changes proposed in this Pull Request:

  • Very rudimentarily checks if the media button render function contains the coblocks textdomain and doesn't append external media links if it does.

Does this pull request change what data or activity we track or use?

No

Before After
image

Testing instructions:

  • Go to the Editor
  • Insert an image block and select an image.
  • Click on "Replace" in the block toolbar and make sure External Media is still available there.
  • Check the sidebar and make sure External Media links are no longer there.

Proposed changelog entry for your changes:

  • External Media: Fixed a conflict with CoBlock's image replace feature.

@obenland obenland added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Team Review [Extension] External Media Extend all block editor media tools to support external providers labels Oct 15, 2020
@obenland obenland requested review from alaczek and a team October 15, 2020 18:41
@obenland obenland self-assigned this Oct 15, 2020
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello obenland! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D51230-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@jetpackbot
Copy link

Scheduled Jetpack release: November 10, 2020.
Scheduled code freeze: November 3, 2020

E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-17493

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Generated by 🚫 dangerJS against 393a16b

Copy link
Contributor

@mreishus mreishus left a comment

Choose a reason for hiding this comment

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

  • ✔️ It works correctly.
  • (Minor) The .indexOf() compared to -1 stuff can be replaced with .includes() in both forms:
> "hamburger".includes("burger")
true
> [1, 10, 15].includes(10)
true
  • (Minor) If there isn't a render prop, it crashes when trying to call .toString() on null. But probably not an issue since you need a render prop to use <MediaLibrary>.
  • ❔ Using render.toString() and looking for 'coblocks' in the string seems questionable (brittle, potentially slow), but there aren't a lot of other options.

The coblocks call looks like this:

								<MediaUpload
									allowedTypes={ [ 'image' ] }
									onSelect={ onSelectImage }
									value={ props.url }
									render={ ( { open } ) => (
										<Button
											isSmall
											isSecondary
											onClick={ open }>
											{ __( 'Replace Image', 'coblocks' ) }
										</Button>
									) }
								>
								</MediaUpload>

So it finds the 'coblocks' they happen to use in a translation function. But what if they replaced the text with an icon? It would stop working. But there isn't enough information elsewhere to go off of.

  • Possibility 1: Change the coblocks call to <MediaUpload> to add a prop like context="coblocks". Doesn't seem likely to happen since it's not our code.
  • Possibility 2: Go the other direction and make all of our calls to <MediaUpload> add a includeExternalSource={true} prop. Also, doesn't seem that good.

So I see the shortcomings but I can't really think of anything better. 🤷‍♂️ .

In my testing with performance.now(), converting the string to a function and looking for the word 'coblocks' in it took 0.01 milliseconds most of the time, and ~2 milliseconds sometimes.

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Team Review labels Oct 19, 2020
@marekhrabe
Copy link
Contributor

(Minor) The .indexOf() compared to -1 stuff can be replaced with .includes() in both forms

IE11 doesn't support this. I'm not 100% sure whether we polyfill this or not, that would need to be checked in the repository or the Gutenberg project

@jeherve jeherve added this to the 9.2 milestone Oct 30, 2020
@jeherve jeherve added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Oct 30, 2020
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Nov 9, 2020
@obenland obenland merged commit 380c497 into master Nov 9, 2020
@obenland obenland deleted the fix/external-media-image-replace branch November 9, 2020 19:23
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Nov 9, 2020
@obenland
Copy link
Member Author

obenland commented Nov 9, 2020

r216518-wpcom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Extension] External Media Extend all block editor media tools to support external providers Touches WP.com Files [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image Block: External media source icons in the wrong spot
6 participants