- Notifications
You must be signed in to change notification settings - Fork1.1k
fix(site): Upload template files on template version editor#6222
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
9a7c981 Base upload fix
BrunoQuaresmae785b18 Add tests
BrunoQuaresmae0bc3e9 Add test to verify folder
BrunoQuaresma34f2ea8 Remove save
BrunoQuaresma3e4b5e6 Fix new folders
BrunoQuaresma3b98873 Merge branch 'main' into fix/upload-template-files
BrunoQuaresmaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletionssite/jest.setup.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletionssite/js-untar.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,21 @@ | ||
| declare module"js-untar"{ | ||
BrunoQuaresma marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| exportinterfaceFile{ | ||
| name:string | ||
| mode:string | ||
| blob:Blob | ||
| gid:number | ||
| uid:number | ||
| mtime:number | ||
| gname:string | ||
| uname:string | ||
| type:"0"|"1"|"2"|"3"|"4"|"5"//https://en.wikipedia.org/wiki/Tar_(computing) on Type flag field | ||
| } | ||
| constUntar:(buffer:ArrayBuffer)=>{ | ||
| then:( | ||
| resolve?:(files:File[])=>void, | ||
| reject?:()=>Promise<void>, | ||
| progress?:(file:File)=>Promise<void>, | ||
| )=>Promise<void> | ||
| } | ||
1 change: 0 additions & 1 deletionsite/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
19 changes: 13 additions & 6 deletionssite/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
33 changes: 25 additions & 8 deletionssite/src/pages/TemplateVersionPage/TemplateVersionEditorPage/data.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,49 @@ | ||
| import { useQuery, UseQueryOptions } from "@tanstack/react-query" | ||
| import {getFile,getTemplateByName, getTemplateVersionByName } from "api/api" | ||
| import { createTemplateVersionFileTree } from "util/templateVersion" | ||
| import untar, { File as UntarFile } from "js-untar" | ||
| const getTemplateVersionData = async ( | ||
| orgId: string, | ||
| templateName: string, | ||
| versionName: string, | ||
| ) => { | ||
| const [template,version] = await Promise.all([ | ||
| getTemplateByName(orgId, templateName), | ||
| getTemplateVersionByName(orgId, templateName, versionName), | ||
| ]) | ||
| const tarFile = await getFile(version.job.file_id) | ||
| let untarFiles: UntarFile[] = [] | ||
| await untar(tarFile).then((files) => { | ||
| untarFiles = files | ||
| }) | ||
| const fileTree = await createTemplateVersionFileTree(untarFiles) | ||
| return { | ||
| template, | ||
| version, | ||
| fileTree, | ||
| untarFiles, | ||
| } | ||
| } | ||
| type GetTemplateVersionResponse = Awaited< | ||
| ReturnType<typeof getTemplateVersionData> | ||
| > | ||
| type UseTemplateVersionDataParams = { | ||
| orgId: string | ||
| templateName: string | ||
| versionName: string | ||
| } | ||
| export const useTemplateVersionData = ( | ||
| { templateName, versionName, orgId }: UseTemplateVersionDataParams, | ||
| options?: UseQueryOptions<GetTemplateVersionResponse>, | ||
| ) => { | ||
| return useQuery({ | ||
| queryKey: ["templateVersion", templateName, versionName], | ||
| queryFn: () => getTemplateVersionData(orgId, templateName, versionName), | ||
| ...options, | ||
| }) | ||
| } |
52 changes: 52 additions & 0 deletionssite/src/util/tar.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { TarReader, TarWriter, ITarFileInfo, TarFileType } from "./tar" | ||
| const mtime = 1666666666666 | ||
| test("tar", async () => { | ||
| // Write | ||
| const writer = new TarWriter() | ||
| writer.addFile("a.txt", "hello", { mtime }) | ||
| writer.addFile("b.txt", new Blob(["world"]), { mtime }) | ||
| writer.addFile("c.txt", "", { mtime }) | ||
| writer.addFolder("etc", { mtime }) | ||
| writer.addFile("etc/d.txt", "", { mtime }) | ||
| const blob = await writer.write() | ||
| // Read | ||
| const reader = new TarReader() | ||
| const fileInfos = await reader.readFile(blob) | ||
| verifyFile(fileInfos[0], reader.getTextFile(fileInfos[0].name) as string, { | ||
| name: "a.txt", | ||
| content: "hello", | ||
| }) | ||
| verifyFile(fileInfos[1], reader.getTextFile(fileInfos[1].name) as string, { | ||
| name: "b.txt", | ||
| content: "world", | ||
| }) | ||
| verifyFile(fileInfos[2], reader.getTextFile(fileInfos[2].name) as string, { | ||
| name: "c.txt", | ||
| content: "", | ||
| }) | ||
| verifyFolder(fileInfos[3], { | ||
| name: "etc", | ||
| }) | ||
| verifyFile(fileInfos[4], reader.getTextFile(fileInfos[4].name) as string, { | ||
| name: "etc/d.txt", | ||
| content: "", | ||
| }) | ||
| }) | ||
| function verifyFile( | ||
| info: ITarFileInfo, | ||
| content: string, | ||
| expected: { name: string; content: string }, | ||
| ) { | ||
| expect(info.name).toEqual(expected.name) | ||
| expect(info.size).toEqual(expected.content.length) | ||
| expect(content).toEqual(expected.content) | ||
| } | ||
| function verifyFolder(info: ITarFileInfo, expected: { name: string }) { | ||
| expect(info.name).toEqual(expected.name) | ||
| expect(info.type).toEqual(TarFileType.Dir) | ||
| } |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.