From fdd815c03040c39bcfb5c59b01d6394942a6182f Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 22 Jun 2023 12:18:29 +0100 Subject: [PATCH 1/3] Ensure edits are passed to save --- .../sidebar-navigation-screen-navigation-menu/index.js | 2 +- .../use-navigation-menu-handlers.js | 6 +++++- .../sidebar-navigation-screen-navigation-menus/index.js | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js index 6fae7b09261981..6bce0f356f7400 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/index.js @@ -60,7 +60,7 @@ export default function SidebarNavigationScreenNavigationMenu() { useNavigationMenuHandlers(); const _handleDelete = () => handleDelete( navigationMenu ); - const _handleSave = () => handleSave( navigationMenu ); + const _handleSave = ( edits ) => handleSave( navigationMenu, edits ); const _handleDuplicate = () => handleDuplicate( navigationMenu ); if ( isLoading ) { diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js index 1ddf1c8d86c6ec..81d4cad95e309f 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/use-navigation-menu-handlers.js @@ -71,7 +71,11 @@ function useSaveNavigationMenu() { const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore ); - const handleSave = async ( navigationMenu, edits = {} ) => { + const handleSave = async ( navigationMenu, edits ) => { + if ( ! edits ) { + return; + } + const postId = navigationMenu?.id; // Prepare for revert in case of error. const originalRecord = getEditedEntityRecord( diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js index 2234f1e1bbdeea..030bb63b6cbfec 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js @@ -78,7 +78,9 @@ export default function SidebarNavigationScreenNavigationMenus() { navigationMenu={ firstNavigationMenu } handleDelete={ () => handleDelete( firstNavigationMenu ) } handleDuplicate={ () => handleDuplicate( firstNavigationMenu ) } - handleSave={ () => handleSave( firstNavigationMenu ) } + handleSave={ ( edits ) => + handleSave( firstNavigationMenu, edits ) + } /> ); } From f69c39fa9b6616a8d52ff71b05f8d32437d7772b Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 23 Jun 2023 10:15:00 +0100 Subject: [PATCH 2/3] Ensure empty strings are invalid --- .../rename-modal.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/rename-modal.js b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/rename-modal.js index 99f674ba8bee3a..668179755ec35a 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/rename-modal.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-navigation-menu/rename-modal.js @@ -11,9 +11,16 @@ import { import { __ } from '@wordpress/i18n'; import { useState } from '@wordpress/element'; +const notEmptyString = ( testString ) => testString?.trim()?.length > 0; + export default function RenameModal( { menuTitle, onClose, onSave } ) { const [ editedMenuTitle, setEditedMenuTitle ] = useState( menuTitle ); + const titleHasChanged = editedMenuTitle !== menuTitle; + + const isEditedMenuTitleValid = + titleHasChanged && notEmptyString( editedMenuTitle ); + return (
@@ -30,11 +37,15 @@ export default function RenameModal( { menuTitle, onClose, onSave } ) {