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

Commit

Permalink
Browse files Browse the repository at this point in the history
…ocks into fix/refactor-product-query-e2e-tests
  • Loading branch information
gigitux committed Dec 20, 2022
2 parents 7c36748 + 4ead2e9 commit ad1d7cd
Show file tree
Hide file tree
Showing 91 changed files with 2,190 additions and 1,446 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,3 @@ trim_trailing_whitespace = false
trim_trailing_whitespace = false
indent_style = space
indent_size = 2

[*.md]
indent_style = space
2 changes: 1 addition & 1 deletion assets/js/base/components/block-error-boundary/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface BlockErrorBoundaryProps extends BlockErrorBase {
* Override the default error with a function that takes the error message and returns a React component
*/
renderError?: ( props: RenderErrorProps ) => React.ReactNode;
showErrorMessage?: boolean;
showErrorMessage?: boolean | undefined;
}

export interface DerivedStateReturn {
Expand Down
30 changes: 0 additions & 30 deletions assets/js/base/components/country-input/country-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,6 @@ export const CountryInput = ( {
required={ required }
autoComplete={ autoComplete }
/>
{ autoComplete !== 'off' && (
<input
type="text"
aria-hidden={ true }
autoComplete={ autoComplete }
value={ value }
onChange={ ( event ) => {
const textValue =
event.target.value.toLocaleUpperCase();
const foundOption = options.find(
( option ) =>
( textValue.length !== 2 &&
option.label.toLocaleUpperCase() ===
textValue ) ||
( textValue.length === 2 &&
option.value.toLocaleUpperCase() ===
textValue )
);
onChange( foundOption ? foundOption.value : '' );
} }
style={ {
minHeight: '0',
height: '0',
border: '0',
padding: '0',
position: 'absolute',
} }
tabIndex={ -1 }
/>
) }
</div>
);
};
Expand Down
4 changes: 4 additions & 0 deletions assets/js/base/components/sidebar-layout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
margin: 0 auto $gap;
position: relative;

.wc-block-must-login-prompt {
display: block;
}

.wc-block-components-main {
box-sizing: border-box;
margin: 0;
Expand Down
53 changes: 16 additions & 37 deletions assets/js/base/components/state-input/state-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,44 +88,23 @@ const StateInput = ( {

if ( options.length > 0 ) {
return (
<>
<Combobox
className={ classnames(
className,
'wc-block-components-state-input'
) }
id={ id }
label={ label }
onChange={ onChangeState }
options={ options }
value={ value }
errorMessage={ __(
'Please select a state.',
'woo-gutenberg-products-block'
) }
required={ required }
autoComplete={ autoComplete }
/>
{ autoComplete !== 'off' && (
<input
type="text"
aria-hidden={ true }
autoComplete={ autoComplete }
value={ value }
onChange={ ( event ) =>
onChangeState( event.target.value )
}
style={ {
minHeight: '0',
height: '0',
border: '0',
padding: '0',
position: 'absolute',
} }
tabIndex={ -1 }
/>
<Combobox
className={ classnames(
className,
'wc-block-components-state-input'
) }
</>
id={ id }
label={ label }
onChange={ onChangeState }
options={ options }
value={ value }
errorMessage={ __(
'Please select a state.',
'woo-gutenberg-products-block'
) }
required={ required }
autoComplete={ autoComplete }
/>
);
}

Expand Down
11 changes: 9 additions & 2 deletions assets/js/base/context/event-emit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ export enum responseTypes {
}

export enum noticeContexts {
PAYMENTS = 'wc/payment-area',
EXPRESS_PAYMENTS = 'wc/express-payment-area',
CART = 'wc/cart',
CHECKOUT = 'wc/checkout',
PAYMENTS = 'wc/checkout/payments',
EXPRESS_PAYMENTS = 'wc/checkout/express-payments',
CONTACT_INFORMATION = 'wc/checkout/contact-information',
SHIPPING_ADDRESS = 'wc/checkout/shipping-address',
BILLING_ADDRESS = 'wc/checkout/billing-address',
SHIPPING_METHODS = 'wc/checkout/shipping-methods',
CHECKOUT_ACTIONS = 'wc/checkout/checkout-actions',
}

export interface ResponseType extends Record< string, unknown > {
Expand Down
66 changes: 32 additions & 34 deletions assets/js/base/context/hooks/cart/use-store-cart-coupons.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
/** @typedef { import('@woocommerce/type-defs/hooks').StoreCartCoupon } StoreCartCoupon */

/**
* External dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import {
CART_STORE_KEY as storeKey,
VALIDATION_STORE_KEY,
} from '@woocommerce/block-data';
import { CART_STORE_KEY, VALIDATION_STORE_KEY } from '@woocommerce/block-data';
import { decodeEntities } from '@wordpress/html-entities';
import type { StoreCartCoupon } from '@woocommerce/types';
import { __experimentalApplyCheckoutFilter } from '@woocommerce/blocks-checkout';

/**
* Internal dependencies
Expand All @@ -21,9 +17,6 @@ import { useStoreCart } from './use-store-cart';
* This is a custom hook for loading the Store API /cart/coupons endpoint and an
* action for adding a coupon _to_ the cart.
* See also: https://github.com/woocommerce/woocommerce-gutenberg-products-block/tree/trunk/src/RestApi/StoreApi
*
* @return {StoreCartCoupon} An object exposing data and actions from/for the
* store api /cart/coupons endpoint.
*/
export const useStoreCartCoupons = ( context = '' ): StoreCartCoupon => {
const { cartCoupons, cartIsLoading } = useStoreCart();
Expand All @@ -32,37 +25,35 @@ export const useStoreCartCoupons = ( context = '' ): StoreCartCoupon => {
const { setValidationErrors } = useDispatch( VALIDATION_STORE_KEY );

const {
applyCoupon,
removeCoupon,
isApplyingCoupon,
isRemovingCoupon,
}: Pick<
StoreCartCoupon,
| 'applyCoupon'
| 'removeCoupon'
| 'isApplyingCoupon'
| 'isRemovingCoupon'
| 'receiveApplyingCoupon'
> = useSelect(
( select, { dispatch } ) => {
const store = select( storeKey );
const actions = dispatch( storeKey );
}: Pick< StoreCartCoupon, 'isApplyingCoupon' | 'isRemovingCoupon' > =
useSelect(
( select ) => {
const store = select( CART_STORE_KEY );

return {
isApplyingCoupon: store.isApplyingCoupon(),
isRemovingCoupon: store.isRemovingCoupon(),
};
},
[ createErrorNotice, createNotice ]
);

return {
applyCoupon: actions.applyCoupon,
removeCoupon: actions.removeCoupon,
isApplyingCoupon: store.isApplyingCoupon(),
isRemovingCoupon: store.isRemovingCoupon(),
receiveApplyingCoupon: actions.receiveApplyingCoupon,
};
},
[ createErrorNotice, createNotice ]
);
const { applyCoupon, removeCoupon, receiveApplyingCoupon } =
useDispatch( CART_STORE_KEY );

const applyCouponWithNotices = ( couponCode: string ) => {
applyCoupon( couponCode )
.then( ( result ) => {
if ( result === true ) {
if (
result === true &&
__experimentalApplyCheckoutFilter( {
filterName: 'showApplyCouponNotice',
defaultValue: true,
arg: { couponCode, context },
} )
) {
createNotice(
'info',
sprintf(
Expand Down Expand Up @@ -96,7 +87,14 @@ export const useStoreCartCoupons = ( context = '' ): StoreCartCoupon => {
const removeCouponWithNotices = ( couponCode: string ) => {
removeCoupon( couponCode )
.then( ( result ) => {
if ( result === true ) {
if (
result === true &&
__experimentalApplyCheckoutFilter( {
filterName: 'showRemoveCouponNotice',
defaultValue: true,
arg: { couponCode, context },
} )
) {
createNotice(
'info',
sprintf(
Expand Down
1 change: 0 additions & 1 deletion assets/js/base/context/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export * from './use-store-products';
export * from './use-store-add-to-cart';
export * from './use-customer-data';
export * from './use-checkout-address';
export * from './use-checkout-notices';
export * from './use-checkout-submit';
export * from './use-checkout-extension-data';
export * from './use-validation';
55 changes: 0 additions & 55 deletions assets/js/base/context/hooks/use-checkout-notices.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import {
* Internal dependencies
*/
import { useEventEmitters, reducer as emitReducer } from './event-emit';
import type { emitterCallback } from '../../../event-emit';
import { emitterCallback, noticeContexts } from '../../../event-emit';
import { useStoreEvents } from '../../../hooks/use-store-events';
import { useCheckoutNotices } from '../../../hooks/use-checkout-notices';
import {
getExpressPaymentMethods,
getPaymentMethods,
Expand Down Expand Up @@ -134,11 +133,29 @@ export const CheckoutEventsProvider = ( {
}

const { setValidationErrors } = useDispatch( VALIDATION_STORE_KEY );
const { createErrorNotice } = useDispatch( 'core/notices' );

const { dispatchCheckoutEvent } = useStoreEvents();
const { checkoutNotices, paymentNotices, expressPaymentNotices } =
useCheckoutNotices();
useSelect( ( select ) => {
const { getNotices } = select( 'core/notices' );
const checkoutContexts = Object.values( noticeContexts ).filter(
( context ) =>
context !== noticeContexts.PAYMENTS &&
context !== noticeContexts.EXPRESS_PAYMENTS
);
const allCheckoutNotices = checkoutContexts.reduce(
( acc, context ) => {
return [ ...acc, ...getNotices( context ) ];
},
[]
);
return {
checkoutNotices: allCheckoutNotices,
paymentNotices: getNotices( noticeContexts.PAYMENTS ),
expressPaymentNotices: getNotices(
noticeContexts.EXPRESS_PAYMENTS
),
};
}, [] );

const [ observers, observerDispatch ] = useReducer( emitReducer, {} );
const currentObservers = useRef( observers );
Expand Down Expand Up @@ -186,7 +203,6 @@ export const CheckoutEventsProvider = ( {
}, [
isCheckoutBeforeProcessing,
setValidationErrors,
createErrorNotice,
__internalEmitValidateEvent,
] );

Expand Down Expand Up @@ -224,7 +240,6 @@ export const CheckoutEventsProvider = ( {
isCheckoutBeforeProcessing,
previousStatus,
previousHasError,
createErrorNotice,
checkoutNotices,
expressPaymentNotices,
paymentNotices,
Expand Down
Loading

0 comments on commit ad1d7cd

Please sign in to comment.