mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-25 17:23:10 -05:00
Cleaning up some code in Async Server Tree. (#22732)
This commit is contained in:
@@ -157,6 +157,51 @@ export class ConnectionProfileGroup implements IConnectionProfileGroup {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given connections from the group.
|
||||
*/
|
||||
public removeConnections(connections: ConnectionProfile[]): void {
|
||||
const connectionIdsToRemove = connections.map(conn => conn.id);
|
||||
this._childConnections = this._childConnections.filter((conn) => { return !connectionIdsToRemove.includes(conn.id); });
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the matching connection from the group if it exists
|
||||
*/
|
||||
public getMatchingConnection(connection: ConnectionProfile): ConnectionProfile | undefined {
|
||||
return this._childConnections.find((conn) => connection.matches(conn));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given connection to the group if it doesn't already exist, otherwise replaces the matching connection.
|
||||
*/
|
||||
public addOrReplaceConnection(connection: ConnectionProfile): void {
|
||||
const matchingConnection = this.getMatchingConnection(connection);
|
||||
connection.parent = this;
|
||||
connection.groupId = this.id;
|
||||
if (matchingConnection) {
|
||||
this.replaceConnection(connection, matchingConnection.id);
|
||||
} else {
|
||||
this._childConnections.push(connection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the connection with the given id with the given connection
|
||||
* @param connection The connection to replace with
|
||||
* @param oldConnectionId The id of the existing connection to replace
|
||||
*/
|
||||
public replaceConnection(connection: ConnectionProfile, oldConnectionId: string): void {
|
||||
const oldConnectionIndex = this._childConnections.findIndex((conn) => conn.id === oldConnectionId);
|
||||
if (oldConnectionIndex !== -1) {
|
||||
this._childConnections[oldConnectionIndex] = connection;
|
||||
connection.parent = this;
|
||||
connection.groupId = this.id;
|
||||
} else {
|
||||
throw new Error(`Could not find connection with id ${oldConnectionId} in group ${this.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
public getParent(): ConnectionProfileGroup | undefined {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user