-
Notifications
You must be signed in to change notification settings - Fork 978
feat!: add ability to cancel pending workspace build #18713
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
ba41ae8
c4ee5b6
c49c33e
ba1dbf3
acffda6
b672d76
86a34df
42170ab
5db9d71
1ede20c
2597615
6c2d0cf
c800494
c5cb203
1de84cc
17fb6a3
1b7b614
634f556
4deace0
43430fa
6272d93
4d4a01d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…atus for pending builds
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1277,9 +1277,14 @@ class ApiMethods { | |
|
||
cancelWorkspaceBuild = async ( | ||
workspaceBuildId: TypesGen.WorkspaceBuild["id"], | ||
request?: TypesGen.CancelWorkspaceBuildRequest, | ||
): Promise<TypesGen.Response> => { | ||
const params = request?.expect_status | ||
? new URLSearchParams({ expect_status: request.expect_status }).toString() | ||
: ""; | ||
|
||
const response = await this.axios.patch( | ||
`/api/v2/workspacebuilds/${workspaceBuildId}/cancel`, | ||
`/api/v2/workspacebuilds/${workspaceBuildId}/cancel${params ? `?${params}` : ""}`, | ||
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. And just use it directly: `/api/v2/workspacebuilds/${workspaceBuildId}/cancel?${params}` |
||
); | ||
|
||
return response.data; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,12 @@ export const startWorkspace = ( | |
export const cancelBuild = (workspace: Workspace, queryClient: QueryClient) => { | ||
return { | ||
mutationFn: () => { | ||
// If workspace status is pending, include expect_status parameter | ||
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. The comment is just saying what the code is doing below. I would rather not having this comment at all, since I can see it in the code, or explaining the why we need to set the |
||
if (workspace.latest_build.status === "pending") { | ||
deansheather marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return API.cancelWorkspaceBuild(workspace.latest_build.id, { | ||
expect_status: "pending", | ||
}); | ||
} | ||
return API.cancelWorkspaceBuild(workspace.latest_build.id); | ||
}, | ||
onSuccess: async () => { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,8 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({ | |
ephemeralParameters: TypesGen.TemplateVersionParameter[]; | ||
}>({ open: false, action: "start", ephemeralParameters: [] }); | ||
|
||
const [isCancelConfirmOpen, setIsCancelConfirmOpen] = useState(false); | ||
|
||
const { mutate: mutateRestartWorkspace, isPending: isRestarting } = | ||
useMutation({ | ||
mutationFn: API.restartWorkspace, | ||
|
@@ -316,7 +318,7 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({ | |
} | ||
}} | ||
handleUpdate={workspaceUpdate.update} | ||
handleCancel={cancelBuildMutation.mutate} | ||
handleCancel={() => setIsCancelConfirmOpen(true)} | ||
handleRetry={handleRetry} | ||
handleDebug={handleDebug} | ||
handleDormantActivate={async () => { | ||
|
@@ -352,6 +354,21 @@ export const WorkspaceReadyPage: FC<WorkspaceReadyPageProps> = ({ | |
} | ||
/> | ||
|
||
{/* Cancel confirmation dialog */} | ||
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 don't think we need this comment. The code below is pretty easy to understand. |
||
<ConfirmDialog | ||
open={isCancelConfirmOpen} | ||
title="Cancel workspace build" | ||
description={`Are you sure you want to cancel the build for workspace "${workspace.name}"? This will stop the current build process.`} | ||
confirmText="Confirm" | ||
cancelText="Discard" | ||
onClose={() => setIsCancelConfirmOpen(false)} | ||
onConfirm={() => { | ||
cancelBuildMutation.mutate(); | ||
setIsCancelConfirmOpen(false); | ||
}} | ||
type="delete" | ||
/> | ||
|
||
<EphemeralParametersDialog | ||
open={ephemeralParametersDialog.open} | ||
onClose={() => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -497,6 +497,8 @@ const WorkspaceActionsCell: FC<WorkspaceActionsCellProps> = ({ | |
|
||
// State for stop confirmation dialog | ||
const [isStopConfirmOpen, setIsStopConfirmOpen] = useState(false); | ||
// State for cancel confirmation dialog | ||
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. The same here, even seeing we do this for the state above. |
||
const [isCancelConfirmOpen, setIsCancelConfirmOpen] = useState(false); | ||
|
||
const isRetrying = | ||
startWorkspaceMutation.isPending || | ||
|
@@ -606,7 +608,7 @@ const WorkspaceActionsCell: FC<WorkspaceActionsCellProps> = ({ | |
|
||
{abilities.canCancel && ( | ||
<PrimaryAction | ||
onClick={cancelBuildMutation.mutate} | ||
onClick={() => setIsCancelConfirmOpen(true)} | ||
isLoading={cancelBuildMutation.isPending} | ||
label="Cancel build" | ||
> | ||
|
@@ -643,6 +645,21 @@ const WorkspaceActionsCell: FC<WorkspaceActionsCellProps> = ({ | |
}} | ||
type="delete" | ||
/> | ||
|
||
{/* Cancel workspace build confirmation dialog */} | ||
<ConfirmDialog | ||
open={isCancelConfirmOpen} | ||
title="Cancel workspace build" | ||
description={`Are you sure you want to cancel the build for workspace "${workspace.name}"? This will stop the current build process.`} | ||
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. Would be nice if this could differ based on whether it thinks it's going to cancel a pending or running build. e.g. 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. Same with the Dialog on the other page too, maybe it should be made into a component? |
||
confirmText="Confirm" | ||
cancelText="Discard" | ||
onClose={() => setIsCancelConfirmOpen(false)} | ||
onConfirm={() => { | ||
cancelBuildMutation.mutate(); | ||
setIsCancelConfirmOpen(false); | ||
}} | ||
type="delete" | ||
/> | ||
</TableCell> | ||
); | ||
}; | ||
|
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.
You can do: