Skip to content

Commit 66bd03a

Browse files
committed
WIP: adding tree view to support crud workspaces
1 parent 6babe59 commit 66bd03a

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

package.json

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"coder": [
4343
{
4444
"id": "coderRemote",
45-
"name": "",
45+
"name": "Workspaces",
4646
"visibility": "visible",
4747
"icon": "media/logo.svg",
4848
"contextualTitle": "Coder Remote"
@@ -54,11 +54,6 @@
5454
"view": "coderRemote",
5555
"contents": "Coder is a platform that provisions remote development environments. \n[Login](command:coder.login)",
5656
"when": "!coder.authenticated && coder.loaded"
57-
},
58-
{
59-
"view": "coderRemote",
60-
"contents": "You're logged in! \n[Open Workspace](command:coder.open)",
61-
"when": "coder.authenticated && coder.loaded"
6257
}
6358
],
6459
"commands": [
@@ -79,7 +74,27 @@
7974
"title": "Coder: Update Workspace",
8075
"when": "coder.workspace.updatable"
8176
}
82-
]
77+
],
78+
"menus": {
79+
"view/title": [
80+
{
81+
"command": "coder.logout",
82+
"when": "coder.authenticated"
83+
},
84+
{
85+
"command": "coder.createWorkspace",
86+
"when": "coder.authenticated",
87+
"group": "navigation"
88+
}
89+
],
90+
"view/item/context": [
91+
{
92+
"command": "coder.open",
93+
"when": "coder.authenticated",
94+
"group": "inline"
95+
}
96+
]
97+
}
8398
},
8499
"scripts": {
85100
"vscode:prepublish": "yarn package",

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import * as vscode from "vscode"
66
import { Commands } from "./commands"
77
import { Remote } from "./remote"
88
import { Storage } from "./storage"
9+
import { WorkspaceProvider } from "./workspacesProvider"
910

1011
export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
1112
const output = vscode.window.createOutputChannel("Coder")
1213
const storage = new Storage(output, ctx.globalState, ctx.secrets, ctx.globalStorageUri, ctx.logUri)
1314
await storage.init()
1415

16+
vscode.window.registerTreeDataProvider("coderRemote", new WorkspaceProvider())
17+
1518
getAuthenticatedUser()
1619
.then(() => {
1720
vscode.commands.executeCommand("setContext", "coder.authenticated", true)

src/workspacesProvider.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { getWorkspaces } from "coder/site/src/api/api"
2+
import * as path from "path"
3+
import * as vscode from "vscode"
4+
5+
export class WorkspaceProvider implements vscode.TreeDataProvider<Dependency> {
6+
getTreeItem(element: Dependency): vscode.TreeItem {
7+
return element
8+
}
9+
10+
getChildren(): Thenable<Dependency[]> {
11+
return getWorkspaces({
12+
q: "owner:me",
13+
}).then((workspaces) => {
14+
const exampleWorkspaces = [{ name: "example1" }, { name: "example2" }]
15+
return [...workspaces.workspaces, ...exampleWorkspaces].map(
16+
(workspace) => new Dependency(workspace.name, vscode.TreeItemCollapsibleState.None),
17+
)
18+
})
19+
}
20+
}
21+
22+
class Dependency extends vscode.TreeItem {
23+
constructor(public readonly label: string, public readonly collapsibleState: vscode.TreeItemCollapsibleState) {
24+
super(label, collapsibleState)
25+
this.tooltip = `${this.label}`
26+
}
27+
28+
iconPath = {
29+
light: path.join(__filename, "..", "..", "media", "logo.svg"),
30+
dark: path.join(__filename, "..", "..", "media", "logo.svg"),
31+
}
32+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy