-
Notifications
You must be signed in to change notification settings - Fork 23
WIP: feat: crud workspaces #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
66bd03a
WIP: adding tree view to support crud workspaces
rodrimaia 4612bea
::coffee:: wip
rodrimaia 255d6b6
simplify worktreeprovider
rodrimaia e9813d8
implemente open workspace command
rodrimaia 4024189
lint
rodrimaia d31ba11
copy changes
rodrimaia 2be39ce
login menu option
rodrimaia ddfe7f8
add icons
rodrimaia 035af4a
add workspace settings button
rodrimaia b011502
only show all workspaces tab for coder owners
rodrimaia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
/.vscode-test/ | ||
/.nyc_output/ | ||
/coverage/ | ||
*.vsix | ||
*.vsix | ||
yarn-error.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Workspace, WorkspaceAgent } from "coder/site/src/api/typesGenerated" | ||
|
||
export function extractAgentsAndFolderPath( | ||
workspace: Workspace, | ||
): [agents: WorkspaceAgent[], folderPath: string | undefined] { | ||
// TODO: multiple agent support | ||
const agents = workspace.latest_build.resources.reduce((acc, resource) => { | ||
return acc.concat(resource.agents || []) | ||
}, [] as WorkspaceAgent[]) | ||
|
||
let folderPath = undefined | ||
if (agents.length === 1) { | ||
folderPath = agents[0].expanded_directory | ||
} | ||
return [agents, folderPath] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { getWorkspaces } from "coder/site/src/api/api" | ||
import * as path from "path" | ||
import * as vscode from "vscode" | ||
import { extractAgentsAndFolderPath } from "./api-helper" | ||
|
||
export enum WorkspaceQuery { | ||
Mine = "owner:me", | ||
All = "", | ||
} | ||
|
||
export class WorkspaceProvider implements vscode.TreeDataProvider<WorkspaceTreeItem> { | ||
constructor(private readonly getWorkspacesQuery: WorkspaceQuery) {} | ||
|
||
private _onDidChangeTreeData: vscode.EventEmitter<WorkspaceTreeItem | undefined | null | void> = | ||
new vscode.EventEmitter<WorkspaceTreeItem | undefined | null | void>() | ||
readonly onDidChangeTreeData: vscode.Event<WorkspaceTreeItem | undefined | null | void> = | ||
this._onDidChangeTreeData.event | ||
|
||
refresh(): void { | ||
this._onDidChangeTreeData.fire() | ||
} | ||
|
||
getTreeItem(element: WorkspaceTreeItem): vscode.TreeItem { | ||
return element | ||
} | ||
|
||
getChildren(): Thenable<WorkspaceTreeItem[]> { | ||
return getWorkspaces({ q: this.getWorkspacesQuery }).then((workspaces) => { | ||
return workspaces.workspaces.map((workspace) => { | ||
const status = | ||
workspace.latest_build.status.substring(0, 1).toUpperCase() + workspace.latest_build.status.substring(1) | ||
|
||
const label = | ||
this.getWorkspacesQuery === WorkspaceQuery.All | ||
? `${workspace.owner_name} / ${workspace.name}` | ||
: workspace.name | ||
const detail = `Template: ${workspace.template_display_name || workspace.template_name} • Status: ${status}` | ||
const [, folderPath] = extractAgentsAndFolderPath(workspace) | ||
return new WorkspaceTreeItem(label, detail, workspace.owner_name, workspace.name, folderPath) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
export class WorkspaceTreeItem extends vscode.TreeItem { | ||
constructor( | ||
public readonly label: string, | ||
public readonly tooltip: string, | ||
public readonly workspaceOwner: string, | ||
public readonly workspaceName: string, | ||
public readonly workspaceFolderPath: string | undefined, | ||
) { | ||
super(label, vscode.TreeItemCollapsibleState.None) | ||
} | ||
|
||
iconPath = { | ||
light: path.join(__filename, "..", "..", "media", "logo.svg"), | ||
dark: path.join(__filename, "..", "..", "media", "logo.svg"), | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is more than 1 agent, does everything fail? Should we randomly choose one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good question. I am not changing the actual behavior, just extracted it to a new function. the current version also does this
agents[0]
choice =/ . I am not sure what is the best way to handle multiple agents...