-
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
Show warning on critical block removal #51145
Merged
Merged
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
2d11a45
Show warning on critical block removal
tellthemachines c1912d9
Extract prompt display logic into a hook
tellthemachines 405c26b
Revert formatting change.
tellthemachines 79ba8ad
Prompt for removal of all the blocks
tellthemachines 15959b5
Move prompt state handling out of BlockList and into self
mcsf ce307ad
findCriticalBlocks: don't dismiss children of matching node
mcsf e5ddee6
findCriticalBlocks -> getBlocksToPromptFor
mcsf df68c00
Drop isBlockCritical()
mcsf 042063a
Redesign removal modal
mcsf fb4c79d
Move prompt into site editor.
tellthemachines d3a12c8
Reset removalPromptExists upon listener unmount
mcsf c9952f1
Let action removeBlocks handle prompts and confirmations
mcsf 33afda6
Add private action `privateRemoveBlocks` to hide extended interface
mcsf 7482ba3
Fix unit tests
tellthemachines a5cce0a
Try: Dispatch setRemovalPromptStatus in edit-site init
mcsf b26efc4
Revert "Try: Dispatch setRemovalPromptStatus in edit-site init"
mcsf 0e88e1a
Make all actions & selectors private. Rename things.
mcsf 29f99c1
Make BlockRemovalWarningModal private
mcsf bb0cd7c
Cleanup: Remove BlockList changes from branch
mcsf c27ab49
Tweak removal message for Query. Tweak comments.
mcsf 65df9cf
Split action into displayRemovalPrompt & clearRemovalPrompt
mcsf 02df539
Rename setRemovalPromptStatus to toggleRemovalPromptSupport
mcsf d2b6a9f
Rename isRemovalPromptDisplayed to getRemovalPromptData
mcsf 5d1c3e2
Add missing @return to displayRemovalPrompt
mcsf e180954
Tweak modal copy per feedback
mcsf 23f034d
Turns out private selectors are attached to the thunk proxy!
mcsf 6a0a806
Don't export the new reducers
mcsf 628207a
Fix tests
mcsf 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
94 changes: 94 additions & 0 deletions
94
packages/block-editor/src/components/block-removal-warning-modal/index.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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEffect } from '@wordpress/element'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { | ||
Modal, | ||
Button, | ||
__experimentalHStack as HStack, | ||
} from '@wordpress/components'; | ||
import { __, _n } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
export const blockTypePromptMessages = { | ||
'core/query': __( 'Query Loop displays a list of posts.' ), | ||
'core/post-content': __( | ||
'Post Content displays the content of a post or page.' | ||
), | ||
}; | ||
|
||
export function BlockRemovalWarningModal() { | ||
const { clientIds, selectPrevious, blockNamesForPrompt } = useSelect( | ||
( select ) => | ||
unlock( select( blockEditorStore ) ).isRemovalPromptDisplayed() | ||
); | ||
|
||
const { | ||
displayRemovalPrompt, | ||
setRemovalPromptStatus, | ||
privateRemoveBlocks, | ||
} = unlock( useDispatch( blockEditorStore ) ); | ||
|
||
// Signalling the removal prompt is in place. | ||
useEffect( () => { | ||
setRemovalPromptStatus( true ); | ||
return () => { | ||
setRemovalPromptStatus( false ); | ||
}; | ||
}, [ setRemovalPromptStatus ] ); | ||
|
||
if ( ! blockNamesForPrompt ) { | ||
return; | ||
} | ||
|
||
const closeModal = () => displayRemovalPrompt( false ); | ||
|
||
const onConfirmRemoval = () => { | ||
privateRemoveBlocks( clientIds, selectPrevious, /* force */ true ); | ||
closeModal(); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
title={ _n( | ||
'Really delete this block?', | ||
'Really delete these blocks?', | ||
clientIds.length | ||
) } | ||
onRequestClose={ closeModal } | ||
> | ||
{ blockNamesForPrompt.length === 1 ? ( | ||
<p>{ blockTypePromptMessages[ blockNamesForPrompt[ 0 ] ] }</p> | ||
) : ( | ||
<ul style={ { listStyleType: 'disc', paddingLeft: '1rem' } }> | ||
{ blockNamesForPrompt.map( ( name ) => ( | ||
<li key={ name }> | ||
{ blockTypePromptMessages[ name ] } | ||
</li> | ||
) ) } | ||
</ul> | ||
) } | ||
<p> | ||
{ _n( | ||
'Removing this block is not advised.', | ||
'Removing these blocks is not advised.', | ||
blockNamesForPrompt.length | ||
) } | ||
</p> | ||
<HStack justify="right"> | ||
<Button variant="tertiary" onClick={ closeModal }> | ||
{ __( 'Cancel' ) } | ||
</Button> | ||
<Button variant="primary" onClick={ onConfirmRemoval }> | ||
{ __( 'Confirm' ) } | ||
</Button> | ||
</HStack> | ||
</Modal> | ||
); | ||
} |
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
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.
Not a blocker, but just noting that this is pretty similar to the
ConfirmDialog
component.There are possibly some differences (the title?), so it could be a later refactor.
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.
Thanks, good observation.