Skip to content
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: Don't navigate to the patterns in Template Parts mode #52884

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/edit-site/src/components/add-new-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export default function AddNewPattern() {
},
];

// Remove condition when command palette issues are resolved.
// See: https://github.com/WordPress/gutenberg/issues/52154.
if ( ! isTemplatePartsMode ) {
controls.push( {
icon: symbolFilled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
__experimentalHeading as Heading,
} from '@wordpress/components';
import { useViewportMatch } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { getTemplatePartIcon } from '@wordpress/editor';
import { __, sprintf } from '@wordpress/i18n';
import { getQueryArgs } from '@wordpress/url';
Expand All @@ -24,7 +23,6 @@ import SidebarNavigationItem from '../sidebar-navigation-item';
import SidebarNavigationScreen from '../sidebar-navigation-screen';
import CategoryItem from './category-item';
import { DEFAULT_CATEGORY, DEFAULT_TYPE } from '../page-patterns/utils';
import { store as editSiteStore } from '../../store';
import { useLink } from '../routes/link';
import usePatternCategories from './use-pattern-categories';
import useMyPatterns from './use-my-patterns';
Expand Down Expand Up @@ -108,11 +106,6 @@ export default function SidebarNavigationScreenPatterns() {
const { patternCategories, hasPatterns } = usePatternCategories();
const { myPatterns } = useMyPatterns();

const isTemplatePartsMode = useSelect( ( select ) => {
const settings = select( editSiteStore ).getSettings();
return !! settings.supportsTemplatePartsMode;
}, [] );

const templatePartsLink = useLink( { path: '/wp_template_part/all' } );
const footer = ! isMobileViewport ? (
<ItemGroup>
Expand All @@ -131,7 +124,6 @@ export default function SidebarNavigationScreenPatterns() {

return (
<SidebarNavigationScreen
isRoot={ isTemplatePartsMode }
title={ __( 'Patterns' ) }
description={ __(
'Manage what patterns are available when editing the site.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { __experimentalUseNavigator as useNavigator } from '@wordpress/components';

/**
* Internal dependencies
*/
import SidebarNavigationScreen from '../sidebar-navigation-screen';
import { store as editSiteStore } from '../../store';

const config = {
wp_template: {
Expand All @@ -29,8 +31,16 @@ export default function SidebarNavigationScreenTemplatesBrowse() {
const {
params: { postType },
} = useNavigator();

const isTemplatePartsMode = useSelect( ( select ) => {
const settings = select( editSiteStore ).getSettings();

return !! settings.supportsTemplatePartsMode;
}, [] );

return (
<SidebarNavigationScreen
isRoot={ isTemplatePartsMode }
title={ config[ postType ].title }
description={ config[ postType ].description }
backPath={ config[ postType ].backPath }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useEntityRecords } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';
import { useViewportMatch } from '@wordpress/compose';

Expand All @@ -18,7 +17,6 @@ import SidebarNavigationScreen from '../sidebar-navigation-screen';
import { useLink } from '../routes/link';
import SidebarNavigationItem from '../sidebar-navigation-item';
import AddNewTemplate from '../add-new-template';
import { store as editSiteStore } from '../../store';
import SidebarButton from '../sidebar-button';

const TemplateItem = ( { postType, postId, ...props } ) => {
Expand All @@ -31,11 +29,6 @@ const TemplateItem = ( { postType, postId, ...props } ) => {

export default function SidebarNavigationScreenTemplates() {
const isMobileViewport = useViewportMatch( 'medium', '<' );
const isTemplatePartsMode = useSelect( ( select ) => {
const settings = select( editSiteStore ).getSettings();

return !! settings.supportsTemplatePartsMode;
}, [] );

const { records: templates, isResolving: isLoading } = useEntityRecords(
'postType',
Expand All @@ -51,10 +44,9 @@ export default function SidebarNavigationScreenTemplates() {
);

const browseAllLink = useLink( { path: '/wp_template/all' } );
const canCreate = ! isMobileViewport && ! isTemplatePartsMode;
const canCreate = ! isMobileViewport;
return (
<SidebarNavigationScreen
isRoot={ isTemplatePartsMode }
title={ __( 'Templates' ) }
description={ __(
'Express the layout of your site with templates'
Expand Down
27 changes: 0 additions & 27 deletions test/e2e/specs/site-editor/hybrid-theme.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,6 @@ test.describe( 'Hybrid theme', () => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

test( 'should not show the Add Template Part button', async ( {
admin,
page,
} ) => {
await admin.visitAdminPage(
'/site-editor.php',
'postType=wp_template_part&path=/wp_template_part/all'
);

await expect(
page.locator( 'role=button[name="Add New Template Part"i]' )
).toBeHidden();

// Back to Patterns page.
await page.click(
'role=region[name="Navigation"i] >> role=button[name="Back"i]'
);

await page.click(
'role=region[name="Navigation"i] >> role=button[name="Create pattern"i]'
);

await expect(
page.locator( 'role=menuitem[name="Create template part"i]' )
).toBeHidden();
} );

test( 'can access template parts list page', async ( { admin, page } ) => {
await admin.visitAdminPage(
'site-editor.php',
Expand Down
Loading