Skip to content

Commit

Permalink
[RNMobile] Fix missing title for some unsupported blocks (#31743)
Browse files Browse the repository at this point in the history
* Add get title to missing block

The block's title is now only translated when is gets registered, for unsupported blocks since they're not registered, title has be explicitly translated.

* Update react-native-editor changelog
  • Loading branch information
fluiddot committed May 18, 2021
1 parent 073bcb0 commit a8061c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/block-library/src/missing/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { compose, withPreferredColorScheme } from '@wordpress/compose';
import { coreBlocks } from '@wordpress/block-library';
import { normalizeIconObject } from '@wordpress/blocks';
import { Component } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { __, _x, sprintf } from '@wordpress/i18n';
import { help, plugins } from '@wordpress/icons';
import { withSelect, withDispatch } from '@wordpress/data';
import { applyFilters } from '@wordpress/hooks';
Expand All @@ -34,6 +34,7 @@ import styles from './style.scss';

// Blocks that can't be edited through the Unsupported block editor identified by their name.
const UBE_INCOMPATIBLE_BLOCKS = [ 'core/block' ];
const I18N_BLOCK_SCHEMA_TITLE = 'block title';

export class UnsupportedBlockEdit extends Component {
constructor( props ) {
Expand Down Expand Up @@ -63,6 +64,18 @@ export class UnsupportedBlockEdit extends Component {
}
}

getTitle() {
const { originalName } = this.props.attributes;
const blockType = coreBlocks[ originalName ];
const title = blockType?.metadata.title;
const textdomain = blockType?.metadata.textdomain;

return title && textdomain
? // eslint-disable-next-line @wordpress/i18n-no-variables, @wordpress/i18n-text-domain
_x( title, I18N_BLOCK_SCHEMA_TITLE, textdomain )
: originalName;
}

renderHelpIcon() {
const infoIconStyle = this.props.getStylesFromColorScheme(
styles.infoIcon,
Expand Down Expand Up @@ -225,7 +238,7 @@ export class UnsupportedBlockEdit extends Component {
const { getStylesFromColorScheme, preferredColorScheme } = this.props;
const blockType = coreBlocks[ originalName ];

const title = blockType ? blockType.settings.title : originalName;
const title = this.getTitle();
const titleStyle = getStylesFromColorScheme(
styles.unsupportedBlockMessage,
styles.unsupportedBlockMessageDark
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ For each user feature we should also add a importance categorization label to i
## 1.52.2

- [*] Disabled featured image banner on iOS. [#31681]
- [*] Fix missing title for some unsupported blocks [#31743]

## 1.52.1

Expand Down

0 comments on commit a8061c1

Please sign in to comment.