-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6a8b8bb
Expose required methods for better unsupported blocks
koke cc21fb4
Show unsupported block title/icon when possible
koke f4daa43
Remove native variant of editor package
koke 95d80c2
Refactor mobile blocks to fix circle dependencies
Tug e1e1d30
Fix styles for unsupported block
koke 9bf5acf
Remove UnsupportedBlock in favor of core/missing
koke 3ebc6f9
Merge commit '828fe4079' into rnmobile/unsupported-core-blocks-master
koke 874760e
Merge commit '342961e48' into rnmobile/unsupported-core-blocks-master
koke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { View, Text } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Icon } from '@wordpress/components'; | ||
import { coreBlocks } from '@wordpress/block-library'; | ||
import { normalizeIconObject } from '@wordpress/blocks'; | ||
import { Component } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './style.scss'; | ||
|
||
export default class UnsupportedBlockEdit extends Component { | ||
render() { | ||
const { originalName } = this.props.attributes; | ||
const blockType = coreBlocks[ originalName ]; | ||
const title = blockType ? blockType.settings.title : __( 'Unsupported' ); | ||
const icon = blockType ? normalizeIconObject( blockType.settings.icon ) : 'admin-plugins'; | ||
|
||
return ( | ||
<View style={ styles.unsupportedBlock }> | ||
<Icon className="unsupported-icon" icon={ icon && icon.src ? icon.src : icon } /> | ||
<Text style={ styles.unsupportedBlockMessage }>{ title }</Text> | ||
</View> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,8 @@ | |
color: #87a6bc; | ||
fill: currentColor; | ||
} | ||
|
||
.unsupported-icon { | ||
color: $gray-dark; | ||
fill: currentColor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be written as a stateless component, since we are not using local state or lifecycle methods.
At my understanding, they are quite faster.