From 521f93619bb98f04bd128524ce812a9c14183280 Mon Sep 17 00:00:00 2001 From: "Michael P. Pfeiffer" Date: Wed, 15 Jun 2022 11:56:52 +0200 Subject: [PATCH] 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 --- plugins/woocommerce-blocks/.markdownlint.json | 4 +- .../product-elements/add-to-cart/block.js | 5 +- .../attribute-select-control.js | 15 +- .../add-to-cart/shared/add-to-cart-button.js | 9 +- .../blocks/product-elements/button/block.js | 3 +- .../product-elements/category-list/block.tsx | 3 +- .../blocks/product-elements/image/block.js | 3 +- .../blocks/product-elements/image/edit.js | 8 +- .../product-elements/image/test/block.test.js | 6 +- .../blocks/product-elements/price/block.js | 3 +- .../product-elements/stock-indicator/block.js | 15 +- .../blocks/product-elements/summary/block.js | 6 +- .../blocks/product-elements/tag-list/block.js | 3 +- .../blocks/product-elements/title/block.tsx | 6 +- .../address-form/address-form.tsx | 11 +- .../cart-checkout/address-form/test/index.js | 7 +- .../cart-checkout/form-step/index.tsx | 3 +- .../shipping-calculator/address.tsx | 6 +- .../package-rates.tsx | 8 +- .../totals/footer-item/stories/index.tsx | 3 +- .../cart-checkout/totals/shipping/index.tsx | 5 +- .../js/base/components/combobox/index.tsx | 10 +- .../country-input/country-input.tsx | 3 +- .../country-input/stories/index.tsx | 6 +- .../js/base/components/drawer/index.tsx | 9 +- .../js/base/components/price-slider/utils.ts | 60 +- .../components/product-list/product-list.tsx | 5 +- .../js/base/components/product-list/types.ts | 4 +- .../radio-control-accordion/index.js | 3 +- .../base/components/radio-control/option.tsx | 15 +- .../reviews/review-list-item/index.js | 3 +- .../context/event-emit/emitter-callback.ts | 17 +- .../cart/test/use-store-cart-item-quantity.js | 27 +- .../context/hooks/cart/test/use-store-cart.js | 24 +- .../cart/use-store-cart-item-quantity.ts | 11 +- .../base/context/hooks/cart/use-store-cart.ts | 5 +- .../hooks/collections/test/use-collection.js | 16 +- .../hooks/collections/use-collection-data.ts | 12 +- .../use-payment-method-interface.ts | 10 +- .../shipping/use-select-shipping-rate.ts | 4 +- .../hooks/shipping/use-shipping-data.ts | 5 +- .../context/hooks/test/use-store-products.js | 17 +- .../context/hooks/use-checkout-address.ts | 6 +- .../base/context/hooks/use-checkout-submit.js | 6 +- .../js/base/context/hooks/use-validation.ts | 12 +- .../add-to-cart-form/form-state/index.js | 24 +- .../add-to-cart-form/form/submit/index.js | 15 +- .../cart-checkout/checkout-state/index.tsx | 25 +- .../cart-checkout/checkout-state/utils.ts | 5 +- .../payment-methods/constants.ts | 23 +- .../payment-method-data-context.tsx | 11 +- .../test/payment-method-data-context.js | 6 +- .../use-payment-method-registration.ts | 8 +- .../providers/cart-checkout/shipping/index.js | 12 +- .../assets/js/base/context/tsconfig.json | 2 +- .../assets/js/base/hocs/with-reviews.js | 14 +- .../test/use-position-relative-to-viewport.js | 6 +- .../assets/js/base/hooks/test/use-previous.js | 20 +- .../use-position-relative-to-viewport.js | 6 +- .../express-payment-method-config.ts | 3 +- .../payment-methods/extensions-config.ts | 6 +- .../payment-method-config-helper.ts | 110 +- .../payment-methods/payment-method-config.tsx | 6 +- .../payment-methods/registry.ts | 6 +- .../test/payment-method-config-helper.ts | 11 +- .../active-attribute-filters.js | 3 +- .../assets/js/blocks/active-filters/block.js | 5 +- .../js/blocks/attribute-filter/block.js | 51 +- .../express-payment-methods.js | 6 +- .../payment-methods/payment-method-card.js | 6 +- .../payment-methods/payment-method-options.js | 6 +- .../payment-methods/test/payment-methods.js | 24 +- .../cart-checkout-shared/use-forced-layout.ts | 17 +- .../use-view-switcher.tsx | 7 +- .../cart-line-item-row.tsx | 13 +- .../cart-express-payment-block/edit.tsx | 3 +- .../cart-order-summary-shipping/edit.tsx | 3 +- .../cart-order-summary-taxes/edit.tsx | 3 +- .../inner-blocks/empty-cart-block/edit.tsx | 4 +- .../proceed-to-checkout-block/block.tsx | 6 +- .../cart/inner-blocks/register-components.ts | 187 +- .../assets/js/blocks/checkout/block.tsx | 12 +- .../assets/js/blocks/checkout/context.ts | 18 +- .../checkout/form-step/form-step-block.tsx | 3 +- .../checkout-billing-address-block/edit.tsx | 5 +- .../block.tsx | 7 +- .../checkout-express-payment-block/edit.tsx | 3 +- .../checkout-fields-block/edit.tsx | 9 +- .../test/block.js | 12 +- .../block.tsx | 5 +- .../checkout-order-summary-discount/block.tsx | 5 +- .../checkout-order-summary-taxes/edit.tsx | 3 +- .../checkout-shipping-address-block/edit.tsx | 5 +- .../checkout-shipping-methods-block/block.tsx | 5 +- .../checkout-terms-block/frontend.tsx | 7 +- .../checkout-terms-block/test/edit.js | 3 +- .../inner-blocks/register-components.ts | 185 +- .../blocks/featured-items/block-controls.tsx | 66 +- .../js/blocks/featured-items/image-editor.tsx | 58 +- .../featured-items/inspector-controls.tsx | 128 +- .../assets/js/blocks/featured-items/utils.ts | 5 +- .../blocks/featured-items/with-api-error.tsx | 42 +- .../blocks/featured-items/with-edit-mode.tsx | 166 +- .../featured-items/with-editing-image.tsx | 30 +- .../featured-items/with-featured-item.tsx | 421 ++-- .../with-update-button-attributes.tsx | 92 +- .../js/blocks/handpicked-products/block.json | 162 +- .../assets/js/blocks/mini-cart/block.tsx | 16 +- .../filled-mini-cart-contents-block/edit.tsx | 4 +- .../mini-cart-items-block/edit.tsx | 4 +- .../inner-blocks/register-components.ts | 63 +- .../assets/js/blocks/price-filter/block.tsx | 8 +- .../assets/js/blocks/price-filter/edit.tsx | 8 +- .../js/blocks/product-categories/block.js | 9 +- .../js/blocks/product-categories/index.js | 8 +- .../assets/js/blocks/product-tag/block.json | 169 +- .../blocks/products-by-attribute/block.json | 179 +- .../assets/js/blocks/stock-filter/block.tsx | 26 +- .../assets/js/blocks/stock-filter/edit.tsx | 9 +- .../assets/js/data/cart/actions.ts | 8 +- .../assets/js/data/cart/index.ts | 6 +- .../assets/js/data/cart/test/selectors.js | 12 +- .../assets/js/data/collections/resolvers.js | 6 +- .../assets/js/data/constants.ts | 16 +- .../assets/js/data/default-states.ts | 4 +- .../assets/js/data/mapped-types.ts | 18 +- .../assets/js/data/schema/selectors.js | 83 +- .../assets/js/data/schema/test/selectors.js | 17 +- .../external-link-card/stories/index.tsx | 3 +- .../product-tag-control/index.js | 9 +- .../search-list-control/types.ts | 2 +- .../search-list-control/utils.tsx | 4 +- .../js/extensions/google-analytics/utils.ts | 70 +- .../exclude-draft-status-from-analytics.js | 14 +- .../assets/js/middleware/store-api-nonce.js | 5 +- .../assets/js/previews/reviews.js | 8 +- .../shared/hocs/with-filtered-attributes.js | 26 +- .../bin/hook-docs/actions/index.js | 3 +- .../bin/hook-docs/data/actions.json | 1492 +++++++------ .../bin/hook-docs/data/filters.json | 1863 ++++++++--------- .../bin/hook-docs/filters/index.js | 3 +- .../woocommerce-blocks/bin/webpack-configs.js | 6 +- plugins/woocommerce-blocks/package-lock.json | 28 +- plugins/woocommerce-blocks/package.json | 3 +- .../components/discounts-meta/index.js | 6 +- .../checkout/components/order-meta/index.js | 5 +- .../checkout/filter-registry/index.ts | 6 +- .../packages/prices/utils/price.ts | 9 +- .../storybook/custom-controls/currency.ts | 16 +- .../best-selling-products.fixture.json | 5 +- .../featured-category.fixture.json | 5 +- .../hand-picked-products.fixture.json | 5 +- .../__fixtures__/newest-products.fixture.json | 5 +- .../product-categories-list.fixture.json | 5 +- .../top-rated-products.fixture.json | 5 +- .../tests/e2e/config/setup.js | 10 +- .../tests/e2e/fixtures/fixture-data.js | 24 +- .../tests/e2e/fixtures/fixture-loaders.js | 4 +- .../e2e/specs/backend/active-filters.test.js | 4 +- .../specs/backend/attribute-filter.test.js | 4 +- .../e2e/specs/backend/price-filter.test.js | 8 +- .../frontend/legacy-template-blocks.test.ts | 18 +- .../shopper/cart-checkout/account.test.js | 3 +- plugins/woocommerce-blocks/tests/e2e/utils.js | 3 +- .../tests/js/jestPreprocess.js | 5 +- .../woocommerce-blocks/tests/utils/shopper.js | 4 +- .../woocommerce-blocks/tests/utils/taxes.ts | 4 +- 167 files changed, 3292 insertions(+), 3625 deletions(-) diff --git a/plugins/woocommerce-blocks/.markdownlint.json b/plugins/woocommerce-blocks/.markdownlint.json index 5efe30c7d25..46f253c2e8f 100644 --- a/plugins/woocommerce-blocks/.markdownlint.json +++ b/plugins/woocommerce-blocks/.markdownlint.json @@ -1,5 +1,3 @@ - - { "default": true, "MD003": { "style": "atx" }, @@ -9,7 +7,7 @@ "MD025": false, "MD029": false, "MD033": false, - "MD046": {"style": "fenced"}, + "MD046": { "style": "fenced" }, "no-hard-tabs": false, "whitespace": false } diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/block.js b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/block.js index c2e55e6023a..7baba132098 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/block.js +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/block.js @@ -37,9 +37,8 @@ const Block = ( { className, showFormElements } ) => { className, 'wc-block-components-product-add-to-cart', { - 'wc-block-components-product-add-to-cart--placeholder': isEmpty( - product - ), + 'wc-block-components-product-add-to-cart--placeholder': + isEmpty( product ), } ); diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/product-types/variable/variation-attributes/attribute-select-control.js b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/product-types/variable/variation-attributes/attribute-select-control.js index df5a81ff6e5..adaf84d472e 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/product-types/variable/variation-attributes/attribute-select-control.js +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/product-types/variable/variation-attributes/attribute-select-control.js @@ -32,11 +32,8 @@ const AttributeSelectControl = ( { 'woo-gutenberg-products-block' ), } ) => { - const { - getValidationError, - setValidationErrors, - clearValidationError, - } = useValidationContext(); + const { getValidationError, setValidationErrors, clearValidationError } = + useValidationContext(); const errorId = attributeName; const error = getValidationError( errorId ) || {}; @@ -60,10 +57,10 @@ const AttributeSelectControl = ( { ] ); // Remove validation errors when unmounted. - useEffect( () => () => void clearValidationError( errorId ), [ - errorId, - clearValidationError, - ] ); + useEffect( + () => () => void clearValidationError( errorId ), + [ errorId, clearValidationError ] + ); return (
diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/shared/add-to-cart-button.js b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/shared/add-to-cart-button.js index e7b9d7b110f..27c4aa24aea 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/shared/add-to-cart-button.js +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/add-to-cart/shared/add-to-cart-button.js @@ -45,10 +45,11 @@ const AddToCartButton = () => { } return true; }; - const unsubscribeProcessing = eventRegistration.onAddToCartAfterProcessingWithSuccess( - onSuccess, - 0 - ); + const unsubscribeProcessing = + eventRegistration.onAddToCartAfterProcessingWithSuccess( + onSuccess, + 0 + ); return () => { unsubscribeProcessing(); }; diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/button/block.js b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/button/block.js index dd256977aae..39502458492 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/button/block.js +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/button/block.js @@ -52,7 +52,8 @@ const Block = ( props ) => { 'wp-block-button', 'wc-block-components-product-button', { - [ `${ parentClassName }__product-add-to-cart` ]: parentClassName, + [ `${ parentClassName }__product-add-to-cart` ]: + parentClassName, } ) } > diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/category-list/block.tsx b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/category-list/block.tsx index 3fc4bbe8c44..afbf64c5914 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/category-list/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/category-list/block.tsx @@ -49,7 +49,8 @@ const Block = ( props: Props ): JSX.Element | null => { 'wc-block-components-product-category-list', colorProps.className, { - [ `${ parentClassName }__product-category-list` ]: parentClassName, + [ `${ parentClassName }__product-category-list` ]: + parentClassName, } ) } style={ { ...colorProps.style, ...typographyProps.style } } diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/block.js b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/block.js index 70d7630f80e..d5c296036b9 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/block.js +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/block.js @@ -60,7 +60,8 @@ export const Block = ( props ) => { className, 'wc-block-components-product-image', { - [ `${ parentClassName }__product-image` ]: parentClassName, + [ `${ parentClassName }__product-image` ]: + parentClassName, }, borderProps.className ) } diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/edit.js b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/edit.js index d1a49967610..f0deda5fc50 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/edit.js +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/edit.js @@ -23,12 +23,8 @@ import withProductSelector from '../shared/with-product-selector'; import { BLOCK_TITLE, BLOCK_ICON } from './constants'; const Edit = ( { attributes, setAttributes } ) => { - const { - showProductLink, - imageSizing, - showSaleBadge, - saleBadgeAlign, - } = attributes; + const { showProductLink, imageSizing, showSaleBadge, saleBadgeAlign } = + attributes; const blockProps = useBlockProps(); diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/test/block.test.js b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/test/block.test.js index f7002908285..802f2a516a0 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/test/block.test.js +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/image/test/block.test.js @@ -46,8 +46,7 @@ const productWithImages = { id: 56, src: 'logo-1.jpg', thumbnail: 'logo-1-324x324.jpg', - srcset: - 'logo-1.jpg 800w, logo-1-300x300.jpg 300w, logo-1-150x150.jpg 150w, logo-1-768x767.jpg 768w, logo-1-324x324.jpg 324w, logo-1-416x415.jpg 416w, logo-1-100x100.jpg 100w', + srcset: 'logo-1.jpg 800w, logo-1-300x300.jpg 300w, logo-1-150x150.jpg 150w, logo-1-768x767.jpg 768w, logo-1-324x324.jpg 324w, logo-1-416x415.jpg 416w, logo-1-100x100.jpg 100w', sizes: '(max-width: 800px) 100vw, 800px', name: 'logo-1.jpg', alt: '', @@ -56,8 +55,7 @@ const productWithImages = { id: 55, src: 'beanie-with-logo-1.jpg', thumbnail: 'beanie-with-logo-1-324x324.jpg', - srcset: - 'beanie-with-logo-1.jpg 800w, beanie-with-logo-1-300x300.jpg 300w, beanie-with-logo-1-150x150.jpg 150w, beanie-with-logo-1-768x768.jpg 768w, beanie-with-logo-1-324x324.jpg 324w, beanie-with-logo-1-416x416.jpg 416w, beanie-with-logo-1-100x100.jpg 100w', + srcset: 'beanie-with-logo-1.jpg 800w, beanie-with-logo-1-300x300.jpg 300w, beanie-with-logo-1-150x150.jpg 150w, beanie-with-logo-1-768x768.jpg 768w, beanie-with-logo-1-324x324.jpg 324w, beanie-with-logo-1-416x416.jpg 416w, beanie-with-logo-1-100x100.jpg 100w', sizes: '(max-width: 800px) 100vw, 800px', name: 'beanie-with-logo-1.jpg', alt: '', diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/block.js b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/block.js index 2f748f50e6a..3831aa10be6 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/block.js +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/block.js @@ -79,7 +79,8 @@ const Block = ( props ) => { // This is the regular or original price when the `price` value is a sale price. regularPrice={ prices.regular_price } regularPriceClassName={ classnames( { - [ `${ parentClassName }__product-price__regular` ]: parentClassName, + [ `${ parentClassName }__product-price__regular` ]: + parentClassName, } ) } /> ); diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/stock-indicator/block.js b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/stock-indicator/block.js index 82b737a5f75..66b1d56aa89 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/stock-indicator/block.js +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/stock-indicator/block.js @@ -48,11 +48,16 @@ const Block = ( props ) => { colorProps.className, 'wc-block-components-product-stock-indicator', { - [ `${ parentClassName }__stock-indicator` ]: parentClassName, - 'wc-block-components-product-stock-indicator--in-stock': inStock, - 'wc-block-components-product-stock-indicator--out-of-stock': ! inStock, - 'wc-block-components-product-stock-indicator--low-stock': !! lowStock, - 'wc-block-components-product-stock-indicator--available-on-backorder': !! isBackordered, + [ `${ parentClassName }__stock-indicator` ]: + parentClassName, + 'wc-block-components-product-stock-indicator--in-stock': + inStock, + 'wc-block-components-product-stock-indicator--out-of-stock': + ! inStock, + 'wc-block-components-product-stock-indicator--low-stock': + !! lowStock, + 'wc-block-components-product-stock-indicator--available-on-backorder': + !! isBackordered, } ) } style={ { ...colorProps.style, ...typographyProps.style } } diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/summary/block.js b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/summary/block.js index 716bb7fc127..aa387969df6 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/summary/block.js +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/summary/block.js @@ -43,7 +43,8 @@ const Block = ( props ) => { className, `wc-block-components-product-summary`, { - [ `${ parentClassName }__product-summary` ]: parentClassName, + [ `${ parentClassName }__product-summary` ]: + parentClassName, } ) } /> @@ -65,7 +66,8 @@ const Block = ( props ) => { colorProps.className, `wc-block-components-product-summary`, { - [ `${ parentClassName }__product-summary` ]: parentClassName, + [ `${ parentClassName }__product-summary` ]: + parentClassName, } ) } source={ source } diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/tag-list/block.js b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/tag-list/block.js index 685dec13502..39d3aad3381 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/tag-list/block.js +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/tag-list/block.js @@ -45,7 +45,8 @@ const Block = ( props ) => { colorProps.className, 'wc-block-components-product-tag-list', { - [ `${ parentClassName }__product-tag-list` ]: parentClassName, + [ `${ parentClassName }__product-tag-list` ]: + parentClassName, } ) } style={ { ...colorProps.style, ...typographyProps.style } } diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/title/block.tsx b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/title/block.tsx index aad699b032c..7070803b976 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/title/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/title/block.tsx @@ -33,7 +33,8 @@ interface TagNameProps extends HTMLAttributes< HTMLOrSVGElement > { const TagName = ( { children, headingLevel, - elementType: ElementType = `h${ headingLevel }` as keyof JSX.IntrinsicElements, + elementType: + ElementType = `h${ headingLevel }` as keyof JSX.IntrinsicElements, ...props }: TagNameProps ): JSX.Element => { return { children }; @@ -77,7 +78,8 @@ export const Block = ( props: Props ): JSX.Element => { colorProps.className, 'wc-block-components-product-title', { - [ `${ parentClassName }__product-title` ]: parentClassName, + [ `${ parentClassName }__product-title` ]: + parentClassName, [ `wc-block-components-product-title--align-${ align }` ]: align && isFeaturePluginBuild(), } diff --git a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/address-form/address-form.tsx b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/address-form/address-form.tsx index e90fec28c07..3b3a4e238be 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/address-form/address-form.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/address-form/address-form.tsx @@ -78,20 +78,17 @@ interface AddressFormProps { */ const AddressForm = ( { id = '', - fields = ( Object.keys( + fields = Object.keys( defaultAddressFields - ) as unknown ) as ( keyof AddressFields )[], + ) as unknown as ( keyof AddressFields )[], fieldConfig = {} as Record< keyof AddressFields, Partial< AddressField > >, instanceId, onChange, type = 'shipping', values, }: AddressFormProps ): JSX.Element => { - const { - getValidationError, - setValidationErrors, - clearValidationError, - } = useValidationContext(); + const { getValidationError, setValidationErrors, clearValidationError } = + useValidationContext(); const currentFields = useShallowEqual( fields ); diff --git a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/address-form/test/index.js b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/address-form/test/index.js index 200f190db75..3b04d30e847 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/address-form/test/index.js +++ b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/address-form/test/index.js @@ -81,11 +81,8 @@ const inputAddress = async ( { describe( 'AddressForm Component', () => { const WrappedAddressForm = ( { type } ) => { - const { - defaultAddressFields, - setShippingAddress, - shippingAddress, - } = useCheckoutAddress(); + const { defaultAddressFields, setShippingAddress, shippingAddress } = + useCheckoutAddress(); return ( { const [ address, setAddress ] = useState( initialAddress ); - const { - hasValidationErrors, - showAllValidationErrors, - } = useValidationContext(); + const { hasValidationErrors, showAllValidationErrors } = + useValidationContext(); const validateSubmit = () => { showAllValidationErrors(); diff --git a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/shipping-rates-control-package/package-rates.tsx b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/shipping-rates-control-package/package-rates.tsx index 045ddb79164..ff3318d776c 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/shipping-rates-control-package/package-rates.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/cart-checkout/shipping-rates-control-package/package-rates.tsx @@ -62,12 +62,8 @@ const PackageRates = ( { ); } - const { - label, - secondaryLabel, - description, - secondaryDescription, - } = renderOption( rates[ 0 ] ); + const { label, secondaryLabel, description, secondaryDescription } = + renderOption( rates[ 0 ] ); return ( { - const [ isShippingCalculatorOpen, setIsShippingCalculatorOpen ] = useState( - false - ); + const [ isShippingCalculatorOpen, setIsShippingCalculatorOpen ] = + useState( false ); const { shippingAddress, cartHasCalculatedShipping, diff --git a/plugins/woocommerce-blocks/assets/js/base/components/combobox/index.tsx b/plugins/woocommerce-blocks/assets/js/base/components/combobox/index.tsx index c29df06c5c4..f0a492fa948 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/combobox/index.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/combobox/index.tsx @@ -55,11 +55,8 @@ const Combobox = ( { instanceId = '0', autoComplete = 'off', }: ComboboxProps ): JSX.Element => { - const { - getValidationError, - setValidationErrors, - clearValidationError, - } = useValidationContext(); + const { getValidationError, setValidationErrors, clearValidationError } = + useValidationContext(); const controlRef = useRef< HTMLDivElement >( null ); const controlId = id || 'control-' + instanceId; @@ -126,7 +123,8 @@ const Combobox = ( { } // Try to match. - const normalizedFilterValue = filterValue.toLocaleUpperCase(); + const normalizedFilterValue = + filterValue.toLocaleUpperCase(); const foundOption = options.find( ( option ) => option.label diff --git a/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.tsx b/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.tsx index 7ef10861325..5a8d6a1a8dd 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/country-input/country-input.tsx @@ -64,7 +64,8 @@ export const CountryInput = ( { autoComplete={ autoComplete } value={ value } onChange={ ( event ) => { - const textValue = event.target.value.toLocaleUpperCase(); + const textValue = + event.target.value.toLocaleUpperCase(); const foundOption = options.find( ( option ) => ( textValue.length !== 2 && diff --git a/plugins/woocommerce-blocks/assets/js/base/components/country-input/stories/index.tsx b/plugins/woocommerce-blocks/assets/js/base/components/country-input/stories/index.tsx index a065b72d2f4..bc2ffa59475 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/country-input/stories/index.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/country-input/stories/index.tsx @@ -44,10 +44,8 @@ const Template: Story< CountryInputWithCountriesProps > = ( args ) => { const [ selectedCountry, selectCountry ] = useState< CountryCode | '' >( '' ); - const { - clearValidationError, - showValidationError, - } = useValidationContext(); + const { clearValidationError, showValidationError } = + useValidationContext(); useEffect( () => { showValidationError( 'country' ); diff --git a/plugins/woocommerce-blocks/assets/js/base/components/drawer/index.tsx b/plugins/woocommerce-blocks/assets/js/base/components/drawer/index.tsx index ff7a4345ec5..ff4c3cb0586 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/drawer/index.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/drawer/index.tsx @@ -46,9 +46,12 @@ const Drawer = ( { overlayClassName={ classNames( 'wc-block-components-drawer__screen-overlay', { - 'wc-block-components-drawer__screen-overlay--is-hidden': ! isOpen, - 'wc-block-components-drawer__screen-overlay--with-slide-in': slideIn, - 'wc-block-components-drawer__screen-overlay--with-slide-out': slideOut, + 'wc-block-components-drawer__screen-overlay--is-hidden': + ! isOpen, + 'wc-block-components-drawer__screen-overlay--with-slide-in': + slideIn, + 'wc-block-components-drawer__screen-overlay--with-slide-out': + slideOut, } ) } closeButtonLabel={ __( diff --git a/plugins/woocommerce-blocks/assets/js/base/components/price-slider/utils.ts b/plugins/woocommerce-blocks/assets/js/base/components/price-slider/utils.ts index c712315cdbb..496d1c8d480 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/price-slider/utils.ts +++ b/plugins/woocommerce-blocks/assets/js/base/components/price-slider/utils.ts @@ -6,36 +6,42 @@ import type { NumberFormatValues } from 'react-number-format'; /** Check if that the value is minor than the max price and greater than 0. */ -export const isValidMaxValue = ( { - maxConstraint, - minorUnit, -}: { - maxConstraint: number; - minorUnit: number; -} ) => ( { floatValue }: NumberFormatValues ): boolean => { - const maxPrice = maxConstraint / 10 ** minorUnit; +export const isValidMaxValue = + ( { + maxConstraint, + minorUnit, + }: { + maxConstraint: number; + minorUnit: number; + } ) => + ( { floatValue }: NumberFormatValues ): boolean => { + const maxPrice = maxConstraint / 10 ** minorUnit; - return floatValue !== undefined && floatValue <= maxPrice && floatValue > 0; -}; + return ( + floatValue !== undefined && floatValue <= maxPrice && floatValue > 0 + ); + }; /** Check if that the value is minor than the max price and greater than 0. */ -export const isValidMinValue = ( { - minConstraint, - currentMaxValue, - minorUnit, -}: { - minConstraint: number; - currentMaxValue: number; - minorUnit: number; -} ) => ( { floatValue }: NumberFormatValues ): boolean => { - const minPrice = minConstraint / 10 ** minorUnit; - const currentMaxPrice = currentMaxValue / 10 ** minorUnit; +export const isValidMinValue = + ( { + minConstraint, + currentMaxValue, + minorUnit, + }: { + minConstraint: number; + currentMaxValue: number; + minorUnit: number; + } ) => + ( { floatValue }: NumberFormatValues ): boolean => { + const minPrice = minConstraint / 10 ** minorUnit; + const currentMaxPrice = currentMaxValue / 10 ** minorUnit; - return ( - floatValue !== undefined && - floatValue >= minPrice && - floatValue < currentMaxPrice - ); -}; + return ( + floatValue !== undefined && + floatValue >= minPrice && + floatValue < currentMaxPrice + ); + }; diff --git a/plugins/woocommerce-blocks/assets/js/base/components/product-list/product-list.tsx b/plugins/woocommerce-blocks/assets/js/base/components/product-list/product-list.tsx index e8b47a7a0c9..c2d0ca4b2e0 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/product-list/product-list.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/product-list/product-list.tsx @@ -142,9 +142,8 @@ const ProductList = ( { currentPage, } ) ); - const { products, totalProducts, productsLoading } = useStoreProducts( - queryState - ); + const { products, totalProducts, productsLoading } = + useStoreProducts( queryState ); const { parentClassName, parentName } = useInnerBlockLayoutContext(); const totalQuery = extractPaginationAndSortAttributes( queryState ); const { dispatchStoreEvent } = useStoreEvents(); diff --git a/plugins/woocommerce-blocks/assets/js/base/components/product-list/types.ts b/plugins/woocommerce-blocks/assets/js/base/components/product-list/types.ts index 8588811563c..983bbb8372e 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/product-list/types.ts +++ b/plugins/woocommerce-blocks/assets/js/base/components/product-list/types.ts @@ -37,9 +37,7 @@ export type TotalQuery = Pick< Query, 'catalog_visibility' >; export type GenerateQuery = ( props: GenerateQueryProps ) => Query; -export type GetSortArgs = ( - orderName: string -) => +export type GetSortArgs = ( orderName: string ) => | { orderby: string; order: string; diff --git a/plugins/woocommerce-blocks/assets/js/base/components/radio-control-accordion/index.js b/plugins/woocommerce-blocks/assets/js/base/components/radio-control-accordion/index.js index 90dff648602..6d01e3bd5af 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/radio-control-accordion/index.js +++ b/plugins/woocommerce-blocks/assets/js/base/components/radio-control-accordion/index.js @@ -54,7 +54,8 @@ const RadioControlAccordion = ( { className={ classnames( 'wc-block-components-radio-control-accordion-content', { - 'wc-block-components-radio-control-accordion-content-hide': ! checked, + 'wc-block-components-radio-control-accordion-content-hide': + ! checked, } ) } > diff --git a/plugins/woocommerce-blocks/assets/js/base/components/radio-control/option.tsx b/plugins/woocommerce-blocks/assets/js/base/components/radio-control/option.tsx index 3ff328592d7..00af90e8749 100644 --- a/plugins/woocommerce-blocks/assets/js/base/components/radio-control/option.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/components/radio-control/option.tsx @@ -15,13 +15,8 @@ const Option = ( { onChange, option, }: RadioControlOptionProps ): JSX.Element => { - const { - value, - label, - description, - secondaryLabel, - secondaryDescription, - } = option; + const { value, label, description, secondaryLabel, secondaryDescription } = + option; const onChangeValue = ( event: React.ChangeEvent< HTMLInputElement > ) => onChange( event.target.value ); @@ -30,7 +25,8 @@ const Option = ( { className={ classnames( 'wc-block-components-radio-control__option', { - 'wc-block-components-radio-control__option-checked': checked, + 'wc-block-components-radio-control__option-checked': + checked, } ) } htmlFor={ `${ name }-${ value }` } @@ -47,7 +43,8 @@ const Option = ( { [ `${ name }-${ value }__label` ]: label, [ `${ name }-${ value }__secondary-label` ]: secondaryLabel, [ `${ name }-${ value }__description` ]: description, - [ `${ name }-${ value }__secondary-description` ]: secondaryDescription, + [ `${ name }-${ value }__secondary-description` ]: + secondaryDescription, } ) } /> { 'wc-block-components-review-list-item__item', { 'is-loading': isLoading, - 'wc-block-components-review-list-item__item--has-image': showReviewImage, + 'wc-block-components-review-list-item__item--has-image': + showReviewImage, } ) } aria-hidden={ isLoading } diff --git a/plugins/woocommerce-blocks/assets/js/base/context/event-emit/emitter-callback.ts b/plugins/woocommerce-blocks/assets/js/base/context/event-emit/emitter-callback.ts index d5efc6520f4..92445a2317c 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/event-emit/emitter-callback.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/event-emit/emitter-callback.ts @@ -4,13 +4,12 @@ import { actions } from './reducer'; import type { ActionType, ActionCallbackType } from './types'; -export const emitterCallback = ( - type: string, - observerDispatch: React.Dispatch< ActionType > -) => ( callback: ActionCallbackType, priority = 10 ): ( () => void ) => { - const action = actions.addEventCallback( type, callback, priority ); - observerDispatch( action ); - return () => { - observerDispatch( actions.removeEventCallback( type, action.id ) ); +export const emitterCallback = + ( type: string, observerDispatch: React.Dispatch< ActionType > ) => + ( callback: ActionCallbackType, priority = 10 ): ( () => void ) => { + const action = actions.addEventCallback( type, callback, priority ); + observerDispatch( action ); + return () => { + observerDispatch( actions.removeEventCallback( type, action.id ) ); + }; }; -}; diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/test/use-store-cart-item-quantity.js b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/test/use-store-cart-item-quantity.js index 6108655a7c3..2fe44a1e3de 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/test/use-store-cart-item-quantity.js +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/test/use-store-cart-item-quantity.js @@ -95,10 +95,8 @@ describe( 'useStoreCartItemQuantity', () => { ); } ); - //eslint-disable-next-line testing-library/await-async-query - const { setItemQuantity, quantity } = renderer.root.findByType( - 'div' - ).props; + const { setItemQuantity, quantity } = + renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query expect( quantity ).toBe( 1 ); @@ -106,10 +104,8 @@ describe( 'useStoreCartItemQuantity', () => { setItemQuantity( 2 ); } ); - //eslint-disable-next-line testing-library/await-async-query - const { quantity: newQuantity } = renderer.root.findByType( - 'div' - ).props; + const { quantity: newQuantity } = + renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query expect( newQuantity ).toBe( 2 ); } ); @@ -126,8 +122,7 @@ describe( 'useStoreCartItemQuantity', () => { ); } ); - //eslint-disable-next-line testing-library/await-async-query - const { removeItem } = renderer.root.findByType( 'div' ).props; + const { removeItem } = renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query act( () => { removeItem(); @@ -148,8 +143,7 @@ describe( 'useStoreCartItemQuantity', () => { ); } ); - //eslint-disable-next-line testing-library/await-async-query - const { setItemQuantity } = renderer.root.findByType( 'div' ).props; + const { setItemQuantity } = renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query act( () => { setItemQuantity( 2 ); @@ -182,10 +176,8 @@ describe( 'useStoreCartItemQuantity', () => { ); } ); - //eslint-disable-next-line testing-library/await-async-query - const { cartItemQuantityErrors } = renderer.root.findByType( - 'div' - ).props; + const { cartItemQuantityErrors } = + renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query expect( cartItemQuantityErrors ).toEqual( mockCartErrors ); } ); @@ -210,8 +202,7 @@ describe( 'useStoreCartItemQuantity', () => { ); } ); - //eslint-disable-next-line testing-library/await-async-query - const { isPendingDelete } = renderer.root.findByType( 'div' ).props; + const { isPendingDelete } = renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query expect( isPendingDelete ).toBe( true ); } ); diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/test/use-store-cart.js b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/test/use-store-cart.js index 9a63fb9c175..ffd5d7e1666 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/test/use-store-cart.js +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/test/use-store-cart.js @@ -189,14 +189,10 @@ describe( 'useStoreCart', () => { ); } ); - //eslint-disable-next-line testing-library/await-async-query - const { results, receiveCart } = renderer.root.findByType( - 'div' - ).props; - const { - receiveCart: defaultReceiveCart, - ...remaining - } = defaultCartData; + const { results, receiveCart } = + renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query + const { receiveCart: defaultReceiveCart, ...remaining } = + defaultCartData; expect( results ).toEqual( remaining ); expect( receiveCart ).toEqual( defaultReceiveCart ); } ); @@ -212,10 +208,8 @@ describe( 'useStoreCart', () => { ); } ); - //eslint-disable-next-line testing-library/await-async-query - const { results, receiveCart } = renderer.root.findByType( - 'div' - ).props; + const { results, receiveCart } = + renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query expect( results ).toEqual( mockStoreCartData ); expect( receiveCart ).toBeUndefined(); @@ -244,10 +238,8 @@ describe( 'useStoreCart', () => { ); } ); - //eslint-disable-next-line testing-library/await-async-query - const { results, receiveCart } = renderer.root.findByType( - 'div' - ).props; + const { results, receiveCart } = + renderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query expect( results ).toEqual( previewCartData ); expect( receiveCart ).toEqual( receiveCartMock ); diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart-item-quantity.ts b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart-item-quantity.ts index e6395a2e6b6..d5d96fa1d22 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart-item-quantity.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart-item-quantity.ts @@ -51,10 +51,8 @@ export const useStoreCartItemQuantity = ( verifiedCartItem.key = cartItem.key; verifiedCartItem.quantity = cartItem.quantity; } - const { - key: cartItemKey = '', - quantity: cartItemQuantity = 1, - } = verifiedCartItem; + const { key: cartItemKey = '', quantity: cartItemQuantity = 1 } = + verifiedCartItem; const { cartErrors } = useStoreCart(); const { dispatchActions } = useCheckoutContext(); @@ -62,9 +60,8 @@ export const useStoreCartItemQuantity = ( const [ quantity, setQuantity ] = useState< number >( cartItemQuantity ); const [ debouncedQuantity ] = useDebounce< number >( quantity, 400 ); const previousDebouncedQuantity = usePrevious( debouncedQuantity ); - const { removeItemFromCart, changeCartItemQuantity } = useDispatch( - storeKey - ); + const { removeItemFromCart, changeCartItemQuantity } = + useDispatch( storeKey ); // Update local state when server updates. useEffect( () => setQuantity( cartItemQuantity ), [ cartItemQuantity ] ); diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart.ts b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart.ts index f14252e0505..ff130605775 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/cart/use-store-cart.ts @@ -179,9 +179,8 @@ export const useStoreCart = ( const cartData = store.getCartData(); const cartErrors = store.getCartErrors(); const cartTotals = store.getCartTotals(); - const cartIsLoading = ! store.hasFinishedResolution( - 'getCartData' - ); + const cartIsLoading = + ! store.hasFinishedResolution( 'getCartData' ); const isLoadingRates = store.isCustomerDataUpdating(); const { receiveCart } = dispatch( storeKey ); diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/collections/test/use-collection.js b/plugins/woocommerce-blocks/assets/js/base/context/hooks/collections/test/use-collection.js index a959b56d9d7..2d1cb5178d4 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/collections/test/use-collection.js +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/collections/test/use-collection.js @@ -38,10 +38,8 @@ class TestErrorBoundary extends ReactComponent { describe( 'useCollection', () => { let registry, mocks, renderer; const getProps = ( testRenderer ) => { - //eslint-disable-next-line testing-library/await-async-query - const { results, isLoading } = testRenderer.root.findByType( - 'div' - ).props; + const { results, isLoading } = + testRenderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query return { results, isLoading, @@ -56,10 +54,12 @@ describe( 'useCollection', () => { ); - const getTestComponent = () => ( { options } ) => { - const items = useCollection( options ); - return
; - }; + const getTestComponent = + () => + ( { options } ) => { + const items = useCollection( options ); + return
; + }; const setUpMocks = () => { mocks = { diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/collections/use-collection-data.ts b/plugins/woocommerce-blocks/assets/js/base/context/hooks/collections/use-collection-data.ts index 0d246958156..1e887193191 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/collections/use-collection-data.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/collections/use-collection-data.ts @@ -57,14 +57,10 @@ export const useCollectionData = ( { context = `${ context }-collection-data`; const [ collectionDataQueryState ] = useQueryStateByContext( context ); - const [ - calculateAttributesQueryState, - setCalculateAttributesQueryState, - ] = useQueryStateByKey( 'calculate_attribute_counts', [], context ); - const [ - calculatePriceRangeQueryState, - setCalculatePriceRangeQueryState, - ] = useQueryStateByKey( 'calculate_price_range', null, context ); + const [ calculateAttributesQueryState, setCalculateAttributesQueryState ] = + useQueryStateByKey( 'calculate_attribute_counts', [], context ); + const [ calculatePriceRangeQueryState, setCalculatePriceRangeQueryState ] = + useQueryStateByKey( 'calculate_price_range', null, context ); const [ calculateStockStatusQueryState, setCalculateStockStatusQueryState, diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/payment-methods/use-payment-method-interface.ts b/plugins/woocommerce-blocks/assets/js/base/context/hooks/payment-methods/use-payment-method-interface.ts index 9ee6a9e4f6d..7e460a3eb62 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/payment-methods/use-payment-method-interface.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/payment-methods/use-payment-method-interface.ts @@ -64,11 +64,8 @@ export const usePaymentMethodInterface = (): PaymentMethodInterface => { selectShippingRate, needsShipping, } = useShippingData(); - const { - billingAddress, - shippingAddress, - setShippingAddress, - } = useCustomerDataContext(); + const { billingAddress, shippingAddress, setShippingAddress } = + useCustomerDataContext(); const { cartItems, cartFees, cartTotals, extensions } = useStoreCart(); const { appliedCoupons } = useStoreCartCoupons(); const { noticeContexts, responseTypes } = useEmitResponse(); @@ -98,8 +95,7 @@ export const usePaymentMethodInterface = (): PaymentMethodInterface => { { alternative: '', plugin: 'woocommerce-gutenberg-products-block', - link: - 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4228', + link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4228', } ); setExpressPaymentError( errorMessage ); diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/shipping/use-select-shipping-rate.ts b/plugins/woocommerce-blocks/assets/js/base/context/hooks/shipping/use-select-shipping-rate.ts index 7f25cd55bd1..22b2a669f00 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/shipping/use-select-shipping-rate.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/shipping/use-select-shipping-rate.ts @@ -23,11 +23,11 @@ export const useSelectShippingRate = (): SelectShippingRateType => { const throwError = useThrowError(); const { dispatchCheckoutEvent } = useStoreEvents(); - const { selectShippingRate: dispatchSelectShippingRate } = ( useDispatch( + const { selectShippingRate: dispatchSelectShippingRate } = useDispatch( storeKey ) as { selectShippingRate: unknown; - } ) as { + } as { selectShippingRate: ( newShippingRateId: string, packageId: string | number diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/shipping/use-shipping-data.ts b/plugins/woocommerce-blocks/assets/js/base/context/hooks/shipping/use-shipping-data.ts index c1e0136da47..1759a0aba49 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/shipping/use-shipping-data.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/shipping/use-shipping-data.ts @@ -43,9 +43,8 @@ export const useShippingData = (): ShippingData => { // set selected rates on ref so it's always current. const selectedRates = useRef< Record< string, unknown > >( {} ); useEffect( () => { - const derivedSelectedRates = deriveSelectedShippingRates( - shippingRates - ); + const derivedSelectedRates = + deriveSelectedShippingRates( shippingRates ); if ( isObject( derivedSelectedRates ) && ! isShallowEqual( selectedRates.current, derivedSelectedRates ) diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/test/use-store-products.js b/plugins/woocommerce-blocks/assets/js/base/context/hooks/test/use-store-products.js index cf72d6520e0..5695994b662 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/test/use-store-products.js +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/test/use-store-products.js @@ -18,11 +18,8 @@ jest.mock( '@woocommerce/block-data', () => ( { describe( 'useStoreProducts', () => { let registry, mocks, renderer; const getProps = ( testRenderer ) => { - const { - products, - totalProducts, - productsLoading, - } = testRenderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query + const { products, totalProducts, productsLoading } = + testRenderer.root.findByType( 'div' ).props; //eslint-disable-line testing-library/await-async-query return { products, totalProducts, @@ -36,10 +33,12 @@ describe( 'useStoreProducts', () => { ); - const getTestComponent = () => ( { query } ) => { - const items = useStoreProducts( query ); - return
; - }; + const getTestComponent = + () => + ( { query } ) => { + const items = useStoreProducts( query ); + return
; + }; const setUpMocks = () => { mocks = { diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-checkout-address.ts b/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-checkout-address.ts index 445bd559489..4b06b7fcb0c 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-checkout-address.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-checkout-address.ts @@ -37,10 +37,8 @@ interface CheckoutAddress { */ export const useCheckoutAddress = (): CheckoutAddress => { const { needsShipping } = useShippingData(); - const { - useShippingAsBilling, - setUseShippingAsBilling, - } = useCheckoutContext(); + const { useShippingAsBilling, setUseShippingAsBilling } = + useCheckoutContext(); const { billingAddress, setBillingAddress, diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-checkout-submit.js b/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-checkout-submit.js index 728fa7a4947..391749dd211 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-checkout-submit.js +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-checkout-submit.js @@ -25,10 +25,8 @@ export const useCheckoutSubmit = () => { hasError, } = useCheckoutContext(); const { paymentMethods = {} } = usePaymentMethods(); - const { - activePaymentMethod, - currentStatus: paymentStatus, - } = usePaymentMethodDataContext(); + const { activePaymentMethod, currentStatus: paymentStatus } = + usePaymentMethodDataContext(); const paymentMethod = paymentMethods[ activePaymentMethod ] || {}; const waitingForProcessing = isProcessing || isAfterProcessing || isBeforeProcessing; diff --git a/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-validation.ts b/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-validation.ts index 5489a41d68b..8145d5a6dd3 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-validation.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/hooks/use-validation.ts @@ -46,12 +46,12 @@ export const useValidation = (): ValidationData => { ( errorsObject: Record< string, ValidationContextError > ) => setValidationErrors( Object.fromEntries( - Object.entries( - errorsObject - ).map( ( [ validationErrorId, error ] ) => [ - `${ prefix }-${ validationErrorId }`, - error, - ] ) + Object.entries( errorsObject ).map( + ( [ validationErrorId, error ] ) => [ + `${ prefix }-${ validationErrorId }`, + error, + ] + ) ) ), [ setValidationErrors ] diff --git a/plugins/woocommerce-blocks/assets/js/base/context/providers/add-to-cart-form/form-state/index.js b/plugins/woocommerce-blocks/assets/js/base/context/providers/add-to-cart-form/form-state/index.js index d657915005b..83f181ee4a0 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/providers/add-to-cart-form/form-state/index.js +++ b/plugins/woocommerce-blocks/assets/js/base/context/providers/add-to-cart-form/form-state/index.js @@ -101,25 +101,23 @@ export const AddToCartFormStateContextProvider = ( { const currentObservers = useShallowEqual( observers ); const { createErrorNotice } = useDispatch( 'core/notices' ); const { setValidationErrors } = useValidationContext(); - const { - isSuccessResponse, - isErrorResponse, - isFailResponse, - } = useEmitResponse(); + const { isSuccessResponse, isErrorResponse, isFailResponse } = + useEmitResponse(); /** * @type {AddToCartFormEventRegistration} */ const eventRegistration = useMemo( () => ( { - onAddToCartAfterProcessingWithSuccess: emitterObservers( - observerDispatch - ).onAddToCartAfterProcessingWithSuccess, - onAddToCartAfterProcessingWithError: emitterObservers( - observerDispatch - ).onAddToCartAfterProcessingWithError, - onAddToCartBeforeProcessing: emitterObservers( observerDispatch ) - .onAddToCartBeforeProcessing, + onAddToCartAfterProcessingWithSuccess: + emitterObservers( observerDispatch ) + .onAddToCartAfterProcessingWithSuccess, + onAddToCartAfterProcessingWithError: + emitterObservers( observerDispatch ) + .onAddToCartAfterProcessingWithError, + onAddToCartBeforeProcessing: + emitterObservers( observerDispatch ) + .onAddToCartBeforeProcessing, } ), [ observerDispatch ] ); diff --git a/plugins/woocommerce-blocks/assets/js/base/context/providers/add-to-cart-form/form/submit/index.js b/plugins/woocommerce-blocks/assets/js/base/context/providers/add-to-cart-form/form/submit/index.js index bb6f165a8f5..9f0b3d6071b 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/providers/add-to-cart-form/form/submit/index.js +++ b/plugins/woocommerce-blocks/assets/js/base/context/providers/add-to-cart-form/form/submit/index.js @@ -30,10 +30,8 @@ const FormSubmit = () => { isProcessing, requestParams, } = useAddToCartFormContext(); - const { - hasValidationErrors, - showAllValidationErrors, - } = useValidationContext(); + const { hasValidationErrors, showAllValidationErrors } = + useValidationContext(); const { createErrorNotice, removeNotice } = useDispatch( 'core/notices' ); const { receiveCart } = useStoreCart(); const [ isSubmitting, setIsSubmitting ] = useState( false ); @@ -51,10 +49,11 @@ const FormSubmit = () => { // Subscribe to emitter before processing. useEffect( () => { - const unsubscribeProcessing = eventRegistration.onAddToCartBeforeProcessing( - checkValidationContext, - 0 - ); + const unsubscribeProcessing = + eventRegistration.onAddToCartBeforeProcessing( + checkValidationContext, + 0 + ); return () => { unsubscribeProcessing(); }; diff --git a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/checkout-state/index.tsx b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/checkout-state/index.tsx index ff648e413a3..54317b23bc6 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/checkout-state/index.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/checkout-state/index.tsx @@ -81,17 +81,10 @@ export const CheckoutStateProvider = ( { const { dispatchCheckoutEvent } = useStoreEvents(); const isCalculating = checkoutState.calculatingCount > 0; - const { - isSuccessResponse, - isErrorResponse, - isFailResponse, - shouldRetry, - } = useEmitResponse(); - const { - checkoutNotices, - paymentNotices, - expressPaymentNotices, - } = useCheckoutNotices(); + const { isSuccessResponse, isErrorResponse, isFailResponse, shouldRetry } = + useEmitResponse(); + const { checkoutNotices, paymentNotices, expressPaymentNotices } = + useCheckoutNotices(); const [ observers, observerDispatch ] = useReducer( emitReducer, {} ); const currentObservers = useRef( observers ); @@ -147,9 +140,8 @@ export const CheckoutStateProvider = ( { setExtensionData: ( extensionData ) => void dispatch( actions.setExtensionData( extensionData ) ), setAfterProcessing: ( response ) => { - const paymentResult = getPaymentResultFromCheckoutResponse( - response - ); + const paymentResult = + getPaymentResultFromCheckoutResponse( response ); dispatch( actions.setRedirectUrl( paymentResult?.redirectUrl || '' ) ); @@ -244,9 +236,8 @@ export const CheckoutStateProvider = ( { EMIT_TYPES.CHECKOUT_AFTER_PROCESSING_WITH_ERROR, data ).then( ( observerResponses ) => { - const errorResponse = handleErrorResponse( - observerResponses - ); + const errorResponse = + handleErrorResponse( observerResponses ); if ( errorResponse !== null ) { // irrecoverable error so set complete if ( ! shouldRetry( errorResponse ) ) { diff --git a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/checkout-state/utils.ts b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/checkout-state/utils.ts index 56c74eeeca6..5e93314a7a8 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/checkout-state/utils.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/checkout-state/utils.ts @@ -33,9 +33,8 @@ export const getPaymentResultFromCheckoutResponse = ( ) { response.payment_result.payment_details.forEach( ( { key, value }: { key: string; value: string } ) => { - paymentResult.paymentDetails[ key ] = decodeEntities( - value - ); + paymentResult.paymentDetails[ key ] = + decodeEntities( value ); } ); } diff --git a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/constants.ts b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/constants.ts index 28d2f2de72e..a5d8e208795 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/constants.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/constants.ts @@ -24,17 +24,18 @@ export enum ACTION { } // Note - if fields are added/shape is changed, you may want to update PRISTINE reducer clause to preserve your new field. -export const DEFAULT_PAYMENT_DATA_CONTEXT_STATE: PaymentMethodDataContextState = { - currentStatus: STATUS.PRISTINE, - shouldSavePaymentMethod: false, - activePaymentMethod: '', - paymentMethodData: { - payment_method: '', - }, - errorMessage: '', - paymentMethods: {}, - expressPaymentMethods: {}, -}; +export const DEFAULT_PAYMENT_DATA_CONTEXT_STATE: PaymentMethodDataContextState = + { + currentStatus: STATUS.PRISTINE, + shouldSavePaymentMethod: false, + activePaymentMethod: '', + paymentMethodData: { + payment_method: '', + }, + errorMessage: '', + paymentMethods: {}, + expressPaymentMethods: {}, + }; export const DEFAULT_PAYMENT_METHOD_DATA: PaymentMethodDataContextType = { setPaymentStatus: () => ( { diff --git a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/payment-method-data-context.tsx b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/payment-method-data-context.tsx index b8bbd14e3b4..833f71fe0e4 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/payment-method-data-context.tsx +++ b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/payment-method-data-context.tsx @@ -70,9 +70,8 @@ export const PaymentMethodDataProvider = ( { } = useCheckoutContext(); const { isEditor, getPreviewData } = useEditorContext(); const { setValidationErrors } = useValidationContext(); - const { createErrorNotice: addErrorNotice, removeNotice } = useDispatch( - 'core/notices' - ); + const { createErrorNotice: addErrorNotice, removeNotice } = + useDispatch( 'core/notices' ); const { isSuccessResponse, isErrorResponse, @@ -93,10 +92,8 @@ export const PaymentMethodDataProvider = ( { DEFAULT_PAYMENT_DATA_CONTEXT_STATE ); - const { - dispatchActions, - setPaymentStatus, - } = usePaymentMethodDataDispatchers( dispatch ); + const { dispatchActions, setPaymentStatus } = + usePaymentMethodDataDispatchers( dispatch ); const paymentMethodsInitialized = usePaymentMethods( dispatchActions.setRegisteredPaymentMethods diff --git a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/test/payment-method-data-context.js b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/test/payment-method-data-context.js index 53a0228b933..d764761abc1 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/test/payment-method-data-context.js +++ b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/test/payment-method-data-context.js @@ -230,10 +230,8 @@ describe( 'Testing Payment Method Data Context Provider with saved cards turned it( 'resets saved payment method data after starting and closing an express payment method', async () => { const TriggerActiveExpressPaymentMethod = () => { - const { - activePaymentMethod, - paymentMethodData, - } = usePaymentMethodDataContext(); + const { activePaymentMethod, paymentMethodData } = + usePaymentMethodDataContext(); return ( <> diff --git a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/use-payment-method-registration.ts b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/use-payment-method-registration.ts index 3b7733da226..42a993cb22d 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/use-payment-method-registration.ts +++ b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/payment-methods/use-payment-method-registration.ts @@ -216,13 +216,14 @@ const usePaymentMethodRegistration = ( export const usePaymentMethods = ( dispatcher: PaymentMethodsDispatcherType ): boolean => { - const standardMethods: PaymentMethods = getPaymentMethods() as PaymentMethods; + const standardMethods: PaymentMethods = + getPaymentMethods() as PaymentMethods; const { noticeContexts } = useEmitResponse(); // Ensure all methods are present in order. // Some payment methods may not be present in paymentGatewaySortOrder if they // depend on state, e.g. COD can depend on shipping method. const displayOrder = new Set( [ - ...( getSetting( 'paymentGatewaySortOrder', [] ) as [ ] ), + ...( getSetting( 'paymentGatewaySortOrder', [] ) as [] ), ...Object.keys( standardMethods ), ] ); return usePaymentMethodRegistration( @@ -243,7 +244,8 @@ export const usePaymentMethods = ( export const useExpressPaymentMethods = ( dispatcher: PaymentMethodsDispatcherType ): boolean => { - const expressMethods: ExpressPaymentMethods = getExpressPaymentMethods() as ExpressPaymentMethods; + const expressMethods: ExpressPaymentMethods = + getExpressPaymentMethods() as ExpressPaymentMethods; const { noticeContexts } = useEmitResponse(); return usePaymentMethodRegistration( dispatcher, diff --git a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/shipping/index.js b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/shipping/index.js index a3700f50713..e17b2ae15c4 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/shipping/index.js +++ b/plugins/woocommerce-blocks/assets/js/base/context/providers/cart-checkout/shipping/index.js @@ -61,13 +61,13 @@ export const ShippingDataProvider = ( { children } ) => { const currentObservers = useRef( observers ); const eventObservers = useMemo( () => ( { - onShippingRateSuccess: emitterObservers( observerDispatch ) - .onSuccess, + onShippingRateSuccess: + emitterObservers( observerDispatch ).onSuccess, onShippingRateFail: emitterObservers( observerDispatch ).onFail, - onShippingRateSelectSuccess: emitterObservers( observerDispatch ) - .onSelectSuccess, - onShippingRateSelectFail: emitterObservers( observerDispatch ) - .onSelectFail, + onShippingRateSelectSuccess: + emitterObservers( observerDispatch ).onSelectSuccess, + onShippingRateSelectFail: + emitterObservers( observerDispatch ).onSelectFail, } ), [ observerDispatch ] ); diff --git a/plugins/woocommerce-blocks/assets/js/base/context/tsconfig.json b/plugins/woocommerce-blocks/assets/js/base/context/tsconfig.json index f486316e06e..8de56c5a7d5 100644 --- a/plugins/woocommerce-blocks/assets/js/base/context/tsconfig.json +++ b/plugins/woocommerce-blocks/assets/js/base/context/tsconfig.json @@ -8,7 +8,7 @@ "../../settings/blocks/index.ts", "../../base/hooks/index.js", "../../base/utils/", - "../../utils", + "../../utils", "../../data/", "../../types/", "../components", diff --git a/plugins/woocommerce-blocks/assets/js/base/hocs/with-reviews.js b/plugins/woocommerce-blocks/assets/js/base/hocs/with-reviews.js index 16de44cc9bc..09441947d16 100644 --- a/plugins/woocommerce-blocks/assets/js/base/hocs/with-reviews.js +++ b/plugins/woocommerce-blocks/assets/js/base/hocs/with-reviews.js @@ -92,13 +92,8 @@ const withReviews = ( OriginalComponent ) => { } getArgs( reviewsToSkip ) { - const { - categoryIds, - order, - orderby, - productId, - reviewsToDisplay, - } = this.props; + const { categoryIds, order, orderby, productId, reviewsToDisplay } = + this.props; const args = { order, orderby, @@ -214,9 +209,8 @@ const withReviews = ( OriginalComponent ) => { } } - const { - displayName = OriginalComponent.name || 'Component', - } = OriginalComponent; + const { displayName = OriginalComponent.name || 'Component' } = + OriginalComponent; WrappedComponent.displayName = `WithReviews( ${ displayName } )`; return WrappedComponent; diff --git a/plugins/woocommerce-blocks/assets/js/base/hooks/test/use-position-relative-to-viewport.js b/plugins/woocommerce-blocks/assets/js/base/hooks/test/use-position-relative-to-viewport.js index 0b18403ea9d..1b0255554c5 100644 --- a/plugins/woocommerce-blocks/assets/js/base/hooks/test/use-position-relative-to-viewport.js +++ b/plugins/woocommerce-blocks/assets/js/base/hooks/test/use-position-relative-to-viewport.js @@ -11,10 +11,8 @@ import { usePositionRelativeToViewport } from '../use-position-relative-to-viewp describe( 'usePositionRelativeToViewport', () => { function setup() { const TestComponent = () => { - const [ - referenceElement, - positionRelativeToViewport, - ] = usePositionRelativeToViewport(); + const [ referenceElement, positionRelativeToViewport ] = + usePositionRelativeToViewport(); return ( <> diff --git a/plugins/woocommerce-blocks/assets/js/base/hooks/test/use-previous.js b/plugins/woocommerce-blocks/assets/js/base/hooks/test/use-previous.js index 0018116ca25..1115c9a9df9 100644 --- a/plugins/woocommerce-blocks/assets/js/base/hooks/test/use-previous.js +++ b/plugins/woocommerce-blocks/assets/js/base/hooks/test/use-previous.js @@ -25,8 +25,8 @@ describe( 'usePrevious', () => { renderer = TestRenderer.create( ); } ); const testValue = renderer.root.findByType( 'div' ).props.testValue; - const testPreviousValue = renderer.root.findByType( 'div' ).props - .previousValue; + const testPreviousValue = + renderer.root.findByType( 'div' ).props.previousValue; expect( testValue ).toBe( 1 ); expect( testPreviousValue ).toBe( undefined ); @@ -43,8 +43,8 @@ describe( 'usePrevious', () => { renderer.update( ); } ); testValue = renderer.root.findByType( 'div' ).props.testValue; - testPreviousValue = renderer.root.findByType( 'div' ).props - .previousValue; + testPreviousValue = + renderer.root.findByType( 'div' ).props.previousValue; expect( testValue ).toBe( 2 ); expect( testPreviousValue ).toBe( 1 ); @@ -52,8 +52,8 @@ describe( 'usePrevious', () => { renderer.update( ); } ); testValue = renderer.root.findByType( 'div' ).props.testValue; - testPreviousValue = renderer.root.findByType( 'div' ).props - .previousValue; + testPreviousValue = + renderer.root.findByType( 'div' ).props.previousValue; expect( testValue ).toBe( 3 ); expect( testPreviousValue ).toBe( 2 ); } ); @@ -73,8 +73,8 @@ describe( 'usePrevious', () => { ); } ); testValue = renderer.root.findByType( 'div' ).props.testValue; - testPreviousValue = renderer.root.findByType( 'div' ).props - .previousValue; + testPreviousValue = + renderer.root.findByType( 'div' ).props.previousValue; expect( testValue ).toBe( 'abc' ); expect( testPreviousValue ).toBe( 1 ); @@ -84,8 +84,8 @@ describe( 'usePrevious', () => { ); } ); testValue = renderer.root.findByType( 'div' ).props.testValue; - testPreviousValue = renderer.root.findByType( 'div' ).props - .previousValue; + testPreviousValue = + renderer.root.findByType( 'div' ).props.previousValue; expect( testValue ).toBe( 3 ); expect( testPreviousValue ).toBe( 1 ); } ); diff --git a/plugins/woocommerce-blocks/assets/js/base/hooks/use-position-relative-to-viewport.js b/plugins/woocommerce-blocks/assets/js/base/hooks/use-position-relative-to-viewport.js index 06e94e7f457..8072bb1e772 100644 --- a/plugins/woocommerce-blocks/assets/js/base/hooks/use-position-relative-to-viewport.js +++ b/plugins/woocommerce-blocks/assets/js/base/hooks/use-position-relative-to-viewport.js @@ -43,10 +43,8 @@ const style = { * ``` */ export const usePositionRelativeToViewport = () => { - const [ - positionRelativeToViewport, - setPositionRelativeToViewport, - ] = useState( '' ); + const [ positionRelativeToViewport, setPositionRelativeToViewport ] = + useState( '' ); const referenceElementRef = useRef( null ); const intersectionObserver = useRef( new IntersectionObserver( diff --git a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/express-payment-method-config.ts b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/express-payment-method-config.ts index 98c1b7ceda1..83a6cc0bc3f 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/express-payment-method-config.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/express-payment-method-config.ts @@ -16,7 +16,8 @@ import { getCanMakePayment } from './payment-method-config-helper'; import { assertConfigHasProperties, assertValidElement } from './assertions'; export default class ExpressPaymentMethodConfig - implements ExpressPaymentMethodConfigInstance { + implements ExpressPaymentMethodConfigInstance +{ public name: string; public content: ReactNode; public edit: ReactNode; diff --git a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/extensions-config.ts b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/extensions-config.ts index 3edbbd4f6e3..25fdb7a38dc 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/extensions-config.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/extensions-config.ts @@ -11,12 +11,14 @@ export type NamespacedCanMakePaymentExtensionsCallbacks = Record< string, CanMakePaymentExtensionCallbacks >; -export type ExtensionNamespace = keyof NamespacedCanMakePaymentExtensionsCallbacks; +export type ExtensionNamespace = + keyof NamespacedCanMakePaymentExtensionsCallbacks; export type PaymentMethodName = keyof CanMakePaymentExtensionCallbacks; // Keeps callbacks registered by extensions for different payment methods // eslint-disable-next-line prefer-const -export const canMakePaymentExtensionsCallbacks: NamespacedCanMakePaymentExtensionsCallbacks = {}; +export const canMakePaymentExtensionsCallbacks: NamespacedCanMakePaymentExtensionsCallbacks = + {}; export const extensionsConfig = { canMakePayment: canMakePaymentExtensionsCallbacks, diff --git a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/payment-method-config-helper.ts b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/payment-method-config-helper.ts index f0e28a28d98..3f0868f124d 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/payment-method-config-helper.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/payment-method-config-helper.ts @@ -17,58 +17,66 @@ import { } from './extensions-config'; // Filter out payment methods by supported features and cart requirement. -export const canMakePaymentWithFeaturesCheck = ( - canMakePayment: CanMakePaymentCallback, - features: string[] -): CanMakePaymentCallback => ( canPayArgument ) => { - const requirements = canPayArgument?.paymentRequirements || []; - const featuresSupportRequirements = requirements.every( ( requirement ) => - features.includes( requirement ) - ); - return featuresSupportRequirements && canMakePayment( canPayArgument ); -}; +export const canMakePaymentWithFeaturesCheck = + ( + canMakePayment: CanMakePaymentCallback, + features: string[] + ): CanMakePaymentCallback => + ( canPayArgument ) => { + const requirements = canPayArgument?.paymentRequirements || []; + const featuresSupportRequirements = requirements.every( + ( requirement ) => features.includes( requirement ) + ); + return featuresSupportRequirements && canMakePayment( canPayArgument ); + }; // Filter out payment methods by callbacks registered by extensions. -export const canMakePaymentWithExtensions = ( - canMakePayment: CanMakePaymentCallback, - extensionsCallbacks: NamespacedCanMakePaymentExtensionsCallbacks, - paymentMethodName: PaymentMethodName -): CanMakePaymentCallback => ( canPayArgument ) => { - // Validate whether the payment method is available based on its own criteria first. - let canPay = canMakePayment( canPayArgument ); +export const canMakePaymentWithExtensions = + ( + canMakePayment: CanMakePaymentCallback, + extensionsCallbacks: NamespacedCanMakePaymentExtensionsCallbacks, + paymentMethodName: PaymentMethodName + ): CanMakePaymentCallback => + ( canPayArgument ) => { + // Validate whether the payment method is available based on its own criteria first. + let canPay = canMakePayment( canPayArgument ); - if ( canPay ) { - // Gather all callbacks for paymentMethodName. - const namespacedCallbacks: Record< - ExtensionNamespace, - CanMakePaymentExtensionCallback - > = {}; + if ( canPay ) { + // Gather all callbacks for paymentMethodName. + const namespacedCallbacks: Record< + ExtensionNamespace, + CanMakePaymentExtensionCallback + > = {}; - Object.entries( extensionsCallbacks ).forEach( - ( [ namespace, callbacks ] ) => { - namespacedCallbacks[ namespace ] = - callbacks[ paymentMethodName ]; - } - ); + Object.entries( extensionsCallbacks ).forEach( + ( [ namespace, callbacks ] ) => { + namespacedCallbacks[ namespace ] = + callbacks[ paymentMethodName ]; + } + ); - canPay = Object.keys( namespacedCallbacks ).every( ( namespace ) => { - try { - return namespacedCallbacks[ namespace ]( canPayArgument ); - } catch ( err ) { - // eslint-disable-next-line no-console - console.error( - `Error when executing callback for ${ paymentMethodName } in ${ namespace }`, - err - ); - // .every() expects a return value at the end of every arrow function and - // this ensures that the error is ignored when computing the whole result. - return true; - } - } ); - } + canPay = Object.keys( namespacedCallbacks ).every( + ( namespace ) => { + try { + return namespacedCallbacks[ namespace ]( + canPayArgument + ); + } catch ( err ) { + // eslint-disable-next-line no-console + console.error( + `Error when executing callback for ${ paymentMethodName } in ${ namespace }`, + err + ); + // .every() expects a return value at the end of every arrow function and + // this ensures that the error is ignored when computing the whole result. + return true; + } + } + ); + } - return canPay; -}; + return canPay; + }; export const getCanMakePayment = ( canMakePayment: CanMakePaymentCallback, @@ -77,10 +85,12 @@ export const getCanMakePayment = ( ): CanMakePaymentCallback => { const canPay = canMakePaymentWithFeaturesCheck( canMakePayment, features ); // Loop through all callbacks to check if there are any registered for this payment method. - return ( Object.values( extensionsConfig.canMakePayment ) as Record< - PaymentMethodName, - CanMakePaymentCallback - >[] ).some( ( callbacks ) => paymentMethodName in callbacks ) + return ( + Object.values( extensionsConfig.canMakePayment ) as Record< + PaymentMethodName, + CanMakePaymentCallback + >[] + ).some( ( callbacks ) => paymentMethodName in callbacks ) ? canMakePaymentWithExtensions( canPay, extensionsConfig.canMakePayment, diff --git a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/payment-method-config.tsx b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/payment-method-config.tsx index 8c0278ec664..8385b872228 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/payment-method-config.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/payment-method-config.tsx @@ -26,7 +26,8 @@ const NullComponent = () => { }; export default class PaymentMethodConfig - implements PaymentMethodConfigInstance { + implements PaymentMethodConfigInstance +{ public name: string; public content: ReactNode; public edit: ReactNode; @@ -142,8 +143,7 @@ export default class PaymentMethodConfig { alternative: 'Pass showSavedCards and showSaveOption', plugin: 'woocommerce-gutenberg-products-block', - link: - 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3686', + link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3686', } ); } diff --git a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/registry.ts b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/registry.ts index e71246da713..cc76e9be183 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/registry.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/registry.ts @@ -38,8 +38,7 @@ export const registerPaymentMethod = ( deprecated( 'Passing a callback to registerPaymentMethod()', { alternative: 'a config options object', plugin: 'woocommerce-gutenberg-products-block', - link: - 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3404', + link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3404', } ); } else { paymentMethodConfig = new PaymentMethodConfig( options ); @@ -65,8 +64,7 @@ export const registerExpressPaymentMethod = ( deprecated( 'Passing a callback to registerExpressPaymentMethod()', { alternative: 'a config options object', plugin: 'woocommerce-gutenberg-products-block', - link: - 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3404', + link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3404', } ); } else { paymentMethodConfig = new ExpressPaymentMethodConfig( options ); diff --git a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/test/payment-method-config-helper.ts b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/test/payment-method-config-helper.ts index 1cc9b279e2a..2951725c3d7 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/test/payment-method-config-helper.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks-registry/payment-methods/test/payment-method-config-helper.ts @@ -153,11 +153,12 @@ describe( 'payment-method-config-helper', () => { describe( 'canMakePaymentWithExtensions', () => { it( "Returns false without executing the registered callbacks, if the payment method's canMakePayment callback returns false.", () => { const canMakePayment = () => false; - const canMakePaymentWithExtensionsResult = helpers.canMakePaymentWithExtensions( - canMakePayment, - canMakePaymentExtensionsCallbacks, - 'cod' - )( canMakePaymentArgument ); + const canMakePaymentWithExtensionsResult = + helpers.canMakePaymentWithExtensions( + canMakePayment, + canMakePaymentExtensionsCallbacks, + 'cod' + )( canMakePaymentArgument ); expect( canMakePaymentWithExtensionsResult ).toBe( false ); expect( trueCallback ).not.toHaveBeenCalled(); } ); diff --git a/plugins/woocommerce-blocks/assets/js/blocks/active-filters/active-attribute-filters.js b/plugins/woocommerce-blocks/assets/js/blocks/active-filters/active-attribute-filters.js index b7b879820ea..789fdd9fb05 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/active-filters/active-attribute-filters.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/active-filters/active-attribute-filters.js @@ -101,7 +101,8 @@ const ActiveAttributeFilters = ( { // Remove only the slug from the URL. return removeArgsFromFilterUrl( { - [ `filter_${ attributeObject.name }` ]: slug, + [ `filter_${ attributeObject.name }` ]: + slug, } ); } removeAttributeFilterBySlug( diff --git a/plugins/woocommerce-blocks/assets/js/blocks/active-filters/block.js b/plugins/woocommerce-blocks/assets/js/blocks/active-filters/block.js index 2f8cd9e1db5..44182e7445b 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/active-filters/block.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/active-filters/block.js @@ -125,9 +125,8 @@ const ActiveFiltersBlock = ( { } ); }, [ productAttributes, blockAttributes.displayStyle ] ); - const [ productRatings, setProductRatings ] = useQueryStateByKey( - 'ratings' - ); + const [ productRatings, setProductRatings ] = + useQueryStateByKey( 'ratings' ); /** * Parse the filter URL to set the active rating fitlers. diff --git a/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.js b/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.js index b48ddbcd227..03ae366c021 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/attribute-filter/block.js @@ -81,9 +81,8 @@ const AttributeFilterBlock = ( { isString ); - const [ hasSetPhpFilterDefaults, setHasSetPhpFilterDefaults ] = useState( - false - ); + const [ hasSetPhpFilterDefaults, setHasSetPhpFilterDefaults ] = + useState( false ); const attributeObject = blockAttributes.isPreview && ! blockAttributes.attributeId @@ -103,37 +102,31 @@ const AttributeFilterBlock = ( { const borderProps = useBorderProps( blockAttributes ); const [ queryState ] = useQueryStateByContext(); - const [ - productAttributesQuery, - setProductAttributesQuery, - ] = useQueryStateByKey( 'attributes', [] ); + const [ productAttributesQuery, setProductAttributesQuery ] = + useQueryStateByKey( 'attributes', [] ); - const { - results: attributeTerms, - isLoading: attributeTermsLoading, - } = useCollection( { - namespace: '/wc/store/v1', - resourceName: 'products/attributes/terms', - resourceValues: [ attributeObject?.id || 0 ], - shouldSelect: blockAttributes.attributeId > 0, - } ); + const { results: attributeTerms, isLoading: attributeTermsLoading } = + useCollection( { + namespace: '/wc/store/v1', + resourceName: 'products/attributes/terms', + resourceValues: [ attributeObject?.id || 0 ], + shouldSelect: blockAttributes.attributeId > 0, + } ); const filterAvailableTerms = blockAttributes.displayStyle !== 'dropdown' && blockAttributes.queryType === 'and'; - const { - results: filteredCounts, - isLoading: filteredCountsLoading, - } = useCollectionData( { - queryAttribute: { - taxonomy: attributeObject?.taxonomy, - queryType: blockAttributes.queryType, - }, - queryState: { - ...queryState, - attributes: filterAvailableTerms ? queryState.attributes : null, - }, - } ); + const { results: filteredCounts, isLoading: filteredCountsLoading } = + useCollectionData( { + queryAttribute: { + taxonomy: attributeObject?.taxonomy, + queryType: blockAttributes.queryType, + }, + queryState: { + ...queryState, + attributes: filterAvailableTerms ? queryState.attributes : null, + }, + } ); /** * Get count data about a given term by ID. diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/express-payment-methods.js b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/express-payment-methods.js index c173cc399bd..10630c08a33 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/express-payment-methods.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/express-payment-methods.js @@ -98,8 +98,7 @@ const ExpressPaymentMethods = () => { { alternative: 'onError', plugin: 'woocommerce-gutenberg-products-block', - link: - 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4228', + link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4228', } ); if ( errorMessage ) { @@ -132,7 +131,8 @@ const ExpressPaymentMethods = () => { onClick: onExpressPaymentClick( id ), onClose: onExpressPaymentClose, onError: onExpressPaymentError, - setExpressPaymentError: deprecatedSetExpressPaymentError, + setExpressPaymentError: + deprecatedSetExpressPaymentError, } ) } ) : null; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-card.js b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-card.js index f9914c96cd0..57210eef3d6 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-card.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-card.js @@ -27,10 +27,8 @@ import PaymentMethodErrorBoundary from './payment-method-error-boundary'; */ const PaymentMethodCard = ( { children, showSaveOption } ) => { const { isEditor } = useEditorContext(); - const { - shouldSavePayment, - setShouldSavePayment, - } = usePaymentMethodDataContext(); + const { shouldSavePayment, setShouldSavePayment } = + usePaymentMethodDataContext(); const { customerId } = useCheckoutContext(); return ( diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-options.js b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-options.js index 51ae62304eb..d0c8e4d95d7 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-options.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/payment-method-options.js @@ -34,10 +34,8 @@ const PaymentMethodOptions = () => { customerPaymentMethods, } = usePaymentMethodDataContext(); const { paymentMethods } = usePaymentMethods(); - const { - activePaymentMethod, - ...paymentMethodInterface - } = usePaymentMethodInterface(); + const { activePaymentMethod, ...paymentMethodInterface } = + usePaymentMethodInterface(); const { noticeContexts } = useEmitResponse(); const { removeNotice } = useDispatch( 'core/notices' ); const { dispatchCheckoutEvent } = useStoreEvents(); diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/test/payment-methods.js b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/test/payment-methods.js index da89b041d3d..0a79fffae42 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/test/payment-methods.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/payment-methods/test/payment-methods.js @@ -32,14 +32,16 @@ jest.mock( '../saved-payment-method-options', () => ( { onChange } ) => { jest.mock( '@woocommerce/base-components/radio-control-accordion', - () => ( { onChange } ) => ( - <> - Payment method options - - - ) + () => + ( { onChange } ) => + ( + <> + Payment method options + + + ) ); const registerMockPaymentMethods = () => { @@ -103,10 +105,8 @@ describe( 'PaymentMethods', () => { test( 'selecting new payment method', async () => { const ShowActivePaymentMethod = () => { - const { - activePaymentMethod, - activeSavedToken, - } = usePaymentMethodDataContext(); + const { activePaymentMethod, activeSavedToken } = + usePaymentMethodDataContext(); return ( <>
diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-forced-layout.ts b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-forced-layout.ts index 39deab87852..bece364977e 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-forced-layout.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-forced-layout.ts @@ -42,16 +42,14 @@ export const useForcedLayout = ( { const currentRegisteredBlocks = useRef( registeredBlocks ); const currentDefaultTemplate = useRef( defaultTemplate ); - const { insertBlock, replaceInnerBlocks } = useDispatch( - 'core/block-editor' - ); + const { insertBlock, replaceInnerBlocks } = + useDispatch( 'core/block-editor' ); const { innerBlocks, registeredBlockTypes } = useSelect( ( select ) => { return { - innerBlocks: select( 'core/block-editor' ).getBlocks( - clientId - ), + innerBlocks: + select( 'core/block-editor' ).getBlocks( clientId ), registeredBlockTypes: currentRegisteredBlocks.current.map( ( blockName ) => getBlockType( blockName ) ), @@ -110,9 +108,10 @@ export const useForcedLayout = ( { } // Is the forced block part of the default template, find it's original position. - const defaultTemplatePosition = currentDefaultTemplate.current.findIndex( - ( [ blockName ] ) => blockName === block.name - ); + const defaultTemplatePosition = + currentDefaultTemplate.current.findIndex( + ( [ blockName ] ) => blockName === block.name + ); switch ( defaultTemplatePosition ) { case -1: diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-view-switcher.tsx b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-view-switcher.tsx index 8d1fdc63c2c..ead1af9d067 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-view-switcher.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-view-switcher.tsx @@ -29,11 +29,8 @@ export const useViewSwitcher = ( const initialView = views[ 0 ]; const [ currentView, setCurrentView ] = useState( initialView ); const { selectBlock } = useDispatch( 'core/block-editor' ); - const { - getBlock, - getSelectedBlockClientId, - getBlockParentsByBlockName, - } = select( blockEditorStore ); + const { getBlock, getSelectedBlockClientId, getBlockParentsByBlockName } = + select( blockEditorStore ); const selectedBlockClientId = getSelectedBlockClientId(); useEffect( () => { diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart/cart-line-items-table/cart-line-item-row.tsx b/plugins/woocommerce-blocks/assets/js/blocks/cart/cart-line-items-table/cart-line-item-row.tsx index 999d299d9f0..af32e5f9551 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart/cart-line-items-table/cart-line-item-row.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart/cart-line-items-table/cart-line-item-row.tsx @@ -114,12 +114,8 @@ const CartLineItemRow = forwardRef< HTMLTableRowElement, CartLineItemRowProps >( extensions, } = lineItem; - const { - quantity, - setItemQuantity, - removeItem, - isPendingDelete, - } = useStoreCartItemQuantity( lineItem ); + const { quantity, setItemQuantity, removeItem, isPendingDelete } = + useStoreCartItemQuantity( lineItem ); const { dispatchStoreEvent } = useStoreEvents(); // Prepare props to pass to the __experimentalApplyCheckoutFilter filter. @@ -150,9 +146,8 @@ const CartLineItemRow = forwardRef< HTMLTableRowElement, CartLineItemRowProps >( amount: parseInt( prices.raw_prices.price, 10 ), precision: prices.raw_prices.precision, } ); - const saleAmountSingle = regularAmountSingle.subtract( - purchaseAmountSingle - ); + const saleAmountSingle = + regularAmountSingle.subtract( purchaseAmountSingle ); const saleAmount = saleAmountSingle.multiply( quantity ); const totalsCurrency = getCurrencyFromPriceResponse( totals ); let lineSubtotal = parseInt( totals.line_subtotal, 10 ); diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/edit.tsx index 1bfbfff15f4..8d7fc22c17c 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-express-payment-block/edit.tsx @@ -56,7 +56,8 @@ export const Edit = ( { const hasExpressPaymentMethods = Object.keys( paymentMethods ).length > 0; const blockProps = useBlockProps( { className: classnames( { - 'wp-block-woocommerce-cart-express-payment-block--has-express-payment-methods': hasExpressPaymentMethods, + 'wp-block-woocommerce-cart-express-payment-block--has-express-payment-methods': + hasExpressPaymentMethods, } ), } ); const { className } = attributes; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/edit.tsx index c541b07611b..ccaaf05677f 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-shipping/edit.tsx @@ -52,7 +52,8 @@ export const Edit = ( { checked={ isShippingCalculatorEnabled } onChange={ () => setAttributes( { - isShippingCalculatorEnabled: ! isShippingCalculatorEnabled, + isShippingCalculatorEnabled: + ! isShippingCalculatorEnabled, } ) } /> diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/edit.tsx index d7b925202c9..9d3c3df688a 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/cart-order-summary-taxes/edit.tsx @@ -56,7 +56,8 @@ export const Edit = ( { checked={ showRateAfterTaxName } onChange={ () => setAttributes( { - showRateAfterTaxName: ! showRateAfterTaxName, + showRateAfterTaxName: + ! showRateAfterTaxName, } ) } /> diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/empty-cart-block/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/empty-cart-block/edit.tsx index 73995b42f9c..7b7a909b23c 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/empty-cart-block/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/empty-cart-block/edit.tsx @@ -36,7 +36,7 @@ const browseStoreTemplate = SHOP_URL ] : null; -const defaultTemplate = ( [ +const defaultTemplate = [ [ 'core/image', { @@ -79,7 +79,7 @@ const defaultTemplate = ( [ rows: 1, }, ], -].filter( Boolean ) as unknown ) as TemplateArray; +].filter( Boolean ) as unknown as TemplateArray; export const Edit = ( { clientId }: { clientId: string } ): JSX.Element => { const blockProps = useBlockProps(); diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/proceed-to-checkout-block/block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/proceed-to-checkout-block/block.tsx index 49875f5804d..c2aea4d84bb 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/proceed-to-checkout-block/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/proceed-to-checkout-block/block.tsx @@ -27,10 +27,8 @@ const Block = ( { } ): JSX.Element => { const link = getSetting( 'page-' + checkoutPageId, false ); const { isCalculating } = useCheckoutContext(); - const [ - positionReferenceElement, - positionRelativeToViewport, - ] = usePositionRelativeToViewport(); + const [ positionReferenceElement, positionRelativeToViewport ] = + usePositionRelativeToViewport(); const [ showSpinner, setShowSpinner ] = useState( false ); useEffect( () => { diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/register-components.ts b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/register-components.ts index 6db34a47bba..bf4ac082f28 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/register-components.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart/inner-blocks/register-components.ts @@ -16,170 +16,187 @@ __webpack_public_path__ = WC_BLOCKS_BUILD_URL; registerCheckoutBlock( { metadata: metadata.FILLED_CART, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/filled-cart" */ - './filled-cart-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/filled-cart" */ + './filled-cart-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.EMPTY_CART, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/empty-cart" */ - './empty-cart-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/empty-cart" */ + './empty-cart-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_ITEMS, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/cart-items" */ - './cart-items-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/cart-items" */ + './cart-items-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_LINE_ITEMS, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/cart-line-items" */ - './cart-line-items-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/cart-line-items" */ + './cart-line-items-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_TOTALS, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/cart-totals" */ - './cart-totals-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/cart-totals" */ + './cart-totals-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_EXPRESS_PAYMENT, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/cart-express-payment" */ - './cart-express-payment-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/cart-express-payment" */ + './cart-express-payment-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.PROCEED_TO_CHECKOUT, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/proceed-to-checkout" */ - './proceed-to-checkout-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/proceed-to-checkout" */ + './proceed-to-checkout-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_ACCEPTED_PAYMENT_METHODS, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/cart-accepted-payment-methods" */ - './cart-accepted-payment-methods-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/cart-accepted-payment-methods" */ + './cart-accepted-payment-methods-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_ORDER_SUMMARY, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/cart-order-summary" */ - './cart-order-summary-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/cart-order-summary" */ + './cart-order-summary-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_ORDER_SUMMARY_HEADING, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/order-summary-heading" */ - './cart-order-summary-heading/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/order-summary-heading" */ + './cart-order-summary-heading/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_ORDER_SUMMARY_SUBTOTAL, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/order-summary-subtotal" */ - './cart-order-summary-subtotal/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/order-summary-subtotal" */ + './cart-order-summary-subtotal/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_ORDER_SUMMARY_FEE, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/order-summary-fee" */ - './cart-order-summary-fee/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/order-summary-fee" */ + './cart-order-summary-fee/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_ORDER_SUMMARY_DISCOUNT, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/order-summary-discount" */ - './cart-order-summary-discount/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/order-summary-discount" */ + './cart-order-summary-discount/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_ORDER_SUMMARY_COUPON_FORM, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/order-summary-coupon-form" */ - './cart-order-summary-coupon-form/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/order-summary-coupon-form" */ + './cart-order-summary-coupon-form/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_ORDER_SUMMARY_SHIPPING, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/order-summary-shipping" */ - './cart-order-summary-shipping/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/order-summary-shipping" */ + './cart-order-summary-shipping/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_ORDER_SUMMARY_TAXES, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/order-summary-taxes" */ - './cart-order-summary-taxes/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/order-summary-taxes" */ + './cart-order-summary-taxes/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CART_ORDER_SUMMARY_HEADING, - component: lazy( () => - import( - /* webpackChunkName: "cart-blocks/order-summary-heading" */ - './cart-order-summary-heading/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "cart-blocks/order-summary-heading" */ + './cart-order-summary-heading/frontend' + ) ), } ); diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/checkout/block.tsx index 3c5112d8da4..17204ba34c0 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/block.tsx @@ -104,14 +104,10 @@ const ScrollOnError = ( { }: { scrollToTop: ( props: Record< string, unknown > ) => void; } ): null => { - const { - hasError: checkoutHasError, - isIdle: checkoutIsIdle, - } = useCheckoutContext(); - const { - hasValidationErrors, - showAllValidationErrors, - } = useValidationContext(); + const { hasError: checkoutHasError, isIdle: checkoutIsIdle } = + useCheckoutContext(); + const { hasValidationErrors, showAllValidationErrors } = + useValidationContext(); const hasErrorsToDisplay = checkoutIsIdle && diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/context.ts b/plugins/woocommerce-blocks/assets/js/blocks/checkout/context.ts index 6e5be401cc0..7293a909e3a 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/context.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/context.ts @@ -41,17 +41,17 @@ export const CheckoutBlockContext = createContext< CheckoutBlockContextProps >( } ); -export const CheckoutBlockControlsContext = createContext< - CheckoutBlockControlsContextProps ->( { - addressFieldControls: () => null, - accountControls: () => null, -} ); +export const CheckoutBlockControlsContext = + createContext< CheckoutBlockControlsContextProps >( { + addressFieldControls: () => null, + accountControls: () => null, + } ); export const useCheckoutBlockContext = (): CheckoutBlockContextProps => { return useContext( CheckoutBlockContext ); }; -export const useCheckoutBlockControlsContext = (): CheckoutBlockControlsContextProps => { - return useContext( CheckoutBlockControlsContext ); -}; +export const useCheckoutBlockControlsContext = + (): CheckoutBlockControlsContextProps => { + return useContext( CheckoutBlockControlsContext ); + }; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/form-step/form-step-block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/checkout/form-step/form-step-block.tsx index 240df907b63..d4eaee87de3 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/form-step/form-step-block.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/form-step/form-step-block.tsx @@ -34,7 +34,8 @@ export const FormStepBlock = ( { const { title = '', description = '', showStepNumber = true } = attributes; const blockProps = useBlockProps( { className: classnames( 'wc-block-components-checkout-step', className, { - 'wc-block-components-checkout-step--with-step-number': showStepNumber, + 'wc-block-components-checkout-step--with-step-number': + showStepNumber, } ), } ); return ( diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-billing-address-block/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-billing-address-block/edit.tsx index 0a19dac5d6a..692b9c4f20c 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-billing-address-block/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-billing-address-block/edit.tsx @@ -39,9 +39,8 @@ export const Edit = ( { showPhoneField, requirePhoneField, } = useCheckoutBlockContext(); - const { - addressFieldControls: Controls, - } = useCheckoutBlockControlsContext(); + const { addressFieldControls: Controls } = + useCheckoutBlockControlsContext(); const { showBillingFields } = useCheckoutAddress(); if ( ! showBillingFields ) { diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-contact-information-block/block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-contact-information-block/block.tsx index 7621be71f49..9c1d5b3e27e 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-contact-information-block/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-contact-information-block/block.tsx @@ -20,11 +20,8 @@ const Block = ( { }: { allowCreateAccount: boolean; } ): JSX.Element => { - const { - customerId, - shouldCreateAccount, - setShouldCreateAccount, - } = useCheckoutContext(); + const { customerId, shouldCreateAccount, setShouldCreateAccount } = + useCheckoutContext(); const { billingAddress, setEmail } = useCheckoutAddress(); const { dispatchCheckoutEvent } = useStoreEvents(); diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/edit.tsx index 94c65db9dcb..e93ad860a0b 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-express-payment-block/edit.tsx @@ -63,7 +63,8 @@ export const Edit = ( { const blockProps = useBlockProps( { className: classnames( { - 'wp-block-woocommerce-checkout-express-payment-block--has-express-payment-methods': hasExpressPaymentMethods, + 'wp-block-woocommerce-checkout-express-payment-block--has-express-payment-methods': + hasExpressPaymentMethods, }, attributes?.className ), diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-fields-block/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-fields-block/edit.tsx index 01072c5fb22..c5fb4f5aa40 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-fields-block/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-fields-block/edit.tsx @@ -34,11 +34,10 @@ export const Edit = ( { } ); const allowedBlocks = getAllowedBlocks( innerBlockAreas.CHECKOUT_FIELDS ); - const { - addressFieldControls: Controls, - } = useCheckoutBlockControlsContext(); + const { addressFieldControls: Controls } = + useCheckoutBlockControlsContext(); - const defaultTemplate = ( [ + const defaultTemplate = [ [ 'woocommerce/checkout-express-payment-block', {}, [] ], [ 'woocommerce/checkout-contact-information-block', {}, [] ], [ 'woocommerce/checkout-shipping-address-block', {}, [] ], @@ -48,7 +47,7 @@ export const Edit = ( { [ 'woocommerce/checkout-order-note-block', {}, [] ], [ 'woocommerce/checkout-terms-block', {}, [] ], [ 'woocommerce/checkout-actions-block', {}, [] ], - ].filter( Boolean ) as unknown ) as TemplateArray; + ].filter( Boolean ) as unknown as TemplateArray; useForcedLayout( { clientId, diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-block/test/block.js b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-block/test/block.js index aced808a6d9..cd2de576659 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-block/test/block.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-block/test/block.js @@ -103,8 +103,7 @@ jest.mock( '@woocommerce/base-context/hooks', () => ( { meta_data: [ { key: 'Items', - value: - 'Hoodie - Blue, Yes × 1, Beanie × 1', + value: 'Hoodie - Blue, Yes × 1, Beanie × 1', }, ], selected: false, @@ -128,8 +127,7 @@ jest.mock( '@woocommerce/base-context/hooks', () => ( { meta_data: [ { key: 'Items', - value: - 'Hoodie - Blue, Yes × 1, Beanie × 1', + value: 'Hoodie - Blue, Yes × 1, Beanie × 1', }, ], selected: false, @@ -153,8 +151,7 @@ jest.mock( '@woocommerce/base-context/hooks', () => ( { meta_data: [ { key: 'Items', - value: - 'Hoodie - Blue, Yes × 1, Beanie × 1', + value: 'Hoodie - Blue, Yes × 1, Beanie × 1', }, ], selected: true, @@ -476,8 +473,7 @@ describe( 'Checkout Order Summary', () => { meta_data: [ { key: 'Items', - value: - 'Hoodie - Blue, Yes × 1, Beanie × 1', + value: 'Hoodie - Blue, Yes × 1, Beanie × 1', }, ], selected: true, diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/block.tsx index 30a8ae4353c..03e34d428be 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-coupon-form/block.tsx @@ -13,9 +13,8 @@ const Block = ( { } ): JSX.Element | null => { const couponsEnabled = getSetting( 'couponsEnabled', true ); - const { applyCoupon, isApplyingCoupon } = useStoreCartCoupons( - 'wc/checkout' - ); + const { applyCoupon, isApplyingCoupon } = + useStoreCartCoupons( 'wc/checkout' ); if ( ! couponsEnabled ) { return null; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/block.tsx index cf9fd4d6df9..4068d6a5719 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-discount/block.tsx @@ -27,9 +27,8 @@ const DiscountSlotFill = (): JSX.Element => { const Block = ( { className = '' }: { className?: string } ): JSX.Element => { const { cartTotals, cartCoupons } = useStoreCart(); - const { removeCoupon, isRemovingCoupon } = useStoreCartCoupons( - 'wc/checkout' - ); + const { removeCoupon, isRemovingCoupon } = + useStoreCartCoupons( 'wc/checkout' ); const totalsCurrency = getCurrencyFromPriceResponse( cartTotals ); return ( diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/edit.tsx index d7b925202c9..9d3c3df688a 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-order-summary-taxes/edit.tsx @@ -56,7 +56,8 @@ export const Edit = ( { checked={ showRateAfterTaxName } onChange={ () => setAttributes( { - showRateAfterTaxName: ! showRateAfterTaxName, + showRateAfterTaxName: + ! showRateAfterTaxName, } ) } /> diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/edit.tsx index b10d8e02868..645f5541623 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/edit.tsx @@ -38,9 +38,8 @@ export const Edit = ( { showPhoneField, requirePhoneField, } = useCheckoutBlockContext(); - const { - addressFieldControls: Controls, - } = useCheckoutBlockControlsContext(); + const { addressFieldControls: Controls } = + useCheckoutBlockControlsContext(); return ( { return null; } - const shippingRatesPackageCount = getShippingRatesPackageCount( - shippingRates - ); + const shippingRatesPackageCount = + getShippingRatesPackageCount( shippingRates ); if ( ! isEditor && diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/frontend.tsx b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/frontend.tsx index 098f68dc5ee..cef8fc5ec20 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/frontend.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/frontend.tsx @@ -32,11 +32,8 @@ const FrontendBlock = ( { const { isDisabled } = useCheckoutSubmit(); const validationErrorId = 'terms-and-conditions-' + instanceId; - const { - getValidationError, - setValidationErrors, - clearValidationError, - } = validation; + const { getValidationError, setValidationErrors, clearValidationError } = + validation; const error = getValidationError( validationErrorId ) || {}; const hasError = error.message && ! error.hidden; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/test/edit.js b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/test/edit.js index f46b8340848..1523f7003cb 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/test/edit.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-terms-block/test/edit.js @@ -91,8 +91,7 @@ describe( 'Edit', () => { const { container } = render( terms and privacy', + text: 'I agree to the terms and privacy', checkbox: true, } } setAttributes={ () => void 0 } diff --git a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/register-components.ts b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/register-components.ts index a6837e41ee0..0c4fd7b7888 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/register-components.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/register-components.ts @@ -17,178 +17,197 @@ __webpack_public_path__ = WC_BLOCKS_BUILD_URL; // @todo When forcing all blocks at once, they will append based on the order they are registered. Introduce formal sorting param. registerCheckoutBlock( { metadata: metadata.CHECKOUT_FIELDS, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/fields" */ './checkout-fields-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/fields" */ './checkout-fields-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_EXPRESS_PAYMENT, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/express-payment" */ './checkout-express-payment-block/block' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/express-payment" */ './checkout-express-payment-block/block' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_CONTACT_INFORMATION, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/contact-information" */ './checkout-contact-information-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/contact-information" */ './checkout-contact-information-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_SHIPPING_ADDRESS, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/shipping-address" */ './checkout-shipping-address-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/shipping-address" */ './checkout-shipping-address-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_BILLING_ADDRESS, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/billing-address" */ './checkout-billing-address-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/billing-address" */ './checkout-billing-address-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_SHIPPING_METHODS, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/shipping-methods" */ './checkout-shipping-methods-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/shipping-methods" */ './checkout-shipping-methods-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_PAYMENT, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/payment" */ './checkout-payment-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/payment" */ './checkout-payment-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_ORDER_NOTE, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/order-note" */ './checkout-order-note-block/block' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/order-note" */ './checkout-order-note-block/block' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_TERMS, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/terms" */ './checkout-terms-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/terms" */ './checkout-terms-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_ACTIONS, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/actions" */ './checkout-actions-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/actions" */ './checkout-actions-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_TOTALS, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/totals" */ './checkout-totals-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/totals" */ './checkout-totals-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_ORDER_SUMMARY, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/order-summary" */ './checkout-order-summary-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/order-summary" */ './checkout-order-summary-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_ORDER_SUMMARY_CART_ITEMS, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/order-summary-cart-items" */ - './checkout-order-summary-cart-items/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/order-summary-cart-items" */ + './checkout-order-summary-cart-items/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_ORDER_SUMMARY_SUBTOTAL, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/order-summary-subtotal" */ - './checkout-order-summary-subtotal/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/order-summary-subtotal" */ + './checkout-order-summary-subtotal/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_ORDER_SUMMARY_FEE, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/order-summary-fee" */ - './checkout-order-summary-fee/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/order-summary-fee" */ + './checkout-order-summary-fee/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_ORDER_SUMMARY_DISCOUNT, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/order-summary-discount" */ - './checkout-order-summary-discount/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/order-summary-discount" */ + './checkout-order-summary-discount/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_ORDER_SUMMARY_COUPON_FORM, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/order-summary-coupon-form" */ - './checkout-order-summary-coupon-form/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/order-summary-coupon-form" */ + './checkout-order-summary-coupon-form/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_ORDER_SUMMARY_SHIPPING, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/order-summary-shipping" */ - './checkout-order-summary-shipping/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/order-summary-shipping" */ + './checkout-order-summary-shipping/frontend' + ) ), } ); registerCheckoutBlock( { metadata: metadata.CHECKOUT_ORDER_SUMMARY_TAXES, - component: lazy( () => - import( - /* webpackChunkName: "checkout-blocks/order-summary-taxes" */ - './checkout-order-summary-taxes/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "checkout-blocks/order-summary-taxes" */ + './checkout-order-summary-taxes/frontend' + ) ), } ); diff --git a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/block-controls.tsx b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/block-controls.tsx index 789490665f4..79d3754e4b3 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/block-controls.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/block-controls.tsx @@ -136,39 +136,37 @@ export const BlockControls = ( { ); }; -export const withBlockControls = ( { - cropLabel, - editLabel, -}: BlockControlsConfiguration ) => < T extends EditorBlock< T > >( - Component: ComponentType< T > -) => ( props: WithBlockControlsProps< T > ) => { - const [ isEditingImage, setIsEditingImage ] = props.useEditingImage; - const { attributes, category, name, product, setAttributes } = props; - const { contentAlign, editMode, mediaId, mediaSrc } = attributes; - const item = category || product; +export const withBlockControls = + ( { cropLabel, editLabel }: BlockControlsConfiguration ) => + < T extends EditorBlock< T > >( Component: ComponentType< T > ) => + ( props: WithBlockControlsProps< T > ) => { + const [ isEditingImage, setIsEditingImage ] = props.useEditingImage; + const { attributes, category, name, product, setAttributes } = props; + const { contentAlign, editMode, mediaId, mediaSrc } = attributes; + const item = category || product; - const { backgroundImageId, backgroundImageSrc } = useBackgroundImage( { - item, - mediaId, - mediaSrc, - blockName: name, - } ); + const { backgroundImageId, backgroundImageSrc } = useBackgroundImage( { + item, + mediaId, + mediaSrc, + blockName: name, + } ); - return ( - <> - - - - ); -}; + return ( + <> + + + + ); + }; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/image-editor.tsx b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/image-editor.tsx index bd426d52e75..843ba04d582 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/image-editor.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/image-editor.tsx @@ -92,35 +92,37 @@ export const ImageEditor = ( { ); }; -export const withImageEditor = < T extends EditorBlock< T > >( - Component: ComponentType< T > -) => ( props: WithImageEditorProps< T > ) => { - const [ isEditingImage, setIsEditingImage ] = props.useEditingImage; +export const withImageEditor = + < T extends EditorBlock< T > >( Component: ComponentType< T > ) => + ( props: WithImageEditorProps< T > ) => { + const [ isEditingImage, setIsEditingImage ] = props.useEditingImage; - const { attributes, backgroundImageSize, name, setAttributes } = props; - const { mediaId, mediaSrc } = attributes; - const item = - name === BLOCK_NAMES.featuredProduct ? props.product : props.category; + const { attributes, backgroundImageSize, name, setAttributes } = props; + const { mediaId, mediaSrc } = attributes; + const item = + name === BLOCK_NAMES.featuredProduct + ? props.product + : props.category; - const { backgroundImageId, backgroundImageSrc } = useBackgroundImage( { - item, - mediaId, - mediaSrc, - blockName: name, - } ); + const { backgroundImageId, backgroundImageSrc } = useBackgroundImage( { + item, + mediaId, + mediaSrc, + blockName: name, + } ); - if ( isEditingImage ) { - return ( - - ); - } + if ( isEditingImage ) { + return ( + + ); + } - return ; -}; + return ; + }; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/inspector-controls.tsx b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/inspector-controls.tsx index ab81c80df73..0daaaf72c0f 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/inspector-controls.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/inspector-controls.tsx @@ -287,70 +287,72 @@ export const InspectorControls = ( { ); }; -export const withInspectorControls = < T extends EditorBlock< T > >( - Component: ComponentType< T > -) => ( props: WithInspectorControlsProps< T > ) => { - const { attributes, name, setAttributes } = props; - const { - alt, - dimRatio, - focalPoint, - hasParallax, - isRepeated, - imageFit, - mediaId, - mediaSrc, - overlayColor, - overlayGradient, - showDesc, - showPrice, - } = attributes; +export const withInspectorControls = + < T extends EditorBlock< T > >( Component: ComponentType< T > ) => + ( props: WithInspectorControlsProps< T > ) => { + const { attributes, name, setAttributes } = props; + const { + alt, + dimRatio, + focalPoint, + hasParallax, + isRepeated, + imageFit, + mediaId, + mediaSrc, + overlayColor, + overlayGradient, + showDesc, + showPrice, + } = attributes; - const item = - name === BLOCK_NAMES.featuredProduct ? props.product : props.category; + const item = + name === BLOCK_NAMES.featuredProduct + ? props.product + : props.category; - const { setGradient } = useGradient( { - gradientAttribute: 'overlayGradient', - customGradientAttribute: 'overlayGradient', - } ); - const { backgroundImageSrc } = useBackgroundImage( { - item, - mediaId, - mediaSrc, - blockName: name, - } ); + const { setGradient } = useGradient( { + gradientAttribute: 'overlayGradient', + customGradientAttribute: 'overlayGradient', + } ); + const { backgroundImageSrc } = useBackgroundImage( { + item, + mediaId, + mediaSrc, + blockName: name, + } ); - const contentPanel = - name === BLOCK_NAMES.featuredProduct ? ( - - setAttributes( { - showPrice: ! showPrice, - } ) - } - /> - ) : undefined; + const contentPanel = + name === BLOCK_NAMES.featuredProduct ? ( + + setAttributes( { + showPrice: ! showPrice, + } ) + } + /> + ) : undefined; - return ( - <> - - - - ); -}; + return ( + <> + + + + ); + }; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/utils.ts b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/utils.ts index 140053be7f2..d4a7d9162d4 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/utils.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/utils.ts @@ -61,9 +61,8 @@ export function getBackgroundImageStyles( { ...( url && { backgroundImage: `url(${ url })`, } ), - backgroundPosition: calculatePercentPositionFromCoordinates( - focalPoint - ), + backgroundPosition: + calculatePercentPositionFromCoordinates( focalPoint ), ...( ! isRepeated && { backgroundRepeat: 'no-repeat', backgroundSize: imageFit === 'cover' ? imageFit : 'auto', diff --git a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-api-error.tsx b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-api-error.tsx index 36bd29c4df9..a49ce87ec97 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-api-error.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-api-error.tsx @@ -33,27 +33,27 @@ type APIErrorProps< T extends Block > = | ( T & APIErrorProductProps ) | ( T & APIErrorCategoryProps ); -export const withApiError = < T extends Block >( - Component: ComponentType< T > -) => ( props: APIErrorProps< T > ) => { - const { error, isLoading, name } = props; +export const withApiError = + < T extends Block >( Component: ComponentType< T > ) => + ( props: APIErrorProps< T > ) => { + const { error, isLoading, name } = props; - const className = getClassPrefixFromName( name ); - const onRetry = - name === BLOCK_NAMES.featuredCategory - ? props.getCategory - : props.getProduct; + const className = getClassPrefixFromName( name ); + const onRetry = + name === BLOCK_NAMES.featuredCategory + ? props.getCategory + : props.getProduct; - if ( error ) { - return ( - - ); - } + if ( error ) { + return ( + + ); + } - return ; -}; + return ; + }; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-edit-mode.tsx b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-edit-mode.tsx index 02db002e9dc..7e4e91fdf1e 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-edit-mode.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-edit-mode.tsx @@ -40,94 +40,90 @@ interface EditModeRequiredProps< T > { type EditModeProps< T extends EditorBlock< T > > = T & EditModeRequiredProps< T >; -export const withEditMode = ( { - description, - editLabel, - icon, - label, -}: EditModeConfiguration ) => < T extends EditorBlock< T > >( - Component: ComponentType< T > -) => ( props: EditModeProps< T > ) => { - const { - attributes, - debouncedSpeak, - name, - setAttributes, - triggerUrlUpdate = () => void null, - } = props; +export const withEditMode = + ( { description, editLabel, icon, label }: EditModeConfiguration ) => + < T extends EditorBlock< T > >( Component: ComponentType< T > ) => + ( props: EditModeProps< T > ) => { + const { + attributes, + debouncedSpeak, + name, + setAttributes, + triggerUrlUpdate = () => void null, + } = props; - const className = getClassPrefixFromName( name ); + const className = getClassPrefixFromName( name ); - const onDone = () => { - setAttributes( { editMode: false } ); - debouncedSpeak( editLabel ); - }; + const onDone = () => { + setAttributes( { editMode: false } ); + debouncedSpeak( editLabel ); + }; - if ( attributes.editMode ) { - return ( - } - label={ label } - className={ className } - > - { description } -
- { name === BLOCK_NAMES.featuredCategory && ( - // Ignoring this TS error for now as it seems that `ProductCategoryControl` - // types might be too strict. - // @todo Convert `ProductCategoryControl` to TypeScript - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - { - const id = value[ 0 ] ? value[ 0 ].id : 0; - setAttributes( { - categoryId: id, - mediaId: 0, - mediaSrc: '', - } ); - triggerUrlUpdate(); - } } - isSingle - /> - ) } - { name === BLOCK_NAMES.featuredProduct && ( - } + label={ label } + className={ className } + > + { description } +
+ { name === BLOCK_NAMES.featuredCategory && ( + // Ignoring this TS error for now as it seems that `ProductCategoryControl` + // types might be too strict. + // @todo Convert `ProductCategoryControl` to TypeScript // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - showVariations - onChange={ ( - value: ProductResponseItem[] = [] - ) => { - const id = value[ 0 ] ? value[ 0 ].id : 0; - setAttributes( { - productId: id, - mediaId: 0, - mediaSrc: '', - } ); - triggerUrlUpdate(); - } } - /> - ) } - -
- - ); - } + { + const id = value[ 0 ] ? value[ 0 ].id : 0; + setAttributes( { + categoryId: id, + mediaId: 0, + mediaSrc: '', + } ); + triggerUrlUpdate(); + } } + isSingle + /> + ) } + { name === BLOCK_NAMES.featuredProduct && ( + { + const id = value[ 0 ] ? value[ 0 ].id : 0; + setAttributes( { + productId: id, + mediaId: 0, + mediaSrc: '', + } ); + triggerUrlUpdate(); + } } + /> + ) } + +
+
+ ); + } - return ; -}; + return ; + }; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-editing-image.tsx b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-editing-image.tsx index 1e36e8c7738..d9e860441ef 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-editing-image.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-editing-image.tsx @@ -15,20 +15,20 @@ interface EditingImageRequiredProps { type EditingImageProps< T extends EditorBlock< T > > = T & EditingImageRequiredProps; -export const withEditingImage = < T extends EditorBlock< T > >( - Component: ComponentType< T > -) => ( props: EditingImageProps< T > ) => { - const [ isEditingImage, setIsEditingImage ] = useState( false ); - const { isSelected } = props; +export const withEditingImage = + < T extends EditorBlock< T > >( Component: ComponentType< T > ) => + ( props: EditingImageProps< T > ) => { + const [ isEditingImage, setIsEditingImage ] = useState( false ); + const { isSelected } = props; - useEffect( () => { - setIsEditingImage( false ); - }, [ isSelected ] ); + useEffect( () => { + setIsEditingImage( false ); + }, [ isSelected ] ); - return ( - - ); -}; + return ( + + ); + }; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-featured-item.tsx b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-featured-item.tsx index f411ea269c4..77130ee8a1f 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-featured-item.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-featured-item.tsx @@ -97,227 +97,226 @@ type FeaturedItemProps< T extends EditorBlock< T > > = | ( T & FeaturedCategoryProps< T > ) | ( T & FeaturedProductProps< T > ); -export const withFeaturedItem = ( { - emptyMessage, - icon, - label, -}: WithFeaturedItemConfig ) => < T extends EditorBlock< T > >( - Component: ComponentType< T > -) => ( props: FeaturedItemProps< T > ) => { - const [ isEditingImage ] = props.useEditingImage; +export const withFeaturedItem = + ( { emptyMessage, icon, label }: WithFeaturedItemConfig ) => + < T extends EditorBlock< T > >( Component: ComponentType< T > ) => + ( props: FeaturedItemProps< T > ) => { + const [ isEditingImage ] = props.useEditingImage; - const { - attributes, - category, - isLoading, - isSelected, - name, - product, - setAttributes, - } = props; - const { mediaId, mediaSrc } = attributes; - const item = category || product; - const [ backgroundImageSize, setBackgroundImageSize ] = useState( {} ); - - const { backgroundImageSrc } = useBackgroundImage( { - item, - mediaId, - mediaSrc, - blockName: name, - } ); - - const className = getClassPrefixFromName( name ); - - const onResize = useCallback( - ( _event, _direction, elt ) => { - setAttributes( { minHeight: parseInt( elt.style.height, 10 ) } ); - }, - [ setAttributes ] - ); - - const renderButton = () => { - const { categoryId, linkText, productId } = attributes; - - return ( - - ); - }; - - const renderNoItem = () => ( - } - label={ label } - > - { isLoading ? : emptyMessage } - - ); - - const renderItem = () => { const { - contentAlign, - dimRatio, - focalPoint, - hasParallax, - isRepeated, - imageFit, - minHeight, - overlayColor, - overlayGradient, - showDesc, - showPrice, - style, - textColor, - } = attributes; + attributes, + category, + isLoading, + isSelected, + name, + product, + setAttributes, + } = props; + const { mediaId, mediaSrc } = attributes; + const item = category || product; + const [ backgroundImageSize, setBackgroundImageSize ] = useState( {} ); - const classes = classnames( - className, - { - 'is-selected': - isSelected && - attributes.categoryId !== 'preview' && - attributes.productId !== 'preview', - 'is-loading': ! item && isLoading, - 'is-not-found': ! item && ! isLoading, - 'has-background-dim': dimRatio !== 0, - 'is-repeated': isRepeated, - }, - dimRatioToClass( dimRatio ), - contentAlign !== 'center' && `has-${ contentAlign }-content` - ); - - const containerStyle = { - borderRadius: style?.border?.radius, - color: textColor - ? `var(--wp--preset--color--${ textColor })` - : style?.color?.text, - }; - - const wrapperStyle = { - ...getSpacingClassesAndStyles( attributes ).style, - minHeight, - }; - - const isImgElement = ! isRepeated && ! hasParallax; - - const backgroundImageStyle = getBackgroundImageStyles( { - focalPoint, - imageFit, - isImgElement, - isRepeated, - url: backgroundImageSrc, + const { backgroundImageSrc } = useBackgroundImage( { + item, + mediaId, + mediaSrc, + blockName: name, } ); - const overlayStyle = { - background: overlayGradient, - backgroundColor: overlayColor, + const className = getClassPrefixFromName( name ); + + const onResize = useCallback( + ( _event, _direction, elt ) => { + setAttributes( { + minHeight: parseInt( elt.style.height, 10 ), + } ); + }, + [ setAttributes ] + ); + + const renderButton = () => { + const { categoryId, linkText, productId } = attributes; + + return ( + + ); }; + const renderNoItem = () => ( + } + label={ label } + > + { isLoading ? : emptyMessage } + + ); + + const renderItem = () => { + const { + contentAlign, + dimRatio, + focalPoint, + hasParallax, + isRepeated, + imageFit, + minHeight, + overlayColor, + overlayGradient, + showDesc, + showPrice, + style, + textColor, + } = attributes; + + const classes = classnames( + className, + { + 'is-selected': + isSelected && + attributes.categoryId !== 'preview' && + attributes.productId !== 'preview', + 'is-loading': ! item && isLoading, + 'is-not-found': ! item && ! isLoading, + 'has-background-dim': dimRatio !== 0, + 'is-repeated': isRepeated, + }, + dimRatioToClass( dimRatio ), + contentAlign !== 'center' && `has-${ contentAlign }-content` + ); + + const containerStyle = { + borderRadius: style?.border?.radius, + color: textColor + ? `var(--wp--preset--color--${ textColor })` + : style?.color?.text, + }; + + const wrapperStyle = { + ...getSpacingClassesAndStyles( attributes ).style, + minHeight, + }; + + const isImgElement = ! isRepeated && ! hasParallax; + + const backgroundImageStyle = getBackgroundImageStyles( { + focalPoint, + imageFit, + isImgElement, + isRepeated, + url: backgroundImageSrc, + } ); + + const overlayStyle = { + background: overlayGradient, + backgroundColor: overlayColor, + }; + + return ( + <> + +
+
+
+ { backgroundImageSrc && + ( isImgElement ? ( + { { + setBackgroundImageSize( { + height: e.currentTarget + ?.naturalHeight, + width: e.currentTarget + ?.naturalWidth, + } ); + } } + /> + ) : ( +
+ ) ) } +

+ { ! isEmpty( product?.variation ) && ( +

+ ) } + { showDesc && ( +
+ ) } + { showPrice && ( +
+ ) } +
+ { renderButton() } +
+
+
+ + ); + }; + + if ( isEditingImage ) { + return ( + + ); + } + return ( <> - -
-
-
- { backgroundImageSrc && - ( isImgElement ? ( - { { - setBackgroundImageSize( { - height: - e.currentTarget?.naturalHeight, - width: - e.currentTarget?.naturalWidth, - } ); - } } - /> - ) : ( -
- ) ) } -

- { ! isEmpty( product?.variation ) && ( -

- ) } - { showDesc && ( -
- ) } - { showPrice && ( -
- ) } -
- { renderButton() } -
-
-
+ { item ? renderItem() : renderNoItem() } ); }; - - if ( isEditingImage ) { - return ( - - ); - } - - return ( - <> - - { item ? renderItem() : renderNoItem() } - - ); -}; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-update-button-attributes.tsx b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-update-button-attributes.tsx index 94ff7dcef64..9a58bc975d6 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-update-button-attributes.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/featured-items/with-update-button-attributes.tsx @@ -36,55 +36,55 @@ type WithUpdateButtonProps< T extends EditorBlock< T > > = | ( T & WithUpdateButtonCategoryProps< T > ) | ( T & WithUpdateButtonProductProps< T > ); -export const withUpdateButtonAttributes = < T extends EditorBlock< T > >( - Component: ComponentType< T > -) => ( props: WithUpdateButtonProps< T > ) => { - const [ doUrlUpdate, setDoUrlUpdate ] = useState( false ); - const { attributes, category, clientId, product } = props; - const item = category || product; +export const withUpdateButtonAttributes = + < T extends EditorBlock< T > >( Component: ComponentType< T > ) => + ( props: WithUpdateButtonProps< T > ) => { + const [ doUrlUpdate, setDoUrlUpdate ] = useState( false ); + const { attributes, category, clientId, product } = props; + const item = category || product; - const { editMode } = attributes; - const permalink = - ( item as WP_REST_API_Category )?.link || - ( item as ProductResponseItem )?.permalink; + const { editMode } = attributes; + const permalink = + ( item as WP_REST_API_Category )?.link || + ( item as ProductResponseItem )?.permalink; - const Block = useSelect( ( select ) => { - return select( 'core/block-editor' ).getBlock( clientId ); - } ); - const InnerButton = Block?.innerBlocks[ 0 ]; - const buttonBlockId = InnerButton?.clientId || ''; - const currentButtonAttributes = useMemo( - () => InnerButton?.attributes || {}, - [ InnerButton ] - ); - const { url } = currentButtonAttributes; + const Block = useSelect( ( select ) => { + return select( 'core/block-editor' ).getBlock( clientId ); + } ); + const InnerButton = Block?.innerBlocks[ 0 ]; + const buttonBlockId = InnerButton?.clientId || ''; + const currentButtonAttributes = useMemo( + () => InnerButton?.attributes || {}, + [ InnerButton ] + ); + const { url } = currentButtonAttributes; - const { updateBlockAttributes } = useDispatch( 'core/block-editor' ); + const { updateBlockAttributes } = useDispatch( 'core/block-editor' ); - useEffect( () => { - if ( - doUrlUpdate && - buttonBlockId && - ! editMode && - permalink && - url && - permalink !== url - ) { - updateBlockAttributes( buttonBlockId, { - url: permalink, - } ); - setDoUrlUpdate( false ); - } - }, [ - buttonBlockId, - doUrlUpdate, - editMode, - permalink, - updateBlockAttributes, - url, - ] ); + useEffect( () => { + if ( + doUrlUpdate && + buttonBlockId && + ! editMode && + permalink && + url && + permalink !== url + ) { + updateBlockAttributes( buttonBlockId, { + url: permalink, + } ); + setDoUrlUpdate( false ); + } + }, [ + buttonBlockId, + doUrlUpdate, + editMode, + permalink, + updateBlockAttributes, + url, + ] ); - const triggerUrlUpdate = () => setDoUrlUpdate( true ); + const triggerUrlUpdate = () => setDoUrlUpdate( true ); - return ; -}; + return ; + }; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/handpicked-products/block.json b/plugins/woocommerce-blocks/assets/js/blocks/handpicked-products/block.json index 7e0629c907f..b6819377598 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/handpicked-products/block.json +++ b/plugins/woocommerce-blocks/assets/js/blocks/handpicked-products/block.json @@ -1,86 +1,80 @@ { - "name": "woocommerce/handpicked-products", - "title": "Hand-picked Products", - "category": "woocommerce", - "keywords": [ - "Handpicked Products", - "WooCommerce" - ], - "description": "Display a selection of hand-picked products in a grid.", - "supports": { - "align": [ - "wide", - "full" - ], - "html": false - }, - "attributes": { - "align": { - "type": "string" - }, - "columns": { - "type": "number", - "default": 3 - }, - "contentVisibility": { - "type": "object", - "default": { - "image": true, - "title": true, - "price": true, - "rating": true, - "button": true - }, - "properties": { - "image": { - "type": "boolean", - "image": true - }, - "title": { - "type": "boolean", - "title": true - }, - "price": { - "type": "boolean", - "price": true - }, - "rating": { - "type": "boolean", - "rating": true - }, - "button": { - "type": "boolean", - "button": true - } - } - }, - "orderby": { - "type": "string", - "enum": [ - "date", - "popularity", - "price_asc", - "price_desc", - "rating", - "title", - "menu_order" - ], - "default": "date" - }, - "products": { - "type": "array", - "default": [] - }, - "alignButtons": { - "type": "boolean", - "default": false - }, - "isPreview": { - "type": "boolean", - "default": false - } - }, - "textdomain": "woo-gutenberg-products-block", - "apiVersion": 2, - "$schema": "https://schemas.wp.org/trunk/block.json" + "name": "woocommerce/handpicked-products", + "title": "Hand-picked Products", + "category": "woocommerce", + "keywords": [ "Handpicked Products", "WooCommerce" ], + "description": "Display a selection of hand-picked products in a grid.", + "supports": { + "align": [ "wide", "full" ], + "html": false + }, + "attributes": { + "align": { + "type": "string" + }, + "columns": { + "type": "number", + "default": 3 + }, + "contentVisibility": { + "type": "object", + "default": { + "image": true, + "title": true, + "price": true, + "rating": true, + "button": true + }, + "properties": { + "image": { + "type": "boolean", + "image": true + }, + "title": { + "type": "boolean", + "title": true + }, + "price": { + "type": "boolean", + "price": true + }, + "rating": { + "type": "boolean", + "rating": true + }, + "button": { + "type": "boolean", + "button": true + } + } + }, + "orderby": { + "type": "string", + "enum": [ + "date", + "popularity", + "price_asc", + "price_desc", + "rating", + "title", + "menu_order" + ], + "default": "date" + }, + "products": { + "type": "array", + "default": [] + }, + "alignButtons": { + "type": "boolean", + "default": false + }, + "isPreview": { + "type": "boolean", + "default": false + } + }, + "textdomain": "woo-gutenberg-products-block", + "apiVersion": 2, + "$schema": "https://schemas.wp.org/trunk/block.json" } diff --git a/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/block.tsx index 8fb3025523f..9c73f54ea0f 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/block.tsx @@ -67,9 +67,8 @@ const MiniCartBlock = ( { const [ isOpen, setIsOpen ] = useState< boolean >( isInitiallyOpen ); // We already rendered the HTML drawer placeholder, so we want to skip the // slide in animation. - const [ skipSlideIn, setSkipSlideIn ] = useState< boolean >( - isInitiallyOpen - ); + const [ skipSlideIn, setSkipSlideIn ] = + useState< boolean >( isInitiallyOpen ); const [ contentsNode, setContentsNode ] = useState< HTMLDivElement | null >( null ); @@ -154,11 +153,12 @@ const MiniCartBlock = ( { isBoolean ); - const preFetchedCartTotals = getSettingWithCoercion< CartResponseTotals | null >( - 'cartTotals', - null, - isCartResponseTotals - ); + const preFetchedCartTotals = + getSettingWithCoercion< CartResponseTotals | null >( + 'cartTotals', + null, + isCartResponseTotals + ); const preFetchedCartItemsCount = getSettingWithCoercion< number >( 'cartItemsCount', diff --git a/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/filled-mini-cart-contents-block/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/filled-mini-cart-contents-block/edit.tsx index 2c8c3db875f..d991483cacd 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/filled-mini-cart-contents-block/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/filled-mini-cart-contents-block/edit.tsx @@ -20,11 +20,11 @@ export const Edit = ( { clientId }: { clientId: string } ): JSX.Element => { const allowedBlocks = getAllowedBlocks( innerBlockAreas.FILLED_MINI_CART ); const { currentView } = useEditorContext(); - const defaultTemplate = ( [ + const defaultTemplate = [ [ 'woocommerce/mini-cart-title-block', {} ], [ 'woocommerce/mini-cart-items-block', {} ], [ 'woocommerce/mini-cart-footer-block', {} ], - ].filter( Boolean ) as unknown ) as TemplateArray; + ].filter( Boolean ) as unknown as TemplateArray; useForcedLayout( { clientId, diff --git a/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-items-block/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-items-block/edit.tsx index dd7b4fcdb91..6005b8e74f3 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-items-block/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-items-block/edit.tsx @@ -14,9 +14,9 @@ export const Edit = (): JSX.Element => { className: 'wc-block-mini-cart__items', } ); - const defaultTemplate = ( [ + const defaultTemplate = [ [ 'woocommerce/mini-cart-products-table-block', {} ], - ].filter( Boolean ) as unknown ) as TemplateArray; + ].filter( Boolean ) as unknown as TemplateArray; return (
diff --git a/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/register-components.ts b/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/register-components.ts index d29a13b2d83..79aa25254e3 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/register-components.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/register-components.ts @@ -21,63 +21,70 @@ __webpack_public_path__ = WC_BLOCKS_BUILD_URL; registerCheckoutBlock( { metadata: filledMiniCartMetadata, - component: lazy( () => - import( - /* webpackChunkName: "mini-cart-contents-block/filled-cart" */ './filled-mini-cart-contents-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "mini-cart-contents-block/filled-cart" */ './filled-mini-cart-contents-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: emptyMiniCartContentsMetadata, - component: lazy( () => - import( - /* webpackChunkName: "mini-cart-contents-block/empty-cart" */ './empty-mini-cart-contents-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "mini-cart-contents-block/empty-cart" */ './empty-mini-cart-contents-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: miniCartTitleMetadata, - component: lazy( () => - import( - /* webpackChunkName: "mini-cart-contents-block/title" */ './mini-cart-title-block/block' - ) + component: lazy( + () => + import( + /* webpackChunkName: "mini-cart-contents-block/title" */ './mini-cart-title-block/block' + ) ), } ); registerCheckoutBlock( { metadata: miniCartItemsMetadata, - component: lazy( () => - import( - /* webpackChunkName: "mini-cart-contents-block/items" */ './mini-cart-items-block/frontend' - ) + component: lazy( + () => + import( + /* webpackChunkName: "mini-cart-contents-block/items" */ './mini-cart-items-block/frontend' + ) ), } ); registerCheckoutBlock( { metadata: miniCartProductsTableMetadata, - component: lazy( () => - import( - /* webpackChunkName: "mini-cart-contents-block/products-table" */ './mini-cart-products-table-block/block' - ) + component: lazy( + () => + import( + /* webpackChunkName: "mini-cart-contents-block/products-table" */ './mini-cart-products-table-block/block' + ) ), } ); registerCheckoutBlock( { metadata: miniCartFooterMetadata, - component: lazy( () => - import( - /* webpackChunkName: "mini-cart-contents-block/footer" */ './mini-cart-footer-block/block' - ) + component: lazy( + () => + import( + /* webpackChunkName: "mini-cart-contents-block/footer" */ './mini-cart-footer-block/block' + ) ), } ); registerCheckoutBlock( { metadata: miniCartShoppingButtonMetadata, - component: lazy( () => - import( - /* webpackChunkName: "mini-cart-contents-block/shopping-button" */ './mini-cart-shopping-button-block/block' - ) + component: lazy( + () => + import( + /* webpackChunkName: "mini-cart-contents-block/shopping-button" */ './mini-cart-shopping-button-block/block' + ) ), } ); diff --git a/plugins/woocommerce-blocks/assets/js/blocks/price-filter/block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/price-filter/block.tsx index 750b5b273e6..7568ff3ac3c 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/price-filter/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/price-filter/block.tsx @@ -100,9 +100,8 @@ const PriceFilterBlock = ( { * Important: Only used on the PHP rendered Block pages to track * the price filter defaults coming from the URL */ - const [ hasSetPhpFilterDefaults, setHasSetPhpFilterDefaults ] = useState( - false - ); + const [ hasSetPhpFilterDefaults, setHasSetPhpFilterDefaults ] = + useState( false ); const minPriceParam = getUrlParameter( 'min_price' ); const maxPriceParam = getUrlParameter( 'max_price' ); @@ -315,7 +314,8 @@ const PriceFilterBlock = ( { return null; } - const TagName = `h${ attributes.headingLevel }` as keyof JSX.IntrinsicElements; + const TagName = + `h${ attributes.headingLevel }` as keyof JSX.IntrinsicElements; return ( <> diff --git a/plugins/woocommerce-blocks/assets/js/blocks/price-filter/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/price-filter/edit.tsx index f58e6f422a7..df830023625 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/price-filter/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/price-filter/edit.tsx @@ -32,12 +32,8 @@ export default function ( { attributes, setAttributes, }: BlockEditProps< Attributes > ) { - const { - heading, - headingLevel, - showInputFields, - showFilterButton, - } = attributes; + const { heading, headingLevel, showInputFields, showFilterButton } = + attributes; const blockProps = useBlockProps(); diff --git a/plugins/woocommerce-blocks/assets/js/blocks/product-categories/block.js b/plugins/woocommerce-blocks/assets/js/blocks/product-categories/block.js index 725ab502324..854d1565734 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/product-categories/block.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/product-categories/block.js @@ -43,13 +43,8 @@ const EmptyPlaceholder = () => ( */ const ProductCategoriesBlock = ( { attributes, setAttributes, name } ) => { const getInspectorControls = () => { - const { - hasCount, - hasImage, - hasEmpty, - isDropdown, - isHierarchical, - } = attributes; + const { hasCount, hasImage, hasEmpty, isDropdown, isHierarchical } = + attributes; return ( diff --git a/plugins/woocommerce-blocks/assets/js/blocks/product-categories/index.js b/plugins/woocommerce-blocks/assets/js/blocks/product-categories/index.js index 270524f0a02..9715d879d34 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/product-categories/index.js +++ b/plugins/woocommerce-blocks/assets/js/blocks/product-categories/index.js @@ -156,12 +156,8 @@ registerBlockType( 'woocommerce/product-categories', { return attributes; }, save( props ) { - const { - hasCount, - hasEmpty, - isDropdown, - isHierarchical, - } = props.attributes; + const { hasCount, hasEmpty, isDropdown, isHierarchical } = + props.attributes; const data = {}; if ( hasCount ) { data[ 'data-has-count' ] = true; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/product-tag/block.json b/plugins/woocommerce-blocks/assets/js/blocks/product-tag/block.json index bcfd346e9fa..04edc01d402 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/product-tag/block.json +++ b/plugins/woocommerce-blocks/assets/js/blocks/product-tag/block.json @@ -1,89 +1,84 @@ { - "name": "woocommerce/product-tag", - "title": "Products by Tag", - "category": "woocommerce", - "keywords": [ - "WooCommerce" - ], - "description": "Display a grid of products with selected tags.", - "supports": { - "align": [ - "wide", - "full" - ], - "html": false - }, - "attributes": { - "columns": { - "type": "number", - "default": 3 - }, - "rows": { - "type": "number", - "default": 3 - }, - "alignButtons": { - "type": "boolean", - "default": false - }, - "contentVisibility": { - "type": "object", - "default": { - "image": true, - "title": true, - "price": true, - "rating": true, - "button": true - }, - "properties": { - "image": { - "type": "boolean", - "default": true - }, - "title": { - "type": "boolean", - "default": true - }, - "price": { - "type": "boolean", - "default": true - }, - "rating": { - "type": "boolean", - "default": true - }, - "button": { - "type": "boolean", - "default": true - } - } - }, - "tags": { - "type": "array", - "default": [] - }, - "tagOperator": { - "type": "string", - "default": "any" - }, - "orderby": { - "type": "string", - "default": "date" - }, - "isPreview": { - "type": "boolean", - "default": false - }, - "stockStatus": { - "type": "array" - } - }, - "example": { - "attributes": { - "isPreview": true - } - }, - "textdomain": "woo-gutenberg-products-block", - "apiVersion": 2, - "$schema": "https://schemas.wp.org/trunk/block.json" + "name": "woocommerce/product-tag", + "title": "Products by Tag", + "category": "woocommerce", + "keywords": [ "WooCommerce" ], + "description": "Display a grid of products with selected tags.", + "supports": { + "align": [ "wide", "full" ], + "html": false + }, + "attributes": { + "columns": { + "type": "number", + "default": 3 + }, + "rows": { + "type": "number", + "default": 3 + }, + "alignButtons": { + "type": "boolean", + "default": false + }, + "contentVisibility": { + "type": "object", + "default": { + "image": true, + "title": true, + "price": true, + "rating": true, + "button": true + }, + "properties": { + "image": { + "type": "boolean", + "default": true + }, + "title": { + "type": "boolean", + "default": true + }, + "price": { + "type": "boolean", + "default": true + }, + "rating": { + "type": "boolean", + "default": true + }, + "button": { + "type": "boolean", + "default": true + } + } + }, + "tags": { + "type": "array", + "default": [] + }, + "tagOperator": { + "type": "string", + "default": "any" + }, + "orderby": { + "type": "string", + "default": "date" + }, + "isPreview": { + "type": "boolean", + "default": false + }, + "stockStatus": { + "type": "array" + } + }, + "example": { + "attributes": { + "isPreview": true + } + }, + "textdomain": "woo-gutenberg-products-block", + "apiVersion": 2, + "$schema": "https://schemas.wp.org/trunk/block.json" } diff --git a/plugins/woocommerce-blocks/assets/js/blocks/products-by-attribute/block.json b/plugins/woocommerce-blocks/assets/js/blocks/products-by-attribute/block.json index 09ab00fddc6..968e28868f0 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/products-by-attribute/block.json +++ b/plugins/woocommerce-blocks/assets/js/blocks/products-by-attribute/block.json @@ -1,94 +1,89 @@ { - "name": "woocommerce/products-by-attribute", - "title": "Products by Attribute", - "category": "woocommerce", - "keywords": [ - "WooCommerce" - ], - "description": "Display a grid of products with selected attributes.", - "supports": { - "align": [ - "wide", - "full" - ], - "html": false - }, - "attributes": { - "attributes": { - "type": "array", - "default": [] - }, - "attrOperator": { - "type": "string", - "enum": [ "all", "any" ], - "default": "any" - }, - "columns": { - "type": "number", - "default": 3 - }, - "contentVisibility": { - "type": "object", - "default": { - "image": true, - "title": true, - "price": true, - "rating": true, - "button": true - }, - "properties": { - "image": { - "type": "boolean", - "default": true - }, - "title": { - "type": "boolean", - "default": true - }, - "price": { - "type": "boolean", - "default": true - }, - "rating": { - "type": "boolean", - "default": true - }, - "button": { - "type": "boolean", - "default": true - } - } - }, - "orderby": { - "type": "string", - "enum": [ - "date", - "popularity", - "price_asc", - "price_desc", - "rating", - "title", - "menu_order" - ], - "default": "date" - }, - "rows": { - "type": "number", - "default": 3 - }, - "alignButtons": { - "type": "boolean", - "default": false - }, - "isPreview": { - "type": "boolean", - "default": false - }, - "stockStatus": { - "type": "array" - } - }, - "textdomain": "woo-gutenberg-products-block", - "apiVersion": 2, - "$schema": "https://schemas.wp.org/trunk/block.json" + "name": "woocommerce/products-by-attribute", + "title": "Products by Attribute", + "category": "woocommerce", + "keywords": [ "WooCommerce" ], + "description": "Display a grid of products with selected attributes.", + "supports": { + "align": [ "wide", "full" ], + "html": false + }, + "attributes": { + "attributes": { + "type": "array", + "default": [] + }, + "attrOperator": { + "type": "string", + "enum": [ "all", "any" ], + "default": "any" + }, + "columns": { + "type": "number", + "default": 3 + }, + "contentVisibility": { + "type": "object", + "default": { + "image": true, + "title": true, + "price": true, + "rating": true, + "button": true + }, + "properties": { + "image": { + "type": "boolean", + "default": true + }, + "title": { + "type": "boolean", + "default": true + }, + "price": { + "type": "boolean", + "default": true + }, + "rating": { + "type": "boolean", + "default": true + }, + "button": { + "type": "boolean", + "default": true + } + } + }, + "orderby": { + "type": "string", + "enum": [ + "date", + "popularity", + "price_asc", + "price_desc", + "rating", + "title", + "menu_order" + ], + "default": "date" + }, + "rows": { + "type": "number", + "default": 3 + }, + "alignButtons": { + "type": "boolean", + "default": false + }, + "isPreview": { + "type": "boolean", + "default": false + }, + "stockStatus": { + "type": "array" + } + }, + "textdomain": "woo-gutenberg-products-block", + "apiVersion": 2, + "$schema": "https://schemas.wp.org/trunk/block.json" } diff --git a/plugins/woocommerce-blocks/assets/js/blocks/stock-filter/block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/stock-filter/block.tsx index 633e2cbdd81..00344a3ac61 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/stock-filter/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/stock-filter/block.tsx @@ -56,9 +56,8 @@ const StockStatusFilterBlock = ( { isBoolean ); - const [ hasSetPhpFilterDefaults, setHasSetPhpFilterDefaults ] = useState( - false - ); + const [ hasSetPhpFilterDefaults, setHasSetPhpFilterDefaults ] = + useState( false ); const { outofstock, ...otherStockStatusOptions } = getSetting( 'stockStatusOptions', @@ -86,18 +85,14 @@ const StockStatusFilterBlock = ( { ); const [ queryState ] = useQueryStateByContext(); - const [ - productStockStatusQuery, - setProductStockStatusQuery, - ] = useQueryStateByKey( 'stock_status', [] ); + const [ productStockStatusQuery, setProductStockStatusQuery ] = + useQueryStateByKey( 'stock_status', [] ); - const { - results: filteredCounts, - isLoading: filteredCountsLoading, - } = useCollectionData( { - queryStock: true, - queryState, - } ); + const { results: filteredCounts, isLoading: filteredCountsLoading } = + useCollectionData( { + queryStock: true, + queryState, + } ); /** * Get count data about a given status by slug. @@ -354,7 +349,8 @@ const StockStatusFilterBlock = ( { return null; } - const TagName = `h${ blockAttributes.headingLevel }` as keyof JSX.IntrinsicElements; + const TagName = + `h${ blockAttributes.headingLevel }` as keyof JSX.IntrinsicElements; const isLoading = ! blockAttributes.isPreview && ! STOCK_STATUS_OPTIONS.current; const isDisabled = ! blockAttributes.isPreview && filteredCountsLoading; diff --git a/plugins/woocommerce-blocks/assets/js/blocks/stock-filter/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/stock-filter/edit.tsx index e754763f39a..05bdf6dd6b1 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/stock-filter/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/stock-filter/edit.tsx @@ -25,13 +25,8 @@ const Edit = ( { attributes, setAttributes, }: BlockEditProps< Attributes > ) => { - const { - className, - heading, - headingLevel, - showCounts, - showFilterButton, - } = attributes; + const { className, heading, headingLevel, showCounts, showFilterButton } = + attributes; const blockProps = useBlockProps( { className: classnames( 'wc-block-stock-filter', className ), diff --git a/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts b/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts index 05ac2b2ee5c..2b5afb94816 100644 --- a/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts +++ b/plugins/woocommerce-blocks/assets/js/data/cart/actions.ts @@ -33,9 +33,9 @@ import { ReturnOrGeneratorYieldUnion } from '../mapped-types'; export const receiveCart = ( response: CartResponse ): { type: string; response: Cart } => { - const cart = ( mapKeys( response, ( _, key ) => + const cart = mapKeys( response, ( _, key ) => camelCase( key ) - ) as unknown ) as Cart; + ) as unknown as Cart; return { type: types.RECEIVE_CART, response: cart, @@ -55,9 +55,9 @@ export const receiveCart = ( export const receiveCartContents = ( response: CartResponse ): { type: string; response: Partial< Cart > } => { - const cart = ( mapKeys( response, ( _, key ) => + const cart = mapKeys( response, ( _, key ) => camelCase( key ) - ) as unknown ) as Cart; + ) as unknown as Cart; const { shippingAddress, billingAddress, ...cartWithoutAddress } = cart; return { type: types.RECEIVE_CART, diff --git a/plugins/woocommerce-blocks/assets/js/data/cart/index.ts b/plugins/woocommerce-blocks/assets/js/data/cart/index.ts index a4bc7a8b98b..a17a1d490c3 100644 --- a/plugins/woocommerce-blocks/assets/js/data/cart/index.ts +++ b/plugins/woocommerce-blocks/assets/js/data/cart/index.ts @@ -34,9 +34,9 @@ declare module '@wordpress/data' { function dispatch( key: typeof CART_STORE_KEY ): DispatchFromMap< typeof actions >; - function select( - key: typeof CART_STORE_KEY - ): SelectFromMap< typeof selectors > & { + function select( key: typeof CART_STORE_KEY ): SelectFromMap< + typeof selectors + > & { hasFinishedResolution: ( selector: string ) => boolean; }; } diff --git a/plugins/woocommerce-blocks/assets/js/data/cart/test/selectors.js b/plugins/woocommerce-blocks/assets/js/data/cart/test/selectors.js index 66d6bfa54fa..f38bcd567ef 100644 --- a/plugins/woocommerce-blocks/assets/js/data/cart/test/selectors.js +++ b/plugins/woocommerce-blocks/assets/js/data/cart/test/selectors.js @@ -45,12 +45,10 @@ const state = { images: [ { id: 48, - src: - 'http://local.wordpress.test/wp-content/uploads/2019/12/album-1.jpg', + src: 'http://local.wordpress.test/wp-content/uploads/2019/12/album-1.jpg', thumbnail: 'http://local.wordpress.test/wp-content/uploads/2019/12/album-1-324x324.jpg', - srcset: - 'http://local.wordpress.test/wp-content/uploads/2019/12/album-1.jpg 800w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-324x324.jpg 324w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-100x100.jpg 100w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-416x416.jpg 416w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-300x300.jpg 300w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-150x150.jpg 150w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-768x768.jpg 768w', + srcset: 'http://local.wordpress.test/wp-content/uploads/2019/12/album-1.jpg 800w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-324x324.jpg 324w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-100x100.jpg 100w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-416x416.jpg 416w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-300x300.jpg 300w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-150x150.jpg 150w, http://local.wordpress.test/wp-content/uploads/2019/12/album-1-768x768.jpg 768w', sizes: '(max-width: 800px) 100vw, 800px', name: 'album-1.jpg', alt: '', @@ -85,12 +83,10 @@ const state = { images: [ { id: 40, - src: - 'http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2.jpg', + src: 'http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2.jpg', thumbnail: 'http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-324x324.jpg', - srcset: - 'http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2.jpg 801w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-324x324.jpg 324w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-100x100.jpg 100w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-416x416.jpg 416w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-300x300.jpg 300w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-150x150.jpg 150w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-768x768.jpg 768w', + srcset: 'http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2.jpg 801w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-324x324.jpg 324w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-100x100.jpg 100w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-416x416.jpg 416w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-300x300.jpg 300w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-150x150.jpg 150w, http://local.wordpress.test/wp-content/uploads/2019/12/beanie-2-768x768.jpg 768w', sizes: '(max-width: 801px) 100vw, 801px', name: 'beanie-2.jpg', alt: '', diff --git a/plugins/woocommerce-blocks/assets/js/data/collections/resolvers.js b/plugins/woocommerce-blocks/assets/js/data/collections/resolvers.js index 86b6109bdc0..5a1a37f6689 100644 --- a/plugins/woocommerce-blocks/assets/js/data/collections/resolvers.js +++ b/plugins/woocommerce-blocks/assets/js/data/collections/resolvers.js @@ -54,10 +54,8 @@ export function* getCollection( namespace, resourceName, query, ids ) { } try { - const { - response = DEFAULT_EMPTY_ARRAY, - headers, - } = yield apiFetchWithHeaders( { path: route + queryString } ); + const { response = DEFAULT_EMPTY_ARRAY, headers } = + yield apiFetchWithHeaders( { path: route + queryString } ); if ( headers && headers.get && headers.has( 'last-modified' ) ) { // Do any invalidation before the collection is received to prevent diff --git a/plugins/woocommerce-blocks/assets/js/data/constants.ts b/plugins/woocommerce-blocks/assets/js/data/constants.ts index 339cf2557a7..996dbbd8105 100644 --- a/plugins/woocommerce-blocks/assets/js/data/constants.ts +++ b/plugins/woocommerce-blocks/assets/js/data/constants.ts @@ -5,12 +5,12 @@ */ export const API_BLOCK_NAMESPACE = 'wc/blocks'; -export const EMPTY_CART_COUPONS: [ ] = []; -export const EMPTY_CART_ITEMS: [ ] = []; -export const EMPTY_CART_FEES: [ ] = []; -export const EMPTY_CART_ITEM_ERRORS: [ ] = []; -export const EMPTY_CART_ERRORS: [ ] = []; -export const EMPTY_SHIPPING_RATES: [ ] = []; -export const EMPTY_PAYMENT_REQUIREMENTS: [ ] = []; +export const EMPTY_CART_COUPONS: [] = []; +export const EMPTY_CART_ITEMS: [] = []; +export const EMPTY_CART_FEES: [] = []; +export const EMPTY_CART_ITEM_ERRORS: [] = []; +export const EMPTY_CART_ERRORS: [] = []; +export const EMPTY_SHIPPING_RATES: [] = []; +export const EMPTY_PAYMENT_REQUIREMENTS: [] = []; export const EMPTY_EXTENSIONS: Record< string, unknown > = {}; -export const EMPTY_TAX_LINES: [ ] = []; +export const EMPTY_TAX_LINES: [] = []; diff --git a/plugins/woocommerce-blocks/assets/js/data/default-states.ts b/plugins/woocommerce-blocks/assets/js/data/default-states.ts index 29ff0e7fe79..8fe8ec2b698 100644 --- a/plugins/woocommerce-blocks/assets/js/data/default-states.ts +++ b/plugins/woocommerce-blocks/assets/js/data/default-states.ts @@ -27,8 +27,8 @@ export interface CartState { errors: Array< ResponseError >; } -export const EMPTY_PENDING_QUANTITY: [ ] = []; -export const EMPTY_PENDING_DELETE: [ ] = []; +export const EMPTY_PENDING_QUANTITY: [] = []; +export const EMPTY_PENDING_DELETE: [] = []; export const defaultCartState: CartState = { cartItemsPendingQuantity: EMPTY_PENDING_QUANTITY, diff --git a/plugins/woocommerce-blocks/assets/js/data/mapped-types.ts b/plugins/woocommerce-blocks/assets/js/data/mapped-types.ts index ec447656341..01c711c8653 100644 --- a/plugins/woocommerce-blocks/assets/js/data/mapped-types.ts +++ b/plugins/woocommerce-blocks/assets/js/data/mapped-types.ts @@ -62,19 +62,17 @@ export type TailParameters< F extends Function > = F extends ( /** * Obtain the type finally returned by the generator when it's done iterating. */ -export type GeneratorReturnType< - T extends ( ...args: any[] ) => Generator -> = T extends ( ...args: any ) => Generator< any, infer R, any > ? R : never; +export type GeneratorReturnType< T extends ( ...args: any[] ) => Generator > = + T extends ( ...args: any ) => Generator< any, infer R, any > ? R : never; /** * Usually we use ReturnType of all the action creators to deduce all the actions. * This works until one of the action creators is a generator and doesn't actually "Return" an action. * This type helper allows for actions to be both functions and generators */ -export type ReturnOrGeneratorYieldUnion< - T extends ( ...args: any ) => any -> = T extends ( ...args: any ) => infer Return - ? Return extends Generator< infer T, infer U, any > - ? T | U - : Return - : never; +export type ReturnOrGeneratorYieldUnion< T extends ( ...args: any ) => any > = + T extends ( ...args: any ) => infer Return + ? Return extends Generator< infer T, infer U, any > + ? T | U + : Return + : never; diff --git a/plugins/woocommerce-blocks/assets/js/data/schema/selectors.js b/plugins/woocommerce-blocks/assets/js/data/schema/selectors.js index 9d85b64b60b..92f45285582 100644 --- a/plugins/woocommerce-blocks/assets/js/data/schema/selectors.js +++ b/plugins/woocommerce-blocks/assets/js/data/schema/selectors.js @@ -32,47 +32,49 @@ import { STORE_KEY } from './constants'; * @return {string} The route if it is available. */ export const getRoute = createRegistrySelector( - ( select ) => ( state, namespace, resourceName, ids = [] ) => { - const hasResolved = select( - STORE_KEY - ).hasFinishedResolution( 'getRoutes', [ namespace ] ); - state = state.routes; - let error = ''; - if ( ! state[ namespace ] ) { - error = sprintf( - 'There is no route for the given namespace (%s) in the store', - namespace + ( select ) => + ( state, namespace, resourceName, ids = [] ) => { + const hasResolved = select( STORE_KEY ).hasFinishedResolution( + 'getRoutes', + [ namespace ] ); - } else if ( ! state[ namespace ][ resourceName ] ) { - error = sprintf( - 'There is no route for the given resource name (%s) in the store', - resourceName - ); - } - if ( error !== '' ) { - if ( hasResolved ) { - throw new Error( error ); - } - return ''; - } - const route = getRouteFromResourceEntries( - state[ namespace ][ resourceName ], - ids - ); - if ( route === '' ) { - if ( hasResolved ) { - throw new Error( - sprintf( - 'While there is a route for the given namespace (%1$s) and resource name (%2$s), there is no route utilizing the number of ids you included in the select arguments. The available routes are: (%3$s)', - namespace, - resourceName, - JSON.stringify( state[ namespace ][ resourceName ] ) - ) + state = state.routes; + let error = ''; + if ( ! state[ namespace ] ) { + error = sprintf( + 'There is no route for the given namespace (%s) in the store', + namespace + ); + } else if ( ! state[ namespace ][ resourceName ] ) { + error = sprintf( + 'There is no route for the given resource name (%s) in the store', + resourceName ); } + if ( error !== '' ) { + if ( hasResolved ) { + throw new Error( error ); + } + return ''; + } + const route = getRouteFromResourceEntries( + state[ namespace ][ resourceName ], + ids + ); + if ( route === '' ) { + if ( hasResolved ) { + throw new Error( + sprintf( + 'While there is a route for the given namespace (%1$s) and resource name (%2$s), there is no route utilizing the number of ids you included in the select arguments. The available routes are: (%3$s)', + namespace, + resourceName, + JSON.stringify( state[ namespace ][ resourceName ] ) + ) + ); + } + } + return route; } - return route; - } ); /** @@ -85,9 +87,10 @@ export const getRoute = createRegistrySelector( */ export const getRoutes = createRegistrySelector( ( select ) => ( state, namespace ) => { - const hasResolved = select( - STORE_KEY - ).hasFinishedResolution( 'getRoutes', [ namespace ] ); + const hasResolved = select( STORE_KEY ).hasFinishedResolution( + 'getRoutes', + [ namespace ] + ); const routes = state.routes[ namespace ]; if ( ! routes ) { if ( hasResolved ) { diff --git a/plugins/woocommerce-blocks/assets/js/data/schema/test/selectors.js b/plugins/woocommerce-blocks/assets/js/data/schema/test/selectors.js index ded81504bfe..0e7bc205cff 100644 --- a/plugins/woocommerce-blocks/assets/js/data/schema/test/selectors.js +++ b/plugins/woocommerce-blocks/assets/js/data/schema/test/selectors.js @@ -34,9 +34,11 @@ const testState = deepFreeze( { } ); describe( 'getRoute', () => { - const invokeTest = ( namespace, resourceName, ids = [] ) => () => { - return getRoute( testState, namespace, resourceName, ids ); - }; + const invokeTest = + ( namespace, resourceName, ids = [] ) => + () => { + return getRoute( testState, namespace, resourceName, ids ); + }; describe( 'with throwing errors', () => { beforeEach( () => mockHasFinishedResolution.mockReturnValue( true ) ); it( 'throws an error if there is no route for the given namespace', () => { @@ -78,10 +80,11 @@ describe( 'getRoute', () => { } ); test( 'when there is a route with placeholders', () => { expect( - invokeTest( 'wc/blocks', 'products/attributes/terms', [ - 10, - 20, - ] )() + invokeTest( + 'wc/blocks', + 'products/attributes/terms', + [ 10, 20 ] + )() ).toBe( 'wc/blocks/products/attributes/10/terms/20' ); } ); } ); diff --git a/plugins/woocommerce-blocks/assets/js/editor-components/external-link-card/stories/index.tsx b/plugins/woocommerce-blocks/assets/js/editor-components/external-link-card/stories/index.tsx index 276d916b267..6c1f23fbd71 100644 --- a/plugins/woocommerce-blocks/assets/js/editor-components/external-link-card/stories/index.tsx +++ b/plugins/woocommerce-blocks/assets/js/editor-components/external-link-card/stories/index.tsx @@ -21,7 +21,6 @@ export const Default = Template.bind( {} ); Default.args = { description: 'This is the description of the link, perhaps a bit of a longer paragraph or a summary of a blog post, or whatever could give more context', - href: - 'https://woocommerce.com/posts/seven-tips-to-extend-holiday-sales-momentum/', + href: 'https://woocommerce.com/posts/seven-tips-to-extend-holiday-sales-momentum/', title: 'Seven tips to extend holiday sales momentum', }; diff --git a/plugins/woocommerce-blocks/assets/js/editor-components/product-tag-control/index.js b/plugins/woocommerce-blocks/assets/js/editor-components/product-tag-control/index.js index a2386d6f7e3..0b6ed524227 100644 --- a/plugins/woocommerce-blocks/assets/js/editor-components/product-tag-control/index.js +++ b/plugins/woocommerce-blocks/assets/js/editor-components/product-tag-control/index.js @@ -93,13 +93,8 @@ class ProductTagControl extends Component { render() { const { list, loading } = this.state; - const { - isCompact, - onChange, - onOperatorChange, - operator, - selected, - } = this.props; + const { isCompact, onChange, onOperatorChange, operator, selected } = + this.props; const messages = { clear: __( diff --git a/plugins/woocommerce-blocks/assets/js/editor-components/search-list-control/types.ts b/plugins/woocommerce-blocks/assets/js/editor-components/search-list-control/types.ts index 6c01296eb49..c1737693c54 100644 --- a/plugins/woocommerce-blocks/assets/js/editor-components/search-list-control/types.ts +++ b/plugins/woocommerce-blocks/assets/js/editor-components/search-list-control/types.ts @@ -13,7 +13,7 @@ export type SearchListItemType = { breadcrumbs: string[]; }; -export type SearchListItemsType = SearchListItemType[] | [ ]; +export type SearchListItemsType = SearchListItemType[] | []; export interface SearchListMessages { // A more detailed label for the "Clear all" button, read to screen reader users. diff --git a/plugins/woocommerce-blocks/assets/js/editor-components/search-list-control/utils.tsx b/plugins/woocommerce-blocks/assets/js/editor-components/search-list-control/utils.tsx index 43c65adfbee..f98d8796f26 100644 --- a/plugins/woocommerce-blocks/assets/js/editor-components/search-list-control/utils.tsx +++ b/plugins/woocommerce-blocks/assets/js/editor-components/search-list-control/utils.tsx @@ -41,7 +41,7 @@ export const defaultMessages = { export const buildTermsTree = ( filteredList: SearchListItemsType, list = filteredList -): SearchListItemType[] | [ ] => { +): SearchListItemType[] | [] => { const termsByParent = groupBy( filteredList, 'parent' ); const listById = keyBy( list, 'id' ); const builtParents = [ '0' ]; @@ -90,7 +90,7 @@ export const getFilteredList = ( list: SearchListItemsType, search: string, isHierarchical: boolean -): SearchListItemType[] | [ ] => { +): SearchListItemType[] | [] => { if ( ! search ) { return isHierarchical ? buildTermsTree( list ) : list; } diff --git a/plugins/woocommerce-blocks/assets/js/extensions/google-analytics/utils.ts b/plugins/woocommerce-blocks/assets/js/extensions/google-analytics/utils.ts index f5e43762b60..e4b22a73c19 100644 --- a/plugins/woocommerce-blocks/assets/js/extensions/google-analytics/utils.ts +++ b/plugins/woocommerce-blocks/assets/js/extensions/google-analytics/utils.ts @@ -79,40 +79,40 @@ export const trackEvent = ( let currentStep = -1; -export const trackCheckoutStep = ( step: number ) => ( { - storeCart, -}: { - storeCart: StoreCart; -} ): void => { - if ( currentStep === step ) { - return; - } - trackEvent( step === 0 ? 'begin_checkout' : 'checkout_progress', { - items: storeCart.cartItems.map( getProductFieldObject ), - coupon: storeCart.cartCoupons[ 0 ]?.code || '', - currency: storeCart.cartTotals.currency_code, - value: ( - parseInt( storeCart.cartTotals.total_price, 10 ) / - 10 ** storeCart.cartTotals.currency_minor_unit - ).toString(), - checkout_step: step, - } ); - currentStep = step; -}; +export const trackCheckoutStep = + ( step: number ) => + ( { storeCart }: { storeCart: StoreCart } ): void => { + if ( currentStep === step ) { + return; + } + trackEvent( step === 0 ? 'begin_checkout' : 'checkout_progress', { + items: storeCart.cartItems.map( getProductFieldObject ), + coupon: storeCart.cartCoupons[ 0 ]?.code || '', + currency: storeCart.cartTotals.currency_code, + value: ( + parseInt( storeCart.cartTotals.total_price, 10 ) / + 10 ** storeCart.cartTotals.currency_minor_unit + ).toString(), + checkout_step: step, + } ); + currentStep = step; + }; -export const trackCheckoutOption = ( { - step, - option, - value, -}: { - step: number; - option: string; - value: string; -} ) => (): void => { - trackEvent( 'set_checkout_option', { - checkout_step: step, - checkout_option: option, +export const trackCheckoutOption = + ( { + step, + option, value, - } ); - currentStep = step; -}; + }: { + step: number; + option: string; + value: string; + } ) => + (): void => { + trackEvent( 'set_checkout_option', { + checkout_step: step, + checkout_option: option, + value, + } ); + currentStep = step; + }; diff --git a/plugins/woocommerce-blocks/assets/js/filters/exclude-draft-status-from-analytics.js b/plugins/woocommerce-blocks/assets/js/filters/exclude-draft-status-from-analytics.js index f935bf8eedb..b97d3e484c9 100644 --- a/plugins/woocommerce-blocks/assets/js/filters/exclude-draft-status-from-analytics.js +++ b/plugins/woocommerce-blocks/assets/js/filters/exclude-draft-status-from-analytics.js @@ -19,12 +19,14 @@ addFilter( return optionsGroup; }; - const actionableStatusesOptions = settings.woocommerce_actionable_order_statuses.options.map( - removeCheckoutDraft - ); - const excludedStatusesOptions = settings.woocommerce_excluded_report_order_statuses.options.map( - removeCheckoutDraft - ); + const actionableStatusesOptions = + settings.woocommerce_actionable_order_statuses.options.map( + removeCheckoutDraft + ); + const excludedStatusesOptions = + settings.woocommerce_excluded_report_order_statuses.options.map( + removeCheckoutDraft + ); return { ...settings, diff --git a/plugins/woocommerce-blocks/assets/js/middleware/store-api-nonce.js b/plugins/woocommerce-blocks/assets/js/middleware/store-api-nonce.js index 2da91f2a8e3..d533d5a3c0a 100644 --- a/plugins/woocommerce-blocks/assets/js/middleware/store-api-nonce.js +++ b/plugins/woocommerce-blocks/assets/js/middleware/store-api-nonce.js @@ -103,9 +103,8 @@ const storeNonceMiddleware = ( options, next ) => { // Add nonce to sub-requests if ( Array.isArray( options?.data?.requests ) ) { - options.data.requests = options.data.requests.map( - appendNonceHeader - ); + options.data.requests = + options.data.requests.map( appendNonceHeader ); } } return next( options, next ); diff --git a/plugins/woocommerce-blocks/assets/js/previews/reviews.js b/plugins/woocommerce-blocks/assets/js/previews/reviews.js index b2ee378a443..f41c2d4607e 100644 --- a/plugins/woocommerce-blocks/assets/js/previews/reviews.js +++ b/plugins/woocommerce-blocks/assets/js/previews/reviews.js @@ -23,8 +23,8 @@ export const previewReviews = [ 'woo-gutenberg-products-block' ) }

\n`, reviewer_avatar_urls: { - '48': blocksConfig.defaultAvatar, - '96': blocksConfig.defaultAvatar, + 48: blocksConfig.defaultAvatar, + 96: blocksConfig.defaultAvatar, }, rating: 5, verified: true, @@ -47,8 +47,8 @@ export const previewReviews = [ 'woo-gutenberg-products-block' ) }

\n`, reviewer_avatar_urls: { - '48': blocksConfig.defaultAvatar, - '96': blocksConfig.defaultAvatar, + 48: blocksConfig.defaultAvatar, + 96: blocksConfig.defaultAvatar, }, rating: null, verified: false, diff --git a/plugins/woocommerce-blocks/assets/js/shared/hocs/with-filtered-attributes.js b/plugins/woocommerce-blocks/assets/js/shared/hocs/with-filtered-attributes.js index e3e95488f2e..1a482be565a 100644 --- a/plugins/woocommerce-blocks/assets/js/shared/hocs/with-filtered-attributes.js +++ b/plugins/woocommerce-blocks/assets/js/shared/hocs/with-filtered-attributes.js @@ -8,17 +8,19 @@ import { getValidBlockAttributes } from '@woocommerce/base-utils'; * * @param {Object} blockAttributes Component being wrapped. */ -export const withFilteredAttributes = ( blockAttributes ) => ( - OriginalComponent -) => { - return ( ownProps ) => { - const validBlockAttributes = getValidBlockAttributes( - blockAttributes, - ownProps - ); +export const withFilteredAttributes = + ( blockAttributes ) => ( OriginalComponent ) => { + return ( ownProps ) => { + const validBlockAttributes = getValidBlockAttributes( + blockAttributes, + ownProps + ); - return ( - - ); + return ( + + ); + }; }; -}; diff --git a/plugins/woocommerce-blocks/bin/hook-docs/actions/index.js b/plugins/woocommerce-blocks/bin/hook-docs/actions/index.js index 9e3c1ec3d8a..821a168b6d6 100644 --- a/plugins/woocommerce-blocks/bin/hook-docs/actions/index.js +++ b/plugins/woocommerce-blocks/bin/hook-docs/actions/index.js @@ -32,8 +32,7 @@ const generate = ( hooks ) => { const jsonDocs = [ { html: '' }, { - html: - '', + html: '', }, { h1: 'Actions' }, { h2: 'Table of Contents' }, diff --git a/plugins/woocommerce-blocks/bin/hook-docs/data/actions.json b/plugins/woocommerce-blocks/bin/hook-docs/data/actions.json index 3d8481c2f82..8dd7578c4a6 100644 --- a/plugins/woocommerce-blocks/bin/hook-docs/data/actions.json +++ b/plugins/woocommerce-blocks/bin/hook-docs/data/actions.json @@ -1,776 +1,718 @@ { - "$schema": "https://raw.githubusercontent.com/johnbillion/wp-hooks-generator/0.7.3/schema.json", - "hooks": [ - { - "name": "woocommerce_add_to_cart", - "file": "StoreApi/Utilities/CartController.php", - "type": "action", - "doc": { - "description": "Fires when an item is added to the cart.", - "long_description": "This hook fires when an item is added to the cart. This is triggered from the Store API in this context, but WooCommerce core add to cart events trigger the same hook.", - "tags": [ - { - "name": "internal", - "content": "Matches action name in WooCommerce core." - }, - { - "name": "param", - "content": "ID of the item in the cart.", - "types": [ - "string" - ], - "variable": "$cart_id" - }, - { - "name": "param", - "content": "ID of the product added to the cart.", - "types": [ - "integer" - ], - "variable": "$product_id" - }, - { - "name": "param", - "content": "Quantity of the item added to the cart.", - "types": [ - "integer" - ], - "variable": "$request_quantity" - }, - { - "name": "param", - "content": "Variation ID of the product added to the cart.", - "types": [ - "integer" - ], - "variable": "$variation_id" - }, - { - "name": "param", - "content": "Array of variation data.", - "types": [ - "array" - ], - "variable": "$variation" - }, - { - "name": "param", - "content": "Array of other cart item data.", - "types": [ - "array" - ], - "variable": "$cart_item_data" - } - ], - "long_description_html": "

This hook fires when an item is added to the cart. This is triggered from the Store API in this context, but WooCommerce core add to cart events trigger the same hook.

" - }, - "args": 6 - }, - { - "name": "woocommerce_after_main_content", - "file": "BlockTypes/ClassicTemplate.php", - "type": "action", - "doc": { - "description": "Hook: woocommerce_after_main_content", - "long_description": "Called after rendering the main content for a product.", - "tags": [ - { - "name": "see", - "content": "Outputs closing DIV for the content (priority 10)", - "refers": "woocommerce_output_content_wrapper_end()" - } - ], - "long_description_html": "

Called after rendering the main content for a product.

" - }, - "args": 0 - }, - { - "name": "woocommerce_after_main_content", - "file": "BlockTypes/ClassicTemplate.php", - "type": "action", - "doc": { - "description": "Hook: woocommerce_after_main_content", - "long_description": "Called after rendering the main content for a product.", - "tags": [ - { - "name": "see", - "content": "Outputs closing DIV for the content (priority 10)", - "refers": "woocommerce_output_content_wrapper_end()" - } - ], - "long_description_html": "

Called after rendering the main content for a product.

" - }, - "args": 0 - }, - { - "name": "woocommerce_after_shop_loop", - "file": "BlockTypes/ClassicTemplate.php", - "type": "action", - "doc": { - "description": "Hook: woocommerce_after_shop_loop.", - "long_description": "", - "tags": [ - { - "name": "see", - "content": "Renders pagination (priority 10)", - "refers": "woocommerce_pagination()" - } - ], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_applied_coupon", - "file": "StoreApi/Utilities/CartController.php", - "type": "action", - "doc": { - "description": "Fires after a coupon has been applied to the cart.", - "long_description": "", - "tags": [ - { - "name": "internal", - "content": "Matches action name in WooCommerce core." - }, - { - "name": "param", - "content": "The coupon code that was applied.", - "types": [ - "string" - ], - "variable": "$coupon_code" - } - ], - "long_description_html": "" - }, - "args": 1 - }, - { - "name": "woocommerce_archive_description", - "file": "BlockTypes/ClassicTemplate.php", - "type": "action", - "doc": { - "description": "Hook: woocommerce_archive_description.", - "long_description": "", - "tags": [ - { - "name": "see", - "content": "Renders the taxonomy archive description (priority 10)", - "refers": "woocommerce_taxonomy_archive_description()" - }, - { - "name": "see", - "content": "Renders the product archive description (priority 10)", - "refers": "woocommerce_product_archive_description()" - } - ], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_before_main_content", - "file": "BlockTypes/ClassicTemplate.php", - "type": "action", - "doc": { - "description": "Hook: woocommerce_before_main_content", - "long_description": "Called before rendering the main content for a product.", - "tags": [ - { - "name": "see", - "content": "Outputs opening DIV for the content (priority 10)", - "refers": "woocommerce_output_content_wrapper()" - }, - { - "name": "see", - "content": "Outputs breadcrumb trail to the current product (priority 20)", - "refers": "woocommerce_breadcrumb()" - }, - { - "name": "see", - "content": "Outputs schema markup (priority 30)", - "refers": "WC_Structured_Data::generate_website_data()" - } - ], - "long_description_html": "

Called before rendering the main content for a product.

" - }, - "args": 0 - }, - { - "name": "woocommerce_before_main_content", - "file": "BlockTypes/ClassicTemplate.php", - "type": "action", - "doc": { - "description": "Hook: woocommerce_before_main_content", - "long_description": "Called before rendering the main content for a product.", - "tags": [ - { - "name": "see", - "content": "Outputs opening DIV for the content (priority 10)", - "refers": "woocommerce_output_content_wrapper()" - }, - { - "name": "see", - "content": "Outputs breadcrumb trail to the current product (priority 20)", - "refers": "woocommerce_breadcrumb()" - }, - { - "name": "see", - "content": "Outputs schema markup (priority 30)", - "refers": "WC_Structured_Data::generate_website_data()" - } - ], - "long_description_html": "

Called before rendering the main content for a product.

" - }, - "args": 0 - }, - { - "name": "woocommerce_before_shop_loop", - "file": "BlockTypes/ClassicTemplate.php", - "type": "action", - "doc": { - "description": "Hook: woocommerce_before_shop_loop.", - "long_description": "", - "tags": [ - { - "name": "see", - "content": "Render error notices (priority 10)", - "refers": "woocommerce_output_all_notices()" - }, - { - "name": "see", - "content": "Show number of results found (priority 20)", - "refers": "woocommerce_result_count()" - }, - { - "name": "see", - "content": "Show form to control sort order (priority 30)", - "refers": "woocommerce_catalog_ordering()" - } - ], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_blocks_cart_enqueue_data", - "file": "BlockTypes/MiniCart.php", - "type": "action", - "doc": { - "description": "Fires after cart block data is registered.", - "long_description": "", - "tags": [], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_blocks_cart_enqueue_data", - "file": "BlockTypes/Cart.php", - "type": "action", - "doc": { - "description": "Fires after cart block data is registered.", - "long_description": "", - "tags": [], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_blocks_checkout_enqueue_data", - "file": "BlockTypes/Checkout.php", - "type": "action", - "doc": { - "description": "Fires after checkout block data is registered.", - "long_description": "", - "tags": [], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_blocks_enqueue_cart_block_scripts_after", - "file": "BlockTypes/Cart.php", - "type": "action", - "doc": { - "description": "Fires after cart block scripts are enqueued.", - "long_description": "", - "tags": [], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_blocks_enqueue_cart_block_scripts_before", - "file": "BlockTypes/Cart.php", - "type": "action", - "doc": { - "description": "Fires before cart block scripts are enqueued.", - "long_description": "", - "tags": [], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_blocks_enqueue_checkout_block_scripts_after", - "file": "BlockTypes/Checkout.php", - "type": "action", - "doc": { - "description": "Fires after checkout block scripts are enqueued.", - "long_description": "", - "tags": [], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_blocks_enqueue_checkout_block_scripts_before", - "file": "BlockTypes/Checkout.php", - "type": "action", - "doc": { - "description": "Fires before checkout block scripts are enqueued.", - "long_description": "", - "tags": [], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_blocks_{$this->registry_identifier}_registration", - "file": "Integrations/IntegrationRegistry.php", - "type": "action", - "doc": { - "description": "Fires when the IntegrationRegistry is initialized.", - "long_description": "Runs before integrations are initialized allowing new integration to be registered for use. This should be used as the primary hook for integrations to include their scripts, styles, and other code extending the blocks.", - "tags": [ - { - "name": "param", - "content": "Instance of the IntegrationRegistry class which exposes the IntegrationRegistry::register() method.", - "types": [ - "\\Automattic\\WooCommerce\\Blocks\\Integrations\\IntegrationRegistry" - ], - "variable": "$this" - } - ], - "long_description_html": "

Runs before integrations are initialized allowing new integration to be registered for use. This should be used as the primary hook for integrations to include their scripts, styles, and other code extending the blocks.

" - }, - "args": 1 - }, - { - "name": "woocommerce_check_cart_items", - "file": "StoreApi/Utilities/CartController.php", - "type": "action", - "doc": { - "description": "Fires when cart items are being validated.", - "long_description": "Allow 3rd parties to validate cart items. This is a legacy hook from Woo core. This filter will be deprecated because it encourages usage of wc_add_notice. For the API we need to capture notices and convert to wp errors instead.", - "tags": [ - { - "name": "deprecated", - "content": "" - }, - { - "name": "internal", - "content": "Matches action name in WooCommerce core." - } - ], - "long_description_html": "

Allow 3rd parties to validate cart items. This is a legacy hook from Woo core. This filter will be deprecated because it encourages usage of wc_add_notice. For the API we need to capture notices and convert to wp errors instead.

" - }, - "args": 0 - }, - { - "name": "woocommerce_created_customer", - "file": "StoreApi/Routes/V1/Checkout.php", - "type": "action", - "doc": { - "description": "Fires after a customer account has been registered.", - "long_description": "This hook fires after customer accounts are created and passes the customer data.", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "New customer (user) ID.", - "types": [ - "integer" - ], - "variable": "$customer_id" - }, - { - "name": "param", - "content": "Array of customer (user) data.", - "types": [ - "array" - ], - "variable": "$new_customer_data" - }, - { - "name": "param", - "content": "The generated password for the account.", - "types": [ - "string" - ], - "variable": "$password_generated" - } - ], - "long_description_html": "

This hook fires after customer accounts are created and passes the customer data.

" - }, - "args": 3 - }, - { - "name": "woocommerce_no_products_found", - "file": "BlockTypes/ClassicTemplate.php", - "type": "action", - "doc": { - "description": "Hook: woocommerce_no_products_found.", - "long_description": "", - "tags": [ - { - "name": "see", - "content": "Default no products found content (priority 10)", - "refers": "wc_no_products_found()" - } - ], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_register_post", - "file": "StoreApi/Routes/V1/Checkout.php", - "type": "action", - "doc": { - "description": "Fires before a customer account is registered.", - "long_description": "This hook fires before customer accounts are created and passes the form data (username, email) and an array of errors.\n This could be used to add extra validation logic and append errors to the array.", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "Customer username.", - "types": [ - "string" - ], - "variable": "$username" - }, - { - "name": "param", - "content": "Customer email address.", - "types": [ - "string" - ], - "variable": "$user_email" - }, - { - "name": "param", - "content": "Error object.", - "types": [ - "\\WP_Error" - ], - "variable": "$errors" - } - ], - "long_description_html": "

This hook fires before customer accounts are created and passes the form data (username, email) and an array of errors.

This could be used to add extra validation logic and append errors to the array.

" - }, - "args": 3 - }, - { - "name": "woocommerce_rest_checkout_process_payment_with_context", - "file": "StoreApi/Routes/V1/Checkout.php", - "type": "action_reference", - "doc": { - "description": "Process payment with context.", - "long_description": "", - "tags": [ - { - "name": "hook", - "content": "woocommerce_rest_checkout_process_payment_with_context" - }, - { - "name": "throws", - "content": "If there is an error taking payment, an \\Exception object can be thrown with an error message.", - "types": [ - "\\Exception" - ] - }, - { - "name": "param", - "content": "Holds context for the payment, including order ID and payment method.", - "types": [ - "\\Automattic\\WooCommerce\\StoreApi\\Payments\\PaymentContext" - ], - "variable": "$context" - }, - { - "name": "param", - "content": "Result object for the transaction.", - "types": [ - "\\Automattic\\WooCommerce\\StoreApi\\Payments\\PaymentResult" - ], - "variable": "$payment_result" - } - ], - "long_description_html": "" - }, - "args": 1 - }, - { - "name": "woocommerce_shop_loop", - "file": "BlockTypes/ClassicTemplate.php", - "type": "action", - "doc": { - "description": "Hook: woocommerce_shop_loop.", - "long_description": "", - "tags": [], - "long_description_html": "" - }, - "args": 0 - }, - { - "name": "woocommerce_store_api_cart_errors", - "file": "StoreApi/Utilities/CartController.php", - "type": "action", - "doc": { - "description": "Fires an action to validate the cart.", - "long_description": "Functions hooking into this should add custom errors using the provided WP_Error instance.", - "tags": [ - { - "name": "example", - "content": "docs/examples/validate-cart.md" - }, - { - "name": "param", - "content": "WP_Error object.", - "types": [ - "\\WP_Error" - ], - "variable": "$errors" - }, - { - "name": "param", - "content": "Cart object.", - "types": [ - "\\WC_Cart" - ], - "variable": "$cart" - } - ], - "long_description_html": "

Functions hooking into this should add custom errors using the provided WP_Error instance.

" - }, - "args": 2 - }, - { - "name": "woocommerce_store_api_cart_update_customer_from_request", - "file": "StoreApi/Routes/V1/CartUpdateCustomer.php", - "type": "action", - "doc": { - "description": "Fires when the Checkout Block/Store API updates a customer from the API request data.", - "long_description": "", - "tags": [ - { - "name": "param", - "content": "Customer object.", - "types": [ - "\\WC_Customer" - ], - "variable": "$customer" - }, - { - "name": "param", - "content": "Full details about the request.", - "types": [ - "\\WP_REST_Request" - ], - "variable": "$request" - } - ], - "long_description_html": "" - }, - "args": 2 - }, - { - "name": "woocommerce_store_api_cart_update_order_from_request", - "file": "StoreApi/Routes/V1/AbstractCartRoute.php", - "type": "action", - "doc": { - "description": "Fires when the order is synced with cart data from a cart route.", - "long_description": "", - "tags": [ - { - "name": "param", - "content": "Order object.", - "types": [ - "\\WC_Order" - ], - "variable": "$draft_order" - }, - { - "name": "param", - "content": "Customer object.", - "types": [ - "\\WC_Customer" - ], - "variable": "$customer" - }, - { - "name": "param", - "content": "Full details about the request.", - "types": [ - "\\WP_REST_Request" - ], - "variable": "$request" - } - ], - "long_description_html": "" - }, - "args": 2 - }, - { - "name": "woocommerce_store_api_checkout_order_processed", - "file": "StoreApi/Routes/V1/Checkout.php", - "type": "action", - "doc": { - "description": "Fires before an order is processed by the Checkout Block/Store API.", - "long_description": "This hook informs extensions that $order has completed processing and is ready for payment.\n This is similar to existing core hook woocommerce_checkout_order_processed. We're using a new action: - To keep the interface focused (only pass $order, not passing request data). - This also explicitly indicates these orders are from checkout block/StoreAPI.", - "tags": [ - { - "name": "see", - "content": "", - "refers": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3238" - }, - { - "name": "example", - "content": "docs/examples/checkout-order-processed.md" - }, - { - "name": "param", - "content": "Order object.", - "types": [ - "\\WC_Order" - ], - "variable": "$order" - } - ], - "long_description_html": "

This hook informs extensions that $order has completed processing and is ready for payment.

This is similar to existing core hook woocommerce_checkout_order_processed. We're using a new action:

  • To keep the interface focused (only pass $order, not passing request data).
  • This also explicitly indicates these orders are from checkout block/StoreAPI.
" - }, - "args": 1 - }, - { - "name": "woocommerce_store_api_checkout_update_order_from_request", - "file": "StoreApi/Routes/V1/Checkout.php", - "type": "action", - "doc": { - "description": "Fires when the Checkout Block/Store API updates an order's from the API request data.", - "long_description": "This hook gives extensions the chance to update orders based on the data in the request. This can be used in conjunction with the ExtendSchema class to post custom data and then process it.", - "tags": [ - { - "name": "param", - "content": "Order object.", - "types": [ - "\\WC_Order" - ], - "variable": "$order" - }, - { - "name": "param", - "content": "Full details about the request.", - "types": [ - "\\WP_REST_Request" - ], - "variable": "$request" - } - ], - "long_description_html": "

This hook gives extensions the chance to update orders based on the data in the request. This can be used in conjunction with the ExtendSchema class to post custom data and then process it.

" - }, - "args": 2 - }, - { - "name": "woocommerce_store_api_checkout_update_order_meta", - "file": "StoreApi/Routes/V1/Checkout.php", - "type": "action", - "doc": { - "description": "Fires when the Checkout Block/Store API updates an order's meta data.", - "long_description": "This hook gives extensions the chance to add or update meta data on the $order. Throwing an exception from a callback attached to this action will make the Checkout Block render in a warning state, effectively preventing checkout.\n This is similar to existing core hook woocommerce_checkout_update_order_meta. We're using a new action: - To keep the interface focused (only pass $order, not passing request data). - This also explicitly indicates these orders are from checkout block/StoreAPI.", - "tags": [ - { - "name": "see", - "content": "", - "refers": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3686" - }, - { - "name": "param", - "content": "Order object.", - "types": [ - "\\WC_Order" - ], - "variable": "$order" - } - ], - "long_description_html": "

This hook gives extensions the chance to add or update meta data on the $order. Throwing an exception from a callback attached to this action will make the Checkout Block render in a warning state, effectively preventing checkout.

This is similar to existing core hook woocommerce_checkout_update_order_meta. We're using a new action:

  • To keep the interface focused (only pass $order, not passing request data).
  • This also explicitly indicates these orders are from checkout block/StoreAPI.
" - }, - "args": 1 - }, - { - "name": "woocommerce_store_api_validate_add_to_cart", - "file": "StoreApi/Utilities/CartController.php", - "type": "action", - "doc": { - "description": "Fires during validation when adding an item to the cart via the Store API.", - "long_description": "Fire action to validate add to cart. Functions hooking into this should throw an \\Exception to prevent add to cart from happening.", - "tags": [ - { - "name": "param", - "content": "Product object being added to the cart.", - "types": [ - "\\WC_Product" - ], - "variable": "$product" - }, - { - "name": "param", - "content": "Add to cart request params including id, quantity, and variation attributes.", - "types": [ - "array" - ], - "variable": "$request" - } - ], - "long_description_html": "

Fire action to validate add to cart. Functions hooking into this should throw an \\Exception to prevent add to cart from happening.

" - }, - "args": 2 - }, - { - "name": "woocommerce_store_api_validate_cart_item", - "file": "StoreApi/Utilities/CartController.php", - "type": "action", - "doc": { - "description": "Fire action to validate add to cart. Functions hooking into this should throw an \\Exception to prevent add to cart from occurring.", - "long_description": "", - "tags": [ - { - "name": "param", - "content": "Product object being added to the cart.", - "types": [ - "\\WC_Product" - ], - "variable": "$product" - }, - { - "name": "param", - "content": "Cart item array.", - "types": [ - "array" - ], - "variable": "$cart_item" - } - ], - "long_description_html": "" - }, - "args": 2 - } - ] -} \ No newline at end of file + "$schema": "https://raw.githubusercontent.com/johnbillion/wp-hooks-generator/0.7.3/schema.json", + "hooks": [ + { + "name": "woocommerce_add_to_cart", + "file": "StoreApi/Utilities/CartController.php", + "type": "action", + "doc": { + "description": "Fires when an item is added to the cart.", + "long_description": "This hook fires when an item is added to the cart. This is triggered from the Store API in this context, but WooCommerce core add to cart events trigger the same hook.", + "tags": [ + { + "name": "internal", + "content": "Matches action name in WooCommerce core." + }, + { + "name": "param", + "content": "ID of the item in the cart.", + "types": [ "string" ], + "variable": "$cart_id" + }, + { + "name": "param", + "content": "ID of the product added to the cart.", + "types": [ "integer" ], + "variable": "$product_id" + }, + { + "name": "param", + "content": "Quantity of the item added to the cart.", + "types": [ "integer" ], + "variable": "$request_quantity" + }, + { + "name": "param", + "content": "Variation ID of the product added to the cart.", + "types": [ "integer" ], + "variable": "$variation_id" + }, + { + "name": "param", + "content": "Array of variation data.", + "types": [ "array" ], + "variable": "$variation" + }, + { + "name": "param", + "content": "Array of other cart item data.", + "types": [ "array" ], + "variable": "$cart_item_data" + } + ], + "long_description_html": "

This hook fires when an item is added to the cart. This is triggered from the Store API in this context, but WooCommerce core add to cart events trigger the same hook.

" + }, + "args": 6 + }, + { + "name": "woocommerce_after_main_content", + "file": "BlockTypes/ClassicTemplate.php", + "type": "action", + "doc": { + "description": "Hook: woocommerce_after_main_content", + "long_description": "Called after rendering the main content for a product.", + "tags": [ + { + "name": "see", + "content": "Outputs closing DIV for the content (priority 10)", + "refers": "woocommerce_output_content_wrapper_end()" + } + ], + "long_description_html": "

Called after rendering the main content for a product.

" + }, + "args": 0 + }, + { + "name": "woocommerce_after_main_content", + "file": "BlockTypes/ClassicTemplate.php", + "type": "action", + "doc": { + "description": "Hook: woocommerce_after_main_content", + "long_description": "Called after rendering the main content for a product.", + "tags": [ + { + "name": "see", + "content": "Outputs closing DIV for the content (priority 10)", + "refers": "woocommerce_output_content_wrapper_end()" + } + ], + "long_description_html": "

Called after rendering the main content for a product.

" + }, + "args": 0 + }, + { + "name": "woocommerce_after_shop_loop", + "file": "BlockTypes/ClassicTemplate.php", + "type": "action", + "doc": { + "description": "Hook: woocommerce_after_shop_loop.", + "long_description": "", + "tags": [ + { + "name": "see", + "content": "Renders pagination (priority 10)", + "refers": "woocommerce_pagination()" + } + ], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_applied_coupon", + "file": "StoreApi/Utilities/CartController.php", + "type": "action", + "doc": { + "description": "Fires after a coupon has been applied to the cart.", + "long_description": "", + "tags": [ + { + "name": "internal", + "content": "Matches action name in WooCommerce core." + }, + { + "name": "param", + "content": "The coupon code that was applied.", + "types": [ "string" ], + "variable": "$coupon_code" + } + ], + "long_description_html": "" + }, + "args": 1 + }, + { + "name": "woocommerce_archive_description", + "file": "BlockTypes/ClassicTemplate.php", + "type": "action", + "doc": { + "description": "Hook: woocommerce_archive_description.", + "long_description": "", + "tags": [ + { + "name": "see", + "content": "Renders the taxonomy archive description (priority 10)", + "refers": "woocommerce_taxonomy_archive_description()" + }, + { + "name": "see", + "content": "Renders the product archive description (priority 10)", + "refers": "woocommerce_product_archive_description()" + } + ], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_before_main_content", + "file": "BlockTypes/ClassicTemplate.php", + "type": "action", + "doc": { + "description": "Hook: woocommerce_before_main_content", + "long_description": "Called before rendering the main content for a product.", + "tags": [ + { + "name": "see", + "content": "Outputs opening DIV for the content (priority 10)", + "refers": "woocommerce_output_content_wrapper()" + }, + { + "name": "see", + "content": "Outputs breadcrumb trail to the current product (priority 20)", + "refers": "woocommerce_breadcrumb()" + }, + { + "name": "see", + "content": "Outputs schema markup (priority 30)", + "refers": "WC_Structured_Data::generate_website_data()" + } + ], + "long_description_html": "

Called before rendering the main content for a product.

" + }, + "args": 0 + }, + { + "name": "woocommerce_before_main_content", + "file": "BlockTypes/ClassicTemplate.php", + "type": "action", + "doc": { + "description": "Hook: woocommerce_before_main_content", + "long_description": "Called before rendering the main content for a product.", + "tags": [ + { + "name": "see", + "content": "Outputs opening DIV for the content (priority 10)", + "refers": "woocommerce_output_content_wrapper()" + }, + { + "name": "see", + "content": "Outputs breadcrumb trail to the current product (priority 20)", + "refers": "woocommerce_breadcrumb()" + }, + { + "name": "see", + "content": "Outputs schema markup (priority 30)", + "refers": "WC_Structured_Data::generate_website_data()" + } + ], + "long_description_html": "

Called before rendering the main content for a product.

" + }, + "args": 0 + }, + { + "name": "woocommerce_before_shop_loop", + "file": "BlockTypes/ClassicTemplate.php", + "type": "action", + "doc": { + "description": "Hook: woocommerce_before_shop_loop.", + "long_description": "", + "tags": [ + { + "name": "see", + "content": "Render error notices (priority 10)", + "refers": "woocommerce_output_all_notices()" + }, + { + "name": "see", + "content": "Show number of results found (priority 20)", + "refers": "woocommerce_result_count()" + }, + { + "name": "see", + "content": "Show form to control sort order (priority 30)", + "refers": "woocommerce_catalog_ordering()" + } + ], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_blocks_cart_enqueue_data", + "file": "BlockTypes/MiniCart.php", + "type": "action", + "doc": { + "description": "Fires after cart block data is registered.", + "long_description": "", + "tags": [], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_blocks_cart_enqueue_data", + "file": "BlockTypes/Cart.php", + "type": "action", + "doc": { + "description": "Fires after cart block data is registered.", + "long_description": "", + "tags": [], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_blocks_checkout_enqueue_data", + "file": "BlockTypes/Checkout.php", + "type": "action", + "doc": { + "description": "Fires after checkout block data is registered.", + "long_description": "", + "tags": [], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_blocks_enqueue_cart_block_scripts_after", + "file": "BlockTypes/Cart.php", + "type": "action", + "doc": { + "description": "Fires after cart block scripts are enqueued.", + "long_description": "", + "tags": [], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_blocks_enqueue_cart_block_scripts_before", + "file": "BlockTypes/Cart.php", + "type": "action", + "doc": { + "description": "Fires before cart block scripts are enqueued.", + "long_description": "", + "tags": [], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_blocks_enqueue_checkout_block_scripts_after", + "file": "BlockTypes/Checkout.php", + "type": "action", + "doc": { + "description": "Fires after checkout block scripts are enqueued.", + "long_description": "", + "tags": [], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_blocks_enqueue_checkout_block_scripts_before", + "file": "BlockTypes/Checkout.php", + "type": "action", + "doc": { + "description": "Fires before checkout block scripts are enqueued.", + "long_description": "", + "tags": [], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_blocks_{$this->registry_identifier}_registration", + "file": "Integrations/IntegrationRegistry.php", + "type": "action", + "doc": { + "description": "Fires when the IntegrationRegistry is initialized.", + "long_description": "Runs before integrations are initialized allowing new integration to be registered for use. This should be used as the primary hook for integrations to include their scripts, styles, and other code extending the blocks.", + "tags": [ + { + "name": "param", + "content": "Instance of the IntegrationRegistry class which exposes the IntegrationRegistry::register() method.", + "types": [ + "\\Automattic\\WooCommerce\\Blocks\\Integrations\\IntegrationRegistry" + ], + "variable": "$this" + } + ], + "long_description_html": "

Runs before integrations are initialized allowing new integration to be registered for use. This should be used as the primary hook for integrations to include their scripts, styles, and other code extending the blocks.

" + }, + "args": 1 + }, + { + "name": "woocommerce_check_cart_items", + "file": "StoreApi/Utilities/CartController.php", + "type": "action", + "doc": { + "description": "Fires when cart items are being validated.", + "long_description": "Allow 3rd parties to validate cart items. This is a legacy hook from Woo core. This filter will be deprecated because it encourages usage of wc_add_notice. For the API we need to capture notices and convert to wp errors instead.", + "tags": [ + { + "name": "deprecated", + "content": "" + }, + { + "name": "internal", + "content": "Matches action name in WooCommerce core." + } + ], + "long_description_html": "

Allow 3rd parties to validate cart items. This is a legacy hook from Woo core. This filter will be deprecated because it encourages usage of wc_add_notice. For the API we need to capture notices and convert to wp errors instead.

" + }, + "args": 0 + }, + { + "name": "woocommerce_created_customer", + "file": "StoreApi/Routes/V1/Checkout.php", + "type": "action", + "doc": { + "description": "Fires after a customer account has been registered.", + "long_description": "This hook fires after customer accounts are created and passes the customer data.", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "New customer (user) ID.", + "types": [ "integer" ], + "variable": "$customer_id" + }, + { + "name": "param", + "content": "Array of customer (user) data.", + "types": [ "array" ], + "variable": "$new_customer_data" + }, + { + "name": "param", + "content": "The generated password for the account.", + "types": [ "string" ], + "variable": "$password_generated" + } + ], + "long_description_html": "

This hook fires after customer accounts are created and passes the customer data.

" + }, + "args": 3 + }, + { + "name": "woocommerce_no_products_found", + "file": "BlockTypes/ClassicTemplate.php", + "type": "action", + "doc": { + "description": "Hook: woocommerce_no_products_found.", + "long_description": "", + "tags": [ + { + "name": "see", + "content": "Default no products found content (priority 10)", + "refers": "wc_no_products_found()" + } + ], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_register_post", + "file": "StoreApi/Routes/V1/Checkout.php", + "type": "action", + "doc": { + "description": "Fires before a customer account is registered.", + "long_description": "This hook fires before customer accounts are created and passes the form data (username, email) and an array of errors.\n This could be used to add extra validation logic and append errors to the array.", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "Customer username.", + "types": [ "string" ], + "variable": "$username" + }, + { + "name": "param", + "content": "Customer email address.", + "types": [ "string" ], + "variable": "$user_email" + }, + { + "name": "param", + "content": "Error object.", + "types": [ "\\WP_Error" ], + "variable": "$errors" + } + ], + "long_description_html": "

This hook fires before customer accounts are created and passes the form data (username, email) and an array of errors.

This could be used to add extra validation logic and append errors to the array.

" + }, + "args": 3 + }, + { + "name": "woocommerce_rest_checkout_process_payment_with_context", + "file": "StoreApi/Routes/V1/Checkout.php", + "type": "action_reference", + "doc": { + "description": "Process payment with context.", + "long_description": "", + "tags": [ + { + "name": "hook", + "content": "woocommerce_rest_checkout_process_payment_with_context" + }, + { + "name": "throws", + "content": "If there is an error taking payment, an \\Exception object can be thrown with an error message.", + "types": [ "\\Exception" ] + }, + { + "name": "param", + "content": "Holds context for the payment, including order ID and payment method.", + "types": [ + "\\Automattic\\WooCommerce\\StoreApi\\Payments\\PaymentContext" + ], + "variable": "$context" + }, + { + "name": "param", + "content": "Result object for the transaction.", + "types": [ + "\\Automattic\\WooCommerce\\StoreApi\\Payments\\PaymentResult" + ], + "variable": "$payment_result" + } + ], + "long_description_html": "" + }, + "args": 1 + }, + { + "name": "woocommerce_shop_loop", + "file": "BlockTypes/ClassicTemplate.php", + "type": "action", + "doc": { + "description": "Hook: woocommerce_shop_loop.", + "long_description": "", + "tags": [], + "long_description_html": "" + }, + "args": 0 + }, + { + "name": "woocommerce_store_api_cart_errors", + "file": "StoreApi/Utilities/CartController.php", + "type": "action", + "doc": { + "description": "Fires an action to validate the cart.", + "long_description": "Functions hooking into this should add custom errors using the provided WP_Error instance.", + "tags": [ + { + "name": "example", + "content": "docs/examples/validate-cart.md" + }, + { + "name": "param", + "content": "WP_Error object.", + "types": [ "\\WP_Error" ], + "variable": "$errors" + }, + { + "name": "param", + "content": "Cart object.", + "types": [ "\\WC_Cart" ], + "variable": "$cart" + } + ], + "long_description_html": "

Functions hooking into this should add custom errors using the provided WP_Error instance.

" + }, + "args": 2 + }, + { + "name": "woocommerce_store_api_cart_update_customer_from_request", + "file": "StoreApi/Routes/V1/CartUpdateCustomer.php", + "type": "action", + "doc": { + "description": "Fires when the Checkout Block/Store API updates a customer from the API request data.", + "long_description": "", + "tags": [ + { + "name": "param", + "content": "Customer object.", + "types": [ "\\WC_Customer" ], + "variable": "$customer" + }, + { + "name": "param", + "content": "Full details about the request.", + "types": [ "\\WP_REST_Request" ], + "variable": "$request" + } + ], + "long_description_html": "" + }, + "args": 2 + }, + { + "name": "woocommerce_store_api_cart_update_order_from_request", + "file": "StoreApi/Routes/V1/AbstractCartRoute.php", + "type": "action", + "doc": { + "description": "Fires when the order is synced with cart data from a cart route.", + "long_description": "", + "tags": [ + { + "name": "param", + "content": "Order object.", + "types": [ "\\WC_Order" ], + "variable": "$draft_order" + }, + { + "name": "param", + "content": "Customer object.", + "types": [ "\\WC_Customer" ], + "variable": "$customer" + }, + { + "name": "param", + "content": "Full details about the request.", + "types": [ "\\WP_REST_Request" ], + "variable": "$request" + } + ], + "long_description_html": "" + }, + "args": 2 + }, + { + "name": "woocommerce_store_api_checkout_order_processed", + "file": "StoreApi/Routes/V1/Checkout.php", + "type": "action", + "doc": { + "description": "Fires before an order is processed by the Checkout Block/Store API.", + "long_description": "This hook informs extensions that $order has completed processing and is ready for payment.\n This is similar to existing core hook woocommerce_checkout_order_processed. We're using a new action: - To keep the interface focused (only pass $order, not passing request data). - This also explicitly indicates these orders are from checkout block/StoreAPI.", + "tags": [ + { + "name": "see", + "content": "", + "refers": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3238" + }, + { + "name": "example", + "content": "docs/examples/checkout-order-processed.md" + }, + { + "name": "param", + "content": "Order object.", + "types": [ "\\WC_Order" ], + "variable": "$order" + } + ], + "long_description_html": "

This hook informs extensions that $order has completed processing and is ready for payment.

This is similar to existing core hook woocommerce_checkout_order_processed. We're using a new action:

  • To keep the interface focused (only pass $order, not passing request data).
  • This also explicitly indicates these orders are from checkout block/StoreAPI.
" + }, + "args": 1 + }, + { + "name": "woocommerce_store_api_checkout_update_order_from_request", + "file": "StoreApi/Routes/V1/Checkout.php", + "type": "action", + "doc": { + "description": "Fires when the Checkout Block/Store API updates an order's from the API request data.", + "long_description": "This hook gives extensions the chance to update orders based on the data in the request. This can be used in conjunction with the ExtendSchema class to post custom data and then process it.", + "tags": [ + { + "name": "param", + "content": "Order object.", + "types": [ "\\WC_Order" ], + "variable": "$order" + }, + { + "name": "param", + "content": "Full details about the request.", + "types": [ "\\WP_REST_Request" ], + "variable": "$request" + } + ], + "long_description_html": "

This hook gives extensions the chance to update orders based on the data in the request. This can be used in conjunction with the ExtendSchema class to post custom data and then process it.

" + }, + "args": 2 + }, + { + "name": "woocommerce_store_api_checkout_update_order_meta", + "file": "StoreApi/Routes/V1/Checkout.php", + "type": "action", + "doc": { + "description": "Fires when the Checkout Block/Store API updates an order's meta data.", + "long_description": "This hook gives extensions the chance to add or update meta data on the $order. Throwing an exception from a callback attached to this action will make the Checkout Block render in a warning state, effectively preventing checkout.\n This is similar to existing core hook woocommerce_checkout_update_order_meta. We're using a new action: - To keep the interface focused (only pass $order, not passing request data). - This also explicitly indicates these orders are from checkout block/StoreAPI.", + "tags": [ + { + "name": "see", + "content": "", + "refers": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3686" + }, + { + "name": "param", + "content": "Order object.", + "types": [ "\\WC_Order" ], + "variable": "$order" + } + ], + "long_description_html": "

This hook gives extensions the chance to add or update meta data on the $order. Throwing an exception from a callback attached to this action will make the Checkout Block render in a warning state, effectively preventing checkout.

This is similar to existing core hook woocommerce_checkout_update_order_meta. We're using a new action:

  • To keep the interface focused (only pass $order, not passing request data).
  • This also explicitly indicates these orders are from checkout block/StoreAPI.
" + }, + "args": 1 + }, + { + "name": "woocommerce_store_api_validate_add_to_cart", + "file": "StoreApi/Utilities/CartController.php", + "type": "action", + "doc": { + "description": "Fires during validation when adding an item to the cart via the Store API.", + "long_description": "Fire action to validate add to cart. Functions hooking into this should throw an \\Exception to prevent add to cart from happening.", + "tags": [ + { + "name": "param", + "content": "Product object being added to the cart.", + "types": [ "\\WC_Product" ], + "variable": "$product" + }, + { + "name": "param", + "content": "Add to cart request params including id, quantity, and variation attributes.", + "types": [ "array" ], + "variable": "$request" + } + ], + "long_description_html": "

Fire action to validate add to cart. Functions hooking into this should throw an \\Exception to prevent add to cart from happening.

" + }, + "args": 2 + }, + { + "name": "woocommerce_store_api_validate_cart_item", + "file": "StoreApi/Utilities/CartController.php", + "type": "action", + "doc": { + "description": "Fire action to validate add to cart. Functions hooking into this should throw an \\Exception to prevent add to cart from occurring.", + "long_description": "", + "tags": [ + { + "name": "param", + "content": "Product object being added to the cart.", + "types": [ "\\WC_Product" ], + "variable": "$product" + }, + { + "name": "param", + "content": "Cart item array.", + "types": [ "array" ], + "variable": "$cart_item" + } + ], + "long_description_html": "" + }, + "args": 2 + } + ] +} diff --git a/plugins/woocommerce-blocks/bin/hook-docs/data/filters.json b/plugins/woocommerce-blocks/bin/hook-docs/data/filters.json index d1d57008517..e2efdd482aa 100644 --- a/plugins/woocommerce-blocks/bin/hook-docs/data/filters.json +++ b/plugins/woocommerce-blocks/bin/hook-docs/data/filters.json @@ -1,1011 +1,854 @@ { - "$schema": "https://raw.githubusercontent.com/johnbillion/wp-hooks-generator/0.7.3/schema.json", - "hooks": [ - { - "name": "__experimental_woocommerce_blocks_add_data_attributes_to_block", - "file": "BlockTypesController.php", - "type": "filter", - "doc": { - "description": "Filters the list of allowed Block Names", - "long_description": "This hook defines which block names should have block name and attribute data- attributes appended on render.", - "tags": [ - { - "name": "param", - "content": "List of namespaces.", - "types": [ - "array" - ], - "variable": "$allowed_namespaces" - } - ], - "long_description_html": "

This hook defines which block names should have block name and attribute data- attributes appended on render.

" - }, - "args": 1 - }, - { - "name": "__experimental_woocommerce_blocks_add_data_attributes_to_namespace", - "file": "BlockTypesController.php", - "type": "filter", - "doc": { - "description": "Filters the list of allowed block namespaces.", - "long_description": "This hook defines which block namespaces should have block name and attribute `data-` attributes appended on render.", - "tags": [ - { - "name": "param", - "content": "List of namespaces.", - "types": [ - "array" - ], - "variable": "$allowed_namespaces" - } - ], - "long_description_html": "

This hook defines which block namespaces should have block name and attribute data- attributes appended on render.

" - }, - "args": 1 - }, - { - "name": "__experimental_woocommerce_blocks_payment_gateway_features_list", - "file": "Payments/Integrations/PayPal.php", - "type": "filter", - "doc": { - "description": "Filter to control what features are available for each payment gateway.", - "long_description": "", - "tags": [ - { - "name": "example", - "content": "docs/examples/payment-gateways-features-list.md" - }, - { - "name": "param", - "content": "List of supported features.", - "types": [ - "array" - ], - "variable": "$features" - }, - { - "name": "param", - "content": "Gateway name.", - "types": [ - "string" - ], - "variable": "$name" - }, - { - "name": "return", - "content": "Updated list of supported features.", - "types": [ - "array" - ] - } - ], - "long_description_html": "" - }, - "args": 2 - }, - { - "name": "woocommerce_add_cart_item", - "file": "StoreApi/Utilities/CartController.php", - "type": "filter", - "doc": { - "description": "Filters the item being added to the cart.", - "long_description": "", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "Array of cart item data being added to the cart.", - "types": [ - "array" - ], - "variable": "$cart_item_data" - }, - { - "name": "param", - "content": "Id of the item in the cart.", - "types": [ - "string" - ], - "variable": "$cart_id" - }, - { - "name": "return", - "content": "Updated cart item data.", - "types": [ - "array" - ] - } - ], - "long_description_html": "" - }, - "args": 2 - }, - { - "name": "woocommerce_add_cart_item_data", - "file": "StoreApi/Utilities/CartController.php", - "type": "filter", - "doc": { - "description": "Filter cart item data for add to cart requests.", - "long_description": "", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "Array of other cart item data.", - "types": [ - "array" - ], - "variable": "$cart_item_data" - }, - { - "name": "param", - "content": "ID of the product added to the cart.", - "types": [ - "integer" - ], - "variable": "$product_id" - }, - { - "name": "param", - "content": "Variation ID of the product added to the cart.", - "types": [ - "integer" - ], - "variable": "$variation_id" - }, - { - "name": "param", - "content": "Quantity of the item added to the cart.", - "types": [ - "integer" - ], - "variable": "$quantity" - }, - { - "name": "return", - "content": "", - "types": [ - "array" - ] - } - ], - "long_description_html": "" - }, - "args": 4 - }, - { - "name": "woocommerce_add_to_cart_sold_individually_quantity", - "file": "StoreApi/Utilities/CartController.php", - "type": "filter", - "doc": { - "description": "Filter sold individually quantity for add to cart requests.", - "long_description": "", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "Defaults to 1.", - "types": [ - "integer" - ], - "variable": "$sold_individually_quantity" - }, - { - "name": "param", - "content": "Quantity of the item added to the cart.", - "types": [ - "integer" - ], - "variable": "$quantity" - }, - { - "name": "param", - "content": "ID of the product added to the cart.", - "types": [ - "integer" - ], - "variable": "$product_id" - }, - { - "name": "param", - "content": "Variation ID of the product added to the cart.", - "types": [ - "integer" - ], - "variable": "$variation_id" - }, - { - "name": "param", - "content": "Array of other cart item data.", - "types": [ - "array" - ], - "variable": "$cart_item_data" - }, - { - "name": "return", - "content": "", - "types": [ - "integer" - ] - } - ], - "long_description_html": "" - }, - "args": 5 - }, - { - "name": "woocommerce_add_to_cart_validation", - "file": "StoreApi/Utilities/CartController.php", - "type": "filter", - "doc": { - "description": "Filters if an item being added to the cart passed validation checks.", - "long_description": "Allow 3rd parties to validate if an item can be added to the cart. This is a legacy hook from Woo core. This filter will be deprecated because it encourages usage of wc_add_notice. For the API we need to capture notices and convert to exceptions instead.", - "tags": [ - { - "name": "deprecated", - "content": "" - }, - { - "name": "param", - "content": "True if the item passed validation.", - "types": [ - "boolean" - ], - "variable": "$passed_validation" - }, - { - "name": "param", - "content": "Product ID being validated.", - "types": [ - "integer" - ], - "variable": "$product_id" - }, - { - "name": "param", - "content": "Quantity added to the cart.", - "types": [ - "integer" - ], - "variable": "$quantity" - }, - { - "name": "param", - "content": "Variation ID being added to the cart.", - "types": [ - "integer" - ], - "variable": "$variation_id" - }, - { - "name": "param", - "content": "Variation data.", - "types": [ - "array" - ], - "variable": "$variation" - }, - { - "name": "return", - "content": "", - "types": [ - "boolean" - ] - } - ], - "long_description_html": "

Allow 3rd parties to validate if an item can be added to the cart. This is a legacy hook from Woo core. This filter will be deprecated because it encourages usage of wc_add_notice. For the API we need to capture notices and convert to exceptions instead.

" - }, - "args": 5 - }, - { - "name": "woocommerce_adjust_non_base_location_prices", - "file": "StoreApi/Utilities/ProductQuery.php", - "type": "filter", - "doc": { - "description": "Filters if taxes should be removed from locations outside the store base location.", - "long_description": "The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing with out of base locations. e.g. If a product costs 10 including tax, all users will pay 10 regardless of location and taxes.", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "True by default.", - "types": [ - "boolean" - ], - "variable": "$adjust_non_base_location_prices" - }, - { - "name": "return", - "content": "", - "types": [ - "boolean" - ] - } - ], - "long_description_html": "

The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing with out of base locations. e.g. If a product costs 10 including tax, all users will pay 10 regardless of location and taxes.

" - }, - "args": 1 - }, - { - "name": "woocommerce_admin_disabled", - "file": "InboxNotifications.php", - "type": "filter", - "doc": { - "description": "", - "long_description": "", - "tags": [], - "long_description_html": "" - }, - "args": 1 - }, - { - "name": "woocommerce_apply_individual_use_coupon", - "file": "StoreApi/Utilities/CartController.php", - "type": "filter", - "doc": { - "description": "Filter coupons to remove when applying an individual use coupon.", - "long_description": "", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "Array of coupons to remove from the cart.", - "types": [ - "array" - ], - "variable": "$coupons" - }, - { - "name": "param", - "content": "Coupon object applied to the cart.", - "types": [ - "\\WC_Coupon" - ], - "variable": "$coupon" - }, - { - "name": "param", - "content": "Array of applied coupons already applied to the cart.", - "types": [ - "array" - ], - "variable": "$applied_coupons" - }, - { - "name": "return", - "content": "", - "types": [ - "array" - ] - } - ], - "long_description_html": "" - }, - "args": 3 - }, - { - "name": "woocommerce_apply_with_individual_use_coupon", - "file": "StoreApi/Utilities/CartController.php", - "type": "filter", - "doc": { - "description": "Filters if a coupon can be applied alongside other individual use coupons.", - "long_description": "", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "Defaults to false.", - "types": [ - "boolean" - ], - "variable": "$apply_with_individual_use_coupon" - }, - { - "name": "param", - "content": "Coupon object applied to the cart.", - "types": [ - "\\WC_Coupon" - ], - "variable": "$coupon" - }, - { - "name": "param", - "content": "Individual use coupon already applied to the cart.", - "types": [ - "\\WC_Coupon" - ], - "variable": "$individual_use_coupon" - }, - { - "name": "param", - "content": "Array of applied coupons already applied to the cart.", - "types": [ - "array" - ], - "variable": "$applied_coupons" - }, - { - "name": "return", - "content": "", - "types": [ - "boolean" - ] - } - ], - "long_description_html": "" - }, - "args": 4 - }, - { - "name": "woocommerce_blocks_product_grid_is_cacheable", - "file": "BlockTypes/AbstractProductGrid.php", - "type": "filter", - "doc": { - "description": "Filters whether or not the product grid is cacheable.", - "long_description": "", - "tags": [ - { - "name": "param", - "content": "The list of script dependencies.", - "types": [ - "boolean" - ], - "variable": "$is_cacheable" - }, - { - "name": "param", - "content": "Query args for the products query passed to BlocksWpQuery.", - "types": [ - "array" - ], - "variable": "$query_args" - }, - { - "name": "return", - "content": "True to enable cache, false to disable cache.", - "types": [ - "array" - ] - } - ], - "long_description_html": "" - }, - "args": 2 - }, - { - "name": "woocommerce_blocks_product_grid_item_html", - "file": "BlockTypes/AbstractProductGrid.php", - "type": "filter", - "doc": { - "description": "Filters the HTML for products in the grid.", - "long_description": "", - "tags": [ - { - "name": "param", - "content": "Product grid item HTML.", - "types": [ - "string" - ], - "variable": "$html" - }, - { - "name": "param", - "content": "Product data passed to the template.", - "types": [ - "array" - ], - "variable": "$data" - }, - { - "name": "param", - "content": "Product object.", - "types": [ - "\\WC_Product" - ], - "variable": "$product" - }, - { - "name": "return", - "content": "Updated product grid item HTML.", - "types": [ - "string" - ] - } - ], - "long_description_html": "" - }, - "args": 3 - }, - { - "name": "woocommerce_blocks_register_script_dependencies", - "file": "Assets/Api.php", - "type": "filter", - "doc": { - "description": "Filters the list of script dependencies.", - "long_description": "", - "tags": [ - { - "name": "param", - "content": "The list of script dependencies.", - "types": [ - "array" - ], - "variable": "$dependencies" - }, - { - "name": "param", - "content": "The script's handle.", - "types": [ - "string" - ], - "variable": "$handle" - }, - { - "name": "return", - "content": "", - "types": [ - "array" - ] - } - ], - "long_description_html": "" - }, - "args": 2 - }, - { - "name": "woocommerce_cart_contents_changed", - "file": "StoreApi/Utilities/CartController.php", - "type": "filter", - "doc": { - "description": "Filters the entire cart contents when the cart changes.", - "long_description": "", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "Array of all cart items.", - "types": [ - "array" - ], - "variable": "$cart_contents" - }, - { - "name": "return", - "content": "Updated array of all cart items.", - "types": [ - "array" - ] - } - ], - "long_description_html": "" - }, - "args": 1 - }, - { - "name": "woocommerce_ga_disable_tracking", - "file": "Domain/Services/GoogleAnalytics.php", - "type": "filter", - "doc": { - "description": "Filter to disable Google Analytics tracking.", - "long_description": "", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in GA extension." - }, - { - "name": "param", - "content": "If true, tracking will be disabled.", - "types": [ - "boolean" - ], - "variable": "$disable_tracking" - } - ], - "long_description_html": "" - }, - "args": 1 - }, - { - "name": "woocommerce_get_item_data", - "file": "StoreApi/Schemas/V1/CartItemSchema.php", - "type": "filter", - "doc": { - "description": "Filters cart item data.", - "long_description": "Filters the variation option name for custom option slugs.", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "Cart item data. Empty by default.", - "types": [ - "array" - ], - "variable": "$item_data" - }, - { - "name": "param", - "content": "Cart item array.", - "types": [ - "array" - ], - "variable": "$cart_item" - }, - { - "name": "return", - "content": "", - "types": [ - "array" - ] - } - ], - "long_description_html": "

Filters the variation option name for custom option slugs.

" - }, - "args": 2 - }, - { - "name": "woocommerce_new_customer_data", - "file": "StoreApi/Routes/V1/Checkout.php", - "type": "filter", - "doc": { - "description": "Filters customer data before a customer account is registered.", - "long_description": "This hook filters customer data. It allows user data to be changed, for example, username, password, email, first name, last name, and role.", - "tags": [ - { - "name": "param", - "content": "An array of customer (user) data.", - "types": [ - "array" - ], - "variable": "$customer_data" - }, - { - "name": "return", - "content": "", - "types": [ - "array" - ] - } - ], - "long_description_html": "

This hook filters customer data. It allows user data to be changed, for example, username, password, email, first name, last name, and role.

" - }, - "args": 1 - }, - { - "name": "woocommerce_registration_errors", - "file": "StoreApi/Routes/V1/Checkout.php", - "type": "filter", - "doc": { - "description": "Filters registration errors before a customer account is registered.", - "long_description": "This hook filters registration errors. This can be used to manipulate the array of errors before they are displayed.", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "Error object.", - "types": [ - "\\WP_Error" - ], - "variable": "$errors" - }, - { - "name": "param", - "content": "Customer username.", - "types": [ - "string" - ], - "variable": "$username" - }, - { - "name": "param", - "content": "Customer email address.", - "types": [ - "string" - ], - "variable": "$user_email" - }, - { - "name": "return", - "content": "", - "types": [ - "\\WP_Error" - ] - } - ], - "long_description_html": "

This hook filters registration errors. This can be used to manipulate the array of errors before they are displayed.

" - }, - "args": 3 - }, - { - "name": "woocommerce_shared_settings", - "file": "Assets/AssetDataRegistry.php", - "type": "filter", - "doc": { - "description": "Filters the array of shared settings.", - "long_description": "Low level hook for registration of new data late in the cycle. This is deprecated. Instead, use the data api:\n ```php Automattic\\WooCommerce\\Blocks\\Package::container()->get( Automattic\\WooCommerce\\Blocks\\Assets\\AssetDataRegistry::class )->add( $key, $value ) ```", - "tags": [ - { - "name": "deprecated", - "content": "" - }, - { - "name": "param", - "content": "Settings data.", - "types": [ - "array" - ], - "variable": "$data" - }, - { - "name": "return", - "content": "", - "types": [ - "array" - ] - } - ], - "long_description_html": "

Low level hook for registration of new data late in the cycle. This is deprecated. Instead, use the data api:

Automattic\\WooCommerce\\Blocks\\Package::container()->get( Automattic\\WooCommerce\\Blocks\\Assets\\AssetDataRegistry::class )->add( $key, $value )
" - }, - "args": 1 - }, - { - "name": "woocommerce_shipping_package_name", - "file": "StoreApi/Utilities/CartController.php", - "type": "filter", - "doc": { - "description": "Filters the shipping package name.", - "long_description": "", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "Shipping package name.", - "types": [ - "string" - ], - "variable": "$shipping_package_name" - }, - { - "name": "param", - "content": "Shipping package ID.", - "types": [ - "string" - ], - "variable": "$package_id" - }, - { - "name": "param", - "content": "Shipping package from WooCommerce.", - "types": [ - "array" - ], - "variable": "$package" - }, - { - "name": "return", - "content": "Shipping package name.", - "types": [ - "string" - ] - } - ], - "long_description_html": "" - }, - "args": 3 - }, - { - "name": "woocommerce_show_page_title", - "file": "BlockTypes/ClassicTemplate.php", - "type": "filter", - "doc": { - "description": "We need to load the scripts here because when using block templates wp_head() gets run after the block template. As a result we are trying to enqueue required scripts before we have even registered them.", - "long_description": "", - "tags": [ - { - "name": "see", - "content": "", - "refers": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/5328#issuecomment-989013447" - } - ], - "long_description_html": "" - }, - "args": 1 - }, - { - "name": "woocommerce_store_api_disable_nonce_check", - "file": "StoreApi/Routes/V1/AbstractCartRoute.php", - "type": "filter", - "doc": { - "description": "Filters the Store API nonce check.", - "long_description": "This can be used to disable the nonce check when testing API endpoints via a REST API client.", - "tags": [ - { - "name": "param", - "content": "If true, nonce checks will be disabled.", - "types": [ - "boolean" - ], - "variable": "$disable_nonce_check" - }, - { - "name": "return", - "content": "", - "types": [ - "boolean" - ] - } - ], - "long_description_html": "

This can be used to disable the nonce check when testing API endpoints via a REST API client.

" - }, - "args": 1 - }, - { - "name": "woocommerce_store_api_product_quantity_limit", - "file": "StoreApi/Utilities/QuantityLimits.php", - "type": "filter", - "doc": { - "description": "Filters the quantity limit for a product being added to the cart via the Store API.", - "long_description": "Filters the variation option name for custom option slugs.", - "tags": [ - { - "name": "param", - "content": "Quantity limit which defaults to 9999 unless sold individually.", - "types": [ - "integer" - ], - "variable": "$quantity_limit" - }, - { - "name": "param", - "content": "Product instance.", - "types": [ - "\\WC_Product" - ], - "variable": "$product" - }, - { - "name": "return", - "content": "", - "types": [ - "integer" - ] - } - ], - "long_description_html": "

Filters the variation option name for custom option slugs.

" - }, - "args": 2 - }, - { - "name": "woocommerce_store_api_product_quantity_{$value_type}", - "file": "StoreApi/Utilities/QuantityLimits.php", - "type": "filter", - "doc": { - "description": "Filters the quantity minimum for a cart item in Store API. This allows extensions to control the minimum qty of items already within the cart.", - "long_description": "The suffix of the hook will vary depending on the value being filtered. For example, minimum, maximum, multiple_of, editable.", - "tags": [ - { - "name": "param", - "content": "The value being filtered.", - "types": [ - "mixed" - ], - "variable": "$value" - }, - { - "name": "param", - "content": "The product object.", - "types": [ - "\\WC_Product" - ], - "variable": "$product" - }, - { - "name": "param", - "content": "The cart item if the product exists in the cart, or null.", - "types": [ - "array", - "null" - ], - "variable": "$cart_item" - }, - { - "name": "return", - "content": "", - "types": [ - "mixed" - ] - } - ], - "long_description_html": "

The suffix of the hook will vary depending on the value being filtered. For example, minimum, maximum, multiple_of, editable.

" - }, - "args": 3 - }, - { - "name": "woocommerce_variation_option_name", - "file": "StoreApi/Schemas/V1/CartItemSchema.php", - "type": "filter", - "doc": { - "description": "Filters the variation option name.", - "long_description": "Filters the variation option name for custom option slugs.", - "tags": [ - { - "name": "internal", - "content": "Matches filter name in WooCommerce core." - }, - { - "name": "param", - "content": "The name to display.", - "types": [ - "string" - ], - "variable": "$value" - }, - { - "name": "param", - "content": "Unused because this is not a variation taxonomy.", - "types": [ - "null" - ], - "variable": "$unused" - }, - { - "name": "param", - "content": "Taxonomy or product attribute name.", - "types": [ - "string" - ], - "variable": "$taxonomy" - }, - { - "name": "param", - "content": "Product data.", - "types": [ - "\\WC_Product" - ], - "variable": "$product" - }, - { - "name": "return", - "content": "", - "types": [ - "string" - ] - } - ], - "long_description_html": "

Filters the variation option name for custom option slugs.

" - }, - "args": 4 - } - ] -} \ No newline at end of file + "$schema": "https://raw.githubusercontent.com/johnbillion/wp-hooks-generator/0.7.3/schema.json", + "hooks": [ + { + "name": "__experimental_woocommerce_blocks_add_data_attributes_to_block", + "file": "BlockTypesController.php", + "type": "filter", + "doc": { + "description": "Filters the list of allowed Block Names", + "long_description": "This hook defines which block names should have block name and attribute data- attributes appended on render.", + "tags": [ + { + "name": "param", + "content": "List of namespaces.", + "types": [ "array" ], + "variable": "$allowed_namespaces" + } + ], + "long_description_html": "

This hook defines which block names should have block name and attribute data- attributes appended on render.

" + }, + "args": 1 + }, + { + "name": "__experimental_woocommerce_blocks_add_data_attributes_to_namespace", + "file": "BlockTypesController.php", + "type": "filter", + "doc": { + "description": "Filters the list of allowed block namespaces.", + "long_description": "This hook defines which block namespaces should have block name and attribute `data-` attributes appended on render.", + "tags": [ + { + "name": "param", + "content": "List of namespaces.", + "types": [ "array" ], + "variable": "$allowed_namespaces" + } + ], + "long_description_html": "

This hook defines which block namespaces should have block name and attribute data- attributes appended on render.

" + }, + "args": 1 + }, + { + "name": "__experimental_woocommerce_blocks_payment_gateway_features_list", + "file": "Payments/Integrations/PayPal.php", + "type": "filter", + "doc": { + "description": "Filter to control what features are available for each payment gateway.", + "long_description": "", + "tags": [ + { + "name": "example", + "content": "docs/examples/payment-gateways-features-list.md" + }, + { + "name": "param", + "content": "List of supported features.", + "types": [ "array" ], + "variable": "$features" + }, + { + "name": "param", + "content": "Gateway name.", + "types": [ "string" ], + "variable": "$name" + }, + { + "name": "return", + "content": "Updated list of supported features.", + "types": [ "array" ] + } + ], + "long_description_html": "" + }, + "args": 2 + }, + { + "name": "woocommerce_add_cart_item", + "file": "StoreApi/Utilities/CartController.php", + "type": "filter", + "doc": { + "description": "Filters the item being added to the cart.", + "long_description": "", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "Array of cart item data being added to the cart.", + "types": [ "array" ], + "variable": "$cart_item_data" + }, + { + "name": "param", + "content": "Id of the item in the cart.", + "types": [ "string" ], + "variable": "$cart_id" + }, + { + "name": "return", + "content": "Updated cart item data.", + "types": [ "array" ] + } + ], + "long_description_html": "" + }, + "args": 2 + }, + { + "name": "woocommerce_add_cart_item_data", + "file": "StoreApi/Utilities/CartController.php", + "type": "filter", + "doc": { + "description": "Filter cart item data for add to cart requests.", + "long_description": "", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "Array of other cart item data.", + "types": [ "array" ], + "variable": "$cart_item_data" + }, + { + "name": "param", + "content": "ID of the product added to the cart.", + "types": [ "integer" ], + "variable": "$product_id" + }, + { + "name": "param", + "content": "Variation ID of the product added to the cart.", + "types": [ "integer" ], + "variable": "$variation_id" + }, + { + "name": "param", + "content": "Quantity of the item added to the cart.", + "types": [ "integer" ], + "variable": "$quantity" + }, + { + "name": "return", + "content": "", + "types": [ "array" ] + } + ], + "long_description_html": "" + }, + "args": 4 + }, + { + "name": "woocommerce_add_to_cart_sold_individually_quantity", + "file": "StoreApi/Utilities/CartController.php", + "type": "filter", + "doc": { + "description": "Filter sold individually quantity for add to cart requests.", + "long_description": "", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "Defaults to 1.", + "types": [ "integer" ], + "variable": "$sold_individually_quantity" + }, + { + "name": "param", + "content": "Quantity of the item added to the cart.", + "types": [ "integer" ], + "variable": "$quantity" + }, + { + "name": "param", + "content": "ID of the product added to the cart.", + "types": [ "integer" ], + "variable": "$product_id" + }, + { + "name": "param", + "content": "Variation ID of the product added to the cart.", + "types": [ "integer" ], + "variable": "$variation_id" + }, + { + "name": "param", + "content": "Array of other cart item data.", + "types": [ "array" ], + "variable": "$cart_item_data" + }, + { + "name": "return", + "content": "", + "types": [ "integer" ] + } + ], + "long_description_html": "" + }, + "args": 5 + }, + { + "name": "woocommerce_add_to_cart_validation", + "file": "StoreApi/Utilities/CartController.php", + "type": "filter", + "doc": { + "description": "Filters if an item being added to the cart passed validation checks.", + "long_description": "Allow 3rd parties to validate if an item can be added to the cart. This is a legacy hook from Woo core. This filter will be deprecated because it encourages usage of wc_add_notice. For the API we need to capture notices and convert to exceptions instead.", + "tags": [ + { + "name": "deprecated", + "content": "" + }, + { + "name": "param", + "content": "True if the item passed validation.", + "types": [ "boolean" ], + "variable": "$passed_validation" + }, + { + "name": "param", + "content": "Product ID being validated.", + "types": [ "integer" ], + "variable": "$product_id" + }, + { + "name": "param", + "content": "Quantity added to the cart.", + "types": [ "integer" ], + "variable": "$quantity" + }, + { + "name": "param", + "content": "Variation ID being added to the cart.", + "types": [ "integer" ], + "variable": "$variation_id" + }, + { + "name": "param", + "content": "Variation data.", + "types": [ "array" ], + "variable": "$variation" + }, + { + "name": "return", + "content": "", + "types": [ "boolean" ] + } + ], + "long_description_html": "

Allow 3rd parties to validate if an item can be added to the cart. This is a legacy hook from Woo core. This filter will be deprecated because it encourages usage of wc_add_notice. For the API we need to capture notices and convert to exceptions instead.

" + }, + "args": 5 + }, + { + "name": "woocommerce_adjust_non_base_location_prices", + "file": "StoreApi/Utilities/ProductQuery.php", + "type": "filter", + "doc": { + "description": "Filters if taxes should be removed from locations outside the store base location.", + "long_description": "The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing with out of base locations. e.g. If a product costs 10 including tax, all users will pay 10 regardless of location and taxes.", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "True by default.", + "types": [ "boolean" ], + "variable": "$adjust_non_base_location_prices" + }, + { + "name": "return", + "content": "", + "types": [ "boolean" ] + } + ], + "long_description_html": "

The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing with out of base locations. e.g. If a product costs 10 including tax, all users will pay 10 regardless of location and taxes.

" + }, + "args": 1 + }, + { + "name": "woocommerce_admin_disabled", + "file": "InboxNotifications.php", + "type": "filter", + "doc": { + "description": "", + "long_description": "", + "tags": [], + "long_description_html": "" + }, + "args": 1 + }, + { + "name": "woocommerce_apply_individual_use_coupon", + "file": "StoreApi/Utilities/CartController.php", + "type": "filter", + "doc": { + "description": "Filter coupons to remove when applying an individual use coupon.", + "long_description": "", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "Array of coupons to remove from the cart.", + "types": [ "array" ], + "variable": "$coupons" + }, + { + "name": "param", + "content": "Coupon object applied to the cart.", + "types": [ "\\WC_Coupon" ], + "variable": "$coupon" + }, + { + "name": "param", + "content": "Array of applied coupons already applied to the cart.", + "types": [ "array" ], + "variable": "$applied_coupons" + }, + { + "name": "return", + "content": "", + "types": [ "array" ] + } + ], + "long_description_html": "" + }, + "args": 3 + }, + { + "name": "woocommerce_apply_with_individual_use_coupon", + "file": "StoreApi/Utilities/CartController.php", + "type": "filter", + "doc": { + "description": "Filters if a coupon can be applied alongside other individual use coupons.", + "long_description": "", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "Defaults to false.", + "types": [ "boolean" ], + "variable": "$apply_with_individual_use_coupon" + }, + { + "name": "param", + "content": "Coupon object applied to the cart.", + "types": [ "\\WC_Coupon" ], + "variable": "$coupon" + }, + { + "name": "param", + "content": "Individual use coupon already applied to the cart.", + "types": [ "\\WC_Coupon" ], + "variable": "$individual_use_coupon" + }, + { + "name": "param", + "content": "Array of applied coupons already applied to the cart.", + "types": [ "array" ], + "variable": "$applied_coupons" + }, + { + "name": "return", + "content": "", + "types": [ "boolean" ] + } + ], + "long_description_html": "" + }, + "args": 4 + }, + { + "name": "woocommerce_blocks_product_grid_is_cacheable", + "file": "BlockTypes/AbstractProductGrid.php", + "type": "filter", + "doc": { + "description": "Filters whether or not the product grid is cacheable.", + "long_description": "", + "tags": [ + { + "name": "param", + "content": "The list of script dependencies.", + "types": [ "boolean" ], + "variable": "$is_cacheable" + }, + { + "name": "param", + "content": "Query args for the products query passed to BlocksWpQuery.", + "types": [ "array" ], + "variable": "$query_args" + }, + { + "name": "return", + "content": "True to enable cache, false to disable cache.", + "types": [ "array" ] + } + ], + "long_description_html": "" + }, + "args": 2 + }, + { + "name": "woocommerce_blocks_product_grid_item_html", + "file": "BlockTypes/AbstractProductGrid.php", + "type": "filter", + "doc": { + "description": "Filters the HTML for products in the grid.", + "long_description": "", + "tags": [ + { + "name": "param", + "content": "Product grid item HTML.", + "types": [ "string" ], + "variable": "$html" + }, + { + "name": "param", + "content": "Product data passed to the template.", + "types": [ "array" ], + "variable": "$data" + }, + { + "name": "param", + "content": "Product object.", + "types": [ "\\WC_Product" ], + "variable": "$product" + }, + { + "name": "return", + "content": "Updated product grid item HTML.", + "types": [ "string" ] + } + ], + "long_description_html": "" + }, + "args": 3 + }, + { + "name": "woocommerce_blocks_register_script_dependencies", + "file": "Assets/Api.php", + "type": "filter", + "doc": { + "description": "Filters the list of script dependencies.", + "long_description": "", + "tags": [ + { + "name": "param", + "content": "The list of script dependencies.", + "types": [ "array" ], + "variable": "$dependencies" + }, + { + "name": "param", + "content": "The script's handle.", + "types": [ "string" ], + "variable": "$handle" + }, + { + "name": "return", + "content": "", + "types": [ "array" ] + } + ], + "long_description_html": "" + }, + "args": 2 + }, + { + "name": "woocommerce_cart_contents_changed", + "file": "StoreApi/Utilities/CartController.php", + "type": "filter", + "doc": { + "description": "Filters the entire cart contents when the cart changes.", + "long_description": "", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "Array of all cart items.", + "types": [ "array" ], + "variable": "$cart_contents" + }, + { + "name": "return", + "content": "Updated array of all cart items.", + "types": [ "array" ] + } + ], + "long_description_html": "" + }, + "args": 1 + }, + { + "name": "woocommerce_ga_disable_tracking", + "file": "Domain/Services/GoogleAnalytics.php", + "type": "filter", + "doc": { + "description": "Filter to disable Google Analytics tracking.", + "long_description": "", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in GA extension." + }, + { + "name": "param", + "content": "If true, tracking will be disabled.", + "types": [ "boolean" ], + "variable": "$disable_tracking" + } + ], + "long_description_html": "" + }, + "args": 1 + }, + { + "name": "woocommerce_get_item_data", + "file": "StoreApi/Schemas/V1/CartItemSchema.php", + "type": "filter", + "doc": { + "description": "Filters cart item data.", + "long_description": "Filters the variation option name for custom option slugs.", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "Cart item data. Empty by default.", + "types": [ "array" ], + "variable": "$item_data" + }, + { + "name": "param", + "content": "Cart item array.", + "types": [ "array" ], + "variable": "$cart_item" + }, + { + "name": "return", + "content": "", + "types": [ "array" ] + } + ], + "long_description_html": "

Filters the variation option name for custom option slugs.

" + }, + "args": 2 + }, + { + "name": "woocommerce_new_customer_data", + "file": "StoreApi/Routes/V1/Checkout.php", + "type": "filter", + "doc": { + "description": "Filters customer data before a customer account is registered.", + "long_description": "This hook filters customer data. It allows user data to be changed, for example, username, password, email, first name, last name, and role.", + "tags": [ + { + "name": "param", + "content": "An array of customer (user) data.", + "types": [ "array" ], + "variable": "$customer_data" + }, + { + "name": "return", + "content": "", + "types": [ "array" ] + } + ], + "long_description_html": "

This hook filters customer data. It allows user data to be changed, for example, username, password, email, first name, last name, and role.

" + }, + "args": 1 + }, + { + "name": "woocommerce_registration_errors", + "file": "StoreApi/Routes/V1/Checkout.php", + "type": "filter", + "doc": { + "description": "Filters registration errors before a customer account is registered.", + "long_description": "This hook filters registration errors. This can be used to manipulate the array of errors before they are displayed.", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "Error object.", + "types": [ "\\WP_Error" ], + "variable": "$errors" + }, + { + "name": "param", + "content": "Customer username.", + "types": [ "string" ], + "variable": "$username" + }, + { + "name": "param", + "content": "Customer email address.", + "types": [ "string" ], + "variable": "$user_email" + }, + { + "name": "return", + "content": "", + "types": [ "\\WP_Error" ] + } + ], + "long_description_html": "

This hook filters registration errors. This can be used to manipulate the array of errors before they are displayed.

" + }, + "args": 3 + }, + { + "name": "woocommerce_shared_settings", + "file": "Assets/AssetDataRegistry.php", + "type": "filter", + "doc": { + "description": "Filters the array of shared settings.", + "long_description": "Low level hook for registration of new data late in the cycle. This is deprecated. Instead, use the data api:\n ```php Automattic\\WooCommerce\\Blocks\\Package::container()->get( Automattic\\WooCommerce\\Blocks\\Assets\\AssetDataRegistry::class )->add( $key, $value ) ```", + "tags": [ + { + "name": "deprecated", + "content": "" + }, + { + "name": "param", + "content": "Settings data.", + "types": [ "array" ], + "variable": "$data" + }, + { + "name": "return", + "content": "", + "types": [ "array" ] + } + ], + "long_description_html": "

Low level hook for registration of new data late in the cycle. This is deprecated. Instead, use the data api:

Automattic\\WooCommerce\\Blocks\\Package::container()->get( Automattic\\WooCommerce\\Blocks\\Assets\\AssetDataRegistry::class )->add( $key, $value )
" + }, + "args": 1 + }, + { + "name": "woocommerce_shipping_package_name", + "file": "StoreApi/Utilities/CartController.php", + "type": "filter", + "doc": { + "description": "Filters the shipping package name.", + "long_description": "", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "Shipping package name.", + "types": [ "string" ], + "variable": "$shipping_package_name" + }, + { + "name": "param", + "content": "Shipping package ID.", + "types": [ "string" ], + "variable": "$package_id" + }, + { + "name": "param", + "content": "Shipping package from WooCommerce.", + "types": [ "array" ], + "variable": "$package" + }, + { + "name": "return", + "content": "Shipping package name.", + "types": [ "string" ] + } + ], + "long_description_html": "" + }, + "args": 3 + }, + { + "name": "woocommerce_show_page_title", + "file": "BlockTypes/ClassicTemplate.php", + "type": "filter", + "doc": { + "description": "We need to load the scripts here because when using block templates wp_head() gets run after the block template. As a result we are trying to enqueue required scripts before we have even registered them.", + "long_description": "", + "tags": [ + { + "name": "see", + "content": "", + "refers": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/5328#issuecomment-989013447" + } + ], + "long_description_html": "" + }, + "args": 1 + }, + { + "name": "woocommerce_store_api_disable_nonce_check", + "file": "StoreApi/Routes/V1/AbstractCartRoute.php", + "type": "filter", + "doc": { + "description": "Filters the Store API nonce check.", + "long_description": "This can be used to disable the nonce check when testing API endpoints via a REST API client.", + "tags": [ + { + "name": "param", + "content": "If true, nonce checks will be disabled.", + "types": [ "boolean" ], + "variable": "$disable_nonce_check" + }, + { + "name": "return", + "content": "", + "types": [ "boolean" ] + } + ], + "long_description_html": "

This can be used to disable the nonce check when testing API endpoints via a REST API client.

" + }, + "args": 1 + }, + { + "name": "woocommerce_store_api_product_quantity_limit", + "file": "StoreApi/Utilities/QuantityLimits.php", + "type": "filter", + "doc": { + "description": "Filters the quantity limit for a product being added to the cart via the Store API.", + "long_description": "Filters the variation option name for custom option slugs.", + "tags": [ + { + "name": "param", + "content": "Quantity limit which defaults to 9999 unless sold individually.", + "types": [ "integer" ], + "variable": "$quantity_limit" + }, + { + "name": "param", + "content": "Product instance.", + "types": [ "\\WC_Product" ], + "variable": "$product" + }, + { + "name": "return", + "content": "", + "types": [ "integer" ] + } + ], + "long_description_html": "

Filters the variation option name for custom option slugs.

" + }, + "args": 2 + }, + { + "name": "woocommerce_store_api_product_quantity_{$value_type}", + "file": "StoreApi/Utilities/QuantityLimits.php", + "type": "filter", + "doc": { + "description": "Filters the quantity minimum for a cart item in Store API. This allows extensions to control the minimum qty of items already within the cart.", + "long_description": "The suffix of the hook will vary depending on the value being filtered. For example, minimum, maximum, multiple_of, editable.", + "tags": [ + { + "name": "param", + "content": "The value being filtered.", + "types": [ "mixed" ], + "variable": "$value" + }, + { + "name": "param", + "content": "The product object.", + "types": [ "\\WC_Product" ], + "variable": "$product" + }, + { + "name": "param", + "content": "The cart item if the product exists in the cart, or null.", + "types": [ "array", "null" ], + "variable": "$cart_item" + }, + { + "name": "return", + "content": "", + "types": [ "mixed" ] + } + ], + "long_description_html": "

The suffix of the hook will vary depending on the value being filtered. For example, minimum, maximum, multiple_of, editable.

" + }, + "args": 3 + }, + { + "name": "woocommerce_variation_option_name", + "file": "StoreApi/Schemas/V1/CartItemSchema.php", + "type": "filter", + "doc": { + "description": "Filters the variation option name.", + "long_description": "Filters the variation option name for custom option slugs.", + "tags": [ + { + "name": "internal", + "content": "Matches filter name in WooCommerce core." + }, + { + "name": "param", + "content": "The name to display.", + "types": [ "string" ], + "variable": "$value" + }, + { + "name": "param", + "content": "Unused because this is not a variation taxonomy.", + "types": [ "null" ], + "variable": "$unused" + }, + { + "name": "param", + "content": "Taxonomy or product attribute name.", + "types": [ "string" ], + "variable": "$taxonomy" + }, + { + "name": "param", + "content": "Product data.", + "types": [ "\\WC_Product" ], + "variable": "$product" + }, + { + "name": "return", + "content": "", + "types": [ "string" ] + } + ], + "long_description_html": "

Filters the variation option name for custom option slugs.

" + }, + "args": 4 + } + ] +} diff --git a/plugins/woocommerce-blocks/bin/hook-docs/filters/index.js b/plugins/woocommerce-blocks/bin/hook-docs/filters/index.js index a5d2fde3937..2d114ad10d3 100644 --- a/plugins/woocommerce-blocks/bin/hook-docs/filters/index.js +++ b/plugins/woocommerce-blocks/bin/hook-docs/filters/index.js @@ -32,8 +32,7 @@ const generate = ( hooks ) => { const jsonDocs = [ { html: '' }, { - html: - '', + html: '', }, { h1: 'Filters' }, { h2: 'Table of Contents' }, diff --git a/plugins/woocommerce-blocks/bin/webpack-configs.js b/plugins/woocommerce-blocks/bin/webpack-configs.js index 2d2ad7684e7..b2e8374333d 100644 --- a/plugins/woocommerce-blocks/bin/webpack-configs.js +++ b/plugins/woocommerce-blocks/bin/webpack-configs.js @@ -711,10 +711,8 @@ const getStylingConfig = ( options = {} ) => { includePaths: [ 'assets/css/abstracts' ], }, additionalData: ( content, loaderContext ) => { - const { - resourcePath, - rootContext, - } = loaderContext; + const { resourcePath, rootContext } = + loaderContext; const relativePath = path.relative( rootContext, resourcePath diff --git a/plugins/woocommerce-blocks/package-lock.json b/plugins/woocommerce-blocks/package-lock.json index 444ae211ac0..1605dad4d41 100644 --- a/plugins/woocommerce-blocks/package-lock.json +++ b/plugins/woocommerce-blocks/package-lock.json @@ -93,6 +93,7 @@ "@wordpress/html-entities": "3.2.3", "@wordpress/i18n": "4.2.4", "@wordpress/is-shallow-equal": "4.2.1", + "@wordpress/prettier-config": "^1.1.1", "@wordpress/scripts": "22.3.0", "autoprefixer": "10.3.7", "axios": "0.21.4", @@ -138,10 +139,10 @@ "patch-package": "6.4.7", "postcss": "8.2.13", "postcss-loader": "4.2.0", - "prettier": "npm:wp-prettier@2.0.5", + "prettier": "npm:wp-prettier@2.6.2", "progress-bar-webpack-plugin": "2.1.0", "promptly": "3.2.0", - "puppeteer": "^13.7.0", + "puppeteer": "13.7.0", "react-docgen": "5.4.0", "react-test-renderer": "17.0.2", "request-promise": "4.2.6", @@ -39459,10 +39460,19 @@ }, "node_modules/prettier": { "name": "wp-prettier", - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-2.0.5.tgz", - "integrity": "sha512-5GCgdeevIXwR3cW4Qj5XWC5MO1iSCz8+IPn0mMw6awAt/PBiey8yyO7MhePRsaMqghJAhg6Q3QLYWSnUHWkG6A==", - "dev": true + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-2.6.2.tgz", + "integrity": "sha512-AV33EzqiFJ3fj+mPlKABN59YFPReLkDxQnj067Z3uEOeRQf3g05WprL0RDuqM7UBhSRo9W1rMSC2KvZmjE5UOA==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } }, "node_modules/prettier-linter-helpers": { "version": "1.0.0", @@ -79483,9 +79493,9 @@ "optional": true }, "prettier": { - "version": "npm:wp-prettier@2.0.5", - "resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-2.0.5.tgz", - "integrity": "sha512-5GCgdeevIXwR3cW4Qj5XWC5MO1iSCz8+IPn0mMw6awAt/PBiey8yyO7MhePRsaMqghJAhg6Q3QLYWSnUHWkG6A==", + "version": "npm:wp-prettier@2.6.2", + "resolved": "https://registry.npmjs.org/wp-prettier/-/wp-prettier-2.6.2.tgz", + "integrity": "sha512-AV33EzqiFJ3fj+mPlKABN59YFPReLkDxQnj067Z3uEOeRQf3g05WprL0RDuqM7UBhSRo9W1rMSC2KvZmjE5UOA==", "dev": true }, "prettier-linter-helpers": { diff --git a/plugins/woocommerce-blocks/package.json b/plugins/woocommerce-blocks/package.json index 7d76bf4bb2d..3272692faf5 100644 --- a/plugins/woocommerce-blocks/package.json +++ b/plugins/woocommerce-blocks/package.json @@ -143,6 +143,7 @@ "@wordpress/i18n": "4.2.4", "@wordpress/is-shallow-equal": "4.2.1", "@wordpress/scripts": "22.3.0", + "@wordpress/prettier-config": "^1.1.1", "autoprefixer": "10.3.7", "axios": "0.21.4", "babel-plugin-explicit-exports-references": "^1.0.2", @@ -187,7 +188,7 @@ "patch-package": "6.4.7", "postcss": "8.2.13", "postcss-loader": "4.2.0", - "prettier": "npm:wp-prettier@2.0.5", + "prettier": "npm:wp-prettier@2.6.2", "progress-bar-webpack-plugin": "2.1.0", "promptly": "3.2.0", "puppeteer": "13.7.0", diff --git a/plugins/woocommerce-blocks/packages/checkout/components/discounts-meta/index.js b/plugins/woocommerce-blocks/packages/checkout/components/discounts-meta/index.js index 267adf39db4..3f87627a7e8 100644 --- a/plugins/woocommerce-blocks/packages/checkout/components/discounts-meta/index.js +++ b/plugins/woocommerce-blocks/packages/checkout/components/discounts-meta/index.js @@ -11,10 +11,8 @@ import TotalsWrapper from '../totals-wrapper'; const slotName = '__experimentalDiscountsMeta'; -const { - Fill: ExperimentalDiscountsMeta, - Slot: DiscountsMetaSlot, -} = createSlotFill( slotName ); +const { Fill: ExperimentalDiscountsMeta, Slot: DiscountsMetaSlot } = + createSlotFill( slotName ); const Slot = ( { className, extensions, cart, context } ) => { const { fills } = useSlot( slotName ); diff --git a/plugins/woocommerce-blocks/packages/checkout/components/order-meta/index.js b/plugins/woocommerce-blocks/packages/checkout/components/order-meta/index.js index 7c86bc632ee..39c7a096107 100644 --- a/plugins/woocommerce-blocks/packages/checkout/components/order-meta/index.js +++ b/plugins/woocommerce-blocks/packages/checkout/components/order-meta/index.js @@ -11,9 +11,8 @@ import TotalsWrapper from '../totals-wrapper'; const slotName = '__experimentalOrderMeta'; -const { Fill: ExperimentalOrderMeta, Slot: OrderMetaSlot } = createSlotFill( - slotName -); +const { Fill: ExperimentalOrderMeta, Slot: OrderMetaSlot } = + createSlotFill( slotName ); const Slot = ( { className, extensions, cart, context } ) => { const { fills } = useSlot( slotName ); diff --git a/plugins/woocommerce-blocks/packages/checkout/filter-registry/index.ts b/plugins/woocommerce-blocks/packages/checkout/filter-registry/index.ts index 854ddc510cf..da3674d9269 100644 --- a/plugins/woocommerce-blocks/packages/checkout/filter-registry/index.ts +++ b/plugins/woocommerce-blocks/packages/checkout/filter-registry/index.ts @@ -49,8 +49,7 @@ export const __experimentalRegisterCheckoutFilters = ( deprecated( 'snackbarNotices', { alternative: 'snackbarNoticeVisibility', plugin: 'WooCommerce Blocks', - link: - 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4417', + link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4417', } ); } @@ -63,8 +62,7 @@ export const __experimentalRegisterCheckoutFilters = ( deprecated( 'couponName', { alternative: 'coupons', plugin: 'WooCommerce Blocks', - link: - 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/bb921d21f42e21f38df2b1c87b48e07aa4cb0538/docs/extensibility/available-filters.md#coupons', + link: 'https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/bb921d21f42e21f38df2b1c87b48e07aa4cb0538/docs/extensibility/available-filters.md#coupons', } ); } diff --git a/plugins/woocommerce-blocks/packages/prices/utils/price.ts b/plugins/woocommerce-blocks/packages/prices/utils/price.ts index 40b76974de3..54a7779d744 100644 --- a/plugins/woocommerce-blocks/packages/prices/utils/price.ts +++ b/plugins/woocommerce-blocks/packages/prices/utils/price.ts @@ -178,13 +178,8 @@ export const formatPrice = ( const currency: Currency = getCurrency( currencyData ); - const { - minorUnit, - prefix, - suffix, - decimalSeparator, - thousandSeparator, - } = currency; + const { minorUnit, prefix, suffix, decimalSeparator, thousandSeparator } = + currency; const formattedPrice: number = priceInt / 10 ** minorUnit; diff --git a/plugins/woocommerce-blocks/storybook/custom-controls/currency.ts b/plugins/woocommerce-blocks/storybook/custom-controls/currency.ts index ce6b175a615..2c1d39e8f1f 100644 --- a/plugins/woocommerce-blocks/storybook/custom-controls/currency.ts +++ b/plugins/woocommerce-blocks/storybook/custom-controls/currency.ts @@ -25,15 +25,13 @@ export const currencies: Record< string, Currency > = { }, } as const; -export const currenciesAPIShape: Record< - string, - CurrencyResponse -> = Object.fromEntries( - Object.entries( currencies ).map( ( [ key, value ] ) => [ - key, - snakecaseKeys( value ), - ] ) -); +export const currenciesAPIShape: Record< string, CurrencyResponse > = + Object.fromEntries( + Object.entries( currencies ).map( ( [ key, value ] ) => [ + key, + snakecaseKeys( value ), + ] ) + ); export const currencyControl = { control: 'select', diff --git a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/best-selling-products.fixture.json b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/best-selling-products.fixture.json index 83be6820f4d..592c5ded3ea 100644 --- a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/best-selling-products.fixture.json +++ b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/best-selling-products.fixture.json @@ -1 +1,4 @@ -{"title":"Best Selling Products Block","pageContent":""} \ No newline at end of file +{ + "title": "Best Selling Products Block", + "pageContent": "" +} diff --git a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/featured-category.fixture.json b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/featured-category.fixture.json index 60f0ae7b0d9..b6c77eb3381 100644 --- a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/featured-category.fixture.json +++ b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/featured-category.fixture.json @@ -1 +1,4 @@ -{"title":"Featured Category Block","pageContent":""} \ No newline at end of file +{ + "title": "Featured Category Block", + "pageContent": "" +} diff --git a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/hand-picked-products.fixture.json b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/hand-picked-products.fixture.json index 907b84ea5ec..4b2f1de3f43 100644 --- a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/hand-picked-products.fixture.json +++ b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/hand-picked-products.fixture.json @@ -1 +1,4 @@ -{"title":"Hand-picked Products Block","pageContent":""} \ No newline at end of file +{ + "title": "Hand-picked Products Block", + "pageContent": "" +} diff --git a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/newest-products.fixture.json b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/newest-products.fixture.json index 5ffe302fc75..d3aa952f8b7 100644 --- a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/newest-products.fixture.json +++ b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/newest-products.fixture.json @@ -1 +1,4 @@ -{"title":"Newest Products Block","pageContent":""} \ No newline at end of file +{ + "title": "Newest Products Block", + "pageContent": "" +} diff --git a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/product-categories-list.fixture.json b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/product-categories-list.fixture.json index 7e6a4d9e3bb..6f6baf27aef 100644 --- a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/product-categories-list.fixture.json +++ b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/product-categories-list.fixture.json @@ -1 +1,4 @@ -{"title":"Product Categories List Block","pageContent":""} \ No newline at end of file +{ + "title": "Product Categories List Block", + "pageContent": "" +} diff --git a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/top-rated-products.fixture.json b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/top-rated-products.fixture.json index 4adb6788563..a3190e493b4 100644 --- a/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/top-rated-products.fixture.json +++ b/plugins/woocommerce-blocks/tests/e2e/config/custom-matchers/__fixtures__/top-rated-products.fixture.json @@ -1 +1,4 @@ -{"title":"Top Rated Products Block","pageContent":""} \ No newline at end of file +{ + "title": "Top Rated Products Block", + "pageContent": "" +} diff --git a/plugins/woocommerce-blocks/tests/e2e/config/setup.js b/plugins/woocommerce-blocks/tests/e2e/config/setup.js index 10a2684115d..3b57bb981a1 100644 --- a/plugins/woocommerce-blocks/tests/e2e/config/setup.js +++ b/plugins/woocommerce-blocks/tests/e2e/config/setup.js @@ -49,14 +49,8 @@ module.exports = async ( globalConfig ) => { enablePaymentGateways(), setupPageSettings(), ] ).catch( console.log ); - const [ - taxes, - coupons, - categories, - tags, - shippingZones, - attributes, - ] = results; + const [ taxes, coupons, categories, tags, shippingZones, attributes ] = + results; // Create products after categories. const products = await createProducts( categories, tags, attributes ); diff --git a/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-data.js b/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-data.js index af7ae386864..382a03c6732 100644 --- a/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-data.js +++ b/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-data.js @@ -152,14 +152,12 @@ const Products = () => [ downloads: [ { name: 'Woo Single', - file: - 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', + file: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', }, ], images: [ { - src: - 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', + src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', }, ], categories: [ 'Music' ], @@ -172,8 +170,7 @@ const Products = () => [ downloadable: false, images: [ { - src: - 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', + src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', }, ], attributes: [ @@ -194,8 +191,7 @@ const Products = () => [ downloadable: false, images: [ { - src: - 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', + src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', }, ], attributes: [ @@ -216,14 +212,12 @@ const Products = () => [ downloads: [ { name: 'Woo Single 2', - file: - 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', + file: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', }, ], images: [ { - src: - 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', + src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', }, ], categories: [ 'Music' ], @@ -238,14 +232,12 @@ const Products = () => [ downloads: [ { name: 'Woo Single 2', - file: - 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', + file: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', }, ], images: [ { - src: - 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', + src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', }, ], categories: [ 'Music' ], diff --git a/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-loaders.js b/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-loaders.js index a343985336b..f734d8c0b74 100644 --- a/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-loaders.js +++ b/plugins/woocommerce-blocks/tests/e2e/fixtures/fixture-loaders.js @@ -1,8 +1,8 @@ /** * External dependencies */ -const WooCommerceRestApi = require( '@woocommerce/woocommerce-rest-api' ) - .default; +const WooCommerceRestApi = + require( '@woocommerce/woocommerce-rest-api' ).default; const glob = require( 'glob-promise' ); const { dirname } = require( 'path' ); const { readJson } = require( 'fs-extra' ); diff --git a/plugins/woocommerce-blocks/tests/e2e/specs/backend/active-filters.test.js b/plugins/woocommerce-blocks/tests/e2e/specs/backend/active-filters.test.js index 157a0c31f08..6c81df7e098 100644 --- a/plugins/woocommerce-blocks/tests/e2e/specs/backend/active-filters.test.js +++ b/plugins/woocommerce-blocks/tests/e2e/specs/backend/active-filters.test.js @@ -50,9 +50,7 @@ describe( `${ block.name } Block`, () => { await page.click( '.components-toolbar button[aria-label="Heading 6"]' ); - await expect( - page - ).toMatchElement( + await expect( page ).toMatchElement( `.wp-block[data-type="${ block.slug }"] h6 textarea`, { text: 'New Title' } ); diff --git a/plugins/woocommerce-blocks/tests/e2e/specs/backend/attribute-filter.test.js b/plugins/woocommerce-blocks/tests/e2e/specs/backend/attribute-filter.test.js index 7b1eebe40a7..a5b4678b6bf 100644 --- a/plugins/woocommerce-blocks/tests/e2e/specs/backend/attribute-filter.test.js +++ b/plugins/woocommerce-blocks/tests/e2e/specs/backend/attribute-filter.test.js @@ -62,9 +62,7 @@ describe( `${ block.name } Block`, () => { await page.click( '.components-toolbar button[aria-label="Heading 6"]' ); - await expect( - page - ).toMatchElement( + await expect( page ).toMatchElement( `.wp-block[data-type="${ block.slug }"] h6 textarea`, { text: 'New Title' } ); diff --git a/plugins/woocommerce-blocks/tests/e2e/specs/backend/price-filter.test.js b/plugins/woocommerce-blocks/tests/e2e/specs/backend/price-filter.test.js index 7a9750a08ca..6acd0887d0e 100644 --- a/plugins/woocommerce-blocks/tests/e2e/specs/backend/price-filter.test.js +++ b/plugins/woocommerce-blocks/tests/e2e/specs/backend/price-filter.test.js @@ -53,9 +53,7 @@ describe( `${ block.name } Block`, () => { await page.click( '.components-toolbar button[aria-label="Heading 6"]' ); - await expect( - page - ).toMatchElement( + await expect( page ).toMatchElement( `.wp-block[data-type="${ block.slug }"] h6 textarea`, { text: 'New Title' } ); @@ -67,9 +65,7 @@ describe( `${ block.name } Block`, () => { await page.click( '.components-toolbar button[aria-label="Heading 3"]' ); - await expect( - page - ).not.toMatchElement( + await expect( page ).not.toMatchElement( `.wp-block[data-type="${ block.slug }"] h6 textarea`, { text: 'New Title' } ); diff --git a/plugins/woocommerce-blocks/tests/e2e/specs/frontend/legacy-template-blocks.test.ts b/plugins/woocommerce-blocks/tests/e2e/specs/frontend/legacy-template-blocks.test.ts index 584ab749e5a..0cd13d14589 100644 --- a/plugins/woocommerce-blocks/tests/e2e/specs/frontend/legacy-template-blocks.test.ts +++ b/plugins/woocommerce-blocks/tests/e2e/specs/frontend/legacy-template-blocks.test.ts @@ -55,10 +55,8 @@ describe( 'Classic Template blocks', () => { await page.waitForSelector( productArchivePage.productsList ); await page.waitForSelector( productArchivePage.resultsCount ); - const { - displayedCount, - shouldHavePaginationUI, - } = await extractPaginationData(); + const { displayedCount, shouldHavePaginationUI } = + await extractPaginationData(); if ( shouldHavePaginationUI ) { await expect( page ).toMatchElement( @@ -93,10 +91,8 @@ describe( 'Classic Template blocks', () => { await page.waitForSelector( productArchivePage.productsList ); await page.waitForSelector( productArchivePage.resultsCount ); - const { - displayedCount, - shouldHavePaginationUI, - } = await extractPaginationData(); + const { displayedCount, shouldHavePaginationUI } = + await extractPaginationData(); if ( shouldHavePaginationUI ) { await expect( page ).toMatchElement( @@ -131,10 +127,8 @@ describe( 'Classic Template blocks', () => { await page.waitForSelector( productArchivePage.productsList ); await page.waitForSelector( productArchivePage.resultsCount ); - const { - displayedCount, - shouldHavePaginationUI, - } = await extractPaginationData(); + const { displayedCount, shouldHavePaginationUI } = + await extractPaginationData(); if ( shouldHavePaginationUI ) { await expect( page ).toMatchElement( diff --git a/plugins/woocommerce-blocks/tests/e2e/specs/shopper/cart-checkout/account.test.js b/plugins/woocommerce-blocks/tests/e2e/specs/shopper/cart-checkout/account.test.js index f49d30c85d9..89943d6400a 100644 --- a/plugins/woocommerce-blocks/tests/e2e/specs/shopper/cart-checkout/account.test.js +++ b/plugins/woocommerce-blocks/tests/e2e/specs/shopper/cart-checkout/account.test.js @@ -52,8 +52,7 @@ describe( 'Shopper → Checkout → Account', () => { //Enable shoppers to sign up at checkout option. // eslint-disable-next-line jest/no-standalone-expect await expect( page ).toClick( 'label', { - text: - 'Allow shoppers to sign up for a user account during checkout', + text: 'Allow shoppers to sign up for a user account during checkout', } ); await saveOrPublish(); await merchant.logout(); diff --git a/plugins/woocommerce-blocks/tests/e2e/utils.js b/plugins/woocommerce-blocks/tests/e2e/utils.js index 74471db59af..b81f23da141 100644 --- a/plugins/woocommerce-blocks/tests/e2e/utils.js +++ b/plugins/woocommerce-blocks/tests/e2e/utils.js @@ -44,8 +44,7 @@ export const DEFAULT_TIMEOUT = 30000; const SELECTORS = { canvas: 'iframe[name="editor-canvas"]', inserter: { - search: - '.components-search-control__input,.block-editor-inserter__search input,.block-editor-inserter__search-input,input.block-editor-inserter__search', + search: '.components-search-control__input,.block-editor-inserter__search input,.block-editor-inserter__search-input,input.block-editor-inserter__search', }, templatesListTable: { actionsContainer: '.edit-site-list-table__actions', diff --git a/plugins/woocommerce-blocks/tests/js/jestPreprocess.js b/plugins/woocommerce-blocks/tests/js/jestPreprocess.js index 40bf8c2621e..9baa877eae3 100644 --- a/plugins/woocommerce-blocks/tests/js/jestPreprocess.js +++ b/plugins/woocommerce-blocks/tests/js/jestPreprocess.js @@ -6,6 +6,5 @@ const babelOptions = { ], }; -module.exports = require( 'babel-jest' ).default.createTransformer( - babelOptions -); +module.exports = + require( 'babel-jest' ).default.createTransformer( babelOptions ); diff --git a/plugins/woocommerce-blocks/tests/utils/shopper.js b/plugins/woocommerce-blocks/tests/utils/shopper.js index be2c75fff41..705449b549a 100644 --- a/plugins/woocommerce-blocks/tests/utils/shopper.js +++ b/plugins/woocommerce-blocks/tests/utils/shopper.js @@ -69,9 +69,7 @@ export const shopper = { await expect( page ).toMatchElement( 'span', { text: productTitle, } ); - await expect( - page - ).toMatchElement( + await expect( page ).toMatchElement( 'div.wc-block-components-order-summary-item__quantity', { text: quantity } ); diff --git a/plugins/woocommerce-blocks/tests/utils/taxes.ts b/plugins/woocommerce-blocks/tests/utils/taxes.ts index c3bf4a5e08f..f4ffedc3ce1 100644 --- a/plugins/woocommerce-blocks/tests/utils/taxes.ts +++ b/plugins/woocommerce-blocks/tests/utils/taxes.ts @@ -72,8 +72,8 @@ export async function getTaxesFromOrderSummaryPage( ) ) .filter( ( node ) => { - const taxLabel = node.getElementsByTagName( 'th' )[ 0 ] - .innerHTML; + const taxLabel = + node.getElementsByTagName( 'th' )[ 0 ].innerHTML; return taxRatesEval.some( // We need to remove the ":" on the end of the string before we compare ( taxRate ) => taxRate.name === taxLabel.slice( 0, -1 )