Skip to content

Commit

Permalink
Remove the block when deleting a shared block
Browse files Browse the repository at this point in the history
When deleting a shared block, any blocks in the page that reference that
shared block should be removed from the post.
  • Loading branch information
noisysocks committed Jul 17, 2018
1 parent ea710ca commit fc7a096
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion editor/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
switchToBlockType,
createBlock,
serialize,
isSharedBlock,
getDefaultBlockForPostFormat,
doBlocksMatchTemplate,
synchronizeBlocksWithTemplate,
Expand All @@ -39,6 +40,7 @@ import {
removeNotice,
saveSharedBlock,
insertBlock,
removeBlocks,
selectBlock,
removeBlock,
resetBlocks,
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit fc7a096

Please sign in to comment.