-
Notifications
You must be signed in to change notification settings - Fork 899
fix: display explicit 'retry' button(s) when a workspace fails #10720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c28f1d8
c249a40
718972f
6005cec
0f91d44
d635ecd
404e4c7
edecd14
b1f6660
c3edba7
2c55fd8
8d7fe73
91ce668
44f86d5
abc3ae6
fa64932
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ const buttonTypes = [ | |
// into one of the starting, stopping, or deleting states (based on the | ||
// WorkspaceTransition type) | ||
"retry", | ||
"retryDebug", | ||
|
||
// These are buttons that should be used with disabled UI elements | ||
"canceling", | ||
|
@@ -33,16 +34,20 @@ const buttonTypes = [ | |
*/ | ||
export type ButtonType = (typeof buttonTypes)[number]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not familiar with this syntax...what is going on here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a little bit to unpack, but:
I did forget to actually export the array, though, so I'll fix that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Appreciate the explanation. It would be nice to use this syntax with |
||
|
||
interface WorkspaceAbilities { | ||
type WorkspaceAbilities = { | ||
actions: readonly ButtonType[]; | ||
canCancel: boolean; | ||
canAcceptJobs: boolean; | ||
} | ||
}; | ||
|
||
type UserInfo = Readonly<{ | ||
canChangeVersions: boolean; | ||
canRetryDebug: boolean; | ||
}>; | ||
|
||
export const actionsByWorkspaceStatus = ( | ||
workspace: Workspace, | ||
status: WorkspaceStatus, | ||
canChangeVersions: boolean, | ||
userInfo: UserInfo, | ||
): WorkspaceAbilities => { | ||
if (workspace.dormant_at) { | ||
return { | ||
|
@@ -51,17 +56,21 @@ export const actionsByWorkspaceStatus = ( | |
canAcceptJobs: false, | ||
}; | ||
} | ||
if ( | ||
|
||
const status = workspace.latest_build.status; | ||
const mustUpdate = | ||
workspace.outdated && | ||
workspaceUpdatePolicy(workspace, canChangeVersions) === "always" | ||
) { | ||
workspaceUpdatePolicy(workspace, userInfo.canChangeVersions) === "always"; | ||
|
||
if (mustUpdate) { | ||
if (status === "running") { | ||
return { | ||
actions: ["stop"], | ||
canCancel: false, | ||
canAcceptJobs: true, | ||
}; | ||
} | ||
|
||
if (status === "stopped") { | ||
return { | ||
actions: [], | ||
|
@@ -70,6 +79,14 @@ export const actionsByWorkspaceStatus = ( | |
}; | ||
} | ||
} | ||
|
||
if (status === "failed" && userInfo.canRetryDebug) { | ||
return { | ||
...statusToActions.failed, | ||
actions: ["retry", "retryDebug"], | ||
}; | ||
} | ||
|
||
return statusToActions[status]; | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,9 +79,6 @@ export const WorkspaceReadyPage = ({ | |
...deploymentConfig(), | ||
enabled: permissions?.viewDeploymentValues, | ||
}); | ||
const canRetryDebugMode = Boolean( | ||
deploymentValues?.config.enable_terraform_debug_mode, | ||
); | ||
|
||
// Build logs | ||
const buildLogs = useWorkspaceBuildLogs(workspace.latest_build.id); | ||
|
@@ -196,6 +193,22 @@ export const WorkspaceReadyPage = ({ | |
// Cancel build | ||
const cancelBuildMutation = useMutation(cancelBuild(workspace, queryClient)); | ||
|
||
const handleBuildRetry = (debug = false) => { | ||
const logLevel = debug ? "debug" : undefined; | ||
|
||
switch (workspace.latest_build.transition) { | ||
case "start": | ||
startWorkspaceMutation.mutate({ logLevel }); | ||
break; | ||
case "stop": | ||
stopWorkspaceMutation.mutate({ logLevel }); | ||
break; | ||
case "delete": | ||
deleteWorkspaceMutation.mutate({ logLevel }); | ||
break; | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Helmet> | ||
|
@@ -242,20 +255,11 @@ export const WorkspaceReadyPage = ({ | |
}} | ||
handleCancel={cancelBuildMutation.mutate} | ||
handleSettings={() => navigate("settings")} | ||
handleBuildRetry={() => { | ||
const logLevel = canRetryDebugMode ? "debug" : undefined; | ||
switch (workspace.latest_build.transition) { | ||
case "start": | ||
startWorkspaceMutation.mutate({ logLevel }); | ||
break; | ||
case "stop": | ||
stopWorkspaceMutation.mutate({ logLevel }); | ||
break; | ||
case "delete": | ||
deleteWorkspaceMutation.mutate({ logLevel }); | ||
break; | ||
} | ||
}} | ||
handleBuildRetry={() => handleBuildRetry(false)} | ||
handleBuildRetryDebug={() => handleBuildRetry(true)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of passing 2 props here, can we just have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would work – my main concern with setting up the functions the way I did was insulating the downstream components from changes, or having implementation details leak out Right now, I am aware that it does kind of increase the number of props (when we already have a lot), but keeping the other components blind to the implementation details seemed like the lesser of two evils to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we might be pre-optimizing here, but I'm happy to keep as-is! |
||
canRetryDebugMode={ | ||
deploymentValues?.config.enable_terraform_debug_mode ?? false | ||
} | ||
handleChangeVersion={() => { | ||
setChangeVersionDialogOpen(true); | ||
}} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge change, but I wanted to make it super explicit that the logic was accounting for three cases:
canBeUpdated
is false