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:
parent
25cc4630be
commit
e6d0a906fb
|
@ -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,
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: fix
|
||||
|
||||
Product Collection: Hide preview label when specific product is selected
|
Loading…
Reference in New Issue