Skip to content

[CYS] Patterns Migration: Update the registration of patterns within WooCommerce, ensuring they are fetched from the relevant PTK categories#47306

Merged
albarin merged 32 commits intotrunkfrom
add-patterns-from-ptk
May 28, 2024
Merged

[CYS] Patterns Migration: Update the registration of patterns within WooCommerce, ensuring they are fetched from the relevant PTK categories#47306
albarin merged 32 commits intotrunkfrom
add-patterns-from-ptk

Conversation

@albarin
Copy link
Contributor

@albarin albarin commented May 9, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

Closes #47396

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

The main feature this PR adds is making available patterns coming from the PTK API that belong to the following categories: Intro, About, Services, and Testimonials (only if the user allows tracking).
Note: the feature is under the pattern-toolkit-full-composability feature flag.

This PR also includes a refactor of the BlockPatterns class. This is an explanation of the changes and classes created:

  • BlockPatterns: previously, it contained code related to the WC core patterns registration and some actions related to AI patterns. After the refactor, it only has the necessary code to register patterns, both from WC core and from the PTK API (using the new PatternRegistry class).
    Note: GitHub is hiding the diff for this class because it’s big, but please make sure to load it and review it as well.

  • PatternRegistry (new class): handles the registration of patterns. This code was previously on BlockPatterns. It’s essentially the same code but adapted to register also patterns coming from the PTK API (not from files).

  • AIPatterns (new class): handles everything related to the patterns with AI (there’s no new code here, it’s all extracted from BlockPatterns).

  • PTKPatternsStore (new class): it handles fetching PTK patterns and caching them to avoid making lots of requests to the PTK API.

  • PTKClient (new class): handles the requests to the PTK API to fetch patterns.

In case this helps, this is a more visual diagram to understand the structure:
Screenshot 2024-05-15 at 12 17 04

How to test the changes in this Pull Request:

We are going to test with one pattern from each of the PTK categories:

  • Intro: Intro: Left-aligned header and button pattern.
  • About: About: Fullwidth image, content pull right pattern.
  • Services: Services: Three column pricing table pattern.
  • Testimonials: Review: A quote with scattered images pattern.
  1. Go to wp-admin/admin.php?page=wc-settings&tab=advanced&section=woocommerce_com and make sure Allow usage of WooCommerce to be tracked is unchecked.
  2. Create a new page or post and search for and try to insert the mentioned patterns, make sure they are not available.
  3. Go to wp-admin/tools.php?page=woocommerce-admin-test-helper, go to Features, and enable pattern-toolkit-full-composability.
  4. Go to wp-admin/admin.php?page=wc-settings&tab=advanced&section=woocommerce_com and check the Allow usage of WooCommerce to be tracked .
  5. Create a new page or post and insert the mentioned patterns. It should be available this time.
  6. Go to wp-admin/admin.php?page=wc-settings&tab=advanced&section=woocommerce_com and uncheck the Allow usage of WooCommerce to be tracked .
  7. Create a new page or post and search for and try to insert the mentioned patterns, make sure it's not available.

Changelog entry

  • Automatically create a changelog entry from the details below.
Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

[CYS] Refactor the pattern registration and add patterns from the PTK API.

Comment

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label May 9, 2024
@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2024

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@albarin albarin force-pushed the add-patterns-from-ptk branch from 0a60ab9 to bb030a0 Compare May 10, 2024 14:39
@albarin albarin changed the title Add patterns from ptk [CYS] Patterns Migration: Update the registration of patterns within WooCommerce, ensuring they are fetched from the relevant PTK categories May 14, 2024
@albarin albarin marked this pull request as ready for review May 15, 2024 10:45
@woocommercebot woocommercebot requested review from a team and thealexandrelara and removed request for a team May 15, 2024 10:45
@github-actions
Copy link
Contributor

github-actions bot commented May 15, 2024

Hi @gigitux, @nefeline, @thealexandrelara,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@albarin albarin requested review from gigitux and nefeline May 15, 2024 10:45
Copy link
Contributor

@nefeline nefeline left a comment

Choose a reason for hiding this comment

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

Exceptional work, @albarin ! I really appreciate your attention to the details on this implementation. Everything tested perfectly: the addition and removal of the transients for caching the requests are also spot on when it comes to plugin deactivation and updating the option for usage tracking on the database.

The fact that you have worked on adding tests is also fantastic! 👏

Just left a suggestion regarding the significance of this change, apart from that, we are off to a great start :)

quick question (not a blocker): did you test if things are still working as expected with AI with those changes in place? It's not super important in this first moment because these changes are behind the feature flag & we are planning to change the way we inject content in patterns down the line, but asking anyways so we can keep this in mind :)

@albarin
Copy link
Contributor Author

albarin commented May 17, 2024

@nefeline thanks for the review!

quick question (not a blocker): did you test if things are still working as expected with AI with those changes in place? It's not super important in this first moment because these changes are behind the feature flag & we are planning to change the way we inject content in patterns down the line, but asking anyways so we can keep this in min

I just tried and in WooExpress AI still works just fine. However, I noticed an issue with the Product Collection block not being registered. I'll investigate that now.
Screenshot 2024-05-17 at 11 29 56

@albarin
Copy link
Contributor Author

albarin commented May 17, 2024

@nefeline I think the Product Collection was just a glitch from some error building locally and uploading to WooExpress, not it's working fine. Would you mind giving it a try yourself? Just double-check 🙏

@albarin albarin closed this May 17, 2024
@albarin albarin reopened this May 17, 2024
Copy link
Contributor

@gigitux gigitux left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your brilliant work! 🚀

I just left a comment, but just out of curiosity! 🚢

@albarin albarin merged commit 9075bf1 into trunk May 28, 2024
@albarin albarin deleted the add-patterns-from-ptk branch May 28, 2024 12:42
@github-actions github-actions bot added this to the 9.1.0 milestone May 28, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label May 28, 2024
@nefeline
Copy link
Contributor

Would you mind giving it a try yourself? Just double-check 🙏

I just did & confirmed things are working as expected, thanks for checking 🙏

@rodelgc rodelgc added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels May 29, 2024
thealexandrelara pushed a commit that referenced this pull request Jul 18, 2024
…WooCommerce, ensuring they are fetched from the relevant PTK categories (#47306)

* Add PatternsToolkit class to fetch patterns from PTK

* Pass the new PatternsToolkit class to the BlockPatterns constructor

* Extract the pattern registration code to the 'register_block_pattern' function

* Extract the file patterns registration to `register_block_patterns_from_files`

* Registers patterns from ptk

* Add ids of excluded patterns (because they have jetpack deps)

* Add PTK client tests

* Filter out patterns with post_type diff than "wp_block"

* Add missing excluded pattern

* Add error log and improve error messages from the PTK client

* Extract function to register patterns to PatternRegistry class

* Extract function to register patterns from PTK

* Rename PatternsToolkitClient to PTKClient

* Extract AI related code to the AIPatterns class

* Rename test to match class name

* Add missing package dep in BlockPatterns

* Cache and register PTK patterns

* Add feature flag

* Fix linting errors

* Add tests for the PatternRegistry

* Add tests for the PTKPatternsStore

* Add changefile(s) from automation for the following project(s): woocommerce

* Check pattern ID exists to filter

* Check title is set when registering the pattern

* Remove unnecessary code from test

* Add more patterns to the excluded list

* Add actions to reset the patterns transient on plugin deactivation and tracking option updates

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CYS > Patterns Migration: Update the registration of patterns within WooCommerce, ensuring they are fetched from the relevant PTK categories

4 participants

Comments