Skip to content

Commit 5459b78

Browse files
authored
fix(connection-import-export): use getConnectionTitle() instead of fav name COMPASS-10038 (#7538)
We have not had the distinction between favorites and non-favorites for a while now, so just using `getConnectionTitle()` is the right thing to use for getting a good connection display name.
1 parent a6e9385 commit 5459b78

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

package-lock.json

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

packages/compass-connection-import-export/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"dependencies": {
5252
"@mongodb-js/compass-components": "^1.57.1",
5353
"@mongodb-js/compass-connections": "^1.86.0",
54+
"@mongodb-js/connection-info": "^0.22.0",
5455
"@mongodb-js/connection-storage": "^0.60.0",
5556
"compass-preferences-model": "^2.64.0",
5657
"hadron-ipc": "^3.5.21",

packages/compass-connection-import-export/src/hooks/use-export-connections.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,23 @@ describe('useExportConnections', function () {
261261
// expecting to include the non-favorite connections as well
262262
savedConnectionType: 'recent',
263263
},
264+
{
265+
id: 'id2',
266+
connectionOptions: {
267+
connectionString: 'mongodb://localhost:2021',
268+
},
269+
favorite: {
270+
name: '',
271+
},
272+
// expecting to include the non-favorite connections as well
273+
savedConnectionType: 'recent',
274+
},
264275
],
265276
}
266277
);
267278

268279
expect(result.current.state.connectionList).to.deep.equal([
280+
{ id: 'id2', name: 'localhost:2021', selected: true },
269281
{ id: 'id1', name: 'name1', selected: true },
270282
]);
271283
});

packages/compass-connection-import-export/src/hooks/use-export-connections.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
} from './common';
1919
import { usePreference } from 'compass-preferences-model/provider';
2020
import { useConnectionsList } from '@mongodb-js/compass-connections/provider';
21+
import { getConnectionTitle } from '@mongodb-js/connection-info';
2122

2223
type ExportConnectionsState = CommonImportExportState<ConnectionShortInfo> & {
2324
removeSecrets: boolean;
@@ -29,12 +30,12 @@ const INITIAL_STATE: Readonly<ExportConnectionsState> = Object.freeze({
2930
});
3031

3132
function connectionInfosToConnectionShortInfos(
32-
infos: Pick<ConnectionInfo, 'favorite' | 'id'>[],
33+
infos: Pick<ConnectionInfo, 'favorite' | 'id' | 'connectionOptions'>[],
3334
existingShortInfoList?: ConnectionShortInfo[]
3435
): ConnectionShortInfo[] {
3536
return infos.map((conn) => ({
3637
id: conn.id,
37-
name: conn.favorite?.name ?? '',
38+
name: getConnectionTitle(conn),
3839
selected:
3940
existingShortInfoList?.find(({ id }) => id === conn.id)?.selected ?? true,
4041
}));

packages/compass-connection-import-export/src/hooks/use-import-connections.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
useConnectionActions,
2020
useConnectionsList,
2121
} from '@mongodb-js/compass-connections/provider';
22+
import { getConnectionTitle } from '@mongodb-js/connection-info';
2223

2324
type ConnectionImportInfo = ConnectionShortInfo & {
2425
isExistingConnection: boolean;
@@ -59,10 +60,11 @@ async function loadFile(
5960
});
6061

6162
for (const info of connections) {
62-
if (info.favorite?.name) {
63+
const name = getConnectionTitle(info);
64+
if (name) {
6365
const isExistingConnection = existingConnectionIds.includes(info.id);
6466
connectionList.push({
65-
name: info.favorite.name,
67+
name,
6668
id: info.id,
6769
selected: !isExistingConnection,
6870
isExistingConnection,

0 commit comments

Comments
 (0)