Fix PropTypes warning for CartLineItem component (https://github.com/woocommerce/woocommerce-blocks/pull/1927)

* fix proptypes declaration.

This ensures that when `lowStockRemaining` is included it’s either null or a number.

* Ensure backorders_allowed value is boolean.

* add missing properties to cart preview
This commit is contained in:
Darren Ethier 2020-03-10 11:14:05 -04:00 committed by GitHub
parent e6dfe243f9
commit 4b4dff1297
3 changed files with 10 additions and 3 deletions

View File

@ -48,7 +48,7 @@ const CartLineItemRow = ( { lineItem } ) => {
const { const {
name, name,
summary, summary,
low_stock_remaining: lowStockRemaining, low_stock_remaining: lowStockRemaining = null,
backorders_allowed: backOrdersAllowed, backorders_allowed: backOrdersAllowed,
permalink, permalink,
images, images,
@ -147,7 +147,10 @@ CartLineItemRow.propTypes = {
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
summary: PropTypes.string.isRequired, summary: PropTypes.string.isRequired,
images: PropTypes.array.isRequired, images: PropTypes.array.isRequired,
low_stock_remaining: PropTypes.number.isRequired, low_stock_remaining: PropTypes.oneOfType( [
PropTypes.number,
PropTypes.oneOf( [ null ] ),
] ),
backorders_allowed: PropTypes.bool.isRequired, backorders_allowed: PropTypes.bool.isRequired,
sold_individually: PropTypes.bool.isRequired, sold_individually: PropTypes.bool.isRequired,
variation: PropTypes.arrayOf( variation: PropTypes.arrayOf(

View File

@ -31,6 +31,8 @@ export const previewCart = {
sku: 'woo-beanie', sku: 'woo-beanie',
permalink: 'https://example.org', permalink: 'https://example.org',
low_stock_remaining: 2, low_stock_remaining: 2,
backorders_allowed: false,
sold_individually: false,
images: [ images: [
{ {
id: 10, id: 10,
@ -95,6 +97,8 @@ export const previewCart = {
'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
sku: 'woo-cap', sku: 'woo-cap',
permalink: 'https://example.org', permalink: 'https://example.org',
backorders_allowed: false,
sold_individually: false,
images: [ images: [
{ {
id: 11, id: 11,

View File

@ -310,7 +310,7 @@ class CartItemSchema extends AbstractSchema {
'description' => $this->prepare_html_response( wc_format_content( $product->get_description() ) ), 'description' => $this->prepare_html_response( wc_format_content( $product->get_description() ) ),
'sku' => $this->prepare_html_response( $product->get_sku() ), 'sku' => $this->prepare_html_response( $product->get_sku() ),
'low_stock_remaining' => $this->get_low_stock_remaining( $product ), 'low_stock_remaining' => $this->get_low_stock_remaining( $product ),
'backorders_allowed' => $product->backorders_allowed(), 'backorders_allowed' => (bool) $product->backorders_allowed(),
'sold_individually' => $product->is_sold_individually(), 'sold_individually' => $product->is_sold_individually(),
'permalink' => $product->get_permalink(), 'permalink' => $product->get_permalink(),
'images' => ( new ProductImages() )->images_to_array( $product ), 'images' => ( new ProductImages() )->images_to_array( $product ),