Docker images / prepare-release (push) Successful in 14s
Docker images / backend-test (push) Successful in 12m24s
Docker images / frontend-image (push) Successful in 2m21s
Docker images / updater-image (push) Successful in 41s
Docker images / netflow-agent-image (push) Successful in 32s
Docker images / backend-image (push) Successful in 1m52s
Docker images / publish-release (push) Successful in 17s
Docker images / notify-webhook (push) Successful in 2s
95 lines
6.9 KiB
TypeScript
95 lines
6.9 KiB
TypeScript
"use client"
|
||
|
||
import { ChevronsUpDownIcon } from "lucide-react"
|
||
import type { KeyboardEvent } from "react"
|
||
import { mapCardMeta, mapCardMetrics } from "@/lib/network-map-card-metrics"
|
||
import { MapFaultBadge } from "./wire-badge"
|
||
import { placeMapLinkLabels, type MapBox } from "@/lib/network-map-layout"
|
||
import type { MapGroupLink } from "@/lib/network-map-group-links"
|
||
|
||
function activate(event: KeyboardEvent<SVGGElement>, action: () => void) {
|
||
if (event.key !== "Enter" && event.key !== " ") return
|
||
event.preventDefault()
|
||
event.stopPropagation()
|
||
action()
|
||
}
|
||
|
||
const roleColors: Record<string, string> = {
|
||
HR: "var(--chart-2)", JH: "var(--chart-1)", EN: "var(--chart-3)", IX: "var(--chart-4)", WAN: "var(--muted-foreground)",
|
||
}
|
||
|
||
export function MapGroupMark({ id, x, y, name, code, count, expanded, problems = 0, unknownCount = 0, onToggle, visible = true, width = code === "WAN" ? 155 : 157 }: {
|
||
id: string; x: number; y: number; name: string; code: string; count: number; expanded: boolean
|
||
problems?: number; unknownCount?: number; onToggle: () => void; visible?: boolean; width?: number
|
||
}) {
|
||
const {height, lines} = mapCardMetrics(name, "group", width)
|
||
const color = roleColors[code] ?? "var(--muted-foreground)"
|
||
const health = problems ? `Проблемы · ${problems}` : unknownCount ? `Нет данных · ${unknownCount}` : ""
|
||
const label = [name, `${code} × ${count}`, health, problems && unknownCount ? `Нет данных · ${unknownCount}` : ""].filter(Boolean).join(" · ")
|
||
const meta = `${code === "WAN" ? "WAN" : "Устройств"} · ${count}`
|
||
return <g transform={`translate(${x - width / 2},${y - height / 2})`} data-map-group={id} data-node-kind="group"
|
||
role="button" tabIndex={visible ? 0 : -1} aria-expanded={expanded} aria-label={`${expanded ? "Свернуть" : "Раскрыть"} группу · ${label}`}
|
||
className="network-map-focusable cursor-pointer" opacity={visible ? 1 : 0.38}
|
||
onPointerDown={event => event.stopPropagation()} onClick={event => { event.stopPropagation(); onToggle() }}
|
||
onKeyDown={event => activate(event, onToggle)}>
|
||
<title>{[name, `${code} ×${count}`, health].filter(Boolean).join(" · ")}</title>
|
||
<rect className="network-map-focus-ring" x="-3" y="-3" width={width + 6} height={height + 6} rx="11" fill="none" stroke="var(--ring)" strokeWidth="2" />
|
||
<rect data-map-box="group" width={width} height={height} rx="9" fill="var(--card)" stroke={problems ? "color-mix(in oklch,var(--warning) 50%,transparent)" : "var(--border)"} strokeWidth="1.5" strokeDasharray="4 2" />
|
||
<rect data-role-tile={code} x="7" y="7" width="24" height="24" rx="7" fill={color} fillOpacity=".18" />
|
||
<text x="19" y="23" textAnchor="middle" fill={color} fontFamily="var(--font-mono,Geist Mono,monospace)" fontSize="11.5" fontWeight="700">{code}</text>
|
||
<ChevronsUpDownIcon x={width - 21} y="6" width="16" height="16" color="var(--muted-foreground)" aria-hidden="true" />
|
||
{lines.map((line, i) => <text key={i} x="37" y={18 + i * 14} fill="var(--foreground)" fontSize="13" fontWeight="600">{line}</text>)}
|
||
<text x="37" y={33 + (lines.length - 1) * 14} fill="var(--muted-foreground)" fontFamily="var(--font-mono,Geist Mono,monospace)" fontSize="10.5">{mapCardMeta(meta, width - 44) === meta ? meta : `×${count}`}</text>
|
||
{health && <text x="8" y={height - 5} fill={problems ? "var(--status-degraded-fg)" : "var(--muted-foreground)"} fontFamily={problems ? undefined : "var(--font-mono,Geist Mono,monospace)"}
|
||
fontSize={problems ? 11 : 10.5} fontWeight={problems ? 500 : 400}>{mapCardMeta(health, width - 18)}</text>}
|
||
</g>
|
||
}
|
||
|
||
const linkNames: Record<MapGroupLink["type"], string> = {
|
||
gre: "GRE", "wan-jh": "WAN → JH", wan: "WAN", ix: "IX", user: "Привязки", service: "Пути к назначению", observation: "Наблюдения IPFIX",
|
||
}
|
||
|
||
function linkColor(link: MapGroupLink) {
|
||
if (link.down === link.count) return "var(--status-offline)"
|
||
if (link.down || link.degraded) return "var(--status-degraded)"
|
||
if (link.type === "gre") return "var(--status-online)"
|
||
if (link.type === "user") return "var(--chart-2)"
|
||
if (link.type === "service" || link.type === "ix") return "var(--chart-4)"
|
||
return "var(--muted-foreground)"
|
||
}
|
||
|
||
export function MapGroupLinks({ links, obstacles, onExpand, layer = "all" }: {
|
||
links: MapGroupLink[]; obstacles: MapBox[]; onExpand: (ids: string[]) => void; layer?: "all" | "lines" | "labels"
|
||
}) {
|
||
// Place outage labels first so that a routine count cannot occupy their available space.
|
||
const entries = [...links].sort((a, b) => b.down - a.down || b.degraded - a.degraded).map(row => {
|
||
const type = linkNames[row.type], color = linkColor(row)
|
||
const summary = [`${type} ×${row.count}`, row.down ? `недоступно ${row.down} из ${row.count}` : "", row.degraded ? `ухудшено · ${row.degraded}` : ""].filter(Boolean).join(" · ")
|
||
const texts = row.down ? [`${type} · Недоступно ${row.down} из ${row.count}`, `Недоступно ${row.down} из ${row.count}`, `↓ ${row.down}/${row.count}`] :
|
||
row.degraded ? [`${type} · Деградация ${row.degraded} из ${row.count}`, `! ${row.degraded}/${row.count}`] : []
|
||
return { ...row, color, texts, fault:Boolean(row.down || row.degraded), title: `${row.from.name} → ${row.to.name} · ${summary}` }
|
||
})
|
||
const labels = layer === "lines" ? [] : placeMapLinkLabels(entries, obstacles)
|
||
return <>
|
||
{layer !== "labels" && entries.map(row => (
|
||
<g key={row.id} data-map-group-link={row.type} data-channel-count={row.count} data-channel-down={row.down} role="button" tabIndex={0}
|
||
aria-label={`${row.title} · Раскрыть группу`} className="network-map-focusable cursor-pointer"
|
||
onPointerDown={event => event.stopPropagation()} onClick={event => { event.stopPropagation(); onExpand(row.groups) }}
|
||
onKeyDown={event => activate(event, () => onExpand(row.groups))}>
|
||
<title>{row.title}</title>
|
||
<path className="network-map-focus-ring" d={row.link.d} fill="none" stroke="var(--ring)" strokeWidth="6" />
|
||
<path d={row.link.d} fill="none" stroke={row.color} strokeWidth={row.fault ? 2.8 : row.type === "gre" ? 2.4 : 1.6} opacity={row.fault ? 1 : row.type === "observation" ? .56 : .76}
|
||
strokeDasharray={row.down === row.count ? "2 3" : row.fault ? "6 3" : row.type === "observation" ? "4 3" : undefined} strokeLinejoin="round" strokeLinecap="round" />
|
||
<path d={row.link.d} fill="none" stroke="transparent" strokeWidth="16" />
|
||
</g>
|
||
))}
|
||
{labels.map(row => (
|
||
<g key={row.id} transform={`translate(${row.x},${row.y})`} data-map-group-link-label={row.type} className="cursor-pointer" aria-hidden="true"
|
||
onPointerDown={event => event.stopPropagation()} onClick={event => { event.stopPropagation(); onExpand(row.groups) }}>
|
||
<title>{row.title}</title>
|
||
<MapFaultBadge width={row.w} text={row.text} down={row.down === row.count} />
|
||
</g>
|
||
))}
|
||
</>
|
||
}
|