diff --git a/packages/block-editor/src/components/block-removal-warning-modal/index.js b/packages/block-editor/src/components/block-removal-warning-modal/index.js index 2ed65481f68959..08f3deccb5ae08 100644 --- a/packages/block-editor/src/components/block-removal-warning-modal/index.js +++ b/packages/block-editor/src/components/block-removal-warning-modal/index.js @@ -16,38 +16,26 @@ import { __ } from '@wordpress/i18n'; import { store as blockEditorStore } from '../../store'; import { unlock } from '../../lock-unlock'; -// In certain editing contexts, we'd like to prevent accidental removal of -// important blocks. For example, in the site editor, the Query Loop block is -// deemed important. In such cases, we'll ask the user for confirmation that -// they intended to remove such block(s). -// -// @see https://github.com/WordPress/gutenberg/pull/51145 -export const blockTypePromptMessages = { - 'core/query': __( 'Query Loop displays a list of posts or pages.' ), - 'core/post-content': __( - 'Post Content displays the content of a post or page.' - ), -}; - -export function BlockRemovalWarningModal() { +export function BlockRemovalWarningModal( { rules } ) { const { clientIds, selectPrevious, blockNamesForPrompt } = useSelect( ( select ) => unlock( select( blockEditorStore ) ).getRemovalPromptData() ); const { - clearRemovalPrompt, - toggleRemovalPromptSupport, + clearBlockRemovalPrompt, + setBlockRemovalRules, privateRemoveBlocks, } = unlock( useDispatch( blockEditorStore ) ); - // Signalling the removal prompt is in place. + // Load block removal rules, simultaneously signalling that the block + // removal prompt is in place. useEffect( () => { - toggleRemovalPromptSupport( true ); + setBlockRemovalRules( rules ); return () => { - toggleRemovalPromptSupport( false ); + setBlockRemovalRules(); }; - }, [ toggleRemovalPromptSupport ] ); + }, [ rules, setBlockRemovalRules ] ); if ( ! blockNamesForPrompt ) { return; @@ -55,22 +43,20 @@ export function BlockRemovalWarningModal() { const onConfirmRemoval = () => { privateRemoveBlocks( clientIds, selectPrevious, /* force */ true ); - clearRemovalPrompt(); + clearBlockRemovalPrompt(); }; return ( { blockNamesForPrompt.length === 1 ? ( -

{ blockTypePromptMessages[ blockNamesForPrompt[ 0 ] ] }

+

{ rules[ blockNamesForPrompt[ 0 ] ] }

) : ( ) } @@ -80,7 +66,7 @@ export function BlockRemovalWarningModal() { : __( 'Removing this block is not advised.' ) }

-