Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'core/trunk' into add/stock-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
diazoxide committed Jun 2, 2021
2 parents 2f6e53b + 413a4e0 commit 1ee393a
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 31 deletions.
Expand Up @@ -7,7 +7,6 @@ import ProductName from '@woocommerce/base-components/product-name';
import { getCurrencyFromPriceResponse } from '@woocommerce/price-format';
import {
__experimentalApplyCheckoutFilter,
mustBeString,
mustContain,
Label,
} from '@woocommerce/blocks-checkout';
Expand Down Expand Up @@ -48,7 +47,7 @@ const OrderSummaryItem = ( { cartItem } ) => {
const { receiveCart, ...cart } = useStoreCart();

const productPriceValidation = useCallback(
( value ) => mustBeString( value ) && mustContain( value, '<price/>' ),
( value ) => mustContain( value, '<price/>' ),
[]
);

Expand All @@ -68,7 +67,6 @@ const OrderSummaryItem = ( { cartItem } ) => {
defaultValue: initialName,
extensions,
arg,
validation: mustBeString,
} );

const regularPriceSingle = Dinero( {
Expand Down
Expand Up @@ -7,7 +7,6 @@ import { RemovableChip } from '@woocommerce/base-components/chip';
import PropTypes from 'prop-types';
import {
__experimentalApplyCheckoutFilter,
mustBeString,
TotalsItem,
} from '@woocommerce/blocks-checkout';
import { getSetting } from '@woocommerce/settings';
Expand Down Expand Up @@ -60,7 +59,6 @@ const TotalsDiscount = ( {
{ cartCoupons.map( ( cartCoupon ) => {
const filteredCouponCode = __experimentalApplyCheckoutFilter(
{
validation: mustBeString,
arg: {
context: 'summary',
coupon: cartCoupon,
Expand Down
Expand Up @@ -7,7 +7,6 @@ import FormattedMonetaryAmount from '@woocommerce/base-components/formatted-mone
import PropTypes from 'prop-types';
import {
__experimentalApplyCheckoutFilter,
mustBeString,
TotalsItem,
} from '@woocommerce/blocks-checkout';
import { useStoreCart } from '@woocommerce/base-context/hooks';
Expand All @@ -34,8 +33,6 @@ const TotalsFooterItem = ( { currency, values } ) => {
defaultValue: __( 'Total', 'woo-gutenberg-products-block' ),
extensions: cart.extensions,
arg: { cart },
// Only accept strings.
validation: mustBeString,
} );

const parsedTaxValue = parseInt( totalTax, 10 );
Expand Down
Expand Up @@ -24,7 +24,6 @@ import {
} from '@woocommerce/price-format';
import {
__experimentalApplyCheckoutFilter,
mustBeString,
mustContain,
} from '@woocommerce/blocks-checkout';
import Dinero from 'dinero.js';
Expand Down Expand Up @@ -112,7 +111,7 @@ const CartLineItemRow = ( {
const { dispatchStoreEvent } = useStoreEvents();

const productPriceValidation = useCallback(
( value ) => mustBeString( value ) && mustContain( value, '<price/>' ),
( value ) => mustContain( value, '<price/>' ),
[]
);

Expand All @@ -134,7 +133,6 @@ const CartLineItemRow = ( {
defaultValue: initialName,
extensions,
arg,
validation: mustBeString,
} );

const regularAmountSingle = Dinero( {
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/registry/index.ts
Expand Up @@ -74,7 +74,7 @@ export const __experimentalApplyCheckoutFilter = < T >( {
/** Object containing arguments for the filter function. */
arg: CheckoutFilterArguments;
/** Function that needs to return true when the filtered value is passed in order for the filter to be applied. */
validation: ( value: unknown ) => true | Error;
validation?: ( value: T ) => true | Error;
} ): T => {
return useMemo( () => {
const filters = getCheckoutFilters( filterName );
Expand Down
19 changes: 0 additions & 19 deletions packages/checkout/utils/validation/index.ts
Expand Up @@ -3,25 +3,6 @@
*/
import { __, sprintf } from '@wordpress/i18n';

/**
* Checks if value passed is a string, throws an error if not.
*/
export const mustBeString = ( value: unknown ): true | Error => {
if ( typeof value !== 'string' ) {
throw Error(
sprintf(
/* translators: %s is type of value passed */
__(
'Returned value must be a string, you passed "%s"',
'woo-gutenberg-products-block'
),
typeof value
)
);
}
return true;
};

/**
* Checks if value passed contain passed label.
*/
Expand Down

0 comments on commit 1ee393a

Please sign in to comment.