Skip to content

Commit 9653fc7

Browse files
committed
Save version on URL even when building
1 parent 1785b90 commit 9653fc7

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
templateVersionVariables,
2424
} from "api/queries/templates";
2525
import { file, uploadFile } from "api/queries/files";
26-
import { TarFileTypeCodes, TarReader, TarWriter } from "utils/tar";
26+
import { TarReader, TarWriter } from "utils/tar";
2727
import { FileTree, traverse } from "utils/filetree";
2828
import { createTemplateVersionFileTree } from "utils/templateVersion";
2929
import { displayError } from "components/GlobalSnackbar/utils";
@@ -78,6 +78,13 @@ export const TemplateVersionEditorPage: FC = () => {
7878
const [lastSuccessfulPublishedVersion, setLastSuccessfulPublishedVersion] =
7979
useState<TemplateVersion>();
8080

81+
const navigateToVersion = (version: TemplateVersion) => {
82+
return navigate(
83+
`/templates/${templateName}/versions/${version.name}/edit`,
84+
{ replace: true },
85+
);
86+
};
87+
8188
// Optimistically update the template version data job status to make the
8289
// build action feels faster
8390
const onBuildStart = () => {
@@ -97,6 +104,7 @@ export const TemplateVersionEditorPage: FC = () => {
97104
const onBuildEnds = (newVersion: TemplateVersion) => {
98105
setCurrentVersionName(newVersion.name);
99106
queryClient.setQueryData(templateVersionOptions.queryKey, newVersion);
107+
navigateToVersion(newVersion);
100108
};
101109

102110
// Provisioner Tags
@@ -163,10 +171,7 @@ export const TemplateVersionEditorPage: FC = () => {
163171
templateVersionOptions.queryKey,
164172
publishedVersion,
165173
);
166-
navigate(
167-
`/templates/${templateName}/versions/${publishedVersion.name}/edit`,
168-
{ replace: true },
169-
);
174+
navigateToVersion(publishedVersion);
170175
}}
171176
isAskingPublishParameters={isPublishingDialogOpen}
172177
isPublishing={publishVersionMutation.isLoading}
@@ -328,37 +333,20 @@ const generateVersionFiles = async (
328333
) => {
329334
const tar = new TarWriter();
330335

331-
// Add previous non editable files
332-
for (const file of tarReader.fileInfo) {
333-
if (file.type === TarFileTypeCodes.Dir) {
334-
tar.addFolder(file.name, {
335-
mode: file.mode, // https://github.com/beatgammit/tar-js/blob/master/lib/tar.js#L42
336-
mtime: file.mtime,
337-
user: file.user,
338-
group: file.group,
339-
});
340-
} else {
341-
tar.addFile(file.name, tarReader.getTextFile(file.name) as string, {
342-
mode: file.mode, // https://github.com/beatgammit/tar-js/blob/master/lib/tar.js#L42
343-
mtime: file.mtime,
344-
user: file.user,
345-
group: file.group,
346-
});
347-
}
348-
}
349-
// Add the editable files
350336
traverse(fileTree, (content, _filename, fullPath) => {
351337
// When a file is deleted. Don't add it to the tar.
352338
if (content === undefined) {
353339
return;
354340
}
355341

342+
const baseFileInfo = tarReader.fileInfo.find((i) => i.name === fullPath);
343+
356344
if (typeof content === "string") {
357-
tar.addFile(fullPath, content);
345+
tar.addFile(fullPath, content, baseFileInfo);
358346
return;
359347
}
360348

361-
tar.addFolder(fullPath);
349+
tar.addFolder(fullPath, baseFileInfo);
362350
});
363351
const blob = (await tar.write()) as Blob;
364352
return new File([blob], "template.tar");

0 commit comments

Comments
 (0)