Files
MikrotikManager/components/network-map/map-site-directory.tsx
T
Denozordec 545a9bbcd2
Docker images / prepare-release (push) Successful in 13s
Docker images / backend-test (push) Successful in 11m8s
Docker images / frontend-image (push) Successful in 2m25s
Docker images / updater-image (push) Successful in 41s
Docker images / netflow-agent-image (push) Successful in 34s
Docker images / backend-image (push) Successful in 2m1s
Docker images / publish-release (push) Successful in 13s
Docker images / notify-webhook (push) Successful in 2s
feat(network-map): добавить сворачивание групп и категории трафика
2026-12-03 09:58:24 +07:00

89 lines
4.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client"
import { ChevronRightIcon } from "lucide-react"
import { Button } from "@/components/ui/button"
import { StatusBadge } from "@/components/status-badge"
import type { Server, ServerType } from "@/lib/data"
import type { GreMapEdge } from "@/lib/network-map-layout"
import { channelStatus, countGroupGre } from "@/lib/network-map-group-links"
import { ruPlural } from "./map-kpi-strip"
export function mapSiteName(server: Server) {
const site = server.site?.trim()
return site && site !== "—" ? site : "Без площадки"
}
export function MapChannelList({ edges, selected, onChannel }: {
edges: GreMapEdge[]; selected?: GreMapEdge; onChannel: (edge: GreMapEdge) => void
}) {
return <div className="max-h-56 overflow-y-auto">{edges.map(edge => {
const state = channelStatus(edge)
return <Button type="button" key={JSON.stringify([edge.tunnel.serverId, edge.tunnel.id])} aria-pressed={selected ? edge === selected : undefined}
variant={edge === selected ? "secondary" : "ghost"} className="h-auto min-h-9 w-full justify-between gap-2 whitespace-normal text-left" onClick={() => onChannel(edge)}>
<span className="min-w-0 break-words">{edge.tunnel.name}<small className="block text-muted-foreground">{edge.fromServer.name} ↔ {edge.toServer.name}</small></span>
<StatusBadge status={state === "up" ? "online" : state === "down" ? "offline" : "degraded"} />
</Button>
})}</div>
}
export function MapSiteDirectory({ servers, edges, sites, active, onSite, onServer, onChannel, roleLabels }: {
servers: Server[]
edges: GreMapEdge[]
sites: string[]
active: string | null
onSite: (site: string | null) => void
onServer: (server: Server) => void
onChannel: (edge: GreMapEdge) => void
roleLabels: Record<ServerType, string>
}) {
const members = new Map<string, Server[]>()
for (const server of servers) {
const site = mapSiteName(server)
if (!members.has(site)) members.set(site, [])
members.get(site)!.push(server)
}
const neighbors = new Map<string, GreMapEdge[]>()
for (const edge of edges) {
const a = mapSiteName(edge.fromServer), b = mapSiteName(edge.toServer)
if (a === b || (active !== a && active !== b)) continue
const other = active === a ? b : a
if (!neighbors.has(other)) neighbors.set(other, [])
neighbors.get(other)!.push(edge)
}
if (!sites.length) return null
return <section aria-label="Площадки" className="space-y-2">
<h3 className="text-sm font-semibold">Площадки</h3>
<div className="divide-y rounded-lg border">
{sites.map(site => {
const devices = members.get(site) ?? []
const open = site === active
const problems = devices.filter(s => s.enabled !== false && (s.status === "offline" || s.status === "degraded")).length
return <div key={site}>
<Button type="button" variant="ghost" aria-expanded={open} className="h-auto min-h-10 w-full justify-start gap-2 whitespace-normal px-3 text-left" onClick={() => onSite(open ? null : site)}>
<ChevronRightIcon aria-hidden className={open ? "rotate-90" : ""} />
<span className="min-w-0 flex-1 break-words">{site}</span>
{problems > 0 && <span className="text-xs text-warning">Требуют внимания · {problems}</span>}
<span className="text-xs text-muted-foreground">{devices.length} {ruPlural(devices.length, "узел", "узла", "узлов")}</span>
</Button>
{open && <div className="space-y-2 border-t bg-muted/20 p-2">
{devices.map(server => <Button key={server.id} type="button" variant="ghost" className="h-auto min-h-9 w-full justify-start gap-2 whitespace-normal text-left" onClick={() => onServer(server)}>
<span className="min-w-0 flex-1 break-words">{server.name}{" "}<small className="ml-2 text-muted-foreground">{roleLabels[server.type]}</small></span>
<StatusBadge status={server.status} />
</Button>)}
{Array.from(neighbors, ([neighbor, channels]) => {
const { count, down, degraded } = countGroupGre(channels)
return <details key={neighbor} className="border-t px-2 pt-2">
<summary className="cursor-pointer text-sm">{site} ↔ {neighbor}
{down > 0 && <span className="ml-2 text-warning">Недоступно {down} из {count}</span>}
{degraded > 0 && <span className="ml-2 text-warning">С деградацией · {degraded}</span>}
</summary>
<MapChannelList edges={channels} onChannel={onChannel} />
</details>
})}
</div>}
</div>
})}
</div>
</section>
}