From 99a28d82177bd90c1383b7b47211a8b6c6d2efec Mon Sep 17 00:00:00 2001 From: Maina Wycliffe Date: Wed, 28 Aug 2024 10:19:30 +0300 Subject: [PATCH] fix: show two columns, when the other one is empty fix: show two columns when no none headline properties chore: remove console.log chore: update spacing fix: show two property columns when no analytics fix: fix issues with cards styling fix: scroll issues --- src/components/Canary/HealthChecksSummary.tsx | 2 +- src/components/StatusLine/StatusLine.tsx | 18 ++- .../Topology/TopologyCard/CardMetrics.tsx | 4 + .../Topology/TopologyCard/TopologyCard.tsx | 120 ++++++++++-------- .../TopologyCardPropertiesColumn.tsx | 10 +- .../TopologyCard/Utils/FormatProperties.tsx | 1 - src/ui/CustomScroll/index.tsx | 8 +- 7 files changed, 92 insertions(+), 71 deletions(-) diff --git a/src/components/Canary/HealthChecksSummary.tsx b/src/components/Canary/HealthChecksSummary.tsx index 34f7a850d..b095e9121 100644 --- a/src/components/Canary/HealthChecksSummary.tsx +++ b/src/components/Canary/HealthChecksSummary.tsx @@ -23,7 +23,7 @@ export function HealthChecksSummary({ const data: StatusLineProps = { label: "Health Checks", - icon: , + icon: , url: "/health", statuses: [ ...(checks.healthy > 0 diff --git a/src/components/StatusLine/StatusLine.tsx b/src/components/StatusLine/StatusLine.tsx index ec0cfed48..618d9ede9 100644 --- a/src/components/StatusLine/StatusLine.tsx +++ b/src/components/StatusLine/StatusLine.tsx @@ -20,15 +20,21 @@ export type StatusLineData = { export type StatusLineProps = React.HTMLProps & StatusLineData; -const renderIcon = (icon: string | React.ReactNode) => { +interface RenderIconProps { + icon: string | React.ReactNode; +} + +const RenderIcon: React.FC = ({ icon }) => { if (!icon) { return null; } if (typeof icon === "object") { - return icon; + // eslint-disable-next-line react/jsx-no-useless-fragment + return <>{icon}; } else if (typeof icon === "string") { - return ; + return ; } + return null; }; const StatusInfoEntry = ({ @@ -46,14 +52,14 @@ const StatusInfoEntry = ({ to={statusInfo.url} target={target || ""} > - {statusInfo.icon && renderIcon(statusInfo.icon)} + {statusInfo.icon && } ); } else { return ( - {statusInfo.icon && renderIcon(statusInfo.icon)} + {statusInfo.icon && } ); @@ -74,7 +80,7 @@ export function StatusLine({ className={clsx("flex flex-row items-center space-x-1", className)} {...rest} > - {icon && renderIcon(icon)} + {icon && } {url && ( { + if (!items || items.length === 0) { + return null; + } + return (
{items.map((item) => ( diff --git a/src/components/Topology/TopologyCard/TopologyCard.tsx b/src/components/Topology/TopologyCard/TopologyCard.tsx index 3ca8f96af..08cfadf14 100644 --- a/src/components/Topology/TopologyCard/TopologyCard.tsx +++ b/src/components/Topology/TopologyCard/TopologyCard.tsx @@ -85,24 +85,6 @@ export function TopologyCard({ [size] ); - const canShowChildHealth = () => { - let totalCount = 0; - if (topology?.summary?.checks) { - topology.summary.checks.healthy = topology.summary.checks.healthy || 0; - topology.summary.checks.unhealthy = - topology.summary.checks.unhealthy || 0; - topology.summary.checks.warning = topology.summary.checks.warning || 0; - Object.keys(topology.summary.checks).forEach((key) => { - totalCount += - topology.summary?.checks?.[key as keyof Topology["summary"]] || 0; - }); - } - return ( - !topology?.components?.length && - (!topology?.is_leaf || (topology.is_leaf && totalCount !== 1)) - ); - }; - const prepareTopologyLink = (topologyItem: Topology) => { if (topologyItem.id === parentId && parentId) { return ""; @@ -143,22 +125,49 @@ export function TopologyCard({ [topology?.components] ); + const { heading, properties, isPropertiesPanelEmpty } = useMemo(() => { + const allProperties = topology?.properties || []; + const properties = allProperties.filter((i) => !i.headline); + + const heading = allProperties.filter( + (i) => i.headline && (!!i.value || !!i.text || !!i.url) + ); + + const isPropertiesPanelShown = + properties.filter( + (i) => !i.headline && i.type !== "hidden" && (i.text || i.value) + ).length > 0; + + return { + heading, + properties, + isPropertiesPanelEmpty: !isPropertiesPanelShown + }; + }, [topology?.properties]); + + const isAnalyticsPanelEmpty = useMemo(() => { + // if there are no insights, checks or components, we don't need to show the + // second panel at all + return ( + !topology?.summary?.insights && + !topology?.summary?.checks && + (sortedTopologyComponents ?? []).length === 0 + ); + }, [ + sortedTopologyComponents, + topology?.summary?.checks, + topology?.summary?.insights + ]); + if (topology == null) { return ; } - const allProperties = topology.properties || []; - const properties = allProperties.filter((i) => !i.headline); - - const heading = allProperties.filter( - (i) => i.headline && (!!i.value || !!i.text || !!i.url) - ); - return (
- {metricsInFooter ? ( + {metricsInFooter && heading.length > 0 ? (
) : ( <> - - - - {canShowChildHealth() && ( - - )} - - {topology?.id && } - {sortedTopologyComponents?.map((component: any) => ( - + {!isAnalyticsPanelEmpty && ( + + + - ))} - + {sortedTopologyComponents?.map((component: any) => ( + + ))} + {topology?.id && } + + )} )}
diff --git a/src/components/Topology/TopologyCard/TopologyCardPropertiesColumn.tsx b/src/components/Topology/TopologyCard/TopologyCardPropertiesColumn.tsx index 0e48109c9..fb1cab671 100644 --- a/src/components/Topology/TopologyCard/TopologyCardPropertiesColumn.tsx +++ b/src/components/Topology/TopologyCard/TopologyCardPropertiesColumn.tsx @@ -1,13 +1,16 @@ import { Property } from "@flanksource-ui/api/types/topology"; import { CustomScroll } from "@flanksource-ui/ui/CustomScroll"; +import clsx from "clsx"; import { PropertyDisplay } from "./Property"; type TopologyCardPropertiesColumnProps = { properties: Property[]; + displayTwoColumns?: boolean; }; export default function TopologyCardPropertiesColumn({ - properties + properties, + displayTwoColumns = false }: TopologyCardPropertiesColumnProps) { // Filter out properties that are hidden, have no text or value, and are not a // headline property. @@ -21,7 +24,10 @@ export default function TopologyCardPropertiesColumn({ return ( @@ -51,7 +47,7 @@ export const CustomScroll = ({ setShowMore(false); }} className={clsx( - "bottom-0 m-auto w-full hover:underline", + "bottom-0 col-span-2 m-auto w-full hover:underline", showMoreClass )} >