Skip to content

Commit

Permalink
[RNMobile] Handle undefined block case in block actions menu (#30920)
Browse files Browse the repository at this point in the history
* Handle undefined block case in block actions menu

* Change selectedBlock to be an object instead of array
  • Loading branch information
fluiddot authored Apr 19, 2021
1 parent 619b2fe commit fe37913
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ],
Expand Down

0 comments on commit fe37913

Please sign in to comment.