-
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
Site Editor: Support starter patterns #60745
Site Editor: Support starter patterns #60745
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
getPatternsByBlockTypes( 'core/post-content' ), | ||
blockPatternsWithPostContentBlockType: getPatternsByBlockTypes( | ||
'core/post-content', | ||
rootClientId |
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.
If we don't pass the right rootClientId, the list of patterns can be empty because we're not allowed to insert patterns top level in "template-locked" mode.
return ( | ||
<BlockPatternsList | ||
blockPatterns={ blockPatterns } | ||
shownPatterns={ shownBlockPatterns } | ||
onClickPattern={ ( _pattern, blocks ) => { | ||
resetEditorBlocks( blocks ); | ||
editEntityRecord( 'postType', postType, postId, { blocks } ); |
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.
This works regardless of the mode, we're actually replacing the patterns of the given post type directly.
Size Change: -41 B (0%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
Flaky tests detected in 5c6baa8. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/8688624054
|
Flow works as intended for me, and matches the admin "add new page" flow. Anything in particular you'd like feedback on? The first time I tried this, there was an odd delay between creating the draft and the modal showing up, but this delay didn't appear the second time so I'm ascribing it to a glitch in the matrix. |
@jasmussen I think the delay is the block patterns being loaded because these load async. The difference between this and trunk is that now we show this flow for any page that is empty (and not just auto-drafts). The reason is that in the site editor there's no "auto-drafts". |
By testing in site editor I think it might make sense to add a snackbar when we add patterns. For me the pattern was inserted but in my viewport it wasn't visible due to the template content, so it might confuse folks. |
|
||
return ( | ||
getRenderingMode() === 'post-only' && | ||
! isFeatureActive( 'welcomeGuide' ) && |
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.
We don't want to preserve the welcome guides check?
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.
It didn't feel that important for me for this PR and it's still and edit-post only preference, so if we want to do that, we'll have to first migrate it in its own PR.
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.
Looks good, thanks!
@youknowriad do you happen to know if this is already noted in a follow up issue, but I just tested this for Gutenberg 18.2 RC1 and it is working fine, but while still in 'draft' it seems the starter pattern modal keeps being triggered when you back out of site editor one step. Please see this video (near the end around 0:24) for visual of odd behavior. It is not entirely a bug, but I feel like it'll drive folks mad to have the starter pattern modal keep triggering in this flow. I'm happy to write up an issue if there is not one. Thanks! site-editor-starter-patterns-odd.mp4 |
@colorful-tones You're right there's indeed an annoying bug here, I'll follow up with a fix. |
Alternative to #55117
Fixes #55108
What?
Adds the 'starter patterns' feature to the site editor for users creating a new page.
Why?
The same feature is available in the post editor when creating a new page, so this provides parity.
How?
It is slightly trickier in the site editor, as the pattern content needs to be inserted into the 'Content' block when in page editing mode. We can't check for an empty title as well because when creating a page in the site editor we fill the title first. So we're checking for "empty content" to show the modal rather than auto-draft status.
Testing Instructions
Test the modal in the post editor too.