|
| 1 | +import Avatar from "@material-ui/core/Avatar" |
| 2 | +import { makeStyles } from "@material-ui/core/styles" |
| 3 | +import FolderIcon from "@material-ui/icons/FolderOutlined" |
| 4 | +import HelpIcon from "@material-ui/icons/HelpOutlined" |
| 5 | +import ImageIcon from "@material-ui/icons/ImageOutlined" |
| 6 | +import MemoryIcon from "@material-ui/icons/MemoryOutlined" |
| 7 | +import React from "react" |
| 8 | + |
| 9 | +// For this special case, we need to apply a different style because how this |
| 10 | +// particular icon has been designed |
| 11 | +const AdjustedMemoryIcon: typeof MemoryIcon = ({ style, ...props }) => { |
| 12 | + return <MemoryIcon style={{ ...style, fontSize: 24 }} {...props} /> |
| 13 | +} |
| 14 | + |
| 15 | +const iconByResource: Record<string, typeof MemoryIcon> = { |
| 16 | + docker_volume: FolderIcon, |
| 17 | + docker_container: AdjustedMemoryIcon, |
| 18 | + docker_image: ImageIcon, |
| 19 | + kubernetes_persistent_volume_claim: FolderIcon, |
| 20 | + kubernetes_pod: AdjustedMemoryIcon, |
| 21 | + google_compute_disk: FolderIcon, |
| 22 | + google_compute_instance: AdjustedMemoryIcon, |
| 23 | + aws_instance: AdjustedMemoryIcon, |
| 24 | + kubernetes_deployment: AdjustedMemoryIcon, |
| 25 | + null_resource: HelpIcon, |
| 26 | +} |
| 27 | + |
| 28 | +export type ResourceAvatarProps = { type: string } |
| 29 | + |
| 30 | +export const ResourceAvatar: React.FC<ResourceAvatarProps> = ({ type }) => { |
| 31 | + // this resource can return undefined |
| 32 | + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
| 33 | + const IconComponent = iconByResource[type] ?? HelpIcon |
| 34 | + const styles = useStyles() |
| 35 | + |
| 36 | + return ( |
| 37 | + <Avatar className={styles.resourceAvatar}> |
| 38 | + <IconComponent style={{ fontSize: 20 }} /> |
| 39 | + </Avatar> |
| 40 | + ) |
| 41 | +} |
| 42 | + |
| 43 | +const useStyles = makeStyles((theme) => ({ |
| 44 | + resourceAvatar: { |
| 45 | + color: theme.palette.info.contrastText, |
| 46 | + backgroundColor: theme.palette.info.main, |
| 47 | + }, |
| 48 | +})) |
0 commit comments