Skip to content

Commit 6716acc

Browse files
committed
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 e9566fc commit 6716acc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

site/src/components/Resources/ResourceAvatar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import ImageIcon from "@material-ui/icons/ImageOutlined"
55
import MemoryIcon from "@material-ui/icons/MemoryOutlined"
66
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,
@@ -25,7 +26,7 @@ const iconByResource: Record<string, typeof MemoryIcon> = {
2526
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 }) => {
3132
const IconComponent = iconByResource[type] ?? WidgetsIcon

0 commit comments

Comments
 (0)