Use new util functions in ShippingRatesControl (https://github.com/woocommerce/woocommerce-blocks/pull/2153)

* Use new util functions in ShippingRatesControl

* Import from base-utils
This commit is contained in:
Albert Juhé Lluveras 2020-04-08 12:19:05 +02:00 committed by GitHub
parent 0000cac384
commit db4f7820c6
4 changed files with 13 additions and 11 deletions

View File

@ -6,6 +6,10 @@ import { useEffect } from 'react';
import PropTypes from 'prop-types';
import { speak } from '@wordpress/a11y';
import LoadingMask from '@woocommerce/base-components/loading-mask';
import {
getShippingRatesPackageCount,
getShippingRatesRateCount,
} from '@woocommerce/base-utils';
/**
* Internal dependencies
@ -25,11 +29,8 @@ const ShippingRatesControl = ( {
if ( shippingRatesLoading ) {
return;
}
const packages = shippingRates.length;
const shippingOptions = shippingRates.reduce(
( acc, shippingRate ) => acc + shippingRate.shipping_rates.length,
0
);
const packages = getShippingRatesPackageCount( shippingRates );
const shippingOptions = getShippingRatesRateCount( shippingRates );
if ( shippingOptions === 0 ) {
speak(
__(

View File

@ -1,3 +1,4 @@
export * from './errors';
export * from './price';
export * from './address';
export * from './shipping-rates';

View File

@ -4,7 +4,7 @@
* @param {Array} shippingRates Shipping rates and packages array.
*/
export const getShippingRatesPackageCount = ( shippingRates ) => {
return Object.keys( shippingRates ).length;
return shippingRates.length;
};
/**

View File

@ -15,7 +15,11 @@ import {
} from '@woocommerce/base-components/cart-checkout';
import { ValidatedTextInput } from '@woocommerce/base-components/text-input';
import CheckboxControl from '@woocommerce/base-components/checkbox-control';
import { getCurrencyFromPriceResponse } from '@woocommerce/base-utils';
import {
getCurrencyFromPriceResponse,
getShippingRatesPackageCount,
getShippingRatesRateCount,
} from '@woocommerce/base-utils';
import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-monetary-amount';
import {
CheckoutProvider,
@ -46,10 +50,6 @@ import CheckoutSidebar from './sidebar';
import CheckoutOrderError from './checkout-order-error';
import NoShippingPlaceholder from './no-shipping-placeholder';
import './style.scss';
import {
getShippingRatesPackageCount,
getShippingRatesRateCount,
} from './utils';
const Block = ( props ) => (
<CheckoutProvider>