Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Search dashboard: hide the Off row of the new feature-selector on WordPress.com, matching the legacy module control's behaviour.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { Button, Stack } from '@wordpress/ui';
import { STORE_ID } from 'store';
import { EXPERIENCE_ORDER } from './constants';
import { EXPERIENCE, EXPERIENCE_ORDER } from './constants';
import ExperienceOption from './experience-option';
import './style.scss';

Expand All @@ -18,15 +18,26 @@ import './style.scss';
* @return {import('react').Element} - The selector.
*/
export default function FeatureSelector() {
const isDirty = useSelect( select => select( STORE_ID ).isDirty(), [] );
const isUpdating = useSelect( select => select( STORE_ID ).isUpdatingJetpackSettings(), [] );
const pendingExperience = useSelect( select => select( STORE_ID ).getPendingExperience(), [] );
const supportsOnlyClassicSearch = useSelect(
select => select( STORE_ID ).supportsOnlyClassicSearch(),
// On WordPress.com Simple sites (where `IS_WPCOM` is defined), 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 { isDirty, isUpdating, pendingExperience, supportsOnlyClassicSearch, isWpcom } = useSelect(
select => ( {
isDirty: select( STORE_ID ).isDirty(),
isUpdating: select( STORE_ID ).isUpdatingJetpackSettings(),
pendingExperience: select( STORE_ID ).getPendingExperience(),
supportsOnlyClassicSearch: select( STORE_ID ).supportsOnlyClassicSearch(),
isWpcom: select( STORE_ID ).isWpcom(),
} ),
[]
);
const { saveExperience } = useDispatch( STORE_ID );

const visibleExperiences = isWpcom
? EXPERIENCE_ORDER.filter( experience => experience !== EXPERIENCE.OFF )
: EXPERIENCE_ORDER;

const isExperienceDisabled = experience =>
supportsOnlyClassicSearch && ( experience === 'embedded' || experience === 'overlay' );

Expand All @@ -51,7 +62,7 @@ export default function FeatureSelector() {
aria-labelledby="jp-search-feature-selector-heading"
>
<Stack direction="column" gap="sm">
{ EXPERIENCE_ORDER.map( experience => (
{ visibleExperiences.map( experience => (
<ExperienceOption
key={ experience }
experience={ experience }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,28 @@ describe( '<FeatureSelector>', () => {
expect( screen.getByRole( 'radio', { name: /theme search/i } ) ).toBeEnabled();
expect( screen.getByRole( 'radio', { name: /off/i } ) ).toBeEnabled();
} );

test( 'hides the Off row on WordPress.com (parity with legacy ModuleControl)', () => {
const registry = createRegistry();
const store = createReduxStore( STORE_ID, {
...storeConfig,
initialState: {
...( storeConfig.initialState || {} ),
jetpackSettings: baseSettings,
siteData: { isWpcom: true },
},
} );
registry.register( store );
render(
<RegistryProvider value={ registry }>
<FeatureSelector />
</RegistryProvider>
);
const radios = screen.getAllByRole( 'radio' );
expect( radios ).toHaveLength( 3 );
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();
} );
} );
Loading