Skip to content

refactor: use WidgetsIcon for null resources #3754

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
Changes from all commits
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
13 changes: 6 additions & 7 deletions site/src/components/Resources/ResourceAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
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 WidgetsIcon from "@material-ui/icons/WidgetsOutlined"
import React from "react"
import { WorkspaceResource } from "../../api/typesGenerated"

// 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> = {
const iconByResource: Record<WorkspaceResource["type"], typeof MemoryIcon | undefined> = {
docker_volume: FolderIcon,
docker_container: AdjustedMemoryIcon,
docker_image: ImageIcon,
Expand All @@ -22,15 +23,13 @@ const iconByResource: Record<string, typeof MemoryIcon> = {
google_compute_instance: AdjustedMemoryIcon,
aws_instance: AdjustedMemoryIcon,
kubernetes_deployment: AdjustedMemoryIcon,
null_resource: HelpIcon,
null_resource: WidgetsIcon,
}

export type ResourceAvatarProps = { type: string }
export type ResourceAvatarProps = { type: WorkspaceResource["type"] }

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 IconComponent = iconByResource[type] ?? WidgetsIcon
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the resource can be undefined, I modified the return type of iconByResource to match that, which lets us remove this eslint line.

const styles = useStyles()

return (
Expand Down