Skip to content

Commit ae6981a

Browse files
committed
Review comments
1 parent b8f340c commit ae6981a

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/api/api-helper.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
type Workspace,
44
type WorkspaceAgent,
55
type WorkspaceResource,
6+
type WorkspaceStatus,
67
} from "coder/site/src/api/typesGenerated";
78
import { ErrorEvent } from "eventsource";
89
import { z } from "zod";
@@ -49,6 +50,20 @@ export function extractAgents(
4950
}, [] as WorkspaceAgent[]);
5051
}
5152

53+
export const WORKSPACE_STATUS_LABEL: Readonly<Record<WorkspaceStatus, string>> =
54+
{
55+
canceled: "Canceled",
56+
canceling: "Canceling",
57+
deleted: "Deleted",
58+
deleting: "Deleting",
59+
failed: "Failed",
60+
pending: "Pending",
61+
running: "Running",
62+
starting: "Starting",
63+
stopped: "Stopped",
64+
stopping: "Stopping",
65+
} as const;
66+
5267
export const AgentMetadataEventSchema = z.object({
5368
result: z.object({
5469
collected_at: z.string(),

src/commands.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import * as path from "node:path";
88
import * as semver from "semver";
99
import * as vscode from "vscode";
1010

11-
import { createWorkspaceIdentifier, extractAgents } from "./api/api-helper";
11+
import {
12+
createWorkspaceIdentifier,
13+
extractAgents,
14+
WORKSPACE_STATUS_LABEL,
15+
} from "./api/api-helper";
1216
import { type CoderApi } from "./api/coderApi";
1317
import { type CliManager } from "./core/cliManager";
1418
import * as cliUtils from "./core/cliUtils";
@@ -939,8 +943,7 @@ export class Commands {
939943
icon = "$(debug-stop)";
940944
}
941945
const status =
942-
workspace.latest_build.status.substring(0, 1).toUpperCase() +
943-
workspace.latest_build.status.substring(1);
946+
WORKSPACE_STATUS_LABEL[workspace.latest_build.status];
944947
return {
945948
alwaysShow: true,
946949
label: `${icon} ${workspace.owner_name} / ${workspace.name}`,
@@ -953,6 +956,10 @@ export class Commands {
953956
this.logger.error("Failed to fetch workspaces", ex);
954957
if (ex instanceof CertificateError) {
955958
void ex.showNotification();
959+
} else {
960+
void vscode.window.showErrorMessage(
961+
`Failed to fetch workspaces: ${toError(ex).message}`,
962+
);
956963
}
957964
})
958965
.finally(() => {

src/workspace/workspacesProvider.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from "../api/agentMetadataHelper";
1414
import {
1515
type AgentMetadataEvent,
16+
WORKSPACE_STATUS_LABEL,
1617
extractAgents,
1718
extractAllAgents,
1819
} from "../api/api-helper";
@@ -446,9 +447,7 @@ export class WorkspaceTreeItem extends OpenableTreeItem {
446447
public readonly showOwner: boolean,
447448
public readonly watchMetadata = false,
448449
) {
449-
const status =
450-
workspace.latest_build.status.substring(0, 1).toUpperCase() +
451-
workspace.latest_build.status.substring(1);
450+
const status = WORKSPACE_STATUS_LABEL[workspace.latest_build.status];
452451

453452
const label = showOwner
454453
? `${workspace.owner_name} / ${workspace.name}`

0 commit comments

Comments
 (0)