Skip to content

Commit 7543fc5

Browse files
fix(compass-web): Rename connections list to clusters list in compass-web COMPASS-8698 (#6611)
* rename connections to context using a provider for is atlas connections * move the context to sidebar * add unit test * only export the provider not the whole context * remove import
1 parent 7b53ebb commit 7543fc5

File tree

4 files changed

+104
-30
lines changed

4 files changed

+104
-30
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import toNS from 'mongodb-ns';
2-
import React, { useCallback, 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';
410
import {
511
ChevronCollapse,
@@ -91,6 +97,12 @@ const noDeploymentStyles = css({
9197
gap: spacing[200],
9298
});
9399

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+
94106
function findCollection(ns: string, databases: Database[]) {
95107
const { database, collection } = toNS(ns);
96108

@@ -477,14 +489,16 @@ const ConnectionsNavigation: React.FC<ConnectionsNavigationProps> = ({
477489
}
478490
}, [activeWorkspace, onDatabaseToggle, onConnectionToggle]);
479491

492+
const isAtlasConnectionStorage = useContext(AtlasClusterConnectionsOnly);
493+
480494
return (
481495
<div className={connectionsContainerStyles}>
482496
<div
483497
className={connectionListHeaderStyles}
484498
data-testid="connections-header"
485499
>
486500
<Subtitle className={connectionListHeaderTitleStyles}>
487-
Connections
501+
{isAtlasConnectionStorage ? 'Clusters' : 'Connections'}
488502
{connections.length !== 0 && (
489503
<span className={connectionCountStyles}>
490504
({connections.length})
@@ -503,7 +517,11 @@ const ConnectionsNavigation: React.FC<ConnectionsNavigationProps> = ({
503517
{connections.length > 0 && (
504518
<>
505519
<NavigationItemsFilter
506-
placeholder="Search connections"
520+
placeholder={
521+
isAtlasConnectionStorage
522+
? 'Search clusters'
523+
: 'Search connections'
524+
}
507525
filter={filter}
508526
onFilterChange={onFilterChange}
509527
/>

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

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import type { WorkspacesService } from '@mongodb-js/compass-workspaces/provider'
1717
import { WorkspacesServiceProvider } from '@mongodb-js/compass-workspaces/provider';
1818
import { TestMongoDBInstanceManager } from '@mongodb-js/compass-app-stores/provider';
1919
import { ConnectionImportExportProvider } from '@mongodb-js/compass-connection-import-export';
20-
import { CompassSidebarPlugin } from '../../index';
20+
import {
21+
AtlasClusterConnectionsOnlyProvider,
22+
CompassSidebarPlugin,
23+
} from '../../index';
2124
import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider';
2225
import type AppRegistry from '../../../../hadron-app-registry/dist';
2326

@@ -91,14 +94,16 @@ describe('Multiple Connections Sidebar Component', function () {
9194

9295
function doRender(
9396
activeWorkspace: WorkspaceTab | null = null,
94-
connections: ConnectionInfo[] = [savedFavoriteConnection]
97+
connections: ConnectionInfo[] = [savedFavoriteConnection],
98+
atlasClusterConnectionsOnly: boolean | undefined = undefined
9599
) {
96100
workspace = sinon.spy({
97101
openMyQueriesWorkspace: () => undefined,
98102
openShellWorkspace: () => undefined,
99103
openPerformanceWorkspace: () => undefined,
100104
}) as any;
101-
const result = renderWithConnections(
105+
106+
let component = (
102107
<ConnectionImportExportProvider>
103108
<WorkspacesProvider
104109
value={[
@@ -112,25 +117,36 @@ describe('Multiple Connections Sidebar Component', function () {
112117
></MultipleConnectionSidebar>
113118
</WorkspacesServiceProvider>
114119
</WorkspacesProvider>
115-
</ConnectionImportExportProvider>,
116-
{
117-
preferences: { enableMultipleConnectionSystem: true },
118-
connections,
119-
connectFn() {
120-
return {
121-
currentOp() {
122-
return {};
123-
},
124-
top() {
125-
return {};
126-
},
127-
getConnectionOptions() {
128-
return {};
129-
},
130-
} as any;
131-
},
132-
}
120+
</ConnectionImportExportProvider>
133121
);
122+
123+
if (atlasClusterConnectionsOnly !== undefined) {
124+
component = (
125+
<AtlasClusterConnectionsOnlyProvider
126+
value={atlasClusterConnectionsOnly}
127+
>
128+
{component}
129+
</AtlasClusterConnectionsOnlyProvider>
130+
);
131+
}
132+
133+
const result = renderWithConnections(component, {
134+
preferences: { enableMultipleConnectionSystem: true },
135+
connections,
136+
connectFn() {
137+
return {
138+
currentOp() {
139+
return {};
140+
},
141+
top() {
142+
return {};
143+
},
144+
getConnectionOptions() {
145+
return {};
146+
},
147+
} as any;
148+
},
149+
});
134150
track = result.track;
135151
appRegistry = sinon.spy(result.globalAppRegistry);
136152
connectionsStoreActions = sinon.spy(result.connectionsStore.actions);
@@ -188,6 +204,37 @@ describe('Multiple Connections Sidebar Component', function () {
188204
});
189205
});
190206

207+
describe("'Connections ' header", function () {
208+
context('by default', () => {
209+
it("shows 'Connections' in header and search bar", () => {
210+
doRender(undefined, [savedFavoriteConnection, savedRecentConnection]);
211+
expect(screen.getByTestId('connections-header').textContent).to.equal(
212+
'Connections(2)'
213+
);
214+
expect(
215+
screen.getByTestId<HTMLInputElement>('sidebar-filter-input')
216+
.placeholder
217+
).to.equal('Search connections');
218+
});
219+
});
220+
context('when is atlas clusters only', () => {
221+
it("shows 'Clusters' in header and search bar", () => {
222+
doRender(
223+
undefined,
224+
[savedFavoriteConnection, savedRecentConnection],
225+
true
226+
);
227+
expect(screen.getByTestId('connections-header').textContent).to.equal(
228+
'Clusters(2)'
229+
);
230+
expect(
231+
screen.getByTestId<HTMLInputElement>('sidebar-filter-input')
232+
.placeholder
233+
).to.equal('Search clusters');
234+
});
235+
});
236+
});
237+
191238
describe('connections list', function () {
192239
context('when there are no connections', function () {
193240
it('should display an empty state with a CTA to add new connection', function () {

packages/compass-sidebar/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { ConnectionsService } from '@mongodb-js/compass-connections/provide
1111
import { connectionsLocator } from '@mongodb-js/compass-connections/provider';
1212
import type { Logger } from '@mongodb-js/compass-logging/provider';
1313
import { createLoggerLocator } from '@mongodb-js/compass-logging/provider';
14+
import { AtlasClusterConnectionsOnly } from './components/multiple-connections/connections-navigation';
1415

1516
export const CompassSidebarPlugin = registerHadronPlugin(
1617
{
@@ -52,3 +53,6 @@ export const CompassSidebarPlugin = registerHadronPlugin(
5253
logger: createLoggerLocator('COMPASS-SIDEBAR-UI'),
5354
}
5455
);
56+
57+
export const AtlasClusterConnectionsOnlyProvider =
58+
AtlasClusterConnectionsOnly.Provider;

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+
AtlasClusterConnectionsOnlyProvider,
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+
<AtlasClusterConnectionsOnlyProvider value={true}>
68+
<AtlasServiceProvider>
69+
<AtlasAiServiceProvider apiURLPreset="cloud">
70+
{children}
71+
</AtlasAiServiceProvider>
72+
</AtlasServiceProvider>
73+
</AtlasClusterConnectionsOnlyProvider>
6974
</AtlasCloudAuthServiceProvider>
7075
);
7176
};

0 commit comments

Comments
 (0)