From 2839af20a01a52904bece680c6b1422703a3d818 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Wed, 14 Jun 2023 10:14:41 +0200 Subject: [PATCH] getBlockParentsByBlockName: simplify filtering condition (#51439) --- packages/block-editor/src/store/selectors.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 10bf42ec23094..a3de21f5c01b6 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -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 ] );