-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[Dashboard] Upgrade to MUIv5 and dependency updates #45789
Changes from 6 commits
1edf57c
7c809cb
1302e60
225af33
575f8cb
28fbb63
40e85c7
bf5e4b1
94a28b4
ebb9248
71cf33b
c878dcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,23 +1,26 @@ | ||||||
import { Card, Link, Typography } from "@mui/material"; | ||||||
import createStyles from "@mui/styles/createStyles"; | ||||||
import makeStyles from "@mui/styles/makeStyles"; | ||||||
import classNames from "classnames"; | ||||||
import { | ||||||
Box, | ||||||
Card, | ||||||
Link, | ||||||
SxProps, | ||||||
Theme, | ||||||
Typography, | ||||||
useTheme, | ||||||
} from "@mui/material"; | ||||||
import yaml from "js-yaml"; | ||||||
import React, { useState } from "react"; | ||||||
import DialogWithTitle from "../DialogWithTitle"; | ||||||
import { ClassNameProps } from "../props"; | ||||||
|
||||||
const useStyles = makeStyles((theme) => | ||||||
createStyles({ | ||||||
configText: { | ||||||
whiteSpace: "pre", | ||||||
fontFamily: "SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace", | ||||||
padding: theme.spacing(2), | ||||||
overflow: "scroll", | ||||||
maxHeight: 600, | ||||||
}, | ||||||
}), | ||||||
); | ||||||
const useStyles = (theme: Theme) => ({ | ||||||
configText: { | ||||||
whiteSpace: "pre", | ||||||
fontFamily: "SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace", | ||||||
padding: theme.spacing(2), | ||||||
overflow: "scroll", | ||||||
maxHeight: 600, | ||||||
}, | ||||||
}); | ||||||
|
||||||
export type CodeDialogButtonProps = { | ||||||
/** | ||||||
|
@@ -32,6 +35,7 @@ export type CodeDialogButtonProps = { | |||||
* Code to show in the dialog. If an object is passed in, that object will be stringified to yaml. | ||||||
*/ | ||||||
code: string | object; | ||||||
sx?: SxProps<Theme>; | ||||||
}; | ||||||
|
||||||
/** | ||||||
|
@@ -42,7 +46,7 @@ export const CodeDialogButton = ({ | |||||
buttonText = "View", | ||||||
code, | ||||||
}: CodeDialogButtonProps) => { | ||||||
const classes = useStyles(); | ||||||
const styles = useStyles(useTheme()); | ||||||
|
||||||
const [showConfigDialog, setShowConfigDialog] = useState(false); | ||||||
|
||||||
|
@@ -63,7 +67,7 @@ export const CodeDialogButton = ({ | |||||
}} | ||||||
> | ||||||
<Card variant="outlined"> | ||||||
<Typography className={classes.configText}> | ||||||
<Typography sx={styles.configText}> | ||||||
{typeof code === "string" ? code : yaml.dump(code, { indent: 2 })} | ||||||
</Typography> | ||||||
</Card> | ||||||
|
@@ -73,23 +77,21 @@ export const CodeDialogButton = ({ | |||||
); | ||||||
}; | ||||||
|
||||||
const useCodeDialogButtonWithPreviewStyles = makeStyles((theme) => | ||||||
createStyles({ | ||||||
root: { | ||||||
display: "flex", | ||||||
flexWrap: "nowrap", | ||||||
flexDirection: "row", | ||||||
gap: theme.spacing(1), | ||||||
}, | ||||||
previewText: { | ||||||
display: "block", | ||||||
whiteSpace: "nowrap", | ||||||
overflow: "hidden", | ||||||
textOverflow: "ellipsis", | ||||||
flex: 1, | ||||||
}, | ||||||
}), | ||||||
); | ||||||
const useCodeDialogButtonWithPreviewStyles = (theme: Theme) => ({ | ||||||
root: { | ||||||
display: "flex", | ||||||
flexWrap: "nowrap", | ||||||
flexDirection: "row", | ||||||
gap: theme.spacing(1), | ||||||
}, | ||||||
previewText: { | ||||||
display: "block", | ||||||
whiteSpace: "nowrap", | ||||||
overflow: "hidden", | ||||||
textOverflow: "ellipsis", | ||||||
flex: 1, | ||||||
}, | ||||||
}); | ||||||
|
||||||
type CodeDialogButtonWithPreviewProps = CodeDialogButtonProps & ClassNameProps; | ||||||
/** | ||||||
|
@@ -99,9 +101,10 @@ export const CodeDialogButtonWithPreview = ({ | |||||
code, | ||||||
buttonText, | ||||||
className, | ||||||
sx, | ||||||
...props | ||||||
}: CodeDialogButtonWithPreviewProps) => { | ||||||
const classes = useCodeDialogButtonWithPreviewStyles(); | ||||||
const styles = useCodeDialogButtonWithPreviewStyles(useTheme()); | ||||||
|
||||||
const codeText = | ||||||
typeof code === "string" | ||||||
|
@@ -111,13 +114,15 @@ export const CodeDialogButtonWithPreview = ({ | |||||
const buttonTextToPass = buttonText ?? "Expand"; | ||||||
|
||||||
return ( | ||||||
<div className={classNames(classes.root, className)}> | ||||||
<span className={classes.previewText}>{codeText}</span> | ||||||
<Box className={className} sx={Object.assign({}, styles.root, sx)}> | ||||||
<Box component="span" sx={styles.previewText}> | ||||||
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.
Suggested change
Please use array syntax instead 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! Made a minor adjustment to |
||||||
{codeText} | ||||||
</Box> | ||||||
<CodeDialogButton | ||||||
code={codeText} | ||||||
buttonText={buttonTextToPass} | ||||||
{...props} | ||||||
/> | ||||||
</div> | ||||||
</Box> | ||||||
); | ||||||
}; |
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.
There shouldn't be a need to create an object like this.
When using sx props, you can also easily get access to the theme by passing a function into sx.
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.
In most cases, I would prefer if we inlined styles instead of creating a separate styles object, but this is not a blocker.
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.
Understood, I've removed the redundant object and directly passed the function instead. Additionally, converted some parts to use inlined styles, while leaving the rest as is for readability considerations.