Skip to content

Commit

Permalink
Revert "chore: extract an interface named ConnectionProvider and adap…
Browse files Browse the repository at this point in the history
…t the current connection loader to use it. " (#5475)

Revert "chore: extract an interface named ConnectionProvider and adapt the cu…"

This reverts commit b2ef862.
  • Loading branch information
kmruiz authored Feb 21, 2024
1 parent b2ef862 commit 27cd80c
Show file tree
Hide file tree
Showing 25 changed files with 363 additions and 790 deletions.
8 changes: 1 addition & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for (let i = 0; i < 5; i++) {
});
}

const mockFavorites: ConnectionInfo[] = [
const mockFavorites = [
{
id: 'mock-connection-atlas',
connectionOptions: {
Expand All @@ -35,7 +35,6 @@ const mockFavorites: ConnectionInfo[] = [
name: 'Atlas test',
color: '#d4366e',
},
savedConnectionType: 'favorite',
lastUsed: new Date(),
},
{
Expand All @@ -47,7 +46,6 @@ const mockFavorites: ConnectionInfo[] = [
name: 'super long favorite name - super long favorite name - super long favorite name - super long favorite name',
color: '#5fc86e',
},
savedConnectionType: 'favorite',
lastUsed: new Date(),
},
{
Expand All @@ -59,15 +57,13 @@ const mockFavorites: ConnectionInfo[] = [
name: 'favorite',
color: '#5fc86e',
},
savedConnectionType: 'favorite',
lastUsed: new Date(),
},
{
id: 'mock-connection-invalid string',
connectionOptions: {
connectionString: 'invalid connection string',
},
savedConnectionType: 'recent',
lastUsed: new Date(),
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ const colorIndicatorStyles = css({
});

function FavoriteColorIndicator({
color,
favorite,
className,
}: {
color?: string;
favorite?: ConnectionInfo['favorite'];
className?: string;
}): React.ReactElement {
const { connectionColorToHex } = useConnectionColor();
const favoriteColorHex = connectionColorToHex(color);
const favoriteColorHex = connectionColorToHex(favorite?.color);

return (
<div
Expand Down Expand Up @@ -194,7 +194,6 @@ function Connection({
const connectionTitle = getConnectionTitle(connectionInfo);
const {
connectionOptions: { connectionString },
savedConnectionType,
favorite,
lastUsed,
} = connectionInfo;
Expand Down Expand Up @@ -293,23 +292,25 @@ function Connection({
onClick={onClick}
onDoubleClick={() => onDoubleClick(connectionInfo)}
>
<FavoriteColorIndicator color={favorite?.color} />
<FavoriteColorIndicator favorite={connectionInfo.favorite} />
<ConnectionIcon
color={titleColor}
connectionString={connectionString}
/>
<H3
className={connectionTitleStyles}
style={{ color: titleColor }}
data-testid={`${savedConnectionType}-connection-title`}
data-testid={`${favorite ? 'favorite' : 'recent'}-connection-title`}
title={connectionTitle}
>
{connectionTitle}
</H3>
<Description
className={connectionDescriptionStyles}
style={{ color: descriptionColor }}
data-testid={`${savedConnectionType}-connection-description`}
data-testid={`${
favorite ? 'favorite' : 'recent'
}-connection-description`}
>
{lastUsed ? lastUsed.toLocaleString('default', dateConfig) : 'Never'}
</Description>
Expand Down
117 changes: 41 additions & 76 deletions packages/compass-connections/src/components/connections.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ import { ToastArea } from '@mongodb-js/compass-components';
import type { PreferencesAccess } from 'compass-preferences-model';
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
import { PreferencesProvider } from 'compass-preferences-model/provider';
import { ConnectionRepository } from '@mongodb-js/connection-storage/main';
import {
ConnectionRepositoryContext,
ConnectionStorageContext,
} from '@mongodb-js/connection-storage/provider';

function getMockConnectionStorage(mockConnections: ConnectionInfo[]) {
return {
Expand Down Expand Up @@ -86,24 +81,20 @@ describe('Connections Component', function () {
beforeEach(function () {
const mockStorage = getMockConnectionStorage([]);
loadConnectionsSpy = sinon.spy(mockStorage, 'loadAll');
const connectionRepository = new ConnectionRepository(mockStorage);

render(
<PreferencesProvider value={preferences}>
<ConnectionStorageContext.Provider value={mockStorage}>
<ConnectionRepositoryContext.Provider value={connectionRepository}>
<Connections
onConnected={onConnectedSpy}
appName="Test App Name"
/>
</ConnectionRepositoryContext.Provider>
</ConnectionStorageContext.Provider>
<Connections
onConnected={onConnectedSpy}
connectionStorage={mockStorage}
appName="Test App Name"
/>
</PreferencesProvider>
);
});

it('calls once to load the connections', function () {
expect(loadConnectionsSpy.callCount).to.equal(2); // favorite + recent
expect(loadConnectionsSpy.callCount).to.equal(1);
});

it('renders the connect button from the connect-form', function () {
Expand Down Expand Up @@ -173,21 +164,17 @@ describe('Connections Component', function () {
];
mockStorage = getMockConnectionStorage(connections);
sinon.replace(mockStorage, 'save', saveConnectionSpy);
const connectionRepository = new ConnectionRepository(mockStorage);

render(
<PreferencesProvider value={preferences}>
<ConnectionStorageContext.Provider value={mockStorage}>
<ConnectionRepositoryContext.Provider value={connectionRepository}>
<ToastArea>
<Connections
onConnected={onConnectedSpy}
connectFn={mockConnectFn}
appName="Test App Name"
/>
</ToastArea>
</ConnectionRepositoryContext.Provider>
</ConnectionStorageContext.Provider>
<ToastArea>
<Connections
onConnected={onConnectedSpy}
connectFn={mockConnectFn}
connectionStorage={mockStorage}
appName="Test App Name"
/>
</ToastArea>
</PreferencesProvider>
);

Expand Down Expand Up @@ -351,21 +338,15 @@ describe('Connections Component', function () {
];
const mockStorage = getMockConnectionStorage(connections);
sinon.replace(mockStorage, 'save', saveConnectionSpy);
const connectionRepository = new ConnectionRepository(mockStorage);

render(
<PreferencesProvider value={preferences}>
<ConnectionStorageContext.Provider value={mockStorage}>
<ConnectionRepositoryContext.Provider value={connectionRepository}>
<ToastArea>
<Connections
onConnected={onConnectedSpy}
connectFn={mockConnectFn}
appName="Test App Name"
/>
</ToastArea>
</ConnectionRepositoryContext.Provider>
</ConnectionStorageContext.Provider>
<Connections
onConnected={onConnectedSpy}
connectFn={mockConnectFn}
connectionStorage={mockStorage}
appName="Test App Name"
/>
</PreferencesProvider>
);

Expand Down Expand Up @@ -488,21 +469,15 @@ describe('Connections Component', function () {
sinon
.stub(mockStorage, 'getLegacyConnections')
.resolves([{ name: 'Connection1' }]);

const connectionRepository = new ConnectionRepository(mockStorage);

render(
<PreferencesProvider value={preferences}>
<ConnectionStorageContext.Provider value={mockStorage}>
<ConnectionRepositoryContext.Provider value={connectionRepository}>
<ToastArea>
<Connections
onConnected={onConnectedSpy}
appName="Test App Name"
/>
</ToastArea>
</ConnectionRepositoryContext.Provider>
</ConnectionStorageContext.Provider>
<ToastArea>
<Connections
onConnected={onConnectedSpy}
connectionStorage={mockStorage}
appName="Test App Name"
/>
</ToastArea>
</PreferencesProvider>
);

Expand All @@ -519,21 +494,15 @@ describe('Connections Component', function () {
sinon
.stub(mockStorage, 'getLegacyConnections')
.resolves([{ name: 'Connection2' }]);

const connectionRepository = new ConnectionRepository(mockStorage);

const { rerender } = render(
<PreferencesProvider value={preferences}>
<ConnectionStorageContext.Provider value={mockStorage}>
<ConnectionRepositoryContext.Provider value={connectionRepository}>
<ToastArea>
<Connections
onConnected={onConnectedSpy}
appName="Test App Name"
/>
</ToastArea>
</ConnectionRepositoryContext.Provider>
</ConnectionStorageContext.Provider>
<ToastArea>
<Connections
onConnected={onConnectedSpy}
connectionStorage={mockStorage}
appName="Test App Name"
/>
</ToastArea>
</PreferencesProvider>
);

Expand All @@ -549,17 +518,13 @@ describe('Connections Component', function () {

rerender(
<PreferencesProvider value={preferences}>
<ConnectionStorageContext.Provider value={mockStorage}>
<ConnectionRepositoryContext.Provider value={connectionRepository}>
<ToastArea>
<Connections
onConnected={onConnectedSpy}
connectionStorage={mockStorage}
appName="Test App Name"
/>
</ToastArea>
</ConnectionRepositoryContext.Provider>
</ConnectionStorageContext.Provider>
<ToastArea>
<Connections
onConnected={onConnectedSpy}
connectionStorage={mockStorage}
appName="Test App Name"
/>
</ToastArea>
</PreferencesProvider>
);

Expand Down
Loading

0 comments on commit 27cd80c

Please sign in to comment.