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

Add a Products by Rating filter block #7048

Merged
merged 30 commits into from
Sep 28, 2022
Merged

Conversation

danieldudzic
Copy link
Contributor

@danieldudzic danieldudzic commented Sep 3, 2022

This is an attempt at adding a Products by Rating filter block.

For now, I have focused on the core functionality, and there are several pending items on the to-do list:

To-do

  • Add support for Display Options: Product count, Show 'Apply filters' button, Color
  • Fix the editor preview display
  • Migrate the block from directly using the Rating component to utilizing the CheckboxList component (this will also make the UX match the preferred option ( pdnLyh-1sR-p2#comment-1044 ))
  • Investigate why the Active Filters block Clear All button doesn't work correctly (doesn't clear Rating filters on a Block Shop page)
  • Provide the legacy Filter Products by Rating widget deprecation
  • Add E2E tests
  • Add the ability for the Rating component to support other contexts (for example the All Products block)

Screenshots

New_shop_–_ratings

Testing

  • Activate a block theme & setup WooCommerce with products that have some ratings
  • Create a classic shop page and a separate page using the All Products block
  • Add the Filter Products by Rating block and Active Filters block on both pages
  • Check that Filter Products by Rating block is correctly:
    • Displaying the star rating buttons within the filter block
    • Displaying the active state (stars using the Primary color and the product count are in bold)
    • Filtering the products in the product loop (on both Classic and block shop pages)
    • Clearing after getting removed via Active Filters remove button
    • Updating the URL with the rating parameter
    • Loading the rating filters via URL parameters on page reload

User Facing Testing

Same as the above steps

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Changelog

Add Filter Products by Rating block

@rubikuserbot rubikuserbot requested review from a team and gigitux and removed request for a team September 3, 2022 07:33
@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2022

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-7048.zip

@danieldudzic danieldudzic added block: filter by rating Issues related to the Filter by Rating block. type: enhancement The issue is a request for an enhancement. labels Sep 3, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2022

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
rating-filter.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-settings, wp-block-editor, wp-blocks, wp-components, wp-compose, wp-data, wp-element, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-primitives, wp-url ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2022

Size Change: +12.9 kB (+1%)

Total Size: 916 kB

Filename Size Change
build/active-filters-frontend.js 7.62 kB +1 B (0%)
build/active-filters.js 8.3 kB +33 B (0%)
build/all-products-frontend.js 26.5 kB +63 B (0%)
build/all-products.js 33.6 kB +23 B (0%)
build/all-reviews.js 7.79 kB -1 B (0%)
build/attribute-filter-frontend.js 22.4 kB +93 B (0%)
build/attribute-filter.js 13.3 kB +40 B (0%)
build/cart-blocks/cart-cross-sells-frontend.js 253 B +1 B (0%)
build/cart-blocks/cart-cross-sells-products-frontend.js 4.66 kB +2 B (0%)
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.12 kB +4 B (0%)
build/cart-blocks/cart-express-payment-frontend.js 798 B -3 B (0%)
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.26 kB -5 B (0%)
build/cart-blocks/cart-line-items-frontend.js 1.07 kB +5 B (0%)
build/cart-blocks/cart-order-summary-frontend.js 1.1 kB -3 B (0%)
build/cart-blocks/cart-totals-frontend.js 321 B -1 B (0%)
build/cart-blocks/empty-cart-frontend.js 345 B -2 B (-1%)
build/cart-blocks/filled-cart-frontend.js 783 B +1 B (0%)
build/cart-blocks/order-summary-coupon-form-frontend.js 2.73 kB +1 B (0%)
build/cart-blocks/order-summary-discount-frontend.js 2.16 kB +1 B (0%)
build/cart-blocks/order-summary-fee-frontend.js 274 B +1 B (0%)
build/cart-blocks/order-summary-heading-frontend.js 454 B -1 B (0%)
build/cart-blocks/order-summary-shipping--checkout-blocks/order-summary-shipping-frontend.js 6.73 kB -3 B (0%)
build/cart-blocks/order-summary-taxes-frontend.js 433 B +1 B (0%)
build/cart-blocks/proceed-to-checkout-frontend.js 1.19 kB -1 B (0%)
build/cart-frontend.js 50.3 kB -41 B (0%)
build/cart.js 46.4 kB -13 B (0%)
build/checkout-blocks/actions-frontend.js 1.76 kB -1 B (0%)
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.94 kB -5 B (0%)
build/checkout-blocks/billing-address-frontend.js 925 B -2 B (0%)
build/checkout-blocks/contact-information-frontend.js 2.99 kB -1 B (0%)
build/checkout-blocks/express-payment-frontend.js 1.18 kB -3 B (0%)
build/checkout-blocks/fields-frontend.js 343 B +1 B (0%)
build/checkout-blocks/order-note-frontend.js 1.13 kB -2 B (0%)
build/checkout-blocks/order-summary-cart-items-frontend.js 3.66 kB -4 B (0%)
build/checkout-blocks/order-summary-coupon-form-frontend.js 2.88 kB +2 B (0%)
build/checkout-blocks/order-summary-discount-frontend.js 2.28 kB +1 B (0%)
build/checkout-blocks/order-summary-frontend.js 1.1 kB -4 B (0%)
build/checkout-blocks/order-summary-shipping-frontend.js 602 B -2 B (0%)
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B -1 B (0%)
build/checkout-blocks/payment-frontend.js 7.89 kB -5 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 4.98 kB -1 B (0%)
build/checkout-blocks/totals-frontend.js 324 B +1 B (0%)
build/checkout-frontend.js 52.5 kB -31 B (0%)
build/checkout.js 40.1 kB -4 B (0%)
build/featured-category.js 13.2 kB -8 B (0%)
build/featured-product.js 13.4 kB -9 B (0%)
build/handpicked-products.js 7.28 kB -2 B (0%)
build/legacy-template.js 2.83 kB -5 B (0%)
build/mini-cart-component-frontend.js 16.8 kB +5 B (0%)
build/mini-cart-contents-block/filled-cart-frontend.js 229 B -1 B (0%)
build/mini-cart-contents-block/items-frontend.js 236 B -1 B (0%)
build/mini-cart-contents-block/products-table-frontend.js 589 B -3 B (-1%)
build/mini-cart-contents-block/shopping-button-frontend.js 287 B -1 B (0%)
build/mini-cart-contents-block/title-frontend.js 366 B -2 B (-1%)
build/mini-cart-contents.js 17 kB -3 B (0%)
build/mini-cart-frontend.js 1.71 kB -1 B (0%)
build/mini-cart.js 4.58 kB +1 B (0%)
build/price-filter-frontend.js 13.5 kB +77 B (+1%)
build/price-filter.js 9.4 kB +56 B (+1%)
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 225 B -1 B (0%)
build/product-add-to-cart--product-button--product-image--product-title.js 2.66 kB +2 B (0%)
build/product-add-to-cart.js 6.47 kB -11 B (0%)
build/product-best-sellers.js 7.63 kB +2 B (0%)
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 433 B +1 B (0%)
build/product-button-frontend.js 1.89 kB +3 B (0%)
build/product-button.js 1.58 kB +2 B (0%)
build/product-categories.js 2.36 kB +6 B (0%)
build/product-category-list-frontend.js 879 B +1 B (0%)
build/product-category-list.js 501 B -1 B (0%)
build/product-category.js 8.61 kB -2 B (0%)
build/product-image.js 1.61 kB +3 B (0%)
build/product-new.js 7.62 kB +4 B (0%)
build/product-on-sale.js 7.94 kB +1 B (0%)
build/product-price-frontend.js 1.91 kB +1 B (0%)
build/product-price.js 1.53 kB -3 B (0%)
build/product-query.js 648 B -1 B (0%)
build/product-rating-frontend.js 1.18 kB +2 B (0%)
build/product-sale-badge-frontend.js 1.14 kB +1 B (0%)
build/product-search.js 2.61 kB -2 B (0%)
build/product-sku-frontend.js 380 B -1 B (0%)
build/product-stock-indicator-frontend.js 995 B +2 B (0%)
build/product-stock-indicator.js 623 B -1 B (0%)
build/product-tag-list-frontend.js 875 B +1 B (0%)
build/product-tag.js 7.99 kB -2 B (0%)
build/product-title-frontend.js 1.33 kB -2 B (0%)
build/product-title.js 939 B +3 B (0%)
build/product-top-rated.js 7.86 kB +2 B (0%)
build/products-by-attribute.js 8.52 kB -4 B (0%)
build/reviews-by-category.js 11.2 kB -2 B (0%)
build/reviews-by-product.js 12.3 kB -1 B (0%)
build/reviews-frontend.js 7.01 kB -1 B (0%)
build/single-product-frontend.js 29.3 kB -12 B (0%)
build/stock-filter-frontend.js 7.64 kB +28 B (0%)
build/stock-filter.js 7.6 kB +67 B (+1%)
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary-shipping--checkout-blocks--18f9376a-frontend.js 19.1 kB +9 B (0%)
build/vendors--cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 7.54 kB +5 B (0%)
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB +1 B (0%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.85 kB +6 B (0%)
build/vendors--mini-cart-contents-block/footer-frontend.js 6.86 kB -2 B (0%)
build/wc-blocks-style-rtl.css 24.1 kB +124 B (+1%)
build/wc-blocks-style.css 24 kB +126 B (+1%)
build/wc-blocks-vendors.js 62 kB +12 B (0%)
build/rating-filter-frontend.js 6.73 kB +6.73 kB (new file) 🆕
build/rating-filter.js 5.53 kB +5.53 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
build/blocks-checkout.js 17.5 kB
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.39 kB
build/cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 5.63 kB
build/cart-blocks/cart-items-frontend.js 299 B
build/cart-blocks/order-summary-shipping-frontend.js 428 B
build/cart-blocks/order-summary-subtotal-frontend.js 274 B
build/checkout-blocks/order-summary-fee-frontend.js 275 B
build/checkout-blocks/order-summary-taxes-frontend.js 433 B
build/checkout-blocks/shipping-address-frontend.js 1.06 kB
build/checkout-blocks/terms-frontend.js 1.62 kB
build/general-style-rtl.css 1.29 kB
build/general-style.css 1.29 kB
build/mini-cart-contents-block/empty-cart-frontend.js 366 B
build/mini-cart-contents-block/footer-frontend.js 3.18 kB
build/price-format.js 1.19 kB
build/product-add-to-cart-frontend.js 1.24 kB
build/product-button--product-image--product-rating--product-sale-badge--product-title.js 302 B
build/product-image-frontend.js 1.91 kB
build/product-rating.js 772 B
build/product-sale-badge.js 817 B
build/product-sku.js 379 B
build/product-summary-frontend.js 1.29 kB
build/product-summary.js 920 B
build/product-tag-list.js 497 B
build/single-product.js 10 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--04fe80d1-frontend.js 5.26 kB
build/wc-blocks-data.js 15.9 kB
build/wc-blocks-editor-style-rtl.css 5.24 kB
build/wc-blocks-editor-style.css 5.24 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 932 B
build/wc-blocks-registry.js 2.79 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.72 kB
build/wc-blocks-vendors-style-rtl.css 1.95 kB
build/wc-blocks-vendors-style.css 1.95 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.6 kB

compressed-size-action

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, congrats for working on this big project, @danieldudzic! I did an initial review and left some minor issues below.

I also noticed the stars are not visible in the Site Editor:

imatge

I'm reporting it here but IMO this can be fixed in a follow-up PR. (Sorry if you had already identified it, maybe that's what you were referring to with Fix the editor preview display)

For this PR to be ready to merge, I think we need to:

  • Add an experimental build gate (similar to this one and this one).
  • I think it would be good to fix all the inline comments I left in this PR since they are minor things and affect translations.
  • I also think it would be great to work on this item: Migrate the block from directly using the Rating component to utilizing the CheckboxList component. If I'm understanding this properly, this will simplify the code significantly.

IMO, all other To-do items you identified can then be worked on in follow-up issues/PRs. How does it sound?

"name": "woocommerce/rating-filter",
"version": "1.0.0",
"title": "Filter Products by Rating",
"description": "Allow customers to filter the grid by products rating. Works in combination with the All Products block.",
Copy link
Contributor

Choose a reason for hiding this comment

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

We are removing the Works in combination... part of the filter blocks description (see #7045).

Copy link
Contributor Author

@danieldudzic danieldudzic Sep 7, 2022

Choose a reason for hiding this comment

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

Sorry if you had already identified it, maybe that's what you were referring to with Fix the editor preview display

That's exactly it :)

Add an experimental build gate

I'll add it today

Migrate the block from directly using the Rating component to utilizing the CheckboxList component. If I'm understanding this properly, this will simplify the code significantly.

Yes, I think it would make a lot of sense. I'll work on that and see if this is something I can get done by the end of the week.

assets/js/blocks/rating-filter/block.json Outdated Show resolved Hide resolved
src/BlockTypesController.php Outdated Show resolved Hide resolved
assets/js/blocks/rating-filter/index.tsx Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

This PR has been marked as stale because it has not seen any activity within the past 60 days. Our team uses this tool to help surface pull requests that have slipped through review.

If deemed still relevant, the pr can be kept active by ensuring it's up to date with the main branch and removing the stale label - otherwise it will automatically be closed after 10 days.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label Sep 16, 2022
@danieldudzic
Copy link
Contributor Author

@Aljullu Re:

I also noticed the stars are not visible in the Site Editor

I have just noticed the same issue occurs for the All Products block. Would you mind having a look?

Editor__beta__‹ratings—_WordPress

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 applying the changes and updating this PR, @danieldudzic!

I have just noticed the same issue occurs for the All Products block. Would you mind having a look?

You are right! Could you fill a separate issue for that? I don't think we should block this PR if this is affecting other blocks.

I left some inline comments below. 🙂

assets/js/base/components/product-rating/index.tsx Outdated Show resolved Hide resolved
assets/js/base/components/product-rating/index.tsx Outdated Show resolved Hide resolved
assets/js/base/components/product-rating/style.scss Outdated Show resolved Hide resolved
assets/js/blocks/rating-filter/style.scss Outdated Show resolved Hide resolved
assets/js/blocks/rating-filter/style.scss Outdated Show resolved Hide resolved
@danieldudzic
Copy link
Contributor Author

Thanks for applying the changes and updating this PR, @danieldudzic!

I have just noticed the same issue occurs for the All Products block. Would you mind having a look?

You are right! Could you fill a separate issue for that? I don't think we should block this PR if this is affecting other blocks.

Issue created: #7167

@github-actions
Copy link
Contributor

Remove this logic when WordPress 6.1 is released.

Remove this logic when WordPress 6.1 is released.


* @todo Remove this logic when WordPress 6.1 is released.
*/
if ( GUTENBERG_EDITOR_CONTEXT !== 'core' ) {
unlinkSync(
path.join(
__dirname,
'../specs/backend/__snapshots__/site-editing-templates.test.js.snap'
)
);
}
// we need to load puppeteer global setup here.
await setupPuppeteer( globalConfig );

🚀 This comment was generated by the automations bot based on a todo comment in 986cf18 in #7048. cc @danieldudzic

@github-actions
Copy link
Contributor

Remove runOnlyWhenGutenbergIsDisabled function and relati...

Remove runOnlyWhenGutenbergIsDisabled function and relative workarounds when WordPress 6.1 is released.


* @todo Remove runOnlyWhenGutenbergIsDisabled function and relative workarounds when WordPress 6.1 is released.
*/
const runOnlyWhenGutenbergIsDisabled = ( fn ) => {
if ( GUTENBERG_EDITOR_CONTEXT === 'core' ) {
fn();
}
};
describe( 'Store Editing Templates', () => {
useTheme( 'emptytheme' );

🚀 This comment was generated by the automations bot based on a todo comment in 986cf18 in #7048. cc @danieldudzic

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 continuing improving this PR, @danieldudzic! I left a comment about the TS definition of displayedOptions.

Besides that, I noticed that the placeholder title is strangely big compared to the other filter blocks:

Can you reproduce as well? I don't think this is blocking this PR to be merged, so IMO you can fix it on a follow-up PR so we don't block this one from getting into trunk.

assets/js/blocks/rating-filter/block.tsx Outdated Show resolved Hide resolved
@github-actions github-actions bot added this to the 8.6.0 milestone Sep 23, 2022
@danieldudzic
Copy link
Contributor Author

Besides that, I noticed that the placeholder title is strangely big compared to the other filter blocks

Thank you for the review!

I'm not seeing the issue with the large placeholder:
New_shop_–_ratings

New_shop_–_ratings

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.

I'm able to reproduce the big placeholder, but it makes sense to create a follow-up issue 👍

I think that before merging this PR, it is necessary fixing the TS type error. (I suggested to you how we could fix the issue, let me know what you think!)

assets/js/blocks/rating-filter/block.tsx Outdated Show resolved Hide resolved
@sunyatasattva sunyatasattva modified the milestones: 8.6.0, 8.7.0 Sep 26, 2022
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.

LGTM!

Thanks for having applied the fix!

@danieldudzic danieldudzic merged commit e044fe6 into trunk Sep 28, 2022
@danieldudzic danieldudzic deleted the try/add-rating-component branch September 28, 2022 21:12
senadir pushed a commit to senadir/woocommerce-blocks that referenced this pull request Nov 12, 2022
* Add interactivity to the Product by Rating filter block

* Fix block with the latest repo changes

* Product by Rating: Code tidying up

* Add an experimental build gate and update block title and description

* Remove redundant title and description

* Add support for the CheckboxList component in the Products by Rating block

* Products by Rating: Minor code clean-up

* Active Filters: Fix the Clear All button for Ratings. Closes #woocommerce#7172

* Products by Rating: Add misc TS fixes
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: filter by rating Issues related to the Filter by Rating block. skip-changelog PRs that you don't want to appear in the changelog. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants