diff --git a/.gitattributes b/.gitattributes index 0db66b9617c..fe40586d798 100644 --- a/.gitattributes +++ b/.gitattributes @@ -28,4 +28,5 @@ /globals.d.ts export-ignore /tsconfig.json export-ignore /tsconfig.base.json export-ignore +/tsconfig.base export-ignore /webpack.config.js export-ignore diff --git a/assets/js/base/components/cart-checkout/product-summary/index.js b/assets/js/base/components/cart-checkout/product-summary/index.tsx similarity index 85% rename from assets/js/base/components/cart-checkout/product-summary/index.js rename to assets/js/base/components/cart-checkout/product-summary/index.tsx index 2503e5feebd..b6e32093f95 100644 --- a/assets/js/base/components/cart-checkout/product-summary/index.js +++ b/assets/js/base/components/cart-checkout/product-summary/index.tsx @@ -5,6 +5,11 @@ import PropTypes from 'prop-types'; import Summary from '@woocommerce/base-components/summary'; import { blocksConfig } from '@woocommerce/block-settings'; +interface ProductSummaryProps { + className?: string; + shortDescription?: string; + fullDescription?: string; +} /** * Returns an element containing a summary of the product. * @@ -17,7 +22,7 @@ const ProductSummary = ( { className, shortDescription = '', fullDescription = '', -} ) => { +}: ProductSummaryProps ): JSX.Element | null => { const source = shortDescription ? shortDescription : fullDescription; if ( ! source ) { @@ -34,10 +39,4 @@ const ProductSummary = ( { ); }; -ProductSummary.propTypes = { - className: PropTypes.string, - shortDescription: PropTypes.string, - fullDescription: PropTypes.string, -}; - export default ProductSummary; diff --git a/assets/js/base/components/summary/index.js b/assets/js/base/components/summary/index.tsx similarity index 80% rename from assets/js/base/components/summary/index.js rename to assets/js/base/components/summary/index.tsx index ab9499616f1..5dee7e5bf81 100644 --- a/assets/js/base/components/summary/index.js +++ b/assets/js/base/components/summary/index.tsx @@ -2,12 +2,19 @@ * External dependencies */ import { RawHTML, useMemo } from '@wordpress/element'; +import { WordCountType } from '@woocommerce/block-settings'; /** * Internal dependencies */ import { generateSummary } from './utils'; +interface SummaryProps { + className?: string; + source: string; + maxLength?: number; + countType?: WordCountType; +} /** * Summary component. * @@ -22,7 +29,7 @@ export const Summary = ( { maxLength = 15, countType = 'words', className = '', -} ) => { +}: SummaryProps ): JSX.Element => { const summaryText = useMemo( () => { return generateSummary( source, maxLength, countType ); }, [ source, maxLength, countType ] ); diff --git a/assets/js/base/context/providers/cart-checkout/checkout-state/constants.js b/assets/js/base/context/providers/cart-checkout/checkout-state/constants.js index 50b67db57a5..fc2d80a6568 100644 --- a/assets/js/base/context/providers/cart-checkout/checkout-state/constants.js +++ b/assets/js/base/context/providers/cart-checkout/checkout-state/constants.js @@ -15,10 +15,12 @@ export const STATUS = { AFTER_PROCESSING: 'after_processing', }; -const checkoutData = getSetting( 'checkoutData', { +const preloadedApiRequests = getSetting( 'preloadedApiRequests', {} ); +const checkoutData = { order_id: 0, customer_id: 0, -} ); + ...( preloadedApiRequests[ '/wc/store/checkout' ]?.body || {} ), +}; export const DEFAULT_STATE = { redirectUrl: '', diff --git a/assets/js/blocks/cart-checkout/checkout/checkout-order-error/index.js b/assets/js/blocks/cart-checkout/checkout/checkout-order-error/index.js index d3dc1cc2d3f..3e283360add 100644 --- a/assets/js/blocks/cart-checkout/checkout/checkout-order-error/index.js +++ b/assets/js/blocks/cart-checkout/checkout/checkout-order-error/index.js @@ -34,7 +34,13 @@ const cartItemErrorCodes = [ * checkout block. */ const CheckoutOrderError = () => { - const checkoutData = getSetting( 'checkoutData', {} ); + const preloadedApiRequests = getSetting( 'preloadedApiRequests', {} ); + const checkoutData = { + code: '', + message: '', + ...( preloadedApiRequests[ '/wc/store/checkout' ]?.body || {} ), + }; + const errorData = { code: checkoutData.code || 'unknown', message: diff --git a/assets/js/hocs/with-store-cart-api-hydration.js b/assets/js/hocs/with-store-cart-api-hydration.js index b3156742479..a618aaa99fc 100644 --- a/assets/js/hocs/with-store-cart-api-hydration.js +++ b/assets/js/hocs/with-store-cart-api-hydration.js @@ -17,13 +17,18 @@ import { LAST_CART_UPDATE_TIMESTAMP_KEY } from '../data/cart/constants'; * Makes cart data available without an API request to wc/store/cart/. */ const useStoreCartApiHydration = () => { - const cartData = useRef( getSetting( 'cartData' ) ); + const preloadedApiRequests = useRef( + getSetting( 'preloadedApiRequests', {} ) + ); const { setIsCartDataStale } = useDispatch( CART_STORE_KEY ); useSelect( ( select, registry ) => { - if ( ! cartData.current ) { + const cartData = preloadedApiRequests.current[ '/wc/store/cart' ]?.body; + + if ( ! cartData ) { return; } + const { isResolving, hasFinishedResolution, isCartDataStale } = select( CART_STORE_KEY ); @@ -46,7 +51,7 @@ const useStoreCartApiHydration = () => { if ( lastCartUpdateRaw ) { const lastCartUpdate = parseFloat( lastCartUpdateRaw ); const cartGeneratedTimestamp = parseFloat( - cartData.current.generated_timestamp + cartData.generated_timestamp ); const needsUpdateFromAPI = @@ -72,10 +77,10 @@ const useStoreCartApiHydration = () => { ! hasFinishedResolution( 'getCartData', [] ) ) { startResolution( 'getCartData', [] ); - if ( cartData.current?.code?.includes( 'error' ) ) { - receiveError( cartData.current ); + if ( cartData?.code?.includes( 'error' ) ) { + receiveError( cartData ); } else { - receiveCart( cartData.current ); + receiveCart( cartData ); } finishResolution( 'getCartData', [] ); } diff --git a/assets/js/settings/blocks/constants.ts b/assets/js/settings/blocks/constants.ts index 8aff413995f..e36bf731cc8 100644 --- a/assets/js/settings/blocks/constants.ts +++ b/assets/js/settings/blocks/constants.ts @@ -3,12 +3,17 @@ */ import { getSetting, STORE_PAGES } from '@woocommerce/settings'; +export type WordCountType = + | 'words' + | 'characters_excluding_spaces' + | 'characters_including_spaces'; + interface WcBlocksConfig { buildPhase: number; pluginUrl: string; productCount: number; restApiRoutes: Record< string, string[] >; - wordCountType: string; + wordCountType: WordCountType; } export const blocksConfig = getSetting( 'wcBlocksConfig', { diff --git a/docs/testing/releases/500.md b/docs/testing/releases/500.md new file mode 100644 index 00000000000..e9ac2ffec91 --- /dev/null +++ b/docs/testing/releases/500.md @@ -0,0 +1,58 @@ +## Testing notes and ZIP for release 5.0.0 + +Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-gutenberg-products-block/files/6392862/woocommerce-gutenberg-products-block.zip) + +## Feature plugin only + +### General smoke testing + +The following are related to various changes impacting existing flows, so smoke testing is needed to verify there are no regressions: + +- Confirm blocks are available in the editor, and confirm insertion works for the All Products Block, Cart and Checkout Blocks specifically. +- Place orders via the Checkout block starting from the Cart Block & shortcode +- During checkout, submit the form without filling out a required field. Confirm validation messages are displayed. +- Fix the validation warnings and submit the order successfully. + +### Remove work-around to load our stylesheets after wp-edit-post #4097 + +![Screenshot](https://user-images.githubusercontent.com/3616980/115833554-78ec8600-a414-11eb-8828-c52ec427fa79.png) + +Open the Checkout block in the editor and verify the Country/Region selector has the same height as the City field next to it, rounded corners, etc. + +### Prevent unwanted parts of address being displayed #4038 + +1. Add an item to the cart. +2. Go to the shortcode cart - use the shipping calculator to enter a US address. (State: California, City: Beverly Hills, ZIP: 90210) +3. Proceed to checkout and successfully complete. If you get errors, ensure the form is filled properly, and submit again (This is a known issue in #3975) +4. Add another item to the cart and go back to the shortcode cart, change your address on the shipping calculator to a Polish one (or any other that doesn't use states). (City: Gdansk, Postcode: 80-000) +5. Go to the cart Block and see there is no CA shown in the address in the shipping totals area. + +### Rest API batching support #4075 + +1. Open up the browser console and go to the Network tab. Filter by XHR requests. +2. Smoke test add to cart functionality from the all products block. +3. After adding to cart, confirm the network tab shows a request to the /batch endpoint. +4. Confirm that each time you add to cart, a new batch/ request is made. + +Optionally, because this is difficult to achieve, if you tab to an add to cart button and hover over another add to cart button with your mouse, hit enter and then click the 2nd add to cart button (we want to trigger 2 add to cart events in quick succession). After a very short delay you should see ONE batch request, but both items should be added to the cart. + +### Deprecate the woocommerce_shared_settings hook #4092 + +1. Running WooCommerce 5.2, visit the admin Dashboard. +2. Open up the browser error console. +3. A warning will be shown stating that the woocommerce_shared_settings hook is deprecated. +4. Again running WooCommerce 5.2, go to the Checkout page (running the checkout block). The same notice will be shown in the console. + +### Change checkoutAllowsGuest to the correct value. #4146 + +1. In WooCommerce Settings > Accounts and Privacy, prevent customers from placing orders without an account, Allow them to create an account during checkout: + +![Settings](https://user-images.githubusercontent.com/6165348/116407897-22bf7e80-a82a-11eb-982f-03d09dcc0e1f.png) + +2. Allow customers to create account during checkout by setting this option within the Checkout Block: + +![Block](https://user-images.githubusercontent.com/6165348/116408030-4682c480-a82a-11eb-8bc4-b2b5c9bf3065.png) + +3. On the frontend, as a logged-out guest, add an item to your cart and go to the Block Checkout. +4. You shouldn't see a "Create an Account?" checkbox on Checkout. +5. When placing an order, an account will be created for you. diff --git a/docs/testing/releases/README.md b/docs/testing/releases/README.md index a109bba7882..1a98eddb399 100644 --- a/docs/testing/releases/README.md +++ b/docs/testing/releases/README.md @@ -28,4 +28,5 @@ Every release includes specific testing instructions for new features and bug fi - [4.7.0](./470.md) - [4.8.0](./480.md) - [4.9.0](./490.md) -- [4.9.1](./491.md) \ No newline at end of file +- [4.9.1](./491.md) +- [5.0.0](./500.md) diff --git a/package-lock.json b/package-lock.json index 6f5530715a0..a5200bf9797 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@woocommerce/block-library", - "version": "5.0.0-dev", + "version": "5.1.0-dev", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -3659,9 +3659,9 @@ "dev": true }, "@testing-library/dom": { - "version": "7.30.3", - "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-7.30.3.tgz", - "integrity": "sha512-7JhIg2MW6WPwyikH2iL3o7z+FTVgSOd2jqCwTAHqK7Qal2gRRYiUQyURAxtbK9VXm/UTyG9bRihv8C5Tznr2zw==", + "version": "7.30.4", + "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-7.30.4.tgz", + "integrity": "sha512-GObDVMaI4ARrZEXaRy4moolNAxWPKvEYNV/fa6Uc2eAzR/t4otS6A7EhrntPBIQLeehL9DbVhscvvv7gd6hWqA==", "dev": true, "requires": { "@babel/code-frame": "^7.10.4", @@ -3675,9 +3675,9 @@ } }, "@testing-library/jest-dom": { - "version": "5.11.10", - "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.11.10.tgz", - "integrity": "sha512-FuKiq5xuk44Fqm0000Z9w0hjOdwZRNzgx7xGGxQYepWFZy+OYUMOT/wPI4nLYXCaVltNVpU1W/qmD88wLWDsqQ==", + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.12.0.tgz", + "integrity": "sha512-N9Y82b2Z3j6wzIoAqajlKVF1Zt7sOH0pPee0sUHXHc5cv2Fdn23r+vpWm0MBBoGJtPOly5+Bdx1lnc3CD+A+ow==", "dev": true, "requires": { "@babel/runtime": "^7.9.2", @@ -3742,9 +3742,9 @@ } }, "@testing-library/react": { - "version": "11.2.5", - "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-11.2.5.tgz", - "integrity": "sha512-yEx7oIa/UWLe2F2dqK0FtMF9sJWNXD+2PPtp39BvE0Kh9MJ9Kl0HrZAgEuhUJR+Lx8Di6Xz+rKwSdEPY2UV8ZQ==", + "version": "11.2.6", + "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-11.2.6.tgz", + "integrity": "sha512-TXMCg0jT8xmuU8BkKMtp8l7Z50Ykew5WNX8UoIKTaLFwKkP2+1YDhOLA2Ga3wY4x29jyntk7EWfum0kjlYiSjQ==", "dev": true, "requires": { "@babel/runtime": "^7.12.5", @@ -3752,9 +3752,9 @@ } }, "@testing-library/react-hooks": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@testing-library/react-hooks/-/react-hooks-5.1.0.tgz", - "integrity": "sha512-ChRyyA14e0CeVkWGp24v8q/IiWUqH+B8daRx4lGZme4dsudmMNWz+Qo2Q2NzbD2O5rAVXh2hSbS/KTKeqHYhkw==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@testing-library/react-hooks/-/react-hooks-5.1.2.tgz", + "integrity": "sha512-jwhtDYZ5gQUIX8cmVCVdtwNvuF5EiCOWjokRlTV+o/V0GdtRZDykUllL1OXq5PS4+J33wGLNQeeWzEHcWrH7tg==", "dev": true, "requires": { "@babel/runtime": "^7.12.5", @@ -3970,9 +3970,9 @@ } }, "@types/jest": { - "version": "26.0.20", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.20.tgz", - "integrity": "sha512-9zi2Y+5USJRxd0FsahERhBwlcvFh6D2GLQnY2FH2BzK8J9s9omvNHIbvABwIluXa0fD8XVKMLTO0aOEuUfACAA==", + "version": "26.0.23", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.23.tgz", + "integrity": "sha512-ZHLmWMJ9jJ9PTiT58juykZpL7KjwJywFN3Rr2pTSkyQfydf/rk22yS7W8p5DaVUMQ2BQC7oYiU3FjbTM/mYrOA==", "dev": true, "requires": { "jest-diff": "^26.0.0", @@ -4412,25 +4412,6 @@ "csstype": "^2.2.0" } }, - "@types/wordpress__notices": { - "version": "1.5.4", - "resolved": "https://registry.npmjs.org/@types/wordpress__notices/-/wordpress__notices-1.5.4.tgz", - "integrity": "sha512-JkWWwukEvv2o8xzyYXi5iveMgUnPZXIgQfw0u/IQkSZE8+1XTJgokLwo3Ks5PrWHEzlPCZXWQXQsGeShdoOkyQ==", - "requires": { - "@types/react": "*", - "@types/wordpress__data": "*" - } - }, - "@types/wordpress__rich-text": { - "version": "3.4.5", - "resolved": "https://registry.npmjs.org/@types/wordpress__rich-text/-/wordpress__rich-text-3.4.5.tgz", - "integrity": "sha512-NMCq//2C9XBLmbYItJVdbWGkB8paoMjSNwiDu8phujQJ0pKhRFJPlvwdfVfuImgfSoK7hO9LnK2QyIUSV3OPzg==", - "requires": { - "@types/react": "*", - "@types/wordpress__data": "*", - "@types/wordpress__rich-text": "*" - } - }, "@types/wordpress__keycodes": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/@types/wordpress__keycodes/-/wordpress__keycodes-2.3.1.tgz", @@ -9202,14 +9183,14 @@ "dev": true }, "autoprefixer": { - "version": "10.2.3", - "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.2.3.tgz", - "integrity": "sha512-vlz+iv+EnLkVaTgX8wApfYzmK3LUfK8Z9XAnmflzxMy/+oFuNK8fVGQV79SOpBv4jxk2YQJimw4hXIKZ29570A==", + "version": "10.2.5", + "resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.2.5.tgz", + "integrity": "sha512-7H4AJZXvSsn62SqZyJCP+1AWwOuoYpUfK6ot9vm0e87XD6mT8lDywc9D9OTJPMULyGcvmIxzTAMeG2Cc+YX+fA==", "dev": true, "requires": { - "browserslist": "^4.16.1", - "caniuse-lite": "^1.0.30001178", - "colorette": "^1.2.1", + "browserslist": "^4.16.3", + "caniuse-lite": "^1.0.30001196", + "colorette": "^1.2.2", "fraction.js": "^4.0.13", "normalize-range": "^0.1.2", "postcss-value-parser": "^4.1.0" diff --git a/package.json b/package.json index 558c9c72ad4..cccbe9bf57f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@woocommerce/block-library", "title": "WooCommerce Blocks", "author": "Automattic", - "version": "5.0.0-dev", + "version": "5.1.0-dev", "description": "WooCommerce blocks for the Gutenberg editor.", "homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/", "keywords": [ @@ -84,20 +84,20 @@ "@storybook/addon-viewport": "6.1.18", "@storybook/addons": "6.1.18", "@storybook/react": "6.1.18", - "@testing-library/jest-dom": "5.11.10", - "@testing-library/react": "11.2.5", - "@testing-library/react-hooks": "5.1.0", + "@testing-library/jest-dom": "5.12.0", + "@testing-library/react": "11.2.6", + "@testing-library/react-hooks": "5.1.2", "@testing-library/user-event": "12.8.3", "@types/classnames": "2.2.11", - "@types/dinero.js": "^1.6.5", + "@types/dinero.js": "1.6.5", "@types/gtag.js": "0.0.4", - "@types/jest": "26.0.20", + "@types/jest": "26.0.23", "@types/lodash": "4.14.168", "@types/react": "16.14.5", "@types/wordpress__data": "4.6.9", "@types/wordpress__data-controls": "1.0.4", "@types/wordpress__element": "2.4.1", - "@types/wordpress__keycodes": "^2.3.1", + "@types/wordpress__keycodes": "2.3.1", "@typescript-eslint/eslint-plugin": "4.14.1", "@typescript-eslint/parser": "4.14.1", "@woocommerce/api": "0.1.2", @@ -120,7 +120,7 @@ "@wordpress/i18n": "3.15.0", "@wordpress/is-shallow-equal": "3.0.1", "@wordpress/scripts": "13.0.1", - "autoprefixer": "10.2.3", + "autoprefixer": "10.2.5", "axios": "0.21.1", "babel-plugin-transform-async-generator-functions": "6.24.1", "babel-plugin-transform-object-rest-spread": "6.26.0", diff --git a/readme.txt b/readme.txt index c096a747bd6..24ffcb2f679 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks Requires at least: 5.5 Tested up to: 5.7 Requires PHP: 7.0 -Stable tag: 5.0.0-dev +Stable tag: 5.0.0 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -85,6 +85,23 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/ == Changelog == += 5.0.0 - 2021-04-28 = + +#### Enhancements + +- Added support to the Store API for batching requests. This allows multiple POST requests to be made at once to reduce the number of separate requests being made to the API. ([4075](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4075)) + +#### Bug Fixes + +- Prevent parts of old addresses being displayed in the shipping calculator when changing countries. ([4038](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4038)) + +#### Refactor + +- Rename onCheckoutBeforeProcessing to onCheckoutValidationBeforeProcessing. +- Switched to `rest_preload_api_request` for API hydration in cart and checkout blocks. ([4090](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4090)) +- Introduced AssetsController and BlockTypesController classes (which replace Assets.php and Library.php). ([4094](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4094)) +- Replaced usage of the `woocommerce_shared_settings` hook. This will be deprecated. ([4092](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4092)) + = 4.9.1 - 2021-04-13 = #### Bug Fixes diff --git a/src/Assets.php b/src/Assets.php index 47336929981..7eeeeadd70e 100644 --- a/src/Assets.php +++ b/src/Assets.php @@ -7,7 +7,7 @@ /** * Assets class. * - * @deprecated $VID:$ This class will be removed in a future release. This has been replaced by AssetsController. + * @deprecated 5.0.0 This class will be removed in a future release. This has been replaced by AssetsController. * @internal */ class Assets { @@ -16,63 +16,63 @@ class Assets { * Initialize class features on init. * * @since 2.5.0 - * @deprecated $VID:$ + * @deprecated 5.0.0 */ public static function init() { - _deprecated_function( 'Assets::init', '$VID:$' ); + _deprecated_function( 'Assets::init', '5.0.0' ); } /** * Register block scripts & styles. * * @since 2.5.0 - * @deprecated $VID:$ + * @deprecated 5.0.0 */ public static function register_assets() { - _deprecated_function( 'Assets::register_assets', '$VID:$' ); + _deprecated_function( 'Assets::register_assets', '5.0.0' ); } /** * Register the vendors style file. We need to do it after the other files * because we need to check if `wp-edit-post` has been enqueued. * - * @deprecated $VID:$ + * @deprecated 5.0.0 */ public static function enqueue_scripts() { - _deprecated_function( 'Assets::enqueue_scripts', '$VID:$' ); + _deprecated_function( 'Assets::enqueue_scripts', '5.0.0' ); } /** * Add body classes. * - * @deprecated $VID:$ + * @deprecated 5.0.0 * @param array $classes Array of CSS classnames. * @return array Modified array of CSS classnames. */ public static function add_theme_body_class( $classes = [] ) { - _deprecated_function( 'Assets::add_theme_body_class', '$VID:$' ); + _deprecated_function( 'Assets::add_theme_body_class', '5.0.0' ); return $classes; } /** * Add theme class to admin body. * - * @deprecated $VID:$ + * @deprecated 5.0.0 * @param array $classes String with the CSS classnames. * @return array Modified string of CSS classnames. */ public static function add_theme_admin_body_class( $classes = '' ) { - _deprecated_function( 'Assets::add_theme_admin_body_class', '$VID:$' ); + _deprecated_function( 'Assets::add_theme_admin_body_class', '5.0.0' ); return $classes; } /** * Adds a redirect field to the login form so blocks can redirect users after login. * - * @deprecated $VID:$ + * @deprecated 5.0.0 */ public static function redirect_to_field() { - _deprecated_function( 'Assets::redirect_to_field', '$VID:$' ); + _deprecated_function( 'Assets::redirect_to_field', '5.0.0' ); } /** diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index 7c771d034dd..f48b188e76b 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -197,15 +197,22 @@ protected function initialize_core_data() { * ->get( Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::class ) * ->add( $key, $value ) */ - $message = __( - 'The filter should not be used for assets registration. Please read woocommerce-gutenberg-products-block/docs/contributors/block-assets.md for more information on how to proceed.', - 'woo-gutenberg-products-block' - ); + $settings = apply_filters( 'woocommerce_shared_settings', $this->data ); - $settings = apply_filters_deprecated( 'woocommerce_shared_settings', [ $this->data ], '5.0.0', '', $message ); + // Surface a deprecation warning in the error console. + if ( has_filter( 'woocommerce_shared_settings' ) ) { + $error_handle = 'deprecated-shared-settings-error'; + $error_message = '`woocommerce_shared_settings` filter in Blocks is deprecated. See https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/trunk/docs/contributors/block-assets.md'; + // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter,WordPress.WP.EnqueuedResourceParameters.MissingVersion + wp_register_script( $error_handle, '' ); + wp_enqueue_script( $error_handle ); + wp_add_inline_script( + $error_handle, + sprintf( 'console.warn( "%s" );', $error_message ) + ); + } - // note this WILL wipe any data already registered to these keys because - // they are protected. + // note this WILL wipe any data already registered to these keys because they are protected. $this->data = array_replace_recursive( $settings, $this->get_core_data() ); } @@ -272,6 +279,20 @@ public function add( $key, $data, $check_key_exists = false ) { } } + /** + * Hydrate from API. + * + * @param string $path REST API path to preload. + */ + public function hydrate_api_request( $path ) { + if ( ! isset( $this->data['preloadedApiRequests'] ) ) { + $this->data['preloadedApiRequests'] = []; + } + if ( ! isset( $this->data['preloadedApiRequests'][ $path ] ) ) { + $this->data['preloadedApiRequests'] = rest_preload_api_request( $this->data['preloadedApiRequests'], $path ); + } + } + /** * Adds a page permalink to the data registry. * diff --git a/src/AssetsController.php b/src/AssetsController.php index 481f0da1e5d..99763cd7a01 100644 --- a/src/AssetsController.php +++ b/src/AssetsController.php @@ -8,7 +8,7 @@ /** * AssetsController class. * - * @since $VID:$ + * @since 5.0.0 * @internal */ final class AssetsController { @@ -37,14 +37,13 @@ protected function init() { add_action( 'init', array( $this, 'register_assets' ) ); add_action( 'body_class', array( $this, 'add_theme_body_class' ), 1 ); add_action( 'admin_body_class', array( $this, 'add_theme_body_class' ), 1 ); - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); } /** * Register block scripts & styles. */ public function register_assets() { + $this->register_style( 'wc-block-vendors-style', plugins_url( $this->api->get_block_asset_build_path( 'vendors-style', 'css' ), __DIR__ ) ); $this->register_style( 'wc-block-editor', plugins_url( $this->api->get_block_asset_build_path( 'editor', 'css' ), __DIR__ ), array( 'wp-edit-blocks' ) ); $this->register_style( 'wc-block-style', plugins_url( $this->api->get_block_asset_build_path( 'style', 'css' ), __DIR__ ), array( 'wc-block-vendors-style' ) ); @@ -76,17 +75,6 @@ public function register_assets() { ); } - /** - * Register the vendors style file. We need to do it after the other files - * because we need to check if `wp-edit-post` has been enqueued. - */ - public function enqueue_scripts() { - // @todo Remove fix to load our stylesheets after editor CSS. - // See #3068 and #3898 for the rationale of this fix. It should be no - // longer necessary when the editor is loaded in an iframe (https://github.com/WordPress/gutenberg/issues/20797). - $this->register_style( 'wc-block-vendors-style', plugins_url( $this->api->get_block_asset_build_path( 'vendors-style', 'css' ), __DIR__ ), wp_style_is( 'wp-edit-post' ) ? [ 'wp-edit-post' ] : [] ); - } - /** * Add body classes to the frontend and within admin. * diff --git a/src/BlockTypes/Cart.php b/src/BlockTypes/Cart.php index 2346481063a..0d91b065797 100644 --- a/src/BlockTypes/Cart.php +++ b/src/BlockTypes/Cart.php @@ -159,9 +159,7 @@ protected function deep_sort_with_accents( $array ) { * Hydrate the cart block with data from the API. */ protected function hydrate_from_api() { - if ( ! $this->asset_data_registry->exists( 'cartData' ) ) { - $this->asset_data_registry->add( 'cartData', WC()->api->get_endpoint_data( '/wc/store/cart' ) ); - } + $this->asset_data_registry->hydrate_api_request( '/wc/store/cart' ); } /** diff --git a/src/BlockTypes/Checkout.php b/src/BlockTypes/Checkout.php index 9be500a3a49..906e11797a4 100644 --- a/src/BlockTypes/Checkout.php +++ b/src/BlockTypes/Checkout.php @@ -144,9 +144,23 @@ function() { true ); $this->asset_data_registry->add( 'baseLocation', wc_get_base_location(), true ); - $this->asset_data_registry->add( 'checkoutAllowsGuest', WC()->checkout()->is_registration_required(), true ); - $this->asset_data_registry->add( 'checkoutAllowsSignup', WC()->checkout()->is_registration_enabled(), true ); - $this->asset_data_registry->add( 'checkoutShowLoginReminder', 'yes' === get_option( 'woocommerce_enable_checkout_login_reminder' ), true ); + $this->asset_data_registry->add( + 'checkoutAllowsGuest', + false === filter_var( + WC()->checkout()->is_registration_required(), + FILTER_VALIDATE_BOOLEAN + ), + true + ); + $this->asset_data_registry->add( + 'checkoutAllowsSignup', + filter_var( + WC()->checkout()->is_registration_enabled(), + FILTER_VALIDATE_BOOLEAN + ), + true + ); + $this->asset_data_registry->add( 'checkoutShowLoginReminder', filter_var( get_option( 'woocommerce_enable_checkout_login_reminder' ), FILTER_VALIDATE_BOOLEAN ), true ); $this->asset_data_registry->add( 'displayCartPricesIncludingTax', 'incl' === get_option( 'woocommerce_tax_display_cart' ), true ); $this->asset_data_registry->add( 'displayItemizedTaxes', 'itemized' === get_option( 'woocommerce_tax_total_display' ), true ); $this->asset_data_registry->add( 'taxesEnabled', wc_tax_enabled(), true ); @@ -216,14 +230,10 @@ protected function hydrate_from_api() { // Controller and converted to exceptions. wc_print_notices(); - if ( ! $this->asset_data_registry->exists( 'cartData' ) ) { - $this->asset_data_registry->add( 'cartData', WC()->api->get_endpoint_data( '/wc/store/cart' ) ); - } - if ( ! $this->asset_data_registry->exists( 'checkoutData' ) ) { - add_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' ); - $this->asset_data_registry->add( 'checkoutData', WC()->api->get_endpoint_data( '/wc/store/checkout' ) ); - remove_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' ); - } + add_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' ); + $this->asset_data_registry->hydrate_api_request( '/wc/store/cart' ); + $this->asset_data_registry->hydrate_api_request( '/wc/store/checkout' ); + remove_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' ); } /** diff --git a/src/BlockTypesController.php b/src/BlockTypesController.php index 1dbec4d92ef..2cc2f7a183c 100644 --- a/src/BlockTypesController.php +++ b/src/BlockTypesController.php @@ -10,7 +10,7 @@ /** * BlockTypesController class. * - * @since $VID:$ + * @since 5.0.0 * @internal */ final class BlockTypesController { diff --git a/src/Library.php b/src/Library.php index ad5871db57b..673422d92d8 100644 --- a/src/Library.php +++ b/src/Library.php @@ -10,7 +10,7 @@ /** * Library class. * - * @deprecated $VID:$ This class will be removed in a future release. This has been replaced by BlockTypesController. + * @deprecated 5.0.0 This class will be removed in a future release. This has been replaced by BlockTypesController. * @internal */ class Library { @@ -18,27 +18,27 @@ class Library { /** * Initialize block library features. * - * @deprecated $VID:$ + * @deprecated 5.0.0 */ public static function init() { - _deprecated_function( 'Library::init', '$VID:$' ); + _deprecated_function( 'Library::init', '5.0.0' ); } /** * Register custom tables within $wpdb object. * - * @deprecated $VID:$ + * @deprecated 5.0.0 */ public static function define_tables() { - _deprecated_function( 'Library::define_tables', '$VID:$' ); + _deprecated_function( 'Library::define_tables', '5.0.0' ); } /** * Register blocks, hooking up assets and render functions as needed. * - * @deprecated $VID:$ + * @deprecated 5.0.0 */ public static function register_blocks() { - _deprecated_function( 'Library::register_blocks', '$VID:$' ); + _deprecated_function( 'Library::register_blocks', '5.0.0' ); } } diff --git a/src/Package.php b/src/Package.php index a1f9ab18a4c..cc4c812d892 100644 --- a/src/Package.php +++ b/src/Package.php @@ -106,7 +106,7 @@ public static function container( $reset = false ) { NewPackage::class, function ( $container ) { // leave for automated version bumping. - $version = '5.0.0-dev'; + $version = '5.0.0'; return new NewPackage( $version, dirname( __DIR__ ), diff --git a/tests/e2e/specs/backend/cart.test.js b/tests/e2e/specs/backend/cart.test.js index 35a19efbc3c..14a1a3864eb 100644 --- a/tests/e2e/specs/backend/cart.test.js +++ b/tests/e2e/specs/backend/cart.test.js @@ -96,6 +96,11 @@ describe( `${ block.name } Block`, () => { } ); it( 'shows empty cart when changing the view', async () => { + await page.waitForSelector( block.class ).catch( () => { + throw new Error( + `Could not find an element with class ${ block.class } - the block probably did not load correctly.` + ); + } ); await page.click( block.class ); await expect( page ).toMatchElement( '[hidden] .wc-block-cart__empty-cart__title' diff --git a/woocommerce-gutenberg-products-block.php b/woocommerce-gutenberg-products-block.php index dd40ee55690..5835a09e20b 100644 --- a/woocommerce-gutenberg-products-block.php +++ b/woocommerce-gutenberg-products-block.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce Blocks * Plugin URI: https://github.com/woocommerce/woocommerce-gutenberg-products-block * Description: WooCommerce blocks for the Gutenberg editor. - * Version: 5.0.0-dev + * Version: 5.1.0-dev * Author: Automattic * Author URI: https://woocommerce.com * Text Domain: woo-gutenberg-products-block