Skip to content

Commit 9e1c6f0

Browse files
committed
chore(web): async instead of then
1 parent 9b45120 commit 9e1c6f0

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

packages/compass-web/src/connection-storage.tsx

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -280,47 +280,48 @@ export class AtlasCloudConnectionStorage
280280
private async _loadAndNormalizeClusterDescriptionInfoV2(): Promise<
281281
ConnectionInfo[]
282282
> {
283-
return this.atlasService
284-
.authenticatedFetch(
285-
this.atlasService.cloudEndpoint(
286-
`/explorer/v1/groups/${this.projectId}/clusters/connectionInfo`
287-
)
283+
const res = await this.atlasService.authenticatedFetch(
284+
this.atlasService.cloudEndpoint(
285+
`/explorer/v1/groups/${this.projectId}/clusters/connectionInfo`
288286
)
289-
.then((res) => {
290-
return res.json();
291-
})
292-
.then((connectionInfoList) => {
293-
return connectionInfoList.map((connectionInfo: ConnectionInfo) => {
294-
if (
295-
!connectionInfo.connectionOptions.connectionString ||
296-
!connectionInfo.atlasMetadata ||
297-
// TODO(COMPASS-8228): do not filter out those connections, display
298-
// them in navigation, but in a way that doesn't allow connecting
299-
!CONNECTABLE_CLUSTER_STATES.includes(
300-
connectionInfo.atlasMetadata.clusterState
301-
)
302-
) {
303-
return null;
304-
}
305-
306-
const clusterName = connectionInfo.atlasMetadata.clusterName;
307-
308-
return {
309-
...connectionInfo,
310-
connectionOptions: {
311-
...connectionInfo.connectionOptions,
312-
lookup: () => {
313-
return {
314-
wsURL: this.atlasService.driverProxyEndpoint(
315-
`/clusterConnection/${this.projectId}`
316-
),
317-
projectId: this.projectId,
318-
clusterName,
319-
};
320-
},
287+
);
288+
289+
const connectionInfoList = (await res.json()) as ConnectionInfo[];
290+
291+
return connectionInfoList
292+
.map((connectionInfo: ConnectionInfo): ConnectionInfo | null => {
293+
if (
294+
!connectionInfo.connectionOptions.connectionString ||
295+
!connectionInfo.atlasMetadata ||
296+
// TODO(COMPASS-8228): do not filter out those connections, display
297+
// them in navigation, but in a way that doesn't allow connecting
298+
!CONNECTABLE_CLUSTER_STATES.includes(
299+
connectionInfo.atlasMetadata.clusterState
300+
)
301+
) {
302+
return null;
303+
}
304+
305+
const clusterName = connectionInfo.atlasMetadata.clusterName;
306+
307+
return {
308+
...connectionInfo,
309+
connectionOptions: {
310+
...connectionInfo.connectionOptions,
311+
lookup: () => {
312+
return {
313+
wsURL: this.atlasService.driverProxyEndpoint(
314+
`/clusterConnection/${this.projectId}`
315+
),
316+
projectId: this.projectId,
317+
clusterName,
318+
};
321319
},
322-
};
323-
});
320+
},
321+
};
322+
})
323+
.filter((connectionInfo): connectionInfo is ConnectionInfo => {
324+
return !!connectionInfo;
324325
});
325326
}
326327

0 commit comments

Comments
 (0)