Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,27 +1,62 @@
/**
* External dependencies
*/
import { TouchableWithoutFeedback } from 'react-native';

/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import Warning from '../warning';
import { store as blockEditorStore } from '../../store';

export default function BlockInvalidWarning( { blockTitle, icon } ) {
export default function BlockInvalidWarning( { blockTitle, icon, clientId } ) {
const accessibilityLabel = sprintf(
/* translators: accessibility text for blocks with invalid content. %d: localized block title */
__( '%s block. This block has invalid content' ),
blockTitle
);

const selector = ( select ) => {
const { getBlock } = select( blockEditorStore );
const block = getBlock( clientId );
return {
block,
};
};

const { block } = useSelect( selector, [ clientId ] );

const { replaceBlock } = useDispatch( blockEditorStore );

const recoverBlock = ( { name, attributes, innerBlocks } ) =>
createBlock( name, attributes, innerBlocks );

const attemptBlockRecovery = () => {
replaceBlock( block.clientId, recoverBlock( block ) );
};

return (
<Warning
title={ blockTitle }
message={ __( 'Problem displaying block' ) }
icon={ icon }
<TouchableWithoutFeedback
onPress={ attemptBlockRecovery }
accessible={ true }
accessibilityLabel={ accessibilityLabel }
/>
accessibilityRole={ 'button' }
>
<Warning
title={ blockTitle }
// eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace
message={ __(
'Problem displaying block. \nTap to attempt block recovery.'
) }
icon={ icon }
accessibilityLabel={ accessibilityLabel }
/>
</TouchableWithoutFeedback>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ class BlockListBlock extends Component {
<BlockInvalidWarning
blockTitle={ title }
icon={ icon }
clientId={ clientId }
/>
)
}
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 @@ -14,6 +14,7 @@ For each user feature we should also add a importance categorization label to i
- [*] Add 'Insert from URL' option to Video block [#41493]
- [*] Image block copies the alt text from the media library when selecting an item [#41839]
- [**] RichText - Improve performance by dropping events during quick typing [#41682]
- [*] Introduce "block recovery" option for invalid blocks [#41988]

## 1.78.1

Expand Down