mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: add typegen for templateVersionEditorXService (#6069)
This was borked before, and actually broken!
This commit is contained in:
@@ -104,6 +104,7 @@
|
||||
"@types/react-helmet": "6.1.5",
|
||||
"@types/react-syntax-highlighter": "15.5.5",
|
||||
"@types/semver": "7.3.12",
|
||||
"@types/tar-js": "^0.3.2",
|
||||
"@types/ua-parser-js": "0.7.36",
|
||||
"@types/uuid": "8.3.4",
|
||||
"@typescript-eslint/eslint-plugin": "5.50.0",
|
||||
|
||||
-4
@@ -42,10 +42,6 @@ export const TemplateVersionEditorPage: FC = () => {
|
||||
if (!versionState.context.template) {
|
||||
throw new Error("no template")
|
||||
}
|
||||
// Send a cancel just in case a version is already being created!
|
||||
sendEvent({
|
||||
type: "CANCEL_VERSION",
|
||||
})
|
||||
sendEvent({
|
||||
type: "CREATE_VERSION",
|
||||
files: files,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
ProvisionerJobLog,
|
||||
ProvisionerJobStatus,
|
||||
TemplateVersion,
|
||||
UploadResponse,
|
||||
WorkspaceResource,
|
||||
@@ -7,7 +8,7 @@ import {
|
||||
import { assign, createMachine } from "xstate"
|
||||
import * as API from "api/api"
|
||||
import { TemplateVersionFiles } from "util/templateVersion"
|
||||
import * as Tar from "tar-js"
|
||||
import Tar from "tar-js"
|
||||
|
||||
export interface CreateVersionData {
|
||||
file: File
|
||||
@@ -40,21 +41,34 @@ export const templateVersionEditorMachine = createMachine(
|
||||
| { type: "ADD_BUILD_LOG"; log: ProvisionerJobLog }
|
||||
| { type: "UPDATE_ACTIVE_VERSION" },
|
||||
services: {} as {
|
||||
uploadTar: {
|
||||
data: UploadResponse
|
||||
}
|
||||
createBuild: {
|
||||
data: TemplateVersion
|
||||
}
|
||||
cancelBuild: {
|
||||
data: void
|
||||
}
|
||||
fetchVersion: {
|
||||
data: TemplateVersion
|
||||
}
|
||||
getResources: {
|
||||
data: WorkspaceResource[]
|
||||
}
|
||||
updateActiveVersion: {
|
||||
data: void
|
||||
}
|
||||
},
|
||||
},
|
||||
tsTypes: {} as import("./templateVersionEditorXService.typegen").Typegen0,
|
||||
initial: "idle",
|
||||
states: {
|
||||
idle: {
|
||||
on: {
|
||||
CREATE_VERSION: {
|
||||
actions: ["assignCreateBuild"],
|
||||
target: "uploadTar",
|
||||
target: "cancelingBuild",
|
||||
},
|
||||
UPDATE_ACTIVE_VERSION: {
|
||||
target: "updatingActiveVersion",
|
||||
@@ -71,6 +85,16 @@ export const templateVersionEditorMachine = createMachine(
|
||||
},
|
||||
},
|
||||
},
|
||||
cancelingBuild: {
|
||||
tags: "loading",
|
||||
invoke: {
|
||||
id: "cancelBuild",
|
||||
src: "cancelBuild",
|
||||
onDone: {
|
||||
target: "uploadTar",
|
||||
},
|
||||
},
|
||||
},
|
||||
uploadTar: {
|
||||
tags: "loading",
|
||||
invoke: {
|
||||
@@ -78,7 +102,7 @@ export const templateVersionEditorMachine = createMachine(
|
||||
src: "uploadTar",
|
||||
onDone: {
|
||||
target: "creatingBuild",
|
||||
actions: ["assignUploadResponse"],
|
||||
actions: "assignUploadResponse",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -88,7 +112,7 @@ export const templateVersionEditorMachine = createMachine(
|
||||
id: "createBuild",
|
||||
src: "createBuild",
|
||||
onDone: {
|
||||
actions: ["assignBuild"],
|
||||
actions: "assignBuild",
|
||||
target: "watchingBuildLogs",
|
||||
},
|
||||
},
|
||||
@@ -104,14 +128,14 @@ export const templateVersionEditorMachine = createMachine(
|
||||
},
|
||||
on: {
|
||||
ADD_BUILD_LOG: {
|
||||
actions: ["addBuildLog"],
|
||||
actions: "addBuildLog",
|
||||
},
|
||||
CANCEL_VERSION: {
|
||||
actions: ["cancelBuild"],
|
||||
actions: "cancelBuild",
|
||||
target: "idle",
|
||||
},
|
||||
CREATE_VERSION: {
|
||||
actions: ["cancelBuild", "assignCreateBuild"],
|
||||
actions: ["assignCreateBuild"],
|
||||
target: "uploadTar",
|
||||
},
|
||||
},
|
||||
@@ -145,8 +169,8 @@ export const templateVersionEditorMachine = createMachine(
|
||||
assignCreateBuild: assign({
|
||||
files: (_, event) => event.files,
|
||||
templateId: (_, event) => event.templateId,
|
||||
buildLogs: [],
|
||||
resources: [],
|
||||
buildLogs: (_, _1) => [],
|
||||
resources: (_, _1) => [],
|
||||
}),
|
||||
assignResources: assign({
|
||||
resources: (_, event) => event.data,
|
||||
@@ -174,7 +198,7 @@ export const templateVersionEditorMachine = createMachine(
|
||||
...context.version,
|
||||
job: {
|
||||
...context.version.job,
|
||||
status: "running",
|
||||
status: "running" as ProvisionerJobStatus,
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -238,20 +262,22 @@ export const templateVersionEditorMachine = createMachine(
|
||||
}
|
||||
return API.getTemplateVersionResources(ctx.version.id)
|
||||
},
|
||||
cancelBuild: (ctx) => {
|
||||
cancelBuild: async (ctx) => {
|
||||
if (!ctx.version) {
|
||||
throw new Error("template version must be set")
|
||||
return
|
||||
}
|
||||
if (ctx.version.job.status === "running") {
|
||||
await API.cancelTemplateVersionBuild(ctx.version.id)
|
||||
}
|
||||
return API.cancelTemplateVersionBuild(ctx.version.id)
|
||||
},
|
||||
updateActiveVersion: (ctx) => {
|
||||
updateActiveVersion: async (ctx) => {
|
||||
if (!ctx.templateId) {
|
||||
throw new Error("template must be set")
|
||||
}
|
||||
if (!ctx.version) {
|
||||
throw new Error("template version must be set")
|
||||
}
|
||||
return API.updateActiveTemplateVersion(ctx.templateId, {
|
||||
await API.updateActiveTemplateVersion(ctx.templateId, {
|
||||
id: ctx.version.id,
|
||||
})
|
||||
},
|
||||
|
||||
@@ -3455,6 +3455,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.8.tgz#b94a4391c85666c7b73299fd3ad79d4faa435310"
|
||||
integrity sha512-ipixuVrh2OdNmauvtT51o3d8z12p6LtFW9in7U79der/kwejjdNchQC5UMn5u/KxNoM7VHHOs/l8KS8uHxhODQ==
|
||||
|
||||
"@types/tar-js@^0.3.2":
|
||||
version "0.3.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/tar-js/-/tar-js-0.3.2.tgz#23d3c7c8ce22bec6ed8355c2169dd3fd6ebe2583"
|
||||
integrity sha512-0ySOBNP+/Ey67EZ0QaCOgkt6zSAeayTwsoln02ztlyB5lF4NQD0sl5C7E5eKS+QUb7xgTEPdPo9LUjYOHUJVqQ==
|
||||
|
||||
"@types/testing-library__jest-dom@^5.9.1":
|
||||
version "5.14.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/testing-library__jest-dom/-/testing-library__jest-dom-5.14.5.tgz#d113709c90b3c75fdb127ec338dad7d5f86c974f"
|
||||
|
||||
Reference in New Issue
Block a user