Skip to content

Commit

Permalink
Check that new pattern is synced before replacing existing blocks wit…
Browse files Browse the repository at this point in the history
…h a synced pattern (#54804)
  • Loading branch information
glendaviesnz authored and mikachan committed Sep 26, 2023
1 parent 37f8bd0 commit 00e7e2f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/patterns/src/components/pattern-convert-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { store as noticesStore } from '@wordpress/notices';
import { store as patternsStore } from '../store';
import CreatePatternModal from './create-pattern-modal';
import { unlock } from '../lock-unlock';
import { PATTERN_SYNC_TYPES } from '../constants';

/**
* Menu control to convert block(s) to a pattern block.
Expand Down Expand Up @@ -96,15 +97,17 @@ export default function PatternConvertButton( { clientIds, rootClientId } ) {
}

const handleSuccess = ( { pattern } ) => {
const newBlock = createBlock( 'core/block', {
ref: pattern.id,
} );
if ( pattern.wp_pattern_sync_status !== PATTERN_SYNC_TYPES.unsynced ) {
const newBlock = createBlock( 'core/block', {
ref: pattern.id,
} );

replaceBlocks( clientIds, newBlock );
setEditingPattern( newBlock.clientId, true );
replaceBlocks( clientIds, newBlock );
setEditingPattern( newBlock.clientId, true );
}

createSuccessNotice(
pattern.wp_pattern_sync_status === 'unsynced'
pattern.wp_pattern_sync_status === PATTERN_SYNC_TYPES.unsynced
? sprintf(
// translators: %s: the name the user has given to the pattern.
__( 'Unsynced Pattern created: %s' ),
Expand Down

0 comments on commit 00e7e2f

Please sign in to comment.