Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experimental] Render headings as inner blocks of collection filters #43109

Merged

Conversation

samueljseay
Copy link
Contributor

Changes proposed in this Pull Request:

We needed to achieve not displaying filter headings when there is nothing to filter. For example when there are no product ratings it makes no sense to render the "Filter by rating" header on its own since nothing can be filtered.

To do this, this PR adjusts all the new experimental filter blocks to accept only core/heading as an inner block. With this change we can render the inner blocks on PHP side, but if we don't have any data (e.g. no product ratings) we can simply not render the whole block including inner blocks.

This also adjusts the collection filters template that auto inserts all the filter blocks. It now inserts the headings as child blocks.

Closes #42055

How to test the changes in this Pull Request:

  1. You can firstly insert the new collection filters block in the editor. You should see that inner heading blocks are inserted. You can test that it saves by updating / saving and then reload the page to ensure the inner heading blocks are retained.

  2. Each block has different conditions in which it will not render. Rating can be tested for example, by ensuring you have no product reviews. (In my test site I just manually delete them all). Once this is done, view the frontend page corresponding to your collection filters and see that nothing is rendered for the rating filter.

  3. for Price Filter it should pretty much always render unless something has gone wrong. (I might not have considered edge cases here, please enlighten me if I have missed some).

  4. for Stock Status filter TBD

  5. for active filters, nothing should render unless at least one filter is active on the page. e.g. with no query params on the page the heading should not render. If you choose a single filter like price range, the heading should render along with the active filter.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

Hide block headings when there are no filter options for experimental collection filter blocks.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Dec 26, 2023
@woocommercebot woocommercebot requested review from a team and imanish003 and removed request for a team December 26, 2023 04:26
@samueljseay samueljseay removed the request for review from imanish003 December 26, 2023 04:27
@samueljseay samueljseay changed the base branch from dev/dropdown-support-text-color to trunk December 26, 2023 04:28
@samueljseay samueljseay changed the base branch from trunk to dev/dropdown-support-text-color December 26, 2023 04:29
Copy link
Contributor

github-actions bot commented Dec 26, 2023

Test Results Summary

Commit SHA: cb24302

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 37s
E2E Tests258003026114m 38s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@woocommerce woocommerce deleted a comment from github-actions bot Dec 26, 2023
@dinhtungdu dinhtungdu self-requested a review December 26, 2023 10:18
Copy link
Contributor

Hi @dinhtungdu,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Copy link
Member

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

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

for Price Filter it should pretty much always render unless something has gone wrong. (I might not have considered edge cases here, please enlighten me if I have missed some).

There is also a case when there is only one simple product, the min and max price is equal, the Price filter shouldn't be render at that point. (I fixed that in https://github.com/woocommerce/woocommerce/pull/43112/files#diff-cae9a0f3ce62ffc67ce67010b5f92334df81848c280613e5f49c43d6819b3591R147-R152).

In my test site I just manually delete them all

Theoretically, rating can be tested with a filtered query that returns products without rating, but it doesn't work now with Store API. #42811 will fix that issue.

@@ -38,7 +43,6 @@ import { AttributeDropdown } from './components/attribute-dropdown';
import './style.scss';
import { extractBuiltInColor } from '../../utils';
import { useStyleProps } from '../../../../base/hooks';
import styled from '@emotion/styled';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused import leftover in the branch this branches from.

Copy link
Member

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

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

LGTM!

const template: Template[] = [
[
'core/heading',
{ content: __( 'Filter by Stock Status', 'woocommerce' ) },
Copy link
Member

Choose a reason for hiding this comment

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

The level is missing here.

@samueljseay samueljseay merged commit be7b261 into dev/dropdown-support-text-color Dec 27, 2023
23 of 26 checks passed
@samueljseay samueljseay deleted the dev/inner-headings-filter-blocks branch December 27, 2023 09:28
samueljseay added a commit that referenced this pull request Dec 28, 2023
…locks (#43068)

* [Experimental] Render headings as inner blocks of collection filters (#43109)
opr pushed a commit that referenced this pull request Jan 3, 2024
…locks (#43068)

* [Experimental] Render headings as inner blocks of collection filters (#43109)
vedanshujain pushed a commit that referenced this pull request Jan 9, 2024
…locks (#43068)

* [Experimental] Render headings as inner blocks of collection filters (#43109)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants