Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: add typegen for templateVersionEditorXService #6069

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 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {
ProvisionerJobLog,
ProvisionerJobStatus,
TemplateVersion,
UploadResponse,
WorkspaceResource,
} from "api/typesGenerated"
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
Expand Down Expand Up @@ -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",
Expand All @@ -71,14 +85,24 @@ export const templateVersionEditorMachine = createMachine(
},
},
},
cancelingBuild: {
tags: "loading",
invoke: {
id: "cancelBuild",
src: "cancelBuild",
onDone: {
target: "uploadTar",
},
},
},
uploadTar: {
tags: "loading",
invoke: {
id: "uploadTar",
src: "uploadTar",
onDone: {
target: "creatingBuild",
actions: ["assignUploadResponse"],
actions: "assignUploadResponse",
},
},
},
Expand All @@ -88,7 +112,7 @@ export const templateVersionEditorMachine = createMachine(
id: "createBuild",
src: "createBuild",
onDone: {
actions: ["assignBuild"],
actions: "assignBuild",
target: "watchingBuildLogs",
},
},
Expand All @@ -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",
},
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -174,7 +198,7 @@ export const templateVersionEditorMachine = createMachine(
...context.version,
job: {
...context.version.job,
status: "running",
status: "running" as ProvisionerJobStatus,
},
}
},
Expand Down Expand Up @@ -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,
})
},
Expand Down
5 changes: 5 additions & 0 deletions site/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down