Skip to content

Commit cb9435a

Browse files
committed
feat: dynamic parameter form for workspace updates
Updating a workspace whose template uses dynamic parameters now works like the dashboard. The extension evaluates the new template version with the current values, and opens a form only when they fail. If the build still rejects the values, the form reopens with the server's reasons. Servers before 2.24 lack the evaluate endpoint and keep the classic prompts. The update prompts now show the new template version's message, and a failed update shows the server's error detail instead of the HTTP status. The form follows the VS Code settings editor layout and uses a new ValidationMessage component in @repo/ui that matches VS Code's input validation styles.
1 parent 271ba1c commit cb9435a

55 files changed

Lines changed: 2189 additions & 112 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77

88
## Unreleased
99

10+
### Added
11+
12+
- Updating a workspace whose template uses dynamic parameters works like the
13+
dashboard: the update goes ahead when the current values are still valid, and
14+
a form asks only for missing or invalid ones. Servers before v2.24 keep the
15+
classic prompts.
16+
- The update prompts show the new template version's message.
17+
1018
### Changed
1119

1220
- **Breaking:** the extension no longer follows a redirect to a different
@@ -32,6 +40,8 @@
3240
``!#$%&'*+-.^_`|~``, so whitespace (including tabs and carriage returns) and
3341
`:` are not allowed. An invisible byte order mark at the start of the output,
3442
which some Windows editors and PowerShell add, is ignored.
43+
- A failed workspace update shows the server's error detail instead of the HTTP
44+
status.
3545

3646
## [v1.17.2](https://github.com/coder/vscode-coder/releases/tag/v1.17.2) 2026-10-28
3747

‎packages/mocks/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from "./parameters";
12
export * from "./tasks";
23
export * from "./workspaces";

‎packages/mocks/src/parameters.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Test factories for dynamic template parameter types.
3+
*/
4+
5+
import type {
6+
FriendlyDiagnostic,
7+
PreviewParameter,
8+
PreviewParameterOption,
9+
} from "coder/site/src/api/typesGenerated";
10+
11+
/** Create a mutable, optional string PreviewParameter with no diagnostics. */
12+
export function previewParameter(
13+
overrides: Partial<PreviewParameter> = {},
14+
): PreviewParameter {
15+
return {
16+
name: "region",
17+
display_name: "",
18+
description: "",
19+
type: "string",
20+
form_type: "input",
21+
styling: {},
22+
mutable: true,
23+
default_value: { valid: true, value: "" },
24+
value: { valid: true, value: "" },
25+
icon: "",
26+
options: [],
27+
validations: [],
28+
required: false,
29+
order: 0,
30+
ephemeral: false,
31+
diagnostics: [],
32+
...overrides,
33+
};
34+
}
35+
36+
/** Create a PreviewParameterOption whose name defaults to its value. */
37+
export function parameterOption(
38+
value: string,
39+
name = value,
40+
description = "",
41+
): PreviewParameterOption {
42+
return { name, description, value: { valid: true, value }, icon: "" };
43+
}
44+
45+
/** Create a FriendlyDiagnostic, an error unless `severity` says otherwise. */
46+
export function diagnostic(
47+
summary: string,
48+
severity: FriendlyDiagnostic["severity"] = "error",
49+
): FriendlyDiagnostic {
50+
return { severity, summary, detail: "", extra: { code: "" } };
51+
}

‎packages/shared/src/index.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ export type {
3333
// Workspaces types and API
3434
export * from "./workspaces/types";
3535
export { WorkspacesApi } from "./workspaces/api";
36+
37+
// Workspace Update types and API
38+
export * from "./workspaceUpdate/types";
39+
export * from "./workspaceUpdate/parameters";
40+
export { WorkspaceUpdateApi } from "./workspaceUpdate/api";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Workspace Update API - Type-safe message definitions for the parameter
3+
* form shown when updating a workspace to the latest template version.
4+
*/
5+
6+
import { defineCommand, defineRequest } from "../ipc/protocol";
7+
8+
import type { DynamicParametersResponse } from "coder/site/src/api/typesGenerated";
9+
10+
import type { ParameterValues, WorkspaceUpdateInit } from "./types";
11+
12+
export const WorkspaceUpdateApi = {
13+
// Requests
14+
init: defineRequest<void, WorkspaceUpdateInit>("workspaceUpdate/init"),
15+
evaluate: defineRequest<ParameterValues, DynamicParametersResponse>(
16+
"workspaceUpdate/evaluate",
17+
),
18+
// Commands
19+
submit: defineCommand<ParameterValues>("workspaceUpdate/submit"),
20+
cancel: defineCommand<void>("workspaceUpdate/cancel"),
21+
} as const;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { DynamicParametersResponse } from "coder/site/src/api/typesGenerated";
2+
3+
export function hasErrorDiagnostics({
4+
parameters,
5+
diagnostics,
6+
}: DynamicParametersResponse): boolean {
7+
return [...diagnostics, ...parameters.flatMap((p) => p.diagnostics)].some(
8+
(d) => d.severity === "error",
9+
);
10+
}
11+
12+
/** Multi-select values are stored as a JSON-encoded string array. */
13+
export function parseMultiSelectValue(raw: string): string[] | null {
14+
try {
15+
const parsed: unknown = JSON.parse(raw);
16+
return Array.isArray(parsed) && parsed.every((v) => typeof v === "string")
17+
? parsed
18+
: null;
19+
} catch {
20+
return null;
21+
}
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { DynamicParametersResponse } from "coder/site/src/api/typesGenerated";
2+
3+
export type ParameterValues = Readonly<Record<string, string>>;
4+
5+
export interface WorkspaceUpdateInit {
6+
readonly workspaceName: string;
7+
/** Omitted parameters use the server's value. */
8+
readonly values: ParameterValues;
9+
/** The server's evaluation of `values`. */
10+
readonly evaluation: DynamicParametersResponse;
11+
readonly restart: boolean;
12+
}

‎packages/ui/src/components/Field/Field.css‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
}
55

66
.ui-field {
7+
--ui-field-gap: 4px;
8+
79
display: flex;
810
flex-direction: column;
9-
gap: 4px;
11+
gap: var(--ui-field-gap);
1012
}
1113

1214
.ui-field__description {
1315
color: var(--ui-description-foreground);
1416
}
1517

18+
/* Attaches to the control above, like VS Code's input validation. */
1619
.ui-field__error {
17-
color: var(--ui-error-foreground);
20+
margin-top: calc(-1 * var(--ui-field-gap));
1821
}

‎packages/ui/src/components/Field/Field.stories.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useId, useState } from "react";
33
import { PIXEL_ALL_THEMES } from "#storybook";
44

55
import { Input } from "../Input/Input";
6+
import { ValidationMessage } from "../ValidationMessage/ValidationMessage";
67

78
import { Field } from "./Field";
89

@@ -30,7 +31,11 @@ const FieldStates = (): React.JSX.Element => {
3031
<Field
3132
label="CPU cores"
3233
htmlFor={coresId}
33-
error="Value must be between 1 and 16."
34+
error={
35+
<ValidationMessage severity="error">
36+
Value must be between 1 and 16.
37+
</ValidationMessage>
38+
}
3439
errorId={`${coresId}-error`}
3540
>
3641
<Input

‎packages/ui/src/components/Field/Field.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface FieldProps extends ComponentProps<"div"> {
1414
description?: ReactNode;
1515
/** ID for the description; associate it with the control via aria-describedby. */
1616
descriptionId?: string;
17+
/** Usually one or more `ValidationMessage`s. */
1718
error?: ReactNode;
1819
/** ID for the error; the consumer owns aria-describedby and aria-invalid. */
1920
errorId?: string;
@@ -22,7 +23,7 @@ export interface FieldProps extends ComponentProps<"div"> {
2223
}
2324

2425
/* Lays out a labelled control like a settings-editor entry: semibold label,
25-
control, then muted description or error text. */
26+
muted description, control, then validation messages flush below it. */
2627
export function Field({
2728
label,
2829
htmlFor,
@@ -37,12 +38,12 @@ export function Field({
3738
return (
3839
<div {...props} className={cx("ui-field", className)}>
3940
{label !== undefined && <Label htmlFor={htmlFor}>{label}</Label>}
40-
{children}
4141
{description !== undefined && (
4242
<div id={descriptionId} className="ui-field__description">
4343
{description}
4444
</div>
4545
)}
46+
{children}
4647
{error !== undefined && (
4748
<div id={errorId} className="ui-field__error">
4849
{error}

0 commit comments

Comments
 (0)