Skip to content

Commit 892c8ba

Browse files
committed
fix: move self topology status to subtitle
1 parent 26932ff commit 892c8ba

File tree

4 files changed

+113
-27
lines changed

4 files changed

+113
-27
lines changed

src/components/StatusLine/StatusLine.tsx

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export type StatusLineData = {
1818
statuses: StatusInfo[];
1919
};
2020

21-
export type StatusLineProps = React.HTMLProps<HTMLDivElement> & StatusLineData;
21+
export type StatusLineProps = React.HTMLProps<HTMLDivElement> &
22+
StatusLineData & {
23+
hideName?: boolean;
24+
};
2225

2326
interface RenderIconProps {
2427
icon: string | React.ReactNode;
@@ -72,34 +75,39 @@ export function StatusLine({
7275
label,
7376
url,
7477
statuses,
75-
className = "py-1",
78+
className = "py-0.5",
79+
hideName = false,
7680
...rest
7781
}: StatusLineProps) {
7882
return (
7983
<div
8084
className={clsx("flex flex-row items-center space-x-1", className)}
8185
{...rest}
8286
>
83-
{icon && <RenderIcon icon={icon} />}
84-
{url && (
85-
<Link
86-
title={label}
87-
target={target || ""}
88-
className="h-4 cursor-pointer overflow-hidden truncate text-xs"
89-
to={url}
90-
>
91-
{label}
92-
</Link>
87+
{!hideName && (
88+
<>
89+
{icon && <RenderIcon icon={icon} />}
90+
{url && (
91+
<Link
92+
title={label}
93+
target={target || ""}
94+
className="h-4 cursor-pointer overflow-hidden truncate text-xs"
95+
to={url}
96+
>
97+
{label}
98+
</Link>
99+
)}
100+
{!url && (
101+
<span
102+
title={label}
103+
className="h-4 cursor-pointer overflow-hidden truncate text-xs"
104+
>
105+
{label}
106+
</span>
107+
)}
108+
</>
93109
)}
94-
{!url && (
95-
<span
96-
title={label}
97-
className="h-4 cursor-pointer overflow-hidden truncate text-xs"
98-
>
99-
{label}
100-
</span>
101-
)}
102-
<div className="flex flex-row space-x-1.5">
110+
<div className="flex flex-row space-x-1">
103111
{statuses.map((status, index) => {
104112
return <StatusInfoEntry statusInfo={status} key={index} />;
105113
})}

src/components/Topology/TopologyCard/TopologyCard.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import { MouseEventHandler, useMemo } from "react";
1010
import { Link, useParams, useSearchParams } from "react-router-dom";
1111
import AgentName from "../../Agents/AgentName";
1212
import { CardMetrics } from "./CardMetrics";
13-
import TopologyCardStatuses from "./TopologCardStatuses";
13+
import TopologyCardStatuses from "./TopologyCardStatuses";
1414
import TopologyCardPropertiesColumn from "./TopologyCardPropertiesColumn";
1515
import { TopologyDropdownMenu } from "./TopologyDropdownMenu";
16+
import TopologyItemHealthSummary from "./TopologyItemHealthSummary";
1617

1718
export enum ComponentHealth {
1819
unhealthy = "unhealthy",
@@ -214,6 +215,7 @@ export function TopologyCard({
214215
{topology.status_reason}
215216
</div>
216217
)}
218+
<TopologyItemHealthSummary topology={topology} />
217219
</div>
218220
</div>
219221
</div>

src/components/Topology/TopologyCard/TopologCardStatuses.tsx renamed to src/components/Topology/TopologyCard/TopologyCardStatuses.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function getTopologyHealthStatuses(topology: Topology) {
169169
return data;
170170
}
171171

172-
function getTopologyHealthSummary(
172+
export function getTopologyHealthSummary(
173173
topology: Topology,
174174
viewType: "individual_level" | "children_level"
175175
) {
@@ -206,7 +206,7 @@ function getTopologyHealthSummary(
206206
return data;
207207
}
208208

209-
function topologiesHealthSummaries(topology: Topology) {
209+
export function topologiesHealthSummaries(topology: Topology) {
210210
return topology?.components
211211
?.sort((a, b) => {
212212
// we want to move unhealthy components to the top, then warning, then healthy
@@ -277,15 +277,13 @@ export default function TopologyCardStatuses({
277277
return [];
278278
}
279279

280-
const healthSummary =
281-
getTopologyHealthSummary(topology, "individual_level") ?? [];
282280
const healthChecks = getTopologyHealthStatuses(topology);
283281
const insights = insightStatuses(topology);
284282
const incidents = incidentsStatuses(topology) ?? [];
285283
const components = topologiesHealthSummaries(topology) ?? [];
286284

287285
return (
288-
[healthSummary, healthChecks, insights, ...incidents, ...components]
286+
[healthChecks, insights, ...incidents, ...components]
289287
.filter((status) => status)
290288
// remove empty statuses
291289
.filter((status) => status!.statuses.length > 0)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { Topology } from "@flanksource-ui/api/types/topology";
2+
import {
3+
StatusInfo,
4+
StatusLine
5+
} from "@flanksource-ui/components/StatusLine/StatusLine";
6+
import { useMemo } from "react";
7+
8+
type TopologyItemHealthSummaryProps = {
9+
topology: Topology;
10+
};
11+
12+
export default function TopologyItemHealthSummary({
13+
topology
14+
}: TopologyItemHealthSummaryProps) {
15+
console.log(
16+
"TopologyItemHealthSummaryProps",
17+
topology.components?.map((c) => c.summary?.checks)
18+
);
19+
20+
const statusLines = useMemo(() => {
21+
const summary = topology.components?.reduce(
22+
(acc, component) => {
23+
const health =
24+
(component.summary?.healthy || 0) +
25+
(component.summary?.checks?.healthy || 0);
26+
const warning =
27+
component.summary?.warning ||
28+
0 + (component.summary?.checks?.warning || 0);
29+
const unhealthy =
30+
component.summary?.unhealthy ||
31+
0 + (component.summary?.checks?.unhealthy || 0);
32+
if (health) {
33+
acc["health"] += health;
34+
}
35+
if (warning) {
36+
acc["warning"] += warning;
37+
}
38+
if (unhealthy) {
39+
acc["unhealthy"] += unhealthy;
40+
}
41+
return acc;
42+
},
43+
{
44+
health: 0,
45+
unhealthy: 0,
46+
warning: 0
47+
}
48+
);
49+
50+
if (!summary) {
51+
return undefined;
52+
}
53+
54+
return Object.entries(summary)
55+
.filter(([_, count]) => count > 0)
56+
.map(([status, count]) => {
57+
return {
58+
label: count,
59+
color:
60+
status === "health"
61+
? "green"
62+
: status === "warning"
63+
? "orange"
64+
: "red"
65+
} satisfies StatusInfo;
66+
});
67+
}, [topology]);
68+
69+
if (!statusLines || statusLines.length === 0) {
70+
return null;
71+
}
72+
73+
return (
74+
<div className="flex flex-col gap-1">
75+
<StatusLine statuses={statusLines} hideName label={""} />
76+
</div>
77+
);
78+
}

0 commit comments

Comments
 (0)