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

Fix: Mini Cart block: divide contents into three inner blocks #5386

Merged
merged 25 commits into from
Dec 20, 2021

Conversation

dinhtungdu
Copy link
Member

Fixes #4855

This PR:

  • Splits the filled mini cart contents into three inner blocks: Mini Cart Title, Mini Cart Products Table, and Mini Cart Footer.
  • Renders filled Mini Cart contents block in the editor.
  • Removes the <Drawer> title.
  • Adds background support to the mini cart content block.
  • Updates mini-cart template part file.
  • Updates markup in the MiniCartContents.php to match with the component.
  • Sets a maximum width for the Mini Cart Contents block in the Site Editor.
  • Blocks interactive for Mini Cart Products Table and Footer blocks.

Screenshots

Click to expand

Editor

image

Front end

image

Testing

Automated Tests

  • Changes in this PR are covered by Automated Tests.
    • Unit tests
    • E2E tests

Manual Testing

How to test the changes in this Pull Request:

  1. Delete all customized mini-cart template parts in /wp-admin/edit.php?post_type=wp_template_part.
  2. Delete the theme's mini-cart template part file.
  3. Edit the Mini Cart template: Site Editor > Template Parts > Mini Cart.
  4. See no error.
  5. See the content of the filled mini cart renders in the editor.
  6. Select the mini cart content block.
  7. Set the background color.
  8. See it works in the editor.
  9. Save the change, see the background color works on the front end.

User Facing Testing

These are steps for user testing (where "user" is someone interacting with this change that is not editing any code).

  • Same as above, or
  • See steps below.

@dinhtungdu dinhtungdu added status: needs review skip-changelog PRs that you don't want to appear in the changelog. focus: FSE Work related to prepare WooCommerce for FSE. block: mini-cart Issues related to the Mini-Cart block. labels Dec 15, 2021
@dinhtungdu dinhtungdu requested a review from Aljullu December 15, 2021 11:03
@dinhtungdu dinhtungdu self-assigned this Dec 15, 2021
@rubikuserbot rubikuserbot requested a review from a team December 15, 2021 11:04
@github-actions
Copy link
Contributor

The `div` wrapper of RawHTML isn't removed on the front e...

The `div` wrapper of RawHTML isn't removed on the front end. */ }


https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/ce31fb0e1d3d99440fcd61dd118b099f59090d3f/assets/js/blocks/cart-checkout/mini-cart/block.tsx#L197-L200

🚀 This comment was generated by the automations bot based on a todo comment in ce31fb0 in #5386. cc @dinhtungdu

@github-actions
Copy link
Contributor

Allow the user to edit the title of the mini cart.

Allow the user to edit the title of the mini cart.


https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/ce31fb0e1d3d99440fcd61dd118b099f59090d3f/assets/js/blocks/cart-checkout/mini-cart-contents/inner-blocks/mini-cart-title-block/block.tsx#L14-L25

🚀 This comment was generated by the automations bot based on a todo comment in ce31fb0 in #5386. cc @dinhtungdu

@github-actions
Copy link
Contributor

Review the class naming convention for Mini Cart inner bl...

Review the class naming convention for Mini Cart inner blocks.


https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/ce31fb0e1d3d99440fcd61dd118b099f59090d3f/assets/js/blocks/cart-checkout/mini-cart/style.scss#L79-L90

🚀 This comment was generated by the automations bot based on a todo comment in ce31fb0 in #5386. cc @dinhtungdu

@github-actions
Copy link
Contributor

github-actions bot commented Dec 15, 2021

Size Change: +85 B (0%)

Total Size: 819 kB

Filename Size Change
build/active-filters.js 7.05 kB +3 B (0%)
build/all-products-frontend.js 18.6 kB +2 B (0%)
build/all-products.js 34.4 kB +2 B (0%)
build/all-reviews.js 8.35 kB +2 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 1.48 kB +1 B (0%)
build/atomic-block-components/add-to-cart.js 6.42 kB +1 B (0%)
build/atomic-block-components/button.js 851 B +1 B (0%)
build/atomic-block-components/price-frontend.js 1.74 kB +4 B (0%)
build/atomic-block-components/price.js 1.7 kB +5 B (0%)
build/atomic-block-components/rating.js 554 B +1 B (0%)
build/atomic-block-components/sale-badge.js 622 B +1 B (0%)
build/atomic-block-components/stock-indicator.js 585 B -1 B (0%)
build/atomic-block-components/summary.js 871 B -2 B (0%)
build/attribute-filter.js 12.6 kB -1 B (0%)
build/cart-blocks/line-items-frontend.js 5.13 kB +5 B (0%)
build/cart-blocks/order-summary-frontend.js 8.97 kB -7 B (0%)
build/cart-frontend.js 45.5 kB -28 B (0%)
build/cart.js 44.4 kB -34 B (0%)
build/checkout-blocks/order-summary-frontend.js 11.4 kB -6 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 4.81 kB +1 B (0%)
build/checkout-frontend.js 47.6 kB -32 B (0%)
build/checkout.js 47.1 kB -27 B (0%)
build/featured-category.js 8.55 kB +2 B (0%)
build/featured-product.js 9.9 kB +1 B (0%)
build/mini-cart-component-frontend.js 14.2 kB -43 B (0%)
build/mini-cart-contents.js 3.59 kB +15 B (0%)
build/mini-cart.js 6.46 kB +1 B (0%)
build/price-filter-frontend.js 12.4 kB -2 B (0%)
build/price-filter.js 8.6 kB -1 B (0%)
build/product-best-sellers.js 7.51 kB -2 B (0%)
build/product-categories.js 3.47 kB +2 B (0%)
build/product-category.js 8.36 kB +5 B (0%)
build/product-search.js 2.47 kB +2 B (0%)
build/product-tag.js 7.76 kB -1 B (0%)
build/product-top-rated.js 7.63 kB -2 B (0%)
build/products-by-attribute.js 8.48 kB -3 B (0%)
build/reviews-by-category.js 11.9 kB +1 B (0%)
build/reviews-by-product.js 12.9 kB -4 B (0%)
build/single-product-frontend.js 22.1 kB +3 B (0%)
build/wc-blocks-editor-style-rtl.css 4.47 kB +65 B (+1%)
build/wc-blocks-editor-style.css 4.47 kB +64 B (+1%)
build/wc-blocks-style-rtl.css 21.7 kB +45 B (0%)
build/wc-blocks-style.css 21.6 kB +43 B (0%)
build/wc-blocks-vendors.js 65.5 kB -1 B (0%)
build/wc-blocks.js 2.96 kB -4 B (0%)
build/wc-settings.js 2.61 kB +8 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 6.22 kB
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/image---a7e2bb9b.js 2.76 kB
build/atomic-block-components/add-to-cart-frontend.js 6.87 kB
build/atomic-block-components/button-frontend.js 1.48 kB
build/atomic-block-components/category-list-frontend.js 457 B
build/atomic-block-components/category-list.js 458 B
build/atomic-block-components/image-frontend.js 1.37 kB
build/atomic-block-components/image.js 1.05 kB
build/atomic-block-components/rating-frontend.js 552 B
build/atomic-block-components/sale-badge-frontend.js 625 B
build/atomic-block-components/sku-frontend.js 386 B
build/atomic-block-components/sku.js 385 B
build/atomic-block-components/stock-indicator-frontend.js 584 B
build/atomic-block-components/summary-frontend.js 872 B
build/atomic-block-components/tag-list-frontend.js 458 B
build/atomic-block-components/tag-list.js 458 B
build/atomic-block-components/title-frontend.js 1.11 kB
build/atomic-block-components/title.js 1.1 kB
build/attribute-filter-frontend.js 16.3 kB
build/blocks-checkout.js 17.6 kB
build/cart-blocks/accepted-payment-methods-frontend.js 1.15 kB
build/cart-blocks/checkout-button-frontend.js 1.14 kB
build/cart-blocks/empty-cart-frontend.js 345 B
build/cart-blocks/express-payment-frontend.js 4.86 kB
build/cart-blocks/filled-cart-frontend.js 766 B
build/cart-blocks/items-frontend.js 298 B
build/cart-blocks/totals-frontend.js 320 B
build/checkout-blocks/actions-frontend.js 1.44 kB
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.24 kB
build/checkout-blocks/billing-address-frontend.js 884 B
build/checkout-blocks/contact-information-frontend.js 2.95 kB
build/checkout-blocks/express-payment-frontend.js 5.15 kB
build/checkout-blocks/fields-frontend.js 343 B
build/checkout-blocks/order-note-frontend.js 1.13 kB
build/checkout-blocks/payment-frontend.js 7.41 kB
build/checkout-blocks/shipping-address-frontend.js 971 B
build/checkout-blocks/terms-frontend.js 1.21 kB
build/checkout-blocks/totals-frontend.js 324 B
build/handpicked-products.js 7.32 kB
build/legacy-template.js 2.08 kB
build/mini-cart-frontend.js 1.76 kB
build/price-format.js 1.18 kB
build/product-new.js 7.66 kB
build/product-on-sale.js 8.05 kB
build/reviews-frontend.js 7.25 kB
build/single-product.js 10.4 kB
build/stock-filter-frontend.js 6.81 kB
build/stock-filter.js 6.82 kB
build/vendors--atomic-block-components/add-to-cart--cart-blocks/order-summary--checkout-blocks/billing-ad--c5eb4dcd-frontend.js 19 kB
build/vendors--atomic-block-components/add-to-cart-frontend.js 6.82 kB
build/vendors--atomic-block-components/price--cart-blocks/line-items--cart-blocks/order-summary--checkout--8a3571de-frontend.js 5.71 kB
build/vendors--cart-blocks/line-items--checkout-blocks/order-summary-frontend.js 3.14 kB
build/vendors--cart-blocks/order-summary--checkout-blocks/billing-address--checkout-blocks/order-summary---eb4d2cec-frontend.js 4.75 kB
build/wc-blocks-data.js 8.84 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 949 B
build/wc-blocks-registry.js 2.7 kB
build/wc-blocks-shared-context.js 1.51 kB
build/wc-blocks-shared-hocs.js 1.14 kB
build/wc-blocks-vendors-style-rtl.css 1.28 kB
build/wc-blocks-vendors-style.css 1.28 kB
build/wc-payment-method-bacs.js 820 B
build/wc-payment-method-cheque.js 816 B
build/wc-payment-method-cod.js 912 B
build/wc-payment-method-paypal.js 838 B
build/wc-payment-method-stripe.js 11.1 kB

compressed-size-action

@github-actions
Copy link
Contributor

The `div` wrapper of RawHTML isn't removed on the front e...

The `div` wrapper of RawHTML isn't removed on the front end. */ }


https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/c98294580e08a1d0f18580150d7f56e0fb1ea68c/assets/js/blocks/cart-checkout/mini-cart/block.tsx#L197-L200

🚀 This comment was generated by the automations bot based on a todo comment in c982945 in #5386. cc @dinhtungdu

@dinhtungdu
Copy link
Member Author

Can you replicate it?

@gigitux The issue happens if Cart and/or Checkout page is missing. I fixed it in a80e16b, thanks for the head-up!

Co-authored-by: Albert Juhé Lluveras <[email protected]>
@github-actions
Copy link
Contributor

The `div` wrapper of RawHTML isn't removed on the front e...

The `div` wrapper of RawHTML isn't removed on the front end. */ }


https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/f2b50657a08ec3657435de35743a40a4aee190f9/assets/js/blocks/cart-checkout/mini-cart/block.tsx#L197-L200

🚀 This comment was generated by the automations bot based on a todo comment in f2b5065 in #5386. cc @dinhtungdu

@github-actions
Copy link
Contributor

The `div` wrapper of RawHTML isn't removed on the front e...

The `div` wrapper of RawHTML isn't removed on the front end. */ }


https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/ed2d86105be76ceced23ef22ea49af0eca31792f/assets/js/blocks/cart-checkout/mini-cart/block.tsx#L197-L200

🚀 This comment was generated by the automations bot based on a todo comment in ed2d861 in #5386. cc @dinhtungdu

@github-actions
Copy link
Contributor

The `div` wrapper of RawHTML isn't removed on the front e...

The `div` wrapper of RawHTML isn't removed on the front end. */ }


https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/8bbaf3853ab4b4c9522c8bfa10a9cbaf1e3230b6/assets/js/blocks/cart-checkout/mini-cart/block.tsx#L197-L200

🚀 This comment was generated by the automations bot based on a todo comment in 8bbaf38 in #5386. cc @dinhtungdu

@dinhtungdu
Copy link
Member Author

I also saw there are several @todo comments in the code. Is the plan to work on them in this PR or in follow-ups?

@Aljullu Given that this PR is already big, I would prefer to work on those todos in follow-ups to make it easier to review.

@dinhtungdu
Copy link
Member Author

Should we allow tweaking the text color too?

I think we should. But it should be addressed in a separated PR because of its complexity. I would like to change only the colors of the Mini Cart Contents block, including text and link color, then the inner blocks should reflect those customizations.

I will create another to-do if the proposal above makes sense to you.

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.

Thanks for updating this PR @dinhtungdu! It looks good to me. :shipit:

@Aljullu Given that this PR is already big, I would prefer to work on those todos in follow-ups to make it easier to review.

Yes, it works for me. Just be aware that for each @todo comment a new issue will be automatically created, so you will need to assign them to the Mini Cart epic.

I think we should. But it should be addressed in a separated PR because of its complexity. I would like to change only the colors of the Mini Cart Contents block, including text and link color, then the inner blocks should reflect those customizations.

I will create another to-do if the proposal above makes sense to you.

💯 Sure, that's what I had in mind as well.

const Block = (): JSX.Element => {
const { cartItemsCount, cartIsLoading } = useStoreCart();
/**
* @todo Allow the user to edit the title of the mini cart.
Copy link
Contributor

Choose a reason for hiding this comment

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

That will be tricky because the string contains a variable (x items). I think @nielslange faced the same challenge in the Free shipping progress bar block and solved it with a placeholder in curly braces ({amount}). It would be good to make sure we align on the same solution.

Copy link
Member

@nielslange nielslange Dec 17, 2021

Choose a reason for hiding this comment

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

@dinhtungdu I wonder how many merchants would actually change the title of the mini-cart block. As @Aljullu mentioned, I used a placeholder while implementing woocommerce/woocommerce-free-shipping-progress-bar-block#15. However, that block has the following editable texts:

  • Spend only {amount} more to get free shipping!
  • You have qualified for free shipping. Great job!

That said, if the mini-cart block title should be editable, I achieved that using the switch-switcher, which I see you also used in #5304 already.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your inputs! I will remove the to-do for now. If we receive enough requests in the future, we can work on it then. For now, I don't think it's worth the effort.

@Aljullu
Copy link
Contributor

Aljullu commented Dec 17, 2021

Something I noticed while doing some more testing is that in WP 5.9 beta 3 with Gutenberg disabled, I can check the color in the editor, but the new color is not applied in the frontend. @dinhtungdu can you reproduce that too? If so, it would be great to create an issue about that so we can investigate it further.

…/mini-cart-footer-block/block.tsx

Co-authored-by: Albert Juhé Lluveras <[email protected]>
@github-actions
Copy link
Contributor

The `div` wrapper of RawHTML isn't removed on the front e...

The `div` wrapper of RawHTML isn't removed on the front end. */ }


https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/45a6c00f6b411dba729275476c6c13b67eb794ca/assets/js/blocks/cart-checkout/mini-cart/block.tsx#L197-L200

🚀 This comment was generated by the automations bot based on a todo comment in 45a6c00 in #5386. cc @dinhtungdu

@github-actions
Copy link
Contributor

The `div` wrapper of RawHTML isn't removed on the front e...

The `div` wrapper of RawHTML isn't removed on the front end. */ }


https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/8d08c6056afede0f97ac204e6add679bc8d6e0d1/assets/js/blocks/cart-checkout/mini-cart/block.tsx#L197-L200

🚀 This comment was generated by the automations bot based on a todo comment in 8d08c60 in #5386. cc @dinhtungdu

@dinhtungdu dinhtungdu changed the title Mini Cart block: divide contents into three inner blocks Fix: Mini Cart block: divide contents into three inner blocks Dec 17, 2021
@dinhtungdu
Copy link
Member Author

Something I noticed while doing some more testing is that in WP 5.9 beta 3 with Gutenberg disabled, I can check the color in the editor, but the new color is not applied in the frontend. @dinhtungdu can you reproduce that too? If so, it would be great to create an issue about that so we can investigate it further.

I can reproduce this issue as well. I created #5416 to track this.

Copy link
Contributor

@gigitux gigitux left a comment

Choose a reason for hiding this comment

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

Great work! 🎉 🚢

@dinhtungdu dinhtungdu merged commit c2444b6 into trunk Dec 20, 2021
@dinhtungdu dinhtungdu deleted the fix/4855-divide-mini-cart-contents-block branch December 20, 2021 07:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: mini-cart Issues related to the Mini-Cart block. focus: FSE Work related to prepare WooCommerce for FSE. skip-changelog PRs that you don't want to appear in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mini Cart block: divide contents into three inner blocks
4 participants