Hide `Variations` section when it is empty (#36202)

* Add changelog

* Hide Variations section when it is empty

* Fix hiding variations

* Remove `totalCount const

Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
This commit is contained in:
Fernando Marichal 2023-01-12 16:32:40 -03:00 committed by GitHub
parent 891ecb7efb
commit 78002eac9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -3,7 +3,8 @@
*/
import { __ } from '@wordpress/i18n';
import { recordEvent } from '@woocommerce/tracks';
import { Link } from '@woocommerce/components';
import { Link, useFormContext } from '@woocommerce/components';
import { Product, ProductAttribute } from '@woocommerce/data';
/**
* Internal dependencies
@ -12,6 +13,28 @@ import { ProductSectionLayout } from '../layout/product-section-layout';
import { Variations } from '../fields/variations';
export const ProductVariationsSection: React.FC = () => {
const {
getInputProps,
values: { id: productId },
} = useFormContext< Product >();
const { value: attributes }: { value: ProductAttribute[] } = getInputProps(
'attributes',
{
productId,
}
);
const options = attributes
? attributes.filter(
( attribute: ProductAttribute ) => attribute.variation
)
: [];
if ( options.length === 0 ) {
return null;
}
return (
<ProductSectionLayout
title={ __( 'Variations', 'woocommerce' ) }

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Hide Variations section when it is empty