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

Commit

Permalink
Merge pull request #1 from woocommerce/trunk
Browse files Browse the repository at this point in the history
Fork update
  • Loading branch information
grogou authored Apr 30, 2021
2 parents 42beb9b + 4343b96 commit d8e6dab
Show file tree
Hide file tree
Showing 22 changed files with 231 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -17,7 +22,7 @@ const ProductSummary = ( {
className,
shortDescription = '',
fullDescription = '',
} ) => {
}: ProductSummaryProps ): JSX.Element | null => {
const source = shortDescription ? shortDescription : fullDescription;

if ( ! source ) {
Expand All @@ -34,10 +39,4 @@ const ProductSummary = ( {
);
};

ProductSummary.propTypes = {
className: PropTypes.string,
shortDescription: PropTypes.string,
fullDescription: PropTypes.string,
};

export default ProductSummary;
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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 ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 11 additions & 6 deletions assets/js/hocs/with-store-cart-api-hydration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -46,7 +51,7 @@ const useStoreCartApiHydration = () => {
if ( lastCartUpdateRaw ) {
const lastCartUpdate = parseFloat( lastCartUpdateRaw );
const cartGeneratedTimestamp = parseFloat(
cartData.current.generated_timestamp
cartData.generated_timestamp
);

const needsUpdateFromAPI =
Expand All @@ -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', [] );
}
Expand Down
7 changes: 6 additions & 1 deletion assets/js/settings/blocks/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
58 changes: 58 additions & 0 deletions docs/testing/releases/500.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion docs/testing/releases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- [4.9.1](./491.md)
- [5.0.0](./500.md)
63 changes: 22 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Loading

0 comments on commit d8e6dab

Please sign in to comment.