Skip to content

Commit

Permalink
Use uniq() to de-duplicate items returned from select() - due to a bu…
Browse files Browse the repository at this point in the history
…g it duplicates {n} results where n is the amount of the deleted items. The underlying state is intact and we should address the root cause in a separate PR.
  • Loading branch information
adamziel committed May 28, 2020
1 parent 28eaf31 commit b6315f4
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { groupBy, sortBy, difference } from 'lodash';
import { groupBy, sortBy, difference, uniq } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -24,11 +24,18 @@ export default function useNavigationBlocks( menuId ) {

// menuItems is an array of menu item objects.
const query = { menus: menuId, per_page: -1 };
// @TODO: uniq() and filter() are here just to work around the bug in select() - let's follow up with a PR
// that addresses the root cause
const menuItems = useSelect(
( select ) =>
select( 'core' )
.getMenuItems( query )
?.filter( ( { id } ) => ! deletedMenuItemsIds.includes( id ) ),
uniq(
select( 'core' )
.getMenuItems( query )
?.filter(
( { id } ) => ! deletedMenuItemsIds.includes( id )
) || [],
( { id } ) => id
),
[ menuId, deletedMenuItemsIds ]
);

Expand Down

0 comments on commit b6315f4

Please sign in to comment.