-
Notifications
You must be signed in to change notification settings - Fork 219
Show classic template in the inserter only for specific templates #6539
Show classic template in the inserter only for specific templates #6539
Conversation
Size Change: +351 B (0%) Total Size: 875 kB
ℹ️ View Unchanged
|
cdb943b
to
c4953d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gigitux This is working as expected for built-in templates from the plugin but not for templates from the theme. I tested overriding the Product Catalog template in theme and got this issue:
…ocks into fix/5193-classic-template-only-for-specific-template
Thanks for the review and for testing! Great catch! 💪 I addressed the bug, the problem was the hardcoded slug. Now, it should be okay! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gigitux thanks for the update! I can confirm this PR is working with overridden templates from themes. I left some minor comments, can you please check?
|
||
if ( isExperimentalBuild() ) { | ||
subscribe( () => { | ||
const previousValue = currentTemplateId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change this to previousTemplateId
for consistency?
html: false, | ||
multiple: false, | ||
reusable: false, | ||
inserter: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be feature gated, otherwise, the block will be always available in the inserter when the block phase is less than 3.
} | ||
|
||
if ( | ||
getBlockType( BLOCK_SLUG ) === undefined && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use the block
variable here?
Thanks for the review, @dinhtungdu. With 1ac90a3 I addressed feedback. I reply to you about your question. Maybe are you thinking about a PHP approach? |
* See https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/5861 for more context | ||
*/ | ||
registerClassicTemplateBlock( { | ||
template: parsedTemplate ?? 'WooCommerce Classic Template', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the condition in line 219, Isn't the parsedTemplate
variable always truly at this point?
By the way, 'WooCommerce Classic Template' isn't the correct value for the template
variable, it should be the template ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for the multiple rounds updates! This is LGTM!
import { BLOCK_SLUG, TEMPLATES } from './constants'; | ||
|
||
interface Props { | ||
attributes: { | ||
template: string; | ||
align: string; | ||
}; | ||
setAttributes: ( attributes: Record< string, string > ) => void; | ||
clientId: string; | ||
} | ||
|
||
const Edit = ( { clientId, attributes }: Props ) => { | ||
const Edit = ( { clientId, attributes, setAttributes }: Props ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is optional but we can use the BlockEditProp
type here, for example:
woocommerce-blocks/assets/js/blocks/price-filter/edit.tsx
Lines 31 to 34 in f2ece16
export default function ( { | |
attributes, | |
setAttributes, | |
}: BlockEditProps< Attributes > ) { |
edit: ( { attributes, clientId, setAttributes } ) => { | ||
const newTemplate = template ?? ( attributes.template as string ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifying the type here can save a type casting call.
edit: ( { attributes, clientId, setAttributes } ) => { | |
const newTemplate = template ?? ( attributes.template as string ); | |
edit: ( { attributes, clientId, setAttributes }: Props ) => { | |
const newTemplate = template ?? attributes.template; | |
Thanks for the multiple reviews! 💪 |
Fixes #5193
Fixes #6110
With this PR the
Classic Template Block
will be visible in the inserter. But, the block will be visible in the inserter only for the templates:Testing
User Facing Testing
Check out this branch
Classic Template Block
is visible in the inserter only for the templates specificated above.WooCommerce Visibility
Changelog