Skip to content

Search: add jetpack-search/filter-static block (SEARCH-219)#49030

Closed
kangzj wants to merge 1 commit into
trunkfrom
search-219-filter-static-block
Closed

Search: add jetpack-search/filter-static block (SEARCH-219)#49030
kangzj wants to merge 1 commit into
trunkfrom
search-219-filter-static-block

Conversation

@kangzj
Copy link
Copy Markdown
Contributor

@kangzj kangzj commented May 21, 2026

Fixes SEARCH-219

Proposed changes

  • New Search 3.0 block jetpack-search/filter-static mirroring the legacy instant-search overlay's static-filter widget — a single-select radio list whose options come from server config (no per-instance editor UI for values).
  • Options resolve from the existing jetpack_instant_search_options hook (so sites already wired up for the legacy overlay get the blocks for free) and from a narrower sibling jetpack_search_static_filters for blocks-only registrations.
  • Selections round-trip as scalar ?filter_id=value URL params — matches the legacy contract so deep links stay interchangeable between the overlay and the blocks surface. New sibling state slice staticFilterSelections follows the priceRange precedent (also scalar, also a sibling slice), gated on filterConfigs[key].kind === 'static' to prevent stale or plugin-emitted scalar params from leaking back into the URL.
  • ES term clauses ({ term: { <filter_id>: <value> } }) folded into the existing bool.must pipeline so the static filter applies alongside dynamic facet selections.
  • New REST route GET /jetpack-search/v1/static-filters?variation=<sidebar|tabbed> (permission edit_posts) backs the editor inspector's filter-id picker.
  • Falls under the existing jetpack_search_blocks_enabled gate — no new flag.
  • Test coverage:
    • 15 new PHPUnit cases (Filter_Static_Test) for get_static_filters_config (both hooks, last-wins on duplicates, reserved-param rejection, empty-values rejection), filters_for_variation, normalize_variation, build_config, derive_label, parse_url_selections.
    • 21 new Jest cases across url-state, api, and store for the scalar URL serialization branch, the kind === 'static' parse gate, buildStaticFilterClauses, buildSearchUrl integration, setStaticFilter single-select semantics, clearFilters reset, and gateStaticFilterSelections.

Related product discussion/links

  • Linear: SEARCH-219 (Jetpack Search blocks project)
  • Legacy reference: projects/packages/search/src/instant-search/components/search-filter.jsx:225-245 (renderGroup) and store/effects.js:176-187 (URL update).

Does this pull request change what data or activity we track or use?

No — purely client-side UI state and ES query construction. No new tracking events; no new data collection.

Testing instructions

A site needs to register at least one static filter for the block to render anything. Drop this into an mu-plugin:

```php
add_filter( 'jetpack_search_static_filters', function () {
return [ [
'filter_id' => 'section',
'name' => 'Section',
'type' => 'group',
'variation' => 'sidebar',
'selected' => '',
'values' => [
[ 'name' => 'News', 'value' => 'news' ],
[ 'name' => 'Guides', 'value' => 'guides' ],
],
] ];
} );
```

Build + enable Search 3.0 blocks (jetpack_search_blocks_enabled=true), then:

  • Insert "Static Filter" on a page that also has `search-results`. In the inspector, confirm the "Filter" SelectControl lists "Section" (REST round-trip).
  • Page load with no URL param: two radios appear, none checked. Server-rendered `` with `data-wp-interactive="jetpack-search"` and ``.
  • Click Guides: URL becomes `?section=guides` (scalar — no `[]`). Network shows one search request with `bool.filter` carrying `{ term: { section: 'guides' } }`.
  • Reload `?section=guides`: "Guides" radio stays checked, results stay filtered.
  • Pick News: URL `section` replaces (does not append) — confirms single-select semantics.
  • Re-pick the currently selected radio: clears the filter (`?section=` is dropped from the URL).
  • Disable the host filter (return `[]`): block renders nothing on the front end; editor Placeholder shows an empty-state message.
  • Confirm the "Tabbed" variation in the inspector renders only the tabbed-registered filters (registered with `variation => 'tabbed'`).

Mirrors the legacy instant-search overlay's static-filter widget as a
Search 3.0 block. Options come from server config via the
jetpack_search_static_filters PHP filter (or the legacy
jetpack_instant_search_options blob's `staticFilters` key, picked up
automatically). The block renders a single-select radio list whose
selection round-trips through scalar `?filter_id=value` URL params,
matching the legacy contract so deep links stay interchangeable between
the two surfaces.

A new sibling state slice `staticFilterSelections` (paired with the
existing `priceRange` precedent) keeps the URL serializer free of
sentinel encodings on `activeFilters` — gated on
`filterConfigs[key].kind === 'static'` so a stale scalar param from a
since-removed registration can't leak back into the URL.

REST route `GET /jetpack-search/v1/static-filters?variation=<v>` backs
the editor inspector's filter-id picker.

Falls under the existing `jetpack_search_blocks_enabled` gate — no new
flag.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the search-219-filter-static-block branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack search-219-filter-static-block

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added [Package] Search Contains core Search functionality for Jetpack and Search plugins [Tests] Includes Tests labels May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 21, 2026
@jp-launch-control
Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/packages/search/src/search-blocks/class-search-blocks.php 488/704 (69.32%) 0.34% 6 💔
projects/packages/search/src/search-blocks/store/index.js 451/528 (85.42%) -0.24% 6 💔
projects/packages/search/src/search-blocks/store/url-state.js 83/84 (98.81%) 0.14% 0 💚
projects/packages/search/src/search-blocks/store/api.js 180/185 (97.30%) 0.71% -1 💚

4 files are newly checked for coverage.

File Coverage
projects/packages/search/src/search-blocks/blocks/filter-static/edit.js 0/33 (0.00%) 💔
projects/packages/search/src/search-blocks/blocks/filter-static/render.php 0/58 (0.00%) 💔
projects/packages/search/src/search-blocks/blocks/filter-static/class-filter-static.php 102/106 (96.23%) 💚
projects/packages/search/src/search-blocks/blocks/filter-static/view.js 0/0 (—%) 🤷

Full summary · PHP report · JS report

If appropriate, add one of these labels to override the failing coverage check: Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage.

@kangzj kangzj self-assigned this May 21, 2026
@kangzj
Copy link
Copy Markdown
Contributor Author

kangzj commented May 21, 2026

Split into three smaller, sequential PRs for easier review (each under ~500 lines of implementation):

Same scope, same SEARCH-219 issue. Reviewing them in order (1 → 2 → 3) lets you focus on one concern at a time, and the foundations (1 and 2) are independently reviewable since both are inert until 3 lands.

Refactor for readability that went in after this PR was opened is rolled into each split commit.

@kangzj kangzj closed this May 21, 2026
@github-actions github-actions Bot removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Search Contains core Search functionality for Jetpack and Search plugins [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant