Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ npm run package

**Managing Servers:**
1. Open the **Drasi** view in the Activity Bar
2. Right-click to add/edit server connections
2. Right-click to add/edit/delete server connections
3. Click the plug icon to switch active server

**Launching the Server:**
Expand Down
6 changes: 6 additions & 0 deletions dev-tools/vscode/drasi-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ Use the **Drasi** view in the activity bar:

To edit the active server URL, choose **Edit server URL**.

### Delete a Server

1. Right-click the server entry you want to remove
2. Select **Delete server**
3. Confirm the deletion when prompted

### Launch a Server

Open a Drasi config YAML file (one with `apiVersion: drasi.io/v1`). A **▶ Launch Server** code lens appears at the top. Click it to:
Expand Down
13 changes: 13 additions & 0 deletions dev-tools/vscode/drasi-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
"title": "Use server",
"icon": "$(plug)"
},
{
"command": "drasi.connection.delete",
"title": "Delete server"
},
{
"command": "drasi.resource.viewConfig",
"title": "View Config (YAML)"
Expand Down Expand Up @@ -291,6 +295,11 @@
"when": "view == drasi && viewItem == drasi.connectionNode",
"group": "navigation"
},
{
"command": "drasi.connection.delete",
"when": "view == drasi && (viewItem == drasi.connectionNode || viewItem == drasi.connectionCurrentNode)",
"group": "3_danger"
},
{
"command": "drasi.instance.add",
"when": "view == drasi && (viewItem == drasi.connectionNode || viewItem == drasi.connectionCurrentNode)",
Expand Down Expand Up @@ -349,6 +358,10 @@
"command": "drasi.connection.use",
"when": "true"
},
{
"command": "drasi.connection.delete",
"when": "true"
},
{
"command": "drasi.yaml.createSource",
"when": "resourceLangId == yaml"
Expand Down
37 changes: 37 additions & 0 deletions dev-tools/vscode/drasi-server/src/drasi-explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class DrasiExplorer implements vscode.TreeDataProvider<ExplorerNode> {
vscode.commands.registerCommand('drasi.connection.configure', this.configureConnection.bind(this));
vscode.commands.registerCommand('drasi.connection.add', this.addConnection.bind(this));
vscode.commands.registerCommand('drasi.connection.use', this.useConnection.bind(this));
vscode.commands.registerCommand('drasi.connection.delete', this.deleteConnection.bind(this));
vscode.commands.registerCommand('drasi.resource.viewConfig', this.viewConfig.bind(this));
}

Expand Down Expand Up @@ -486,6 +487,42 @@ export class DrasiExplorer implements vscode.TreeDataProvider<ExplorerNode> {
this.refresh();
}

async deleteConnection(connectionNode?: ConnectionNode) {
let target = connectionNode?.connection;
if (!target) {
await this.registry.ensureDefaultConnection();
const connections = this.registry.getConnections();
const currentId = this.registry.getCurrentConnectionId();
const options = connections.map((connection) => ({
label: connection.name,
description: connection.url,
detail: connection.id === currentId ? 'Current' : undefined,
connection,
}));
const picked = await vscode.window.showQuickPick(options, {
placeHolder: 'Select Drasi server to delete',
matchOnDescription: true,
});
if (!picked) {
return;
}
target = picked.connection;
}

const confirm = await vscode.window.showWarningMessage(
`Are you sure you want to delete server "${target.name}"?`,
'Yes',
'No'
);

if (confirm !== 'Yes') {
return;
}

await this.registry.removeConnection(target.id);
this.refresh();
}

private async startStopResource(resourceNode: ResourceNode, action: string, fn: () => Promise<void>) {
if (!resourceNode) {
return;
Expand Down
14 changes: 14 additions & 0 deletions dev-tools/vscode/drasi-server/src/sdk/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ export class ConnectionRegistry {
return connection;
}

async removeConnection(connectionId: string) {
const connections = this.getConnections();
const remaining = connections.filter((connection) => connection.id !== connectionId);
if (remaining.length === connections.length) {
return;
}
await this.setConnections(remaining);

if (this.getCurrentConnectionId() === connectionId) {
const nextId = remaining.length > 0 ? remaining[0].id : '';
await this.setCurrentConnectionId(nextId);
}
}

async updateCurrentConnectionUrl(url: string) {
const connections = this.getConnections();
const currentId = this.getCurrentConnectionId();
Expand Down