Product Collection: Hide preview label when specific product is selected (#52150)

* Hide preview label when a specific product is selected

This commit modifies the Product Collection block to hide the preview
label when a specific product is selected by the user. It addresses the
issue where the preview label was still showing even when a product
reference was available.

* Add changefile(s) from automation for the following project(s): woocommerce-blocks

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Manish Menaria 2024-10-22 12:54:16 +05:30 committed by GitHub
parent 25cc4630be
commit e6d0a906fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 7 deletions

View File

@ -207,16 +207,16 @@ export const useProductCollectionUIState = ( {
} ) => {
// Fetch product to check if it's deleted.
// `product` will be undefined if it doesn't exist.
const productId = attributes.query?.productReference;
const productReference = attributes.query?.productReference;
const { product, hasResolved } = useSelect(
( selectFunc ) => {
if ( ! productId ) {
if ( ! productReference ) {
return { product: null, hasResolved: true };
}
const { getEntityRecord, hasFinishedResolution } =
selectFunc( coreDataStore );
const selectorArgs = [ 'postType', 'product', productId ];
const selectorArgs = [ 'postType', 'product', productReference ];
return {
product: getEntityRecord( ...selectorArgs ),
hasResolved: hasFinishedResolution(
@ -225,7 +225,7 @@ export const useProductCollectionUIState = ( {
),
};
},
[ productId ]
[ productReference ]
);
const productCollectionUIStateInEditor = useMemo( () => {
@ -255,7 +255,7 @@ export const useProductCollectionUIState = ( {
isProductContextSelected
) {
const isProductDeleted =
productId &&
productReference &&
( product === undefined || product?.status === 'trash' );
if ( isProductDeleted ) {
return ProductCollectionUIStatesInEditor.DELETED_PRODUCT_REFERENCE;
@ -282,7 +282,9 @@ export const useProductCollectionUIState = ( {
if (
! isArchiveLocationWithTermId &&
! isProductLocationWithProductId
! isProductLocationWithProductId &&
// If there's a user-selected product reference, don't show the preview label
! productReference
) {
return ProductCollectionUIStatesInEditor.VALID_WITH_PREVIEW;
}
@ -302,7 +304,7 @@ export const useProductCollectionUIState = ( {
location.sourceData?.productId,
usesReference,
attributes.collection,
productId,
productReference,
product,
hasInnerBlocks,
attributes.query?.productReference,

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Product Collection: Hide preview label when specific product is selected