Skip to content

Commit

Permalink
Site Editor: Don't allow creating template part on the Patterns page …
Browse files Browse the repository at this point in the history
…for non-block themes (#52656)

* Don't allow template part to be created on the Patterns page for non-block themes

* Remove unnecessary theme directory name in E2E test
  • Loading branch information
t-hamano authored Jul 17, 2023
1 parent d4f5869 commit 5fadae5
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( '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();
} );
} );

1 comment on commit 5fadae5

@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 5fadae5.
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/5576153331
📝 Reported issues:

Please sign in to comment.