Skip to content

Commit a4472ef

Browse files
mabaasitaddaleax
andauthored
chore(storage-mixin): connections from storage COMPASS-6948 COMPASS-6949 (#4647)
Co-authored-by: Anna Henningsen <[email protected]>
1 parent b7a79e0 commit a4472ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+953
-8763
lines changed

.evergreen/functions.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ functions:
169169
set -e
170170
eval $(.evergreen/print-compass-env.sh)
171171
172+
# Pre-built binaries for keytar do not support older RHEL versions.
173+
# Since we have started importing keytar from top-level scripts in packages,
174+
# re-built keytar before the bootstrap process so that it is always usable.
175+
if [[ "$IS_RHEL" == "true" ]]; then
176+
echo "Rebuilding packages for rhel"
177+
npm run node-rebuild
178+
fi
179+
172180
# Prepare workspaces in provided scope
173181
npx lerna run bootstrap \
174182
--stream \

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,6 @@ The root cause is native modules compiled for a different version of the runtime
138138
1. Modules have to be recompiled for the runtime they will be used in
139139
1. Due to npm workspaces hoisting all shared dependencies to the very root of the monorepo, all packages use the same modules imported from the same location
140140

141-
This means that if you e.g., start Compass application locally it will recompile all native modules to work in Electron runtime, if you would try to run tests for `mongodb-connection-model` library right after that, tests would fail due to `keytar` library not being compatible with Node.js environment that the tests are running in.
141+
This means that if you e.g., start Compass application locally it will recompile all native modules to work in Electron runtime, if you would try to run tests for `@mongodb-js/connection-storage` library right after that, tests would fail due to `keytar` library not being compatible with Node.js environment that the tests are running in.
142142

143143
If you run into this issue, make sure that native modules are rebuilt for whatever runtime you are planning to use at the moment. To help with that we provide two npm scripts: `npm run electron-rebuild` will recompile native modules to work with Electron and `npm run node-rebuild` will recompile them to work with Node.js.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ Is there anything else you’d like to see in Compass? Let us know by submitting
7272
- [**hadron-reflux-store**](packages/reflux-store): Hadron Reflux Stores
7373
- [**hadron-type-checker**](packages/hadron-type-checker): Hadron Type Checker
7474
- [**mongodb-collection-model**](packages/collection-model): MongoDB collection model
75-
- [**mongodb-connection-model**](packages/connection-model): MongoDB connection model
7675
- [**mongodb-data-service**](packages/data-service): MongoDB Data Service
7776
- [**mongodb-database-model**](packages/database-model): MongoDB database model
7877
- [**mongodb-explain-compat**](packages/mongodb-explain-compat): Convert mongodb SBE explain output to 4.4 explain output

package-lock.json

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function getMockConnectionStorage(
2525
loadAll: () => {
2626
return Promise.resolve(mockConnections);
2727
},
28+
hasLegacyConnections: () => Promise.resolve(false),
2829
save: () => Promise.resolve(),
2930
delete: () => Promise.resolve(),
3031
load: (id: string) =>
@@ -444,4 +445,21 @@ describe('Connections Component', function () {
444445
});
445446
});
446447
});
448+
449+
it('shows toast when user has any legacy connection', async function () {
450+
const mockStorage = getMockConnectionStorage([]);
451+
sinon.stub(mockStorage, 'hasLegacyConnections').resolves(true);
452+
render(
453+
<ToastArea>
454+
<Connections
455+
onConnected={onConnectedSpy}
456+
connectionStorage={mockStorage}
457+
appName="Test App Name"
458+
/>
459+
</ToastArea>
460+
);
461+
await waitFor(
462+
() => expect(screen.getByTestId('toast-legacy-connections')).to.exist
463+
);
464+
});
447465
});

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

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useState } from 'react';
1+
import React, { useCallback, useEffect, useState } from 'react';
22
import {
33
ImportConnectionsModal,
44
ExportConnectionsModal,
@@ -8,6 +8,8 @@ import {
88
ErrorBoundary,
99
spacing,
1010
css,
11+
openToast,
12+
Link,
1113
} from '@mongodb-js/compass-components';
1214
import ConnectionForm from '@mongodb-js/connection-form';
1315
import type { DataService } from 'mongodb-data-service';
@@ -22,11 +24,14 @@ import Connecting from './connecting/connecting';
2224
import { useConnections } from '../stores/connections-store';
2325
import { cloneDeep } from 'lodash';
2426
import ConnectionList from './connection-list/connection-list';
27+
import { getStoragePaths } from '@mongodb-js/compass-utils';
2528

2629
const { log, mongoLogId } = createLoggerAndTelemetry(
2730
'mongodb-compass:connections:connections'
2831
);
2932

33+
const { basepath } = getStoragePaths() ?? {};
34+
3035
type ConnectFn = typeof connect;
3136

3237
export type { ConnectFn };
@@ -55,11 +60,56 @@ const formContainerStyles = css({
5560
height: '100%',
5661
});
5762

63+
const toastListStyle = css({
64+
listStyle: 'inherit',
65+
paddingLeft: spacing[1] + spacing[2],
66+
});
67+
68+
const MigrateLegacyConnectionDescription = () => (
69+
<>
70+
Compass has identified connections created with an older version, which are
71+
no longer supported by the current version. To migrate these connections,
72+
follow the steps below:
73+
<ul className={toastListStyle}>
74+
<li>
75+
Install Compass{' '}
76+
<Link
77+
target="_blank"
78+
hideExternalIcon
79+
href="https://github.com/mongodb-js/compass/releases/tag/v1.39.0"
80+
>
81+
v1.39.0
82+
</Link>{' '}
83+
and{' '}
84+
<Link
85+
target="_blank"
86+
hideExternalIcon
87+
href="https://www.mongodb.com/docs/compass/current/connect/favorite-connections/import-export-ui/export/"
88+
>
89+
export all the connections
90+
</Link>
91+
.
92+
</li>
93+
<li>
94+
Update Compass to the latest version and{' '}
95+
<Link
96+
target="_blank"
97+
hideExternalIcon
98+
href="https://www.mongodb.com/docs/compass/current/connect/favorite-connections/import-export-ui/import/"
99+
>
100+
import the connections
101+
</Link>{' '}
102+
exported.
103+
</li>
104+
</ul>
105+
</>
106+
);
107+
58108
function Connections({
59109
appRegistry,
60110
onConnected,
61111
isConnected,
62-
connectionStorage = new ConnectionStorage(),
112+
connectionStorage = new ConnectionStorage(basepath),
63113
appName,
64114
getAutoConnectInfo,
65115
connectFn = connect,
@@ -122,6 +172,25 @@ function Connections({
122172
[]
123173
);
124174

175+
// Handle Legacy Connections toast.
176+
const [hasSeenLegacyToast, setHasSeenLegacyToast] = useState(false);
177+
useEffect(() => {
178+
if (hasSeenLegacyToast) {
179+
return;
180+
}
181+
void connectionStorage
182+
.hasLegacyConnections()
183+
.then((hasLegacyConnections) => {
184+
if (hasLegacyConnections) {
185+
openToast('legacy-connections', {
186+
title: 'Legacy connections detected',
187+
description: <MigrateLegacyConnectionDescription />,
188+
});
189+
setHasSeenLegacyToast(true);
190+
}
191+
});
192+
}, [connectionStorage, hasSeenLegacyToast]);
193+
125194
return (
126195
<div data-testid="connections-wrapper" className={connectStyles}>
127196
<ResizableSidebar>

packages/compass-connections/src/stores/connections-store.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe('use-connections hook', function () {
217217
await waitFor(() => {
218218
// eslint-disable-next-line @typescript-eslint/unbound-method
219219
expect(mockConnectionStorage.delete).to.have.been.calledWith(
220-
mockRecents[mockRecents.length - 1]
220+
mockRecents[mockRecents.length - 1].id
221221
);
222222
});
223223
});

packages/compass-connections/src/stores/connections-store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export function useConnections({
344344
}
345345

346346
async function removeConnection(connectionInfo: ConnectionInfo) {
347-
await connectionStorage.delete(connectionInfo);
347+
await connectionStorage.delete(connectionInfo.id);
348348
dispatch({
349349
type: 'set-connections',
350350
connections: connections.filter((conn) => conn.id !== connectionInfo.id),
@@ -437,7 +437,7 @@ export function useConnections({
437437
recentConnections.length >= MAX_RECENT_CONNECTIONS_LENGTH
438438
) {
439439
await connectionStorage.delete(
440-
recentConnections[recentConnections.length - 1]
440+
recentConnections[recentConnections.length - 1].id
441441
);
442442
}
443443
} catch (err) {
@@ -700,7 +700,7 @@ export function useConnections({
700700
return !conn.favorite;
701701
});
702702
await Promise.all(
703-
recentConnections.map((conn) => connectionStorage.delete(conn))
703+
recentConnections.map((conn) => connectionStorage.delete(conn.id))
704704
);
705705
dispatch({
706706
type: 'set-connections',

packages/compass-sidebar/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@mongodb-js/compass-databases-navigation": "^1.10.0",
6262
"@mongodb-js/compass-logging": "^1.1.6",
6363
"@mongodb-js/compass-maybe-protect-connection-string": "^0.8.0",
64+
"@mongodb-js/compass-utils": "^0.3.1",
6465
"@mongodb-js/connection-form": "^1.10.0",
6566
"@mongodb-js/connection-storage": "^0.1.0",
6667
"@mongodb-js/mongodb-redux-common": "^2.0.8",
@@ -73,6 +74,7 @@
7374
"@mongodb-js/compass-databases-navigation": "^1.10.0",
7475
"@mongodb-js/compass-logging": "^1.1.6",
7576
"@mongodb-js/compass-maybe-protect-connection-string": "^0.8.0",
77+
"@mongodb-js/compass-utils": "^0.3.1",
7678
"@mongodb-js/connection-form": "^1.10.0",
7779
"@mongodb-js/connection-storage": "^0.1.0",
7880
"@mongodb-js/mongodb-redux-common": "^2.0.8",

packages/compass-sidebar/src/modules/connection-info.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { ConnectionStorage } from '@mongodb-js/connection-storage';
22
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';
3+
import { getStoragePaths } from '@mongodb-js/compass-utils';
34

45
const { debug } = createLoggerAndTelemetry('COMPASS-SIDEBAR');
56

7+
const { basepath } = getStoragePaths() ?? {};
8+
69
/**
710
* Change connection action name.
811
*/
@@ -22,7 +25,7 @@ export const INITIAL_STATE = {
2225
connectionString: 'mongodb://localhost:27017',
2326
},
2427
},
25-
connectionStorage: new ConnectionStorage(),
28+
connectionStorage: new ConnectionStorage(basepath),
2629
};
2730

2831
async function saveConnectionInfo(connectionInfo, connectionStorage) {
@@ -79,7 +82,6 @@ const MAPPINGS = {
7982
* @param {String} state - The status state.
8083
* @param {Object} action - The action.
8184
*
82-
* @returns {String} The new state.
8385
*/
8486
export default function reducer(state = INITIAL_STATE, action) {
8587
const fn = MAPPINGS[action.type];

0 commit comments

Comments
 (0)