Skip to content

Commit

Permalink
Inline applyEdits
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Sep 21, 2021
1 parent 005fbfd commit 4ff8b16
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions packages/edit-navigation/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ const batchInsertPlaceholderMenuItems = ( navigationBlock ) => async ( {
*/
const batchUpdateMenuItems = ( navigationBlock, menuId ) => async ( {
registry,
dispatch,
} ) => {
const updatedMenuItems = blocksTreeToAnnotatedList( navigationBlock )
// Filter out unsupported blocks
Expand All @@ -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(
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4ff8b16

Please sign in to comment.