-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(atlas-service): convert to plugin (#5512)
* Revert "breadcrumbs ui" This reverts commit 8b0b3d9. * setup provider * convert atlas-sign-in to a plugin * rename * bootstrap * logger component * clean up * use refs * bootstrap
- Loading branch information
Showing
15 changed files
with
320 additions
and
302 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
78 changes: 0 additions & 78 deletions
78
packages/atlas-service/src/components/atlas-signin.spec.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,11 @@ | ||
import React from 'react'; | ||
import AISignInModal from './ai-signin-modal'; | ||
import { ConfirmationModalArea } from '@mongodb-js/compass-components'; | ||
|
||
export const AtlasSignIn = () => { | ||
return ( | ||
<ConfirmationModalArea> | ||
<AISignInModal></AISignInModal> | ||
</ConfirmationModalArea> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains 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,46 @@ | ||
import React, { createContext, useContext, useMemo } from 'react'; | ||
import type { AtlasAuthService } from './atlas-auth-service'; | ||
import { AtlasService, type AtlasServiceOptions } from './atlas-service'; | ||
import { preferencesLocator } from 'compass-preferences-model/provider'; | ||
import { useLoggerAndTelemetry } from '@mongodb-js/compass-logging/provider'; | ||
|
||
const AtlasAuthServiceContext = createContext<AtlasAuthService | null>(null); | ||
export const AtlasAuthServiceProvider = AtlasAuthServiceContext.Provider; | ||
function useAtlasAuthServiceLocator(): AtlasAuthService { | ||
const service = useContext(AtlasAuthServiceContext); | ||
if (!service) { | ||
throw new Error('No AtlasAuthService available in this context'); | ||
} | ||
return service; | ||
} | ||
export const atlasAuthServiceLocator = useAtlasAuthServiceLocator; | ||
|
||
const AtlasServiceContext = createContext<AtlasService | null>(null); | ||
export const AtlasServiceProvider: React.FC<{ | ||
options?: AtlasServiceOptions; | ||
}> = ({ options, children }) => { | ||
const logger = useLoggerAndTelemetry('ATLAS-SERVICE'); | ||
const preferences = preferencesLocator(); | ||
const authService = atlasAuthServiceLocator(); | ||
|
||
const atlasService = useMemo(() => { | ||
return new AtlasService(authService, preferences, logger, options); | ||
}, [authService, preferences, logger, options]); | ||
|
||
return ( | ||
<AtlasServiceContext.Provider value={atlasService}> | ||
{children} | ||
</AtlasServiceContext.Provider> | ||
); | ||
}; | ||
function useAtlasServiceLocator(): AtlasService { | ||
const service = useContext(AtlasServiceContext); | ||
if (!service) { | ||
throw new Error('No AtlasService available in this context'); | ||
} | ||
return service; | ||
} | ||
export const atlasServiceLocator = useAtlasServiceLocator; | ||
|
||
export { AtlasAuthService } from './atlas-auth-service'; | ||
export type { AtlasService } from './atlas-service'; |
This file contains 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/atlas-service/src/store/atlas-signin-store.spec.ts
This file contains 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 { expect } from 'chai'; | ||
import type { AtlasAuthPluginServices } from './atlas-signin-store'; | ||
import { activatePlugin } from './atlas-signin-store'; | ||
import type { ActivateHelpers } from 'hadron-app-registry'; | ||
import { waitFor } from '@testing-library/react'; | ||
|
||
const activateHelpers = { | ||
on: () => {}, | ||
addCleanup: () => {}, | ||
cleanup: () => {}, | ||
} as unknown as ActivateHelpers; | ||
|
||
describe('Atlas Signin Store', () => { | ||
context('when plugin is activated', function () { | ||
it('should restore the sign-in state - when signed in', async function () { | ||
const services = { | ||
atlasAuthService: { | ||
isAuthenticated: () => Promise.resolve(true), | ||
getUserInfo: () => Promise.resolve({ sub: '1234' }), | ||
}, | ||
} as unknown as AtlasAuthPluginServices; | ||
const { store } = activatePlugin({}, services, activateHelpers); | ||
expect(store.getState()).to.have.property('state', 'restoring'); | ||
await waitFor(() => { | ||
expect(store.getState()).to.have.property('state', 'success'); | ||
}); | ||
expect(store.getState()).to.have.nested.property('userInfo.sub', '1234'); | ||
}); | ||
it('should restore the sign-in state - when signed out', async function () { | ||
const services = { | ||
atlasAuthService: { | ||
isAuthenticated: () => Promise.resolve(false), | ||
}, | ||
} as unknown as AtlasAuthPluginServices; | ||
const { store } = activatePlugin({}, services, activateHelpers); | ||
expect(store.getState()).to.have.property('state', 'restoring'); | ||
await waitFor(() => { | ||
expect(store.getState()).to.have.property('state', 'unauthenticated'); | ||
}); | ||
expect(store.getState()).to.have.property('userInfo', null); | ||
}); | ||
}); | ||
}); |
This file contains 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
Oops, something went wrong.