Skip to content

Commit dd99ac3

Browse files
authored
Fixed Jetpack Aearch AI answers toggle (#48777)
* Fixed bug where disabling the AI answers feature was not working * changelog
1 parent 707d545 commit dd99ac3

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
AI answers feature disable toggle was not working. Fixed.

projects/packages/search/src/dashboard/components/ai-answers-tab/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default function AiAnswersTab() {
108108
checked={ isAiAnswersEnabled }
109109
onChange={ setAiAnswersEnabled }
110110
className="jp-search-dashboard-toggle lg-col-span-12 md-col-span-8 sm-col-span-4"
111-
disabled={ ! isInstantSearchEnabled }
111+
disabled={ ! isInstantSearchEnabled && ! isAiAnswersEnabled }
112112
/>
113113

114114
{ ! isLoading && ! isUnavailable && (

projects/packages/search/src/dashboard/components/test/ai-answers-tab.test.jsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ jest.mock( '@wordpress/data', () => ( {
2525

2626
jest.mock( '@wordpress/components', () => ( {
2727
TextareaControl: ( { label } ) => <span>{ label }</span>,
28-
ToggleControl: ( { label, checked, onChange } ) => (
28+
ToggleControl: ( { label, checked, onChange, disabled } ) => (
2929
<label htmlFor="toggle-control">
3030
<input
3131
id="toggle-control"
3232
type="checkbox"
3333
checked={ checked }
3434
onChange={ e => onChange( e.target.checked ) }
35+
disabled={ disabled }
3536
/>
3637
{ label }
3738
</label>
@@ -155,4 +156,18 @@ describe( 'AiAnswersTab', () => {
155156
screen.findByText( 'Instant Search must be enabled for AI Answers to work.' )
156157
).resolves.toBeInTheDocument();
157158
} );
159+
160+
it( 'toggle is not disabled when instant search is off but AI answers is already on', async () => {
161+
setupStore( { isInstantSearchEnabled: false, isAiAnswersEnabled: true } );
162+
render( <AiAnswersTab /> );
163+
const toggle = await screen.findByRole( 'checkbox' );
164+
expect( toggle ).toBeEnabled();
165+
} );
166+
167+
it( 'toggle is disabled when both instant search and AI answers are off', async () => {
168+
setupStore( { isInstantSearchEnabled: false, isAiAnswersEnabled: false } );
169+
render( <AiAnswersTab /> );
170+
const toggle = await screen.findByRole( 'checkbox' );
171+
expect( toggle ).toBeDisabled();
172+
} );
158173
} );

projects/packages/search/src/dashboard/store/actions/jetpack-settings.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ const getRollbackSettings = settings =>
2626
k === 'module_active' ||
2727
k === 'instant_search_enabled' ||
2828
k === 'experience' ||
29-
k === 'reader_chat'
29+
k === 'reader_chat' ||
30+
k === 'ai_answers_enabled' ||
31+
k === 'search_suggestions_enabled'
3032
)
3133
);
3234

0 commit comments

Comments
 (0)