Skip to content

Enhanced query filter blocks [rebased and updated]#39

Open
goldenapples wants to merge 5 commits intomainfrom
enhanced-query-filter-blocks-updated
Open

Enhanced query filter blocks [rebased and updated]#39
goldenapples wants to merge 5 commits intomainfrom
enhanced-query-filter-blocks-updated

Conversation

@goldenapples
Copy link
Copy Markdown

See #25 - this is the same branch, just cleaned up with phpcbf to follow the formatting standards of this project.

@goldenapples goldenapples force-pushed the enhanced-query-filter-blocks-updated branch 3 times, most recently from 167000c to 2ee049c Compare March 4, 2026 21:14
Thomas Navarro and others added 3 commits March 4, 2026 16:16
… direction

- Updated package.json to include @wordpress/env as a dev dependency.
- Added new attributes `displayType` and `layoutDirection` to block.json for post-type and taxonomy blocks.
- Modified the Edit component for post-type and taxonomy blocks to include SelectControl for display type and ToggleGroupControl for layout direction.
- Implemented conditional rendering for select, radio, and checkbox inputs based on the selected display type.
- Updated render.php files for post-type and taxonomy blocks to handle new display type and layout direction attributes.
- Added styles for radio and checkbox groups in style-index.css to support vertical and horizontal layouts.
- refactor: Remove shared styles registration and update label classes in taxonomy render

Build changes to render files
Copy link
Copy Markdown

@kadamwhite kadamwhite left a comment

Choose a reason for hiding this comment

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

The patch looks sensible and I didn't see any blocking issues while reviewing, :shipit: !

Only called out a few areas where we could conceivably clean up apparently-duplicated UI and options code, and asked about whether the boolean tax query logic should be more explicitly spelled out in a comment.

Note: have not tested locally.

'taxonomy' => $key,
'terms' => $values,
'field' => 'slug',
'operator' => 'IN', // This creates OR logic
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Might be good to expand this comment to explicitly clarify the relationship between 'operator' and $tax_query['relation'] = 'AND', above — I've seen this lead to confusion in other projects

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Update in b31e558. I'm also not sure if we should add an option for this logic on the filter settings. This IN logic seems like the most common use case to me, but I have seen faceting controls where selecting an additional term is expected to drill down into results rather than widening the search.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

My default approach to filtering (and what I think most users expect / understand intuitively) is OR between multiple Terms in a Taxonomy and AND between multiple Taxonomies. Which is what is being done now. But more code comments can't hurt. I think if there's a setting it should be user-facing which may a bigger discussion for the dev team? Thanks for working on the PR though. Can't want to have multiple form options merged into the main branch!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agreed with @goldenapples, IN logic seems like the most common use case to me as well. No need for an extra setting right now IMO.

<SelectControl
label={ __( 'Display Type', 'query-filter' ) }
value={ displayType }
options={ [
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nitpick, since these options are static (not dependent on other state) I'd recommend to hoist them up to a const DISPLAY_TYPE_OPTIONS or some such in the parent file scope outside of this component. Not blocking, strictly a preference thing; this doesn't get called in a loop enough that the recreated object reference would be a problem.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'd also like to see something of this nature, but I'd like to see that done as part of a bigger refactoring of display types. Ultimately each of these display types contains a lot of reusable logic that could be abstracted out, but I don't want to do a naive refactoring of a codebase I'm not fully familiar with and potentially make it harder to add new filter types in the future.

/>
{ ( displayType === 'radio' ||
displayType === 'checkbox' ) && (
<ToggleGroupControl
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this mean that direction is not relevant with displayType === 'select' -- and if so, should the onChange for the displayType reset this to vertical if "select" is chosen? We don't use the layout option in select mode, today, but it doesn't read like we'd otherwise "reset" to the default vertical value if we switch off of the radio/checkbox options that allow for horizontal layout

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That makes sense to me. Is something like 862cfa7 what you have in mind?

<SelectControl
label={ __( 'Display Type', 'query-filter' ) }
value={ displayType }
options={ [
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Realized these options are repeated, inclusive of their selection UI; worth extracting these components and sharing them between the taxonomy and post type blocks...?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I definitely think so - especially as we're considering adding other filters like Author (#23). But I think that refactor can be done in a separate PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is an inconsistency in the apiVersion across the blocks, perhaps it would be a good idea to standardise this in this PR as well and set it to v3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants