Skip to content

Commit

Permalink
Ensure replacing a template part creates a new entity and sets that e…
Browse files Browse the repository at this point in the history
…ntity as active (#44221)
  • Loading branch information
talldan authored Sep 19, 2022
1 parent 533e0b7 commit 7974e05
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions packages/block-library/src/template-part/edit/selection-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import { store as noticesStore } from '@wordpress/notices';
import { useDispatch } from '@wordpress/data';
import { parse } from '@wordpress/blocks';
import { useAsyncList } from '@wordpress/compose';
import {
__experimentalBlockPatternsList as BlockPatternsList,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';
import {
SearchControl,
__experimentalHStack as HStack,
Expand All @@ -36,9 +33,6 @@ export default function TemplatePartSelectionModal( {
} ) {
const [ searchValue, setSearchValue ] = useState( '' );

// When the templatePartId is undefined,
// it means the user is creating a new one from the placeholder.
const isReplacingTemplatePartContent = !! templatePartId;
const { templateParts } = useAlternativeTemplateParts(
area,
templatePartId
Expand All @@ -62,7 +56,6 @@ export default function TemplatePartSelectionModal( {
const shownBlockPatterns = useAsyncList( filteredBlockPatterns );

const { createSuccessNotice } = useDispatch( noticesStore );
const { replaceInnerBlocks } = useDispatch( blockEditorStore );

const onTemplatePartSelect = useCallback( ( templatePart ) => {
setAttributes( {
Expand Down Expand Up @@ -121,12 +114,7 @@ export default function TemplatePartSelectionModal( {
blockPatterns={ filteredBlockPatterns }
shownPatterns={ shownBlockPatterns }
onClickPattern={ ( pattern, blocks ) => {
if ( isReplacingTemplatePartContent ) {
replaceInnerBlocks( clientId, blocks );
} else {
createFromBlocks( blocks, pattern.title );
}

createFromBlocks( blocks, pattern.title );
onClose();
} }
/>
Expand Down

0 comments on commit 7974e05

Please sign in to comment.