Skip to content

feat: UI for canceling workspace builds #1735

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

Merged
merged 10 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Start hooking up cancel
  • Loading branch information
presleyp committed May 23, 2022
commit ff45d7124241ad36ef5e080299656fdcacd5fe7e
5 changes: 5 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ export const startWorkspace = postWorkspaceBuild("start")
export const stopWorkspace = postWorkspaceBuild("stop")
export const deleteWorkspace = postWorkspaceBuild("delete")

export const cancelWorkspaceBuild = async (workspaceBuildId: TypesGen.WorkspaceBuild["id"]): Promise<string> => {
const response = await axios.patch(`/api/v2/workspacebuilds/${workspaceBuildId}/cancel`)
return response.data
}

export const createUser = async (user: TypesGen.CreateUserRequest): Promise<TypesGen.User> => {
const response = await axios.post<TypesGen.User>("/api/v2/users", user)
return response.data
Expand Down
26 changes: 26 additions & 0 deletions site/src/xServices/workspace/workspaceXService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ContextExclusionPlugin } from "webpack"
import { assign, createMachine, send } from "xstate"
import { pure } from "xstate/lib/actions"
import * as API from "../../api/api"
Expand Down Expand Up @@ -68,6 +69,9 @@ export const workspaceMachine = createMachine(
stopWorkspace: {
data: TypesGen.WorkspaceBuild
}
cancelWorkspace: {
data: TypesGen.WorkspaceBuild
}
refreshWorkspace: {
data: TypesGen.Workspace | undefined
}
Expand Down Expand Up @@ -208,6 +212,21 @@ export const workspaceMachine = createMachine(
},
},
},
requestingCancel: {
entry: "clearCancelError",
invoke: {
id: "cancelWorkspace",
src: "cancelWorkspace",
onDone: {
target: "idle",
actions: ["assignBuild", "refreshTimeline"],
},
onError: {
target: "idle",
actions: ["assignBuildError", "displayBuildError"]
}
}
},
refreshingTemplate: {
entry: "clearRefreshTemplateError",
invoke: {
Expand Down Expand Up @@ -459,6 +478,13 @@ export const workspaceMachine = createMachine(
throw Error("Cannot stop workspace without workspace id")
}
},
cancelWorkspace: async (context) => {
if (context.workspace) {
return await API.cancelWorkspaceBuild(context.workspace.latest_build.id)
} else {
throw Error("Cannot cancel workspace without build id")
}
},
refreshWorkspace: async (context) => {
if (context.workspace) {
return await API.getWorkspace(context.workspace.id)
Expand Down