Skip to content

feat: Add template version warnings (WIP) #7509

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

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
site: get template version
  • Loading branch information
mtojek committed May 10, 2023
commit 912a604a5acffba90abc5ee152cf725627e6da00
36 changes: 36 additions & 0 deletions site/src/xServices/workspace/workspaceXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface WorkspaceContext {
eventSource?: EventSource
workspace?: TypesGen.Workspace
template?: TypesGen.Template
templateVersion?: TypesGen.TemplateVersion
build?: TypesGen.WorkspaceBuild
getWorkspaceError?: AxiosError
getTemplateWarning: Error | unknown
Expand Down Expand Up @@ -157,6 +158,9 @@ export const workspaceMachine = createMachine(
getTemplate: {
data: TypesGen.Template
}
getTemplateVersion: {
data: TypesGen.TemplateVersion
}
getTemplateParameters: {
data: TypesGen.TemplateVersionParameter[]
}
Expand Down Expand Up @@ -221,6 +225,28 @@ export const workspaceMachine = createMachine(
onDone: [
{
actions: ["assignTemplate", "clearGetTemplateWarning"],
target: "gettingTemplateVersion",
},
],
onError: [
{
actions: [
"assignGetTemplateWarning",
"displayGetTemplateWarning",
],
target: "error",
},
],
},
tags: "loading",
},
gettingTemplateVersion: {
invoke: {
src: "getTemplateVersion",
id: "getTemplateVersion",
onDone: [
{
actions: ["assignTemplateVersion", "clearGetTemplateWarning"],
target: "gettingPermissions",
},
],
Expand Down Expand Up @@ -557,6 +583,9 @@ export const workspaceMachine = createMachine(
assignTemplate: assign({
template: (_, event) => event.data,
}),
assignTemplateVersion: assign({
templateVersion: (_, event) => event.data,
}),
assignPermissions: assign({
// Setting event.data as Permissions to be more stricted. So we know
// what permissions we asked for.
Expand Down Expand Up @@ -689,6 +718,13 @@ export const workspaceMachine = createMachine(
throw Error("Cannot get template without workspace")
}
},
getTemplateVersion: async (context) => {
if (context.template) {
return await API.getTemplateVersion(context.template.active_version_id)
} else {
throw Error("Cannot get template version without template")
}
},
updateWorkspace:
({ workspace }, { buildParameters }) =>
async (send) => {
Expand Down