Skip to content

Commit ab8a8eb

Browse files
review comments and checking for userPref
1 parent ae6fa98 commit ab8a8eb

File tree

4 files changed

+31
-46
lines changed

4 files changed

+31
-46
lines changed

packages/compass-generative-ai/src/atlas-ai-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ export class AtlasAiService {
461461
);
462462
if (res.ok) {
463463
await this.preferences.savePreferences({
464-
enableGenAIFeatures: true,
464+
optInDataExplorerGenAIFeatures: true,
465465
});
466466
}
467467
}

packages/compass-generative-ai/src/components/ai-optin-modal.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import {
1818
const GEN_AI_FAQ_LINK = 'https://www.mongodb.com/docs/generative-ai-faq/';
1919

2020
type OptInModalProps = {
21-
isOptInModalVisible?: boolean;
22-
isOptInInProgress?: boolean;
23-
onOptInModalClose?: () => void;
24-
onOptInClick?: () => void;
21+
isOptInModalVisible: boolean;
22+
isOptInInProgress: boolean;
23+
onOptInModalClose: () => void;
24+
onOptInClick: () => void;
2525
};
2626

2727
const titleStyles = css({
@@ -73,13 +73,12 @@ const AIOptInModal: React.FunctionComponent<OptInModalProps> = ({
7373
}
7474
onOptInClick?.();
7575
}}
76-
linkText="Back to Classic Mode"
76+
linkText="Cancel"
7777
onLinkClick={onOptInModalClose}
7878
>
7979
<Body>
8080
Atlas users can now quickly create queries and aggregations with
81-
MongoDB&apos;s&nbsp; intelligent AI-powered feature, available today in
82-
Compass.
81+
MongoDB&apos;s&nbsp; intelligent AI-powered feature, available today.
8382
</Body>
8483
</MarketingModal>
8584
);

packages/compass-generative-ai/src/store/atlas-ai-store.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import signInReducer, {
55
atlasServiceSignedIn,
66
//atlasServiceSignInTokenRefreshFailed,
77
} from './atlas-signin-reducer';
8-
import optInReducer, {/*atlasAiServiceOptedIn,*/ atlasServiceOptInTokenRefreshFailed } from './atlas-optin-reducer';
8+
import optInReducer, {
9+
atlasServiceSignInTokenRefreshFailed,
10+
} from './atlas-signin-reducer';
911
import type { AtlasAuthService } from '@mongodb-js/atlas-service/provider';
1012
import type { ActivateHelpers } from 'hadron-app-registry';
1113
import type { AtlasAiService } from '../atlas-ai-service';
14+
import type { PreferencesAccess } from 'compass-preferences-model';
1215

1316
let store: CompassGenerativeAIServiceStore;
1417
export function getStore() {
@@ -19,20 +22,19 @@ export function getStore() {
1922
}
2023
const reducer = combineReducers({
2124
signInReducer,
22-
optInReducer
25+
optInReducer,
2326
});
2427

2528
export type CompassGenerativeAIPluginServices = {
2629
atlasAuthService: AtlasAuthService;
27-
atlasAiService: AtlasAiService
30+
atlasAiService: AtlasAiService;
2831
};
2932
export function activatePlugin(
3033
_: Record<string, never>,
3134
services: CompassGenerativeAIPluginServices,
3235
{ cleanup }: ActivateHelpers
3336
) {
3437
store = configureStore(services);
35-
console.log(services.atlasAiService)
3638
services.atlasAuthService.on('signed-in', () => {
3739
void store.dispatch(atlasServiceSignedIn());
3840
});
@@ -42,19 +44,27 @@ export function activatePlugin(
4244
});
4345

4446
services.atlasAuthService.on('token-refresh-failed', () => {
45-
void store.dispatch(atlasServiceOptInTokenRefreshFailed());
47+
void store.dispatch(atlasServiceSignInTokenRefreshFailed());
4648
});
4749
return { store, deactivate: cleanup };
4850
}
4951

5052
export function configureStore({
51-
atlasAuthService, atlasAiService
53+
atlasAuthService,
54+
atlasAiService,
5255
}: CompassGenerativeAIPluginServices) {
5356
const store = createStore(
5457
reducer,
55-
applyMiddleware(thunk.withExtraArgument({ atlasAuthService, atlasAiService }))
58+
applyMiddleware(
59+
thunk.withExtraArgument({ atlasAuthService, atlasAiService })
60+
)
5661
);
5762
return store;
5863
}
5964

65+
export type GenAIAtlasExtraArgs = {
66+
preferences: PreferencesAccess;
67+
atlasAiService: AtlasAiService;
68+
};
69+
6070
export type CompassGenerativeAIServiceStore = ReturnType<typeof configureStore>;

packages/compass-generative-ai/src/store/atlas-optin-reducer.ts

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Action, AnyAction, Reducer } from 'redux';
22
import type { ThunkAction } from 'redux-thunk';
3-
import type { AtlasAiService } from '../atlas-ai-service';
3+
import type { GenAIAtlasExtraArgs } from './atlas-ai-store';
44
import { throwIfAborted } from '@mongodb-js/compass-utils';
55

66
function isAction<A extends AnyAction>(
@@ -28,7 +28,7 @@ export type AtlasOptInState = {
2828
export type GenAIAtlasOptInThunkAction<
2929
R,
3030
A extends AnyAction = AnyAction
31-
> = ThunkAction<R, AtlasOptInState, { atlasAiService: AtlasAiService }, A>;
31+
> = ThunkAction<R, AtlasOptInState, GenAIAtlasExtraArgs, A>;
3232

3333
export const enum AtlasOptInActions {
3434
OpenOptInModal = 'compass-generative-ai/atlas-optin/OpenOptInModal',
@@ -39,7 +39,6 @@ export const enum AtlasOptInActions {
3939
OptInSuccess = 'compass-generative-ai/atlas-optin/AtlasOptInSuccess',
4040
Error = 'compass-generative-ai/atlas-optin/AtlasOptInError',
4141
Cancel = 'compass-generative-ai/atlas-optin/AtlasOptInCancel',
42-
OptInTokenRefreshFailed = 'compass-generative-ai/atlas-optin/OptInTokenRefreshFailed',
4342
}
4443

4544
export type AtlasOptInOpenModalAction = {
@@ -75,10 +74,6 @@ export type AtlasOptInErrorAction = {
7574

7675
export type AtlasOptInCancelAction = { type: AtlasOptInActions.Cancel };
7776

78-
export type AtlasOptInTokenRefreshFailedAction = {
79-
type: AtlasOptInActions.OptInTokenRefreshFailed;
80-
};
81-
8277
const INITIAL_STATE = {
8378
state: 'initial' as const,
8479
error: null,
@@ -191,22 +186,6 @@ const optInReducer: Reducer<AtlasOptInState, Action> = (
191186
return { ...state, isModalOpen: false };
192187
}
193188

194-
if (
195-
isAction<AtlasOptInTokenRefreshFailedAction>(
196-
action,
197-
AtlasOptInActions.OptInTokenRefreshFailed
198-
)
199-
) {
200-
// Only reset state on refresh failed when we are currently successfully
201-
// signed in. All other cases mean that either there is a sign in already
202-
// in progress or something else already failed: no need to update either
203-
// way
204-
if (state.state !== 'optin-success') {
205-
return state;
206-
}
207-
return { ...INITIAL_STATE, state: 'error' };
208-
}
209-
210189
return state;
211190
};
212191

@@ -243,10 +222,13 @@ export const optIntoGenAIWithModalPrompt = ({
243222
}: { signal?: AbortSignal } = {}): GenAIAtlasOptInThunkAction<
244223
Promise<void>
245224
> => {
246-
return (dispatch, getState) => {
225+
return (dispatch, getState, { preferences }) => {
247226
// Nothing to do if we already signed in.
248227
const { state } = getState();
249-
if (state === 'optin-success') {
228+
if (
229+
state === 'optin-success' ||
230+
preferences.getPreferences().optInDataExplorerGenAIFeatures
231+
) {
250232
return Promise.resolve();
251233
}
252234
const attempt = dispatch(
@@ -278,8 +260,6 @@ export const optIn = (): GenAIAtlasOptInThunkAction<Promise<void>> => {
278260

279261
try {
280262
throwIfAborted(signal);
281-
//if pref set to false then call an opt in function
282-
console.log(atlasAiService);
283263
await atlasAiService.optIntoGenAIFeaturesAtlas();
284264
dispatch(atlasAiServiceOptedIn());
285265
resolve();
@@ -323,10 +303,6 @@ export const cancelOptIn = (reason?: any): GenAIAtlasOptInThunkAction<void> => {
323303
};
324304
};
325305

326-
export const atlasServiceOptInTokenRefreshFailed = () => ({
327-
type: AtlasOptInActions.OptInTokenRefreshFailed,
328-
});
329-
330306
export const atlasAiServiceOptedIn = () => ({
331307
type: AtlasOptInActions.OptInSuccess,
332308
});

0 commit comments

Comments
 (0)