-
Notifications
You must be signed in to change notification settings - Fork 980
feat: Add diff and Dockerfile support for template version page #5339
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
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7bf286f
Load diff files
BrunoQuaresma fc414bc
Show diff files with monaco
BrunoQuaresma b0a0ec0
Update wrapper
BrunoQuaresma 43e256d
Add reference
BrunoQuaresma 294bab5
Add Docker icon
BrunoQuaresma 8503418
Show diff badge
BrunoQuaresma 1c05356
Do safe request
BrunoQuaresma 7585ab1
Improve extension language
BrunoQuaresma c716995
Merge branch 'main' of github.com:coder/coder into bq/add-diff
BrunoQuaresma e1bcc93
Add a few fixes
BrunoQuaresma ed9559f
Add more tests for t previous query
BrunoQuaresma 1db00e3
Update deps
BrunoQuaresma f86e024
Remove test
BrunoQuaresma f37dabe
Remove unecessary import
BrunoQuaresma 5c141ba
Fix databse fake
BrunoQuaresma 1ca4d0a
Update coderd/database/queries/templateversions.sql
BrunoQuaresma 9f6dbef
Apply PR suggestions
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Show diff files with monaco
- Loading branch information
commit fc414bc0840df01d337f05ff48ca299b969a4a4e
There are no files selected for viewing
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
86 changes: 32 additions & 54 deletions
86
site/src/components/SyntaxHighlighter/SyntaxHighlighter.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,36 @@ | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import { ComponentProps, FC } from "react" | ||
import { Prism } from "react-syntax-highlighter" | ||
import { colors } from "theme/colors" | ||
import darcula from "react-syntax-highlighter/dist/cjs/styles/prism/darcula" | ||
import { combineClasses } from "util/combineClasses" | ||
|
||
export const SyntaxHighlighter: FC<ComponentProps<typeof Prism>> = ({ | ||
className, | ||
...props | ||
}) => { | ||
const styles = useStyles() | ||
|
||
return ( | ||
<Prism | ||
style={darcula} | ||
useInlineStyles={false} | ||
// Use inline styles does not work correctly | ||
// https://github.com/react-syntax-highlighter/react-syntax-highlighter/issues/329 | ||
codeTagProps={{ style: {} }} | ||
className={combineClasses([styles.prism, className])} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
prism: { | ||
margin: 0, | ||
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, | ||
import { FC } from "react" | ||
import Editor, { DiffEditor } from "@monaco-editor/react" | ||
import { useCoderTheme } from "./coderTheme" | ||
|
||
export const SyntaxHighlighter: FC<{ | ||
value: string | ||
language: string | ||
compareWith?: string | ||
}> = ({ value, compareWith, language }) => { | ||
const hasDiff = compareWith && value !== compareWith | ||
const coderTheme = useCoderTheme() | ||
const commonProps = { | ||
language, | ||
theme: coderTheme.name, | ||
height: 560, | ||
options: { | ||
minimap: { | ||
enabled: false, | ||
}, | ||
renderSideBySide: false, | ||
readOnly: true, | ||
}, | ||
} | ||
|
||
"& .key, & .property, & .code-snippet, & .keyword": { | ||
color: colors.turquoise[7], | ||
}, | ||
if (coderTheme.isLoading) { | ||
return null | ||
} | ||
|
||
"& .url": { | ||
color: colors.blue[6], | ||
}, | ||
|
||
"& .comment": { | ||
color: theme.palette.text.disabled, | ||
}, | ||
if (hasDiff) { | ||
return ( | ||
<DiffEditor original={value} modified={compareWith} {...commonProps} /> | ||
) | ||
} | ||
|
||
"& .title": { | ||
color: theme.palette.text.primary, | ||
fontWeight: 600, | ||
}, | ||
}, | ||
})) | ||
return <Editor value={value} {...commonProps} /> | ||
} |
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,238 @@ | ||
import { Theme, useTheme } from "@material-ui/core/styles" | ||
import { useMonaco } from "@monaco-editor/react" | ||
import { useEffect, useState } from "react" | ||
import { hslToHex } from "util/colors" | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- The theme is not typed | ||
export const coderTheme = (theme: Theme): Record<string, any> => ({ | ||
base: "vs-dark", | ||
inherit: true, | ||
rules: [ | ||
{ | ||
background: "282a36", | ||
token: "", | ||
}, | ||
{ | ||
foreground: "6272a4", | ||
token: "comment", | ||
}, | ||
{ | ||
foreground: "f1fa8c", | ||
token: "string", | ||
}, | ||
{ | ||
foreground: "bd93f9", | ||
token: "constant.numeric", | ||
}, | ||
{ | ||
foreground: "bd93f9", | ||
token: "constant.language", | ||
}, | ||
{ | ||
foreground: "bd93f9", | ||
token: "constant.character", | ||
}, | ||
{ | ||
foreground: "bd93f9", | ||
token: "constant.other", | ||
}, | ||
{ | ||
foreground: "ffb86c", | ||
token: "variable.other.readwrite.instance", | ||
}, | ||
{ | ||
foreground: "ff79c6", | ||
token: "constant.character.escaped", | ||
}, | ||
{ | ||
foreground: "ff79c6", | ||
token: "constant.character.escape", | ||
}, | ||
{ | ||
foreground: "ff79c6", | ||
token: "string source", | ||
}, | ||
{ | ||
foreground: "ff79c6", | ||
token: "string source.ruby", | ||
}, | ||
{ | ||
foreground: "ff79c6", | ||
token: "keyword", | ||
}, | ||
{ | ||
foreground: "ff79c6", | ||
token: "storage", | ||
}, | ||
{ | ||
foreground: "8be9fd", | ||
fontStyle: "italic", | ||
token: "storage.type", | ||
}, | ||
{ | ||
foreground: "50fa7b", | ||
fontStyle: "underline", | ||
token: "entity.name.class", | ||
}, | ||
{ | ||
foreground: "50fa7b", | ||
fontStyle: "italic underline", | ||
token: "entity.other.inherited-class", | ||
}, | ||
{ | ||
foreground: "50fa7b", | ||
token: "entity.name.function", | ||
}, | ||
{ | ||
foreground: "ffb86c", | ||
fontStyle: "italic", | ||
token: "variable.parameter", | ||
}, | ||
{ | ||
foreground: "ff79c6", | ||
token: "entity.name.tag", | ||
}, | ||
{ | ||
foreground: "50fa7b", | ||
token: "entity.other.attribute-name", | ||
}, | ||
{ | ||
foreground: "8be9fd", | ||
token: "support.function", | ||
}, | ||
{ | ||
foreground: "6be5fd", | ||
token: "support.constant", | ||
}, | ||
{ | ||
foreground: "66d9ef", | ||
fontStyle: " italic", | ||
token: "support.type", | ||
}, | ||
{ | ||
foreground: "66d9ef", | ||
fontStyle: " italic", | ||
token: "support.class", | ||
}, | ||
{ | ||
foreground: "f8f8f0", | ||
background: "ff79c6", | ||
token: "invalid", | ||
}, | ||
{ | ||
foreground: "f8f8f0", | ||
background: "bd93f9", | ||
token: "invalid.deprecated", | ||
}, | ||
{ | ||
foreground: "cfcfc2", | ||
token: "meta.structure.dictionary.json string.quoted.double.json", | ||
}, | ||
{ | ||
foreground: "6272a4", | ||
token: "meta.diff", | ||
}, | ||
{ | ||
foreground: "6272a4", | ||
token: "meta.diff.header", | ||
}, | ||
{ | ||
foreground: "ff79c6", | ||
token: "markup.deleted", | ||
}, | ||
{ | ||
foreground: "50fa7b", | ||
token: "markup.inserted", | ||
}, | ||
{ | ||
foreground: "e6db74", | ||
token: "markup.changed", | ||
}, | ||
{ | ||
foreground: "bd93f9", | ||
token: "constant.numeric.line-number.find-in-files - match", | ||
}, | ||
{ | ||
foreground: "e6db74", | ||
token: "entity.name.filename", | ||
}, | ||
{ | ||
foreground: "f83333", | ||
token: "message.error", | ||
}, | ||
{ | ||
foreground: "eeeeee", | ||
token: | ||
"punctuation.definition.string.begin.json - meta.structure.dictionary.value.json", | ||
}, | ||
{ | ||
foreground: "eeeeee", | ||
token: | ||
"punctuation.definition.string.end.json - meta.structure.dictionary.value.json", | ||
}, | ||
{ | ||
foreground: "8be9fd", | ||
token: "meta.structure.dictionary.json string.quoted.double.json", | ||
}, | ||
{ | ||
foreground: "f1fa8c", | ||
token: "meta.structure.dictionary.value.json string.quoted.double.json", | ||
}, | ||
{ | ||
foreground: "50fa7b", | ||
token: | ||
"meta meta meta meta meta meta meta.structure.dictionary.value string", | ||
}, | ||
{ | ||
foreground: "ffb86c", | ||
token: "meta meta meta meta meta meta.structure.dictionary.value string", | ||
}, | ||
{ | ||
foreground: "ff79c6", | ||
token: "meta meta meta meta meta.structure.dictionary.value string", | ||
}, | ||
{ | ||
foreground: "bd93f9", | ||
token: "meta meta meta meta.structure.dictionary.value string", | ||
}, | ||
{ | ||
foreground: "50fa7b", | ||
token: "meta meta meta.structure.dictionary.value string", | ||
}, | ||
{ | ||
foreground: "ffb86c", | ||
token: "meta meta.structure.dictionary.value string", | ||
}, | ||
], | ||
colors: { | ||
"editor.foreground": hslToHex(theme.palette.text.secondary), | ||
"editor.background": hslToHex(theme.palette.background.paper), | ||
"editor.selectionBackground": hslToHex(theme.palette.action.hover), | ||
"editor.lineHighlightBackground": hslToHex( | ||
theme.palette.background.paperLight, | ||
), | ||
"editorCursor.foreground": "#f8f8f0", | ||
"editorWhitespace.foreground": "#3B3A32", | ||
"editorIndentGuide.activeBackground": "#9D550FB0", | ||
"editor.selectionHighlightBorder": "#222218", | ||
}, | ||
}) | ||
|
||
export const useCoderTheme = (): { isLoading: boolean; name: string } => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a comment here explaining what this hook/what its scope is might be helpful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing! |
||
const [isLoading, setIsLoading] = useState(true) | ||
const monaco = useMonaco() | ||
const theme = useTheme<Theme>() | ||
const name = "coder" | ||
|
||
useEffect(() => { | ||
if (monaco) { | ||
monaco.editor.defineTheme(name, coderTheme(theme)) | ||
setIsLoading(false) | ||
} | ||
}, [monaco, theme]) | ||
|
||
return { | ||
isLoading, | ||
name, | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a loading state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, it is VERY fast. It is only a few milliseconds to
monaco
be loaded. From what I was able to inspect there is no networking involved so the "loading time" is "static"