Skip to content

Commit

Permalink
getBlockParentsByBlockName: simplify filtering condition (WordPress#5…
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr authored and sethrubenstein committed Jul 13, 2023
1 parent abec2ba commit 2839af2
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,18 +539,10 @@ export const getBlockParents = createSelector(
export const getBlockParentsByBlockName = createSelector(
( state, clientId, blockName, ascending = false ) => {
const parents = getBlockParents( state, clientId, ascending );
return parents
.map( ( id ) => ( {
id,
name: getBlockName( state, id ),
} ) )
.filter( ( { name } ) => {
if ( Array.isArray( blockName ) ) {
return blockName.includes( name );
}
return name === blockName;
} )
.map( ( { id } ) => id );
const hasName = Array.isArray( blockName )
? ( name ) => blockName.includes( name )
: ( name ) => blockName === name;
return parents.filter( ( id ) => hasName( getBlockName( state, id ) ) );
},
( state ) => [ state.blocks.parents ]
);
Expand Down

0 comments on commit 2839af2

Please sign in to comment.