Skip to content

Commit a5d5cce

Browse files
move the context to sidebar
1 parent 3bdc7eb commit a5d5cce

File tree

6 files changed

+29
-19
lines changed

6 files changed

+29
-19
lines changed

packages/compass-sidebar/src/components/multiple-connections/connections-navigation.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import toNS from 'mongodb-ns';
2-
import React, { useCallback, useContext, useEffect, useMemo } from 'react';
2+
import React, {
3+
createContext,
4+
useCallback,
5+
useContext,
6+
useEffect,
7+
useMemo,
8+
} from 'react';
39
import { connect } from 'react-redux';
4-
import {
5-
connectionStorageLocator,
6-
IsAtlasConnectionStorageContext,
7-
} from '@mongodb-js/connection-storage/provider';
810
import {
911
ChevronCollapse,
1012
type ItemAction,
@@ -95,6 +97,12 @@ const noDeploymentStyles = css({
9597
gap: spacing[200],
9698
});
9799

100+
/**
101+
* Indicates only Atlas cluster connections are supported, and the user cannot navigate
102+
* to other types of connections from this UI.
103+
*/
104+
export const AtlasClusterConnectionsOnly = createContext<boolean>(false);
105+
98106
function findCollection(ns: string, databases: Database[]) {
99107
const { database, collection } = toNS(ns);
100108

@@ -481,7 +489,7 @@ const ConnectionsNavigation: React.FC<ConnectionsNavigationProps> = ({
481489
}
482490
}, [activeWorkspace, onDatabaseToggle, onConnectionToggle]);
483491

484-
const isAtlasConnectionStorage = useContext(IsAtlasConnectionStorageContext);
492+
const isAtlasConnectionStorage = useContext(AtlasClusterConnectionsOnly);
485493

486494
return (
487495
<div className={connectionsContainerStyles}>

packages/compass-sidebar/src/components/multiple-connections/sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useContext, useState } from 'react';
1+
import React, { useCallback, useState } from 'react';
22
import { type MapStateToProps, connect } from 'react-redux';
33
import {
44
ConnectionStatus,

packages/compass-sidebar/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ActivateHelpers } from 'hadron-app-registry';
22
import { registerHadronPlugin, type AppRegistry } from 'hadron-app-registry';
3+
import { createContext } from 'react';
34
import SidebarPlugin from './plugin';
45
import { createSidebarStore } from './stores';
56
import {
@@ -11,6 +12,7 @@ import type { ConnectionsService } from '@mongodb-js/compass-connections/provide
1112
import { connectionsLocator } from '@mongodb-js/compass-connections/provider';
1213
import type { Logger } from '@mongodb-js/compass-logging/provider';
1314
import { createLoggerLocator } from '@mongodb-js/compass-logging/provider';
15+
export { AtlasClusterConnectionsOnly } from './components/multiple-connections/connections-navigation';
1416

1517
export const CompassSidebarPlugin = registerHadronPlugin(
1618
{

packages/compass-web/src/connection-storage.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useContext, useRef } from 'react';
2-
import { IsAtlasConnectionStorageContext } from '@mongodb-js/connection-storage/provider';
32
import type {
43
ConnectionStorage,
54
ConnectionInfo,
@@ -375,9 +374,7 @@ export const AtlasCloudConnectionStorageProvider = createServiceProvider(
375374
<ConnectionStorageProvider
376375
value={sandboxConnectionStorage ?? storage.current}
377376
>
378-
<IsAtlasConnectionStorageContext.Provider value={true}>
379-
{children}
380-
</IsAtlasConnectionStorageContext.Provider>
377+
{children}
381378
</ConnectionStorageProvider>
382379
);
383380
}

packages/compass-web/src/entrypoint.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import {
1919
WorkspaceTab as CollectionWorkspace,
2020
CollectionTabsProvider,
2121
} from '@mongodb-js/compass-collection';
22-
import { CompassSidebarPlugin } from '@mongodb-js/compass-sidebar';
22+
import {
23+
CompassSidebarPlugin,
24+
AtlasClusterConnectionsOnly,
25+
} from '@mongodb-js/compass-sidebar';
2326
import CompassQueryBarPlugin from '@mongodb-js/compass-query-bar';
2427
import { CompassDocumentsPlugin } from '@mongodb-js/compass-crud';
2528
import {
@@ -61,11 +64,13 @@ import { useCompassWebPreferences } from './preferences';
6164
const WithAtlasProviders: React.FC = ({ children }) => {
6265
return (
6366
<AtlasCloudAuthServiceProvider>
64-
<AtlasServiceProvider>
65-
<AtlasAiServiceProvider apiURLPreset="cloud">
66-
{children}
67-
</AtlasAiServiceProvider>
68-
</AtlasServiceProvider>
67+
<AtlasClusterConnectionsOnly.Provider value={true}>
68+
<AtlasServiceProvider>
69+
<AtlasAiServiceProvider apiURLPreset="cloud">
70+
{children}
71+
</AtlasAiServiceProvider>
72+
</AtlasServiceProvider>
73+
</AtlasClusterConnectionsOnly.Provider>
6974
</AtlasCloudAuthServiceProvider>
7075
);
7176
};

packages/connection-storage/src/provider.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export const ConnectionStorageContext = createContext<ConnectionStorage | null>(
1515
null
1616
);
1717

18-
export const IsAtlasConnectionStorageContext = createContext<boolean>(false);
19-
2018
export const ConnectionStorageProvider = ConnectionStorageContext.Provider;
2119

2220
// TODO(COMPASS-7397): storage context should not be leaking out of the service

0 commit comments

Comments
 (0)