Skip to content

Commit 7022f0f

Browse files
committed
WIP: adding tree view to support crud workspaces
1 parent 4e471cb commit 7022f0f

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ 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+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17+
vscode.window.registerTreeDataProvider("coderRemote", new WorkspaceProvider())
18+
1519
getUser()
1620
.then(() => {
1721
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)