Skip to content

Commit

Permalink
Don't allow template part to be created on the Patterns page for non-…
Browse files Browse the repository at this point in the history
…block themes
  • Loading branch information
t-hamano committed Jul 15, 2023
1 parent 33bf984 commit 9b1fc47
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/edit-site/src/components/add-new-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DropdownMenu } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { plus, symbol, symbolFilled } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';
import { privateApis as routerPrivateApis } from '@wordpress/router';

/**
Expand All @@ -14,6 +15,7 @@ import CreatePatternModal from '../create-pattern-modal';
import CreateTemplatePartModal from '../create-template-part-modal';
import SidebarButton from '../sidebar-button';
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';

const { useHistory } = unlock( routerPrivateApis );

Expand All @@ -22,6 +24,10 @@ export default function AddNewPattern() {
const [ showPatternModal, setShowPatternModal ] = useState( false );
const [ showTemplatePartModal, setShowTemplatePartModal ] =
useState( false );
const isTemplatePartsMode = useSelect( ( select ) => {
const settings = select( editSiteStore ).getSettings();
return !! settings.supportsTemplatePartsMode;
}, [] );

function handleCreatePattern( { pattern, categoryId } ) {
setShowPatternModal( false );
Expand Down Expand Up @@ -55,7 +61,7 @@ export default function AddNewPattern() {
<>
<DropdownMenu
controls={ [
{
! isTemplatePartsMode && {
icon: symbolFilled,
onClick: () => setShowTemplatePartModal( true ),
title: __( 'Create template part' ),
Expand All @@ -65,7 +71,7 @@ export default function AddNewPattern() {
onClick: () => setShowPatternModal( true ),
title: __( 'Create pattern' ),
},
] }
].filter( Boolean ) }
toggleProps={ {
as: SidebarButton,
} }
Expand Down
41 changes: 41 additions & 0 deletions test/e2e/specs/site-editor/hybrid-theme.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Hybrid theme', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'gutenberg-test-themes/emptyhybrid' );
} );

test.afterAll( async ( { requestUtils } ) => {
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();
} );
} );

0 comments on commit 9b1fc47

Please sign in to comment.