Skip to content

Commit e36e84e

Browse files
committed
chore(connections): remove more single connection related code; remove redundant mentions of multiple connections
1 parent eb46cd5 commit e36e84e

31 files changed

+192
-416
lines changed

package-lock.json

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

packages/compass-app-stores/src/stores/instance-store.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -352,25 +352,14 @@ export function createInstancesStore(
352352
}
353353
);
354354

355-
on(
356-
globalAppRegistry,
357-
'sidebar-filter-navigation-list',
358-
({ connectionId }: { connectionId?: string } = {}) => {
359-
const connectedConnectionIds = Array.from(
360-
instancesManager.listMongoDBInstances().keys()
361-
);
362-
// connectionId will be provided by the sidebar when in single connection
363-
// mode. We don't derive that from the list of connected connections
364-
// because there is a possibility for us to be fetching all collections on
365-
// wrong connection that way
366-
const connectionIds = connectionId
367-
? [connectionId]
368-
: connectedConnectionIds;
369-
for (const id of connectionIds) {
370-
void fetchAllCollections({ connectionId: id });
371-
}
355+
on(globalAppRegistry, 'sidebar-filter-navigation-list', () => {
356+
const connectedConnectionIds = Array.from(
357+
instancesManager.listMongoDBInstances().keys()
358+
);
359+
for (const id of connectedConnectionIds) {
360+
void fetchAllCollections({ connectionId: id });
372361
}
373-
);
362+
});
374363

375364
on(
376365
globalAppRegistry,

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

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -243,30 +243,28 @@ describe('useExportConnections', function () {
243243
expect(result.current.state.error).to.equal('');
244244
});
245245

246-
context('when multiple connections is enabled', function () {
247-
it('includes also the non-favorites connections in the export list', function () {
248-
const { result } = renderUseExportConnectionsHook(
249-
{},
250-
{
251-
connections: [
252-
{
253-
id: 'id1',
254-
connectionOptions: {
255-
connectionString: 'mongodb://localhost:2020',
256-
},
257-
favorite: {
258-
name: 'name1',
259-
},
260-
// expecting to include the non-favorite connections as well
261-
savedConnectionType: 'recent',
246+
it('includes also the non-favorites connections in the export list', function () {
247+
const { result } = renderUseExportConnectionsHook(
248+
{},
249+
{
250+
connections: [
251+
{
252+
id: 'id1',
253+
connectionOptions: {
254+
connectionString: 'mongodb://localhost:2020',
262255
},
263-
],
264-
}
265-
);
256+
favorite: {
257+
name: 'name1',
258+
},
259+
// expecting to include the non-favorite connections as well
260+
savedConnectionType: 'recent',
261+
},
262+
],
263+
}
264+
);
266265

267-
expect(result.current.state.connectionList).to.deep.equal([
268-
{ id: 'id1', name: 'name1', selected: true },
269-
]);
270-
});
266+
expect(result.current.state.connectionList).to.deep.equal([
267+
{ id: 'id1', name: 'name1', selected: true },
268+
]);
271269
});
272270
});

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

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -185,24 +185,8 @@ export type State = {
185185
| { status: 'error'; error: Error }
186186
);
187187

188-
// Device auth flow info, stored in state so that it can be appended to the
189-
// "Connecting..." modal. Only required for single connection mode and can be
190-
// cleaned-up when multiple connections is the only mode of the app
191-
oidcDeviceAuthInfo: Record<
192-
ConnectionId,
193-
{
194-
verificationUrl: string;
195-
userCode: string;
196-
}
197-
>;
198-
199188
editingConnectionInfoId: ConnectionId | null;
200189
isEditingConnectionInfoModalOpen: boolean;
201-
202-
// State related to connection favorite fields editing modal form (right now
203-
// only relevant for single connection mode, this might change)
204-
editingConnectionFavoriteInfoId: ConnectionId | null;
205-
isEditingConnectionFavoriteInfoModalOpen: boolean;
206190
};
207191

208192
type ThunkExtraArg = {
@@ -371,13 +355,6 @@ type DisconnectAction = {
371355
connectionId: ConnectionId;
372356
};
373357

374-
type OidcNotifyDeviceAuthAction = {
375-
type: ActionTypes.OidcNotifyDeviceAuth;
376-
connectionId: ConnectionId;
377-
verificationUrl: string;
378-
userCode: string;
379-
};
380-
381358
type CreateNewConnectionAction = {
382359
type: ActionTypes.CreateNewConnection;
383360
};
@@ -422,11 +399,6 @@ type RemoveAllRecentConnectionsActions = {
422399
type: ActionTypes.RemoveAllRecentConnections;
423400
};
424401

425-
type EditConnectionFavoriteInfoAction = {
426-
type: ActionTypes.EditConnectionFavoriteInfo;
427-
connectionId: ConnectionId;
428-
};
429-
430402
function isAction<A extends AnyAction>(
431403
action: AnyAction,
432404
type: A['type']
@@ -491,11 +463,8 @@ const INITIAL_STATE: State = {
491463
status: 'initial',
492464
error: null,
493465
},
494-
oidcDeviceAuthInfo: {},
495466
editingConnectionInfoId: null,
496467
isEditingConnectionInfoModalOpen: false,
497-
editingConnectionFavoriteInfoId: null,
498-
isEditingConnectionFavoriteInfoModalOpen: false,
499468
};
500469

501470
export function getInitialConnectionsStateForConnectionInfos(
@@ -822,10 +791,6 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
822791
isAutoconnectInfo: true,
823792
}
824793
),
825-
// Single connection mode special case: when autoconnecting set
826-
// autoconnect info as editing so that the always-visible connection form
827-
// is populated correctly and the error is mapped to it if it happend
828-
editingConnectionInfoId: connectionState.info.id,
829794
};
830795
}
831796
if (
@@ -834,12 +799,6 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
834799
ActionTypes.ConnectionAttemptStart
835800
)
836801
) {
837-
// Clean-up existing device auth info before starting new connection so that
838-
// we don't show anything until driver actually provides it. Can be removed
839-
// when this state is not in the store anymore
840-
const oidcDeviceAuthInfo = { ...state.oidcDeviceAuthInfo };
841-
delete oidcDeviceAuthInfo[action.connectionInfo.id];
842-
843802
return {
844803
...state,
845804
connections: mergeConnectionStateById(
@@ -870,7 +829,6 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
870829
error: null,
871830
}
872831
),
873-
oidcDeviceAuthInfo,
874832
isEditingConnectionInfoModalOpen:
875833
// Close the modal when connection starts for edited connection
876834
state.editingConnectionInfoId === action.connectionInfo.id
@@ -943,27 +901,6 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
943901
),
944902
};
945903
}
946-
if (
947-
isAction<OidcNotifyDeviceAuthAction>(
948-
action,
949-
ActionTypes.OidcNotifyDeviceAuth
950-
)
951-
) {
952-
if (!hasConnectionForId(state, action.connectionId)) {
953-
return state;
954-
}
955-
956-
return {
957-
...state,
958-
oidcDeviceAuthInfo: {
959-
...state.oidcDeviceAuthInfo,
960-
[action.connectionId]: {
961-
userCode: action.userCode,
962-
verificationUrl: action.verificationUrl,
963-
},
964-
},
965-
};
966-
}
967904
if (
968905
isAction<CreateNewConnectionAction>(action, ActionTypes.CreateNewConnection)
969906
) {
@@ -1071,9 +1008,6 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
10711008
...(state.editingConnectionInfoId === action.connectionId && {
10721009
isEditingConnectionInfoModalOpen: false,
10731010
}),
1074-
...(state.editingConnectionFavoriteInfoId === action.connectionId && {
1075-
isEditingConnectionFavoriteInfoModalOpen: false,
1076-
}),
10771011
};
10781012
}
10791013
if (
@@ -1091,9 +1025,6 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
10911025
...(state.editingConnectionInfoId === action.connectionId && {
10921026
isEditingConnectionInfoModalOpen: false,
10931027
}),
1094-
...(state.editingConnectionFavoriteInfoId === action.connectionId && {
1095-
isEditingConnectionFavoriteInfoModalOpen: false,
1096-
}),
10971028
};
10981029
}
10991030
if (
@@ -1162,10 +1093,6 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
11621093
newConnection?.info.id ?? state.editingConnectionInfoId,
11631094
isEditingConnectionInfoModalOpen: false,
11641095
}),
1165-
...(state.editingConnectionFavoriteInfoId === action.connectionId && {
1166-
editingConnectionFavoriteInfoId: null,
1167-
isEditingConnectionFavoriteInfoModalOpen: false,
1168-
}),
11691096
};
11701097
}
11711098
if (
@@ -1204,12 +1131,6 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
12041131
return id === state.editingConnectionInfoId;
12051132
});
12061133

1207-
const isEditingFavoriteRemoveConnections =
1208-
!!state.editingConnectionFavoriteInfoId &&
1209-
idsToRemove.some((id) => {
1210-
return id === state.editingConnectionFavoriteInfoId;
1211-
});
1212-
12131134
const newConnection = isEditingRemovedConnection
12141135
? createDefaultConnectionState()
12151136
: undefined;
@@ -1236,26 +1157,6 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
12361157
newConnection?.info.id ?? state.editingConnectionInfoId,
12371158
isEditingConnectionInfoModalOpen: false,
12381159
}),
1239-
...(isEditingFavoriteRemoveConnections && {
1240-
editingConnectionFavoriteInfoId: null,
1241-
isEditingConnectionFavoriteInfoModalOpen: false,
1242-
}),
1243-
};
1244-
}
1245-
if (
1246-
isAction<EditConnectionFavoriteInfoAction>(
1247-
action,
1248-
ActionTypes.EditConnectionFavoriteInfo
1249-
)
1250-
) {
1251-
if (!hasConnectionForId(state, action.connectionId)) {
1252-
return state;
1253-
}
1254-
1255-
return {
1256-
...state,
1257-
editingConnectionFavoriteInfoId: action.connectionId,
1258-
isEditingConnectionFavoriteInfoModalOpen: true,
12591160
};
12601161
}
12611162
return state;
@@ -1467,7 +1368,6 @@ export const connect = (
14671368
| ConnectionAttemptErrorAction
14681369
| ConnectionAttemptSuccessAction
14691370
| ConnectionAttemptCancelledAction
1470-
| OidcNotifyDeviceAuthAction
14711371
> => {
14721372
return connectWithOptions(connectionInfo, { forceSave: false });
14731373
};
@@ -1480,7 +1380,6 @@ export const saveAndConnect = (
14801380
| ConnectionAttemptErrorAction
14811381
| ConnectionAttemptSuccessAction
14821382
| ConnectionAttemptCancelledAction
1483-
| OidcNotifyDeviceAuthAction
14841383
> => {
14851384
return connectWithOptions(connectionInfo, { forceSave: true });
14861385
};
@@ -1496,7 +1395,6 @@ const connectWithOptions = (
14961395
| ConnectionAttemptErrorAction
14971396
| ConnectionAttemptSuccessAction
14981397
| ConnectionAttemptCancelledAction
1499-
| OidcNotifyDeviceAuthAction
15001398
> => {
15011399
return async (
15021400
dispatch,
@@ -1595,12 +1493,6 @@ const connectWithOptions = (
15951493
browserCommandForOIDCAuth,
15961494
},
15971495
notifyDeviceFlow: (deviceFlowInfo) => {
1598-
dispatch({
1599-
type: ActionTypes.OidcNotifyDeviceAuth,
1600-
connectionId: connectionInfo.id,
1601-
...deviceFlowInfo,
1602-
});
1603-
16041496
connectionProgress.openNotifyDeviceAuthModal(
16051497
connectionInfo,
16061498
deviceFlowInfo.verificationUrl,

packages/compass-e2e-tests/helpers/commands/close-connect-modal.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/compass-e2e-tests/helpers/commands/connect-form.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ import { getConnectionTitle } from '@mongodb-js/connection-info';
1313
const debug = Debug('compass-e2e-tests');
1414

1515
export async function resetConnectForm(browser: CompassBrowser): Promise<void> {
16-
const Sidebar = Selectors.Multiple;
17-
1816
if (await browser.$(Selectors.ConnectionModal).isDisplayed()) {
1917
await browser.clickVisible(Selectors.ConnectionModalCloseButton);
2018
await browser
2119
.$(Selectors.ConnectionModal)
2220
.waitForDisplayed({ reverse: true });
2321
}
2422

25-
await browser.clickVisible(Sidebar.SidebarNewConnectionButton);
23+
await browser.clickVisible(Selectors.SidebarNewConnectionButton);
2624

2725
const connectionTitleSelector = Selectors.ConnectionModalTitle;
2826

packages/compass-e2e-tests/helpers/commands/connect.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export async function connectWithConnectionString(
7676
});
7777
}
7878

79-
await browser.clickVisible(Selectors.Multiple.SidebarNewConnectionButton);
79+
await browser.clickVisible(Selectors.SidebarNewConnectionButton);
8080
await browser.$(Selectors.ConnectionModal).waitForDisplayed();
8181

8282
await browser.setValueVisible(
@@ -143,12 +143,9 @@ export async function waitForConnectionResult(
143143
if (connectionStatus === 'either') {
144144
// For the very rare cases where we don't care whether it fails or succeeds.
145145
// Usually because the exact result is a race condition.
146-
const successSelector = Selectors.Multiple.connectionItemByName(
147-
connectionName,
148-
{
149-
connected: true,
150-
}
151-
);
146+
const successSelector = Selectors.connectionItemByName(connectionName, {
147+
connected: true,
148+
});
152149
const failureSelector = Selectors.ConnectionToastErrorText;
153150
await browser
154151
.$(`${successSelector},${failureSelector}`)
@@ -159,7 +156,7 @@ export async function waitForConnectionResult(
159156
// server
160157
await browser
161158
.$(
162-
Selectors.Multiple.connectionItemByName(connectionName, {
159+
Selectors.connectionItemByName(connectionName, {
163160
connected: true,
164161
})
165162
)

0 commit comments

Comments
 (0)