From fe379134644e6a8b43a220d1d6e956def9b5295e Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Mon, 19 Apr 2021 16:18:00 +0200 Subject: [PATCH] [RNMobile] Handle undefined block case in block actions menu (#30920) * Handle undefined block case in block actions menu * Change selectedBlock to be an object instead of array --- .../block-actions-menu.native.js | 17 +++++++++-------- .../block-transformations-menu.native.js | 3 +-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js b/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js index a5cc68adaf85e3..0c2e3bfc821339 100644 --- a/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js +++ b/packages/block-editor/src/components/block-mobile-toolbar/block-actions-menu.native.js @@ -272,7 +272,7 @@ export default compose( const block = getBlock( normalizedClientIds ); const blockName = getBlockName( normalizedClientIds ); const blockType = getBlockType( blockName ); - const blockTitle = blockType.title; + const blockTitle = blockType?.title; const firstClientId = first( normalizedClientIds ); const rootClientId = getBlockRootClientId( firstClientId ); const blockOrder = getBlockOrder( rootClientId ); @@ -284,17 +284,18 @@ export default compose( ); const isDefaultBlock = blockName === getDefaultBlockName(); - const isEmptyContent = block.attributes.content === ''; + const isEmptyContent = block?.attributes.content === ''; const isExactlyOneBlock = blockOrder.length === 1; const isEmptyDefaultBlock = isExactlyOneBlock && isDefaultBlock && isEmptyContent; - const selectedBlockClientId = getSelectedBlockClientIds(); - const selectedBlock = getBlocksByClientId( selectedBlockClientId ); - const selectedBlockPossibleTransformations = getBlockTransformItems( - selectedBlock, - rootClientId - ); + const selectedBlockClientId = first( getSelectedBlockClientIds() ); + const selectedBlock = selectedBlockClientId + ? first( getBlocksByClientId( selectedBlockClientId ) ) + : undefined; + const selectedBlockPossibleTransformations = selectedBlock + ? getBlockTransformItems( [ selectedBlock ], rootClientId ) + : []; return { blockTitle, diff --git a/packages/block-editor/src/components/block-switcher/block-transformations-menu.native.js b/packages/block-editor/src/components/block-switcher/block-transformations-menu.native.js index ce2822d0c6dbc9..fc91bdd6d37dc1 100644 --- a/packages/block-editor/src/components/block-switcher/block-transformations-menu.native.js +++ b/packages/block-editor/src/components/block-switcher/block-transformations-menu.native.js @@ -29,8 +29,7 @@ const BlockTransformationsMenu = ( { const { createSuccessNotice } = useDispatch( noticesStore ); const pickerOptions = () => { - const selectedBlockName = - ( selectedBlock.length && selectedBlock[ 0 ].name ) || ''; + const selectedBlockName = selectedBlock?.name ?? ''; const blocksThatSplitWhenTransformed = { 'core/list': [ 'core/paragraph', 'core/heading' ], 'core/quote': [ 'core/paragraph' ],