Skip to content

Commit

Permalink
findCriticalBlocks -> getBlocksToPromptFor
Browse files Browse the repository at this point in the history
The intention here was to drop the "find" prefix, which can mislead the
render into believing the function is meant to return a single match or
none.
  • Loading branch information
mcsf committed Jun 6, 2023
1 parent c972adf commit 5059a67
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/block-editor/src/utils/show-block-removal-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ export function useBlockRemovalWarning() {
const { displayRemovalPrompt, removeBlocks } =
useDispatch( blockEditorStore );

function findCriticalBlocks( clientIds ) {
function getBlocksToPromptFor( clientIds ) {
return clientIds.flatMap( ( clientId ) => {
const found = [];
const blockName = getBlockName( clientId );
if ( isBlockCritical( blockName ) ) {
found.push( blockName );
}
const innerBlocks = getBlockOrder( clientId );
return found.concat( findCriticalBlocks( innerBlocks ) );
return found.concat( getBlocksToPromptFor( innerBlocks ) );
} );
}

return ( clientIds, selectPrevious = true ) => {
const criticalBlocks = findCriticalBlocks( clientIds );
const blocksToPromptFor = getBlocksToPromptFor( clientIds );

if ( criticalBlocks.length ) {
if ( blocksToPromptFor.length ) {
displayRemovalPrompt( true, {
removalFunction: () => {
removeBlocks( clientIds, selectPrevious );
},
blocksToPromptFor: criticalBlocks,
blocksToPromptFor,
} );
} else {
removeBlocks( clientIds, selectPrevious );
Expand Down

0 comments on commit 5059a67

Please sign in to comment.