-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lookout UI: dark mode and visual improvements (#4107)
Add dark mode to the Lookout UI and make other visual improvements: - add syntax highlighting and correct the consistency for displaying code blocks in various languages - make job sets table more responsive and use MUI table component for better styling consistency - remove the use of react-virtualized, which is no longer well-maintained (last published two years ago). I don't think a virtualised table is necessary here given the volume of rows we're likely to display - all the job sets in a queue.
- Loading branch information
1 parent
6b15e67
commit a57e7f2
Showing
36 changed files
with
641 additions
and
1,344 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,148 @@ | ||
import { useCallback } from "react" | ||
|
||
import { Download } from "@mui/icons-material" | ||
import { IconButton, styled, useColorScheme } from "@mui/material" | ||
import { Highlight, themes } from "prism-react-renderer" | ||
import Prism from "prismjs" | ||
import "prismjs/components/prism-bash" | ||
import "prismjs/components/prism-yaml" | ||
|
||
import { CopyIconButton } from "./CopyIconButton" | ||
|
||
// All langauges in this set must be imported from Prism in the form: | ||
// import "prismjs/components/prism-{language}" | ||
type SupportedLanguage = "bash" | "yaml" | ||
|
||
const DARK_PRISM_THEME = themes.oneDark | ||
const LIGHT_PRISM_THEME = themes.oneLight | ||
|
||
const CodeActionsContainer = styled("div")({ | ||
display: "flex", | ||
position: "absolute", | ||
top: 10, | ||
right: 10, | ||
opacity: 0, | ||
transition: "opacity 300ms ease-in-out", | ||
}) | ||
|
||
const CodeBlockContainer = styled("div")({ | ||
position: "relative", | ||
|
||
"&:hover > .codeActionsContainer": { | ||
opacity: 1, | ||
}, | ||
}) | ||
|
||
const StyledPre = styled("pre")(({ theme }) => ({ | ||
lineHeight: 1.2, | ||
fontSize: theme.typography.body2.fontSize, | ||
overflow: "auto", | ||
padding: 5, | ||
borderRadius: 5, | ||
minHeight: 50, | ||
display: "flex", | ||
alignItems: "center", | ||
})) | ||
|
||
const Code = styled("code")({ | ||
display: "table", | ||
wordWrap: "break-word", | ||
}) | ||
|
||
const CodeLine = styled("div")({ | ||
display: "table-row", | ||
counterIncrement: "line-count", | ||
}) | ||
|
||
const CodeLineNumber = styled("span")({ | ||
display: "table-cell", | ||
textAlign: "right", | ||
width: "1%", | ||
position: "sticky", | ||
left: 0, | ||
padding: "0 12px", | ||
overflowWrap: "normal", | ||
|
||
"&::before": { | ||
content: "counter(line-count)", | ||
opacity: 0.4, | ||
}, | ||
}) | ||
|
||
export type CodeBlockProps = { | ||
language: SupportedLanguage | "text" | ||
code: string | ||
showLineNumbers: boolean | ||
} & ( | ||
| { | ||
downloadable: true | ||
downloadBlobType: string | ||
downloadFileName: string | ||
} | ||
| { downloadable: false; downloadBlobType?: undefined | string; downloadFileName?: undefined | string } | ||
) | ||
|
||
export const CodeBlock = ({ | ||
language, | ||
code, | ||
showLineNumbers, | ||
downloadable, | ||
downloadBlobType, | ||
downloadFileName, | ||
}: CodeBlockProps) => { | ||
const { colorScheme } = useColorScheme() | ||
|
||
const downloadFile = useCallback(() => { | ||
if (!downloadable) { | ||
return | ||
} | ||
|
||
const element = document.createElement("a") | ||
const file = new Blob([code], { | ||
type: downloadBlobType, | ||
}) | ||
element.href = URL.createObjectURL(file) | ||
element.download = downloadFileName | ||
document.body.appendChild(element) | ||
element.click() | ||
}, [code, downloadable, downloadBlobType, downloadFileName]) | ||
|
||
return ( | ||
<CodeBlockContainer> | ||
<CodeActionsContainer className="codeActionsContainer"> | ||
<CopyIconButton size="small" content={code} /> | ||
{downloadable && ( | ||
<IconButton size="small" title={`Download as ${language} file`} onClick={downloadFile}> | ||
<Download /> | ||
</IconButton> | ||
)} | ||
</CodeActionsContainer> | ||
<Highlight | ||
prism={Prism} | ||
theme={colorScheme === "dark" ? DARK_PRISM_THEME : LIGHT_PRISM_THEME} | ||
language={language} | ||
code={code} | ||
> | ||
{({ style, tokens, getLineProps, getTokenProps }) => ( | ||
<StyledPre style={style}> | ||
<Code> | ||
{tokens.map((line, i) => { | ||
const lineTokens = line.map((token, key) => <span key={key} {...getTokenProps({ token })} />) | ||
return showLineNumbers ? ( | ||
<CodeLine key={i} {...getLineProps({ line })}> | ||
<CodeLineNumber /> | ||
<span>{lineTokens}</span> | ||
</CodeLine> | ||
) : ( | ||
<div key={i} {...getLineProps({ line })}> | ||
{lineTokens} | ||
</div> | ||
) | ||
})} | ||
</Code> | ||
</StyledPre> | ||
)} | ||
</Highlight> | ||
</CodeBlockContainer> | ||
) | ||
} |
This file contains 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
Oops, something went wrong.