Skip to content

Commit

Permalink
Run parse to get the correct attributes and innerBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle committed Sep 1, 2020
1 parent 86cc1e0 commit 2413b8c
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
*/
import { __, sprintf } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { createBlock, getBlockType, parse } from '@wordpress/blocks';
import { useSelect, useDispatch } from '@wordpress/data';
import {
createBlock,
getBlockAttributes,
getBlockType,
} from '@wordpress/blocks';

export default function InstallButton( { attributes, block, clientId } ) {
const isInstallingBlock = useSelect( ( select ) =>
Expand All @@ -23,14 +19,19 @@ export default function InstallButton( { attributes, block, clientId } ) {
installBlockType( block ).then( ( success ) => {
if ( success ) {
const blockType = getBlockType( block.name );
const oldAttributes = getBlockAttributes(
blockType,
attributes.originalUndelimitedContent
);
replaceBlock(
clientId,
createBlock( blockType.name, oldAttributes )
const [ originalBlock ] = parse(
attributes.originalContent
);
if ( originalBlock ) {
replaceBlock(
clientId,
createBlock(
blockType.name,
originalBlock.attributes,
originalBlock.innerBlocks
)
);
}
}
} )
}
Expand Down

0 comments on commit 2413b8c

Please sign in to comment.