diff --git a/site/src/components/AvatarData/AvatarData.tsx b/site/src/components/AvatarData/AvatarData.tsx index 107b0370039a4..81876befabed9 100644 --- a/site/src/components/AvatarData/AvatarData.tsx +++ b/site/src/components/AvatarData/AvatarData.tsx @@ -15,14 +15,25 @@ export interface AvatarDataProps { subtitle: string highlightTitle?: boolean link?: string + avatar?: React.ReactNode } -export const AvatarData: FC = ({ title, subtitle, link, highlightTitle }) => { +export const AvatarData: FC = ({ + title, + subtitle, + link, + highlightTitle, + avatar, +}) => { const styles = useStyles() + if (!avatar) { + avatar = {firstLetter(title)} + } + return (
- {firstLetter(title)} +
{avatar}
{link ? ( @@ -46,8 +57,7 @@ const useStyles = makeStyles((theme) => ({ display: "flex", alignItems: "center", }, - avatar: { + avatarWrapper: { marginRight: theme.spacing(1.5), - background: "hsl(219, 8%, 52%)", }, })) diff --git a/site/src/components/Resources/ResourceAvatar.stories.tsx b/site/src/components/Resources/ResourceAvatar.stories.tsx new file mode 100644 index 0000000000000..cf641cba0b6c8 --- /dev/null +++ b/site/src/components/Resources/ResourceAvatar.stories.tsx @@ -0,0 +1,34 @@ +import { Story } from "@storybook/react" +import { ResourceAvatar, ResourceAvatarProps } from "./ResourceAvatar" + +export default { + title: "components/ResourceAvatar", + component: ResourceAvatar, +} + +const Template: Story = (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", +} diff --git a/site/src/components/Resources/ResourceAvatar.tsx b/site/src/components/Resources/ResourceAvatar.tsx new file mode 100644 index 0000000000000..66ff0e25b7462 --- /dev/null +++ b/site/src/components/Resources/ResourceAvatar.tsx @@ -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 +} + +const iconByResource: Record = { + 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 = ({ type }) => { + // this resource can return undefined + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + const IconComponent = iconByResource[type] ?? HelpIcon + const styles = useStyles() + + return ( + + + + ) +} + +const useStyles = makeStyles((theme) => ({ + resourceAvatar: { + color: theme.palette.info.contrastText, + backgroundColor: theme.palette.info.main, + }, +})) diff --git a/site/src/components/Resources/Resources.tsx b/site/src/components/Resources/Resources.tsx index 119de5240167a..bb3ba6cf3c6db 100644 --- a/site/src/components/Resources/Resources.tsx +++ b/site/src/components/Resources/Resources.tsx @@ -7,6 +7,7 @@ import TableRow from "@material-ui/core/TableRow" import useTheme from "@material-ui/styles/useTheme" 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" @@ -15,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", @@ -68,6 +70,15 @@ export const Resources: FC = ({ /* We need to initialize the agents to display the resource */ } const agents = resource.agents ?? [null] + const resourceName = ( + } + title={resource.name} + subtitle={resource.type} + highlightTitle + /> + ) + return agents.map((agent, agentIndex) => { { /* If there is no agent, just display the resource name */ @@ -75,10 +86,7 @@ export const Resources: FC = ({ if (!agent) { return ( - - {resource.name} - {resource.type} - + {resourceName} ) @@ -91,8 +99,7 @@ export const Resources: FC = ({ {/* The rowspan should be the same than the number of agents */} {agentIndex === 0 && ( - {resource.name} - {resource.type} + {resourceName} )} @@ -149,6 +156,11 @@ const useStyles = makeStyles((theme) => ({ border: 0, }, + resourceAvatar: { + color: "#FFF", + backgroundColor: "#3B73D8", + }, + resourceNameCell: { borderRight: `1px solid ${theme.palette.divider}`, }, diff --git a/site/src/theme/overrides.ts b/site/src/theme/overrides.ts index 7310ad77e945a..9deac14e03fa0 100644 --- a/site/src/theme/overrides.ts +++ b/site/src/theme/overrides.ts @@ -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: { diff --git a/site/src/theme/palettes.ts b/site/src/theme/palettes.ts index 41702d0d73d27..399ee47662502 100644 --- a/site/src/theme/palettes.ts +++ b/site/src/theme/palettes.ts @@ -28,4 +28,7 @@ export const darkPalette: PaletteOptions = { success: { main: "hsl(142, 58%, 41%)", }, + info: { + main: "hsl(219, 67%, 54%)", + }, }