From fc7a0963a1e8f39ae8b5f01a239fd49b7eb4988a Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Tue, 17 Jul 2018 16:05:04 +1000 Subject: [PATCH] Remove the block when deleting a shared block When deleting a shared block, any blocks in the page that reference that shared block should be removed from the post. --- editor/store/effects.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/editor/store/effects.js b/editor/store/effects.js index 3310bdc30bfc2..0f86f75fe1a52 100644 --- a/editor/store/effects.js +++ b/editor/store/effects.js @@ -13,6 +13,7 @@ import { switchToBlockType, createBlock, serialize, + isSharedBlock, getDefaultBlockForPostFormat, doBlocksMatchTemplate, synchronizeBlocksWithTemplate, @@ -39,6 +40,7 @@ import { removeNotice, saveSharedBlock, insertBlock, + removeBlocks, selectBlock, removeBlock, resetBlocks, @@ -545,7 +547,13 @@ export default { } const { id } = action; - const { dispatch } = store; + const { getState, dispatch } = store; + + // Remove any blocks that reference this shared block + const allBlocks = getBlocks( getState() ); + const associatedBlocks = allBlocks.filter( ( block ) => isSharedBlock( block ) && block.attributes.ref === id ); + const associatedBlockUids = associatedBlocks.map( ( block ) => block.uid ); + dispatch( removeBlocks( associatedBlockUids ) ); const transactionId = uniqueId();