Skip to content

Commit 5454786

Browse files
authored
chore(compass-assistant): hide the drawer if AI features are disabled (#7291)
We had a change for this which ended up only applying to entry points, so this adds this to the sidebar itself.
1 parent e864723 commit 5454786

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

packages/compass-assistant/src/compass-assistant-drawer.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import {
1414
AssistantActionsContext,
1515
AssistantContext,
1616
} from './compass-assistant-provider';
17-
import { usePreference } from 'compass-preferences-model/provider';
17+
import {
18+
useIsAIFeatureEnabled,
19+
usePreference,
20+
} from 'compass-preferences-model/provider';
1821

1922
const assistantTitleStyles = css({
2023
display: 'flex',
@@ -39,6 +42,7 @@ export const CompassAssistantDrawer: React.FunctionComponent<{
3942
const { clearChat } = useContext(AssistantActionsContext);
4043

4144
const enableAIAssistant = usePreference('enableAIAssistant');
45+
const isAiFeatureEnabled = useIsAIFeatureEnabled();
4246

4347
const handleClearChat = useCallback(async () => {
4448
const confirmed = await showConfirmation({
@@ -54,7 +58,7 @@ export const CompassAssistantDrawer: React.FunctionComponent<{
5458
}
5559
}, [clearChat]);
5660

57-
if (!enableAIAssistant) {
61+
if (!enableAIAssistant || !isAiFeatureEnabled) {
5862
return null;
5963
}
6064

packages/compass-assistant/src/compass-assistant-provider.spec.tsx

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,67 @@ describe('CompassAssistantProvider', function () {
234234
expect(screen.getByTestId('provider-children')).to.exist;
235235
});
236236

237-
it('does not render assistant drawer when AI assistant is disabled', function () {
238-
render(<TestComponent chat={createMockChat({ messages: [] })} />, {
239-
preferences: {
240-
enableAIAssistant: false,
241-
enableGenAIFeatures: true,
242-
enableGenAIFeaturesAtlasOrg: true,
243-
cloudFeatureRolloutAccess: { GEN_AI_COMPASS: true },
244-
},
237+
describe('disabling the Assistant', function () {
238+
it('does not render assistant drawer when AI assistant is disabled', function () {
239+
render(<TestComponent chat={createMockChat({ messages: [] })} />, {
240+
preferences: {
241+
enableAIAssistant: false,
242+
enableGenAIFeatures: true,
243+
enableGenAIFeaturesAtlasOrg: true,
244+
cloudFeatureRolloutAccess: { GEN_AI_COMPASS: true },
245+
},
246+
});
247+
248+
expect(screen.getByTestId('provider-children')).to.exist;
249+
// The drawer toolbar button should not exist when disabled
250+
expect(screen.queryByLabelText('MongoDB Assistant')).to.not.exist;
245251
});
246252

247-
expect(screen.getByTestId('provider-children')).to.exist;
248-
// The drawer toolbar button should not exist when disabled
249-
expect(screen.queryByLabelText('MongoDB Assistant')).to.not.exist;
253+
it('does not render assistant drawer when AI features are disabled via isAIFeatureEnabled', function () {
254+
render(<TestComponent chat={createMockChat({ messages: [] })} />, {
255+
preferences: {
256+
enableAIAssistant: true,
257+
// These control isAIFeatureEnabled
258+
enableGenAIFeatures: false,
259+
enableGenAIFeaturesAtlasOrg: true,
260+
cloudFeatureRolloutAccess: { GEN_AI_COMPASS: true },
261+
},
262+
});
263+
264+
expect(screen.getByTestId('provider-children')).to.exist;
265+
// The drawer toolbar button should not exist when AI features are disabled
266+
expect(screen.queryByLabelText('MongoDB Assistant')).to.not.exist;
267+
});
268+
269+
it('does not render assistant drawer when Atlas org AI features are disabled', function () {
270+
render(<TestComponent chat={createMockChat({ messages: [] })} />, {
271+
preferences: {
272+
enableAIAssistant: true,
273+
enableGenAIFeatures: true,
274+
enableGenAIFeaturesAtlasOrg: false,
275+
cloudFeatureRolloutAccess: { GEN_AI_COMPASS: true },
276+
},
277+
});
278+
279+
expect(screen.getByTestId('provider-children')).to.exist;
280+
// The drawer toolbar button should not exist when Atlas org AI features are disabled
281+
expect(screen.queryByLabelText('MongoDB Assistant')).to.not.exist;
282+
});
283+
284+
it('does not render assistant drawer when cloud feature rollout access is disabled', function () {
285+
render(<TestComponent chat={createMockChat({ messages: [] })} />, {
286+
preferences: {
287+
enableAIAssistant: true,
288+
enableGenAIFeatures: true,
289+
enableGenAIFeaturesAtlasOrg: true,
290+
cloudFeatureRolloutAccess: { GEN_AI_COMPASS: false },
291+
},
292+
});
293+
294+
expect(screen.getByTestId('provider-children')).to.exist;
295+
// The drawer toolbar button should not exist when cloud feature rollout access is disabled
296+
expect(screen.queryByLabelText('MongoDB Assistant')).to.not.exist;
297+
});
250298
});
251299

252300
it('renders the assistant drawer as the first drawer item when AI assistant is enabled', function () {

0 commit comments

Comments
 (0)