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: Move the external-media to the new @automattic/jetpack-external-media package #41078

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

Conversation

arthur791004
Copy link
Contributor

@arthur791004 arthur791004 commented Jan 15, 2025

Related to https://github.com/Automattic/dotcom-forge/issues/10251 and pbxlJb-6P2-p2

Proposed changes:

Referring to p1737356188889759-slack-CDLH4C1UZ, let's try to create a new package, external-media to complete our project, https://github.com/Automattic/dotcom-forge/issues/10251 and pbxlJb-6P2-p2, to add the ”Import Media” page on WP Admin to allow users to import photos from external media.

Here are the proposal of this PR:

image

  • Move the codebase related to the AI to the @automattic/jetpack-ai-client
  • Move the codebase related to the external-media to the @automattic/jetpack-external-media
  • Move the codebase related to AI, external-media, and others to the @automattic/jetpack-shared-extension-utils

Main changes

  • js-packages/ai-client
    • Added components/ai-icon
    • Added components/ai-images
    • Added components/modal
    • Added components/quota-exceeded-message
    • Added hooks/use-ai-checkout
    • Added hooks/use-ai-feature
    • Added hooks/use-post-content
    • Added hooks/use-save-to-media-library
    • Added libs/connection
    • Added store/wordpress-com and export it under the subpath, @automattic/jetpack-ai-client/store/wordpress-com
  • js-packages/components
    • Export the getRedirectUrl under the subpath, @automattic/jetpack-components/tools/jp-redirect. The issue is ai-client is built with different way, nodenext, and we cannot import this package directly. Otherwise, you will see lots of following error:
      • Relative import paths need explicit file extensions in EcmaScript imports when ‘--moduleResolution’ is ‘node16’ or ‘nodenext’
  • js-packages/shared-extension-utils
    • Added block-icons
    • Added components/number-control
    • Added components/upgrade-nudge
    • Added hooks/use-autosave-and-redirect
    • Added hooks/use-plan-type
    • Added hooks/use-ref-interval
    • Added icons
  • js-packages/storybook
    • Changed the target from es2018 to esnext. There are components with stories that is moved to the js-packages/ai-client, and it seems to break the build of the storybook. As a result, we have to change the target to esnext
  • packages/external-media
    • Migrated the external-media to this package
  • plugins/jetpack/extensions/shared
    • Moved lots of components, hooks, icons to either js-packages/ai-client or js-packages/shared-extension-utils
    • Moved external-media to packages/external-media
  • plugins/jetpack/modules/external-media
    • Register the external-media module by the module-extra.php suggested by p1737706488009929/1737356188.889759-slack-CDLH4C1UZ 🙂

Issues

  • projects/plugins/jetpack/extensions/store/wordpress-com - The wordpress-com/plans store that is used by ai-assistent-plugin (e.g.: useAiImage). I'm unsure whether it's good to move to @automattic/jetpack-ai-client
    • Note that it cannot be moved to @automattic/jetpack-shared-extension-utils because of the circular dependency. Maybe we need to create another new package for this case.
  • JP_CONNECTION_INITIAL_STATE - Some of the components related to AI requires data
    from the injected global variable, JP_CONNECTION_INITIAL_STATE. I'm unsure whether these components can be moved to a package or not.

Quick Demo

See #41282 for a quick demo. The PR shows importing external media on the new Import Media page.

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:

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 feat/move-external-media-to-package 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 feat/move-external-media-to-package
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin feat/move-external-media-to-package
    

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

@github-actions github-actions bot added [Block] AI Assistant [Extension] AI Assistant Plugin [Extension] External Media Extend all block editor media tools to support external providers [JS Package] Shared Extension Utils [Plugin] CRM Issues about the Jetpack CRM plugin [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Social Issues about the Jetpack Social plugin [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Plugin] Wpcomsh [Status] In Progress [Tests] Includes Tests Docs RNA labels Jan 15, 2025
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!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for February 4, 2025 (scheduled code freeze on February 4, 2025).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Backup plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Boost plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Search plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Social plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Starter Plugin plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Protect plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Videopress plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Mu Wpcom plugin:

  • Next scheduled release: WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Inspect plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Wpcomsh plugin:

  • Next scheduled release: Atomic deploys happen twice daily on weekdays (p9o2xV-2EN-p2).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Automattic For agencies client plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Classic Theme helper plugin plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@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
@jeherve
Copy link
Member

jeherve commented Jan 15, 2025

Jumping in here as the title caught my eye. Is there a p2 post about this, so I can l learn more about the project? I must say it feels odd at first to have a full feature moved to a utility package.

@arthur791004 arthur791004 force-pushed the feat/move-external-media-to-package branch from 5042902 to 6ca8de7 Compare January 15, 2025 12:11
@arthur791004 arthur791004 changed the title WIP External Media: Move the codebase to @automattic/jetpack-shared-extension-utils WIP External Media: Move the GooglePhotosMedia, OpenverseMedia, PexelsMedia to @automattic/jetpack-shared-extension-utils Jan 15, 2025
@arthur791004
Copy link
Contributor Author

arthur791004 commented Jan 15, 2025

@jeherve It's related to https://github.com/Automattic/dotcom-forge/issues/10251 and pbxlJb-6P2-p2 We want to add the import media page to allow users to import external media on WP Admin to eliminate the feature gaps of the Media page between Calypso and WP Admin.

The goal of this PR is to share the external media modal so it can be used by jetpack-mu-wpcom. I'm just trying and unsure whether this is a correct solution. Do you have any thoughts? Thanks for catching up this so quickly 🙂

@arthur791004 arthur791004 force-pushed the feat/move-external-media-to-package branch 4 times, most recently from fc75f1d to 56e0b58 Compare January 17, 2025 06:28
@arthur791004 arthur791004 force-pushed the feat/move-external-media-to-package branch from b55d703 to 570c40a Compare January 24, 2025 18:18
@arthur791004
Copy link
Contributor Author

Can you speak more about that? At first, the shared utils package seems like a good location for such a store.

I was moving the external media to the shared utils package. I thought it was wrong at that time, and it works when the external media is moved to the new package. It's moved to shared utils package by bf921ac.

Could we require the Connection package and run Connection_Initial_State::render_script() in the External media package to work around that?

See #41078 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] AI Assistant [Block] AI Chat [Block] Blogroll [Block] Pay With Paypal aka Simple Payments [Block] Send a message [Block] VideoPress Docs [Extension] AI Assistant Plugin [Extension] AI Content Lens [Extension] External Media Extend all block editor media tools to support external providers [Extension] Post Publish QR Post Panel [JS Package] AI Client [JS Package] Components [JS Package] Shared Extension Utils [JS Package] Storybook [Plugin] Automattic For Agencies Client [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Classic Theme Helper Plugin [Plugin] CRM Issues about the Jetpack CRM plugin [Plugin] Inspect [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Plugin] Wpcomsh RNA [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Tests] Includes Tests [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants