|
| 1 | +import { getWorkspaces } from "coder/site/src/api/api" |
| 2 | +import * as path from "path" |
1 | 3 | import * as vscode from "vscode" |
2 | 4 |
|
3 | 5 | export class OutlineProvider implements vscode.TreeDataProvider<any> { |
4 | | - constructor(private outline: any, private context: vscode.ExtensionContext) { |
5 | | - console.log(outline) |
6 | | - } |
| 6 | + constructor(private outline: any, private context: vscode.ExtensionContext) {} |
7 | 7 |
|
8 | | - getTreeItem(item: any): vscode.TreeItem { |
9 | | - return new vscode.TreeItem( |
10 | | - item.label, |
11 | | - item.children.length > 0 ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.None, |
12 | | - ) |
| 8 | + getTreeItem(element: Workspace): vscode.TreeItem { |
| 9 | + return element |
13 | 10 | } |
14 | 11 |
|
15 | | - getChildren(element?: any): Thenable<[]> { |
| 12 | + async getChildren(element?: Workspace): Promise<Workspace[]> { |
16 | 13 | // TODO - make request to get requests |
17 | 14 | // then resolve with workspaces as children |
18 | 15 | // otherwise resolve with empty array |
| 16 | + // TODO create dummy data and show those |
| 17 | + const workspaces = await getWorkspaces({ |
| 18 | + q: "owner:me", |
| 19 | + }).catch(() => { |
| 20 | + return |
| 21 | + }) |
19 | 22 |
|
20 | | - // TODO - if error, what do we do? |
| 23 | + if (workspaces) { |
| 24 | + const items: Workspace[] = workspaces.workspaces.map((workspace) => { |
| 25 | + return new Workspace( |
| 26 | + `${workspace.name}`, |
| 27 | + vscode.TreeItemCollapsibleState.None, |
| 28 | + `${workspace.latest_build.status !== "running" ? "circle-outline" : "circle-filled"}`, |
| 29 | + { |
| 30 | + command: "coder.open", |
| 31 | + title: "", |
| 32 | + arguments: [workspace.owner_name, workspace.name], |
| 33 | + }, |
| 34 | + ) |
| 35 | + }) |
21 | 36 |
|
22 | | - // TODO - if you login does it refresh the view? |
23 | | - // same thing with logout |
24 | | - if (element) { |
25 | | - return Promise.resolve(element.children) |
| 37 | + return Promise.resolve(items) |
26 | 38 | } else { |
27 | 39 | return Promise.resolve([]) |
28 | 40 | } |
| 41 | + |
| 42 | + // TODO - if error, what do we do? |
| 43 | + |
| 44 | + // TODO - if you login does it refresh the view? |
| 45 | + // same thing with logout |
| 46 | + // if (element) { |
| 47 | + // return Promise.resolve(element.children) |
| 48 | + // } else { |
| 49 | + // return Promise.resolve(this.outline) |
| 50 | + // } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +export class Workspace extends vscode.TreeItem { |
| 55 | + constructor( |
| 56 | + public readonly label: string, |
| 57 | + public readonly collapsibleState: vscode.TreeItemCollapsibleState, |
| 58 | + public readonly iconId: vscode.ThemeIcon["id"], |
| 59 | + public readonly command?: vscode.Command, |
| 60 | + ) { |
| 61 | + super(label, collapsibleState) |
| 62 | + |
| 63 | + this.tooltip = `${this.label}` |
| 64 | + } |
| 65 | + |
| 66 | + // this.iconId iconPath = this.iconId |
| 67 | + iconPath = { |
| 68 | + light: path.join(__filename, "..", "..", "media", "dependency.svg"), |
| 69 | + dark: path.join(__filename, "..", "..", "media", "dependency.svg"), |
29 | 70 | } |
30 | 71 | } |
0 commit comments