From f448947625ada1c2360fa8ae9d03d1c3df8b7584 Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Tue, 11 Jul 2023 08:56:13 +0900 Subject: [PATCH] Ensure that the unsaved title is not persisted when reopening the modal (#52473) --- .../template-actions/rename-menu-item.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/edit-site/src/components/template-actions/rename-menu-item.js b/packages/edit-site/src/components/template-actions/rename-menu-item.js index 9c6368ced17bf..9f897fcd2e943 100644 --- a/packages/edit-site/src/components/template-actions/rename-menu-item.js +++ b/packages/edit-site/src/components/template-actions/rename-menu-item.js @@ -17,10 +17,8 @@ import { store as noticesStore } from '@wordpress/notices'; import { decodeEntities } from '@wordpress/html-entities'; export default function RenameMenuItem( { template, onClose } ) { - const [ title, setTitle ] = useState( - decodeEntities( template.title.rendered ) - ); - + const title = decodeEntities( template.title.rendered ); + const [ editedTitle, setEditedTitle ] = useState( title ); const [ isModalOpen, setIsModalOpen ] = useState( false ); const { @@ -39,11 +37,11 @@ export default function RenameMenuItem( { template, onClose } ) { try { await editEntityRecord( 'postType', template.type, template.id, { - title, + title: editedTitle, } ); // Update state before saving rerenders the list. - setTitle( '' ); + setEditedTitle( '' ); setIsModalOpen( false ); onClose(); @@ -73,7 +71,12 @@ export default function RenameMenuItem( { template, onClose } ) { return ( <> - setIsModalOpen( true ) }> + { + setIsModalOpen( true ); + setEditedTitle( title ); + } } + > { __( 'Rename' ) } { isModalOpen && ( @@ -89,8 +92,8 @@ export default function RenameMenuItem( { template, onClose } ) {