Skip to content

Commit 1bbe8d0

Browse files
committed
Support build parameters on retry and debug actions
1 parent cf51f13 commit 1bbe8d0

File tree

6 files changed

+113
-45
lines changed

6 files changed

+113
-45
lines changed

site/src/pages/WorkspacePage/Workspace.tsx

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type Interpolation, type Theme } from "@emotion/react";
2-
import Button from "@mui/material/Button";
32
import AlertTitle from "@mui/material/AlertTitle";
43
import { type FC } from "react";
54
import { useNavigate } from "react-router-dom";
@@ -44,8 +43,8 @@ export interface WorkspaceProps {
4443
sshPrefix?: string;
4544
template: TypesGen.Template;
4645
canRetryDebugMode: boolean;
47-
handleBuildRetry: () => void;
48-
handleBuildRetryDebug: () => void;
46+
handleRetry: (buildParameters?: TypesGen.WorkspaceBuildParameter[]) => void;
47+
handleDebug: (buildParameters?: TypesGen.WorkspaceBuildParameter[]) => void;
4948
buildLogs?: React.ReactNode;
5049
latestVersion?: TypesGen.TemplateVersion;
5150
permissions: WorkspacePermissions;
@@ -76,8 +75,8 @@ export const Workspace: FC<WorkspaceProps> = ({
7675
sshPrefix,
7776
template,
7877
canRetryDebugMode,
79-
handleBuildRetry,
80-
handleBuildRetryDebug,
78+
handleRetry,
79+
handleDebug,
8180
buildLogs,
8281
latestVersion,
8382
permissions,
@@ -129,8 +128,8 @@ export const Workspace: FC<WorkspaceProps> = ({
129128
handleUpdate={handleUpdate}
130129
handleCancel={handleCancel}
131130
handleSettings={handleSettings}
132-
handleBuildRetry={handleBuildRetry}
133-
handleBuildRetryDebug={handleBuildRetryDebug}
131+
handleRetry={handleRetry}
132+
handleDebug={handleDebug}
134133
handleChangeVersion={handleChangeVersion}
135134
handleDormantActivate={handleDormantActivate}
136135
handleToggleFavorite={handleToggleFavorite}
@@ -208,20 +207,7 @@ export const Workspace: FC<WorkspaceProps> = ({
208207
)}
209208

210209
{workspace.latest_build.job.error && (
211-
<Alert
212-
severity="error"
213-
actions={
214-
<Button
215-
onClick={
216-
canRetryDebugMode ? handleBuildRetryDebug : handleBuildRetry
217-
}
218-
variant="text"
219-
size="small"
220-
>
221-
Retry{canRetryDebugMode && " in debug mode"}
222-
</Button>
223-
}
224-
>
210+
<Alert severity="error">
225211
<AlertTitle>Workspace build failed</AlertTitle>
226212
<AlertDetail>{workspace.latest_build.job.error}</AlertDetail>
227213
</Alert>

site/src/pages/WorkspacePage/WorkspaceActions/Buttons.tsx

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,24 +175,76 @@ export const DisabledButton: FC<DisabledButtonProps> = ({ label }) => {
175175
);
176176
};
177177

178-
type RetryButtonProps = Omit<ActionButtonProps, "loading">;
178+
type RetryButtonProps = Omit<ActionButtonProps, "loading"> & {
179+
enableBuildParameters: boolean;
180+
workspace: Workspace;
181+
};
179182

180-
export const RetryButton: FC<RetryButtonProps> = ({ handleAction }) => {
181-
return (
183+
export const RetryButton: FC<RetryButtonProps> = ({
184+
handleAction,
185+
workspace,
186+
enableBuildParameters,
187+
}) => {
188+
const mainAction = (
182189
<TopbarButton startIcon={<RetryIcon />} onClick={() => handleAction()}>
183190
Retry
184191
</TopbarButton>
185192
);
186-
};
187193

188-
type DebugButtonProps = Omit<ActionButtonProps, "loading">;
194+
if (!enableBuildParameters) {
195+
return mainAction;
196+
}
189197

190-
export const DebugButton: FC<DebugButtonProps> = ({ handleAction }) => {
191198
return (
199+
<ButtonGroup
200+
variant="outlined"
201+
css={{
202+
// Workaround to make the border transitions smoothly on button groups
203+
"& > button:hover + button": {
204+
borderLeft: "1px solid #FFF",
205+
},
206+
}}
207+
>
208+
{mainAction}
209+
<BuildParametersPopover workspace={workspace} onSubmit={handleAction} />
210+
</ButtonGroup>
211+
);
212+
};
213+
214+
type DebugButtonProps = Omit<ActionButtonProps, "loading"> & {
215+
workspace: Workspace;
216+
enableBuildParameters: boolean;
217+
};
218+
219+
export const DebugButton: FC<DebugButtonProps> = ({
220+
handleAction,
221+
workspace,
222+
enableBuildParameters,
223+
}) => {
224+
const mainAction = (
192225
<TopbarButton startIcon={<DebugIcon />} onClick={() => handleAction()}>
193226
Debug
194227
</TopbarButton>
195228
);
229+
230+
if (!enableBuildParameters) {
231+
return mainAction;
232+
}
233+
234+
return (
235+
<ButtonGroup
236+
variant="outlined"
237+
css={{
238+
// Workaround to make the border transitions smoothly on button groups
239+
"& > button:hover + button": {
240+
borderLeft: "1px solid #FFF",
241+
},
242+
}}
243+
>
244+
{mainAction}
245+
<BuildParametersPopover workspace={workspace} onSubmit={handleAction} />
246+
</ButtonGroup>
247+
);
196248
};
197249

198250
interface FavoriteButtonProps {

site/src/pages/WorkspacePage/WorkspaceActions/WorkspaceActions.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export interface WorkspaceActionsProps {
4141
handleCancel: () => void;
4242
handleSettings: () => void;
4343
handleChangeVersion: () => void;
44-
handleRetry: () => void;
45-
handleDebug: () => void;
44+
handleRetry: (buildParameters?: WorkspaceBuildParameter[]) => void;
45+
handleDebug: (buildParameters?: WorkspaceBuildParameter[]) => void;
4646
handleDormantActivate: () => void;
4747
isUpdating: boolean;
4848
isRestarting: boolean;
@@ -133,8 +133,20 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
133133
pending: <DisabledButton label="Pending..." />,
134134
activate: <ActivateButton handleAction={handleDormantActivate} />,
135135
activating: <ActivateButton loading handleAction={handleDormantActivate} />,
136-
retry: <RetryButton handleAction={handleRetry} />,
137-
retryDebug: <DebugButton handleAction={handleDebug} />,
136+
retry: (
137+
<RetryButton
138+
handleAction={handleRetry}
139+
workspace={workspace}
140+
enableBuildParameters={workspace.latest_build.transition === "start"}
141+
/>
142+
),
143+
debug: (
144+
<DebugButton
145+
handleAction={handleDebug}
146+
workspace={workspace}
147+
enableBuildParameters={workspace.latest_build.transition === "start"}
148+
/>
149+
),
138150
toggleFavorite: (
139151
<FavoriteButton
140152
workspaceID={workspace.id}

site/src/pages/WorkspacePage/WorkspaceActions/constants.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const actionTypes = [
2121
// into one of the starting, stopping, or deleting states (based on the
2222
// WorkspaceTransition type)
2323
"retry",
24-
"retryDebug",
24+
"debug",
2525

2626
// These are buttons that should be used with disabled UI elements
2727
"canceling",
@@ -39,7 +39,7 @@ type WorkspaceAbilities = {
3939

4040
export const abilitiesByWorkspaceStatus = (
4141
workspace: Workspace,
42-
canRetryDebug: boolean,
42+
canDebug: boolean,
4343
): WorkspaceAbilities => {
4444
if (workspace.dormant_at) {
4545
return {
@@ -50,10 +50,10 @@ export const abilitiesByWorkspaceStatus = (
5050
}
5151

5252
const status = workspace.latest_build.status;
53-
if (status === "failed" && canRetryDebug) {
53+
if (status === "failed" && canDebug) {
5454
return {
5555
...statusToAbility.failed,
56-
actions: ["retry", "retryDebug"],
56+
actions: ["retry", "debug"],
5757
};
5858
}
5959

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,18 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({
153153
// Cancel build
154154
const cancelBuildMutation = useMutation(cancelBuild(workspace, queryClient));
155155

156-
const handleBuildRetry = (debug = false) => {
156+
const runLastBuild = (
157+
buildParameters: TypesGen.WorkspaceBuildParameter[] | undefined,
158+
debug: boolean,
159+
) => {
157160
const logLevel = debug ? "debug" : undefined;
158161

159162
switch (workspace.latest_build.transition) {
160163
case "start":
161-
startWorkspaceMutation.mutate({ logLevel });
164+
startWorkspaceMutation.mutate({
165+
logLevel,
166+
buildParameters,
167+
});
162168
break;
163169
case "stop":
164170
stopWorkspaceMutation.mutate({ logLevel });
@@ -169,6 +175,18 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({
169175
}
170176
};
171177

178+
const handleRetry = (
179+
buildParameters?: TypesGen.WorkspaceBuildParameter[],
180+
) => {
181+
runLastBuild(buildParameters, false);
182+
};
183+
184+
const handleDebug = (
185+
buildParameters?: TypesGen.WorkspaceBuildParameter[],
186+
) => {
187+
runLastBuild(buildParameters, true);
188+
};
189+
172190
return (
173191
<>
174192
<Helmet>
@@ -207,8 +225,8 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({
207225
}}
208226
handleCancel={cancelBuildMutation.mutate}
209227
handleSettings={() => navigate("settings")}
210-
handleBuildRetry={() => handleBuildRetry(false)}
211-
handleBuildRetryDebug={() => handleBuildRetry(true)}
228+
handleRetry={handleRetry}
229+
handleDebug={handleDebug}
212230
canRetryDebugMode={
213231
deploymentValues?.config.enable_terraform_debug_mode ?? false
214232
}

site/src/pages/WorkspacePage/WorkspaceTopbar.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export interface WorkspaceProps {
5353
canUpdateWorkspace: boolean;
5454
canChangeVersions: boolean;
5555
canRetryDebugMode: boolean;
56-
handleBuildRetry: () => void;
57-
handleBuildRetryDebug: () => void;
56+
handleRetry: (buildParameters?: TypesGen.WorkspaceBuildParameter[]) => void;
57+
handleDebug: (buildParameters?: TypesGen.WorkspaceBuildParameter[]) => void;
5858
isOwner: boolean;
5959
template: TypesGen.Template;
6060
permissions: WorkspacePermissions;
@@ -79,8 +79,8 @@ export const WorkspaceTopbar: FC<WorkspaceProps> = ({
7979
canUpdateWorkspace,
8080
canChangeVersions,
8181
canRetryDebugMode,
82-
handleBuildRetry,
83-
handleBuildRetryDebug,
82+
handleRetry,
83+
handleDebug,
8484
isOwner,
8585
template,
8686
latestVersion,
@@ -266,8 +266,8 @@ export const WorkspaceTopbar: FC<WorkspaceProps> = ({
266266
handleUpdate={handleUpdate}
267267
handleCancel={handleCancel}
268268
handleSettings={handleSettings}
269-
handleRetry={handleBuildRetry}
270-
handleDebug={handleBuildRetryDebug}
269+
handleRetry={handleRetry}
270+
handleDebug={handleDebug}
271271
handleChangeVersion={handleChangeVersion}
272272
handleDormantActivate={handleDormantActivate}
273273
handleToggleFavorite={handleToggleFavorite}

0 commit comments

Comments
 (0)