Skip to content

Commit b5fa276

Browse files
committed
workspace connection groups now show
1 parent 61e6f28 commit b5fa276

File tree

4 files changed

+89
-65
lines changed

4 files changed

+89
-65
lines changed

src/controllers/connectionGroupWebviewController.ts

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -77,44 +77,58 @@ export class ConnectionGroupWebviewController extends ReactWebviewPanelControlle
7777
return state;
7878
});
7979

80-
this.registerReducer("saveConnectionGroup", async (state, payload) => {
81-
try {
82-
if (this.connectionGroupToEdit) {
83-
this.logger.verbose("Updating existing connection group", payload);
84-
await this.connectionConfig.updateGroup({
85-
...this.connectionGroupToEdit,
86-
name: payload.name,
87-
description: payload.description,
88-
color: payload.color,
89-
});
90-
} else {
91-
this.logger.verbose("Creating new connection group", payload);
92-
await this.connectionConfig.addGroup(createConnectionGroupFromSpec(payload));
93-
}
80+
this.registerReducer(
81+
"saveConnectionGroup",
82+
async (state, payload: ConnectionGroupSpec & { scope: "user" | "workspace" }) => {
83+
try {
84+
if (this.connectionGroupToEdit) {
85+
this.logger.verbose("Updating existing connection group", payload);
86+
// Only update name, description, color; parentId and scope are not editable for existing groups
87+
await this.connectionConfig.updateGroup({
88+
...this.connectionGroupToEdit,
89+
name: payload.name,
90+
description: payload.description,
91+
color: payload.color,
92+
});
93+
} else {
94+
this.logger.verbose("Creating new connection group", payload);
95+
// Set parentId based on scope
96+
let parentId: string | undefined;
97+
if (payload.scope === "workspace") {
98+
parentId = this.connectionConfig.getWorkspaceConnectionsGroupId();
99+
} else {
100+
parentId = this.connectionConfig.getUserConnectionsGroupId();
101+
}
102+
const groupSpec = { ...payload, parentId };
103+
await this.connectionConfig.addGroup(
104+
createConnectionGroupFromSpec(groupSpec),
105+
);
106+
}
94107

95-
sendActionEvent(
96-
TelemetryViews.ConnectionGroup,
97-
TelemetryActions.SaveConnectionGroup,
98-
{ newOrEdit: this.connectionGroupToEdit ? "edit" : "new" },
99-
);
108+
sendActionEvent(
109+
TelemetryViews.ConnectionGroup,
110+
TelemetryActions.SaveConnectionGroup,
111+
{ newOrEdit: this.connectionGroupToEdit ? "edit" : "new" },
112+
);
100113

101-
this.dialogResult.resolve(true);
102-
await this.panel.dispose();
103-
} catch (err) {
104-
state.message = getErrorMessage(err);
105-
sendErrorEvent(
106-
TelemetryViews.ConnectionGroup,
107-
TelemetryActions.SaveConnectionGroup,
108-
err,
109-
true, // includeErrorMessage
110-
undefined, // errorCode
111-
undefined, // errorType
112-
{ newOrEdit: this.connectionGroupToEdit ? "edit" : "new" },
113-
);
114-
}
114+
this.dialogResult.resolve(true);
115+
await this.panel.dispose();
116+
} catch (err) {
117+
state.message = getErrorMessage(err);
118+
sendErrorEvent(
119+
TelemetryViews.ConnectionGroup,
120+
TelemetryActions.SaveConnectionGroup,
121+
err,
122+
true, // includeErrorMessage
123+
undefined, // errorCode
124+
undefined, // errorType
125+
{ newOrEdit: this.connectionGroupToEdit ? "edit" : "new" },
126+
);
127+
}
115128

116-
return state;
117-
});
129+
return state;
130+
},
131+
);
118132
}
119133
}
120134

@@ -124,6 +138,8 @@ export function createConnectionGroupFromSpec(spec: ConnectionGroupState): IConn
124138
description: spec.description,
125139
color: spec.color,
126140
id: Utils.generateGuid(),
141+
parentId:
142+
"parentId" in spec && spec.parentId !== undefined ? String(spec.parentId) : undefined,
127143
};
128144
}
129145

src/objectExplorer/objectExplorerService.ts

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,19 @@ export class ObjectExplorerService {
8888
const result = [];
8989

9090
const rootId = this._connectionManager.connectionStore.rootGroupId;
91-
9291
if (!this._connectionGroupNodes.has(rootId)) {
9392
this._logger.error(
9493
"Root server group is not defined. Cannot get root nodes for Object Explorer.",
9594
);
9695
return [];
9796
}
9897

99-
// Only show 'User Connections' and 'Workspace Connections' as children of ROOT
98+
// Always show both User Connections and Workspace Connections as children of ROOT
10099
const rootChildren = this._connectionGroupNodes.get(rootId)?.children || [];
101-
for (const child of rootChildren) {
102-
if (child.label === "User Connections" || child.label === "Workspace Connections") {
103-
result.push(child);
104-
}
105-
}
100+
let userGroup = rootChildren.find((child) => child.label === "User Connections");
101+
let workspaceGroup = rootChildren.find((child) => child.label === "Workspace Connections");
102+
if (userGroup) result.push(userGroup);
103+
if (workspaceGroup) result.push(workspaceGroup);
106104

107105
return result;
108106
}
@@ -394,16 +392,22 @@ export class ObjectExplorerService {
394392
);
395393

396394
const rootId = this._connectionManager.connectionStore.rootGroupId;
397-
const serverGroups =
398-
await this._connectionManager.connectionStore.readAllConnectionGroups();
395+
// Read user and workspace groups separately
396+
const userGroups =
397+
this._connectionManager.connectionStore.connectionConfig.getGroupsFromSettings();
398+
// Import ConfigurationTarget from the correct module
399+
// Use VscodeWrapper.ConfigurationTarget.Workspace
400+
const { ConfigurationTarget } = require("../controllers/vscodeWrapper");
401+
const workspaceGroups =
402+
this._connectionManager.connectionStore.connectionConfig.getGroupsFromSettings(
403+
ConfigurationTarget.Workspace,
404+
);
405+
// Merge root, user, and workspace groups
406+
const allGroups = [...userGroups, ...workspaceGroups];
399407
let savedConnections = await this._connectionManager.connectionStore.readAllConnections();
400408

401409
// if there are no saved connections, show the add connection node
402-
if (
403-
savedConnections.length === 0 &&
404-
serverGroups.length === 1 &&
405-
serverGroups[0].id === rootId
406-
) {
410+
if (savedConnections.length === 0 && allGroups.length === 1 && allGroups[0].id === rootId) {
407411
this._logger.verbose(
408412
"No saved connections or groups found. Showing add connection node.",
409413
);
@@ -416,34 +420,27 @@ export class ObjectExplorerService {
416420
const newConnectionGroupNodes = new Map<string, ConnectionGroupNode>();
417421
const newConnectionNodes = new Map<string, ConnectionNode>();
418422

419-
// Add all group nodes from settings first
420-
for (const group of serverGroups) {
423+
// Add all group nodes from merged settings
424+
for (const group of allGroups) {
421425
const groupNode = new ConnectionGroupNode(group);
422-
423426
if (this._connectionGroupNodes.has(group.id)) {
424427
groupNode.id = this._connectionGroupNodes.get(group.id).id;
425428
}
426-
427429
newConnectionGroupNodes.set(group.id, groupNode);
428430
}
429431

430432
// Populate group hierarchy - add each group as a child to its parent
431-
for (const group of serverGroups) {
433+
for (const group of allGroups) {
432434
// Skip the root group as it has no parent
433435
if (group.id === rootId) {
434436
continue;
435437
}
436-
437438
if (group.parentId && newConnectionGroupNodes.has(group.parentId)) {
438439
const parentNode = newConnectionGroupNodes.get(group.parentId);
439440
const childNode = newConnectionGroupNodes.get(group.id);
440-
441441
if (parentNode && childNode) {
442442
parentNode.addChild(childNode);
443-
444443
if (parentNode.id !== rootId) {
445-
// set the parent node for the child group unless the parent is the root group
446-
// parent property is used to
447444
childNode.parentNode = parentNode;
448445
}
449446
} else {
@@ -462,9 +459,7 @@ export class ObjectExplorerService {
462459
for (const connection of savedConnections) {
463460
if (connection.groupId && newConnectionGroupNodes.has(connection.groupId)) {
464461
const groupNode = newConnectionGroupNodes.get(connection.groupId);
465-
466462
let connectionNode: ConnectionNode;
467-
468463
if (this._connectionNodes.has(connection.id)) {
469464
connectionNode = this._connectionNodes.get(connection.id);
470465
connectionNode.updateConnectionProfile(connection);
@@ -475,9 +470,7 @@ export class ObjectExplorerService {
475470
groupNode.id === rootId ? undefined : groupNode,
476471
);
477472
}
478-
479473
connectionNode.parentNode = groupNode.id === rootId ? undefined : groupNode;
480-
481474
newConnectionNodes.set(connection.id, connectionNode);
482475
groupNode.addChild(connectionNode);
483476
} else {
@@ -491,7 +484,6 @@ export class ObjectExplorerService {
491484
this._connectionNodes = newConnectionNodes;
492485

493486
const result = [...this._rootTreeNodeArray];
494-
495487
getConnectionActivity.end(ActivityStatus.Succeeded, undefined, {
496488
nodeCount: result.length,
497489
});

src/reactviews/pages/ConnectionGroup/connectionGroup.component.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export const ConnectionGroupDialog = ({
9999
const [color, setColor] = useState(intialHsvColor);
100100
const [pickerColor, setPickerColor] = useState(intialHsvColor);
101101
const [popoverOpen, setPopoverOpen] = useState(false);
102+
const [scope, setScope] = useState(state.scope || "user");
102103

103104
const handleChange: ColorPickerProps["onColorChange"] = (_, data) => {
104105
setColor({ ...data.color, a: 1 });
@@ -116,6 +117,7 @@ export const ConnectionGroupDialog = ({
116117
color:
117118
new TinyColor(color).toHexString(false /* allow3Char */).toUpperCase() ||
118119
undefined,
120+
scope,
119121
});
120122
}
121123
}
@@ -145,6 +147,17 @@ export const ConnectionGroupDialog = ({
145147
<br />
146148
</>
147149
)}{" "}
150+
<Field className={formStyles.formComponentDiv} label={"Scope"} required>
151+
<select
152+
value={scope}
153+
onChange={(e) =>
154+
setScope(e.target.value as "user" | "workspace")
155+
}
156+
style={{ width: "100%", padding: "8px", fontSize: "16px" }}>
157+
<option value="user">User Connections</option>
158+
<option value="workspace">Workspace Connections</option>
159+
</select>
160+
</Field>
148161
<Field
149162
className={formStyles.formComponentDiv}
150163
label={Loc.connectionGroups.name}
@@ -157,7 +170,7 @@ export const ConnectionGroupDialog = ({
157170
required
158171
placeholder={Loc.connectionGroups.enterConnectionGroupName}
159172
/>
160-
</Field>{" "}
173+
</Field>
161174
<Field
162175
className={formStyles.formComponentDiv}
163176
label={Loc.connectionGroups.description}>

src/sharedInterfaces/connectionGroup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface IConnectionGroup {
2222
parentId?: string;
2323
color?: string;
2424
description?: string;
25+
scope?: "user" | "workspace";
2526
}
2627

2728
/**
@@ -41,6 +42,7 @@ export interface ConnectionGroupState {
4142
description?: string;
4243
color?: string;
4344
message?: string;
45+
scope?: "user" | "workspace";
4446
}
4547

4648
/**
@@ -68,4 +70,5 @@ export interface ConnectionGroupSpec {
6870
name: string;
6971
description?: string;
7072
color?: string;
73+
scope: "user" | "workspace";
7174
}

0 commit comments

Comments
 (0)