Skip to content

Commit

Permalink
Add open workspace in browser command (#1466)
Browse files Browse the repository at this point in the history
This commit adds a command and button to the Workspace View to open the selected workspace in the system browser
  • Loading branch information
jpogran authored Jun 5, 2023
1 parent dcf7e2d commit 362e193
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@
"title": "Refresh",
"icon": "$(refresh)"
},
{
"command": "terraform.cloud.workspaces.viewInBrowser",
"title": "View Workspace",
"icon": "$(globe)"
},
{
"command": "terraform.cloud.runs.refresh",
"title": "Refresh",
Expand Down Expand Up @@ -520,6 +525,10 @@
"command": "terraform.providers.openDocumentation",
"when": "false"
},
{
"command": "terraform.cloud.workspaces.viewInBrowser",
"when": "false"
},
{
"command": "terraform.cloud.run.viewInBrowser",
"when": "false"
Expand Down Expand Up @@ -566,6 +575,11 @@
"command": "terraform.providers.openDocumentation",
"when": "view == terraform.providers && viewItem == moduleProviderHasDocs"
},
{
"command": "terraform.cloud.workspaces.viewInBrowser",
"when": "view == terraform.cloud.workspaces",
"group": "inline"
},
{
"command": "terraform.cloud.run.viewInBrowser",
"when": "view == terraform.cloud.runs",
Expand Down
12 changes: 10 additions & 2 deletions src/providers/tfc/workspaceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<Worksp
public readonly onDidChangeTreeData = this.didChangeTreeData.event;
private projectFilter: string | undefined;

// TODO: get from settings or somewhere global
private baseUrl = 'https://app.staging.terraform.io/app';

constructor(private ctx: vscode.ExtensionContext, private runDataProvider: RunTreeDataProvider) {
this.ctx.subscriptions.push(
vscode.commands.registerCommand('terraform.cloud.workspaces.refresh', (workspaceItem: WorkspaceTreeItem) => {
this.refresh();
this.runDataProvider.refresh(workspaceItem);
}),
vscode.commands.registerCommand('terraform.cloud.workspaces.viewInBrowser', (workspace: WorkspaceTreeItem) => {
const runURL = `${this.baseUrl}/${workspace.organization}/workspaces/${workspace.name}`;
vscode.env.openExternal(vscode.Uri.parse(runURL));
}),
vscode.commands.registerCommand('terraform.cloud.workspaces.filterByProject', () => this.filterByProject()),
);
}
Expand Down Expand Up @@ -107,7 +114,8 @@ export class WorkspaceTreeDataProvider implements vscode.TreeDataProvider<Worksp
const project = projects.find((p) => p.id === workspace.relationships.project.data.id);

const projectName = project ? project.attributes.name : '';
items.push(new WorkspaceTreeItem(workspace.attributes.name, workspace.id, projectName));

items.push(new WorkspaceTreeItem(workspace.attributes.name, workspace.id, projectName, organization));
}

return items;
Expand All @@ -134,7 +142,7 @@ export class WorkspaceTreeItem extends vscode.TreeItem {
* @param id This is the workspaceID as well as the unique ID for the treeitem
* @param projectName The name of the project this workspace is in
*/
constructor(public name: string, public id: string, public projectName: string) {
constructor(public name: string, public id: string, public projectName: string, public organization: string) {
super(name, vscode.TreeItemCollapsibleState.None);
this.description = this.projectName;
this.tooltip = new vscode.MarkdownString(`
Expand Down

0 comments on commit 362e193

Please sign in to comment.