Skip to content

Commit

Permalink
Site Editor: Don't navigate to the patterns in Template Parts mode (#…
Browse files Browse the repository at this point in the history
…52884)

* Site Editor: Don't navigate to the patterns in Template Parts mode

* Remove leftovers

* No need for check in patterns navigation sidebar

* Restore only condition
  • Loading branch information
Mamaduka committed Jul 25, 2023
1 parent 5582673 commit 5a9a8e3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 44 deletions.
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

1 comment on commit 5a9a8e3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 5a9a8e3.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5653093848
📝 Reported issues:

Please sign in to comment.