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

Use real previews for the Cart and Checkout blocks #2992

Merged
merged 3 commits into from Aug 13, 2020

Conversation

senadir
Copy link
Member

@senadir senadir commented Aug 11, 2020

Part of #2981

This PR uses real previews for the cart and checkout, something we can use because:
1- We have container queries so our blocks are responsive regardless of the screen size.
2- We don't have a select product step for those blocks, what you see is what you get.

Screenshots

Before:
image
image

Screen Shot 2020-08-11 at 1 47 46 PM

Screen Shot 2020-08-11 at 1 48 43 PM

After:
image
image

Screen Shot 2020-08-11 at 2 40 32 PM

Screen Shot 2020-08-11 at 2 40 38 PM

How to test the changes in this Pull Request:

  1. Preview the cart and checkout inside the block inserter.
  2. Make sure the block is not very long and overflowing.
  3. Make sure the changes didn't leak to the actual block or the editor block.

Changelog

Cart and Checkout will show a live preview inside the block inserter and style selector.

@senadir senadir added block: cart Issues related to the cart block. block: checkout Issues related to the checkout block. labels Aug 11, 2020
@senadir senadir added this to the 3.2.0 milestone Aug 11, 2020
@senadir senadir requested a review from a team as a code owner August 11, 2020 14:01
@senadir senadir self-assigned this Aug 11, 2020
@senadir senadir requested review from Aljullu and removed request for a team August 11, 2020 14:01
@github-actions
Copy link
Contributor

github-actions bot commented Aug 11, 2020

Size Change: +51 B (0%)

Total Size: 1.66 MB

Filename Size Change
build/cart.js 34.8 kB -42 B (0%)
build/checkout.js 40.2 kB -24 B (0%)
build/editor-legacy-rtl.css 13.8 kB +28 B (0%)
build/editor-legacy.css 13.8 kB +30 B (0%)
build/editor-rtl.css 14.1 kB +29 B (0%)
build/editor.css 14.1 kB +30 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/active-filters-frontend.js 8.76 kB 0 B
build/active-filters.js 8.8 kB 0 B
build/all-products-frontend.js 31.2 kB 0 B
build/all-products.js 35.6 kB 0 B
build/all-reviews-legacy.js 9.4 kB 0 B
build/all-reviews.js 9.73 kB 0 B
build/atomic-block-components/add-to-cart-frontend.js 8.88 kB 0 B
build/atomic-block-components/add-to-cart.js 7.46 kB 0 B
build/atomic-block-components/add-to-cart~atomic-block-components/button.js 3.17 kB 0 B
build/atomic-block-components/add-to-cart~atomic-block-components/image~atomic-block-components/title.js 335 B 0 B
build/atomic-block-components/button-frontend.js 2.02 kB 0 B
build/atomic-block-components/button.js 837 B 0 B
build/atomic-block-components/category-list-frontend.js 468 B 0 B
build/atomic-block-components/category-list.js 476 B 0 B
build/atomic-block-components/image-frontend.js 1.71 kB 0 B
build/atomic-block-components/image.js 1.15 kB 0 B
build/atomic-block-components/price-frontend.js 2.09 kB 0 B
build/atomic-block-components/price.js 2.11 kB 0 B
build/atomic-block-components/rating-frontend.js 524 B 0 B
build/atomic-block-components/rating.js 528 B 0 B
build/atomic-block-components/sale-badge-frontend.js 862 B 0 B
build/atomic-block-components/sale-badge.js 864 B 0 B
build/atomic-block-components/sku-frontend.js 389 B 0 B
build/atomic-block-components/sku.js 394 B 0 B
build/atomic-block-components/stock-indicator-frontend.js 568 B 0 B
build/atomic-block-components/stock-indicator.js 570 B 0 B
build/atomic-block-components/summary-frontend.js 918 B 0 B
build/atomic-block-components/summary.js 926 B 0 B
build/atomic-block-components/tag-list-frontend.js 466 B 0 B
build/atomic-block-components/tag-list.js 472 B 0 B
build/atomic-block-components/title-frontend.js 1.22 kB 0 B
build/atomic-block-components/title.js 1.06 kB 0 B
build/attribute-filter-frontend.js 18.1 kB 0 B
build/attribute-filter.js 12.4 kB 0 B
build/blocks-legacy.js 3.54 kB 0 B
build/blocks.js 3.54 kB 0 B
build/cart-frontend.js 66.5 kB 0 B
build/checkout-frontend.js 83.8 kB 0 B
build/featured-category-legacy.js 7.29 kB 0 B
build/featured-category.js 7.67 kB 0 B
build/featured-product-legacy.js 9.55 kB 0 B
build/featured-product.js 9.93 kB 0 B
build/handpicked-products-legacy.js 6.95 kB 0 B
build/handpicked-products.js 7.32 kB 0 B
build/price-filter-frontend.js 14.4 kB 0 B
build/price-filter.js 10.2 kB 0 B
build/product-best-sellers-legacy.js 7.03 kB 0 B
build/product-best-sellers.js 7.39 kB 0 B
build/product-categories-legacy.js 3.23 kB 0 B
build/product-categories.js 3.23 kB 0 B
build/product-category-legacy.js 7.94 kB 0 B
build/product-category.js 8.34 kB 0 B
build/product-new-legacy.js 7.19 kB 0 B
build/product-new.js 7.55 kB 0 B
build/product-on-sale-legacy.js 7.56 kB 0 B
build/product-on-sale.js 7.94 kB 0 B
build/product-search-legacy.js 3.17 kB 0 B
build/product-search.js 3.51 kB 0 B
build/product-tag-legacy.js 6.12 kB 0 B
build/product-tag.js 6.47 kB 0 B
build/product-top-rated-legacy.js 7.16 kB 0 B
build/product-top-rated.js 7.53 kB 0 B
build/products-by-attribute-legacy.js 7.92 kB 0 B
build/products-by-attribute.js 8.27 kB 0 B
build/reviews-by-category-legacy.js 11.4 kB 0 B
build/reviews-by-category.js 11.8 kB 0 B
build/reviews-by-product-legacy.js 12.9 kB 0 B
build/reviews-by-product.js 13.3 kB 0 B
build/reviews-frontend-legacy.js 8.43 kB 0 B
build/reviews-frontend.js 9.33 kB 0 B
build/single-product-frontend.js 34 kB 0 B
build/single-product.js 10.1 kB 0 B
build/style-legacy-rtl.css 16.8 kB 0 B
build/style-legacy.css 16.8 kB 0 B
build/style-rtl.css 17.5 kB 0 B
build/style.css 17.5 kB 0 B
build/vendors-legacy.js 367 kB 0 B
build/vendors-style-legacy-rtl.css 1.03 kB 0 B
build/vendors-style-legacy.css 1.03 kB 0 B
build/vendors-style-rtl.css 1.03 kB 0 B
build/vendors-style.css 1.03 kB 0 B
build/vendors.js 416 kB 0 B
build/vendors~atomic-block-components/price-frontend.js 5.65 kB 0 B
build/wc-blocks-data.js 7.09 kB 0 B
build/wc-blocks-middleware.js 931 B 0 B
build/wc-blocks-registry.js 2.28 kB 0 B
build/wc-payment-method-bacs.js 790 B 0 B
build/wc-payment-method-cheque.js 787 B 0 B
build/wc-payment-method-cod.js 875 B 0 B
build/wc-payment-method-paypal.js 831 B 0 B
build/wc-payment-method-stripe.js 11.9 kB 0 B
build/wc-settings.js 2.14 kB 0 B
build/wc-shared-context.js 1.53 kB 0 B
build/wc-shared-hocs.js 1.66 kB 0 B

compressed-size-action

@@ -1,3 +1,9 @@
.wc-block-cart__page-notice {
margin: 0;
}

.wp-block-woocommerce-cart.is-editor-preview {
max-height: 1000px;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a hack to limit the preview height, I filled an issue in GB
WordPress/gutenberg#24484

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we could display the desktop preview instead of the responsive mobile preview we would probably not have this problem, right? In addition, displaying the mobile preview in a desktop seems a bit weird.

One idea would be to extend the EditorProvider with an isPreview property. This way, inside ContainerWidthContextProvider we could check if it's a preview and, in that case, always apply the isLarge class. I don't think that should block this PR but if it's a solution that makes sense to you too, we could fill an issue.

@nerrad
Copy link
Contributor

nerrad commented Aug 11, 2020

Just noting that we need to test this change across the various versions of WordPress Blocks support (currently WP 5.2+). I think we could consider bumping the next release of Blocks to support WP 5.3+ too if needed and it would simplify any necessary progressive enhancement.

@senadir
Copy link
Member Author

senadir commented Aug 11, 2020

Will test it in other versions, but this shouldn't impact anything because we're not touching anything new, preview attribute has been there since forever.

@LevinMedia
Copy link
Contributor

@senadir @nerrad while I appreciate the idea behind the preview for the styles, I don't think they're necessary in this case. The default, light inputs, are designed to work on all background colors - so this is really optional. Also, the nature of the toggle is such that activating it will provide instant feedback in the editor. If the look isn't desired, it can simply be toggled off.

For this reason I think we should stick with a simple toggle switch:
Screen Shot 2020-08-11 at 12 14 58 PM

@senadir
Copy link
Member Author

senadir commented Aug 12, 2020

@LevinMedia I agree, but I don't think that should be a blocker for this PR, but more for #2981, I think we can merge this as a good enhancement to our blocks.
What I mean is, the ability to see the actual block on the inserter before inserting it, and how it will look with your theme.

Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great, previews make more sense than just showing a gray SVG placeholder. I wonder why went for the SVG placeholder in the first place. 🤔

For this reason I think we should stick with a simple toggle switch:

So, if I'm understanding it right, if we use the toggle instead of the style previews, this should be removed from the testing steps Make sure the styles are not very long and overflowing, right? Or at least, re-phrased so it refers to the inserter preview instead of the styles.


I left some comments below, but pre-approving. I think it would be good to handle the comments about removing some dead files and a couple of lines in CSS in this PR before merging. The other one about investigating how we could display desktop previews in the inserter shouldn't be blocking in my opinion.

assets/js/blocks/cart-checkout/cart/edit.js Show resolved Hide resolved
@@ -1,3 +1,9 @@
.wc-block-cart__page-notice {
margin: 0;
}

.wp-block-woocommerce-cart.is-editor-preview {
max-height: 1000px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we could display the desktop preview instead of the responsive mobile preview we would probably not have this problem, right? In addition, displaying the mobile preview in a desktop seems a bit weird.

One idea would be to extend the EditorProvider with an isPreview property. This way, inside ContainerWidthContextProvider we could check if it's a preview and, in that case, always apply the isLarge class. I don't think that should block this PR but if it's a solution that makes sense to you too, we could fill an issue.

assets/js/blocks/cart-checkout/cart/editor.scss Outdated Show resolved Hide resolved
assets/js/blocks/cart-checkout/checkout/editor.scss Outdated Show resolved Hide resolved
@senadir senadir merged commit c109efa into main Aug 13, 2020
@senadir senadir deleted the add/live-previews-to-cart-checkout branch August 13, 2020 13:24
@senadir senadir mentioned this pull request Aug 19, 2020
20 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: cart Issues related to the cart block. block: checkout Issues related to the checkout block.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants