-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Update Manage Patterns to point to the Site Editor if available #51957
Conversation
Size Change: +152 B (0%) Total Size: 1.42 MB
ℹ️ View Unchanged
|
Flaky tests detected in 39bcf6f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5421056805
|
I like this change, but it only works for block themes.
|
Thanks @carolinan, I wasn't thinking clearly on this one. I'll iterate on it soon. |
href={ addQueryArgs( 'site-editor.php', { | ||
path: '/library', | ||
categoryType: 'pattern', | ||
categoryId: 'my-patterns', |
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.
May need to check how this works for roles that can't access the site editor. Maybe a fallback can be added.
7211b55
to
6824694
Compare
6824694
to
97ffc57
Compare
d5cacfa
to
39bcf6f
Compare
I've updated this PR to link to the site editor only if it is accessible by the current user. If the general approach taken in 1621bc6 is passable, then I can clean up this PR on Monday. |
const [ url, setUrl ] = useState( defaultUrl ); | ||
|
||
useEffect( () => { | ||
window.fetch( patternsUrl ).then( ( response ) => { |
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 is clever but I'm not a fan 😀
The problem is that the result isn't cached so the component will perform an AJAX request every time it mounts. If we use canUser
then it will only perform the OPTIONS
request once.
My preference would be to:
- Return
null
if user can’t access the Manage Patterns screen- Determine this using
canUser( 'read', 'global-styles' )
- Determine this using
- Link to the site editor if
getSettings().__unstableIsBlockBasedTheme
is true
Closing this PR in favour of #52403 which avoids an uncached fetch call to check for user permissions. |
Fixes: #51944
Related:
What?
Updates "Manage Patterns" links to go to the library.
Note: This could be updated to simply direct to the root
/library
path once it defaults to themy-patterns
category and falls back to the header template parts category if there aren't any patternsWhy?
With the new Library, there is a better location to direct users for managing their patterns.
How?
href
attributes for the Manage Patterns linksTesting Instructions