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

Patterns: Add missing decoding entities processing in Patterns and Template/Parts pages #52449

Merged
merged 1 commit into from Jul 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,6 +4,7 @@
import { parse } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
Expand Down Expand Up @@ -33,7 +34,7 @@ const templatePartToPattern = ( templatePart ) => ( {
keywords: templatePart.keywords || [],
id: createTemplatePartId( templatePart.theme, templatePart.slug ),
name: createTemplatePartId( templatePart.theme, templatePart.slug ),
title: templatePart.title.rendered,
title: decodeEntities( templatePart.title.rendered ),
Comment on lines -36 to +37
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Decoding here eliminates the need for separate decoding in the lower-layer components. This is consistent with the fact that reusableBlockToPattern in the same file uses title.raw as the value of the title property.

type: templatePart.type,
templatePart,
} );
Expand Down
3 changes: 2 additions & 1 deletion packages/edit-site/src/components/template-actions/index.js
Expand Up @@ -13,6 +13,7 @@ import {
} from '@wordpress/components';
import { moreVertical } from '@wordpress/icons';
import { store as noticesStore } from '@wordpress/notices';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
Expand Down Expand Up @@ -58,7 +59,7 @@ export default function TemplateActions( {
sprintf(
/* translators: The template/part's name. */
__( '"%s" reverted.' ),
template.title.rendered
decodeEntities( template.title.rendered )
),
{
type: 'snackbar',
Expand Down
Expand Up @@ -14,9 +14,13 @@ import {
} from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { store as noticesStore } from '@wordpress/notices';
import { decodeEntities } from '@wordpress/html-entities';

export default function RenameMenuItem( { template, onClose } ) {
const [ title, setTitle ] = useState( () => template.title.rendered );
const [ title, setTitle ] = useState(
decodeEntities( template.title.rendered )
);

const [ isModalOpen, setIsModalOpen ] = useState( false );

const {
Expand Down Expand Up @@ -69,12 +73,7 @@ export default function RenameMenuItem( { template, onClose } ) {

return (
<>
<MenuItem
onClick={ () => {
setIsModalOpen( true );
setTitle( template.title.rendered );
} }
>
<MenuItem onClick={ () => setIsModalOpen( true ) }>
Comment on lines -72 to +76
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there is no need to call setState() again when opening a popover, so I removed it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this was set in #36879 so that unsaved changes wouldn't persist when closing and reopening the modal. It's a bit of an edge case, but if you make changes, click cancel, and then click "rename" again (without closing and reopening the parent menu of the "rename" button), you'll see the unsaved changes have been kept.

{ __( 'Rename' ) }
</MenuItem>
{ isModalOpen && (
Expand Down