Search: add jetpack-search/filter-static block (SEARCH-219)#49030
Search: add jetpack-search/filter-static block (SEARCH-219)#49030kangzj wants to merge 1 commit into
Conversation
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.
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 4 files.
4 files are newly checked for coverage.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
|
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. |
Fixes SEARCH-219
Proposed changes
jetpack-search/filter-staticmirroring 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).jetpack_instant_search_optionshook (so sites already wired up for the legacy overlay get the blocks for free) and from a narrower siblingjetpack_search_static_filtersfor blocks-only registrations.?filter_id=valueURL params — matches the legacy contract so deep links stay interchangeable between the overlay and the blocks surface. New sibling state slicestaticFilterSelectionsfollows thepriceRangeprecedent (also scalar, also a sibling slice), gated onfilterConfigs[key].kind === 'static'to prevent stale or plugin-emitted scalar params from leaking back into the URL.{ term: { <filter_id>: <value> } }) folded into the existingbool.mustpipeline so the static filter applies alongside dynamic facet selections.GET /jetpack-search/v1/static-filters?variation=<sidebar|tabbed>(permissionedit_posts) backs the editor inspector's filter-id picker.jetpack_search_blocks_enabledgate — no new flag.Filter_Static_Test) forget_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.url-state,api, andstorefor the scalar URL serialization branch, thekind === 'static'parse gate,buildStaticFilterClauses,buildSearchUrlintegration,setStaticFiltersingle-select semantics,clearFiltersreset, andgateStaticFilterSelections.Related product discussion/links
projects/packages/search/src/instant-search/components/search-filter.jsx:225-245(renderGroup) andstore/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: