Skip to content

Commit edecd14

Browse files
committed
fix: restore granularity to retry operations (debug vs normal)
1 parent 404e4c7 commit edecd14

File tree

5 files changed

+82
-41
lines changed

5 files changed

+82
-41
lines changed

site/src/pages/WorkspacePage/Workspace.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export interface WorkspaceProps {
6666
sshPrefix?: string;
6767
template?: TypesGen.Template;
6868
quotaBudget?: number;
69+
canRetryDebugMode: boolean;
6970
handleBuildRetry: () => void;
71+
handleBuildRetryDebug: () => void;
7072
buildLogs?: React.ReactNode;
7173
builds: TypesGen.WorkspaceBuild[] | undefined;
7274
onLoadMoreBuilds: () => void;
@@ -88,7 +90,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
8890
handleCancel,
8991
handleSettings,
9092
handleChangeVersion,
91-
handleDormantActivate: handleDormantActivate,
93+
handleDormantActivate,
9294
workspace,
9395
isUpdating,
9496
isRestarting,
@@ -103,7 +105,9 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
103105
buildInfo,
104106
sshPrefix,
105107
template,
108+
canRetryDebugMode,
106109
handleBuildRetry,
110+
handleBuildRetryDebug,
107111
buildLogs,
108112
onLoadMoreBuilds,
109113
isLoadingMoreBuilds,
@@ -200,8 +204,10 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
200204
handleCancel={handleCancel}
201205
handleSettings={handleSettings}
202206
handleRetry={handleBuildRetry}
207+
handleRetryDebug={handleBuildRetryDebug}
203208
handleChangeVersion={handleChangeVersion}
204209
handleDormantActivate={handleDormantActivate}
210+
canRetryDebug={canRetryDebugMode}
205211
canChangeVersions={canChangeVersions}
206212
isUpdating={isUpdating}
207213
isRestarting={isRestarting}
@@ -305,8 +311,14 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
305311
<Alert
306312
severity="error"
307313
actions={
308-
<Button onClick={handleBuildRetry} variant="text" size="small">
309-
Retry
314+
<Button
315+
onClick={
316+
canRetryDebugMode ? handleBuildRetryDebug : handleBuildRetry
317+
}
318+
variant="text"
319+
size="small"
320+
>
321+
Retry{canRetryDebugMode && " in debug mode"}
310322
</Button>
311323
}
312324
>

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import BlockIcon from "@mui/icons-material/Block";
1313
import OutlinedBlockIcon from "@mui/icons-material/BlockOutlined";
1414
import PowerSettingsNewIcon from "@mui/icons-material/PowerSettingsNew";
1515
import RetryIcon from "@mui/icons-material/BuildOutlined";
16+
import RetryDebugIcon from "@mui/icons-material/BugReportOutlined";
1617

1718
interface WorkspaceActionProps {
1819
loading?: boolean;
@@ -168,12 +169,17 @@ export const ActionLoadingButton: FC<LoadingProps> = ({ label }) => {
168169
);
169170
};
170171

171-
export function RetryButton({
172-
handleAction,
173-
}: Omit<WorkspaceActionProps, "loading">) {
172+
type DebugButtonProps = Omit<WorkspaceActionProps, "loading"> & {
173+
debug?: boolean;
174+
};
175+
176+
export function RetryButton({ handleAction, debug = false }: DebugButtonProps) {
174177
return (
175-
<Button startIcon={<RetryIcon />} onClick={handleAction}>
176-
Retry
178+
<Button
179+
startIcon={debug ? <RetryDebugIcon /> : <RetryIcon />}
180+
onClick={handleAction}
181+
>
182+
Retry{debug && " (Debug)"}
177183
</Button>
178184
);
179185
}

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ export interface WorkspaceActionsProps {
3939
handleSettings: () => void;
4040
handleChangeVersion: () => void;
4141
handleRetry: () => void;
42+
handleRetryDebug: () => void;
4243
handleDormantActivate: () => void;
4344
isUpdating: boolean;
4445
isRestarting: boolean;
4546
children?: ReactNode;
4647
canChangeVersions: boolean;
48+
canRetryDebug: boolean;
4749
}
4850

4951
export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
@@ -56,11 +58,13 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
5658
handleCancel,
5759
handleSettings,
5860
handleRetry,
61+
handleRetryDebug,
5962
handleChangeVersion,
60-
handleDormantActivate: handleDormantActivate,
63+
handleDormantActivate,
6164
isUpdating,
6265
isRestarting,
6366
canChangeVersions,
67+
canRetryDebug,
6468
}) => {
6569
const { duplicateWorkspace, isDuplicationReady } =
6670
useWorkspaceDuplication(workspace);
@@ -92,26 +96,24 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
9296
activate: <ActivateButton handleAction={handleDormantActivate} />,
9397
activating: <ActivateButton loading handleAction={handleDormantActivate} />,
9498
retry: <RetryButton handleAction={handleRetry} />,
99+
retryDebug: <RetryButton debug handleAction={handleRetryDebug} />,
95100
};
96101

97102
const { actions, canCancel, canAcceptJobs } = actionsByWorkspaceStatus(
98103
workspace,
99-
workspace.latest_build.status,
100-
canChangeVersions,
104+
{ canChangeVersions, canRetryDebug },
101105
);
106+
102107
const canBeUpdated = workspace.outdated && canAcceptJobs;
103108

104109
return (
105110
<div
106111
css={{ display: "flex", alignItems: "center", gap: 12 }}
107112
data-testid="workspace-actions"
108113
>
109-
{/*
110-
* Parentheses important – if canBeUpdated is false, nothing should
111-
* appear in the UI
112-
*/}
113-
{canBeUpdated &&
114-
(isUpdating ? buttonMapping.updating : buttonMapping.update)}
114+
{canBeUpdated && (
115+
<>{isUpdating ? buttonMapping.updating : buttonMapping.update}</>
116+
)}
115117

116118
{isRestarting
117119
? buttonMapping.restarting

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

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

2526
// These are buttons that should be used with disabled UI elements
2627
"canceling",
@@ -33,16 +34,20 @@ const buttonTypes = [
3334
*/
3435
export type ButtonType = (typeof buttonTypes)[number];
3536

36-
interface WorkspaceAbilities {
37+
type WorkspaceAbilities = {
3738
actions: readonly ButtonType[];
3839
canCancel: boolean;
3940
canAcceptJobs: boolean;
40-
}
41+
};
42+
43+
type UserInfo = Readonly<{
44+
canChangeVersions: boolean;
45+
canRetryDebug: boolean;
46+
}>;
4147

4248
export const actionsByWorkspaceStatus = (
4349
workspace: Workspace,
44-
status: WorkspaceStatus,
45-
canChangeVersions: boolean,
50+
userInfo: UserInfo,
4651
): WorkspaceAbilities => {
4752
if (workspace.dormant_at) {
4853
return {
@@ -51,17 +56,21 @@ export const actionsByWorkspaceStatus = (
5156
canAcceptJobs: false,
5257
};
5358
}
54-
if (
59+
60+
const status = workspace.latest_build.status;
61+
const mustUpdate =
5562
workspace.outdated &&
56-
workspaceUpdatePolicy(workspace, canChangeVersions) === "always"
57-
) {
63+
workspaceUpdatePolicy(workspace, userInfo.canChangeVersions) === "always";
64+
65+
if (mustUpdate) {
5866
if (status === "running") {
5967
return {
6068
actions: ["stop"],
6169
canCancel: false,
6270
canAcceptJobs: true,
6371
};
6472
}
73+
6574
if (status === "stopped") {
6675
return {
6776
actions: [],
@@ -70,6 +79,14 @@ export const actionsByWorkspaceStatus = (
7079
};
7180
}
7281
}
82+
83+
if (status === "failed" && userInfo.canRetryDebug) {
84+
return {
85+
...statusToActions.failed,
86+
actions: ["retry", "retryDebug"],
87+
};
88+
}
89+
7390
return statusToActions[status];
7491
};
7592

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ export const WorkspaceReadyPage = ({
7979
...deploymentConfig(),
8080
enabled: permissions?.viewDeploymentValues,
8181
});
82-
const canRetryDebugMode = Boolean(
83-
deploymentValues?.config.enable_terraform_debug_mode,
84-
);
8582

8683
// Build logs
8784
const buildLogs = useWorkspaceBuildLogs(workspace.latest_build.id);
@@ -196,6 +193,22 @@ export const WorkspaceReadyPage = ({
196193
// Cancel build
197194
const cancelBuildMutation = useMutation(cancelBuild(workspace, queryClient));
198195

196+
const handleBuildRetry = (debug = false) => {
197+
const logLevel = debug ? "debug" : undefined;
198+
199+
switch (workspace.latest_build.transition) {
200+
case "start":
201+
startWorkspaceMutation.mutate({ logLevel });
202+
break;
203+
case "stop":
204+
stopWorkspaceMutation.mutate({ logLevel });
205+
break;
206+
case "delete":
207+
deleteWorkspaceMutation.mutate({ logLevel });
208+
break;
209+
}
210+
};
211+
199212
return (
200213
<>
201214
<Helmet>
@@ -242,20 +255,11 @@ export const WorkspaceReadyPage = ({
242255
}}
243256
handleCancel={cancelBuildMutation.mutate}
244257
handleSettings={() => navigate("settings")}
245-
handleBuildRetry={() => {
246-
const logLevel = canRetryDebugMode ? "debug" : undefined;
247-
switch (workspace.latest_build.transition) {
248-
case "start":
249-
startWorkspaceMutation.mutate({ logLevel });
250-
break;
251-
case "stop":
252-
stopWorkspaceMutation.mutate({ logLevel });
253-
break;
254-
case "delete":
255-
deleteWorkspaceMutation.mutate({ logLevel });
256-
break;
257-
}
258-
}}
258+
handleBuildRetry={() => handleBuildRetry(false)}
259+
handleBuildRetryDebug={() => handleBuildRetry(true)}
260+
canRetryDebugMode={
261+
deploymentValues?.config.enable_terraform_debug_mode ?? false
262+
}
259263
handleChangeVersion={() => {
260264
setChangeVersionDialogOpen(true);
261265
}}

0 commit comments

Comments
 (0)