Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d158ef

Browse files
authored
Adding support for reading from/writing to workspace connections. (#20853)
* Dev/benjin/workspace connections (#20852) * checkpoint * Cleanup * checkpoint * Refine connection config source handling * Document config handling and factor orphan filters * clenaup * new tests * checkpoint * Removing "getFromWorkspace" optionality in public API * Saving workspace connections * removing unused var * (hopefully) fixing messy merge * loc * test cleanup * fixed test * Cleaning up tests * removing unusued parameter * merging from main * fixing tests
1 parent 471e142 commit 8d158ef

23 files changed

+953
-313
lines changed

extensions/mssql/l10n/bundle.l10n.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,18 @@
17581758
"message": "The connection with ID '{0}' does not have the 'server' property set and is being ignored. Please set the 'server' property on this connection in order to use it.",
17591759
"comment": ["{0} is the connection ID for the connection that has been ignored"]
17601760
},
1761+
"One or more connection groups reference parent groups that do not exist and have been ignored: {0}. Update your settings file to fix these entries./{0} is the comma separated list of connection group names": {
1762+
"message": "One or more connection groups reference parent groups that do not exist and have been ignored: {0}. Update your settings file to fix these entries.",
1763+
"comment": ["{0} is the comma separated list of connection group names"]
1764+
},
1765+
"One or more connections reference groups that do not exist and have been ignored: {0}. Update your connection settings to fix these entries./{0} is the comma separated list of connection display names": {
1766+
"message": "One or more connections reference groups that do not exist and have been ignored: {0}. Update your connection settings to fix these entries.",
1767+
"comment": ["{0} is the comma separated list of connection display names"]
1768+
},
1769+
"Multiple connection groups with ID '{0}' found. Delete or rename all of them, except one in User/Global settings.json, then restart the extension./{0} is the root id": {
1770+
"message": "Multiple connection groups with ID '{0}' found. Delete or rename all of them, except one in User/Global settings.json, then restart the extension.",
1771+
"comment": ["{0} is the root id"]
1772+
},
17611773
"Error migrating connection ID {0} to new format. Please recreate this connection to use it.\nError:\n{1}/{0} is the connection id{1} is the error message": {
17621774
"message": "Error migrating connection ID {0} to new format. Please recreate this connection to use it.\nError:\n{1}",
17631775
"comment": ["{0} is the connection id", "{1} is the error message"]

extensions/mssql/src/connectionSharing/connectionSharingService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export class ConnectionSharingService implements mssql.IConnectionSharingService
381381
await this.validateExtensionPermission(extensionId);
382382

383383
const connections =
384-
await this._connectionManager.connectionStore.connectionConfig.getConnections(false);
384+
await this._connectionManager.connectionStore.connectionConfig.getConnections();
385385
const targetConnection = connections.find((conn) => conn.id === connectionId);
386386

387387
if (!targetConnection) {
@@ -399,7 +399,7 @@ export class ConnectionSharingService implements mssql.IConnectionSharingService
399399
await this.validateExtensionPermission(extensionId);
400400

401401
const connections =
402-
await this._connectionManager.connectionStore.connectionConfig.getConnections(false);
402+
await this._connectionManager.connectionStore.connectionConfig.getConnections();
403403
const targetConnection = connections.find((conn) => conn.id === connectionId);
404404

405405
if (!targetConnection) {
@@ -613,7 +613,7 @@ export class ConnectionSharingService implements mssql.IConnectionSharingService
613613
await this.validateExtensionPermission(extensionId);
614614

615615
const connections =
616-
await this._connectionManager.connectionStore.connectionConfig.getConnections(false);
616+
await this._connectionManager.connectionStore.connectionConfig.getConnections();
617617
const targetConnection = connections.find((conn) => conn.id === connectionId);
618618

619619
if (!targetConnection) {

extensions/mssql/src/connectionconfig/connectionDialogWebviewController.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import {
9595
ChangePasswordWebviewState,
9696
} from "../sharedInterfaces/changePassword";
9797
import { getCloudId } from "../azure/providerSettings";
98+
import { ConnectionConfig } from "./connectionconfig";
9899

99100
const FABRIC_WORKSPACE_AUTOLOAD_LIMIT = 10;
100101
export const CLEAR_TOKEN_CACHE = "clearTokenCache";
@@ -249,8 +250,14 @@ export class ConnectionDialogWebviewController extends FormWebviewController<
249250
}
250251
}
251252

253+
// Ensure connection group is set in precedence order:
254+
// 1. explicitly-specified initialConnectionGroup
255+
// 2. existing groupId on connection being edited
256+
// 3. default to root group
252257
if (initialConnectionGroup) {
253258
this.state.connectionProfile.groupId = initialConnectionGroup.id;
259+
} else {
260+
this.state.connectionProfile.groupId ??= ConnectionConfig.ROOT_GROUP_ID;
254261
}
255262

256263
await this.updateItemVisibility();
@@ -1128,19 +1135,28 @@ export class ConnectionDialogWebviewController extends FormWebviewController<
11281135
);
11291136
}
11301137

1131-
// all properties are set when converting from a ConnectionDetails object,
1132-
// so we want to clean the default undefined properties before saving.
1138+
// Prep connection for saving
1139+
// 1. Clean properties that are set to keep the config JSON clean
11331140
cleanedConnection = ConnectionCredentials.removeUndefinedProperties(
11341141
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11351142
cleanedConnection as any,
11361143
);
11371144

1145+
// 2. Set the config source for serialization; use the group config source if not already set
1146+
if ((cleanedConnection as IConnectionProfile).configSource === undefined) {
1147+
const connectionGroup =
1148+
this._mainController.connectionManager.connectionStore.connectionConfig.getGroupById(
1149+
cleanedConnection.groupId,
1150+
);
1151+
(cleanedConnection as IConnectionProfile).configSource =
1152+
connectionGroup.configSource;
1153+
}
1154+
11381155
async function saveConnectionAndCreateSession(
11391156
self: ConnectionDialogWebviewController,
11401157
): Promise<TreeNodeInfo> {
11411158
await self._mainController.connectionManager.connectionStore.saveProfile(
1142-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1143-
cleanedConnection as any,
1159+
cleanedConnection as IConnectionProfile,
11441160
);
11451161
const node =
11461162
await self._mainController.createObjectExplorerSession(cleanedConnection);

0 commit comments

Comments
 (0)