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

Media Library: Implement upload media from URL #41089

Open
wants to merge 12 commits into
base: trunk
Choose a base branch
from

Conversation

fushar
Copy link
Contributor

@fushar fushar commented Jan 15, 2025

Fixes https://github.com/Automattic/dotcom-forge/issues/10180

Proposed changes:

This PR implements the feature where we can upload media files from URL in the Media Library and Site Editor.

The UX is implemented by following the default file upload behavior as similar as possible.

See the following videos:

Media Library

48MySt.mp4

Site Editor

lFwwGW.mp4

Implementation Details

This feature is implemented by showing a simple url input form after the Plupload uploader via the post-plupload-upload-ui hook. On submitting the form, it calls an AJAX handler, which then call Core's download_url() and then media_handle_sideload(). This logic is very similar to that of the original endpoint used by Calypso version of the Media Library.

Limitations

  • This feature is currently not available in Media -> Add New Media File.
  • This feature currently won't send video files to VideoPress; we still need to use the dropzone.

Failure Cases

The upload form can handle failure cases, e.g. when the media has unsupported extension. It will show an error notice, similar to when we upload the file via the dropzone:

PwQbJv.mp4

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

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

Testing instructions:

  1. Patch this PR using the instructions provided by the bot.
  2. Try to upload via URL in both Media -> Library and Site Editor as per the videos above.
  3. Test in both Simple and Atomic sites.
  4. Try to break it.

Copy link
Contributor

github-actions bot commented Jan 15, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the wpcom-media-url-import branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack-mu-wpcom-plugin wpcom-media-url-import
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented Jan 15, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • 🔴 Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Jan 15, 2025
@fushar fushar force-pushed the wpcom-media-url-import branch 2 times, most recently from 85afb83 to 24a4df4 Compare January 20, 2025 02:20
@fushar fushar changed the title WIP Implement media import via URL Implement upload media from URL Jan 20, 2025
@fushar fushar force-pushed the wpcom-media-url-import branch 7 times, most recently from 3f8e1cb to ba93666 Compare January 21, 2025 15:05
@fushar fushar changed the title Implement upload media from URL Media Library: Implement upload media from URL Jan 21, 2025
@fushar fushar marked this pull request as ready for review January 21, 2025 22:49
@fushar fushar requested review from a team and jameskoster January 21, 2025 22:49
@fushar fushar self-assigned this Jan 21, 2025
okmttdhr
okmttdhr previously approved these changes Jan 22, 2025
Copy link
Member

@okmttdhr okmttdhr left a comment

Choose a reason for hiding this comment

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

Tested this both on Media -> Library and Site Editor and worked well 👍


import './style.scss';

const WpcomMediaUrlUploadForm = ( { ajaxUrl, action, nonce, isSiteEditor } ) => {
Copy link
Member

Choose a reason for hiding this comment

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

badge I believe we can turn jsx into tsx

@taipeicoder
Copy link
Contributor

It seems that window.wp.media.frame.content.get().collection is unset whenever the preview modal is shown. As a result, the following flow breaks for me:

  1. Open the preview modal and close it.
  2. Try to upload media via URL.
  3. Get the JS error Uncaught TypeError: Cannot read properties of undefined (reading 'add') pointing to the line https://github.com/Automattic/jetpack/pull/41089/files#diff-1488c0a404dd4b7e54404ac816954fb83810886fcb03fc282ea8845c4dfc8503R55
Screen.Capture.on.2025-01-22.at.17-12-33.mp4

@arthur791004
Copy link
Contributor

Left minor feedback as follows:

image

  • It would be better to increase the gap between input and button
  • How to dismiss the input to restore the page to the link?

image

  • The user may not notice there is a link... There are lots of items there and, weirdly, the link is shown between storage usage and max size 😅

@fushar
Copy link
Contributor Author

fushar commented Jan 23, 2025

The user may not notice there is a link... There are lots of items there and, weirdly, the link is shown between storage usage and max size 😅

It's all based on the design in https://github.com/Automattic/dotcom-forge/issues/10180#issuecomment-2572909885. @jameskoster, thoughts?

@arthur791004
Copy link
Contributor

It's all based on the design in https://github.com/Automattic/dotcom-forge/issues/10180#issuecomment-2572909885. @jameskoster, thoughts?

Yep but the design doesn't have the storage usage there. Maybe we can remove it since there is another one below the page title 🤔

@fushar fushar force-pushed the wpcom-media-url-import branch from f6c24d0 to d37ff21 Compare January 26, 2025 13:50
Copy link
Member

@okmttdhr okmttdhr left a comment

Choose a reason for hiding this comment

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

I could check the visual updates 👍

@fushar
Copy link
Contributor Author

fushar commented Jan 30, 2025

BTW I found this change also affected media library

But isn't this the whole reason of the PT? This is to (re-)allow users to upload images from URL in the Site Editor, because without the editor iframe, we lose the ability to do that using native Core's Media Library (see: Automattic/wp-calypso#98590)

Copy link
Contributor

github-actions bot commented Jan 30, 2025

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php 0/216 (0.00%) 0.00% 1 💔

1 file is newly checked for coverage.

File Coverage
projects/packages/jetpack-mu-wpcom/src/features/wpcom-media/wpcom-media-url-upload.php 0/42 (0.00%) 💔

Full summary · PHP report · JS report

@fushar
Copy link
Contributor Author

fushar commented Jan 30, 2025

How to dismiss the input to restore the page to the link?

@jameskoster, thoughts? Should we allow the user to "close" the form and show the link back? (I'm not sure if it's worth it IMO)

@fushar fushar force-pushed the wpcom-media-url-import branch from 1fcbc2a to 984679d Compare February 3, 2025 04:34
@fushar
Copy link
Contributor Author

fushar commented Feb 3, 2025

I think we should only display the storage info in this location if the user is approaching maximum capacity (>95% or something). Otherwise I agree it's a bit distracting.

I'm not sure it's a good idea. The Calypso version of this page shows this storage info in all cases. If we remove it, I'm afraid users will lose this functionality.

image

Maybe we can remove it since there is another one below the page title 🤔

Unfortunately, in the Site Editor (media blocks), it's the only place where we show the storage info, so we can't remove it.

Also agree we should increase the gap between input + submit button slightly. 6px seems to be quite common across wp-admin.

This is done ✅

Finally can we double-check the link color?

Unfortunately, the link color comes from Core (https://github.com/WordPress/wordpress-develop/blob/bcdca3f9925f1d3eca7b78d231837c0caf0c8c24/src/wp-includes/css/media-views.css#L39) with very high specificity of the selector. It's not easy to override it without JavaScript magic because there's no way to get the current link color of the current color scheme 🥲

To overcome the above issue(s), what if we make it as a button, and put it above the storage info? Like this:

image

I pushed it to this PR. What do you think?

@arthur791004
Copy link
Contributor

Unfortunately, in the Site Editor (media blocks), it's the only place where we show the storage info, so we can't remove it.

How about using the $pagenow to determine whether to hide it? Is it a good idea 🤔

@lsl
Copy link
Contributor

lsl commented Feb 4, 2025

Unfortunately, in the Site Editor (media blocks), it's the only place where we show the storage info, so we can't remove it.

What's the error message you see if you run out of space and try to upload media via blocks?

@fushar
Copy link
Contributor Author

fushar commented Feb 4, 2025

What's the error message you see if you run out of space and try to upload media via blocks?

@lsl Looking at the code I think it will just show this generic message like this if this is what you're asking.

image

@fushar
Copy link
Contributor Author

fushar commented Feb 4, 2025

How about using the $pagenow to determine whether to hide it? Is it a good idea 🤔

I'm now thinking that we should treat this discussion as separate ticket (like the upsell message simplification). It's not really related to the upload via URL feature 🥹

@arthur791004
Copy link
Contributor

I'm now thinking that we should treat this discussion as separate ticket (like the upsell message simplification). It's not really related to the upload via URL feature 🥹

Make sense! I'll review this PR again, and let's iterate the UI in the follow-up PR 🙂

Copy link
Contributor

@arthur791004 arthur791004 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 to me. Left some minor feedback 🙂

arthur791004
arthur791004 previously approved these changes Feb 5, 2025
Copy link
Contributor

@arthur791004 arthur791004 left a comment

Choose a reason for hiding this comment

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

Tested and works as expected 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[mu wpcom Feature] Wpcom Media [Package] Jetpack mu wpcom WordPress.com Features [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants