Skip to content

Commit a8f551c

Browse files
committed
chore(app-stores): handle ipv6 hosts when building data for instance model; pass instance info to constructor instead of extra .set call
1 parent 7ecdc82 commit a8f551c

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,26 +320,36 @@ export function createInstancesStore(
320320
connections.getDataServiceForConnection(instanceConnectionId);
321321
const connectionString = dataService.getConnectionString();
322322
const firstHost = connectionString.hosts[0] || '';
323-
const [hostname, port] = firstHost.split(':');
323+
const [hostname, port] = (() => {
324+
if (firstHost.startsWith('[')) {
325+
return firstHost.slice(1).split(']'); // IPv6
326+
}
327+
return firstHost.split(':');
328+
})();
324329

325330
const initialInstanceProps: Partial<MongoDBInstanceProps> = {
331+
// We pre-fetched instance info and so can right away construct it in a
332+
// "ready" state
333+
...(instanceInfo as Partial<MongoDBInstanceProps>),
334+
status: 'ready',
335+
statusError: null,
336+
337+
// Required initial values that are not returned with instance info
326338
_id: firstHost,
327339
hostname: hostname,
328340
port: port ? +port : undefined,
329341
topologyDescription: getTopologyDescription(
330342
dataService.getLastSeenTopology()
331343
),
344+
345+
// Service injection for preferences (currently only controls namespace
346+
// stats fetching)
332347
preferences,
333348
};
334349
const instance = instancesManager.createMongoDBInstanceForConnection(
335350
instanceConnectionId,
336351
initialInstanceProps as MongoDBInstanceProps
337352
);
338-
instance.set({
339-
status: 'ready',
340-
statusError: null,
341-
...(instanceInfo as Partial<MongoDBInstanceProps>),
342-
});
343353

344354
addCleanup(() => {
345355
instance.removeAllListeners();

0 commit comments

Comments
 (0)