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

Template part placeholders - use label and icon per variation. #31721

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,13 +1,18 @@
/**
* External dependencies
*/
import { find } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { useCallback, useState } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { Placeholder, Dropdown, Button } from '@wordpress/components';
import { blockDefault } from '@wordpress/icons';
import { serialize } from '@wordpress/blocks';
import { store as coreStore } from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';

/**
* Internal dependencies
Expand All @@ -28,6 +33,23 @@ export default function TemplatePartPlaceholder( {
const { saveEntityRecord } = useDispatch( coreStore );
const [ step, setStep ] = useState( PLACEHOLDER_STEPS.initial );

const { areaIcon, areaLabel } = useSelect(
( select ) => {
const definedAreas = select(
editorStore
).__experimentalGetDefaultTemplatePartAreas();

const selectedArea = find( definedAreas, { area } );
const defaultArea = find( definedAreas, { area: 'uncategorized' } );

return {
areaIcon: selectedArea?.icon || defaultArea?.icon,
areaLabel: selectedArea?.label || __( 'Template Part' ),
};
},
[ area ]
);

const onCreate = useCallback(
async ( startingBlocks = [] ) => {
const title = __( 'Untitled Template Part' );
Expand Down Expand Up @@ -61,10 +83,12 @@ export default function TemplatePartPlaceholder( {
<>
{ step === PLACEHOLDER_STEPS.initial && (
<Placeholder
icon={ blockDefault }
label={ __( 'Template Part' ) }
instructions={ __(
'Create a new template part or pick an existing one from the list.'
icon={ areaIcon }
label={ areaLabel }
instructions={ sprintf(
// Translators: %s as template part area title ("Header", "Footer", etc.).
'Choose an existing %s or create a new one.',
areaLabel
) }
>
<Dropdown
Expand All @@ -85,7 +109,11 @@ export default function TemplatePartPlaceholder( {
setStep( PLACEHOLDER_STEPS.patterns )
}
>
{ __( 'New template part' ) }
{ sprintf(
// Translators: %s as template part area title ("Header", "Footer", etc.).
'New %s',
areaLabel
) }
</Button>
</>
) }
Expand Down
Expand Up @@ -31,7 +31,7 @@ const createTemplatePart = async (
// Create new template part.
await insertBlock( 'Template Part' );
const [ createNewButton ] = await page.$x(
'//button[contains(text(), "New template part")]'
'//button[contains(text(), "New Template Part")]'
);
await createNewButton.click();
await page.waitForSelector(
Expand Down
Expand Up @@ -27,7 +27,7 @@ describe( 'Multi-entity save flow', () => {
const closePanelButtonSelector =
'.editor-post-publish-panel__header-cancel-button button';
const createNewButtonSelector =
'//button[contains(text(), "New template part")]';
'//button[contains(text(), "New Template Part")]';

// Reusable assertions across Post/Site editors.
const assertAllBoxesChecked = async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/specs/experiments/template-part.test.js
Expand Up @@ -268,7 +268,7 @@ describe( 'Template Part', () => {
const activatedTemplatePartSelector = `${ templatePartSelector }.block-editor-block-list__layout`;
const testContentSelector = `//p[contains(., "${ testContent }")]`;
const createNewButtonSelector =
'//button[contains(text(), "New template part")]';
'//button[contains(text(), "New Template Part")]';
const chooseExistingButtonSelector =
'//button[contains(text(), "Choose existing")]';

Expand Down