Skip to content

Commit 06999d8

Browse files
authored
chore(generative-ai): move ai sign in modal to gen ai package from atlas-service COMPASS-8459 (#6448)
1 parent fac4f9d commit 06999d8

33 files changed

+657
-232
lines changed

package-lock.json

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/atlas-service/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
"hadron-ipc": "^3.2.25",
8989
"lodash": "^4.17.21",
9090
"react": "^17.0.2",
91-
"react-redux": "^8.1.3",
9291
"redux": "^4.2.1",
9392
"redux-thunk": "^2.4.2"
9493
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { AtlasUserInfo } from './util';
44
export type ArgsWithSignal<T = Record<string, unknown>> = T & {
55
signal?: AbortSignal;
66
};
7-
export type SignInPrompt = 'none' | 'ai-promo-modal';
7+
export type SignInPrompt = 'none';
88

99
type AtlasAuthServiceEvents = {
1010
'signed-in': [];

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { ipcRenderer } from 'hadron-ipc';
22
import type { CompassAuthService as AtlasServiceMain } from './main';
3-
import {
4-
signInWithModalPrompt,
5-
signInWithoutPrompt,
6-
} from './store/atlas-signin-reducer';
3+
import { signInWithoutPrompt } from './store/atlas-signin-reducer';
74
import { getStore } from './store/atlas-signin-store';
85
import { AtlasAuthService } from './atlas-auth-service';
96
import type { ArgsWithSignal, SignInPrompt } from './atlas-auth-service';
@@ -46,8 +43,6 @@ export class CompassAtlasAuthService extends AtlasAuthService {
4643
switch (promptType) {
4744
case 'none':
4845
return getStore().dispatch(signInWithoutPrompt({ signal }));
49-
case 'ai-promo-modal':
50-
return getStore().dispatch(signInWithModalPrompt({ signal }));
5146
default:
5247
return this.ipc.signIn({ signal });
5348
}

packages/atlas-service/src/renderer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { registerHadronPlugin } from 'hadron-app-registry';
22
import { activatePlugin } from './store/atlas-signin-store';
33
import { atlasAuthServiceLocator } from './provider';
4-
import { AtlasSignIn } from './components';
54

65
export const AtlasAuthPlugin = registerHadronPlugin(
76
{
87
name: 'AtlasAuth',
9-
component: AtlasSignIn,
8+
component: () => null,
109
activate: activatePlugin,
1110
},
1211
{

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

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import {
55
cancelSignIn,
66
attemptId,
77
AttemptStateMap,
8-
signInWithModalPrompt,
9-
closeSignInModal,
108
signInWithoutPrompt,
119
} from './atlas-signin-reducer';
1210
import { expect } from 'chai';
@@ -176,7 +174,7 @@ describe('atlasSignInReducer', function () {
176174
atlasAuthService: mockAtlasService as any,
177175
});
178176

179-
void store.dispatch(signInWithModalPrompt()).catch(() => {});
177+
void store.dispatch(signInWithoutPrompt()).catch(() => {});
180178

181179
await Promise.all([
182180
store.dispatch(signIn()),
@@ -186,101 +184,6 @@ describe('atlasSignInReducer', function () {
186184
});
187185
});
188186

189-
describe('signInWithModalPrompt', function () {
190-
it('should resolve when user finishes sign in with prompt flow', async function () {
191-
const mockAtlasService = {
192-
isAuthenticated: sandbox.stub().resolves(false),
193-
signIn: sandbox.stub().resolves({ sub: '1234' }),
194-
getUserInfo: sandbox.stub().resolves({ sub: '1234' }),
195-
emit: sandbox.stub(),
196-
};
197-
const store = configureStore({
198-
atlasAuthService: mockAtlasService as any,
199-
});
200-
201-
const signInPromise = store.dispatch(signInWithModalPrompt());
202-
await store.dispatch(signIn());
203-
await signInPromise;
204-
205-
expect(store.getState()).to.have.property('state', 'success');
206-
});
207-
208-
it('should reject if sign in flow fails', async function () {
209-
const mockAtlasService = {
210-
isAuthenticated: sandbox.stub().resolves(false),
211-
signIn: sandbox.stub().rejects(new Error('Whoops!')),
212-
getUserInfo: sandbox.stub().resolves({ sub: '1234' }),
213-
emit: sandbox.stub(),
214-
};
215-
const store = configureStore({
216-
atlasAuthService: mockAtlasService as any,
217-
});
218-
219-
const signInPromise = store.dispatch(signInWithModalPrompt());
220-
await store.dispatch(signIn());
221-
222-
try {
223-
await signInPromise;
224-
throw new Error('Expected signInPromise to throw');
225-
} catch (err) {
226-
expect(err).to.have.property('message', 'Whoops!');
227-
}
228-
229-
expect(store.getState()).to.have.property('state', 'error');
230-
});
231-
232-
it('should reject if user dismissed the modal', async function () {
233-
const mockAtlasService = {
234-
isAuthenticated: sandbox.stub().resolves(false),
235-
signIn: sandbox.stub().resolves({ sub: '1234' }),
236-
getUserInfo: sandbox.stub().resolves({ sub: '1234' }),
237-
emit: sandbox.stub(),
238-
};
239-
const store = configureStore({
240-
atlasAuthService: mockAtlasService as any,
241-
});
242-
243-
const signInPromise = store.dispatch(signInWithModalPrompt());
244-
store.dispatch(closeSignInModal());
245-
246-
try {
247-
await signInPromise;
248-
throw new Error('Expected signInPromise to throw');
249-
} catch (err) {
250-
expect(err).to.have.property('message', 'This operation was aborted');
251-
}
252-
253-
expect(store.getState()).to.have.property('state', 'canceled');
254-
});
255-
256-
it('should reject if provided signal was aborted', async function () {
257-
const mockAtlasService = {
258-
isAuthenticated: sandbox.stub().resolves(false),
259-
signIn: sandbox.stub().resolves({ sub: '1234' }),
260-
getUserInfo: sandbox.stub().resolves({ sub: '1234' }),
261-
emit: sandbox.stub(),
262-
};
263-
const store = configureStore({
264-
atlasAuthService: mockAtlasService as any,
265-
});
266-
267-
const c = new AbortController();
268-
const signInPromise = store.dispatch(
269-
signInWithModalPrompt({ signal: c.signal })
270-
);
271-
c.abort(new Error('Aborted from outside'));
272-
273-
try {
274-
await signInPromise;
275-
throw new Error('Expected signInPromise to throw');
276-
} catch (err) {
277-
expect(err).to.have.property('message', 'Aborted from outside');
278-
}
279-
280-
expect(store.getState()).to.have.property('state', 'canceled');
281-
});
282-
});
283-
284187
describe('signInWithoutPrompt', function () {
285188
it('should resolve when sign in flow finishes', async function () {
286189
const mockAtlasService = {

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

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export function isAction<A extends AnyAction>(
1414

1515
export type AtlasSignInState = {
1616
error: string | null;
17-
isModalOpen: boolean;
1817
// For managing attempt state that doesn't belong in the store
1918
currentAttemptId: number | null;
2019
} & (
@@ -37,8 +36,6 @@ export type AtlasSignInThunkAction<
3736
> = ThunkAction<R, AtlasSignInState, { atlasAuthService: AtlasAuthService }, A>;
3837

3938
export const enum AtlasSignInActions {
40-
OpenSignInModal = 'atlas-service/atlas-signin/OpenSignInModal',
41-
CloseSignInModal = 'atlas-service/atlas-signin/CloseSignInModal',
4239
RestoringStart = 'atlas-service/atlas-signin/StartRestoring',
4340
RestoringFailed = 'atlas-service/atlas-signin/RestoringFailed',
4441
RestoringSuccess = 'atlas-service/atlas-signin/RestoringSuccess',
@@ -52,14 +49,6 @@ export const enum AtlasSignInActions {
5249
SignedOut = 'atlas-service/atlas-signin/SignedOut',
5350
}
5451

55-
export type AtlasSignInOpenModalAction = {
56-
type: AtlasSignInActions.OpenSignInModal;
57-
};
58-
59-
export type AtlasSignInCloseModalAction = {
60-
type: AtlasSignInActions.CloseSignInModal;
61-
};
62-
6352
export type AtlasSignInRestoringStartAction = {
6453
type: AtlasSignInActions.RestoringStart;
6554
};
@@ -250,24 +239,6 @@ const reducer: Reducer<AtlasSignInState, Action> = (
250239
return { ...INITIAL_STATE, state: 'canceled' };
251240
}
252241

253-
if (
254-
isAction<AtlasSignInOpenModalAction>(
255-
action,
256-
AtlasSignInActions.OpenSignInModal
257-
)
258-
) {
259-
return { ...state, isModalOpen: true };
260-
}
261-
262-
if (
263-
isAction<AtlasSignInCloseModalAction>(
264-
action,
265-
AtlasSignInActions.CloseSignInModal
266-
)
267-
) {
268-
return { ...state, isModalOpen: false };
269-
}
270-
271242
if (
272243
isAction<AtlasSignInTokenRefreshFailedAction>(
273244
action,
@@ -337,29 +308,6 @@ const startAttempt = (fn: () => void): AtlasSignInThunkAction<AttemptState> => {
337308
};
338309
};
339310

340-
export const signInWithModalPrompt = ({
341-
signal,
342-
}: { signal?: AbortSignal } = {}): AtlasSignInThunkAction<
343-
Promise<AtlasUserInfo>
344-
> => {
345-
return async (dispatch, getState) => {
346-
// Nothing to do if we already signed in
347-
const { state, userInfo } = getState();
348-
if (state === 'success') {
349-
return userInfo;
350-
}
351-
const attempt = dispatch(
352-
startAttempt(() => {
353-
dispatch(openSignInModal());
354-
})
355-
);
356-
signal?.addEventListener('abort', () => {
357-
dispatch(closeSignInModal(signal.reason));
358-
});
359-
return attempt.promise;
360-
};
361-
};
362-
363311
export const signInWithoutPrompt = ({
364312
signal,
365313
}: { signal?: AbortSignal } = {}): AtlasSignInThunkAction<
@@ -383,12 +331,8 @@ export const signInWithoutPrompt = ({
383331
};
384332
};
385333

386-
export const openSignInModal = () => {
387-
return { type: AtlasSignInActions.OpenSignInModal };
388-
};
389-
390334
/**
391-
* Sign in from the opt in window
335+
* Sign into Atlas. To be called when the user isn't signed in yet.
392336
*/
393337
export const signIn = (): AtlasSignInThunkAction<Promise<void>> => {
394338
return async (dispatch, getState, { atlasAuthService }) => {
@@ -434,15 +378,6 @@ export const signIn = (): AtlasSignInThunkAction<Promise<void>> => {
434378
};
435379
};
436380

437-
export const closeSignInModal = (
438-
reason?: any
439-
): AtlasSignInThunkAction<void> => {
440-
return (dispatch) => {
441-
dispatch(cancelSignIn(reason));
442-
dispatch({ type: AtlasSignInActions.CloseSignInModal });
443-
};
444-
};
445-
446381
export const cancelSignIn = (reason?: any): AtlasSignInThunkAction<void> => {
447382
return (dispatch, getState) => {
448383
// Can't cancel sign in after the flow was finished indicated by current

packages/compass-aggregations/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
} from '@mongodb-js/compass-app-stores/provider';
2626
import { workspacesServiceLocator } from '@mongodb-js/compass-workspaces/provider';
2727
import { preferencesLocator } from 'compass-preferences-model/provider';
28-
import { atlasAuthServiceLocator } from '@mongodb-js/atlas-service/provider';
2928
import { atlasAiServiceLocator } from '@mongodb-js/compass-generative-ai/provider';
3029
import { pipelineStorageLocator } from '@mongodb-js/my-queries-storage/provider';
3130
import { connectionRepositoryAccessLocator } from '@mongodb-js/compass-connections/provider';
@@ -49,7 +48,6 @@ const CompassAggregationsHadronPlugin = registerHadronPlugin(
4948
preferences: preferencesLocator,
5049
logger: createLoggerLocator('COMPASS-AGGREGATIONS-UI'),
5150
track: telemetryLocator,
52-
atlasAuthService: atlasAuthServiceLocator,
5351
atlasAiService: atlasAiServiceLocator,
5452
pipelineStorage: pipelineStorageLocator,
5553
connectionInfoRef: connectionInfoRefLocator,

packages/compass-aggregations/src/modules/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import type { PreferencesAccess } from 'compass-preferences-model';
4242
import type { Logger } from '@mongodb-js/compass-logging/provider';
4343
import type AppRegistry from 'hadron-app-registry';
4444
import type { AtlasAiService } from '@mongodb-js/compass-generative-ai/provider';
45-
import type { AtlasAuthService } from '@mongodb-js/atlas-service/provider';
4645
import type { MongoDBInstance } from 'mongodb-instance-model';
4746
import type { DataService } from '../modules/data-service';
4847
import type {
@@ -100,7 +99,6 @@ export type PipelineBuilderExtraArgs = {
10099
localAppRegistry: AppRegistry;
101100
pipelineBuilder: PipelineBuilder;
102101
pipelineStorage: PipelineStorage;
103-
atlasAuthService: AtlasAuthService;
104102
workspaces: WorkspacesService;
105103
preferences: PreferencesAccess;
106104
logger: Logger;

packages/compass-aggregations/src/modules/pipeline-builder/pipeline-ai.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,10 @@ export const resetIsAggregationGeneratedFromQuery =
447447
};
448448

449449
export const showInput = (): PipelineBuilderThunkAction<Promise<void>> => {
450-
return async (dispatch, _getState, { atlasAuthService }) => {
450+
return async (dispatch, _getState, { atlasAiService }) => {
451451
try {
452452
if (process.env.COMPASS_E2E_SKIP_ATLAS_SIGNIN !== 'true') {
453-
await atlasAuthService.signIn({ promptType: 'ai-promo-modal' });
453+
await atlasAiService.ensureAiFeatureAccess();
454454
}
455455
dispatch({
456456
type: AIPipelineActionTypes.ShowInput,

0 commit comments

Comments
 (0)