Skip to content

Commit e6802f0

Browse files
authored
refactor: use WidgetsIcon for null resources (#3754)
* refactor: replace HelpIcon w/WidgetsIcon Based on user feedback, we believe the `WidgetsIcon` will cause less confusion. * fixup * refactor: clean up types in ResourceAvatar.tsx Before, we were using `string` for `type` in `ResourceAvatar`. This meant it wasn't tied to the types generated from the backend. Now it imports `WorkspaceResource` so that there is a single source of truth and they always stay in sync.
1 parent 774d758 commit e6802f0

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

site/src/components/Resources/ResourceAvatar.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import Avatar from "@material-ui/core/Avatar"
22
import { makeStyles } from "@material-ui/core/styles"
33
import FolderIcon from "@material-ui/icons/FolderOutlined"
4-
import HelpIcon from "@material-ui/icons/HelpOutlined"
54
import ImageIcon from "@material-ui/icons/ImageOutlined"
65
import MemoryIcon from "@material-ui/icons/MemoryOutlined"
6+
import WidgetsIcon from "@material-ui/icons/WidgetsOutlined"
77
import React from "react"
8+
import { WorkspaceResource } from "../../api/typesGenerated"
89

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

15-
const iconByResource: Record<string, typeof MemoryIcon> = {
16+
const iconByResource: Record<WorkspaceResource["type"], typeof MemoryIcon | undefined> = {
1617
docker_volume: FolderIcon,
1718
docker_container: AdjustedMemoryIcon,
1819
docker_image: ImageIcon,
@@ -22,15 +23,13 @@ const iconByResource: Record<string, typeof MemoryIcon> = {
2223
google_compute_instance: AdjustedMemoryIcon,
2324
aws_instance: AdjustedMemoryIcon,
2425
kubernetes_deployment: AdjustedMemoryIcon,
25-
null_resource: HelpIcon,
26+
null_resource: WidgetsIcon,
2627
}
2728

28-
export type ResourceAvatarProps = { type: string }
29+
export type ResourceAvatarProps = { type: WorkspaceResource["type"] }
2930

3031
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
32+
const IconComponent = iconByResource[type] ?? WidgetsIcon
3433
const styles = useStyles()
3534

3635
return (

0 commit comments

Comments
 (0)