-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Implement recovery option for invalid blocks (#41988)
If a block's validation fails within the mobile app, users are shown an error but not provided with any options for recovering the block. This PR introduces an option for users to attempt block recovery. They'll be prompted to tap on a block if they wish to attempt recovery.
- Loading branch information
Showing
3 changed files
with
44 additions
and
7 deletions.
There are no files selected for viewing
49 changes: 42 additions & 7 deletions
49
packages/block-editor/src/components/block-list/block-invalid-warning.native.js
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 |
---|---|---|
@@ -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> | ||
); | ||
} |
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