Search 3.0: hide the Off row of the feature-selector on WordPress.com (RSM-2400)#48558
Search 3.0: hide the Off row of the feature-selector on WordPress.com (RSM-2400)#48558adamwoodnz wants to merge 2 commits intotrunkfrom
Conversation
Mirrors the legacy `<ModuleControl>`'s `! isWpcom` gate around its "Enable Jetpack Search" toggle. On WordPress.com, search activation is managed from the .com side, so the new `<FeatureSelector>` shouldn't expose Off as a save target either. We were rendering all four rows regardless of platform, which would let a .com admin pick Off, hit Save, and dispatch `Modules::deactivate( 'search' )` — the exact action the legacy UI deliberately hides. Reads `isWpcom` via the existing store selector (seeded from `Helper::is_wpcom()` in `class-initial-state.php`), filters `EXPERIENCE_ORDER` to drop `EXPERIENCE.OFF` when true, and renders the filtered list. The legacy `<ModuleControl>` continues to render alongside the new selector while RSM-2291 lands, so admins on .com still see the instant-search-vs-classic toggle that ModuleControl already renders unconditionally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
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 2 files.
|
| expect( screen.getByRole( 'radio', { name: /embedded search/i } ) ).toBeInTheDocument(); | ||
| expect( screen.getByRole( 'radio', { name: /overlay search/i } ) ).toBeInTheDocument(); | ||
| expect( screen.getByRole( 'radio', { name: /theme search/i } ) ).toBeInTheDocument(); | ||
| expect( screen.queryByRole( 'radio', { name: /^off$/i } ) ).not.toBeInTheDocument(); |
There was a problem hiding this comment.
One tiny thing on this assertion — the Off radio's accessible name is computed from the whole <label>, so it actually ends up looking like "Off WordPress default search." (see how <ExperienceOption> lays out the title plus description inside the label, around experience-option.jsx:86-97). That means /^off$/i (anchored, exact-match) won't match even when the row is rendered, so this line would pass regardless of whether the Off row is gone.
The good news: the expect( radios ).toHaveLength( 3 ) above is what's actually proving the row is hidden, so the test is sound. Just this last line ends up being a tautology. If you want the negative assertion to pull its weight, maybe drop the anchors to /off/i (matches the substring form used in the existing tests on lines 37 and 92), or just delete it since the length check has us covered.
| ); | ||
| // On WordPress.com, search activation is managed from the .com side, so we | ||
| // hide the Off row here to mirror the legacy `<ModuleControl>`'s | ||
| // `! isWpcom` gate around the "Enable Jetpack Search" toggle. |
There was a problem hiding this comment.
Small wording suggestion — and to be clear this isn't your invention, the same loose phrasing lives in the legacy <ModuleControl> comment already. But while we're here:
Helper::is_wpcom() only checks the IS_WPCOM constant, which is defined on Simple sites and not on Atomic/WoA. So in practice an Atomic admin will still see the Off row here. That's actually correct behavior — the legacy <ModuleControl> gate has the same Simple-only meaning, so we're at parity — but a future reader scanning the comment might assume "WordPress.com" includes Atomic and get confused. Mind tightening to something like "On WordPress.com Simple sites" or "where IS_WPCOM is defined"? Just so the Atomic case isn't ambiguous.
| // On WordPress.com, search activation is managed from the .com side, so we | ||
| // hide the Off row here to mirror the legacy `<ModuleControl>`'s | ||
| // `! isWpcom` gate around the "Enable Jetpack Search" toggle. | ||
| const isWpcom = useSelect( select => select( STORE_ID ).isWpcom(), [] ); |
There was a problem hiding this comment.
Tiny style musing, totally take or leave: this brings the component to five useSelect calls. Could batch them into a single call that returns an object — experience-option.jsx:34-40 already does that for two values and reads nicely. Pre-existing pattern in this file though, so happy to leave it for a follow-up if you'd rather keep this PR tight.
|
Intentional for now while the backend isn't ready. Without the old UI you can't change settings 🙂 |
- Batch the five useSelect calls into one returning an object, matching the pattern already used in experience-option.jsx. - Clarify the WPcom comment: only Simple sites (where IS_WPCOM is defined) hit this gate, not Atomic. - Drop the anchors on the negative Off-row matcher so the regex actually matches the row's accessible name; the toHaveLength(3) above is the load-bearing check, but the assertion now pulls its weight too.


Fixes RSM-2400
Why
WordPress.com admins on the Search dashboard manage Search activation through the .com side, so the legacy
<ModuleControl>deliberately hides its "Enable Jetpack Search" toggle on .com. The new feature-selector (shipped behindjetpack_search_blocks_enabledin #48500) was rendering all four rows regardless of platform, which would let a .com admin pick Off, hit Save, and triggerModules::deactivate( 'search' )— the exact action the legacy UI hides. This PR brings the new selector to platform parity.Proposed changes
<FeatureSelector>now reads the existingisWpcomselector (seeded fromHelper::is_wpcom()inclass-initial-state.php) and filtersEXPERIENCE_ORDERto dropEXPERIENCE.OFFwhen true. The remaining rows (Embedded / Overlay / Theme search) render unchanged.hides the Off row on WordPress.com (parity with legacy ModuleControl)seedssiteData: { isWpcom: true }and asserts the Off radio is absent while the other three are present.Related product discussion/links
experiencefield in settings API (RSM-2291) #48540 (RSM-2291, back-end persistence)Does this pull request change what data or activity we track or use?
No.
Testing instructions
The whole feature-selector is gated behind
jetpack_search_blocks_enabled, so set that on a test site to see the new UI. The legacy<ModuleControl>continues to render alongside the new selector, so admins on .com retain the instant-search-vs-classic toggle that ModuleControl already shows unconditionally.Automated
Expected: 17 tests pass across 2 suites.
Manual
jetpack_search_blocks_enabledreturningtrue.Helper::is_wpcom()returns true), open the same dashboard.<ModuleControl>continues to render its instant-search toggle on .com (its own module-active toggle remains hidden, same as before this PR).