Skip to content

feat(site): Duplicate template #6853

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 11 commits into from
Mar 30, 2023
Prev Previous commit
Next Next commit
Fix copy from file template
  • Loading branch information
BrunoQuaresma committed Mar 29, 2023
commit 7cd4101ecea2ae32c3f454df7df14be5e7b1d8c9
16 changes: 9 additions & 7 deletions site/src/components/TemplateLayout/TemplatePageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ const TemplateMenu: FC<{
>
{Language.settingsButton}
</MenuItem>
<MenuItem
onClick={handleClose}
component={RouterLink}
to={`/templates/new?copyTemplate=${templateName}`}
>
{Language.duplicateButton}
</MenuItem>
{canEditFiles && (
<MenuItem
onClick={handleClose}
component={RouterLink}
to={`/templates/new?copyTemplate=${templateName}`}
>
{Language.duplicateButton}
</MenuItem>
)}
{canEditFiles && (
<MenuItem
component={RouterLink}
Expand Down
4 changes: 3 additions & 1 deletion site/src/pages/CreateTemplatePage/CreateTemplateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ const getInitialValues = ({
...initialValues,
...fromCopy,
name: `${fromCopy.name}-copy`,
display_name: `${fromCopy.display_name} Copy`,
display_name: fromCopy.display_name
? `${fromCopy.display_name} Copy`
: "",
}
}

Expand Down
15 changes: 15 additions & 0 deletions site/src/xServices/createTemplate/createTemplateXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,10 @@ export const createTemplateMachine =
},
createFirstVersion: async ({
organizationId,
templateNameToCopy,
exampleId,
uploadResponse,
version,
}) => {
if (exampleId) {
return createTemplateVersion(organizationId, {
Expand All @@ -388,6 +390,19 @@ export const createTemplateMachine =
})
}

if (templateNameToCopy) {
if (!version) {
throw new Error("Not able to copy without having a version")
}

return createTemplateVersion(organizationId, {
storage_method: "file",
file_id: version.job.file_id,
provisioner: "terraform",
tags: {},
})
}

if (uploadResponse) {
return createTemplateVersion(organizationId, {
storage_method: "file",
Expand Down