Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more information to unsupported blocks on native #14577

Merged
merged 8 commits into from
Apr 3, 2019
Prev Previous commit
Next Next commit
Remove UnsupportedBlock in favor of core/missing
  • Loading branch information
koke committed Mar 22, 2019
commit 9bf5acf9111009bcfef4ecc477670e6fbd56dfac
6 changes: 3 additions & 3 deletions packages/block-library/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
registerBlockType,
setDefaultBlockName,
setUnregisteredTypeHandlerName,
} from '@wordpress/blocks';

/**
Expand Down Expand Up @@ -49,9 +50,6 @@ import * as verse from './verse';
import * as video from './video';
import * as tagCloud from './tag-cloud';

import * as UnsupportedBlock from './mobile/unsupported-block';
export { UnsupportedBlock };

export const coreBlocks = [
// Common blocks are grouped at the top to prioritize their display
// in various contexts — like the inserter and auto-complete components.
Expand Down Expand Up @@ -108,6 +106,7 @@ export const registerCoreBlocks = () => {
paragraph,
heading,
code,
missing,
more,
image,
nextpage,
Expand All @@ -117,3 +116,4 @@ export const registerCoreBlocks = () => {
};

setDefaultBlockName( paragraph.name );
setUnregisteredTypeHandlerName( missing.name );
54 changes: 54 additions & 0 deletions packages/block-library/src/missing/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { RawHTML, Fragment } from '@wordpress/element';
import { Button } from '@wordpress/components';
import { getBlockType, createBlock } from '@wordpress/blocks';
import { withDispatch } from '@wordpress/data';
import { Warning } from '@wordpress/block-editor';

function MissingBlockWarning( { attributes, convertToHTML } ) {
const { originalName, originalUndelimitedContent } = attributes;
const hasContent = !! originalUndelimitedContent;
const hasHTMLBlock = getBlockType( 'core/html' );

const actions = [];
let messageHTML;
if ( hasContent && hasHTMLBlock ) {
messageHTML = sprintf(
__( 'Your site doesn’t include support for the "%s" block. You can leave this block intact, convert its content to a Custom HTML block, or remove it entirely.' ),
originalName
);
actions.push(
<Button key="convert" onClick={ convertToHTML } isLarge isPrimary>
{ __( 'Keep as HTML' ) }
</Button>
);
} else {
messageHTML = sprintf(
__( 'Your site doesn’t include support for the "%s" block. You can leave this block intact or remove it entirely.' ),
originalName
);
}

return (
<Fragment>
<Warning actions={ actions }>
{ messageHTML }
</Warning>
<RawHTML>{ originalUndelimitedContent }</RawHTML>
</Fragment>
);
}

export default withDispatch( ( dispatch, { clientId, attributes } ) => {
const { replaceBlock } = dispatch( 'core/block-editor' );
return {
convertToHTML() {
replaceBlock( clientId, createBlock( 'core/html', {
content: attributes.originalUndelimitedContent,
} ) );
},
};
} )( MissingBlockWarning );
56 changes: 6 additions & 50 deletions packages/block-library/src/missing/index.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,13 @@
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { RawHTML, Fragment } from '@wordpress/element';
import { Button } from '@wordpress/components';
import { getBlockType, createBlock } from '@wordpress/blocks';
import { withDispatch } from '@wordpress/data';
import { Warning } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { RawHTML } from '@wordpress/element';

function MissingBlockWarning( { attributes, convertToHTML } ) {
const { originalName, originalUndelimitedContent } = attributes;
const hasContent = !! originalUndelimitedContent;
const hasHTMLBlock = getBlockType( 'core/html' );

const actions = [];
let messageHTML;
if ( hasContent && hasHTMLBlock ) {
messageHTML = sprintf(
__( 'Your site doesn’t include support for the "%s" block. You can leave this block intact, convert its content to a Custom HTML block, or remove it entirely.' ),
originalName
);
actions.push(
<Button key="convert" onClick={ convertToHTML } isLarge isPrimary>
{ __( 'Keep as HTML' ) }
</Button>
);
} else {
messageHTML = sprintf(
__( 'Your site doesn’t include support for the "%s" block. You can leave this block intact or remove it entirely.' ),
originalName
);
}

return (
<Fragment>
<Warning actions={ actions }>
{ messageHTML }
</Warning>
<RawHTML>{ originalUndelimitedContent }</RawHTML>
</Fragment>
);
}

const edit = withDispatch( ( dispatch, { clientId, attributes } ) => {
const { replaceBlock } = dispatch( 'core/block-editor' );
return {
convertToHTML() {
replaceBlock( clientId, createBlock( 'core/html', {
content: attributes.originalUndelimitedContent,
} ) );
},
};
} )( MissingBlockWarning );
/**
* Internal dependencies
*/
import edit from './edit';

export const name = 'core/missing';

Expand Down
46 changes: 0 additions & 46 deletions packages/block-library/src/mobile/unsupported-block/index.js

This file was deleted.

6 changes: 2 additions & 4 deletions packages/edit-post/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
import '@wordpress/core-data';
import '@wordpress/notices';
import { registerCoreBlocks, UnsupportedBlock } from '@wordpress/block-library';
import { registerBlockType, setUnregisteredTypeHandlerName, unregisterBlockType } from '@wordpress/blocks';
import { registerCoreBlocks } from '@wordpress/block-library';
import { unregisterBlockType } from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -17,8 +17,6 @@ import './store';
export function initializeEditor() {
// register and setup blocks
registerCoreBlocks();
registerBlockType( UnsupportedBlock.name, UnsupportedBlock.settings );
setUnregisteredTypeHandlerName( UnsupportedBlock.name );

// disable Code and More blocks for the release
// eslint-disable-next-line no-undef
Expand Down