Skip to content

Commit

Permalink
Editor: offer the option to convert to HTML on invalid blockss
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Sep 28, 2017
1 parent 5a949b7 commit eb5f014
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
35 changes: 24 additions & 11 deletions editor/modes/visual-editor/invalid-block-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ import {
*/
import { replaceBlock } from '../../actions';

function InvalidBlockWarning( { ignoreInvalid, switchToDefaultType } ) {
function InvalidBlockWarning( { ignoreInvalid, switchToBlockType } ) {
const htmlBlockName = 'core/html';
const defaultBlockType = getBlockType( getUnknownTypeHandlerName() );
const htmlBlockType = getBlockType( htmlBlockName );
const switchTo = ( blockType ) => () => switchToBlockType( blockType );

return (
<BlockWarning>
<p>{ sprintf( __(
<p>{ defaultBlockType && htmlBlockType && sprintf( __(
'This block appears to have been modified externally. ' +
'Overwrite the external changes or Convert to %s to keep ' +
'Overwrite the external changes or Convert to %s or %s to keep ' +
'your changes.'
), defaultBlockType.title ) }</p>
<p>
), defaultBlockType.title, htmlBlockType.title ) }</p>
<p className="visual-editor__invalid-block-warning-buttons">
<Button
onClick={ ignoreInvalid }
isLarge
Expand All @@ -43,15 +46,26 @@ function InvalidBlockWarning( { ignoreInvalid, switchToDefaultType } ) {
</Button>
{ defaultBlockType && (
<Button
onClick={ switchToDefaultType }
onClick={ switchTo( defaultBlockType ) }
isLarge
>
{
/* translators: Revert invalid block to default */
/* translators: Revert invalid block to another block type */
sprintf( __( 'Convert to %s' ), defaultBlockType.title )
}
</Button>
) }

{ htmlBlockType && (
<Button
onClick={ switchTo( htmlBlockType ) }
isLarge
>
{
sprintf( __( 'Edit as HTML block' ) )
}
</Button>
) }
</p>
</BlockWarning>
);
Expand All @@ -67,11 +81,10 @@ export default connect(
const nextBlock = createBlock( name, attributes );
dispatch( replaceBlock( block.uid, nextBlock ) );
},
switchToDefaultType() {
const defaultBlockName = getUnknownTypeHandlerName();
switchToBlockType( blockType ) {
const { block } = ownProps;
if ( defaultBlockName && block ) {
const nextBlock = createBlock( defaultBlockName, {
if ( blockType && block ) {
const nextBlock = createBlock( blockType.name, {
content: block.originalContent,
} );

Expand Down
4 changes: 4 additions & 0 deletions editor/modes/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,7 @@ $sticky-bottom-offset: 20px;
margin-left: $item-spacing;
}
}

.visual-editor__invalid-block-warning-buttons .components-button {
margin-bottom: 5px;
}

0 comments on commit eb5f014

Please sign in to comment.