Make WordPress Core

Opened 21 months ago

Closed 21 months ago

Last modified 21 months ago

#57501 closed enhancement (fixed)

Backport the added query args to Pattern_Directory Controller

Reported by: ntsekouras's profile ntsekouras Owned by: hellofromtonya's profile hellofromTonya
Milestone: 6.2 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch has-unit-tests gutenberg-merge has-testing-info commit
Focuses: Cc:

Description

This ticket tracks the addition of 'per_page', 'page', 'offset', 'order', and 'orderby' args to WP_REST_Pattern_Directory_Controller

It's a backport from the Gutenberg plugin.(https://github.com/WordPress/gutenberg/pull/45293)

Change History (15)

This ticket was mentioned in PR #3861 on WordPress/wordpress-develop by @ntsekouras.


21 months ago
#1

  • Keywords has-patch has-unit-tests added

Trac ticket: https://core.trac.wordpress.org/ticket/57501

Adds the 'per_page', 'page', 'offset', 'order', and 'orderby' args to WP_REST_Pattern_Directory_Controller.

GB PR: https://github.com/WordPress/gutenberg/pull/45293

--cc @hellofromtonya @ryelle

#2 @hellofromTonya
21 months ago

  • Keywords gutenberg-merge added
  • Milestone changed from Awaiting Review to 6.2

@hellofromTonya commented on PR #3861:


21 months ago
#3

Once committed, I can open a PR in Gutenberg to synch the changes from here back to Gutenberg.

#4 @hellofromTonya
21 months ago

  • Keywords has-testing-info needs-testing added

The code in PR 3861 looks good. Updated a few areas for Core parity and a few tweaks for performance.

Next step: Needs a manual test to make sure it works as intended.

Copying testing instructions from the original Gutenberg PR:

## Testing Instructions

1. Ensure the remote patterns are still loading in the editor — the Featured query, the core patterns, and any theme-added patterns.

Test the API endpoint in a REST client.

1. Try pagination, ex: `/wp-json/wp/v2/pattern-directory/patterns/?per_page=6&page=2` — It should show the middle 6 patterns on [wordpress.org/patterns/](https://wordpress.org/patterns/).
2. Try order: `/wp-json/wp/v2/pattern-directory/patterns/?category=37&per_page=3&orderby=date&order=asc` — should show the last 3 items on [wordpress.org/patterns/categories/footer/page/2/](https://wordpress.org/patterns/categories/footer/page/2/)
3. Make sure search still works `/wp-json/wp/v2/pattern-directory/patterns/?search=plants` — should match [wordpress.org/patterns/search/plants/](https://wordpress.org/patterns/search/plants/)
4. Make sure slug still works `/wp-json/wp/v2/pattern-directory/patterns/?slug=centered-text-title-with-two-columns` — should return a single pattern

This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.


21 months ago

#6 @robinwpdeveloper
21 months ago

Using Postman and Application password generated from Dashboard.

  1. /wp-json/wp/v2/pattern-directory/patterns/?per_page=6&page=2 shows items 7-12 from wordpress.org/patterns/
  1. ❌ returns these items: 43551 (Newsletter, Subscribe section design with title, description, background image and subscribe button), 44367 (Contact us/call action section design with gradient background and title, button), 44504 (footer section design with 3 column description, social media, contact and newsletter) Seems API returns last, 3rd last and 4th last item (instead of last 3 items ( = last, 2nd last and 3rd last) ).
  1. ✅ Found fixed. only one item "Natural Hero Section"
  1. ✅ Found single pattern titled "Centered text title with two columns"
Last edited 21 months ago by robinwpdeveloper (previous) (diff)

#7 @arrasel403
21 months ago

I have tested with Postman and Application password from WP Dashboard:

  1. ✅ I use
    /wp-json/wp/v2/pattern-directory/patterns/?per_page=6&page=2
    
    to show 7-12 items from https://wordpress.org/patterns/

Screenshot from ORG: https://prnt.sc/OJk3KNGldJNc
Screenshot from API: https://prnt.sc/xywwMcv9qRcZ

  1. ✅ Get the last three items (but in random order). 43551 (Newsletter, Subscribe section design with title, description, background image and subscribe button), 44504 (footer section design with 3 column description, social media, contact and newsletter), 44715 (Purchase, offerd, discount section with creative design) Screenshot from ORG (last page): https://prnt.sc/AiGT8D7l9rt- Screenshot from ORG (second last page): https://prnt.sc/6n31IWsMOyF-
  1. ✅ Get it fixed. Only one item was found "Natural Hero Section" Screenshot from API: https://prnt.sc/gNGQz-_z1lFV
  1. ✅ Get it fixed. Get only a single pattern title "Centered text title with two columns" Screenshot from API: https://prnt.sc/blB18Aw7U9fD

#8 @robinwpdeveloper
21 months ago

Re trying.

  1. ✅ Found these 3 items:
  • 43551 (Newsletter, Subscribe section design with title, description, background image and subscribe button)
  • 44504 (footer section design with 3 column description, social media, contact and newsletter)
  • 44715 (Purchase, offerd, discount section with creative design)

Last page: https://prnt.sc/HioAL2jn-lNy
2nd last page: https://prnt.sc/zTMFHPfEL6I8

I guess due to cache or something previous report was showing wrong.
Now seems working.

#9 @ironprogrammer
21 months ago

Test Report

Patch tested: https://github.com/WordPress/wordpress-develop/pull/3861

Environment

  • Hardware: MacBook Pro Apple M1 Pro
  • OS: macOS 12.6.2
  • Browser: Safari 16.2
  • Server: nginx/1.23.3
  • PHP: 7.4.33
  • WordPress: 6.2-alpha-54642-src
  • Theme: twentytwentythree v1.0
  • Gutenberg NOT activated

Actual Results

Manual UI Test

Ensure the remote patterns are still loading in the editor — the Featured query, the core patterns, and any theme-added patterns.

  • ❌ While patterns are still loaded, there are both new and missing categories after the patch.
  • ✅ For categories that matched between before/after the patch, the counts were the same.

Editor Patterns explorer counts before patch:

  • Banners: 6
  • Buttons: 3
  • Columns: 5
  • Featured: 16
  • Footers: 9
  • Gallery: 3
  • Headers: 9
  • Posts: 7
  • Text: 9

After patch (🔴=missing, 🟡=new):

  • 🔴 Banners: n/a
  • Buttons: 3
  • Columns: 5
  • Featured: 16
  • Footers: 9
  • Gallery: 3
  • Headers: 9
  • 🔴 Posts: n/a
  • 🟡 Query: 7
  • Text: 9
  • 🟡 Uncategorized: 3

Additional Notes

The user-facing WordPress.org Patterns directory has a different set of category filters from what is in core or in this backport PR. The directory currently includes:

  • Buttons
  • Columns
  • Featured
  • Footers
  • Gallery
  • Headers
  • 🟡 Images
  • Text
  • 🟡 Wireframe

Items with 🟡 are not exposed in core or the PR. Additionally, these categories appear in core before/after the patch, but are not visible on the patterns site: Banners, Posts, Query, Uncategorized.

Supplemental Artifacts

Patterns Explorer Before Patch After Patch
https://cldup.com/4gWF3iqXi0.png https://cldup.com/kpRYVJ9FmV.png
WordPress.org Patterns Directory
https://cldup.com/X3qvMotY84.png

#10 @ironprogrammer
21 months ago

Test Report

This is a follow-up to comment:9 with API test results. tl;dr: Found an issue when modifying search queries.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/3861

Environment

  • Hardware: MacBook Pro Apple M1 Pro
  • OS: macOS 12.6.2
  • Application: Postman 10.8.3
  • Server: nginx/1.23.3
  • PHP: 7.4.33
  • WordPress: 6.2-alpha-54642-src

Actual Results

API Test

Test the API endpoint in a REST client.

  1. ✅ Try pagination (per_page, page, offset):

/wp-json/wp/v2/pattern-directory/patterns/?per_page=6&page=2 Figure 1
/wp-json/wp/v2/pattern-directory/patterns/?per_page=6&page=1&offset=6 Figure 2

  1. ✅ Try order (orderby, order):

/wp-json/wp/v2/pattern-directory/patterns/?category=26&per_page=5&orderby=date&order=asc Figure 3

  1. ❌ Make sure search still works (search):

/wp-json/wp/v2/pattern-directory/patterns/?search=plants Figure 4
🟢 search works alone, and along with the per_page and page parameters.
🔴 search is not affected by the offset, orderby, or order parameters. Figure 5

  1. ✅ Make sure slug still works (slug):

/wp-json/wp/v2/pattern-directory/patterns/?slug=centered-text-title-with-two-columns Figure 6

  1. ✅ When setting parameters with invalid values (e.g. per_page=200 or orderby=foobar), the API responds with appropriate errors.

Additional Information

  • These tests were performed with Postman and a rudimentary visualizer to compare retrieved results with those visible on the WordPress.org Patterns directory. See the image artifacts below for comparisons.
  • Re: Test 2 -- The original test instructions included a sample category query for footers (37), but there appears to be a problem with the data which causes the test to fail. However, tests with other categories work as expected.

Supplemental Artifacts

Click an image to view the large version.

Figure 1 Figure 2
https://cldup.com/mKIbdya9Nu.png https://cldup.com/nL7NeBWgrM.png
Figure 3 Figure 4
https://cldup.com/tllvlr_leO.png https://cldup.com/86cy8yDaNp.png
Figure 5 Figure 6
https://cldup.com/jAjLvNLCOO.png https://cldup.com/huMzOl_Bk4.png

#11 @ironprogrammer
21 months ago

Test Report

This is a follow-up to comment:9 regarding the reported failure during manual UI testing.
tl;dr: After the merge of [55098], this issue is resolved. Refreshing this ticket's PR against trunk would likewise resolve the categories displayed.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/3861, plus PR 3854 which was merged after this ticket was created.

Actual Results

Manual UI Test

Ensure the remote patterns are still loading in the editor — the Featured query, the core patterns, and any theme-added patterns.

✅ Pattern categories displayed match those after applying the patch.

Supplemental Artifacts

Patterns Explorer Before Patch After Patch ✅
https://cldup.com/4gWF3iqXi0.png https://cldup.com/LY0Gz4s8sA.png
Version 0, edited 21 months ago by ironprogrammer (next)

#12 @hellofromTonya
21 months ago

  • Keywords commit added; needs-testing removed
  • Owner changed from ntsekouras to hellofromTonya
  • Status changed from assigned to reviewing

Aha, [55098] was the missing part. Thanks @ironprogrammer @robinwpdeveloper @arrasel403 for the test reports! Well done!

Updating the keywords including marking for commit. Self-assigning for commit.

#13 @hellofromTonya
21 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 55132:

Editor: Adds pagination and ordering support to WP_REST_Pattern_Directory_Controller.

Adds pagination and ordering support to WP_REST_Pattern_Directory_Controller by allow listing 'per_page', 'page', 'offset', 'order', and 'orderby' query parameters. This change enables pagination and ordering features in the pattern directory explorer by using the same sort as wordpress.org/patterns.

Reference:

Follow-up to [55098], [51206], [51021].

Props ntsekouras, ryelle, arrasel403, hellofromTonya, ironprogrammer, mukesh27, robinwpdeveloper.
Fixes #57501.

#15 @hellofromTonya
21 months ago

Follow-up: @ironprogrammer noted a problem with the API's use of `search` in conjunction with `offet`, `orderby`, and `order`.

In talking with @ryelle, the issue is replicated on the Pattern Directory API itself, meaning it's an issue on the API. It'll need to be fixed on wp.org, not within Core or Gutenberg.

Note: See TracTickets for help on using tickets.