Skip to content

Commit 858e8c3

Browse files
committed
fix: Fix resource avatar when icon is empty string
1 parent e04877a commit 858e8c3

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

site/src/components/Resources/ResourceAvatar.stories.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,12 @@ UnknownResource.args = {
5050
type: "noexistentvalue",
5151
},
5252
}
53+
54+
export const EmptyIcon = Template.bind({})
55+
EmptyIcon.args = {
56+
resource: {
57+
...MockWorkspaceResource,
58+
type: "helm_release",
59+
icon: "",
60+
},
61+
}

site/src/components/Resources/ResourceAvatar.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { makeStyles } from "@material-ui/core/styles"
33
import React from "react"
44
import { WorkspaceResource } from "../../api/typesGenerated"
55

6+
const FALLBACK_ICON = "/icon/widgets.svg"
7+
68
// NOTE @jsjoeio, @BrunoQuaresma
79
// These resources (i.e. docker_image, kubernetes_deployment) map to Terraform
810
// resource types. These are the most used ones and are based on user usage.
911
// We may want to update from time-to-time.
10-
const DEFAULT_ICON_PATHS: {
12+
const BUILT_IN_ICON_PATHS: {
1113
[resourceType: WorkspaceResource["type"]]: string
1214
} = {
1315
docker_volume: "/icon/folder.svg",
@@ -19,15 +21,15 @@ const DEFAULT_ICON_PATHS: {
1921
google_compute_instance: "/icon/memory.svg",
2022
aws_instance: "/icon/memory.svg",
2123
kubernetes_deployment: "/icon/memory.svg",
22-
null_resource: "/icon/widgets.svg",
24+
null_resource: FALLBACK_ICON,
2325
}
2426

2527
const getIconPathResource = (resourceType: string): string => {
26-
if (resourceType in DEFAULT_ICON_PATHS) {
27-
return DEFAULT_ICON_PATHS[resourceType]
28+
if (resourceType in BUILT_IN_ICON_PATHS) {
29+
return BUILT_IN_ICON_PATHS[resourceType]
2830
}
2931

30-
return DEFAULT_ICON_PATHS[resourceType]
32+
return FALLBACK_ICON
3133
}
3234

3335
export type ResourceAvatarProps = { resource: WorkspaceResource }

0 commit comments

Comments
 (0)