Skip to content

Commit 7b0ef6b

Browse files
committed
Review comments
1 parent b8f340c commit 7b0ef6b

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

src/api/api-helper.ts

Lines changed: 21 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,26 @@ export function extractAgents(
4950
}, [] as WorkspaceAgent[]);
5051
}
5152

53+
const WORKSPACE_STATUS_LABEL: Readonly<Record<WorkspaceStatus, string>> = {
54+
canceled: "Canceled",
55+
canceling: "Canceling",
56+
deleted: "Deleted",
57+
deleting: "Deleting",
58+
failed: "Failed",
59+
pending: "Pending",
60+
running: "Running",
61+
starting: "Starting",
62+
stopped: "Stopped",
63+
stopping: "Stopping",
64+
};
65+
66+
export function workspaceStatusLabel(status: WorkspaceStatus): string {
67+
return (
68+
WORKSPACE_STATUS_LABEL[status] ??
69+
status.charAt(0).toUpperCase() + status.slice(1)
70+
);
71+
}
72+
5273
export const AgentMetadataEventSchema = z.object({
5374
result: z.object({
5475
collected_at: z.string(),

src/commands.ts

Lines changed: 12 additions & 4 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+
workspaceStatusLabel,
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";
@@ -938,9 +942,9 @@ export class Commands {
938942
if (workspace.latest_build.status !== "running") {
939943
icon = "$(debug-stop)";
940944
}
941-
const status =
942-
workspace.latest_build.status.substring(0, 1).toUpperCase() +
943-
workspace.latest_build.status.substring(1);
945+
const status = workspaceStatusLabel(
946+
workspace.latest_build.status,
947+
);
944948
return {
945949
alwaysShow: true,
946950
label: `${icon} ${workspace.owner_name} / ${workspace.name}`,
@@ -953,6 +957,10 @@ export class Commands {
953957
this.logger.error("Failed to fetch workspaces", ex);
954958
if (ex instanceof CertificateError) {
955959
void ex.showNotification();
960+
} else {
961+
void vscode.window.showErrorMessage(
962+
`Failed to fetch workspaces: ${toError(ex).message}`,
963+
);
956964
}
957965
})
958966
.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+
workspaceStatusLabel,
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 = workspaceStatusLabel(workspace.latest_build.status);
452451

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

0 commit comments

Comments
 (0)