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

Commit

Permalink
Classic Product Template visible in the inserter (#9573)
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux authored May 25, 2023
1 parent abbaaff commit 9505e89
Showing 1 changed file with 38 additions and 50 deletions.
88 changes: 38 additions & 50 deletions assets/js/blocks/classic-template/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,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,
BlockPreview,
Expand Down Expand Up @@ -340,55 +337,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;
subscribe( () => {
const previousTemplateId = currentTemplateId;
const store = select( 'core/edit-site' );
currentTemplateId = store?.getEditedPostId() as string | undefined;

if ( previousTemplateId === currentTemplateId ) {
return;
}
if ( previousTemplateId === currentTemplateId ) {
return;
}

const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ];
const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ];

if ( parsedTemplate === null || parsedTemplate === undefined ) {
return;
}
if ( parsedTemplate === null || parsedTemplate === undefined ) {
return;
}

const block = getBlockType( BLOCK_SLUG );
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
) ||
isClassicTemplateBlockRegisteredWithAnotherTitle(
block,
parsedTemplate
) )
) {
unregisterBlockType( BLOCK_SLUG );
currentTemplateId = undefined;
return;
}

if (
block === undefined &&
hasTemplateSupportForClassicTemplateBlock(
parsedTemplate,
TEMPLATES
)
) {
registerClassicTemplateBlock( {
template: parsedTemplate,
inserter: true,
} );
}
} );
} else {
registerClassicTemplateBlock( {
inserter: false,
} );
}
if (
block === undefined &&
hasTemplateSupportForClassicTemplateBlock( parsedTemplate, TEMPLATES )
) {
registerClassicTemplateBlock( {
template: parsedTemplate,
inserter: true,
} );
}
} );

0 comments on commit 9505e89

Please sign in to comment.