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

Rating Product block: Add support for global style #5521

Merged
merged 14 commits into from
Feb 15, 2022

Conversation

gigitux
Copy link
Contributor

@gigitux gigitux commented Jan 5, 2022

This PR is blocked by #5515

This PR adds support for global style for the Rating Product block.

Now, the user can edit the style for:

  • text-color

Fixes #4965

Screenshots

image
without global style

image
with global style

Testing

Manual Testing

Check out this branch:

  1. On WordPress 5.9, install and enable the Gutenberg plugin.
  2. Install and enable the Twenty Twenty-Two theme.
  3. Add the Single Product block (this block contains Rating Product block) to a post.
  4. Get the focus on Rating Product block.
  5. On the right sidebar, personalize the styles of the block.
  6. Go on the page and check if there are changes.
  7. Reset to default using the Reset button from the different sections.
  8. Go to Dashboard and select Appearance > Editor (beta). On top of the screen, select Home > Browser all templates > Single Post. When the page is loaded, add the block to the page.
  9. On the Editor page click on the Styles icon on the right-top corner.
  10. Verify that the Rating Product block is shown under the Blocks section. Personalize again the block.
  11. Save your changes.
  12. Go on the page created earlier and check if all styles are applied correctly.
  13. Edit your previous post/page again.
  14. Change again the styles.
  15. Save your changes.
  16. Check if these styles have priority over the styles from the Site Editor.

Changelog

Add support for the global style for the Rating Product block.

@gigitux gigitux added type: enhancement The issue is a request for an enhancement. focus: global styles Issues that involve styles/css/layout structure. block-type: product Issues related to/affecting all blocks related to products. focus: FSE Work related to prepare WooCommerce for FSE. labels Jan 5, 2022
@gigitux gigitux self-assigned this Jan 5, 2022
@rubikuserbot rubikuserbot requested review from a team and Aljullu and removed request for a team January 5, 2022 17:06
@gigitux gigitux mentioned this pull request Jan 5, 2022
18 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2022

Size Change: +454 B (0%)

Total Size: 816 kB

Filename Size Change
build/active-filters.js 7.05 kB -2 B (0%)
build/all-products-frontend.js 18.8 kB +3 B (0%)
build/all-products.js 34.3 kB +69 B (0%)
build/all-reviews.js 8.06 kB +1 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/catego--ce653f6d.js 0 B -255 B (removed) 🏆
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/image---a7e2bb9b.js 2.7 kB +1 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 1.48 kB -2 B (0%)
build/atomic-block-components/add-to-cart.js 6.51 kB +3 B (0%)
build/atomic-block-components/category-list--atomic-block-components/image--atomic-block-components/sale---5e68150f.js 0 B -468 B (removed) 🏆
build/atomic-block-components/image-frontend.js 1.77 kB -1 B (0%)
build/atomic-block-components/price.js 1.69 kB +3 B (0%)
build/atomic-block-components/rating-frontend.js 1.04 kB +339 B (+48%) 🚨
build/atomic-block-components/rating.js 719 B +18 B (+3%)
build/atomic-block-components/sale-badge-frontend.js 1 kB -1 B (0%)
build/atomic-block-components/sale-badge.js 685 B +1 B (0%)
build/atomic-block-components/stock-indicator.js 622 B -1 B (0%)
build/atomic-block-components/summary.js 923 B -1 B (0%)
build/atomic-block-components/tag-list.js 499 B -1 B (0%)
build/atomic-block-components/title-frontend.js 1.21 kB -2 B (0%)
build/attribute-filter-frontend.js 16.8 kB +1 B (0%)
build/attribute-filter.js 13 kB -1 B (0%)
build/cart-blocks/checkout-button-frontend.js 1.16 kB +1 B (0%)
build/cart-blocks/express-payment-frontend.js 5.18 kB +1 B (0%)
build/cart-blocks/order-summary-frontend.js 8.87 kB +4 B (0%)
build/cart-frontend.js 45.6 kB -4 B (0%)
build/cart.js 43.7 kB -2 B (0%)
build/checkout-blocks/express-payment-frontend.js 5.46 kB +1 B (0%)
build/checkout-blocks/order-summary-frontend.js 11.3 kB +5 B (0%)
build/checkout-frontend.js 47.7 kB +5 B (0%)
build/checkout.js 45.2 kB -2 B (0%)
build/featured-product.js 9.62 kB -1 B (0%)
build/handpicked-products.js 7.09 kB +3 B (0%)
build/legacy-template.js 2.18 kB -1 B (0%)
build/mini-cart-contents.js 3.82 kB -3 B (0%)
build/mini-cart.js 6.39 kB -1 B (0%)
build/price-filter.js 8.51 kB -1 B (0%)
build/product-category.js 8.49 kB -1 B (0%)
build/product-new.js 7.66 kB -1 B (0%)
build/product-tag.js 7.81 kB -1 B (0%)
build/product-top-rated.js 7.9 kB -2 B (0%)
build/reviews-by-category.js 11.5 kB +3 B (0%)
build/reviews-by-product.js 12.6 kB -1 B (0%)
build/single-product-frontend.js 22.2 kB +3 B (0%)
build/single-product.js 10 kB -8 B (0%)
build/wc-blocks-style-rtl.css 22 kB +15 B (0%)
build/wc-blocks-style.css 22 kB +15 B (0%)
build/wc-blocks-vendors.js 69.7 kB +2 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/catego--214e300a.js 255 B +255 B (new file) 🆕
build/atomic-block-components/category-list--atomic-block-components/image--atomic-block-components/ratin--2614069e.js 466 B +466 B (new file) 🆕
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 6.37 kB
build/atomic-block-components/add-to-cart-frontend.js 6.94 kB
build/atomic-block-components/button-frontend.js 1.54 kB
build/atomic-block-components/button.js 912 B
build/atomic-block-components/category-list-frontend.js 826 B
build/atomic-block-components/category-list.js 500 B
build/atomic-block-components/image.js 1.1 kB
build/atomic-block-components/price-frontend.js 1.74 kB
build/atomic-block-components/sku-frontend.js 386 B
build/atomic-block-components/sku.js 386 B
build/atomic-block-components/stock-indicator-frontend.js 942 B
build/atomic-block-components/summary-frontend.js 1.24 kB
build/atomic-block-components/tag-list-frontend.js 825 B
build/atomic-block-components/title.js 934 B
build/blocks-checkout.js 17.6 kB
build/cart-blocks/accepted-payment-methods-frontend.js 1.14 kB
build/cart-blocks/empty-cart-frontend.js 345 B
build/cart-blocks/filled-cart-frontend.js 766 B
build/cart-blocks/items-frontend.js 299 B
build/cart-blocks/line-items-frontend.js 5.49 kB
build/cart-blocks/totals-frontend.js 320 B
build/checkout-blocks/actions-frontend.js 1.41 kB
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.22 kB
build/checkout-blocks/billing-address-frontend.js 888 B
build/checkout-blocks/contact-information-frontend.js 2.94 kB
build/checkout-blocks/fields-frontend.js 344 B
build/checkout-blocks/order-note-frontend.js 1.13 kB
build/checkout-blocks/payment-frontend.js 7.75 kB
build/checkout-blocks/shipping-address-frontend.js 976 B
build/checkout-blocks/shipping-methods-frontend.js 4.81 kB
build/checkout-blocks/terms-frontend.js 1.22 kB
build/checkout-blocks/totals-frontend.js 324 B
build/featured-category.js 8.61 kB
build/mini-cart-component-frontend.js 14.3 kB
build/mini-cart-frontend.js 1.81 kB
build/price-filter-frontend.js 12.6 kB
build/price-format.js 1.18 kB
build/product-best-sellers.js 7.37 kB
build/product-categories.js 3.17 kB
build/product-on-sale.js 7.99 kB
build/product-search.js 2.18 kB
build/products-by-attribute.js 8.39 kB
build/reviews-frontend.js 7.34 kB
build/stock-filter-frontend.js 6.61 kB
build/stock-filter.js 6.69 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 7.51 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.74 kB
build/wc-blocks-data.js 8.84 kB
build/wc-blocks-editor-style-rtl.css 4.85 kB
build/wc-blocks-editor-style.css 4.85 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.52 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-blocks.js 2.62 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.61 kB

compressed-size-action

@gigitux gigitux added the status: blocked The issue is blocked from progressing, waiting for another piece of work to be done. label Jan 6, 2022
@gigitux gigitux force-pushed the add/4965-rating-product branch from b901166 to 23f9587 Compare January 12, 2022 14:32
@gigitux gigitux removed the status: blocked The issue is blocked from progressing, waiting for another piece of work to be done. label Jan 12, 2022
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 working great, and I really like the style hooks you created and how clean the code looks. 👏

The only issue I found is that when using the Product Rating block inside the All Products block, the color doesn't seem to be applied. What's weird is that Product title styles do work, so the issue is only in the Product Rating block:

imatge

Any idea what might be going on?

@gigitux
Copy link
Contributor Author

gigitux commented Feb 7, 2022

This is working great, and I really like the style hooks you created and how clean the code looks. 👏

The only issue I found is that when using the Product Rating block inside the All Products block, the color doesn't seem to be applied. What's weird is that Product title styles do work, so the issue is only in the Product Rating block:

imatge

Any idea what might be going on?

It is fixed now!

@gigitux gigitux requested a review from Aljullu February 7, 2022 10:25
@gigitux gigitux force-pushed the add/4965-rating-product branch from f82aa78 to 33b6b61 Compare February 7, 2022 10:27
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, @gigitux! Confirming it's working now. I just left one last comment regarding the color of the stars having changed in blocks without global styles. 👇

@@ -143,7 +143,6 @@
left: 0;
right: 0;
position: absolute;
color: #000;
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing this line changes the color of the stars in product grid blocks.

All Products block without styles applied:

Before After
imatge imatge

Top Rated Products block:

Before After
imatge imatge

Do you think there is any way to keep this declaration while getting global styles to work?

Copy link
Contributor Author

@gigitux gigitux Feb 8, 2022

Choose a reason for hiding this comment

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

Thanks for catching this!

I restored the previous CSS with 84f00de commit.

I forgot that we have some components that display product ratings on the PHP side (as ´Top Rated Products` block). Now the global style will be applied on PHP side blocks too (but as default the color will be black)

I'm not sure about the screenshot that you shared.
image

I checked the trunk and I see always black stars. Can you check again?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, not sure what I did to get that color. 😅 It was in Storefront but I checked it again and it's dark-gray as the other blocks.

@gigitux gigitux force-pushed the add/4965-rating-product branch from 84f00de to 98416dc Compare February 8, 2022 15:09
@gigitux gigitux requested a review from Aljullu February 8, 2022 15:13
@@ -562,7 +562,7 @@ protected function get_rating_html( $product ) {

if ( $rating_count > 0 ) {
return sprintf(
'<div class="wc-block-grid__product-rating">%s</div>',
'<div class="wc-block-grid__product-rating wc-block-components-product-rating">%s</div>',
Copy link
Contributor

@Aljullu Aljullu Feb 10, 2022

Choose a reason for hiding this comment

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

I noticed this change makes it so the color is also changed in ratings displayed inside the PHP product grid blocks. IMO Product rating global styles should only change the styles of the Product rating block, but they shouldn't impact any other rating component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok! I will revert this change

@@ -143,7 +143,6 @@
left: 0;
right: 0;
position: absolute;
color: #000;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, not sure what I did to get that color. 😅 It was in Storefront but I checked it again and it's dark-gray as the other blocks.

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.

Confirming the issue is fixed now, I still left one additional comment about the selector we use for the styles. I think we should intentionally apply the global styles only to the Product Rating block, instead of applying to any product rating component displayed in any block.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 14, 2022

Size Change: +688 B (0%)

Total Size: 816 kB

Filename Size Change
build/active-filters.js 7.05 kB -2 B (0%)
build/all-products-frontend.js 18.8 kB +3 B (0%)
build/all-products.js 34.3 kB +69 B (0%)
build/all-reviews.js 8.06 kB +1 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/catego--ce653f6d.js 0 B -255 B (removed) 🏆
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/image---a7e2bb9b.js 2.7 kB +1 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 1.48 kB -2 B (0%)
build/atomic-block-components/add-to-cart.js 6.51 kB +3 B (0%)
build/atomic-block-components/category-list--atomic-block-components/image--atomic-block-components/sale---5e68150f.js 0 B -468 B (removed) 🏆
build/atomic-block-components/image-frontend.js 1.77 kB -1 B (0%)
build/atomic-block-components/price.js 1.69 kB +3 B (0%)
build/atomic-block-components/rating-frontend.js 1.04 kB +339 B (+48%) 🚨
build/atomic-block-components/rating.js 719 B +18 B (+3%)
build/atomic-block-components/sale-badge-frontend.js 1 kB -1 B (0%)
build/atomic-block-components/sale-badge.js 685 B +1 B (0%)
build/atomic-block-components/stock-indicator.js 622 B -1 B (0%)
build/atomic-block-components/summary.js 923 B -1 B (0%)
build/atomic-block-components/tag-list.js 499 B -1 B (0%)
build/atomic-block-components/title-frontend.js 1.21 kB -2 B (0%)
build/attribute-filter-frontend.js 16.8 kB +1 B (0%)
build/attribute-filter.js 13 kB -1 B (0%)
build/cart-blocks/checkout-button-frontend.js 1.16 kB +1 B (0%)
build/cart-blocks/express-payment-frontend.js 5.18 kB +1 B (0%)
build/cart-blocks/order-summary-frontend.js 8.87 kB +4 B (0%)
build/cart-frontend.js 45.6 kB -4 B (0%)
build/cart.js 43.7 kB -2 B (0%)
build/checkout-blocks/express-payment-frontend.js 5.46 kB +1 B (0%)
build/checkout-blocks/order-summary-frontend.js 11.3 kB +5 B (0%)
build/checkout-frontend.js 47.7 kB +5 B (0%)
build/checkout.js 45.2 kB -2 B (0%)
build/featured-product.js 9.62 kB -1 B (0%)
build/handpicked-products.js 7.09 kB +3 B (0%)
build/legacy-template.js 2.18 kB -1 B (0%)
build/mini-cart-component-frontend.js 14.3 kB -3 B (0%)
build/mini-cart-contents.js 3.83 kB +9 B (0%)
build/mini-cart.js 6.39 kB -1 B (0%)
build/price-filter.js 8.51 kB -1 B (0%)
build/product-category.js 8.49 kB -1 B (0%)
build/product-new.js 7.66 kB -1 B (0%)
build/product-tag.js 7.81 kB -1 B (0%)
build/product-top-rated.js 7.9 kB -2 B (0%)
build/reviews-by-category.js 11.5 kB +3 B (0%)
build/reviews-by-product.js 12.6 kB -1 B (0%)
build/single-product-frontend.js 22.2 kB +3 B (0%)
build/single-product.js 10 kB -8 B (0%)
build/wc-blocks-style-rtl.css 22.1 kB +132 B (+1%)
build/wc-blocks-style.css 22.1 kB +123 B (+1%)
build/wc-blocks-vendors.js 69.7 kB +2 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/catego--214e300a.js 255 B +255 B (new file) 🆕
build/atomic-block-components/category-list--atomic-block-components/image--atomic-block-components/ratin--2614069e.js 466 B +466 B (new file) 🆕
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 6.37 kB
build/atomic-block-components/add-to-cart-frontend.js 6.94 kB
build/atomic-block-components/button-frontend.js 1.54 kB
build/atomic-block-components/button.js 912 B
build/atomic-block-components/category-list-frontend.js 826 B
build/atomic-block-components/category-list.js 500 B
build/atomic-block-components/image.js 1.1 kB
build/atomic-block-components/price-frontend.js 1.74 kB
build/atomic-block-components/sku-frontend.js 386 B
build/atomic-block-components/sku.js 386 B
build/atomic-block-components/stock-indicator-frontend.js 942 B
build/atomic-block-components/summary-frontend.js 1.24 kB
build/atomic-block-components/tag-list-frontend.js 825 B
build/atomic-block-components/title.js 934 B
build/blocks-checkout.js 17.6 kB
build/cart-blocks/accepted-payment-methods-frontend.js 1.14 kB
build/cart-blocks/empty-cart-frontend.js 345 B
build/cart-blocks/filled-cart-frontend.js 766 B
build/cart-blocks/items-frontend.js 299 B
build/cart-blocks/line-items-frontend.js 5.49 kB
build/cart-blocks/totals-frontend.js 320 B
build/checkout-blocks/actions-frontend.js 1.41 kB
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.22 kB
build/checkout-blocks/billing-address-frontend.js 888 B
build/checkout-blocks/contact-information-frontend.js 2.94 kB
build/checkout-blocks/fields-frontend.js 344 B
build/checkout-blocks/order-note-frontend.js 1.13 kB
build/checkout-blocks/payment-frontend.js 7.75 kB
build/checkout-blocks/shipping-address-frontend.js 976 B
build/checkout-blocks/shipping-methods-frontend.js 4.81 kB
build/checkout-blocks/terms-frontend.js 1.22 kB
build/checkout-blocks/totals-frontend.js 324 B
build/featured-category.js 8.61 kB
build/mini-cart-frontend.js 1.81 kB
build/price-filter-frontend.js 12.6 kB
build/price-format.js 1.18 kB
build/product-best-sellers.js 7.37 kB
build/product-categories.js 3.17 kB
build/product-on-sale.js 7.99 kB
build/product-search.js 2.18 kB
build/products-by-attribute.js 8.39 kB
build/reviews-frontend.js 7.34 kB
build/stock-filter-frontend.js 6.61 kB
build/stock-filter.js 6.69 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 7.51 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.74 kB
build/wc-blocks-data.js 8.84 kB
build/wc-blocks-editor-style-rtl.css 4.85 kB
build/wc-blocks-editor-style.css 4.85 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.52 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-blocks.js 2.62 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.61 kB

compressed-size-action

@gigitux gigitux requested a review from Aljullu February 14, 2022 11:44
@gigitux
Copy link
Contributor Author

gigitux commented Feb 14, 2022

Confirming the issue is fixed now, I still left one additional comment about the selector we use for the styles. I think we should intentionally apply the global styles only to the Product Rating block, instead of applying to any product rating component displayed in any block.

Ok! I just reverted the change on AbstractProductGrid.php file (eebfd45)

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.

LGTM! I left one comment that needs to be addressed, but pre-approving. 👍

@@ -234,7 +235,7 @@ protected function get_atomic_blocks() {
'product-button',
'product-image',
'product-price',
'product-rating',
'product-sale-badge',
Copy link
Contributor

Choose a reason for hiding this comment

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

I had to remove this line, otherwise I was getting an error telling me product-sale-badge was registered twice:

( ! ) Notice: WP_Block_Type_Registry::register was called <strong>incorrectly</strong>. Block type "woocommerce/product-sale-badge" is already registered. Please see <a href="https://wordpress.org/support/article/debugging-in-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 5.0.0.) in .../Local Sites/latest/app/public/wp-includes/functions.php on line 5768

imatge

@github-actions github-actions bot added this to the 7.0.0 milestone Feb 15, 2022
@gigitux gigitux merged commit 75bd816 into trunk Feb 15, 2022
@gigitux gigitux deleted the add/4965-rating-product branch February 15, 2022 14:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block-type: product Issues related to/affecting all blocks related to products. focus: FSE Work related to prepare WooCommerce for FSE. focus: global styles Issues that involve styles/css/layout structure. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add global styles to all WC Blocks
2 participants