From 9740a91fe32a2d34a95741617a4a56e75886de23 Mon Sep 17 00:00:00 2001 From: ibolton336 Date: Fri, 29 Sep 2023 17:26:16 -0400 Subject: [PATCH] :bug: Fix img fetching logic Signed-off-by: ibolton336 --- .../src/app/components/KeycloakProvider.tsx | 2 +- client/src/app/components/TargetCard.tsx | 45 ++++++++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/client/src/app/components/KeycloakProvider.tsx b/client/src/app/components/KeycloakProvider.tsx index a523eaea64..daf2ed50f5 100644 --- a/client/src/app/components/KeycloakProvider.tsx +++ b/client/src/app/components/KeycloakProvider.tsx @@ -6,7 +6,7 @@ import { deleteCookie, getCookie, setCookie } from "@app/queries/cookies"; import { AppPlaceholder } from "./AppPlaceholder"; import { Flex, FlexItem, Spinner } from "@patternfly/react-core"; import { ReactKeycloakProvider } from "@react-keycloak/web"; -import React, { Suspense, useEffect } from "react"; +import React, { Suspense } from "react"; interface IKeycloakProviderProps { children: React.ReactNode; diff --git a/client/src/app/components/TargetCard.tsx b/client/src/app/components/TargetCard.tsx index 5044d0af22..8a78a8a972 100644 --- a/client/src/app/components/TargetCard.tsx +++ b/client/src/app/components/TargetCard.tsx @@ -24,7 +24,7 @@ import { SelectVariant, SelectOptionObject, } from "@patternfly/react-core/deprecated"; -import { CubesIcon, GripVerticalIcon } from "@patternfly/react-icons"; +import { GripVerticalIcon } from "@patternfly/react-icons"; import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing"; import { useTranslation } from "react-i18next"; @@ -32,6 +32,7 @@ import { KebabDropdown } from "./KebabDropdown"; import DefaultRulesetIcon from "@app/images/Icon-Red_Hat-Virtual_server_stack-A-Black-RGB.svg"; import { Target, TargetLabel } from "@app/api/models"; import "./TargetCard.css"; +import axios from "axios"; export interface TargetCardProps { item: Target; @@ -68,6 +69,8 @@ export const TargetCard: React.FC = ({ const { t } = useTranslation(); const [isCardSelected, setCardSelected] = React.useState(cardSelected); + const [imageDataUrl, setImageDataUrl] = React.useState(null); + const prevSelectedLabel = formLabels?.find((formLabel) => { const labelNames = target?.labels?.map((label) => label.name); @@ -105,23 +108,23 @@ export const TargetCard: React.FC = ({ } }; - const getImage = (): React.ComponentType => { - let result: React.ComponentType = CubesIcon; - const imagePath = target?.image?.id - ? `/hub/files/${target?.image.id}` - : DefaultRulesetIcon; - if (target.image) { - result = () => ( - Card logo - ); + const fetchImageAndSetDataUrl = async (imagePath: string) => { + try { + const imageDataResponse = await axios.get(imagePath, { + headers: { + Accept: "application/octet-stream", + }, + }); + const encodedSvg = encodeURIComponent(imageDataResponse.data); + setImageDataUrl(`data:image/svg+xml,${encodedSvg}`); + } catch (error) { + console.error("There was an issue fetching the image:", error); } - - return result; }; + const imagePath = target?.image?.id + ? `/hub/files/${target?.image.id}` + : DefaultRulesetIcon; + fetchImageAndSetDataUrl(imagePath); return ( = ({ variant={EmptyStateVariant.sm} className="select-card__component__empty-state" > - + ( + Card logo + )} + /> {target.name}