From 5106b815fcfa2ed275a18b73e6faa9550b7fdbe2 Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Tue, 15 Nov 2022 18:36:25 +0000 Subject: [PATCH 1/3] Fix code overflow --- site/src/components/SyntaxHighlighter/SyntaxHighlighter.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/site/src/components/SyntaxHighlighter/SyntaxHighlighter.tsx b/site/src/components/SyntaxHighlighter/SyntaxHighlighter.tsx index dae37d0b7104a..88d494b17c799 100644 --- a/site/src/components/SyntaxHighlighter/SyntaxHighlighter.tsx +++ b/site/src/components/SyntaxHighlighter/SyntaxHighlighter.tsx @@ -30,6 +30,9 @@ const useStyles = makeStyles((theme) => ({ background: theme.palette.background.paperLight, borderRadius: theme.shape.borderRadius, padding: theme.spacing(2, 3), + // Line breaks are broken when used with line numbers on react-syntax-highlighter + // https://github.com/react-syntax-highlighter/react-syntax-highlighter/pull/483 + overflowX: "auto", "& code": { color: theme.palette.text.secondary, From 96aee3fc86c46510138fe1942946a7f6d3322b53 Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Tue, 15 Nov 2022 19:26:20 +0000 Subject: [PATCH 2/3] Fix emoji support --- site/js-untar.d.ts | 2 +- site/src/util/templateVersion.ts | 27 ++++++++++--------- .../templateVersionXService.ts | 6 +---- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/site/js-untar.d.ts b/site/js-untar.d.ts index 58268644ff3bc..e28cb0a65c058 100644 --- a/site/js-untar.d.ts +++ b/site/js-untar.d.ts @@ -1,7 +1,7 @@ declare module "js-untar" { interface File { name: string - readAsString: () => string + blob: Blob } const Untar: (buffer: ArrayBuffer) => { diff --git a/site/src/util/templateVersion.ts b/site/src/util/templateVersion.ts index 71bccceb1295a..58fc1853548b0 100644 --- a/site/src/util/templateVersion.ts +++ b/site/src/util/templateVersion.ts @@ -9,26 +9,27 @@ export type TemplateVersionFiles = Record export const getTemplateVersionFiles = async ( version: TemplateVersion, + allowedExtensions: string[], ): Promise => { const files: TemplateVersionFiles = {} const tarFile = await getFile(version.job.file_id) + const blobs: Record = {} + await untar(tarFile).then(undefined, undefined, async (file) => { const paths = file.name.split("/") const filename = paths[paths.length - 1] - files[filename] = file.readAsString() + const [_, extension] = filename.split(".") + + if (allowedExtensions.includes(extension)) { + blobs[filename] = file.blob + } }) - return files -} -export const filterTemplateFilesByExtension = ( - files: TemplateVersionFiles, - extensions: string[], -): TemplateVersionFiles => { - return Object.keys(files).reduce((filteredFiles, filename) => { - const [_, extension] = filename.split(".") + await Promise.all( + Object.entries(blobs).map(async ([filename, blob]) => { + files[filename] = await blob.text() + }), + ) - return extensions.includes(extension) - ? { ...filteredFiles, [filename]: files[filename] } - : filteredFiles - }, {} as TemplateVersionFiles) + return files } diff --git a/site/src/xServices/templateVersion/templateVersionXService.ts b/site/src/xServices/templateVersion/templateVersionXService.ts index 852191d12896a..7b99fcd19159e 100644 --- a/site/src/xServices/templateVersion/templateVersionXService.ts +++ b/site/src/xServices/templateVersion/templateVersionXService.ts @@ -1,7 +1,6 @@ import { getTemplateVersionByName } from "api/api" import { TemplateVersion } from "api/typesGenerated" import { - filterTemplateFilesByExtension, getTemplateVersionFiles, TemplateVersionFiles, } from "util/templateVersion" @@ -86,10 +85,7 @@ export const templateVersionMachine = createMachine( if (!version) { throw new Error("Version is not defined") } - return filterTemplateFilesByExtension( - await getTemplateVersionFiles(version), - ["tf", "md"], - ) + return getTemplateVersionFiles(version, ["tf", "md"]) }, }, }, From ab772a4076944b59225137fc44eb76baae06c110 Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Tue, 15 Nov 2022 19:53:35 +0000 Subject: [PATCH 3/3] Fix test --- .../pages/TemplateVersionPage/TemplateVersionPage.test.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/site/src/pages/TemplateVersionPage/TemplateVersionPage.test.tsx b/site/src/pages/TemplateVersionPage/TemplateVersionPage.test.tsx index 44a494362e140..fe5a8dae7b46a 100644 --- a/site/src/pages/TemplateVersionPage/TemplateVersionPage.test.tsx +++ b/site/src/pages/TemplateVersionPage/TemplateVersionPage.test.tsx @@ -12,11 +12,9 @@ const TEMPLATE_NAME = "coder-ts" const VERSION_NAME = "12345" const TERRAFORM_FILENAME = "main.tf" const README_FILENAME = "readme.md" -const GPG_FILENAME = "key.gpg" const TEMPLATE_VERSION_FILES = { [TERRAFORM_FILENAME]: "{}", [README_FILENAME]: "Readme", - [GPG_FILENAME]: "Some sensitive info", } const setup = async () => { @@ -38,10 +36,9 @@ const setup = async () => { describe("TemplateVersionPage", () => { beforeEach(setup) - it("shows the tf and md files only", () => { + it("shows files", () => { expect(screen.queryByText(TERRAFORM_FILENAME)).toBeInTheDocument() expect(screen.queryByText(README_FILENAME)).toBeInTheDocument() - expect(screen.queryByText(GPG_FILENAME)).not.toBeInTheDocument() }) it("shows the right content when click on the file name", async () => {