Skip to content

Commit 4e1fd28

Browse files
committed
add forceSave option to connect action creator
1 parent f2a74f0 commit 4e1fd28

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function Connections({
118118
);
119119

120120
const onConnectClick = (connectionInfo: ConnectionInfo) => {
121-
void connect(connectionInfo);
121+
void connect(connectionInfo, { forceSave: false });
122122
};
123123

124124
const connectionErrorMessage = getConnectionErrorMessage(

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ type ConnectionAutoconnectCheckAction = {
313313
type ConnectionAttemptStartAction = {
314314
type: ActionTypes.ConnectionAttemptStart;
315315
connectionInfo: ConnectionInfo;
316+
options: {
317+
forceSave: boolean;
318+
};
316319
};
317320

318321
type ConnectionAttemptSuccessAction = {
@@ -823,10 +826,13 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
823826
state.connections,
824827
action.connectionInfo.id,
825828
{
826-
...(isNewConnection(state, action.connectionInfo.id)
829+
...(isNewConnection(state, action.connectionInfo.id) ||
830+
action.options.forceSave
827831
? {
828-
// For new connections, update the state with new info right
829-
// away (we will also save it to the storage at the end)
832+
// For new connections or when we're forcing a
833+
// save (the Save & Connect button), update the state with new
834+
// info right away (we will also save it to the storage at the
835+
// end)
830836
info: action.connectionInfo,
831837
}
832838
: {
@@ -1383,7 +1389,7 @@ export const autoconnectCheck = (
13831389
connectionInfo: connectionInfo,
13841390
});
13851391
if (connectionInfo) {
1386-
void dispatch(connect(connectionInfo));
1392+
void dispatch(connect(connectionInfo, { forceSave: false }));
13871393
}
13881394
} catch (err) {
13891395
dispatch(connectionAttemptError(null, err));
@@ -1455,8 +1461,13 @@ function isAtlasStreamsInstance(
14551461
}
14561462
}
14571463

1464+
export type ConnectOptions = {
1465+
forceSave: boolean;
1466+
};
1467+
14581468
export const connect = (
1459-
connectionInfo: ConnectionInfo
1469+
connectionInfo: ConnectionInfo,
1470+
options: ConnectOptions
14601471
): ConnectionsThunkAction<
14611472
Promise<void>,
14621473
| ConnectionAttemptStartAction
@@ -1516,6 +1527,7 @@ export const connect = (
15161527
dispatch({
15171528
type: ActionTypes.ConnectionAttemptStart,
15181529
connectionInfo,
1530+
options: { forceSave: options.forceSave },
15191531
});
15201532

15211533
track(

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ConnectionInfo } from '@mongodb-js/connection-storage/provider';
22
import { useConnectionActions, useConnectionsState } from './store-context';
3+
import type { ConnectOptions } from './connections-store-redux';
34

45
type State = {
56
connectionErrors: Record<string, Error | null>;
@@ -15,7 +16,10 @@ type State = {
1516
export function useConnections(): {
1617
state: State;
1718

18-
connect: (connectionInfo: ConnectionInfo) => Promise<void>;
19+
connect: (
20+
connectionInfo: ConnectionInfo,
21+
options: ConnectOptions
22+
) => Promise<void>;
1923
disconnect: (connectionId: string) => void;
2024

2125
createNewConnection: () => void;

packages/compass-connections/src/stores/store-context.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
configureStore,
1515
ConnectionId,
1616
ConnectionState,
17+
ConnectOptions,
1718
} from './connections-store-redux';
1819
import {
1920
cancelEditConnection,
@@ -84,8 +85,8 @@ export const connect = ((
8485

8586
function getConnectionsActions(dispatch: ConnectionsStore['dispatch']) {
8687
return {
87-
connect: (connectionInfo: ConnectionInfo) => {
88-
return dispatch(connectionsConnect(connectionInfo));
88+
connect: (connectionInfo: ConnectionInfo, options: ConnectOptions) => {
89+
return dispatch(connectionsConnect(connectionInfo, options));
8990
},
9091
disconnect: (connectionId: ConnectionId) => {
9192
return dispatch(disconnect(connectionId));

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export function MultipleConnectionSidebar({
205205
filterRegex={activeConnectionsFilterRegex}
206206
onFilterChange={onActiveConnectionFilterChange}
207207
onConnect={(connectionInfo) => {
208-
void connect(connectionInfo);
208+
void connect(connectionInfo, { forceSave: false });
209209
}}
210210
onNewConnection={createNewConnection}
211211
onEditConnection={(connectionInfo) => {
@@ -260,15 +260,14 @@ export function MultipleConnectionSidebar({
260260
isEditingNewConnection || disableEditingConnectedConnection
261261
? undefined
262262
: (connectionInfo) => {
263-
void connect(connectionInfo);
263+
void connect(connectionInfo, { forceSave: false });
264264
}
265265
}
266266
onSaveAndConnectClicked={
267267
disableEditingConnectedConnection
268268
? undefined
269269
: (connectionInfo) => {
270-
void saveEditedConnection(connectionInfo);
271-
void connect(connectionInfo);
270+
void connect(connectionInfo, { forceSave: true });
272271
}
273272
}
274273
/>

0 commit comments

Comments
 (0)