Skip to content

feat(site): Ask for version name and if it is active when publishing a new version on editor #6756

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 8 commits into from
Mar 27, 2023
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
Prev Previous commit
Next Next commit
Fix patch
  • Loading branch information
BrunoQuaresma committed Mar 23, 2023
commit 351340449c6e2497cb58dc1e8ad35d68196cf458
11 changes: 11 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,17 @@ export const updateActiveTemplateVersion = async (
return response.data
}

export const patchTemplateVersion = async (
templateVersionId: string,
data: TypesGen.PatchTemplateVersionRequest,
) => {
const response = await axios.patch<Types.Message>(
`/api/v2/templateversions/${templateVersionId}`,
data,
)
return response.data
}

export const updateTemplateMeta = async (
templateId: string,
data: TypesGen.UpdateTemplateMeta,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const PublishTemplateVersionDialog: FC<
isActiveVersion: false,
},
validationSchema: Yup.object({
name: nameValidator("name"),
name: nameValidator("name").optional(),
isActiveVersion: Yup.boolean(),
}),
onSubmit: onConfirm,
Expand Down Expand Up @@ -62,6 +62,7 @@ export const PublishTemplateVersionDialog: FC<
InputLabelProps={{
shrink: true,
}}
helperText="If you leave this blank, the version name will be automatically generated."
/>

<FormControlLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,28 +332,23 @@ export const templateVersionEditorMachine = createMachine(
}
},
publishingVersion: async (
{ orgId, templateId, uploadResponse },
{ version, templateId },
{ name, isActiveVersion },
) => {
if (!templateId) {
throw new Error("template must be set")
}
if (!uploadResponse) {
throw new Error("upload response must be set")
if (!version) {
throw new Error("Version is not set")
}
const newestVersion = await API.createTemplateVersion(orgId, {
name,
provisioner: "terraform",
storage_method: "file",
tags: {},
template_id: templateId,
file_id: uploadResponse.hash,
})
if (isActiveVersion) {
await API.updateActiveTemplateVersion(templateId, {
id: newestVersion.id,
})
if (!templateId) {
throw new Error("Template is not set")
}
await Promise.all([
API.patchTemplateVersion(version.id, { name: name ?? version.name }),
isActiveVersion
? API.updateActiveTemplateVersion(templateId, {
id: version.id,
})
: Promise.resolve(),
])
},
},
},
Expand Down