From 858e8c3b5c7465a7bf23f9e8a6d7339f81eefabb Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Mon, 5 Dec 2022 16:27:01 +0000 Subject: [PATCH] fix: Fix resource avatar when icon is empty string --- .../components/Resources/ResourceAvatar.stories.tsx | 9 +++++++++ site/src/components/Resources/ResourceAvatar.tsx | 12 +++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/site/src/components/Resources/ResourceAvatar.stories.tsx b/site/src/components/Resources/ResourceAvatar.stories.tsx index 07cbb7e0b77b4..3f9d9c2e8e77c 100644 --- a/site/src/components/Resources/ResourceAvatar.stories.tsx +++ b/site/src/components/Resources/ResourceAvatar.stories.tsx @@ -50,3 +50,12 @@ UnknownResource.args = { type: "noexistentvalue", }, } + +export const EmptyIcon = Template.bind({}) +EmptyIcon.args = { + resource: { + ...MockWorkspaceResource, + type: "helm_release", + icon: "", + }, +} diff --git a/site/src/components/Resources/ResourceAvatar.tsx b/site/src/components/Resources/ResourceAvatar.tsx index db01c7e00ef9f..85d99d3fbb13b 100644 --- a/site/src/components/Resources/ResourceAvatar.tsx +++ b/site/src/components/Resources/ResourceAvatar.tsx @@ -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", @@ -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 }