Skip to content
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

Ensure replacing a template part using a pattern doesn't update the existing entity #44221

Merged
merged 1 commit into from
Sep 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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