From c154329c935a949097d08d8c5f972c1fa4a485ab Mon Sep 17 00:00:00 2001 From: "Daniel W. Robert" Date: Wed, 29 Mar 2023 13:45:21 -0400 Subject: [PATCH 1/2] Remove isExperimentalBuild checks. By removing the `isExperimentalBuild` conditional checks in the Classic Template block, we can ensure the features added in #8324 will land in WooCommerce Core and are not limited to the feature plugin. See p1680000654295729-slack-C02UBB1EPEF for additional context. --- assets/js/blocks/classic-template/index.tsx | 102 +++++++++----------- 1 file changed, 45 insertions(+), 57 deletions(-) diff --git a/assets/js/blocks/classic-template/index.tsx b/assets/js/blocks/classic-template/index.tsx index ea3da89e34f..194b6fc4ef4 100644 --- a/assets/js/blocks/classic-template/index.tsx +++ b/assets/js/blocks/classic-template/index.tsx @@ -7,10 +7,7 @@ import { unregisterBlockType, } from '@wordpress/blocks'; import type { BlockEditProps } from '@wordpress/blocks'; -import { - isExperimentalBuild, - WC_BLOCKS_IMAGE_URL, -} from '@woocommerce/block-settings'; +import { WC_BLOCKS_IMAGE_URL } from '@woocommerce/block-settings'; import { useBlockProps } from '@wordpress/block-editor'; import { Button, Placeholder } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; @@ -89,7 +86,7 @@ const Edit = ( { getButtonLabel, } = conversionConfig[ templateType ]; - const canConvert = isExperimentalBuild() && isConversionPossible(); + const canConvert = isConversionPossible(); const placeholderDescription = getDescription( templateTitle, canConvert ); return ( @@ -210,55 +207,46 @@ const registerClassicTemplateBlock = ( { let currentTemplateId: string | undefined; -if ( isExperimentalBuild() ) { - subscribe( () => { - const previousTemplateId = currentTemplateId; - const store = select( 'core/edit-site' ); - currentTemplateId = store?.getEditedPostId() as string | undefined; - - if ( previousTemplateId === currentTemplateId ) { - return; - } - - const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ]; - - if ( parsedTemplate === null || parsedTemplate === undefined ) { - return; - } - - const block = getBlockType( BLOCK_SLUG ); - - if ( - block !== undefined && - ( ! hasTemplateSupportForClassicTemplateBlock( - parsedTemplate, - TEMPLATES - ) || - isClassicTemplateBlockRegisteredWithAnotherTitle( - block, - parsedTemplate - ) ) - ) { - unregisterBlockType( BLOCK_SLUG ); - currentTemplateId = undefined; - return; - } - - if ( - block === undefined && - hasTemplateSupportForClassicTemplateBlock( - parsedTemplate, - TEMPLATES - ) - ) { - registerClassicTemplateBlock( { - template: parsedTemplate, - inserter: true, - } ); - } - } ); -} else { - registerClassicTemplateBlock( { - inserter: false, - } ); -} +subscribe( () => { + const previousTemplateId = currentTemplateId; + const store = select( 'core/edit-site' ); + currentTemplateId = store?.getEditedPostId() as string | undefined; + + if ( previousTemplateId === currentTemplateId ) { + return; + } + + const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ]; + + if ( parsedTemplate === null || parsedTemplate === undefined ) { + return; + } + + const block = getBlockType( BLOCK_SLUG ); + + if ( + block !== undefined && + ( ! hasTemplateSupportForClassicTemplateBlock( + parsedTemplate, + TEMPLATES + ) || + isClassicTemplateBlockRegisteredWithAnotherTitle( + block, + parsedTemplate + ) ) + ) { + unregisterBlockType( BLOCK_SLUG ); + currentTemplateId = undefined; + return; + } + + if ( + block === undefined && + hasTemplateSupportForClassicTemplateBlock( parsedTemplate, TEMPLATES ) + ) { + registerClassicTemplateBlock( { + template: parsedTemplate, + inserter: true, + } ); + } +} ); From 3ee34d52c3a6f110dfd3c40bfe321f1223c569a3 Mon Sep 17 00:00:00 2001 From: "Daniel W. Robert" Date: Wed, 29 Mar 2023 16:46:18 -0400 Subject: [PATCH 2/2] Revert isExperimentalBuild removal on registration The conditional `isExperimentalBuild` conditional check that was wrapping some conditional registration of the classic template block seems to be unrelated to the template conversion/migration. This is something we can revisit and test separately but should not be included in this changeset. --- assets/js/blocks/classic-template/index.tsx | 100 +++++++++++--------- 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/assets/js/blocks/classic-template/index.tsx b/assets/js/blocks/classic-template/index.tsx index 194b6fc4ef4..2df71d93f5e 100644 --- a/assets/js/blocks/classic-template/index.tsx +++ b/assets/js/blocks/classic-template/index.tsx @@ -7,7 +7,10 @@ import { unregisterBlockType, } from '@wordpress/blocks'; import type { BlockEditProps } from '@wordpress/blocks'; -import { WC_BLOCKS_IMAGE_URL } from '@woocommerce/block-settings'; +import { + isExperimentalBuild, + WC_BLOCKS_IMAGE_URL, +} from '@woocommerce/block-settings'; import { useBlockProps } from '@wordpress/block-editor'; import { Button, Placeholder } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; @@ -207,46 +210,55 @@ const registerClassicTemplateBlock = ( { let currentTemplateId: string | undefined; -subscribe( () => { - const previousTemplateId = currentTemplateId; - const store = select( 'core/edit-site' ); - currentTemplateId = store?.getEditedPostId() as string | undefined; - - if ( previousTemplateId === currentTemplateId ) { - return; - } - - const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ]; - - if ( parsedTemplate === null || parsedTemplate === undefined ) { - return; - } - - const block = getBlockType( BLOCK_SLUG ); - - if ( - block !== undefined && - ( ! hasTemplateSupportForClassicTemplateBlock( - parsedTemplate, - TEMPLATES - ) || - isClassicTemplateBlockRegisteredWithAnotherTitle( - block, - parsedTemplate - ) ) - ) { - unregisterBlockType( BLOCK_SLUG ); - currentTemplateId = undefined; - return; - } - - if ( - block === undefined && - hasTemplateSupportForClassicTemplateBlock( parsedTemplate, TEMPLATES ) - ) { - registerClassicTemplateBlock( { - template: parsedTemplate, - inserter: true, - } ); - } -} ); +if ( isExperimentalBuild() ) { + subscribe( () => { + const previousTemplateId = currentTemplateId; + const store = select( 'core/edit-site' ); + currentTemplateId = store?.getEditedPostId() as string | undefined; + + if ( previousTemplateId === currentTemplateId ) { + return; + } + + const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ]; + + if ( parsedTemplate === null || parsedTemplate === undefined ) { + return; + } + + const block = getBlockType( BLOCK_SLUG ); + + if ( + block !== undefined && + ( ! hasTemplateSupportForClassicTemplateBlock( + parsedTemplate, + TEMPLATES + ) || + isClassicTemplateBlockRegisteredWithAnotherTitle( + block, + parsedTemplate + ) ) + ) { + unregisterBlockType( BLOCK_SLUG ); + currentTemplateId = undefined; + return; + } + + if ( + block === undefined && + hasTemplateSupportForClassicTemplateBlock( + parsedTemplate, + TEMPLATES + ) + ) { + registerClassicTemplateBlock( { + template: parsedTemplate, + inserter: true, + } ); + } + } ); +} else { + registerClassicTemplateBlock( { + inserter: false, + } ); +}