Skip to content

Commit d79e1fc

Browse files
feat: update atlas login screen flow COMPASS-7755 (#5606)
* feat: update the atlas login screen flow COMPASS-7755 * test: remove TOS test cases
1 parent 28f4da7 commit d79e1fc

File tree

30 files changed

+54
-898
lines changed

30 files changed

+54
-898
lines changed

packages/atlas-service/src/atlas-auth-service.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { EventEmitter } from 'events';
2-
import type { AtlasUserConfig } from './user-config-store';
32
import type { AtlasUserInfo } from './util';
43

54
export type ArgsWithSignal<T = Record<string, unknown>> = T & {
@@ -11,7 +10,6 @@ type AtlasAuthServiceEvents = {
1110
'signed-in': [];
1211
'signed-out': [];
1312
'token-refresh-failed': [];
14-
'user-config-changed': [AtlasUserConfig];
1513
};
1614

1715
type AtlasAuthEventNames = keyof AtlasAuthServiceEvents;
@@ -30,7 +28,6 @@ export abstract class AtlasAuthService extends EventEmitter {
3028
): Promise<Record<string, string>>;
3129

3230
abstract getUserInfo(opts?: ArgsWithSignal): Promise<AtlasUserInfo>;
33-
abstract updateUserConfig(config: AtlasUserConfig): Promise<void>;
3431

3532
on<T extends AtlasAuthEventNames>(
3633
evt: T,

packages/atlas-service/src/compass-atlas-auth-service.spec.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,4 @@ describe('CompassAtlasAuthService', function () {
5757
expect(res).to.deep.equal({ id: 1 });
5858
expect(getUserInfoStub.calledOnce).to.be.true;
5959
});
60-
61-
it('calls updateUserConfig on ipc', async function () {
62-
const updateUserConfigStub = sandbox.stub();
63-
const atlasAuthService = getAtlasAuthService({
64-
updateAtlasUserConfig: updateUserConfigStub,
65-
});
66-
await atlasAuthService.updateUserConfig({ enabledAIFeature: false });
67-
expect(updateUserConfigStub.calledOnce).to.be.true;
68-
expect(updateUserConfigStub.firstCall.firstArg).to.deep.equal({
69-
config: { enabledAIFeature: false },
70-
});
71-
});
7260
});

packages/atlas-service/src/compass-atlas-auth-service.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { AtlasUserConfig } from './user-config-store';
21
import { ipcRenderer } from 'hadron-ipc';
32
import type { CompassAuthService as AtlasServiceMain } from './main';
43
import {
@@ -12,18 +11,12 @@ import type { ArgsWithSignal, SignInPrompt } from './atlas-auth-service';
1211
export class CompassAtlasAuthService extends AtlasAuthService {
1312
private _ipc = ipcRenderer?.createInvoke<
1413
typeof AtlasServiceMain,
15-
| 'getUserInfo'
16-
| 'isAuthenticated'
17-
| 'signIn'
18-
| 'signOut'
19-
| 'updateAtlasUserConfig'
20-
| 'maybeGetToken'
14+
'getUserInfo' | 'isAuthenticated' | 'signIn' | 'signOut' | 'maybeGetToken'
2115
>('AtlasService', [
2216
'getUserInfo',
2317
'isAuthenticated',
2418
'signIn',
2519
'signOut',
26-
'updateAtlasUserConfig',
2720
'maybeGetToken',
2821
]);
2922

@@ -62,7 +55,4 @@ export class CompassAtlasAuthService extends AtlasAuthService {
6255
getUserInfo(opts?: ArgsWithSignal) {
6356
return this.ipc.getUserInfo(opts);
6457
}
65-
updateUserConfig(config: AtlasUserConfig) {
66-
return this.ipc.updateAtlasUserConfig({ config });
67-
}
6858
}

packages/atlas-service/src/components/ai-signin-modal.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import { connect } from 'react-redux';
33
import {
4-
Badge,
54
Body,
5+
Disclaimer,
66
Icon,
7+
Link,
78
MarketingModal,
89
SpinLoader,
910
css,
@@ -15,6 +16,8 @@ import { AISignInImageBanner } from './ai-signin-banner-image';
1516
import type { AtlasSignInState } from '../store/atlas-signin-reducer';
1617
import { closeSignInModal, signIn } from '../store/atlas-signin-reducer';
1718

19+
const GEN_AI_FAQ_LINK = 'https://www.mongodb.com/docs/generative-ai-faq/';
20+
1821
type SignInModalProps = {
1922
isSignInModalVisible?: boolean;
2023
isSignInInProgress?: boolean;
@@ -43,6 +46,10 @@ const paragraphStyles = css({
4346
marginBottom: spacing[2],
4447
});
4548

49+
const disclaimer = css({
50+
marginTop: spacing[3],
51+
});
52+
4653
const AISignInModal: React.FunctionComponent<SignInModalProps> = ({
4754
isSignInModalVisible = false,
4855
isSignInInProgress = false,
@@ -97,7 +104,14 @@ const AISignInModal: React.FunctionComponent<SignInModalProps> = ({
97104
MongoDB&apos;s&nbsp; intelligent AI-powered feature, available today
98105
in Compass.
99106
</Body>
100-
<Badge variant="blue">Preview</Badge>
107+
<Disclaimer className={disclaimer}>
108+
This is a feature powered by generative AI, and may give inaccurate
109+
responses. Please see our{' '}
110+
<Link hideExternalIcon={false} href={GEN_AI_FAQ_LINK} target="_blank">
111+
FAQ
112+
</Link>{' '}
113+
for more information.
114+
</Disclaimer>
101115
</div>
102116
</MarketingModal>
103117
);

packages/atlas-service/src/main.spec.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { throwIfNotOk } from './util';
55
import { EventEmitter } from 'events';
66
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
77
import type { PreferencesAccess } from 'compass-preferences-model';
8-
import type { AtlasUserConfigStore } from './user-config-store';
98
import * as util from './util';
109

1110
function getListenerCount(emitter: EventEmitter) {
@@ -37,11 +36,6 @@ describe('CompassAuthServiceMain', function () {
3736
}[url];
3837
});
3938

40-
const mockUserConfigStore = {
41-
getUserConfig: sandbox.stub().resolves({}),
42-
updateUserConfig: sandbox.stub().resolves(),
43-
};
44-
4539
const mockOidcPlugin = {
4640
mongoClientOptions: {
4741
authMechanismProperties: {
@@ -71,7 +65,6 @@ describe('CompassAuthServiceMain', function () {
7165
const fetch = CompassAuthService['fetch'];
7266
const ipcMain = CompassAuthService['ipcMain'];
7367
const createPlugin = CompassAuthService['createMongoDBOIDCPlugin'];
74-
const userStore = CompassAuthService['atlasUserConfigStore'];
7568
const authConfig = CompassAuthService['config'];
7669
let preferences: PreferencesAccess;
7770

@@ -91,8 +84,6 @@ describe('CompassAuthServiceMain', function () {
9184
};
9285
CompassAuthService['fetch'] = mockFetch as any;
9386
CompassAuthService['createMongoDBOIDCPlugin'] = () => mockOidcPlugin;
94-
CompassAuthService['atlasUserConfigStore'] =
95-
mockUserConfigStore as unknown as AtlasUserConfigStore;
9687

9788
CompassAuthService['config'] = defaultConfig;
9889

@@ -111,7 +102,6 @@ describe('CompassAuthServiceMain', function () {
111102
// eslint-disable-next-line @typescript-eslint/require-await
112103
afterEach(async function () {
113104
CompassAuthService['fetch'] = fetch;
114-
CompassAuthService['atlasUserConfigStore'] = userStore;
115105
CompassAuthService['ipcMain'] = ipcMain;
116106
CompassAuthService['initPromise'] = null;
117107
CompassAuthService['createMongoDBOIDCPlugin'] = createPlugin;
@@ -339,7 +329,7 @@ describe('CompassAuthServiceMain', function () {
339329
} as any;
340330
await CompassAuthService.init(preferences);
341331
CompassAuthService['config'] = defaultConfig;
342-
expect(getListenerCount(logger)).to.eq(28);
332+
expect(getListenerCount(logger)).to.eq(27);
343333
// We did all preparations, reset sinon history for easier assertions
344334
sandbox.resetHistory();
345335

packages/atlas-service/src/main.ts

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import type { AbortSignal as NodeFetchAbortSignal } from 'node-fetch/externals';
1717
import type { RequestInfo, RequestInit, Response } from 'node-fetch';
1818
import nodeFetch from 'node-fetch';
1919
import type { IntrospectInfo, AtlasUserInfo, AtlasServiceConfig } from './util';
20-
import type { AtlasUserConfig } from './user-config-store';
2120
import { throwIfAborted } from '@mongodb-js/compass-utils';
2221
import type { HadronIpcMain } from 'hadron-ipc';
2322
import { ipcMain } from 'hadron-ipc';
@@ -27,7 +26,6 @@ import {
2726
} from '@mongodb-js/compass-logging';
2827
import type { PreferencesAccess } from 'compass-preferences-model';
2928
import { SecretStore } from './secret-store';
30-
import { AtlasUserConfigStore } from './user-config-store';
3129
import { OidcPluginLogger } from './oidc-plugin-logger';
3230
import { spawn } from 'child_process';
3331
import { getAtlasConfig } from './util';
@@ -93,8 +91,6 @@ export class CompassAuthService {
9391

9492
private static secretStore = new SecretStore();
9593

96-
private static atlasUserConfigStore = new AtlasUserConfigStore();
97-
9894
private static ipcMain:
9995
| Pick<HadronIpcMain, 'createHandle' | 'handle' | 'broadcast'>
10096
| undefined = ipcMain;
@@ -173,7 +169,6 @@ export class CompassAuthService {
173169
'isAuthenticated',
174170
'signIn',
175171
'signOut',
176-
'updateAtlasUserConfig',
177172
'maybeGetToken',
178173
]);
179174
}
@@ -233,12 +228,6 @@ export class CompassAuthService {
233228
this.oidcPluginLogger.on('atlas-service-signed-out', () => {
234229
this.ipcMain?.broadcast('atlas-service-signed-out');
235230
});
236-
this.oidcPluginLogger.on(
237-
'atlas-service-user-config-changed',
238-
(newConfig) => {
239-
this.ipcMain?.broadcast('atlas-service-user-config-changed', newConfig);
240-
}
241-
);
242231
}
243232

244233
static async isAuthenticated({
@@ -381,34 +370,12 @@ export class CompassAuthService {
381370

382371
const userInfo = (await res.json()) as AtlasUserInfo;
383372

384-
const userConfig = await this.atlasUserConfigStore.getUserConfig(
385-
userInfo.sub
386-
);
387-
388-
return { ...userInfo, ...userConfig };
373+
// TODO: Remove hadcoded `enabledAIFeature: true` when Atlas returns the actual value.
374+
return { ...userInfo, enabledAIFeature: true };
389375
})();
390376
return this.currentUser;
391377
}
392378

393-
static async updateAtlasUserConfig({
394-
config,
395-
}: {
396-
config: Partial<AtlasUserConfig>;
397-
}) {
398-
if (!this.currentUser) {
399-
throw new Error("Can't update user config when not logged in");
400-
}
401-
const newConfig = await this.atlasUserConfigStore.updateUserConfig(
402-
this.currentUser.sub,
403-
config
404-
);
405-
this.currentUser = {
406-
...this.currentUser,
407-
...newConfig,
408-
};
409-
this.oidcPluginLogger.emit('atlas-service-user-config-changed', newConfig);
410-
}
411-
412379
static async introspect({
413380
signal,
414381
tokenType,

packages/atlas-service/src/oidc-plugin-logger.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { EventEmitter } from 'events';
22
import type { MongoDBOIDCPluginOptions } from '@mongodb-js/oidc-plugin';
3-
import type { AtlasUserConfig } from './user-config-store';
43

54
type MongoDBOIDCPluginLogger = Required<MongoDBOIDCPluginOptions>['logger'];
65

@@ -54,24 +53,13 @@ type OidcPluginLogger = MongoDBOIDCPluginLogger & {
5453
on(evt: 'atlas-service-token-refreshed', fn: () => void): void;
5554
on(evt: 'atlas-service-token-refresh-failed', fn: () => void): void;
5655
on(evt: 'atlas-service-signed-out', fn: () => void): void;
57-
on(
58-
evt: 'atlas-service-user-config-changed',
59-
fn: (newConfig: AtlasUserConfig) => void
60-
): void;
56+
6157
once(evt: 'atlas-service-token-refreshed', fn: () => void): void;
6258
once(evt: 'atlas-service-token-refresh-failed', fn: () => void): void;
6359
once(evt: 'atlas-service-signed-out', fn: () => void): void;
64-
once(
65-
evt: 'atlas-service-user-config-changed',
66-
fn: (newConfig: AtlasUserConfig) => void
67-
): void;
6860
emit(evt: 'atlas-service-token-refreshed'): void;
6961
emit(evt: 'atlas-service-token-refresh-failed'): void;
7062
emit(evt: 'atlas-service-signed-out'): void;
71-
emit(
72-
evt: 'atlas-service-user-config-changed',
73-
newConfig: AtlasUserConfig
74-
): void;
7563
} & Pick<EventEmitter, 'removeAllListeners'>;
7664

7765
export const OidcPluginLogger: { new (): OidcPluginLogger } = EventEmitter;

packages/atlas-service/src/renderer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ export const AtlasAuthPlugin = registerHadronPlugin(
1515
);
1616
export default AtlasAuthPlugin;
1717
export { AtlasServiceError } from './util';
18-
export type { AtlasUserConfig } from './user-config-store';
1918
export type { AtlasUserInfo } from './util';
2019
export { CompassAtlasAuthService } from './compass-atlas-auth-service';

packages/atlas-service/src/store/atlas-signin-reducer.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { AnyAction, Reducer } from 'redux';
22
import type { ThunkAction } from 'redux-thunk';
33
import { openToast } from '@mongodb-js/compass-components';
44
import type { AtlasUserInfo } from '../util';
5-
import type { AtlasUserConfig } from '../user-config-store';
65
import type { AtlasAuthService } from '../provider';
76
import { throwIfAborted } from '@mongodb-js/compass-utils';
87

@@ -51,7 +50,6 @@ export const enum AtlasSignInActions {
5150
Cancel = 'atlas-service/atlas-signin/AtlasSignInCancel',
5251
TokenRefreshFailed = 'atlas-service/atlas-signin/TokenRefreshFailed',
5352
SignedOut = 'atlas-service/atlas-signin/SignedOut',
54-
UserConfigChanged = 'atlas-service/atlas-signin/UserConfigChanged',
5553
}
5654

5755
export type AtlasSignInOpenModalAction = {
@@ -107,11 +105,6 @@ export type AtlasSignInSignedOutAction = {
107105
type: AtlasSignInActions.SignedOut;
108106
};
109107

110-
export type AtlasSignInUserConfigChangedAction = {
111-
type: AtlasSignInActions.UserConfigChanged;
112-
newConfig: AtlasUserConfig;
113-
};
114-
115108
export type AtlasSignInCancelAction = { type: AtlasSignInActions.Cancel };
116109

117110
const INITIAL_STATE = {
@@ -297,18 +290,6 @@ const reducer: Reducer<AtlasSignInState> = (
297290
return { ...INITIAL_STATE };
298291
}
299292

300-
if (
301-
isAction<AtlasSignInUserConfigChangedAction>(
302-
action,
303-
AtlasSignInActions.UserConfigChanged
304-
)
305-
) {
306-
if (state.state !== 'success') {
307-
return state;
308-
}
309-
return { ...state, userInfo: { ...state.userInfo, ...action.newConfig } };
310-
}
311-
312293
return state;
313294
};
314295

@@ -490,13 +471,4 @@ export const signedOut = (): AtlasSignInThunkAction<void> => {
490471
};
491472
};
492473

493-
export const userConfigChanged = (
494-
newConfig: AtlasUserConfig
495-
): AtlasSignInThunkAction<void> => {
496-
return (dispatch, _getState, { atlasAuthService }) => {
497-
dispatch({ type: AtlasSignInActions.UserConfigChanged, newConfig });
498-
atlasAuthService.emit('user-config-changed', newConfig);
499-
};
500-
};
501-
502474
export default reducer;

packages/atlas-service/src/store/atlas-signin-store.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { createStore, applyMiddleware } from 'redux';
22
import thunk from 'redux-thunk';
3-
import type { AtlasUserConfig } from '../renderer';
43
import reducer, {
54
restoreSignInState,
65
signedOut,
76
tokenRefreshFailed,
8-
userConfigChanged,
97
} from './atlas-signin-reducer';
108
import { type AtlasAuthService } from '../provider';
119
import { ipcRenderer } from 'hadron-ipc';
@@ -31,13 +29,10 @@ export function activatePlugin(
3129

3230
const onSignedOut = () => store.dispatch(signedOut);
3331
const onTokenRefreshFailed = () => store.dispatch(tokenRefreshFailed);
34-
const onUserConfigChanged = (_evt: unknown, newConfig: AtlasUserConfig) =>
35-
store.dispatch(userConfigChanged(newConfig));
3632

3733
if (ipcRenderer) {
3834
on(ipcRenderer, 'atlas-service-token-refresh-failed', onSignedOut);
3935
on(ipcRenderer, 'atlas-service-signed-out', onTokenRefreshFailed);
40-
on(ipcRenderer, 'atlas-service-user-config-changed', onUserConfigChanged);
4136
}
4237

4338
addCleanup(() => {
@@ -47,7 +42,6 @@ export function activatePlugin(
4742
onTokenRefreshFailed
4843
);
4944
ipcRenderer.off('atlas-service-signed-out', onSignedOut);
50-
ipcRenderer.off('atlas-service-user-config-changed', onUserConfigChanged);
5145
}
5246
});
5347

0 commit comments

Comments
 (0)