From 306cee8aeb6a408ed3d65da2017a8367f4519bd9 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 26 Oct 2018 13:29:09 -0400 Subject: [PATCH] Editor: Flatten Inserter mapSelectToProps to optimize rendering (#11028) * Editor: Flatten Inserter mapSelectToProps * Inserter: Assign layout, index as undefined rootClientId fallback --- .../editor/src/components/inserter/index.js | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/editor/src/components/inserter/index.js b/packages/editor/src/components/inserter/index.js index 720198626a85c9..92df06eeda445c 100644 --- a/packages/editor/src/components/inserter/index.js +++ b/packages/editor/src/components/inserter/index.js @@ -92,26 +92,30 @@ export default compose( [ getBlockInsertionPoint, getSelectedBlock, getInserterItems, - getBlockOrder, } = select( 'core/editor' ); - const insertionPoint = getBlockInsertionPoint(); - const parentId = rootClientId || insertionPoint.rootClientId; + + let index; + if ( rootClientId === undefined ) { + // Unless explicitly provided, the default insertion point provided + // by the store occurs immediately following the selected block. + // Otherwise, the default behavior for an undefined index is to + // append block to the end of the rootClientId context. + const insertionPoint = getBlockInsertionPoint(); + ( { rootClientId, layout, index } = insertionPoint ); + } + return { title: getEditedPostAttribute( 'title' ), - insertionPoint: { - rootClientId: parentId, - layout: rootClientId ? layout : insertionPoint.layout, - index: rootClientId ? getBlockOrder( rootClientId ).length : insertionPoint.index, - }, selectedBlock: getSelectedBlock(), - items: getInserterItems( parentId ), - rootClientId: parentId, + items: getInserterItems( rootClientId ), + layout, + index, + rootClientId, }; } ), withDispatch( ( dispatch, ownProps ) => ( { onInsertBlock: ( item ) => { - const { selectedBlock, insertionPoint } = ownProps; - const { index, rootClientId, layout } = insertionPoint; + const { selectedBlock, index, rootClientId, layout } = ownProps; const { name, initialAttributes } = item; const insertedBlock = createBlock( name, { ...initialAttributes, layout } ); if ( selectedBlock && isUnmodifiedDefaultBlock( selectedBlock ) ) {