Skip to content

fix: Fix resource avatar when icon is empty string #5291

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
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions site/src/components/Resources/ResourceAvatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@ UnknownResource.args = {
type: "noexistentvalue",
},
}

export const EmptyIcon = Template.bind({})
EmptyIcon.args = {
resource: {
...MockWorkspaceResource,
type: "helm_release",
icon: "",
},
}
12 changes: 7 additions & 5 deletions site/src/components/Resources/ResourceAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { makeStyles } from "@material-ui/core/styles"
import React from "react"
import { WorkspaceResource } from "../../api/typesGenerated"

const FALLBACK_ICON = "/icon/widgets.svg"

// NOTE @jsjoeio, @BrunoQuaresma
// These resources (i.e. docker_image, kubernetes_deployment) map to Terraform
// resource types. These are the most used ones and are based on user usage.
// We may want to update from time-to-time.
const DEFAULT_ICON_PATHS: {
const BUILT_IN_ICON_PATHS: {
[resourceType: WorkspaceResource["type"]]: string
} = {
docker_volume: "/icon/folder.svg",
Expand All @@ -19,15 +21,15 @@ const DEFAULT_ICON_PATHS: {
google_compute_instance: "/icon/memory.svg",
aws_instance: "/icon/memory.svg",
kubernetes_deployment: "/icon/memory.svg",
null_resource: "/icon/widgets.svg",
null_resource: FALLBACK_ICON,
}

const getIconPathResource = (resourceType: string): string => {
if (resourceType in DEFAULT_ICON_PATHS) {
return DEFAULT_ICON_PATHS[resourceType]
if (resourceType in BUILT_IN_ICON_PATHS) {
return BUILT_IN_ICON_PATHS[resourceType]
}

return DEFAULT_ICON_PATHS[resourceType]
return FALLBACK_ICON
}

export type ResourceAvatarProps = { resource: WorkspaceResource }
Expand Down