fix: Update workspace wasn't using the latest build (#4001)

This was an oversight in a prior contribution. It broke the update
button, but fixed the other cases.
This commit is contained in:
Kyle Carberry 2022-09-12 06:22:29 -05:00 committed by GitHub
parent 43f368dfc4
commit 66ad86a755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 1 deletions

View File

@ -92,6 +92,9 @@ export const workspaceMachine = createMachine(
getTemplate: {
data: TypesGen.Template
}
startWorkspaceWithLatestTemplate: {
data: TypesGen.WorkspaceBuild
}
startWorkspace: {
data: TypesGen.WorkspaceBuild
}
@ -212,7 +215,7 @@ export const workspaceMachine = createMachine(
START: "requestingStart",
STOP: "requestingStop",
ASK_DELETE: "askingDelete",
UPDATE: "refreshingTemplate",
UPDATE: "requestingStartWithLatestTemplate",
CANCEL: "requestingCancel",
},
},
@ -222,6 +225,21 @@ export const workspaceMachine = createMachine(
CANCEL_DELETE: "idle",
},
},
requestingStartWithLatestTemplate: {
entry: "clearBuildError",
invoke: {
id: "startWorkspaceWithLatestTemplate",
src: "startWorkspaceWithLatestTemplate",
onDone: {
target: "idle",
actions: ["assignBuild", "refreshTimeline"],
},
onError: {
target: "idle",
actions: ["assignBuildError"],
},
},
},
requestingStart: {
entry: "clearBuildError",
invoke: {
@ -524,6 +542,13 @@ export const workspaceMachine = createMachine(
throw Error("Cannot get template without workspace")
}
},
startWorkspaceWithLatestTemplate: async (context) => {
if (context.workspace && context.template) {
return await API.startWorkspace(context.workspace.id, context.template.active_version_id)
} else {
throw Error("Cannot start workspace without workspace id")
}
},
startWorkspace: async (context) => {
if (context.workspace) {
return await API.startWorkspace(