Product SKU: fix product SKU when added in the product meta block (https://github.com/woocommerce/woocommerce-blocks/pull/8966)

This commit is contained in:
Luigi Teschio 2023-04-19 09:47:03 +02:00 committed by GitHub
parent eb0d30c248
commit 4fbf32cef6
1 changed files with 28 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import type { BlockEditProps } from '@wordpress/blocks';
import EditProductLink from '@woocommerce/editor-components/edit-product-link';
import { ProductQueryContext as Context } from '@woocommerce/blocks/product-query/types';
import { useEffect } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
@ -28,9 +29,34 @@ const Edit = ( {
};
const isDescendentOfQueryLoop = Number.isFinite( context.queryId );
const isDescendentOfSingleProductTemplate = useSelect(
( select ) => {
const store = select( 'core/edit-site' );
const postId = store?.getEditedPostId< string | undefined >();
if ( ! postId ) {
return false;
}
return (
postId.includes( '//single-product' ) &&
! isDescendentOfQueryLoop
);
},
[ isDescendentOfQueryLoop ]
);
useEffect(
() => setAttributes( { isDescendentOfQueryLoop } ),
[ setAttributes, isDescendentOfQueryLoop ]
() =>
setAttributes( {
isDescendentOfQueryLoop,
isDescendentOfSingleProductTemplate,
} ),
[
setAttributes,
isDescendentOfQueryLoop,
isDescendentOfSingleProductTemplate,
]
);
return (