Skip to content

feat: Add resource icons #3118

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 3 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: Add resource icons
  • Loading branch information
BrunoQuaresma committed Jul 22, 2022
commit 8473b49696a2731ee399b692bf7244da0867543c
7 changes: 3 additions & 4 deletions site/src/components/AvatarData/AvatarData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export const AvatarData: FC<AvatarDataProps> = ({
const styles = useStyles()

if (!avatar) {
avatar = firstLetter(title)
avatar = <Avatar>{firstLetter(title)}</Avatar>
}

return (
<div className={styles.root}>
<Avatar className={styles.avatar}>{avatar}</Avatar>
<div className={styles.avatarWrapper}>{avatar}</div>

{link ? (
<Link to={link} underline="none" component={RouterLink}>
Expand All @@ -57,8 +57,7 @@ const useStyles = makeStyles((theme) => ({
display: "flex",
alignItems: "center",
},
avatar: {
avatarWrapper: {
marginRight: theme.spacing(1.5),
background: "hsl(219, 8%, 52%)",
},
}))
34 changes: 34 additions & 0 deletions site/src/components/Resources/ResourceAvatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Story } from "@storybook/react"
import { ResourceAvatar, ResourceAvatarProps } from "./ResourceAvatar"

export default {
title: "components/ResourceAvatar",
component: ResourceAvatar,
}

const Template: Story<ResourceAvatarProps> = (args) => <ResourceAvatar {...args} />

export const VolumeResource = Template.bind({})
VolumeResource.args = {
type: "docker_volume",
}

export const ComputeResource = Template.bind({})
ComputeResource.args = {
type: "docker_container",
}

export const ImageResource = Template.bind({})
ImageResource.args = {
type: "docker_image",
}

export const NullResource = Template.bind({})
NullResource.args = {
type: "null_resource",
}

export const UnkownResource = Template.bind({})
UnkownResource.args = {
type: "noexistentvalue",
}
48 changes: 48 additions & 0 deletions site/src/components/Resources/ResourceAvatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Avatar from "@material-ui/core/Avatar"
import { makeStyles } from "@material-ui/core/styles"
import FolderIcon from "@material-ui/icons/FolderOutlined"
import HelpIcon from "@material-ui/icons/HelpOutlined"
import ImageIcon from "@material-ui/icons/ImageOutlined"
import MemoryIcon from "@material-ui/icons/MemoryOutlined"
import React from "react"

// For this special case, we need to apply a different style because how this
// particular icon has been designed
const AdjustedMemoryIcon: typeof MemoryIcon = ({ style, ...props }) => {
return <MemoryIcon style={{ ...style, fontSize: 24 }} {...props} />
}

const iconByResource: Record<string, typeof MemoryIcon> = {
docker_volume: FolderIcon,
docker_container: AdjustedMemoryIcon,
docker_image: ImageIcon,
kubernetes_persistent_volume_claim: FolderIcon,
kubernetes_pod: AdjustedMemoryIcon,
google_compute_disk: FolderIcon,
google_compute_instance: AdjustedMemoryIcon,
aws_instance: AdjustedMemoryIcon,
kubernetes_deployment: AdjustedMemoryIcon,
null_resource: HelpIcon,
}

export type ResourceAvatarProps = { type: string }

export const ResourceAvatar: React.FC<ResourceAvatarProps> = ({ type }) => {
// this resource can return undefined
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const IconComponent = iconByResource[type] ?? HelpIcon
const styles = useStyles()

return (
<Avatar className={styles.resourceAvatar}>
<IconComponent style={{ fontSize: 20 }} />
</Avatar>
)
}

const useStyles = makeStyles((theme) => ({
resourceAvatar: {
color: theme.palette.info.contrastText,
backgroundColor: theme.palette.info.main,
},
}))
11 changes: 8 additions & 3 deletions site/src/components/Resources/Resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import TableBody from "@material-ui/core/TableBody"
import TableCell from "@material-ui/core/TableCell"
import TableHead from "@material-ui/core/TableHead"
import TableRow from "@material-ui/core/TableRow"
import MemoryIcon from "@material-ui/icons/MemoryOutlined"
import useTheme from "@material-ui/styles/useTheme"
import { AvatarData } from "components/AvatarData/AvatarData"
import { FC } from "react"
import { Workspace, WorkspaceResource } from "../../api/typesGenerated"
import { AvatarData } from "../../components/AvatarData/AvatarData"
import { getDisplayAgentStatus } from "../../util/workspace"
import { AppLink } from "../AppLink/AppLink"
import { SSHButton } from "../SSHButton/SSHButton"
Expand All @@ -17,6 +16,7 @@ import { TableHeaderRow } from "../TableHeaders/TableHeaders"
import { TerminalLink } from "../TerminalLink/TerminalLink"
import { AgentHelpTooltip } from "../Tooltips/AgentHelpTooltip"
import { ResourcesHelpTooltip } from "../Tooltips/ResourcesHelpTooltip"
import { ResourceAvatar } from "./ResourceAvatar"

const Language = {
resources: "Resources",
Expand Down Expand Up @@ -72,7 +72,7 @@ export const Resources: FC<ResourcesProps> = ({
const agents = resource.agents ?? [null]
const resourceName = (
<AvatarData
avatar={<MemoryIcon />}
avatar={<ResourceAvatar type={resource.type} />}
title={resource.name}
subtitle={resource.type}
highlightTitle
Expand Down Expand Up @@ -156,6 +156,11 @@ const useStyles = makeStyles((theme) => ({
border: 0,
},

resourceAvatar: {
color: "#FFF",
backgroundColor: "#3B73D8",
},

resourceNameCell: {
borderRight: `1px solid ${theme.palette.divider}`,
},
Expand Down
4 changes: 3 additions & 1 deletion site/src/theme/overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export const getOverrides = (palette: PaletteOptions) => {
},
MuiAvatar: {
root: {
borderColor: palette.divider,
width: 36,
height: 36,
fontSize: 18,
},
colorDefault: {
backgroundColor: "#a1adc9",
},
},
MuiButton: {
root: {
Expand Down
3 changes: 3 additions & 0 deletions site/src/theme/palettes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ export const darkPalette: PaletteOptions = {
success: {
main: "hsl(142, 58%, 41%)",
},
info: {
main: "hsl(219, 67%, 54%)",
},
}