Skip to content

Commit 7ecdc82

Browse files
committed
chore(connections): separate should show and show methods
1 parent d00eb2d commit 7ecdc82

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

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

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,15 +1830,19 @@ const connectWithOptions = (
18301830
connectionId: connectionInfo.id,
18311831
});
18321832

1833-
const { showEndOfLifeConnectionModal } = preferences.getPreferences();
1834-
18351833
if (
18361834
getGenuineMongoDB(connectionInfo.connectionOptions.connectionString)
18371835
.isGenuine === false
18381836
) {
18391837
dispatch(showNonGenuineMongoDBWarningModal(connectionInfo.id));
1840-
} else if (showEndOfLifeConnectionModal) {
1841-
void dispatch(
1838+
} else if (
1839+
await shouldShowEndOfLifeWarning(
1840+
instanceInfo.build.version,
1841+
preferences,
1842+
debug
1843+
)
1844+
) {
1845+
dispatch(
18421846
showEndOfLifeMongoDBWarningModal(
18431847
connectionInfo.id,
18441848
instanceInfo.build.version
@@ -2168,34 +2172,38 @@ export const showNonGenuineMongoDBWarningModal = (
21682172
};
21692173
};
21702174

2175+
async function shouldShowEndOfLifeWarning(
2176+
serverVersion: string,
2177+
preferences: PreferencesAccess,
2178+
debug: Logger['debug']
2179+
) {
2180+
try {
2181+
const { showEndOfLifeConnectionModal, networkTraffic } =
2182+
preferences.getPreferences();
2183+
if (!showEndOfLifeConnectionModal) {
2184+
return;
2185+
}
2186+
const latestEndOfLifeServerVersion = await getLatestEndOfLifeServerVersion(
2187+
networkTraffic
2188+
);
2189+
return isEndOfLifeVersion(serverVersion, latestEndOfLifeServerVersion);
2190+
} catch (err) {
2191+
debug(
2192+
'failed to get instance details to determine if the server version is end-of-life',
2193+
err
2194+
);
2195+
return false;
2196+
}
2197+
}
2198+
21712199
export const showEndOfLifeMongoDBWarningModal = (
21722200
connectionId: string,
21732201
version: string
2174-
): ConnectionsThunkAction<Promise<void>> => {
2175-
return async (
2176-
_dispatch,
2177-
getState,
2178-
{ track, logger: { debug }, preferences }
2179-
) => {
2180-
try {
2181-
const latestEndOfLifeServerVersion =
2182-
await getLatestEndOfLifeServerVersion(
2183-
preferences.getPreferences().networkTraffic
2184-
);
2185-
if (isEndOfLifeVersion(version, latestEndOfLifeServerVersion)) {
2186-
const connectionInfo = getCurrentConnectionInfo(
2187-
getState(),
2188-
connectionId
2189-
);
2190-
track('Screen', { name: 'end_of_life_mongodb_modal' }, connectionInfo);
2191-
void _showEndOfLifeMongoDBWarningModal(connectionInfo, version);
2192-
}
2193-
} catch (err) {
2194-
debug(
2195-
'failed to get instance details to determine if the server version is end-of-life',
2196-
err
2197-
);
2198-
}
2202+
): ConnectionsThunkAction<void> => {
2203+
return (_dispatch, getState, { track }) => {
2204+
const connectionInfo = getCurrentConnectionInfo(getState(), connectionId);
2205+
track('Screen', { name: 'end_of_life_mongodb_modal' }, connectionInfo);
2206+
void _showEndOfLifeMongoDBWarningModal(connectionInfo, version);
21992207
};
22002208
};
22012209

0 commit comments

Comments
 (0)