From 6de5145fac1417cab509f3b8f6c72edee3889fbd Mon Sep 17 00:00:00 2001 From: Feroze Mohideen Date: Fri, 29 Sep 2023 11:48:00 -0400 Subject: [PATCH] hotfix buildpack rendering (#3685) --- .../buildpacks/BuildpackCard.tsx | 136 +++++++++--------- .../buildpacks/BuildpackCard.tsx | 49 ++++--- 2 files changed, 99 insertions(+), 86 deletions(-) diff --git a/dashboard/src/main/home/app-dashboard/build-settings/buildpacks/BuildpackCard.tsx b/dashboard/src/main/home/app-dashboard/build-settings/buildpacks/BuildpackCard.tsx index 52d49ab55d..5dd33205a8 100644 --- a/dashboard/src/main/home/app-dashboard/build-settings/buildpacks/BuildpackCard.tsx +++ b/dashboard/src/main/home/app-dashboard/build-settings/buildpacks/BuildpackCard.tsx @@ -1,12 +1,12 @@ -import React from "react"; +import React, { useMemo } from "react"; import { DeviconsNameList } from "assets/devicons-name-list"; import styled, { keyframes } from "styled-components"; import { Draggable } from "react-beautiful-dnd"; -import { Buildpack } from "../../types/buildpack"; +import { Buildpack } from "main/home/app-dashboard/types/buildpack"; interface Props { buildpack: Buildpack; - action: 'add' | 'remove'; + action: "add" | "remove"; onClickFn: (buildpack: string) => void; index: number; draggable: boolean; @@ -19,65 +19,73 @@ const BuildpackCard: React.FC = ({ index, draggable, }) => { - const [languageName] = buildpack.name?.split("/").reverse(); - - const devicon = DeviconsNameList.find( - (devicon) => languageName.toLowerCase() === devicon.name - ); - - const icon = `devicon-${devicon?.name}-plain colored`; - - return ( - draggable ? - - {(provided) => ( - - - - - {buildpack?.name} - - - - onClickFn(buildpack.buildpack)} - > - {action === "remove" ? "delete" : "add"} - + const iconClassName = useMemo(() => { + if (!buildpack.name) { + return ""; + } - - - )} - - : - - - - - {buildpack?.name} - - - - onClickFn(buildpack.buildpack)} - > - {action === "remove" ? "delete" : "add"} - + const splits = buildpack.name.split("/"); + if (splits.length !== 1) { + return ""; + } - - + const devicon = DeviconsNameList.find( + (devicon) => splits[0].toLowerCase() === devicon.name + ); + if (!devicon) { + return ""; + } + return `devicon-${devicon.name}-plain colored` + }, [buildpack.name]); + + const renderedBuildpackName = useMemo(() => { + return buildpack.name ?? buildpack.buildpack; + }, [buildpack.name]); + + return draggable ? ( + + {(provided) => ( + + + {iconClassName && } + + {renderedBuildpackName} + + + + onClickFn(buildpack.buildpack)}> + + {action === "remove" ? "delete" : "add"} + + + + + )} + + ) : ( + + + {iconClassName && } + + {renderedBuildpackName} + + + + onClickFn(buildpack.buildpack)}> + + {action === "remove" ? "delete" : "add"} + + + + ); -} +}; export default BuildpackCard; @@ -112,14 +120,10 @@ const ContentContainer = styled.div` align-items: center; `; -const Icon = styled.span<{ disableMarginRight: boolean }>` +const Icon = styled.span` font-size: 20px; margin-left: 10px; - ${(props) => { - if (!props.disableMarginRight) { - return "margin-right: 20px"; - } - }} + margin-right: 20px `; const EventInformation = styled.div` @@ -154,12 +158,10 @@ const ActionButton = styled.button` border-radius: 50%; cursor: pointer; color: #aaaabb; - :hover { background: #ffffff11; border: 1px solid #ffffff44; } - > span { font-size: 20px; } diff --git a/dashboard/src/main/home/app-dashboard/validate-apply/build-settings/buildpacks/BuildpackCard.tsx b/dashboard/src/main/home/app-dashboard/validate-apply/build-settings/buildpacks/BuildpackCard.tsx index 113201d5bf..5dd33205a8 100644 --- a/dashboard/src/main/home/app-dashboard/validate-apply/build-settings/buildpacks/BuildpackCard.tsx +++ b/dashboard/src/main/home/app-dashboard/validate-apply/build-settings/buildpacks/BuildpackCard.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useMemo } from "react"; import { DeviconsNameList } from "assets/devicons-name-list"; import styled, { keyframes } from "styled-components"; import { Draggable } from "react-beautiful-dnd"; @@ -19,28 +19,43 @@ const BuildpackCard: React.FC = ({ index, draggable, }) => { - const [languageName] = buildpack.name?.split("/").reverse(); + const iconClassName = useMemo(() => { + if (!buildpack.name) { + return ""; + } - const devicon = DeviconsNameList.find( - (devicon) => languageName.toLowerCase() === devicon.name - ); + const splits = buildpack.name.split("/"); + if (splits.length !== 1) { + return ""; + } - const icon = `devicon-${devicon?.name}-plain colored`; + const devicon = DeviconsNameList.find( + (devicon) => splits[0].toLowerCase() === devicon.name + ); + if (!devicon) { + return ""; + } + return `devicon-${devicon.name}-plain colored` + }, [buildpack.name]); + + const renderedBuildpackName = useMemo(() => { + return buildpack.name ?? buildpack.buildpack; + }, [buildpack.name]); return draggable ? ( - + {(provided) => ( - + {iconClassName && } - {buildpack?.name} + {renderedBuildpackName} @@ -54,11 +69,11 @@ const BuildpackCard: React.FC = ({ )} ) : ( - + - + {iconClassName && } - {buildpack?.name} + {renderedBuildpackName} @@ -105,14 +120,10 @@ const ContentContainer = styled.div` align-items: center; `; -const Icon = styled.span<{ disableMarginRight: boolean }>` +const Icon = styled.span` font-size: 20px; margin-left: 10px; - ${(props) => { - if (!props.disableMarginRight) { - return "margin-right: 20px"; - } - }} + margin-right: 20px `; const EventInformation = styled.div`