-
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
Site Editor: Prevent unintended actions on the classic theme #54422
Changes from 4 commits
8a78ac2
4a264b3
a1a100a
33b08a5
ad869b5
fa499af
b3963ef
58f0d0a
d10682b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ import { useViewportMatch } from '@wordpress/compose'; | |
import { getTemplatePartIcon } from '@wordpress/editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { getQueryArgs } from '@wordpress/url'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { file } from '@wordpress/icons'; | ||
|
||
/** | ||
|
@@ -27,6 +29,7 @@ import { | |
import { useLink } from '../routes/link'; | ||
import usePatternCategories from './use-pattern-categories'; | ||
import useTemplatePartAreas from './use-template-part-areas'; | ||
import { store as editSiteStore } from '../../store'; | ||
|
||
function TemplatePartGroup( { areas, currentArea, currentType } ) { | ||
return ( | ||
|
@@ -93,8 +96,21 @@ export default function SidebarNavigationScreenPatterns() { | |
const { templatePartAreas, hasTemplateParts, isLoading } = | ||
useTemplatePartAreas(); | ||
const { patternCategories, hasPatterns } = usePatternCategories(); | ||
const isBlockBasedTheme = useSelect( | ||
( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme, | ||
[] | ||
); | ||
const isTemplatePartsMode = useSelect( ( select ) => { | ||
const settings = select( editSiteStore ).getSettings(); | ||
return !! settings.supportsTemplatePartsMode; | ||
}, [] ); | ||
const templatePartsLink = useLink( { | ||
path: '/wp_template_part/all', | ||
// If a classic theme that supports template parts accessed | ||
// the Patterns page directly, preserve that state in the URL. | ||
didAccessPatternsPage: isTemplatePartsMode ? 1 : undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I know There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When someone comes to this fresh without much context, I think it could really help to be explicit here and probably doesn't hurt much to make this tweak. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, added by b3963ef 👍 |
||
} ); | ||
|
||
const templatePartsLink = useLink( { path: '/wp_template_part/all' } ); | ||
const footer = ! isMobileViewport ? ( | ||
<ItemGroup> | ||
<SidebarNavigationItem | ||
|
@@ -104,14 +120,17 @@ export default function SidebarNavigationScreenPatterns() { | |
> | ||
{ __( 'Manage all of my patterns' ) } | ||
</SidebarNavigationItem> | ||
<SidebarNavigationItem withChevron { ...templatePartsLink }> | ||
{ __( 'Manage all template parts' ) } | ||
</SidebarNavigationItem> | ||
{ ( isBlockBasedTheme || isTemplatePartsMode ) && ( | ||
<SidebarNavigationItem withChevron { ...templatePartsLink }> | ||
{ __( 'Manage all template parts' ) } | ||
</SidebarNavigationItem> | ||
) } | ||
</ItemGroup> | ||
) : undefined; | ||
|
||
return ( | ||
<SidebarNavigationScreen | ||
isRoot={ ! isBlockBasedTheme } | ||
title={ __( 'Patterns' ) } | ||
description={ __( | ||
'Manage what patterns are available when editing the site.' | ||
|
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 appears to throw an error when using the command palette anywhere except the site editor e.g. post editor, editing custom post type such as the wp_block patterns 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.
We only need to check for these params while in the site editor, so a simple guard against the undefined location might suffice. What do you think?
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 spot! Guarding against
undefined
seems logical to me 👍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.
Thank you for finding it! I fixed it with fa499af.Fixed with fa499af and 58f0d0a.