From 2d41950fa5811e00ed20af1c63352f8f44f8b703 Mon Sep 17 00:00:00 2001 From: Rhys Date: Mon, 3 Jun 2024 11:08:04 -0400 Subject: [PATCH] chore(settings): add show gen ai sample docs setting feature flag (#5781) --- .../src/feature-flags.ts | 14 +++ .../settings/gen-ai-settings.spec.tsx | 97 +++++++++++++++++++ .../components/settings/gen-ai-settings.tsx | 13 +-- 3 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 packages/compass-settings/src/components/settings/gen-ai-settings.spec.tsx diff --git a/packages/compass-preferences-model/src/feature-flags.ts b/packages/compass-preferences-model/src/feature-flags.ts index 75a6f59ce8d..51a498d4c21 100644 --- a/packages/compass-preferences-model/src/feature-flags.ts +++ b/packages/compass-preferences-model/src/feature-flags.ts @@ -19,6 +19,7 @@ export type FeatureFlags = { showInsights: boolean; enableRenameCollectionModal: boolean; enableNewMultipleConnectionSystem: boolean; + showGenAIPassSampleDocumentsSetting: boolean; }; export const featureFlags: Required<{ @@ -73,4 +74,17 @@ export const featureFlags: Required<{ long: 'Allows users to open multiple connections in the same window.', }, }, + + /** + * Feature flag for showing the option to pass sample documents with our query and aggregation generation requests. + * Enables showing the `enableGenAISampleDocumentPassing` setting in the settings UI so folks can turn it on. + * Epic: COMPASS-7584 + */ + showGenAIPassSampleDocumentsSetting: { + stage: 'development', + description: { + short: 'Enable showing the sample document gen ai setting.', + long: 'Allows users to show a setting to enable the passing of sample field values with our query and aggregation generation requests.', + }, + }, }; diff --git a/packages/compass-settings/src/components/settings/gen-ai-settings.spec.tsx b/packages/compass-settings/src/components/settings/gen-ai-settings.spec.tsx new file mode 100644 index 00000000000..0a5d8543310 --- /dev/null +++ b/packages/compass-settings/src/components/settings/gen-ai-settings.spec.tsx @@ -0,0 +1,97 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import { expect } from 'chai'; +import { Provider } from 'react-redux'; + +import { GenAISettings } from './gen-ai-settings'; +import configureStore from '../../../test/configure-store'; +import { fetchSettings } from '../../stores/settings'; + +function renderGenAiSettings({ + store = configureStore(), + props, +}: { + store: ReturnType; + props?: Partial>; +}) { + return render( + + + + ); +} + +const sampleDocsSettingText = + 'Enable sending sample field values with query and aggregation generation requests'; +const atlasLoginSettingText = 'You must log in with an Atlas account to use '; + +describe('GenAISettings', function () { + let container: HTMLElement; + let store: ReturnType; + + describe('when the isAIFeatureEnabled prop is false', function () { + beforeEach(async function () { + store = configureStore(); + await store.dispatch(fetchSettings()); + renderGenAiSettings({ + store, + props: { + isAIFeatureEnabled: false, + }, + }); + container = screen.getByTestId('gen-ai-settings'); + }); + + it('does not show the atlas login setting', function () { + expect(container).to.not.include.text(atlasLoginSettingText); + }); + }); + + describe('when the isAIFeatureEnabled setting is true', function () { + beforeEach(async function () { + store = configureStore(); + await store.dispatch(fetchSettings()); + }); + + it('shows the atlas login setting', function () { + renderGenAiSettings({ + store, + }); + container = screen.getByTestId('gen-ai-settings'); + expect(container).to.include.text(atlasLoginSettingText); + }); + + describe('when the showGenAIPassSampleDocumentsSetting feature flag is disabled', function () { + beforeEach(function () { + renderGenAiSettings({ + store, + }); + container = screen.getByTestId('gen-ai-settings'); + }); + + it('does not show the enableGenAISampleDocumentPassing setting', function () { + expect(container).to.not.include.text(sampleDocsSettingText); + }); + }); + + describe('when the showGenAIPassSampleDocumentsSetting feature flag is enabled', function () { + beforeEach(function () { + renderGenAiSettings({ + store, + props: { + showGenAIPassSampleDocumentsSetting: true, + }, + }); + container = screen.getByTestId('gen-ai-settings'); + }); + + it('does not show the enableGenAISampleDocumentPassing setting', function () { + expect(container).to.include.text(sampleDocsSettingText); + }); + }); + }); +}); diff --git a/packages/compass-settings/src/components/settings/gen-ai-settings.tsx b/packages/compass-settings/src/components/settings/gen-ai-settings.tsx index 2e9abac1dcb..087cc802de6 100644 --- a/packages/compass-settings/src/components/settings/gen-ai-settings.tsx +++ b/packages/compass-settings/src/components/settings/gen-ai-settings.tsx @@ -12,7 +12,8 @@ const atlasSettingsContainerStyles = css({ export const GenAISettings: React.FunctionComponent<{ isAIFeatureEnabled: boolean; -}> = ({ isAIFeatureEnabled }) => { + showGenAIPassSampleDocumentsSetting: boolean; +}> = ({ isAIFeatureEnabled, showGenAIPassSampleDocumentsSetting }) => { return (
@@ -27,11 +28,9 @@ export const GenAISettings: React.FunctionComponent<{
- {/* TODO(COMPASS-7865): We're currently sending our sample field values to the server - and into the ai prompt as regular JSON. This means the AI isn't generating good - results with certain bson types. It'll take a bit of work server - side for us to do this. In the meantime we are hiding this setting. */} - {/* */} + {showGenAIPassSampleDocumentsSetting && ( + + )} )}
@@ -40,6 +39,8 @@ export const GenAISettings: React.FunctionComponent<{ const mapState = (state: RootState) => ({ isAIFeatureEnabled: !!state.settings.settings.enableGenAIFeatures, + showGenAIPassSampleDocumentsSetting: + !!state.settings.settings.showGenAIPassSampleDocumentsSetting, }); export default connect(mapState, null)(GenAISettings);