Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: Syntax highlighting with long lines and untar content with emojis#5098

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
BrunoQuaresma merged 3 commits intomainfrombq/fix-syntax-highlight
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
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
2 changes: 1 addition & 1 deletionsite/js-untar.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
declare module "js-untar" {
interface File {
name: string
readAsString: () => string
blob: Blob
}

const Untar: (buffer: ArrayBuffer) => {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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,
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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 () => {
Expand All@@ -38,10 +36,9 @@ const setup = async () => {
describe("TemplateVersionPage", () => {
beforeEach(setup)

it("showsthe tf and mdfiles only", () => {
it("shows files", () => {
expect(screen.queryByText(TERRAFORM_FILENAME)).toBeInTheDocument()
expect(screen.queryByText(README_FILENAME)).toBeInTheDocument()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why did we end up changing this test?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Because now, the filtering happens inside of the "parsing" function. I made it to not have to parse 100 files to only get 2 of them after.

expect(screen.queryByText(GPG_FILENAME)).not.toBeInTheDocument()
})

it("shows the right content when click on the file name", async () => {
Expand Down
27 changes: 14 additions & 13 deletionssite/src/util/templateVersion.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,26 +9,27 @@ export type TemplateVersionFiles = Record<string, string>

export const getTemplateVersionFiles = async (
version: TemplateVersion,
allowedExtensions: string[],
): Promise<TemplateVersionFiles> => {
const files: TemplateVersionFiles = {}
const tarFile = await getFile(version.job.file_id)
const blobs: Record<string, Blob> = {}

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
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
import { getTemplateVersionByName } from "api/api"
import { TemplateVersion } from "api/typesGenerated"
import {
filterTemplateFilesByExtension,
getTemplateVersionFiles,
TemplateVersionFiles,
} from "util/templateVersion"
Expand DownExpand Up@@ -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"])
},
},
},
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp