From 1c010efa294123d489ceefa41633aa82432a4bbd Mon Sep 17 00:00:00 2001 From: Amit Amrutiya Date: Wed, 30 Oct 2024 10:12:24 +0530 Subject: [PATCH] feat: show only valid svgs Signed-off-by: Amit Amrutiya --- src/custom/CatalogDetail/RightPanel.tsx | 4 +-- .../CatalogDetail/TechnologySection.tsx | 28 ++++++++++++++++--- src/custom/CatalogDetail/UserInfo.tsx | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/custom/CatalogDetail/RightPanel.tsx b/src/custom/CatalogDetail/RightPanel.tsx index 78e47625e..0c3c8a4d5 100644 --- a/src/custom/CatalogDetail/RightPanel.tsx +++ b/src/custom/CatalogDetail/RightPanel.tsx @@ -17,11 +17,11 @@ interface RightPanelProps { showCaveats: boolean; classes: Class[]; patternsPerUser: PatternsPerUser; - onSuggestedPatternClick: (pattern: Pattern) => void; handleCopyUrl: (type: string, name: string, id: string) => void; - fontFamily?: string; + onSuggestedPatternClick: (pattern: Pattern) => void; // eslint-disable-next-line @typescript-eslint/no-explicit-any useGetUserProfileByIdQuery: any; + fontFamily?: string; } const RightPanel: React.FC = ({ diff --git a/src/custom/CatalogDetail/TechnologySection.tsx b/src/custom/CatalogDetail/TechnologySection.tsx index f4cda831f..4018c6255 100644 --- a/src/custom/CatalogDetail/TechnologySection.tsx +++ b/src/custom/CatalogDetail/TechnologySection.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { ListItemIcon } from '../../base'; import { useTheme } from '../../theme'; import CollapsibleSection from './CollapsibleSection'; @@ -16,15 +16,35 @@ const TechnologySection: React.FC = ({ technologies }) => { const [openTechnologies, setOpenTechnologies] = useState(true); - + const [validTechnologies, setValidTechnologies] = useState([]); const theme = useTheme(); + useEffect(() => { + // Function to check if SVG exists + const validateTechnologies = async () => { + const validTechs = await Promise.all( + technologies.map(async (tech) => { + const svg_path = `/${technologySVGPath}/${tech.toLowerCase()}/${technologySVGSubpath}/${tech.toLowerCase()}-color.svg`; + try { + const response = await fetch(svg_path); + return response.ok ? tech : null; + } catch { + return null; + } + }) + ); + setValidTechnologies(validTechs.filter((tech): tech is string => tech !== null)); + }; + + validateTechnologies(); + }, [technologies, technologySVGPath, technologySVGSubpath]); + const renderTechnologyItem = (item: string, index: number) => { const svg_path = `${technologySVGPath}/${item.toLowerCase()}/${technologySVGSubpath}/${item.toLowerCase()}-color.svg`; return ( - technology icon + {`${item} {item} @@ -46,7 +66,7 @@ const TechnologySection: React.FC = ({ title="TECHNOLOGY" isOpen={openTechnologies} onToggle={() => setOpenTechnologies((prev) => !prev)} - items={technologies} + items={validTechnologies} renderItem={renderTechnologyItem} emptyState={'No technologies assigned to this design'} tooltip={'Technologies used in this design'} diff --git a/src/custom/CatalogDetail/UserInfo.tsx b/src/custom/CatalogDetail/UserInfo.tsx index 602433086..86029f960 100644 --- a/src/custom/CatalogDetail/UserInfo.tsx +++ b/src/custom/CatalogDetail/UserInfo.tsx @@ -21,7 +21,7 @@ const UserInfo: React.FC = ({ details, showVersion = true, userPr target="_blank" rel="noopener noreferrer" > - + {userProfile?.first_name} {userProfile?.last_name}