Skip to content

Commit

Permalink
Blocks: invalid block overwrite
Browse files Browse the repository at this point in the history
Add the option to overwrite an invalid block by saving the block and dropping anything invalid
  • Loading branch information
johngodley committed Jul 29, 2018
1 parent a25b8e6 commit c5389dc
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
getBlockType,
createBlock,
rawHandler,
getBlockAttributes,
getSaveContent,
} from '@wordpress/blocks';
import { withSelect, withDispatch } from '@wordpress/data';

Expand Down Expand Up @@ -35,12 +37,13 @@ export class BlockInvalidWarning extends Component {
}

render() {
const { convertToHTML, convertToBlocks, convertToClassic, block } = this.props;
const { convertToHTML, convertToBlocks, convertToClassic, convertOverwrite, block } = this.props;
const hasHTMLBlock = !! getBlockType( 'core/html' );
const { compare } = this.state;
const hiddenActions = [
{ title: __( 'Convert to Blocks' ), onClick: convertToBlocks },
{ title: __( 'Convert to Classic Block' ), onClick: convertToClassic },
{ title: __( 'Overwrite' ), onClick: convertOverwrite },
{ title: __( 'Compare conversion' ), onClick: this.onCompare },
];

Expand Down Expand Up @@ -94,6 +97,9 @@ const blockToBlocks = ( block ) => rawHandler( {
HTML: block.originalContent,
mode: 'BLOCKS',
} );
const blockSave = ( block ) => createBlock( block.name,
getBlockAttributes( getBlockType( block.name ), getSaveContent( getBlockType( block.name ), block.attributes ) )
);

export default compose(
withSelect( () => ( {} ) ),
Expand All @@ -109,6 +115,9 @@ export default compose(
convertToBlocks() {
replaceBlock( block.uid, blockToBlocks( block ) );
},
convertOverwrite() {
replaceBlock( block.uid, blockSave( block ) );
},
};
} ),
)( BlockInvalidWarning );

0 comments on commit c5389dc

Please sign in to comment.