diff --git a/README.md b/README.md index 3cfe585c..dacc1433 100644 --- a/README.md +++ b/README.md @@ -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:** diff --git a/dev-tools/vscode/drasi-server/README.md b/dev-tools/vscode/drasi-server/README.md index 588be51e..9db1c0eb 100644 --- a/dev-tools/vscode/drasi-server/README.md +++ b/dev-tools/vscode/drasi-server/README.md @@ -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: diff --git a/dev-tools/vscode/drasi-server/package.json b/dev-tools/vscode/drasi-server/package.json index b8de9925..5e110dde 100644 --- a/dev-tools/vscode/drasi-server/package.json +++ b/dev-tools/vscode/drasi-server/package.json @@ -141,6 +141,10 @@ "title": "Use server", "icon": "$(plug)" }, + { + "command": "drasi.connection.delete", + "title": "Delete server" + }, { "command": "drasi.resource.viewConfig", "title": "View Config (YAML)" @@ -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)", @@ -349,6 +358,10 @@ "command": "drasi.connection.use", "when": "true" }, + { + "command": "drasi.connection.delete", + "when": "true" + }, { "command": "drasi.yaml.createSource", "when": "resourceLangId == yaml" diff --git a/dev-tools/vscode/drasi-server/src/drasi-explorer.ts b/dev-tools/vscode/drasi-server/src/drasi-explorer.ts index ba8ac6db..c16d0808 100644 --- a/dev-tools/vscode/drasi-server/src/drasi-explorer.ts +++ b/dev-tools/vscode/drasi-server/src/drasi-explorer.ts @@ -35,6 +35,7 @@ export class DrasiExplorer implements vscode.TreeDataProvider { 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)); } @@ -486,6 +487,42 @@ export class DrasiExplorer implements vscode.TreeDataProvider { 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) { if (!resourceNode) { return; diff --git a/dev-tools/vscode/drasi-server/src/sdk/config.ts b/dev-tools/vscode/drasi-server/src/sdk/config.ts index 5ef08a63..827b3af3 100644 --- a/dev-tools/vscode/drasi-server/src/sdk/config.ts +++ b/dev-tools/vscode/drasi-server/src/sdk/config.ts @@ -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();