Commit Graph

1768 Commits

Author SHA1 Message Date
Alex Florisca b927fcfe80 Remove Notices context 2022-09-28 13:45:42 +01:00
Thomas Roberts 28659ee653 Refactor registration of payment methods and update unit tests for payment data store (https://github.com/woocommerce/woocommerce-blocks/pull/6669)
* Mock getCartTotals

* Change test to use data store instead of context

* Move payment method context test to data store selectors

* Change description of test suite

* Bump commit to trigger tests

* Fix path in test

* update package lock

* Set correct state payment method reducer tests/use correct actions

* Get saved payment methods from store not context

* Mock stores and update tests to allow switching payment methods

* Update tests to get onSubmit from checkoutEventsContext

* Remove cartTotalsLoaded check from payment method initialize check

* Make PaymentMethods test wait until payments initialized

* initialize payment method data store when cart is loaded

* Remove unneeded actions and add initializePaymentMethodDataStore

* Remove check for cart totals loaded in checkPaymentMethods

* Remove updateAvilablePaymentMethods from registry

* Remove unneeded mock

* Remove unused import

* Rename imports to fix eslint errors

* Remove unused imports

* Remove return false from checkPaymentMethods

* Remove unnecessary setPaymentMethodsInitialized call

* Add todo comment to track refactoring opportunity

* Remove savedpayment methods from payment method context and rename it

* Rename payment method data context to payment method events context

* Add tests for setDefaultPaymentMethods

* Optimize the availablePaymentMethods state data

Store only the "name" attribute for now.

* Get list of payment methods from the registry instead of the store

We are using this hook to get some React elements in the payment method
object. So, we are getting the raw data directly from the registry instead
of the store.

* Fix payment state not loading on the Checkout edit page

* Handle checkout edit page case

* Fix infinite loop error on C&C Blocks

* Include @wordpress/redux-routine in transformIgnorePatterns jest config

Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-09-28 13:45:42 +01:00
Thomas Roberts aa9fd66e8e Fix lint errors 2022-09-28 13:45:42 +01:00
Alex Florisca d13d5b3fdd Feature: Data Store Migration - Payments (https://github.com/woocommerce/woocommerce-blocks/pull/6619)
* Move paymentMethodDataProvider into a data store (https://github.com/woocommerce/woocommerce-blocks/pull/6208)

* Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type

* Add default state for PaymentMethod data store

* Add preliminary action types

* Add preliminary action dispatchers

* Create payment method data store

* Add preliminary reducers for payment method data store

* Add preliminary selectors for payment method data store

* Add reducers/actions for registering payment methods

* Export payment method data store key

* Add test for payment method data reducers

* Add shouldSavePaymentMethod selector

* Add store key as constant

* Add more action types for registering and initializing payment methods

* Get active payment method from data store instead of from context

* Add registered methods to default state of payment method data store

* Dispatch name of registered payment method to payment method data store

* Remove setShouldSavePayment from payment method dispatcher and types

* Get payment methods from registry instead of payment context

* Add available payment methods to store

* Add function to check whether payment methods are allowed to be used

* Add selector to check if payments are initialised

* Remove resolvers and add controls to payment method data store

* Change type of payment requirements to string[]

* Turn addRegistered and addRegisteredExpress into generators

This is so we can check each payment method's validity before adding it to the list of available payment methods

* Add action type for setting express payments as initialized

* Only select from available methods in payment method options

* Remove argument from addRegisteredPaymentMethod in payment method registry

* Rename folder and store name to not contain the word data

* Add selectors for express payment methods and their initialisation

* Delete controls again in favour of thunks

* Rename payment-method-data to payment-methdods

* Create new setDefaultPaymentMethod function

This will set the payment method when the cart loads.

* Add CustomerPaymentMethodConfiguration type

* Make getAvailableExpressPaymentMethods return correct data

* Check express methods and normal methods when cart changes

* Add action for setting active express payment methods

* Handle express methods in checkPaymentMethodCanPay

* Hide express payments area if none are available

* Add selector for paymentMethodData

* Add customer data to default state and add selector for it

* Add setPaymentStatus action and reducer case

* Set the default payment method when one isn't selected

* Correct types on getCustomerPaymentMethods

* Set status in data store alongside context status

* Comment out active gateway selection - remove later

* Set status in express payment methods in data store

* Use correct key in payment method data context

* Directly check payment methods from the list in blocks-registry

* Add semicolon to import statement

* Fix payment method data state call

* Get paymentMethodData from store not context

* Fix linting issues

Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
Co-authored-by: Alex Florisca <alex.florisca@automattic.com>

* Rebase on the update/checkout-data-store branch & Fix failed payments (https://github.com/woocommerce/woocommerce-blocks/pull/6587)

* Add checkout data store

* wip on checkout data store

* CheckoutContext now uses the checkout store

* Investigated and removed setting the redirectUrl on the default state

* update extension and address hooks to use checkout data store

* use checkout data store in checkout-processor and use-checkout-button

* trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity

* Remove useCheckoutContext from shipping provider

* Remove isCalculating from state

* Removed useCheckoutContext from lots of places

* Remove useCheckoutContext from checkout-payment-block

* Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block

* add isCart selector and action and update the checkoutstate context

* Fixed redirectUrl bug by using thunks

* Remove dispatchActions from checkout-state

* Change SET_HAS_ERROR action to be neater

* Thomas' feedback

* Tidy up

* Oops, deleted things I shouldn't have

* Typescript

* Fix types

* Fix tests

* Remove isCart

* Update docs and remove unecessary getRedirectUrl() selector

* set correct type for preloadedCheckoutData

* Remove duplicate Address type

* Fix missing addresses from type-defs index

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Revert feedback changes

* REvert feedback formatting

* Update docs formatting

* Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type

* Add default state for PaymentMethod data store

* Add preliminary action types

* Add preliminary action dispatchers

* Create payment method data store

* Add preliminary reducers for payment method data store

* Add preliminary selectors for payment method data store

* Add reducers/actions for registering payment methods

* Export payment method data store key

* Add test for payment method data reducers

* Add shouldSavePaymentMethod selector

* Add store key as constant

* Add more action types for registering and initializing payment methods

* Get active payment method from data store instead of from context

* Add registered methods to default state of payment method data store

* Dispatch name of registered payment method to payment method data store

* Remove setShouldSavePayment from payment method dispatcher and types

* Get payment methods from registry instead of payment context

* Add available payment methods to store

* Add function to check whether payment methods are allowed to be used

* Add selector to check if payments are initialised

* Remove resolvers and add controls to payment method data store

* Change type of payment requirements to string[]

* Turn addRegistered and addRegisteredExpress into generators

This is so we can check each payment method's validity before adding it to the list of available payment methods

* Add action type for setting express payments as initialized

* Only select from available methods in payment method options

* Remove argument from addRegisteredPaymentMethod in payment method registry

* Rename folder and store name to not contain the word data

* Add selectors for express payment methods and their initialisation

* Delete controls again in favour of thunks

* Rename payment-method-data to payment-methdods

* Create new setDefaultPaymentMethod function

This will set the payment method when the cart loads.

* Add CustomerPaymentMethodConfiguration type

* Make getAvailableExpressPaymentMethods return correct data

* Check express methods and normal methods when cart changes

* Add action for setting active express payment methods

* Handle express methods in checkPaymentMethodCanPay

* Hide express payments area if none are available

* Add selector for paymentMethodData

* Add customer data to default state and add selector for it

* Add setPaymentStatus action and reducer case

* Set the default payment method when one isn't selected

* Correct types on getCustomerPaymentMethods

* Set status in data store alongside context status

* Comment out active gateway selection - remove later

* Set status in express payment methods in data store

* Directly check payment methods from the list in blocks-registry

* Add semicolon to import statement

* Fix payment method data state call

* Get paymentMethodData from store not context

* Add addPaymentMethodData action/reducer case

* Update payment method on payment success

* Add 'getCurrentStatus' selector

* Remove the temporary solution

For getting payment method data into the data store

* Prevent the 'success' context action from being dispatched

* Update the "setPaymentStatus" data store action

Accept status as an object instead of string

* Fix the "currentStatus" reducer state update value

* Get payment data into data store

* Set the correct payment status to data store

* Get the success status of payment from data store

* Use store data in the payment dispatchers

Replace the React useReducers action in the payment dispatchers file with
the payment method data store

* Get payment status from data store

* Use data store for the payment error status

* Use payment data store failed status

* Use payment data store for the isFinished status

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>

* Fix merge conflict error

* Set & get the provider's state from our data store instead of React's useReducer (https://github.com/woocommerce/woocommerce-blocks/pull/6588)

* Add checkout data store

* wip on checkout data store

* CheckoutContext now uses the checkout store

* Investigated and removed setting the redirectUrl on the default state

* update extension and address hooks to use checkout data store

* use checkout data store in checkout-processor and use-checkout-button

* trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity

* Remove useCheckoutContext from shipping provider

* Remove isCalculating from state

* Removed useCheckoutContext from lots of places

* Remove useCheckoutContext from checkout-payment-block

* Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block

* add isCart selector and action and update the checkoutstate context

* Fixed redirectUrl bug by using thunks

* Remove dispatchActions from checkout-state

* Change SET_HAS_ERROR action to be neater

* Thomas' feedback

* Tidy up

* Oops, deleted things I shouldn't have

* Typescript

* Fix types

* Fix tests

* Remove isCart

* Update docs and remove unecessary getRedirectUrl() selector

* set correct type for preloadedCheckoutData

* Remove duplicate Address type

* Fix missing addresses from type-defs index

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Revert feedback changes

* REvert feedback formatting

* Update docs formatting

* Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type

* Add default state for PaymentMethod data store

* Add preliminary action types

* Add preliminary action dispatchers

* Create payment method data store

* Add preliminary reducers for payment method data store

* Add preliminary selectors for payment method data store

* Add reducers/actions for registering payment methods

* Export payment method data store key

* Add test for payment method data reducers

* Add shouldSavePaymentMethod selector

* Add store key as constant

* Add more action types for registering and initializing payment methods

* Get active payment method from data store instead of from context

* Add registered methods to default state of payment method data store

* Dispatch name of registered payment method to payment method data store

* Remove setShouldSavePayment from payment method dispatcher and types

* Get payment methods from registry instead of payment context

* Add available payment methods to store

* Add function to check whether payment methods are allowed to be used

* Add selector to check if payments are initialised

* Remove resolvers and add controls to payment method data store

* Change type of payment requirements to string[]

* Turn addRegistered and addRegisteredExpress into generators

This is so we can check each payment method's validity before adding it to the list of available payment methods

* Add action type for setting express payments as initialized

* Only select from available methods in payment method options

* Remove argument from addRegisteredPaymentMethod in payment method registry

* Rename folder and store name to not contain the word data

* Add selectors for express payment methods and their initialisation

* Delete controls again in favour of thunks

* Rename payment-method-data to payment-methdods

* Create new setDefaultPaymentMethod function

This will set the payment method when the cart loads.

* Add CustomerPaymentMethodConfiguration type

* Make getAvailableExpressPaymentMethods return correct data

* Check express methods and normal methods when cart changes

* Add action for setting active express payment methods

* Handle express methods in checkPaymentMethodCanPay

* Hide express payments area if none are available

* Add selector for paymentMethodData

* Add customer data to default state and add selector for it

* Add setPaymentStatus action and reducer case

* Set the default payment method when one isn't selected

* Correct types on getCustomerPaymentMethods

* Set status in data store alongside context status

* Comment out active gateway selection - remove later

* Set status in express payment methods in data store

* Directly check payment methods from the list in blocks-registry

* Add semicolon to import statement

* Fix payment method data state call

* Get paymentMethodData from store not context

* Add addPaymentMethodData action/reducer case

* Update payment method on payment success

* Add 'getCurrentStatus' selector

* Remove the temporary solution

For getting payment method data into the data store

* Prevent the 'success' context action from being dispatched

* Update the "setPaymentStatus" data store action

Accept status as an object instead of string

* Fix the "currentStatus" reducer state update value

* Get payment data into data store

* Set the correct payment status to data store

* Get the success status of payment from data store

* Use store data in the payment dispatchers

Replace the React useReducers action in the payment dispatchers file with
the payment method data store

* Get payment status from data store

* Use data store for the payment error status

* Use payment data store failed status

* Use payment data store for the isFinished status

* Update the setPaymentStatus argument

* Set up setRegisteredPaymentMethods in data store

* Use the data store version of the registeredPaymentMethods

* Fix the default state type of the registeredPaymentMethods

* Set up setRegisteredExpressPaymentMethod in data store

* Use the data version of the registred express payment methods

* Set the correct action type for removing payment methods

* Fix default state express payment methods type

* Use the store data version of activePaymentMethod

* Use setActivePaymentMethod in the dispatchers file

And refactor code

* Update payment status arguments for express payment methods

* Use paymentMethodData from the data store

* Use payment method's errorMessage from data store

* Update paymentMethods list in data store reducer

* Replace remaining payment context data with data store

* Clean up payment method context file

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>

* Get payment method data directly from the data store instead of the usePaymentMethodDataContext hook (https://github.com/woocommerce/woocommerce-blocks/pull/6589)

* Add checkout data store

* wip on checkout data store

* CheckoutContext now uses the checkout store

* Investigated and removed setting the redirectUrl on the default state

* update extension and address hooks to use checkout data store

* use checkout data store in checkout-processor and use-checkout-button

* trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity

* Remove useCheckoutContext from shipping provider

* Remove isCalculating from state

* Removed useCheckoutContext from lots of places

* Remove useCheckoutContext from checkout-payment-block

* Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block

* add isCart selector and action and update the checkoutstate context

* Fixed redirectUrl bug by using thunks

* Remove dispatchActions from checkout-state

* Change SET_HAS_ERROR action to be neater

* Thomas' feedback

* Tidy up

* Oops, deleted things I shouldn't have

* Typescript

* Fix types

* Fix tests

* Remove isCart

* Update docs and remove unecessary getRedirectUrl() selector

* set correct type for preloadedCheckoutData

* Remove duplicate Address type

* Fix missing addresses from type-defs index

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Revert feedback changes

* REvert feedback formatting

* Update docs formatting

* Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type

* Add default state for PaymentMethod data store

* Add preliminary action types

* Add preliminary action dispatchers

* Create payment method data store

* Add preliminary reducers for payment method data store

* Add preliminary selectors for payment method data store

* Add reducers/actions for registering payment methods

* Export payment method data store key

* Add test for payment method data reducers

* Add shouldSavePaymentMethod selector

* Add store key as constant

* Add more action types for registering and initializing payment methods

* Get active payment method from data store instead of from context

* Add registered methods to default state of payment method data store

* Dispatch name of registered payment method to payment method data store

* Remove setShouldSavePayment from payment method dispatcher and types

* Get payment methods from registry instead of payment context

* Add available payment methods to store

* Add function to check whether payment methods are allowed to be used

* Add selector to check if payments are initialised

* Remove resolvers and add controls to payment method data store

* Change type of payment requirements to string[]

* Turn addRegistered and addRegisteredExpress into generators

This is so we can check each payment method's validity before adding it to the list of available payment methods

* Add action type for setting express payments as initialized

* Only select from available methods in payment method options

* Remove argument from addRegisteredPaymentMethod in payment method registry

* Rename folder and store name to not contain the word data

* Add selectors for express payment methods and their initialisation

* Delete controls again in favour of thunks

* Rename payment-method-data to payment-methdods

* Create new setDefaultPaymentMethod function

This will set the payment method when the cart loads.

* Add CustomerPaymentMethodConfiguration type

* Make getAvailableExpressPaymentMethods return correct data

* Check express methods and normal methods when cart changes

* Add action for setting active express payment methods

* Handle express methods in checkPaymentMethodCanPay

* Hide express payments area if none are available

* Add selector for paymentMethodData

* Add customer data to default state and add selector for it

* Add setPaymentStatus action and reducer case

* Set the default payment method when one isn't selected

* Correct types on getCustomerPaymentMethods

* Set status in data store alongside context status

* Comment out active gateway selection - remove later

* Set status in express payment methods in data store

* Directly check payment methods from the list in blocks-registry

* Add semicolon to import statement

* Fix payment method data state call

* Get paymentMethodData from store not context

* Add addPaymentMethodData action/reducer case

* Update payment method on payment success

* Add 'getCurrentStatus' selector

* Remove the temporary solution

For getting payment method data into the data store

* Prevent the 'success' context action from being dispatched

* Update the "setPaymentStatus" data store action

Accept status as an object instead of string

* Fix the "currentStatus" reducer state update value

* Get payment data into data store

* Set the correct payment status to data store

* Get the success status of payment from data store

* Use store data in the payment dispatchers

Replace the React useReducers action in the payment dispatchers file with
the payment method data store

* Get payment status from data store

* Use data store for the payment error status

* Use payment data store failed status

* Use payment data store for the isFinished status

* Update the setPaymentStatus argument

* Set up setRegisteredPaymentMethods in data store

* Use the data store version of the registeredPaymentMethods

* Fix the default state type of the registeredPaymentMethods

* Set up setRegisteredExpressPaymentMethod in data store

* Use the data version of the registred express payment methods

* Set the correct action type for removing payment methods

* Fix default state express payment methods type

* Use the store data version of activePaymentMethod

* Use setActivePaymentMethod in the dispatchers file

And refactor code

* Update payment status arguments for express payment methods

* Use paymentMethodData from the data store

* Use payment method's errorMessage from data store

* Update paymentMethods list in data store reducer

* Replace remaining payment context data with data store

* Clean up payment method context file

* Get payment method state from data store in the checkout submit hook

* Copy types.ts file into the payment data store folder

* Fix isExpressPaymentMethodActive selector

* Move the entire currentStatus into the data store

* Replace the payment context state with the data store

* Fix getActiveSavedToken & clean up the context file

* Use the accutrate name of the "createErrorNotice"

* Update the payment method data store key import

* Diable unused state from the context

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>

* Refactor the payment method data store & context (https://github.com/woocommerce/woocommerce-blocks/pull/6607)

* Add checkout data store

* wip on checkout data store

* CheckoutContext now uses the checkout store

* Investigated and removed setting the redirectUrl on the default state

* update extension and address hooks to use checkout data store

* use checkout data store in checkout-processor and use-checkout-button

* trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity

* Remove useCheckoutContext from shipping provider

* Remove isCalculating from state

* Removed useCheckoutContext from lots of places

* Remove useCheckoutContext from checkout-payment-block

* Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block

* add isCart selector and action and update the checkoutstate context

* Fixed redirectUrl bug by using thunks

* Remove dispatchActions from checkout-state

* Change SET_HAS_ERROR action to be neater

* Thomas' feedback

* Tidy up

* Oops, deleted things I shouldn't have

* Typescript

* Fix types

* Fix tests

* Remove isCart

* Update docs and remove unecessary getRedirectUrl() selector

* set correct type for preloadedCheckoutData

* Remove duplicate Address type

* Fix missing addresses from type-defs index

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Revert feedback changes

* REvert feedback formatting

* Update docs formatting

* Fix typographical error on LegacyRegisterExpressPaymentMethodFunction type

* Add default state for PaymentMethod data store

* Add preliminary action types

* Add preliminary action dispatchers

* Create payment method data store

* Add preliminary reducers for payment method data store

* Add preliminary selectors for payment method data store

* Add reducers/actions for registering payment methods

* Export payment method data store key

* Add test for payment method data reducers

* Add shouldSavePaymentMethod selector

* Add store key as constant

* Add more action types for registering and initializing payment methods

* Get active payment method from data store instead of from context

* Add registered methods to default state of payment method data store

* Dispatch name of registered payment method to payment method data store

* Remove setShouldSavePayment from payment method dispatcher and types

* Get payment methods from registry instead of payment context

* Add available payment methods to store

* Add function to check whether payment methods are allowed to be used

* Add selector to check if payments are initialised

* Remove resolvers and add controls to payment method data store

* Change type of payment requirements to string[]

* Turn addRegistered and addRegisteredExpress into generators

This is so we can check each payment method's validity before adding it to the list of available payment methods

* Add action type for setting express payments as initialized

* Only select from available methods in payment method options

* Remove argument from addRegisteredPaymentMethod in payment method registry

* Rename folder and store name to not contain the word data

* Add selectors for express payment methods and their initialisation

* Delete controls again in favour of thunks

* Rename payment-method-data to payment-methdods

* Create new setDefaultPaymentMethod function

This will set the payment method when the cart loads.

* Add CustomerPaymentMethodConfiguration type

* Make getAvailableExpressPaymentMethods return correct data

* Check express methods and normal methods when cart changes

* Add action for setting active express payment methods

* Handle express methods in checkPaymentMethodCanPay

* Hide express payments area if none are available

* Add selector for paymentMethodData

* Add customer data to default state and add selector for it

* Add setPaymentStatus action and reducer case

* Set the default payment method when one isn't selected

* Correct types on getCustomerPaymentMethods

* Set status in data store alongside context status

* Comment out active gateway selection - remove later

* Set status in express payment methods in data store

* Directly check payment methods from the list in blocks-registry

* Add semicolon to import statement

* Fix payment method data state call

* Get paymentMethodData from store not context

* Add addPaymentMethodData action/reducer case

* Update payment method on payment success

* Add 'getCurrentStatus' selector

* Remove the temporary solution

For getting payment method data into the data store

* Prevent the 'success' context action from being dispatched

* Update the "setPaymentStatus" data store action

Accept status as an object instead of string

* Fix the "currentStatus" reducer state update value

* Get payment data into data store

* Set the correct payment status to data store

* Get the success status of payment from data store

* Use store data in the payment dispatchers

Replace the React useReducers action in the payment dispatchers file with
the payment method data store

* Get payment status from data store

* Use data store for the payment error status

* Use payment data store failed status

* Use payment data store for the isFinished status

* Update the setPaymentStatus argument

* Set up setRegisteredPaymentMethods in data store

* Use the data store version of the registeredPaymentMethods

* Fix the default state type of the registeredPaymentMethods

* Set up setRegisteredExpressPaymentMethod in data store

* Use the data version of the registred express payment methods

* Set the correct action type for removing payment methods

* Fix default state express payment methods type

* Use the store data version of activePaymentMethod

* Use setActivePaymentMethod in the dispatchers file

And refactor code

* Update payment status arguments for express payment methods

* Use paymentMethodData from the data store

* Use payment method's errorMessage from data store

* Update paymentMethods list in data store reducer

* Replace remaining payment context data with data store

* Clean up payment method context file

* Get payment method state from data store in the checkout submit hook

* Copy types.ts file into the payment data store folder

* Fix isExpressPaymentMethodActive selector

* Move the entire currentStatus into the data store

* Replace the payment context state with the data store

* Fix getActiveSavedToken & clean up the context file

* Use the accutrate name of the "createErrorNotice"

* Update the payment method data store key import

* Diable unused state from the context

* Get enabled customer payment methods using data store selector

* Remove remaining useReducer action from the dispatchers file

* Update types and remove unused vars

* Remove the payment method dispatchers hook

* Refactor & clean up (remove unused files)

* Remove commented line from payment methods types

* Move event emitter into thunks

Co-authored-by: Alex Florisca <alex.florisca@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>

* Remove checkout-state after merge conflicts

* Fix linting errors

* Move types to types.ts

* Move default states into respective store folders

* Fix types and add comment

* Move setExpressPaymentError to payment-methods store

* fix express payment methods not showing up

* Check if payment method is active from the state

* Add comments

* Remove commented out code in payment method data context

* Display an error in the check-payment-methods directly from data store

* Remove use-emit-response hook and move utils in event-emit/utils.ts

* Use correct action property to remove payment methods

* Fix formatting

* Only try to initialize payment methods when cart is done loading

* Add function to order payment methods from server

* Add payment methods in the correct order

* Prevent adding registered payment methods before cart is ready

* Ensure payment methods get removed from state when deregistered

* Reorder setting default payment methods to add customer methods first

* Get customer methods from store not context

* Remove error from payment-method state and associated selectors

* Remove use-payment-method-registration and update the payment method state to remove the duplicated registeredPaymentMethods

* Remove errorMessage from payment-methods store

* Rename customerPaymentMethods -> savedPaymentMethods

* Order payment methods when validating

* Refactor payment-methods.js

* Fix "Payment methods not set in editor" woocommerce/woocommerce-blocks#6655 bug

We never get to load the payment methods object in the editor mode
because there are no cart totals to load.

* Initialize payment methods when available payments are loaded

* Remove duplicate code

* Fix data store state mutation anti-pattern

A Redux rule is to never mutate the state in a reducer to avoid any unexpected results

* Set availablePaymentMethods to the paymentMethods object

Instead of its keys. We can get the keys using "Object.keys".

* Use the available ordered payment methods

The `getPaymentMethods` & `getExpressPaymentMethods` may include unordored
& unavailable payment methods.

* Get the correct value from the emit event response

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2022-09-28 13:45:42 +01:00
Tarun Vijwani 4de3bdb0f1 Convert validation context to data store (https://github.com/woocommerce/woocommerce-blocks/pull/6402)
* Add validation reducers, actions, and action types

* Add selector for getValidationErrors

* Export store key and register store

* Export validation store key

* Move TextInput files to checkout package

* Export ValidatedTextInput from blocks-checkout package

* Update imports of ValidatedTextInput to reflect new location

* Use the validation wp-data store for showing error messages

* Export getValidationError in checkout package

* Move validation store to checkout package

* Move ValidationInputError to blocks-checkout package

* Only export "exposedSelectors" from validation

* Convert validation context to data store

* Fixed linting error

* Fixed linting error

* Change the validation selectors to return a function

* Convert reducer and selectors to TS

* Remove superfluous comments and improve test titles

* Test to ensure visible errors remain visible

* Make test for hasValidationErrors more robust

* Augment the wp-data module to include our selectors and actions

* Removed unused `exposedSelectors` variable

* Remove TS error because of `instanceId` on props

* Remove unnecessary as const

* Use function returned by getValidationError

* Use correct selector/action names now context has been decoupled

* hide validation error when input value changes

* Add correct aria-describedBy now we can get error id from store

* Clear validation error from store when component unmounts

* Clear validation error if input is valid

* convert ValidationInputError to TS and get correct id/error from store

* Ensure checkout block doesn't break when there are no errors

* Get validation data from the store instead of context

* Update country input to remove validation context

* Move validation store out of checkout package

* Move TextInput and ValidationInputError back out of the checkout package

* Remove duplicate internal styles comment

* Remove exports that no longer exist

* Get validation store key from block-data

* Make attribute-select-control use validation data store

* Export FieldValidationStatus type

* Make combobox use validation store not context

* Make Address use validation store not context

* Make Address use validation store not context

* Use hasValidationErrors selector as a function in shipping calculator

* Remove validation context from coupon story

* Import VALIDATION_STORE_KEY from correct location

* Stop coupon story from erroring

* Update useStoreCartCoupons to use validation store not context

* Make TotalsCoupon use validation store instead of context

* Make AddToCartFormContext use validation store not context

* Remove ValidationContext

* Import FieldValidationStatus from correct location

* Import ValidatedTextInput and ValidatedTextInput from correct location

* Remove ValidationContextProvider

* Update components to use validation store not context

* Update useValidation to use the data store

* Replace the validation context in checkout-events file

* Use the re-mapped path for the store key import

* Use "register" instead of the deprecated "registerStore"

* Fix import error of the "FieldValidationStatus" type

* Use TS instead of React's "PropTypes"

* Fix the type of "ValidationInputError" in the "payment-method-interface"

* Fix error not showing on the first place order click bug

We were mutating the state in the reducer, which prevented re-rendering
on state change

* Fix state mutation issue in the Validation reducer

Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-09-28 13:45:42 +01:00
Alex Florisca 22f61cf4d9 Fixed missing lint error 2022-09-28 13:45:42 +01:00
Alex Florisca e2c495d7ac Fix lint issues 2022-09-28 13:45:42 +01:00
Alex Florisca 015291ccf3 Move checkout state code into thunks and rename `CheckoutState` context to `CheckoutEvents` (https://github.com/woocommerce/woocommerce-blocks/pull/6455)
* Add checkout data store

* wip on checkout data store

* CheckoutContext now uses the checkout store

* Investigated and removed setting the redirectUrl on the default state

* update extension and address hooks to use checkout data store

* use checkout data store in checkout-processor and use-checkout-button

* trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity

* Remove useCheckoutContext from shipping provider

* Remove isCalculating from state

* Removed useCheckoutContext from lots of places

* Remove useCheckoutContext from checkout-payment-block

* Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block

* add isCart selector and action and update the checkoutstate context

* Fixed redirectUrl bug by using thunks

* Remove dispatchActions from checkout-state

* Change SET_HAS_ERROR action to be neater

* Thomas' feedback

* Tidy up

* Oops, deleted things I shouldn't have

* Typescript

* Fix types

* Fix tests

* Remove isCart

* Update docs and remove unecessary getRedirectUrl() selector

* validate event emitter button

* Added thunks in a separate file

* Call thunks from checkout-state

* Checkout logic tested and working

* Remove dependency injection as much as poss, tidy up and fix some TS errors

* Fix types in thunks.ts

* Fixed some ts errors

* WIP

* Fixed bug

* Shift side effects from checkout-state to checkout-processor

* Revert "Shift side effects from checkout-state to checkout-processor"

This reverts commit 059533da4eb34f9982f66cd4adacc7b2c24f939f.

* Rename CheckoutState to CheckoutEvents

* Move status check outside the thunk

* remove duplicate EVENTS constant

* remove temp buttons

* Remove console logs

* Augment @wordpress/data package with our new store types

* Add correct type for CheckoutAction

* Remove createErrorNotice arg from runCheckoutAfterProcessingWithErrorObservers

* Remove createErrorNotice from emit event types

* Use type keyword when importing types

* Add correct types for dispatch and select in thunks

* Update wordpress/data types

* Replace store creation with new preferred method

* Set correct action type on reducer

* Remove unnecessary async from thunk

* add CHECKOUT_ prefix to checkout events again

* export EVENTS with eveything else in checkout0-events/event-emit

* Remove duplicate SelectFromMap and TailParameters

* Updated type for paymentStatus

* TODO remove wp/data experimental thunks

* Remove `setCustomerId` from events and `processCheckoutResponseHeaders` (https://github.com/woocommerce/woocommerce-blocks/pull/6586)

* Prevent passing dispatch, instead get actions direct from store

* Get setCustomerId from the store instead of passing it to processCheckoutResponseHeaders

* Revert "Prevent passing dispatch, instead get actions direct from store"

This reverts commit 4479a2ef5599d9c8d99c3629616b3d662210fc08.

* Auto stash before revert of "Prevent passing dispatch, instead get actions direct from store"

* Remove duplicate dispatch

* Fix unit tests

Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-09-28 13:45:42 +01:00
Alex Florisca 3630b7b03e Convert checkout context to data store - part 1 (https://github.com/woocommerce/woocommerce-blocks/pull/6232)
* Add checkout data store

* wip on checkout data store

* CheckoutContext now uses the checkout store

* Investigated and removed setting the redirectUrl on the default state

* update extension and address hooks to use checkout data store

* use checkout data store in checkout-processor and use-checkout-button

* trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity

* Remove useCheckoutContext from shipping provider

* Remove isCalculating from state

* Removed useCheckoutContext from lots of places

* Remove useCheckoutContext from checkout-payment-block

* Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block

* add isCart selector and action and update the checkoutstate context

* Fixed redirectUrl bug by using thunks

* Remove dispatchActions from checkout-state

* Change SET_HAS_ERROR action to be neater

* Thomas' feedback

* Tidy up

* Oops, deleted things I shouldn't have

* Typescript

* Fix types

* Fix tests

* Remove isCart

* Update docs and remove unecessary getRedirectUrl() selector

* set correct type for preloadedCheckoutData

* Remove duplicate Address type

* Fix missing addresses from type-defs index

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update docs/block-client-apis/checkout/checkout-api.md

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Revert feedback changes

* REvert feedback formatting

* Update docs formatting

* Delete empty types.ts file

* remove merge conflict from docs

* Correct linting in docs

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-09-28 13:45:42 +01:00
Luigi Teschio 3732363ba6 Add to the Product Button block the support for the Product Query block (https://github.com/woocommerce/woocommerce-blocks/pull/6948)
* Adds to the Product Image Block the support for the Product Query Block

Adds to the Product Image Block the support for the Product Query Block woocommerce/woocommerce-blocks#6911

* use shared config

* use shared config

* use shared config

* Add to the Product Button Block the support for the Product Query Block

* Add to the Product Image Block the support for the Product Query Block

* fix lint errors

* address feedback

* set grid view and font-size L as default
2022-09-28 10:54:38 +02:00
Manish Menaria ac064775f4 Fix not enough margin for Filter blocks woocommerce/woocommerce-blocks#7018 (https://github.com/woocommerce/woocommerce-blocks/pull/7226) 2022-09-27 12:48:06 +05:30
Niels Lange 9678673497 Allow rendering HTML in shipping package names (https://github.com/woocommerce/woocommerce-blocks/pull/7147)
* Allow renderiung HTML in shipping package names

* Sanitize HTML to render

* Create reusable util sanitizeHTML

* Solve TS error

* Remove __experimentalApplyCheckoutFilter
2022-09-26 23:16:44 +07:00
Hsing-yu Flowers c2c639dee1 Sanitize store notices html (https://github.com/woocommerce/woocommerce-blocks/pull/7145)
Sanitizing the merchant store link in the error message added in WooPay when in some
cases the customer could run into an issue where we need to tell them an error occurred
and they have to go back to the merchant store and re-initialize WooPay to fix it.

Because previously we were only expecting strings, the text was not sanitized.
2022-09-23 20:48:28 +02:00
Lucio Giannotta d174051787 Refactor Product Query to use the latest Gutenberg APIs (https://github.com/woocommerce/woocommerce-blocks/pull/7169)
* Refactor Product Query to use the latest Gutenberg APIs

As we worked with Gutenberg folks in WordPress/gutenbergwoocommerce/woocommerce-blocks#43590,
WordPress/gutenbergwoocommerce/woocommerce-blocks#43632 and WordPress/gutenbergwoocommerce/woocommerce-blocks#44093 we have
created a standard API that could be used for our use-case. This
PR refactors our WIP experimental work to use that standardized API.
2022-09-23 15:07:44 +02:00
Niels Lange 690ccb5191 Remove experimental flag from Cross-Sells block (https://github.com/woocommerce/woocommerce-blocks/pull/7188)
* Remove experimental flag from Cross-Sells block

* Remove experimental flag from Cross-Sells block

* Remove experimental flag from woocommerce/cart-cross-sells-products-block
2022-09-22 12:28:55 +07:00
Alex Florisca 79b1d4a38a Revert "Add static class name for product-details (https://github.com/woocommerce/woocommerce-blocks/pull/6914)" (https://github.com/woocommerce/woocommerce-blocks/pull/7191)
This reverts commit d6d94ae622.
2022-09-21 15:20:00 +01:00
Niels Lange 3d55668983 Create Cross-Sells product list (https://github.com/woocommerce/woocommerce-blocks/pull/6645)
* Create Cross-Sells product list

* Show “Read more” button for out-of-stock cross-sells products

* Update assets/js/blocks/cart/inner-blocks/cart-cross-sells-products/block.tsx

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Update assets/js/blocks/cart/cart-cross-sells-product-list/index.tsx

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>

* Remove obsolete isLoading and placeholderRows

* Fix TS errors

* Rename crossSellsProduct to product

* Fix critical error

* Lock “Cart Cross-Sells products” inner block

* Update assets/js/blocks/cart/inner-blocks/cart-cross-sells-products/block.json

Co-authored-by: Saad Tarhi <saad.trh@gmail.com>

* Prevent moving of the Cross-Sells block

Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-09-21 13:04:15 +07:00
Paulo Arromba 8a5dd65bc1 fix: Markup is visible in checkout error notices (https://github.com/woocommerce/woocommerce-blocks/pull/6800)
* Enabled __unstableHTML hidden option for HTML rendering within notices.

* Fixed margin-bottom for HTML notice content

* Fixed margin-top for HTML notice content

* Attempt to fix a broken e2e test
2022-09-20 16:54:25 +01:00
Niels Lange 7bd48074fb Prevent Express Checkout block from being cut off (https://github.com/woocommerce/woocommerce-blocks/pull/7152)
* Prevent Express Checkout block from being cut off

* Prevent step numbers from being cut off in editor
2022-09-20 17:45:20 +07:00
Tarun Vijwani 4d8cc8d751 Fix: Inner blocks control position for Cart Block (https://github.com/woocommerce/woocommerce-blocks/pull/6973) 2022-09-16 11:32:46 +05:30
Albert Juhé Lluveras 87e1748811 Make chevron clickable in Filter by Product block input (https://github.com/woocommerce/woocommerce-blocks/pull/7139)
* Make chevron clickable in Filter by Product block

* Make sure the chevron is vertically centered
2022-09-15 12:39:34 +02:00
Albert Juhé Lluveras 8d03ad4f4f Remove unused CSS selectors from Filter blocks (https://github.com/woocommerce/woocommerce-blocks/pull/7150) 2022-09-14 09:47:50 +02:00
Albert Juhé Lluveras 16feccdd74 Fix invisible Reset filter button in some themes (https://github.com/woocommerce/woocommerce-blocks/pull/7111) 2022-09-13 09:32:11 +02:00
Albert Juhé Lluveras 798fdc2107 Fix pills in the Filter by Attribute block dropdown overlapping with the chevron (second attempt) (https://github.com/woocommerce/woocommerce-blocks/pull/7112) 2022-09-13 09:31:51 +02:00
Lucio Giannotta 5dd05d7ab2 Improve public-facing texts and labels (https://github.com/woocommerce/woocommerce-blocks/pull/7045)
We noticed that oftentimes our labels and text tend to be overly
technical or unclear. We decided to do a bulk pass to improve
the readability to non-technical users.
2022-09-12 10:39:26 +02:00
Niels Lange 2f52565c75 Correct broken *.md links (https://github.com/woocommerce/woocommerce-blocks/pull/7108) 2022-09-12 11:29:24 +07:00
Daniel W. Robert 252caccb82 Featured Items: Remove inline style defaults for color options (https://github.com/woocommerce/woocommerce-blocks/pull/7036)
* Remove inline style defaults for color options.

This replaces the inline style with an added editor-specific styling
with slightly more specificity - but not too much to where it overrides
the Site Editor.

* Remove additional styles from editor stylesheet.

These styles are meant to apply to both the frontend and the editor. The
ruleset was originally added to the editor stylesheet to add an
additional layer of specificity but it was decided that this is
unnecessary.
2022-09-09 13:15:19 -04:00
Daniel W. Robert 32bebd381e Update Active Filters "remove filter" icon to use Icon component (https://github.com/woocommerce/woocommerce-blocks/pull/7035)
* Update "remove filter" icon to use Icon component.

To be consistent with the button icon used on the Chips view, this
replaces the native svg element used in the List view with the same
Icon component from core.

* Add proper margin to active filters by price list.

There is currently no top margin when the active filters contain a price
filter in the list view. This is because the filters only contain a
range and do not render a child list.

This update will target that price filter item and add a top margin that
is consistent with the other active filters.
2022-09-09 11:06:42 -04:00
Alba Rincón cc0f9906d2 Add Apply button placeholders to filters and adjust title margins (https://github.com/woocommerce/woocommerce-blocks/pull/7077)
* Adjust filter titles margins

* Show the Apply button placeholder and adjust title margins

* Add placeholder for the Apply button on filter by price

* Add placeholder for the Apply button on filter by attr

* Update stock filter snapshot

* Move the apply button placeholder to inside the FilterSubmitButton component

* Fix the placeholder button height

* Fix apply button on editor

* Change loading class to be is-loading
2022-09-09 13:28:04 +02:00
Tom Cafferkey dd11b23bef Active Filters Loading Placeholders (https://github.com/woocommerce/woocommerce-blocks/pull/7083)
* Active Filters Loading Placeholders

* Use flexbox for active filters loading placeholders

* Clear all placeholder loading styles

* Ensure active filters which arent attribute filters render null when in a loading state

* Refactor loading placeholders and state setting

* Add useIsMounted to shared hooks and check productAttributes only when mounted

* Add componentHasMounted to useMemo deps

* Check URL for attribute filter hint

* Check URL for attribute filter hint

* Remove border-radius from placeholder for clear all button

* Fix filter loading when no filters are active on shop page
2022-09-09 11:59:29 +01:00
Albert Juhé Lluveras 380f270975 Make Active filters texts bigger (https://github.com/woocommerce/woocommerce-blocks/pull/7087) 2022-09-09 09:53:27 +02:00
Albert Juhé Lluveras 4b6a5bf997 Fix remove button alignment in Filter by Attribute block (https://github.com/woocommerce/woocommerce-blocks/pull/7088) 2022-09-08 15:38:20 +02:00
Alba Rincón 9f0d1cd86e Compare count with null to avoid rendering a 0 when count is 0 (https://github.com/woocommerce/woocommerce-blocks/pull/7073) 2022-09-08 10:41:11 +02:00
Alba Rincón a15ffff043 Update `filter by attribute` skeleton design (https://github.com/woocommerce/woocommerce-blocks/pull/6990)
* Update filter by attribute skeleton design

* Update filter by attribute skeleton design

* Start using the FilterTitlePlaceholder

* Fix title animation

* Show two placeholder lines on checkboxes

* Fix dropdown border

* Fix gap

* Fix border radius for dropdown

* Don't show placeholder when changing other filters

* Improve filter title margins
2022-09-06 15:17:11 +02:00
Tom Cafferkey cf9325fc07 Fix corrupt Classic Template placeholders for specific products. (https://github.com/woocommerce/woocommerce-blocks/pull/7033)
* If user has created a template for a specific product, find the closest matching template details

* Move Classic Template functions into Utils file and refactor function for specific template names

* Classic Template utils refactor and unit tests
2022-09-06 10:52:33 +01:00
Alba Rincón f141a75acc Update `filter by price` skeleton design (https://github.com/woocommerce/woocommerce-blocks/pull/6997)
* Update filter by price skeleton design

* Improve skeleton colors

* Update skeleton when no apply button

* Update skeleton with apply button

* Avoid showing a very wide placeholder when the filter title is very long

* Start using the FilterTitlePlaceholder component for the placeholder

* Add comment to isUpdating

* Remove unneeded styles

* Fix title animation
2022-09-02 15:52:52 +02:00
Alba Rincón 70cbc31332 Fix pills in the `Filter by Attribute` block dropdown overlapping with the chevron (https://github.com/woocommerce/woocommerce-blocks/pull/7039)
* Avoid chevron overlap

* Improve input width calculation
2022-09-02 12:57:58 +02:00
Luigi Teschio 3ea46e426a Add to the Product Image block the support for the Product Query block (https://github.com/woocommerce/woocommerce-blocks/pull/6911)
* Adds to the Product Image Block the support for the Product Query Block

Adds to the Product Image Block the support for the Product Query Block woocommerce/woocommerce-blocks#6911

* Add to the Product Image Block the support for the Product Query Block

* address feedback

* set grid view and font-size L as default
2022-09-01 15:13:19 +02:00
Daniel W. Robert 6b251cc222 Remove __experimentalDuotone from block.json. (https://github.com/woocommerce/woocommerce-blocks/pull/7000)
The __experimentalDuotone Supports property in the block.json files were
preventing the Global Styles from being applied in the Editor.

Removing them remedies the issue.

This also adds a Schema property to improve development in supported
editors. See
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#benefits-using-the-metadata-file.
2022-08-31 13:03:21 -04:00
Tom Cafferkey 89cdf7897a Set default orderby to popularity (https://github.com/woocommerce/woocommerce-blocks/pull/7025) 2022-08-31 12:38:48 +01:00
Alba Rincón 3421857599 Fix stock filter placeholder (https://github.com/woocommerce/woocommerce-blocks/pull/7009)
* Set max-height to avoid showing a big placeholder on longer titles

* Avoid showing placeholder when no there are no products

* Extract the placeholder to a separate component

* Adjust width

* Adjust border radius

* Pass the title to adjust the placeholder width/height

* Rename component
2022-08-31 10:43:26 +02:00
Alba Rincón 1e488287ed Update `filter by stock` skeleton design (https://github.com/woocommerce/woocommerce-blocks/pull/6996)
* Update filter by stock skeleton design

* Show skeleton only when is loading, otherwise it will show the loading state also after clicking on an option
2022-08-30 09:32:30 +02:00
Alex Florisca d6d94ae622 Add static class name for product-details (https://github.com/woocommerce/woocommerce-blocks/pull/6914)
* Add a static class name for the product details item instead of the translatable string

* Update Jest snapshot

Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-29 11:46:33 +01:00
Alba Rincón aa214f4d28 Remove the price filter setting label style (https://github.com/woocommerce/woocommerce-blocks/pull/6994) 2022-08-29 10:41:25 +02:00
Seghir Nadir 42f3ffefc9 Turn current page into the default Cart/Checkout page (https://github.com/woocommerce/woocommerce-blocks/pull/6867)
* Add default page notice

* show notice all inner blocks

* support flow when page isnt saved

* switch from where we get the current post id

* update lock

* fix types

* update logic to support cart as well

* fix package.json

* update design and move away from wc.data

* restore notice

* handle older versions of WooCommerce

* fix package lock

* fix typo
2022-08-29 09:35:05 +01:00
Daniel W. Robert b2f98c2f51 Layout Updates to Active Filters Block (https://github.com/woocommerce/woocommerce-blocks/pull/6905)
* Reverse ordter of filter item name and close btn.

* Update layout & typography styles for block items

* Update chip ui view styles.

Additionally, add editor styles to have the editor match the rendered
frontend.

* Update additional remove button styles.

- Add hover state to remove button on chip layout.
- Update disabled styles to remove button in both layouts (mainly relevant
to the editor view).

* Adjust remove button colors.

Set hover states to shades of grey. Also set chip color and text to
match selected text color of the block.

* Update e2e test to account for new element order.

Since we're moving the remove button in the list view from the last
child node to the first child node, we need to adjust the expected order
of the active filter item text.

* Design and copy updates on the block settings

Co-authored-by: Alba Rincón <albarin@users.noreply.github.com>
Co-authored-by: Alba Rincón <alba.rincon@automattic.com>
2022-08-26 09:11:23 -04:00
Albert Juhé Lluveras 2c1dacdd93 Fix z-index issue in Filter by Attribute dropdowns (https://github.com/woocommerce/woocommerce-blocks/pull/6981)
* Fix z-index issue in Filter by Attribute dropdowns

* Remove unnecessary z-index property
2022-08-25 13:55:33 +02:00
Alba Rincón 2060f11474 `Filter by Attribute` block design updates (https://github.com/woocommerce/woocommerce-blocks/pull/6920)
* Add and style Reset and Apply buttons

* Style the dropdown option

* Fix class and label

* Fix checkbox margin in editor

* Fix alignment

* Fix the reset button

* Disable Apply button when no changes have been made to the filter to improve UX

* Reduce vertical spacing between list items

* Style chips

* Don't reload on reset if filters have not been applied

* Fix heading styles on the front end

* Add chevron down to filter by attribute dropdown ui component

* Force FormTokenField to remount on reset

* Fix dropdown z-index

* Reduce apply button margin

* Fix styles for single token selection

Co-authored-by: tjcafferkey <tjcafferkey@gmail.com>
2022-08-25 12:01:41 +02:00
Tung Du 6327094a49 Style the Filter by Price block based on the wrapper width (https://github.com/woocommerce/woocommerce-blocks/pull/6943) 2022-08-24 16:10:21 +07:00
Tomasz Tunik b295689571 Product search block as core/search variation (https://github.com/woocommerce/woocommerce-blocks/pull/6191)
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
Co-authored-by: Tung Du <dinhtungdu@gmail.com>
2022-08-23 23:06:17 +07:00
Alba Rincón aae8c5d357 Update filter button styles (https://github.com/woocommerce/woocommerce-blocks/pull/6958)
* Update filter button styles

* Address feedback: use mixings

* Improve the editor selector for stock apply button

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>

* Reduce vertical margin and input width

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2022-08-23 12:38:39 +02:00
Alba Rincón d8a1dfc456 Make the inlineInput default to false to avoid changing existing block behaviour (https://github.com/woocommerce/woocommerce-blocks/pull/6957) 2022-08-23 12:10:46 +02:00
Albert Juhé Lluveras a362a89524 When converting the Filter Products by Price widget into the Filter by Price block, don't use inline input (https://github.com/woocommerce/woocommerce-blocks/pull/6953) 2022-08-22 14:29:29 +02:00
Tom Cafferkey a07cc3c978 Update Filter by Stock block (https://github.com/woocommerce/woocommerce-blocks/pull/6883)
* Update Filter by Stock controls and UI to include custom checkbox and settings.

* Include and style Filter by Stock reset button

* Make checkbox accessible via keyboard

* Update snapshot tests for Filter Products by Stock component

* Update E2E tests with new label value

* Update label test for Apply Filters in E2E tests

* Specify checkbox type so styles are not overridden in the editor

* Update E2E test label for filter button

* Update label selector to search for containing text rather than exact match

* Escape quotation marks for label query in E2E shopper tests for Filter by Stock

* Correct typo on Filter by Stock controls

* Replace custom checkbox with CheckboxControl component from the checkout package.

* Remove opacity on product count for checkbox label so its the same color as the label.

* Update snapshot tests with new component usage for filter by stock

* Update block title from Filter Products by Stock to Filter by Stock

* Update reset button behaviour to clear selections immediately regardless of whether the Apply Filters button is active or not.

* Pass option value as ID to satisfy E2E tests

* Update snapshot tests for stock filter

* Reset checked state on reset for when they have filters checked but not applied.
2022-08-19 09:04:04 +01:00
Alba Rincón 8167f0afb4 `Filter by Attribute` block settings design update (https://github.com/woocommerce/woocommerce-blocks/pull/6912)
* Updata block title and description

* Update block settings to match designs

* Update block title in tests

* Update copy in test
2022-08-19 08:55:34 +02:00
Luigi Teschio ffbf5823d3 Product Query Block POC (Phase 1) (https://github.com/woocommerce/woocommerce-blocks/pull/6812)
* Move `EditorBlock` to general `type-defs`

`EditorBlock` was scoped under the `featured-items` directory at the time of its creation. It is, however, a useful type that should be shared repo-wide. For this reason, I am moving it into the `blocks` type-defs and updating all the references.

* Define types for the Product Query block

Also defines a more generic `WooCommerceBlockVariation` type which should be also useful in the future to implement a similar pattern.

* Add Product Query utils

Add two utility functions:

 1. `isWooQueryBlockVariation`: is used to check whether a given block is a variation of the core Query Loop block, and also one of the allowed variations within our repo. See: `QueryVariation` enum type.
2. `setCustomQueryAttribute`: is a shorthand to set an attribute within the variation query attribute.

* Refactor and cleanup the JS demo code

Specifically:

1. Creates a `constant.ts` file to store all shared constants. Currently, the default variation attributes.
2. Move the variations to their own directory. One file per variation.
3. Move the inspector controls into own file and create a conditional logic to allow showing only certain settings.

* Update webpack config

* Add ProductQuery class

* Fix `QueryVariation` enum

We had changed the Products on Sale variation slug to something else,
but we had forgotten to update the proper enum.

* Remove unused params from `update_query`

The filter we added to Gutenberg will pass the block and the page,
as we might need them in the future and we want to minimize the
amount of changes we'll have to do upstream.

However, we currently do not use those, so I removed
them from our own inner function.

Co-authored-by: Lucio Giannotta <lucio.giannotta@a8c.com>
2022-08-18 10:02:21 +02:00
Tung Du 401e7b5a70 Price Filter Block Design update (https://github.com/woocommerce/woocommerce-blocks/pull/6877)
* make toggle control full width

* add inlineInput attribute

* add inlineInput sidebar setting

* add inlineInput help text

* style the filter button

* style price input

* wip: reset button

* clicking on reset button will reset the price query

* support inline input fields

* price text styling update

* fix reset button font size

* add loading placeholder to all elements

* fix filter button style

* update range slider thumb and track style

* fix loading placeholder for non empty query

* move reset button into FilterSubmitButton component

* try: render placeholder serverside

* update filter button label

* Revert "try: render placeholder serverside"

This reverts commit 98f08efdb8048b8f78c7476b774d1128c1d31295.

* remove LoadingPlaceholder component

* remove Price: prefix from the current displayed price range

* update labels

* extract reset button as a dedicated component

* update price text section

* update reset button behavior

* avoid breaking filter submit button style for other filter blocks

* rename block to Filter by Price

* fix e2e test

* remove border support

* adjust padding for elments

* rename panel title

* Make the inline option enabled by default and fix frontend rendering

* Make the `Price Range Selector` uppercase

* Show `Reset` button only when a selection has been made

* Revert the `save` change to avoid the 'Block Recovery Prompt'

Co-authored-by: Alba Rincón <alba.rincon@automattic.com>
2022-08-16 19:58:55 +02:00
Thomas Roberts de9b044eba Only show items if there are multiple packages in the cart (https://github.com/woocommerce/woocommerce-blocks/pull/6899) 2022-08-16 17:19:40 +01:00
Seghir Nadir c338a799b3 Add _blank to terms link (https://github.com/woocommerce/woocommerce-blocks/pull/6908) 2022-08-16 15:59:21 +01:00
Seghir Nadir 4bfb255f6b add side effect to package (https://github.com/woocommerce/woocommerce-blocks/pull/6904) 2022-08-16 16:21:26 +05:30
Albert Juhé Lluveras 03c5d9ccd1 Add global styles to Product Categories List block in WC core (https://github.com/woocommerce/woocommerce-blocks/pull/6906) 2022-08-16 09:42:38 +02:00
Thomas Roberts 2285d1d4e2 Include Cart and Checkout Blocks when included in WC Core (https://github.com/woocommerce/woocommerce-blocks/pull/6805)
* Remove all inbox notifications about cart and checkout blocks

* Remove feature flag check from CreateAccount class

* Remove feature plugin check to register PaymentsApi class

* Comment out is_feature_plugin_build function

We might need this later, so keeping it around seems useful.

* Remove feature plugin check when adding resource hints

* Import registerBlockType and use it over registerFeaturePLuginBlockType

* Ensure Cart and Checkout inner blocks register even if not feature plugin

* Comment out registerFeaturePluginBlockType

* Remove duplicate import

* Revert "Comment out registerFeaturePluginBlockType"

This reverts commit bec6ed899b68e26e836bde1c573d6066fb2bcc47.

* Align PHPDoc correctly

* Update feature flag doc to remove Cart and Checkout blocks + PaymentApi
2022-08-15 11:15:15 +05:30
Wojtek Naruniec eb1c1c5201 Refactor Product Categories block to use block.json (https://github.com/woocommerce/woocommerce-blocks/pull/6875)
I refactor block to use block.json schema. The block schema
internally extends the main block.json schema and it fixes an issue
that occurs on WPCOM.
2022-08-12 17:46:00 +02:00
Thomas Roberts d45ef84219 Add dismissible compatibility notice to sidebar when editing Cart and Checkout (https://github.com/woocommerce/woocommerce-blocks/pull/6869)
* Add default page notice

* show notice all inner blocks

* support flow when page isnt saved

* switch from where we get the current post id

* update lock

* fix types

* Remove old compatibility notices from Cart and Checkout

* Move useCompatibilityNotice to sidebar-compatibility-notice directory

* Remove old CartCheckoutCompatibilityNotice

* Create sidebar compatibility notice hoc

* Add isCartOrCheckoutOrInnerBlock function

* Refactor defaultNotice to use new isCartOrCheckoutOrInnerBlock func

* Remove BlockSettings from checkout edit and export from checkout-shared

* Change so component still renders, it is just hidden with display: none

This is required because when it returns null the component gets skipped from being added to the Slot, then when it does return a component, then it gets rendered at the bottom of the Slot. By ensuring it always renders we can have it at the top all the time.

* Set the priorities of the hoc filters so compat notice renders first

* Make isCartOrCheckoutInnerBlock a hook

* Remove old compatibility notice related tests

* Remove BlockSettings from Cart

* Remove withDefaultNotice hoc

* Include DefaultNotice in compatibility notice

* Remove DefaultNotice from Checkout

* Rename withSidebarCompatibilityNotice to withSidebarNotices

This is because it includes the sidebar compatibility notice and the default notices

* Remove useIsCartOrCheckoutOrInnerBlock hook

* Remove compatibility notice code from tests

* Revert DefaultNotice back to the old one

* Remove unused components

* Remove withBlockSettings HOC and fix TS types

This is an abstraction that is no longer required, we can just include BlockSettings in the Cart and Checkout blocks

* Remove CartCheckoutFeedbackPrompt from BlockSettings

It will be included in sidebar-notices instead

* Fix TS Types in DefaultNotice

* Add BlockSettings to cart and checkout edit

* Editor: Add feedback box to the Cart & Checkout Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6881)

* Show "Feedback prompt" for all inner blocks

* Fix the "feedback" notice position for these blocks

The "checkout fields", "checkout billing address" and
"checkout shipping address" have the addressFields option which
gets rerendered and placed at the bottom of the inspector controls.

* Tidy up the address-fields hoc

* Use correct block name to check for billing or shipping address

* Revert "Editor: Add feedback box to the Cart & Checkout Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6881)"

This reverts commit 5f3d6cf15ce08d9c303e62ec3e0d0315ead1281f.

* Add hack to get feedback prompt to render last

* Fix TS errors for context and attributes

* Include CartCheckoutFeedbackPrompt in accountcontrols & addresscontrols

* Do not include feedback prompt if on an address block or contact info

* Remove unused hoc for address fields

Co-authored-by: Nadir Seghir <nadir.seghir@gmail.com>
Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-12 15:23:08 +01:00
Daniel W. Robert 5c40b83480 Add Style Attributes Hooks to blocks/hooks Directory. (https://github.com/woocommerce/woocommerce-blocks/pull/6870)
* Copy style-attributes file to desired directory.

Add a copy of the style-attributes file in blocks/hooks to the desired
base/hooks directory with the other hooks.

* Remove relative imports in favor of global aliases

Utilizes the custom global project aliases in place of using relative
imports.

Note: seeing some linting issues with the aliases. This seems to be the
case elsewhere so it is likely not a blocker for this effort, however,
it may be worth looking into as a follow-up.

* Adjust all imports to use @woocommerce/base-hooks.

Replace all instances of relative file paths to hooks/style-attributes
to use the custom global alias.

* Remove the hooks dir in `assets/js/blocks/`.

Now that everything is using the `@woocommerce/base-hooks` custom global
alias and we have the `style-attributes` hooks file in the base/hooks
directory, we no longer need the `style-attributes` hooks file in the
aforementioned `assets/js/blocks` directory.

* Split style-attributes.ts out into separate files.

Moved the four hooks in style-attributes.ts out into their own, separate
hook file to be consistent with the rest of our custom hooks.

Additionally, moved the helper function (parseStyle) out into a separate
export in base/utils.
2022-08-10 20:04:12 -04:00
Tarun Vijwani d258a0696c Update billing address when shipping address gets change in Cart block (https://github.com/woocommerce/woocommerce-blocks/pull/6823) 2022-08-10 17:03:28 +05:30
Daniel W. Robert 02ce62109e Add font-weight option to Mini Cart block text (https://github.com/woocommerce/woocommerce-blocks/pull/6760)
* Add font-weight option to Mini Cart button text.

Need to repeat steps for icon SVG and cart item count.

* Add font-weight controls to mini-cart item count.

* Add better error handling to PHP style output.

Ensure style value is set for style item in the
get_font_weight_class_and_style attributes array before rendering it to
the output.

* Revert font-weight option for quantity badge.

Per conversation with @vivialice, it looks better for now to keep the
font weight adjustment capabilities to just the price and leave the cart
icon and count as-is.

* Move $typography_styles variable into markup fn.

To resolve merge conflicts and get everything in it's proper place, this
commit will move the $typography_styles variable into the
get_cart_price_markup() function from woocommerce/woocommerce-blocks#6796.
2022-08-05 14:15:10 -04:00
Tung Du b5cc976905 E2E: Try improving product list loading state detection and fix Site Editor URL (https://github.com/woocommerce/woocommerce-blocks/pull/6811)
* e2e:try: detect loading state for product list

* fix: always use site-editor.php

* wait for price filter to be applied before checking the result
2022-08-03 16:22:37 -04:00
Thomas Roberts aad09c975d Ensure onChange is set for radio buttons in SavedPaymentMethodOptions (https://github.com/woocommerce/woocommerce-blocks/pull/6825)
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
2022-08-03 11:51:56 +01:00
Daniel W. Robert fef4d5e597 Add option to hide/show price in Mini Cart block (https://github.com/woocommerce/woocommerce-blocks/pull/6796)
* Add toggle control to sidebar in editor.

Adds a visibility toggle in the Mini Cart block's sidebar editor
settings for the block price.

* Update name of hasVisiblePrice attrubite.

Adjusts the name of the hasVisiblePrice attribute to hasHiddenPrice.
This seems a bit easier to reason about, where we can set the default
state of the visibility toggle to 'off'.

* Add conditional price rendering to server side.

Since this is a dynamic block, need to add the condidional attribute
state to the server-side render callback.

* Add price visibility setting to block frontend.

We need to prevent pricec from rendering when hidden setting is active
after the JS kicks in on the frontend (i.e., when the Mini Cart is
interacted with by the user).

* Fix logic error in frontend rendering conditional.

* Add unit tests for both show/hide price states.
2022-08-02 10:28:52 -04:00
Thomas Roberts 0fc1ee46bd Ensure package names display correctly if only one item is in package (https://github.com/woocommerce/woocommerce-blocks/pull/6815)
* Check package length >= 1 to show package name

* Check shipping rates length in order shipping packages slot

* Fix TS error where boolean value could be undefined

* Show items if there is more than one shipping rate
2022-08-02 04:51:21 -07:00
Tung Du 862477f9aa Remove compatibility notice from Mini Cart block (https://github.com/woocommerce/woocommerce-blocks/pull/6803) 2022-08-01 18:01:57 +02:00
Saad Tarhi dc97e5af1e Fix missing translations in inspector (https://github.com/woocommerce/woocommerce-blocks/pull/6737)
* Try registering the "cart taxes" inner block

Registering server side. This example isn't working, but I'm pushing to
share it and see what's wrong with this implementation.

* Fix registering the cart taxes inner block issue

* Update translation script loading

* Remove unnecessary JS translation

The translation should work fine by getting the title & description from
the `block.json` file

* Put back the initial code in the 'Cart Taxes' inner block

We didn't provide the correct `block.json` file path server side,
that's why the `metadata` wasn't correctly registered

* Generate `block.json`files for inner blocks

This is the first step on fixing the missing translations of `metadata`
in `block.json` files

* Set the folder name exactly the same as the inner block name

We are doing this first test for the `Cart taxes` inner block.

The `Block` & its containing folder need to have the same name for:
- Consistency
- We use the `Block` name to get the file Path

* Update imports after folder renaming

* Get block name directly from the JSON metadata

Getting the block name from the JSON metadata is less error prone than
extracting it from the file path.

And no need to rename all our `inner-blocks` to get the correct
`block.json` path

* Revert folder naming change of `Cart taxes` inner block

Since we are getting the `block` name directly from the `block.json`
metadata instead of extracting it from the file path, there is no need
to keep their names in sync anymore

* Fix missing translations for the `Cart Subtotal` Block

* Register only the client-side settings on the client

When the block is registered on the server, you only need to register
the client-side settings on the client using the same block’s name.
See [docs](https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#javascript-client-side).

* Add schema validation to `block.json`

Development is improved by using a defined schema definition file.
Supported editors can provide help like tooltips, autocomplete, and
schema validation.

* Use the same `editor_script` as the parent block

This prevents WordPress from generating script tags to inexistant
inner blocks JS files

* Add C&C inner blocks in Cart.php & Checkout.php

This is a refactoring to keep the block types controller file less
overloaded

* Fix all Cart inner blocks missing translations

* Create the "AbstractInnerBlock" class

The "Inner Blocks" will use their parent's script, so no need to create
new scripts for each one of them

And, our "Inner Blocks" should always be registered using the metadata file

* Update the "Inner Blocks" PHP classes

* Fix PHP lint erros & update function description

* Fix missing translations bug for all Checkout Inner Blocks

* Update src/BlockTypes/Checkout.php

Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>

* skip lazy loaded scripts

Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
2022-08-01 15:57:33 +01:00
Tung Du 0ee5dbbc18 Fix: Replace DropdownSelector with FormTokenField from Gutenberg (https://github.com/woocommerce/woocommerce-blocks/pull/6647) 2022-08-01 19:00:59 +07:00
Daniel W. Robert 056e6946e8 Add new icon for mini cart block (https://github.com/woocommerce/woocommerce-blocks/pull/6784)
* Add new icon for mini cart block (inserter).

See https://github.com/woocommerce/woocommerce-blocks/issues/6617.

* Adjust size of SVG

The new SVG was rendering a little bit smaller than the original icon.
Potentially because of the mask and the artboard size.

This commit adjusts the size to render at the same size as the original
version of the icon in the inserter.
2022-07-29 15:40:03 -04:00
Seghir Nadir 008c63b0dc Refactor external dispatch actions from being called inside useSelect (https://github.com/woocommerce/woocommerce-blocks/pull/6718)
* refactor coupon functions outside of useSelect

* fix test
2022-07-29 16:20:48 +01:00
Thomas Roberts 89022e18f8 Ensure addresses sync when loading the checkout shipping address block (https://github.com/woocommerce/woocommerce-blocks/pull/6773) 2022-07-28 07:38:29 -07:00
Bernie Reiter 3858b03aec All Products block: Migrate to block.json (https://github.com/woocommerce/woocommerce-blocks/pull/6754)
* All Products: Use block.json to register

* Simplify edit def

* Separate file for save

* No more client-side registration

* Remove uncommented, now-obsolete code

* Add back client-side block registration

* Remove stray textdomain from keywords field

* Add textdomain field

* Set apiVersion to 1
2022-07-28 12:26:36 +02:00
Thomas Roberts 488ff13ca9 Update the `previewCart` property we use to get `hasCalculatedShipping` in `useShippingData` and fix broken JS tests (https://github.com/woocommerce/woocommerce-blocks/pull/6781)
* Require the rest of the @woocommerce/block-settings module in block.test.js

* Use correct property from previewCart for hasCalculatedShipping
2022-07-28 02:22:42 -07:00
Thomas Roberts 3fbd497d28 Add gap between pakage panels (https://github.com/woocommerce/woocommerce-blocks/pull/6740) 2022-07-26 23:00:38 -07:00
Thomas Roberts 6bf8f07c39 Ensure shipping rate names show when multiple packages are used (https://github.com/woocommerce/woocommerce-blocks/pull/6753)
* Get shipping rates from preview cart in editor

* Set showItems in ShippingRatesControl to true if multiple packages

* Move dependency in useShippingData to correct section

* Ensure getting packageData.shipping_rates.length won't error
2022-07-26 23:00:17 -07:00
Alba Rincón e56107f436 Select the correct inner button for the "Featured Item" button to update its url (https://github.com/woocommerce/woocommerce-blocks/pull/6741)
* Select the correct id/attributes for the button to update its url

* Fix variables case
2022-07-26 14:30:18 +02:00
Tung Du c10e91e7e1 Fix: navigate through Mini Cart contents with keyboard (https://github.com/woocommerce/woocommerce-blocks/pull/6731)
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2022-07-25 12:39:47 +07:00
Lucio Giannotta 615ff35fac `SearchListControl`: Fix preserving case of original item (https://github.com/woocommerce/woocommerce-blocks/pull/6551)
Searches would keep the case of the user input instead of the original
case of the name. Search still is case insensitive, but preserves
the original item's case.

Also, this PR adds a test for this bug and fixes a previous test case.
2022-07-21 21:49:42 +02:00
Alba Rincón 63ce706139 Start using `block.json` and convert to TS the `Product Best Sellers` block (https://github.com/woocommerce/woocommerce-blocks/pull/6683)
* Start using `block.json` and convert to TS the `Product Best Sellers` block

* Update assets/js/blocks/product-best-sellers/edit.tsx

Co-authored-by: Luigi Teschio <gigitux@gmail.com>

* Import props

Co-authored-by: Luigi Teschio <gigitux@gmail.com>
2022-07-20 11:29:49 +02:00
Alba Rincón ad4fb01228 Start using `block.json` and convert to TS the `Product by Category` block (https://github.com/woocommerce/woocommerce-blocks/pull/6680)
* Start using `block.json` and convert to TS the `Product by Category` block

* Address feedback to remove some TS errors

* Remove unnecessary prop
2022-07-19 15:09:46 +02:00
Tung Du 42453b7582 Fix: Add support to apply filters via URL for All Products block (https://github.com/woocommerce/woocommerce-blocks/pull/6642)
* price-filter: update URL when filtering products of All Products block.

* active-filters: update the URL when removing price filter

* price-filter: prevent update query on PHP templates when changing prices

* active-filters: on PHP templates, remove filter only triggers the page reload

* price-filter: update comments and naming to reflect new URL behavior

* stock-filter: update url when filtering for All Products block

* attribute-filter: update the URL when filtering for All Products block

* attribute-filter: fix: uncheck all filter doesn't clear the URL

* attribute-filter: fix: endless page reload when filtering for PHP template

* attribute-filter: correctly set the defaults and update the filter query from URL

* fix: filter URL containing stock status doesn't work on homepage

* price-filter: fix issue with URL on All Products

The price slider doesn't reset after removing price filter from the Active Filters block if the initial price filter is set from URL

* ref: passing document.title to pushState is unnecessary

* use replaceState to avoid changing browser history

* extract change URL logic
2022-07-11 14:04:19 +07:00
Tung Du 4e8c48144c Fix: Attribute Filters: allow choosing between single/multiple selection (https://github.com/woocommerce/woocommerce-blocks/pull/6620) 2022-07-07 06:14:22 +07:00
Paulo Arromba ffbc39bfd3 fix: fixed colors for error input and labels on dark palette mode themes and dark controls. (https://github.com/woocommerce/woocommerce-blocks/pull/6292) 2022-07-06 15:03:15 +01:00
github-actions[bot] 4e6da0b80d Release: 8.0.0 (https://github.com/woocommerce/woocommerce-blocks/pull/6652)
* Empty commit for release pull request

* Empty commit for release pull request

* Update readme.txt

* Update phpcs.xml

* Add testing notes and ZIP for release 8.0.0

* Update testing notes

* Update testing notes

* Revert woocommerce/woocommerce-blocks#6591

* Update testing notes

* Update readme.txt

* Update ZIP for release 8.0.0

* Change version from 8.0.0-dev to 8.0.0

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Niels Lange <info@nielslange.de>
2022-07-05 18:41:05 +02:00
Alba Rincón f36115b175 Prevent `Featured Product` block from breaking when product is out of stock + hidden from catalog (https://github.com/woocommerce/woocommerce-blocks/pull/6640) 2022-07-05 09:24:28 +02:00
Tarun Vijwani e6dfd66d5d Update billing address when shipping address gets change in Cart block (https://github.com/woocommerce/woocommerce-blocks/pull/6591)
* update billing address when shipping address gets change in Cart block

* Add a new line to test linting error

* Remove a new line to test linting error

* Fix linting error

* Fix linting error

* Fix linting error by adding a space and removing a comma

* Fix linting error by replacing a space with tab

Co-authored-by: Niels Lange <info@nielslange.de>
2022-07-04 12:22:32 +02:00
Tarun Vijwani a1526ed660 Make form components require onChange and have a default value (https://github.com/woocommerce/woocommerce-blocks/pull/6636) 2022-07-01 21:50:44 +04:00
Luigi Teschio e7eb8a6dd5 Show classic template in the inserter only for specific templates (https://github.com/woocommerce/woocommerce-blocks/pull/6539)
* Show classic template in the inserter only for specific templates

* add feature gate

* add todo comment

* rename variable

* address feedback

* not register block on post and page editor

* avoid casting
2022-06-29 09:42:02 +02:00
Tarun Vijwani 474d432836 Add key to BlockErrorBoundary component in renderForcedBlocks (https://github.com/woocommerce/woocommerce-blocks/pull/6582) 2022-06-24 16:55:49 +04:00
Tung Du 138df96762 Fix: Convert Active Filters Block codebase to TypeScript (https://github.com/woocommerce/woocommerce-blocks/pull/6580) 2022-06-21 21:53:49 +07:00
Albert Juhé Lluveras fc956b7f48 Fix images hidden by default in Product grid blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6599) 2022-06-20 14:13:56 +02:00
Tung Du 27224fd46e Fix: Convert Filter Products by Attribute Block to TypeScript (https://github.com/woocommerce/woocommerce-blocks/pull/6545)
* wip: convert attribute filter to ts

* change query to optional

* update SearchListControlProps and SearchListItemType

* get default attribute from metadata

* update types

* convert attributes utils to ts

* convert attribute query utils to ts

* fix type error, remove type casting

* revert type change for SearchListItemType

* apply new format
2022-06-15 19:50:42 +07:00
Michael P. Pfeiffer 521f93619b Upgrade wp-prettier to 2.6.2 and reformat the codebase (https://github.com/woocommerce/woocommerce-blocks/pull/6566)
* Remove mixed tabs and spaces in tsconfig.json

* Update formatting in json files

* Upgrade wp-prettier to 2.6.2
2022-06-15 11:56:52 +02:00
Tung Du 1ba3ca2ba1 Fix: Mini Cart content scrolling issue (https://github.com/woocommerce/woocommerce-blocks/pull/6565) 2022-06-15 15:18:50 +07:00
Tung Du 6531c4cb0b Fix: Convert Filter Products by Price Block to TypeScript (https://github.com/woocommerce/woocommerce-blocks/pull/6514) 2022-06-14 15:48:49 +07:00
Michael P. Pfeiffer d7820b98bb Featured items: fix focal point block json spacing (https://github.com/woocommerce/woocommerce-blocks/pull/6552) 2022-06-13 14:06:48 +02:00
Tung Du 876e955125 Fix: Convert Filter Products by Stock to TypeScript (https://github.com/woocommerce/woocommerce-blocks/pull/6533) 2022-06-13 08:39:09 +07:00
Niels Lange d7d043cb5b Rename billingData to billingAddress (https://github.com/woocommerce/woocommerce-blocks/pull/6369)
* Rename billingData to billingAddress

* Add unit test to ensure billingData remains accessible

* add integration tests for slots

* Keep billingData in usePaymentMethodRegistration for backwards compatibility

* Gate `billingData` in deprecation gate

* Replace deprecation call

Co-authored-by: Nadir Seghir <nadir.seghir@gmail.com>
2022-06-10 18:59:25 +02:00
Michael P. Pfeiffer a432a85bf0 Cart: ensure express checkout placeholder does not stick to checkout button (https://github.com/woocommerce/woocommerce-blocks/pull/6547)
* Cart: ensure express checkout placeholder does not stick to checkout button

* Display to affect description only
2022-06-10 15:20:41 +02:00
Niels Lange 3208da551b Improve the structure of the WooCommerce Blocks Handbook (https://github.com/woocommerce/woocommerce-blocks/pull/6429)
* Improve the structure of the WooCommerce Blocks Handbook

Co-authored-by: Rania Lang <rania.langouretou@automattic.com>
2022-06-09 17:52:19 +02:00
Tung Du 45f48e6b0a Fix: Register Filter Blocks using `block.json` (https://github.com/woocommerce/woocommerce-blocks/pull/6505) 2022-06-09 21:45:24 +07:00
Niels Lange a748f533a8 Format Markdown files using wp-scripts (https://github.com/woocommerce/woocommerce-blocks/pull/6462)
* Format Markdown files using Prettier

* Format Markdown files using wp-scripts

* Adjust MD linting
2022-06-09 14:43:17 +02:00
Tung Du 111b4eca48 Convert `useCollectionData` hook to TS (https://github.com/woocommerce/woocommerce-blocks/pull/6535) 2022-06-09 16:05:11 +07:00
Albert Juhé Lluveras b5252dbd8f Disable page scroll when Mini Cart is open (https://github.com/woocommerce/woocommerce-blocks/pull/6532) 2022-06-09 09:58:29 +02:00
Albert Juhé Lluveras 40231ea1f9 Revert "Remove Combobox patch (https://github.com/woocommerce/woocommerce-blocks/pull/6465)" (https://github.com/woocommerce/woocommerce-blocks/pull/6531)
This reverts commit 4976afad58.
2022-06-07 14:09:50 +02:00
Lucio Giannotta 7531428b31 Featured Item: Fix colors from default palette not being applied (https://github.com/woocommerce/woocommerce-blocks/pull/6525)
Gutenberg uses two different attributes for text colors:

* `style.color.text`, and
* `textColor`

However, the second one is used only when a color from the default
palette is selected AND the post is saved and reloaded.

With this fix we use the human readable string from the default palette
as a CSS variable.

Please note that while Gutenberg correctly assigns the appropriate CSS
class to render the right color, the problem is that if the color is
handled by a class, it can be overridden for example by themes.

See woocommerce/woocommerce-blocks#6492
2022-06-07 10:44:45 +02:00
Luigi Teschio 96b9cbf0c6 Add the button to migrate to the blockified version of the Product Grid Block woocommerce/woocommerce-blocks#6483 (https://github.com/woocommerce/woocommerce-blocks/pull/6485)
Add the button to migrate to the blockified version of the Product Grid Block
2022-06-06 16:49:19 +02:00
Michael P. Pfeiffer f38e0819ad Featured items: ensure valid DOM nesting in inspector controls (https://github.com/woocommerce/woocommerce-blocks/pull/6501) 2022-06-01 10:02:24 +02:00
Lucio Giannotta 52b946bd29 Featured Item: Fix default color being overridden by themes (https://github.com/woocommerce/woocommerce-blocks/pull/6492)
This fix applies the user selected color on the block's parent element.

Also: Fix default and custom colors not being applied to title correctly.
2022-05-31 17:43:03 +02:00
Alba Rincón 2a99207fac Set the default value for focalPoint on block.json (https://github.com/woocommerce/woocommerce-blocks/pull/6499) 2022-05-31 13:26:36 +02:00
Michael P. Pfeiffer d17bb32c02 Filter Products by Price: Decrease step sequence from 10 to 1 (https://github.com/woocommerce/woocommerce-blocks/pull/6486) 2022-05-31 12:44:50 +02:00
Lucio Giannotta d63c5dafc1 Migrate Featured Items Blocks to TypeScript (https://github.com/woocommerce/woocommerce-blocks/pull/6439)
Also:

* Refactored some composed components into one inclusive HOC,
called `withUpdateButtonAttributes`.

* The HOC `withTransformSingleSelectToMultipleSelect` allows for the wrong
type to be passed to its wrapped component: if a single element is
passed, that is wrapped into an array.

This didn't play well with TypeScript which obviously complains about
the wrong type being passed to the component.

So we now allow for arrays to be passed as props and ignored by the HOC
2022-05-30 16:38:52 +02:00
Daniel Dudzic b15050909e Mini Cart: Add font size and font family controls (https://github.com/woocommerce/woocommerce-blocks/pull/6396)
* Mini Cart: Add font size and family controls

* Remove redundant property from the path

* Add conditional check for isFeaturePluginBuild
2022-05-30 10:45:15 +02:00
Tung Du 0b51900bd2 Fix: Wait for the product to be added to cart before redirecting customer to the cart page (https://github.com/woocommerce/woocommerce-blocks/pull/6466) 2022-05-27 13:36:49 +07:00
Albert Juhé Lluveras 4976afad58 Remove Combobox patch (https://github.com/woocommerce/woocommerce-blocks/pull/6465) 2022-05-26 12:31:29 +02:00
Saad Tarhi 25cb047483 Remove `useStoreSnackbarNotices` and interact directly with data store instead (https://github.com/woocommerce/woocommerce-blocks/pull/6411)
* Use wp store directly instead of React Context

We are using now actions directly from wp store in 'useStoreCartCoupons'
hook to apply and remove coupon.

* Remove unused "useStoreSnackbarNotices" related
files

* Add NoticeContext TS definition

* Remove the Provider references and refactor code

* Fix snackbar notice creation bug

* Fix "clear out snackbar coupon notice" bug

* Update "notices" API documentation

Remove snackbar hooks mentions since it's not used anymore
2022-05-25 22:00:47 +01:00
Alba Rincón 983a13c8bf Add `Fixed/Repeated background` to the `Featured Category` block (https://github.com/woocommerce/woocommerce-blocks/pull/6440)
* Add `Fixed/Repeated background` to the `Featured Category` block

* Reorganize `Featured Product` and `Feature Category` before unification

* Fix gradient overlay
2022-05-24 16:10:16 +02:00
Alex Florisca 3f0e93268e Fix being able to remove Cart Totals block (https://github.com/woocommerce/woocommerce-blocks/pull/6449) 2022-05-24 12:49:53 +01:00
Thomas Roberts 4a7b8ae1cf Revert "Add `requireExactMatch` prop to `ComboBox` to prevent wrong country/state values being sent to the server (https://github.com/woocommerce/woocommerce-blocks/pull/6426)" (https://github.com/woocommerce/woocommerce-blocks/pull/6447)
This reverts commit b1f4e35c00.
2022-05-24 10:49:17 +02:00
Luigi Teschio 33a9e654ca Enable ESLint for E2E folder woocommerce/woocommerce-blocks#6410 (https://github.com/woocommerce/woocommerce-blocks/pull/6413)
Enable ESLint for E2E folder; fix ESLint errors
2022-05-23 14:05:30 +02:00
Alex Florisca 903f96f677 Locked blocks cannot be unlocked and removed (https://github.com/woocommerce/woocommerce-blocks/pull/6419)
* DIsable the locking/unlocking mechansism for the cart-items-block so it cannot be unlocked and deleted

* Update all locked inner blocks with support: { lock: false } to disable locking/unlocking the blocks
2022-05-23 13:59:07 +02:00
Alba Rincón a18e44e1a7 Convert `Products by Attribute` to TS (https://github.com/woocommerce/woocommerce-blocks/pull/6418)
* Convert `Products by Attribute` block to TS

* Small tweaks after review

* Extract InspectorControls and EditMode into components

* Refactor: move the edit related code to the edit.jsx file

* Remove the `editMode` attribute and control the edit mode inside the edit component

* Remove edit mode

* Change `isEditing` depending on attributes are selected or not

* Improved interfaces/props after review

* Add enum allowed values to `attrOperator` and `orderby` on the `block.json`

* Move `withSpokenMessages` to wrap the whole Edit block
2022-05-23 10:45:54 +02:00
Alba Rincón eec68ed371 Convert `Handpicked Products` block to TS (https://github.com/woocommerce/woocommerce-blocks/pull/6417)
* Convert `Handpicked Products` block to TS

* Extract InspectorControls and EditMode into components

* Refactor edit and remove the `editMode` attribute

* Change `isEditing` default depending on products selected or not

* Improve interfaces/props after review

* Move withSpokenMessages to wrap the whole Edit block
2022-05-23 10:14:51 +02:00
Alba Rincón d61c5116ad Start using `block.json` for the `Products by Attribute` block (https://github.com/woocommerce/woocommerce-blocks/pull/6414) 2022-05-23 10:10:06 +02:00
Albert Juhé Lluveras bcdb2174aa Remove bold styles from All Products block (https://github.com/woocommerce/woocommerce-blocks/pull/6436) 2022-05-20 15:15:55 +02:00
Alba Rincón 6e5ebdff85 Start using the `block.json` metadata file for `Products by Tag` (https://github.com/woocommerce/woocommerce-blocks/pull/6403)
* Start using the block.json metadata file for `Products by Tag`

* Remove comment

* Add version, schema, and text domain

* Add defaults

* Remove wrong keyword

* Add tag icon when registering the block
2022-05-20 14:43:43 +02:00
Lucio Giannotta 7fcc561db1 Refactor Featured Category and Featured Product blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6406)
This PR creates a new directory called `featured-items` which includes both blocks.
All the shared code lives at the top level of that directory.

Individual blocks still have their own directories, with their `block.json` and all other relevant configuration.

All the functionalities have been refactored out into their own files, accepting configuration when relevant, but mostly de-duplicating all the code.

Styles have also been refactored using mixins and extends and they mostly live in one place.
2022-05-19 18:16:46 +02:00
Thomas Roberts b1f4e35c00 Add `requireExactMatch` prop to `ComboBox` to prevent wrong country/state values being sent to the server (https://github.com/woocommerce/woocommerce-blocks/pull/6426)
* Add requireExactMatch prop to ComboBox & only run onChange if value matches

* Set requireExactMatch to true for Country and State inputs

* Add unit tests for ComboBox

* Update expected value for onChange call

* Re-add autocomplete option to country input

* Use correct case for autoComplete in country input
2022-05-18 18:32:42 +01:00
Alba Rincón 22e6394d47 Implement `Fixed image` and `Repeated image` media controls for the `Featured Product` (https://github.com/woocommerce/woocommerce-blocks/pull/6344)
* Add `Fixed` and `Repeated` background controls to `Featured Product`

* Add `Repeated background` feature when the toggle is activated

* Extract `get_image_url` function

* Add the styles for rendering the repeated image on the frontend

* Add `hasParallax` and `isRepeated` to the `block.json` file

* Adjust styles

* Remove unused function, improve phpdoc

* Use alt and product name

Fix error rebasing master

* Hide alt if isRepeat is true

When isRepeated is true, the image is a background so it does not
make sense to have an alt attribute.

* Add `Fixed image` behaviour

* Remove unnecessary single quotes

* Remove duplicated const due to rebasing

* Fix focal point getting lost after enabling Fixed bg

* Fix duotone for fixed and repeated images

* Fix duotone for fixed and repeated images on the front end

* Don't allow alt if the image is a bg not an img element
2022-05-18 16:08:32 +02:00
Alba Rincón 42166068b6 Start using the `block.json` metadata file for `Handpicked products` (https://github.com/woocommerce/woocommerce-blocks/pull/6392)
* Start using the `block.json` metadata file for `Handpicked products`

* Add the `properties` attribute to properly parse booleans

* Remove comment

* Add schema, delete version
2022-05-13 14:57:34 +02:00
Alba Rincón bedd25ead6 Remove unnecessary `index.js` on Featured Category (https://github.com/woocommerce/woocommerce-blocks/pull/6394) 2022-05-13 12:36:46 +02:00
Daniel Dudzic 0b3acfad27 Add the product image control for all blocks utilizing GridContentControl (https://github.com/woocommerce/woocommerce-blocks/pull/6302) 2022-05-09 12:04:33 +02:00
Tung Du 773db56bc5 Fix: Empty Mini Cart Contents view in editor is not vertically centered on WP 6.0 (https://github.com/woocommerce/woocommerce-blocks/pull/6379) 2022-05-06 18:05:54 +07:00
Michael P. Pfeiffer 3aba1b4339 Featured Product: add background color option (https://github.com/woocommerce/woocommerce-blocks/pull/6367) 2022-05-06 07:13:11 +02:00
Lucio Giannotta 3ed91db9e7 Add media controls to the Featured Category block (https://github.com/woocommerce/woocommerce-blocks/pull/6360)
Also:

* Make sure media controls are unavailable unless there is media
2022-05-05 17:55:53 +02:00
Michael P. Pfeiffer 3f6b197063 Featured Category: add background color option (https://github.com/woocommerce/woocommerce-blocks/pull/6368) 2022-05-05 16:12:01 +02:00
Tung Du a22c93f00b Disable lock menu item for Mini Carts Contents and its inner blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6374) 2022-05-05 17:31:57 +07:00
Tung Du 206672f27e Classic Template: set the default alignment to wide (https://github.com/woocommerce/woocommerce-blocks/pull/6356) 2022-05-04 18:02:42 +07:00
Alba Rincón dcc4e60dda Parse categories coming from the back-end as a json array (https://github.com/woocommerce/woocommerce-blocks/pull/6358)
* Parse categories coming from the back-end as a json array

The category ids that come from php are in json array format (e.g. '[40,41]'),
so it's necessary to parse them and convert them into a js array before
processing them. Otherwise the api request will fail.

* Only parse category ids if not undefined
2022-05-03 16:09:20 +02:00
Tung Du ab797e8237 Fix: Prevent page reloads twice when the shopper sets a price filter and attribute filter using blocks in a PHP template (https://github.com/woocommerce/woocommerce-blocks/pull/6350) 2022-05-03 17:04:44 +07:00
Lucio Giannotta 9a38c6445e Add media controls to the Featured Product block (https://github.com/woocommerce/woocommerce-blocks/pull/6348)
This PR adds image editing controls to the Featured Product block. In particular, user can now:

* Rotate the image
* Crop the image
* Change the aspect ratio of the image
* Zoom the image

Each edit gets saved in the database as a new image.
2022-05-03 09:11:13 +02:00
Alba Rincón bdfd1da4c5 Start using the `block.json` metadata file for the `Featured Category` block (https://github.com/woocommerce/woocommerce-blocks/pull/6300)
* Start using the `block.json` metadata file for the `Featured Category` block

* Get default attributes from the `block.json` file

* Remove unnecessary `get_block_metadata_defaults` function

* Add alt attribute to the block.json file

* Remove unused imports
2022-04-28 17:31:59 +02:00
Alba Rincón 0aac2c59ef Start using the `block.json` metadata file for the `Featured Product` block (https://github.com/woocommerce/woocommerce-blocks/pull/6296)
* Start using the `block.json` metadata file for the `Feature Product` block

* Get default attributes from the block.json file

* Add removed comment

* Remove unnecessary `get_block_metadata_defaults` function

* Add alt default to block.json
2022-04-28 17:04:56 +02:00
Alba Rincón 964f6e5965 Add new `alt` attribute to the `Featured Product` media settings (https://github.com/woocommerce/woocommerce-blocks/pull/6308)
* Add new `alt` attribute to Media Settings

Allow to define an alt text for the Feature Product block

* Simplify on change

* Improve alt description and use name instead of short description

Short description can contain html and images, so it's not adequate to use on the alt attribute
2022-04-28 16:28:22 +02:00