diff --git a/packages/edit-navigation/src/store/actions.js b/packages/edit-navigation/src/store/actions.js index 8c391f96c1252..e77e82101c462 100644 --- a/packages/edit-navigation/src/store/actions.js +++ b/packages/edit-navigation/src/store/actions.js @@ -192,7 +192,6 @@ const batchInsertPlaceholderMenuItems = ( navigationBlock ) => async ( { */ const batchUpdateMenuItems = ( navigationBlock, menuId ) => async ( { registry, - dispatch, } ) => { const updatedMenuItems = blocksTreeToAnnotatedList( navigationBlock ) // Filter out unsupported blocks @@ -210,9 +209,18 @@ const batchUpdateMenuItems = ( navigationBlock, menuId ) => async ( { ) ) // Filter out menu items without any edits - .filter( ( menuItem ) => - dispatch( applyEdits( menuItem.id, menuItem ) ) - ); + .filter( ( menuItem ) => { + // Update an existing entity record. + registry + .dispatch( coreDataStore ) + .editEntityRecord( 'root', 'menuItem', menuItem.id, menuItem, { + undoIgnore: true, + } ); + + return registry + .select( coreDataStore ) + .hasEditsForEntityRecord( 'root', 'menuItem', menuItem.id ); + } ); // Map the edited menu items to batch tasks const tasks = updatedMenuItems.map( @@ -251,19 +259,6 @@ const batchUpdateMenuItems = ( navigationBlock, menuId ) => async ( { } ); }; -const applyEdits = ( id, edits ) => ( { registry } ) => { - // Update an existing entity record. - registry - .dispatch( coreDataStore ) - .editEntityRecord( 'root', 'menuItem', id, edits, { - undoIgnore: true, - } ); - - return registry - .select( coreDataStore ) - .hasEditsForEntityRecord( 'root', 'menuItem', id ); -}; - /** * Deletes multiple menu items. * Sends a batch request with one DELETE /wp/v2/menu-items for every deleted menu item.