Patterns: Update Manage Patterns to point to the Site Editor if available#51957
Patterns: Update Manage Patterns to point to the Site Editor if available#51957aaronrobertshaw wants to merge 2 commits intotrunkfrom
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. |
There was a problem hiding this comment.
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.
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
nullif 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().__unstableIsBlockBasedThemeis 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
/librarypath once it defaults to themy-patternscategory 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?
hrefattributes for the Manage Patterns linksTesting Instructions