-
Notifications
You must be signed in to change notification settings - Fork 245
feat(compass-generative-ai): Add plugin to generative ai package to show opt-in for project setting in DE COMPASS-8378 #6489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
c2025de
moving prefs up nit from prev ticket
ruchitharajaghatta c8ae0da
new modal and plugin
ruchitharajaghatta ae6fa98
removing console log
ruchitharajaghatta ab8a8eb
review comments and checking for userPref
ruchitharajaghatta 842007a
review comments and checking for userPref
ruchitharajaghatta be9d03d
PR comments
ruchitharajaghatta f116d9e
PR comments
ruchitharajaghatta ee684c7
reducer name change bug
ruchitharajaghatta cdbfa92
fixing post request
ruchitharajaghatta c09dd67
fixing test setup failures
ruchitharajaghatta 8cda9e9
new test and sign in test fixes
ruchitharajaghatta 102306b
Merge branch 'main' of github.com:mongodb-js/compass into COMPASS-8378
ruchitharajaghatta 514816c
test fixes and package.json fix
ruchitharajaghatta 59bdf04
state name update
ruchitharajaghatta d2c0290
test and reducer bug fixes
ruchitharajaghatta 3803589
commenting out errors for evg patch
ruchitharajaghatta ce2cccd
fixing reducer type and entrypoint
ruchitharajaghatta b41dbda
npm check fix
ruchitharajaghatta 618d1de
removing ts-expect-errors
ruchitharajaghatta 222487e
Merge branch 'main' of github.com:mongodb-js/compass into COMPASS-8378
ruchitharajaghatta 5feb8fd
prettier fix
ruchitharajaghatta ce93dd2
taking out duplicated function
ruchitharajaghatta 587e4ec
addressing changes to modal
ruchitharajaghatta e0c897d
fixing flag for disabling opt in
ruchitharajaghatta 5fbf83f
nit:
ruchitharajaghatta 0f554dc
nits and fixing optin modal/refctoring for projid
ruchitharajaghatta 712aefb
merge main
ruchitharajaghatta 072e8d6
fixing projectID prop
ruchitharajaghatta b69f37f
optin modal test
ruchitharajaghatta f93424a
test tweak
ruchitharajaghatta baedb84
nit comment
ruchitharajaghatta 2860198
Merge branch 'main' of github.com:mongodb-js/compass into COMPASS-8378
ruchitharajaghatta 70d3566
fixing projectId
ruchitharajaghatta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
packages/compass-generative-ai/src/components/ai-optin-modal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import React from 'react'; | ||
| import { connect } from 'react-redux'; | ||
| import { | ||
| Banner, | ||
| Body, | ||
| Link, | ||
| ConfirmationModal, | ||
| SpinLoader, | ||
| css, | ||
| spacing, | ||
| H3, | ||
| palette, | ||
| } from '@mongodb-js/compass-components'; | ||
| import { AISignInImageBanner } from './ai-signin-banner-image'; | ||
| import { closeOptInModal, optIn } from '../store/atlas-optin-reducer'; | ||
| import type { RootState } from '../store/atlas-ai-store'; | ||
| import { usePreference } from 'compass-preferences-model/provider'; | ||
|
|
||
| const GEN_AI_FAQ_LINK = 'https://www.mongodb.com/docs/generative-ai-faq/'; | ||
|
|
||
| type OptInModalProps = { | ||
| isOptInModalVisible: boolean; | ||
| isOptInInProgress: boolean; | ||
| onOptInModalClose: () => void; | ||
| onOptInClick: () => void; | ||
| projectId: string; | ||
| }; | ||
|
|
||
| const titleStyles = css({ | ||
| marginBottom: spacing[400], | ||
| marginTop: spacing[400], | ||
| marginLeft: spacing[500], | ||
| marginRight: spacing[500], | ||
| textAlign: 'center', | ||
| }); | ||
|
|
||
| const bodyStyles = css({ | ||
| marginBottom: spacing[400], | ||
| marginTop: spacing[400], | ||
| marginLeft: spacing[300], | ||
| marginRight: spacing[300], | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'center', | ||
| textAlign: 'center', | ||
| }); | ||
|
|
||
| const disclaimer = css({ | ||
| color: palette.gray.dark1, | ||
| marginTop: spacing[400], | ||
| marginLeft: spacing[800], | ||
| marginRight: spacing[800], | ||
| }); | ||
|
|
||
| const banner = css({ | ||
ruchitharajaghatta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| padding: spacing[400], | ||
| marginTop: spacing[400], | ||
| textAlign: 'left', | ||
| }); | ||
|
|
||
| const featureStatusBannerVariant = (pIsOrgAiEnabled: boolean) => { | ||
| switch (true) { | ||
| case pIsOrgAiEnabled: | ||
| return 'info'; | ||
| default: | ||
| return 'warning'; | ||
| } | ||
| }; | ||
|
|
||
| function getFeatureStatusBannerText(pIsOrgAiEnabled: boolean) { | ||
| switch (true) { | ||
| case pIsOrgAiEnabled: | ||
| return 'AI features are enabled for project users with data access.'; | ||
|
|
||
| default: | ||
| return 'AI features are disabled for project users.'; | ||
| } | ||
ruchitharajaghatta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| const AIOptInModal: React.FunctionComponent<OptInModalProps> = ({ | ||
ruchitharajaghatta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ruchitharajaghatta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| isOptInModalVisible, | ||
| isOptInInProgress, | ||
| onOptInModalClose, | ||
| onOptInClick, | ||
| projectId, | ||
| }) => { | ||
| const isOrgAiEnabled = usePreference('enableGenAIFeaturesAtlasProject'); | ||
| const PROJECT_SETTINGS_LINK = | ||
| window.location.origin + '/v2/' + projectId + '#/settings/groupSettings'; | ||
|
|
||
| return ( | ||
| <ConfirmationModal | ||
| open={isOptInModalVisible} | ||
| onClose={onOptInModalClose} | ||
| title="" | ||
| // @ts-expect-error leafygreen only allows strings, but we need to pass icons | ||
| buttonText={ | ||
| <> | ||
ruchitharajaghatta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Opt in to Atlas to enable | ||
| {isOptInInProgress && ( | ||
| <> | ||
| | ||
| <SpinLoader darkMode={true}></SpinLoader> | ||
| </> | ||
| )} | ||
| </> | ||
| } | ||
| submitDisabled={isOrgAiEnabled} | ||
| onConfirm={() => { | ||
| if (isOptInInProgress) { | ||
| return; | ||
| } | ||
| onOptInClick(); | ||
| }} | ||
| onCancel={onOptInModalClose} | ||
| > | ||
| <Body className={bodyStyles}> | ||
| <AISignInImageBanner></AISignInImageBanner> | ||
ruchitharajaghatta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <H3 className={titleStyles}> | ||
| Use natural language to generate queries and pipelines | ||
| </H3> | ||
| Atlas users can now quickly create queries and aggregations with | ||
| MongoDB's intelligent AI-powered feature, available today. | ||
| <Banner | ||
| variant={featureStatusBannerVariant(isOrgAiEnabled)} | ||
| className={banner} | ||
| > | ||
| {getFeatureStatusBannerText(isOrgAiEnabled)} Project Owners can change | ||
| this setting in the{' '} | ||
| <Link href={PROJECT_SETTINGS_LINK} target="_blank"> | ||
| AI features | ||
| </Link>{' '} | ||
| section. | ||
| </Banner> | ||
| <div className={disclaimer}> | ||
| This is a feature powered by generative AI, and may give inaccurate | ||
| responses. Please see our{' '} | ||
| <Link hideExternalIcon={false} href={GEN_AI_FAQ_LINK} target="_blank"> | ||
| FAQ | ||
| </Link>{' '} | ||
| for more information. | ||
| </div> | ||
| </Body> | ||
| </ConfirmationModal> | ||
| ); | ||
| }; | ||
|
|
||
| export default connect( | ||
| (state: RootState) => { | ||
| return { | ||
| isOptInModalVisible: state.optIn.isModalOpen, | ||
| isOptInInProgress: state.optIn.state === 'in-progress', | ||
| }; | ||
| }, | ||
| { onOptInModalClose: closeOptInModal, onOptInClick: optIn } | ||
| )(AIOptInModal); | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
packages/compass-generative-ai/src/components/atlas-signin/index.tsx
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import React from 'react'; | ||
| import AISignInModal from './ai-signin-modal'; | ||
| import AIOptInModal from './ai-optin-modal'; | ||
| import { ConfirmationModalArea } from '@mongodb-js/compass-components'; | ||
|
|
||
| export interface AtlasAiPluginProps { | ||
| projectId: string; | ||
Anemy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| export const AtlasAiPlugin: React.FunctionComponent<AtlasAiPluginProps> = ({ | ||
| projectId, | ||
| }) => { | ||
| return ( | ||
| <ConfirmationModalArea> | ||
| <AISignInModal></AISignInModal> | ||
| <AIOptInModal projectId={projectId}></AIOptInModal> | ||
| </ConfirmationModalArea> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/compass-generative-ai/src/store/atlas-ai-store.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { createStore, applyMiddleware, combineReducers } from 'redux'; | ||
| import thunk from 'redux-thunk'; | ||
| import signInReducer from './atlas-signin-reducer'; | ||
| import optInReducer from './atlas-optin-reducer'; | ||
| import type { AtlasAuthService } from '@mongodb-js/atlas-service/provider'; | ||
| import type { AtlasAiService } from '../atlas-ai-service'; | ||
| import type { PreferencesAccess } from 'compass-preferences-model'; | ||
|
|
||
| let store: CompassGenerativeAIServiceStore; | ||
| export function getStore() { | ||
| if (!store) { | ||
| throw new Error('CompassGenerativeAIPlugin not activated'); | ||
| } | ||
| return store; | ||
| } | ||
| const reducer = combineReducers({ | ||
| signIn: signInReducer, | ||
| optIn: optInReducer, | ||
| }); | ||
|
|
||
| export type RootState = ReturnType<typeof reducer>; | ||
|
|
||
| export type CompassGenerativeAIExtraArgs = { | ||
| atlasAuthService: AtlasAuthService; | ||
| atlasAiService: AtlasAiService; | ||
| preferences: PreferencesAccess; | ||
| }; | ||
|
|
||
| export function configureStore({ | ||
| atlasAuthService, | ||
| atlasAiService, | ||
| preferences, | ||
| }: CompassGenerativeAIExtraArgs) { | ||
| const store = createStore( | ||
| reducer, | ||
| applyMiddleware( | ||
| thunk.withExtraArgument({ atlasAuthService, atlasAiService, preferences }) | ||
| ) | ||
| ); | ||
| return store; | ||
| } | ||
|
|
||
| export type CompassGenerativeAIServiceStore = ReturnType<typeof configureStore>; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.