-
Notifications
You must be signed in to change notification settings - Fork 905
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
Changes from all commits
7bf286f
fc414bc
b0a0ec0
43e256d
294bab5
8503418
1c05356
7585ab1
c716995
e1bcc93
ed9559f
1db00e3
f86e024
f37dabe
5c141ba
1ca4d0a
9f6dbef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,6 +231,34 @@ export const getTemplateVersionByName = async ( | |
return response.data | ||
} | ||
|
||
export type GetPreviousTemplateVersionByNameResponse = | ||
| TypesGen.TemplateVersion | ||
| undefined | ||
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.
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. Great! |
||
|
||
export const getPreviousTemplateVersionByName = async ( | ||
organizationId: string, | ||
versionName: string, | ||
): Promise<GetPreviousTemplateVersionByNameResponse> => { | ||
try { | ||
const response = await axios.get<TypesGen.TemplateVersion>( | ||
`/api/v2/organizations/${organizationId}/templateversions/${versionName}/previous`, | ||
) | ||
return response.data | ||
} catch (error) { | ||
// When there is no previous version, like the first version of a template, | ||
// the API returns 404 so in this case we can safely return undefined | ||
if ( | ||
axios.isAxiosError(error) && | ||
error.response && | ||
error.response.status === 404 | ||
) { | ||
return undefined | ||
} | ||
|
||
throw error | ||
} | ||
} | ||
|
||
export const updateTemplateMeta = async ( | ||
templateId: string, | ||
data: TypesGen.UpdateTemplateMeta, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import SvgIcon, { SvgIconProps } from "@material-ui/core/SvgIcon" | ||
|
||
export const DockerIcon = (props: SvgIconProps): JSX.Element => ( | ||
<SvgIcon {...props} viewBox="0 0 32 32"> | ||
<path | ||
d="M16.54,12.663H19.4v2.924h1.446a6.272,6.272,0,0,0,1.988-.333,5.091,5.091,0,0,0,.966-.436,3.584,3.584,0,0,1-.67-1.849,3.907,3.907,0,0,1,.7-2.753l.3-.348.358.288a4.558,4.558,0,0,1,1.795,2.892,4.375,4.375,0,0,1,3.319.309l.393.226-.207.4a4.141,4.141,0,0,1-4.157,1.983c-2.48,6.168-7.871,9.088-14.409,9.088-3.378,0-6.476-1.263-8.241-4.259l-.029-.049L2.7,20.227a8.316,8.316,0,0,1-.659-4.208l.04-.433H4.526V12.663H7.387V9.8h5.721V6.942H16.54v5.721Z" | ||
style={{ fill: "#0096e6" }} | ||
/> | ||
<path | ||
d="M12.006,24.567a6.022,6.022,0,0,1-3.14-3.089,10.329,10.329,0,0,1-2.264.343q-.5.028-1.045.028-.632,0-1.331-.037a9.051,9.051,0,0,0,7,2.769Q11.618,24.581,12.006,24.567Z" | ||
style={{ fill: "#fff" }} | ||
/> | ||
<path | ||
d="M7.08,13.346h.2v2.067h-.2Zm-.376,0h.2v2.067H6.7V13.346Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.368,0h.2v2.067h-.2V13.346ZM5,13.14H7.482v2.479H5Zm2.859-2.861h2.48v2.479H7.863Zm2.077.207h.2v2.066h-.2Zm-.376,0h.2v2.066h-.2Zm-.376,0h.2v2.066h-.2V10.486Zm-.376,0h.2v2.066h-.2Zm-.376,0h.2v2.066h-.2Zm-.368,0h.2v2.066h-.2Zm-.207,2.653h2.48v2.48H7.863V13.14Zm2.077.207h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2V13.346Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.368,0h.2v2.067h-.2Zm2.654-.207H13.2v2.48h-2.48V13.14Zm2.076.207H13v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.368,0h.2v2.067h-.2Zm-.206-3.067H13.2v2.479h-2.48V10.279Zm2.076.207H13v2.066h-.2Zm-.376,0h.2v2.066h-.2Zm-.376,0h.2v2.066h-.2Zm-.376,0h.2v2.066h-.2Zm-.376,0h.2v2.066h-.2Zm-.368,0h.2v2.066h-.2Zm2.654,2.653h2.479v2.48h-2.48V13.14Zm2.076.207h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.368,0h.192v2.067h-.2V13.346Zm-.206-3.067h2.479v2.479h-2.48V10.279Zm2.076.207h.2v2.066h-.2Zm-.376,0h.2v2.066h-.2Zm-.376,0h.2v2.066h-.2Zm-.376,0h.2v2.066h-.2Zm-.376,0h.2v2.066h-.2Zm-.368,0h.192v2.066h-.2V10.486Zm-.206-3.067h2.479V9.9h-2.48V7.419Zm2.076.206h.2V9.691h-.2Zm-.376,0h.2V9.691h-.2Zm-.376,0h.2V9.691h-.2Zm-.376,0h.2V9.691h-.2Zm-.376,0h.2V9.691h-.2Zm-.368,0h.192V9.691h-.2V7.625Zm2.654,5.514h2.479v2.48h-2.48V13.14Zm2.076.207h.195v2.067h-.2V13.346Zm-.376,0h.206v2.067h-.206Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.2Zm-.376,0h.2v2.067h-.205V13.346Zm-.368,0h.2v2.067h-.194V13.346Z" | ||
style={{ fill: "#fff" }} | ||
/> | ||
<path | ||
d="M10.188,19.638a.684.684,0,1,1-.684.684A.684.684,0,0,1,10.188,19.638Zm0,.194a.489.489,0,0,1,.177.033.2.2,0,1,0,.275.269.49.49,0,1,1-.453-.3Z" | ||
style={{ fill: "#fff" }} | ||
/> | ||
</SvgIcon> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,47 @@ | ||
import { FC } from "react" | ||
import Editor, { DiffEditor } from "@monaco-editor/react" | ||
import { useCoderTheme } from "./coderTheme" | ||
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 | ||
}) => { | ||
export const SyntaxHighlighter: FC<{ | ||
value: string | ||
language: string | ||
compareWith?: string | ||
}> = ({ value, compareWith, language }) => { | ||
const styles = useStyles() | ||
const hasDiff = compareWith && value !== compareWith | ||
const coderTheme = useCoderTheme() | ||
const commonProps = { | ||
language, | ||
theme: coderTheme.name, | ||
height: 560, | ||
options: { | ||
minimap: { | ||
enabled: false, | ||
}, | ||
renderSideBySide: true, | ||
readOnly: true, | ||
}, | ||
} | ||
|
||
if (coderTheme.isLoading) { | ||
return null | ||
} | ||
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. Do we need a loading state? 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. Not really, it is VERY fast. It is only a few milliseconds to |
||
|
||
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} | ||
/> | ||
<div className={styles.wrapper}> | ||
{hasDiff ? ( | ||
<DiffEditor original={compareWith} modified={value} {...commonProps} /> | ||
) : ( | ||
<Editor value={value} {...commonProps} /> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
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, | ||
}, | ||
|
||
"& .key, & .property, & .code-snippet, & .keyword": { | ||
color: colors.turquoise[7], | ||
}, | ||
|
||
"& .url": { | ||
color: colors.blue[6], | ||
}, | ||
|
||
"& .comment": { | ||
color: theme.palette.text.disabled, | ||
}, | ||
|
||
"& .title": { | ||
color: theme.palette.text.primary, | ||
fontWeight: 600, | ||
}, | ||
wrapper: { | ||
padding: theme.spacing(1, 0), | ||
background: theme.palette.background.paper, | ||
}, | ||
})) |
Uh oh!
There was an error while loading. Please reload this page.