-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[Patterns]: Featured patterns from pattern directory #35115
[Patterns]: Featured patterns from pattern directory #35115
Conversation
Size Change: +856 B (0%) Total Size: 1.07 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this, @ntsekouras.
The feature works as expected, including the missing image 😄
I would defer on the final decision to the folks who are more familiar with the patterns directory.
P.S. I found an unrelated issue while testing this. If you resize the browser window so that bottom is near the last pattern, it starts "glitching."
CleanShot.2021-09-24.at.18.17.44.mp4
Very cool! This seems to work well in my testing. @shaunandrews was there any talk about a "Featured" category in the patterns directory? @melchoyce, @beafialho and I can help curate a short list of patterns to start featuring here, but I wonder if it makes sense to have this list featured in the actual pattern directory or not at this point? |
lib/block-patterns.php
Outdated
// TODO: check to update the controller here: https://github.com/WordPress/gutenberg/blob/trunk/lib/class-wp-rest-pattern-directory-controller.php#L321 | ||
// because it unsets the `per_page` param. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, pagination is disabled because there is no way to paginate in the UI, so we want to return every pattern from the API for local filtering. Is there a reason to request just 2 patterns here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to change from unsetting entirely, to support the params and set defaults or make the other request to pass -1
to fetch all. The API needs to support other use cases as well besides the pattern directory UI.
Is there a reason to request just 2 patterns here?
2
was just for demo and I guess we will show a bit more - maybe 10 or something? I believe we have to have a limit though because of performance and the current UI for selecting patterns, which is not super friendly for previewing a large number of patterns. We can revisit of course later..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out I was misremembering slightly - the wp.org API does not support pagination, it always requests 100 patterns. If/when we revamp the pattern inserter, we can update the API to support pagination, and then we can reenable these params here. For now, the featured category is manually curated, so you can be sure it's a smaller list.
Yeah, we decided not to launch with it because the technical details were unclear. If it's just another pattern category, we can create that any time.
Can you identify which pattern this is? I'm not seeing a missing image. |
You can see the error in developer tools when you open the |
Ok cool. I think for now, it would make sense to just curate a short list of 10 or so patterns. We can get started on that later this week/early next. |
The new category, Featured, has been created - you can query it with |
1bb837b
to
0abfd1f
Compare
Over in WordPress/pattern-directory#365, @beafialho, @melchoyce and I pulled together a collection of 12 initial patterns to feature. That should be a decent starting point for now. 👍 |
Awesome! So I guess this just needs a code review now 😄 |
lib/block-patterns.php
Outdated
$pattern_name = sanitize_title( $pattern['title'] ); | ||
if ( ! WP_Block_Patterns_Registry::get_instance()->is_registered( $pattern_name ) ) { | ||
register_block_pattern( $pattern_name, (array) $pattern ); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these same patterns are already being registered with the prefix core/
and there's no prefix here, so I'm seeing a few duplicates in the featured tab: core/heading
and heading
, core/large-header-with-left-aligned-text
and large-header-with-left-aligned-text
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... I updated with a check if a pattern is registered with the core
prefix. This made me wonder why we need the core
prefix in the first place.. Should we also incorporate the id
that exists in pattern directory in is_registered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR itself looks spotless, but I left a note about how we're using the pattern directory.
lib/block-patterns.php
Outdated
if ( ! WP_Block_Patterns_Registry::get_instance()->is_registered( $pattern_name ) ) { | ||
register_block_pattern( $pattern_name, (array) $pattern ); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm noticing some things that are slightly tangent to this PR, but I'll still mention them:
- As in the previous function, the pattern's title is sanitised but the rest of the payload isn't, neither here nor in the patterns registry class. Seems like a code smell to me — either we are oversanitising or undersanitising.
- Though it's not the only case in WP, I've always found it very odd that the backend should make a HTTP request to itself. :) I don't know what arguments support this against just querying directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good questions Miguel. @ryelle does the sanitisation has to do with the current way the patterns are included in the directory? The inclusion happens manually for now so it's sanitised
by 'us'?
I agree that such questions/changes can happen in a separate PR.
Great to see this! |
This PR is just a quick POC for fetching and showing
featured
patterns from patterns directory.Resolves: #33046
Testing instructions
patterns
tabs and check the first shown category (featured
) with patterns from the directory.Notes