Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Remove isExperimentalBuild checks.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danielwrobert committed Mar 29, 2023
1 parent 298010e commit c154329
Showing 1 changed file with 45 additions and 57 deletions.
102 changes: 45 additions & 57 deletions assets/js/blocks/classic-template/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -89,7 +86,7 @@ const Edit = ( {
getButtonLabel,
} = conversionConfig[ templateType ];

const canConvert = isExperimentalBuild() && isConversionPossible();
const canConvert = isConversionPossible();
const placeholderDescription = getDescription( templateTitle, canConvert );

return (
Expand Down Expand Up @@ -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,
} );
}
} );

0 comments on commit c154329

Please sign in to comment.