fix(map): улучшить навигацию и разбор инцидентов на карте
Docker images / prepare-release (push) Successful in 15s
Docker images / backend-test (push) Successful in 4s
Docker images / frontend-image (push) Successful in 2m22s
Docker images / updater-image (push) Successful in 41s
Docker images / netflow-agent-image (push) Successful in 33s
Docker images / backend-image (push) Successful in 16s
Docker images / publish-release (push) Successful in 10s
Docker images / notify-webhook (push) Successful in 2s
Docker images / prepare-release (push) Successful in 15s
Docker images / backend-test (push) Successful in 4s
Docker images / frontend-image (push) Successful in 2m22s
Docker images / updater-image (push) Successful in 41s
Docker images / netflow-agent-image (push) Successful in 33s
Docker images / backend-image (push) Successful in 16s
Docker images / publish-release (push) Successful in 10s
Docker images / notify-webhook (push) Successful in 2s
This commit is contained in:
1 parent
d174bca5d6
commit
4eafc78c8e
9 files changed
+322
-126
No files matched your search
@@ -7,7 +7,7 @@ import type { IxLinuxBinding, IxSegment } from "@mmapp/contracts/internet-exchan
|
||||
import type { FlowMapService, FlowMapServicePath } from "@mmapp/contracts/traffic-flow"
|
||||
import { Badge } from "@/components/reui/badge"
|
||||
import { Button, buttonVariants } from "@/components/ui/button"
|
||||
import { Command, CommandDialog, CommandEmpty, CommandInput, CommandItem, CommandList } from "@/components/ui/command"
|
||||
import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command"
|
||||
import { INIT_USERS } from "@/lib/users"
|
||||
import { fmtRate } from "@/lib/fmt-rate"
|
||||
import { formatNetflowRate } from "@/lib/map-netflow-hops"
|
||||
@@ -128,19 +128,35 @@ export function accessRate(bindings: AccessBinding[], rates?: Map<string, Access
|
||||
return { measured, total, rx, tx, label: measured ? `${measured < total ? "≥ " : ""}${fmtRate(rx + tx)}` : "Нет замера" }
|
||||
}
|
||||
|
||||
export function MapUserPicker({ open, onOpenChange, users, pending, unavailable, onPick }: {
|
||||
export function MapUserPicker({ open, onOpenChange, users, pending, unavailable, selectedUser, nodeName, onPick, onClear }: {
|
||||
open: boolean; onOpenChange: (open: boolean) => void; users: MapAccessUser[]; pending: boolean; unavailable: boolean; onPick: (user: MapAccessUser) => void
|
||||
selectedUser?: MapAccessUser; nodeName: (id: string) => string; onClear: () => void
|
||||
}) {
|
||||
return <CommandDialog open={open} onOpenChange={onOpenChange} title="Выбор пользователя" description="Поиск по имени, логину или интерфейсу">
|
||||
const ordered = [...users].sort((a, b) => a.name.localeCompare(b.name, "ru"))
|
||||
return <CommandDialog open={open} onOpenChange={onOpenChange} showCloseButton title="Выбор пользователя" description="Поиск по имени, логину, узлу или интерфейсу">
|
||||
<Command>
|
||||
<CommandInput aria-label="Поиск пользователей" placeholder="Имя, логин или интерфейс…" />
|
||||
<div className="flex flex-col gap-1 px-3 pt-3 pb-2">
|
||||
<p className="pr-8 text-sm font-semibold">Кого показать на карте?</p>
|
||||
<p className="text-xs text-muted-foreground">Выберите пользователя, чтобы увидеть его подключения и сервисы.</p>
|
||||
</div>
|
||||
<CommandInput aria-label="Поиск пользователей" placeholder="Имя, логин, узел или интерфейс…" />
|
||||
<CommandList>
|
||||
<CommandEmpty>{pending ? "Загрузка пользователей…" : unavailable ? "Каталог пользователей недоступен" : "Пользователи не найдены"}</CommandEmpty>
|
||||
{users.map(user => <CommandItem key={user.id} value={user.id} keywords={[user.name, user.login ?? "", ...user.bindings.map(binding => binding.name)]} onSelect={() => onPick(user)}>
|
||||
<UsersIcon aria-hidden /><span className="min-w-0 flex-1 truncate">{user.name}</span>
|
||||
<Badge variant="outline" size="xs">{user.bindings.length}</Badge>
|
||||
</CommandItem>)}
|
||||
{selectedUser && <CommandItem value="all-network" keywords={["Вся схема", "Сбросить пользователя"]} onSelect={onClear}>Вся схема</CommandItem>}
|
||||
<CommandGroup heading={ordered.length ? `Пользователи · ${ordered.length}` : undefined}>
|
||||
{ordered.map(user => {
|
||||
const nodes = [...new Set(user.bindings.map(binding => nodeName(binding.node)))].sort()
|
||||
return <CommandItem key={user.id} value={user.id} keywords={[user.name, user.login ?? "", ...nodes, ...user.bindings.map(binding => binding.name)]} onSelect={() => onPick(user)}>
|
||||
<UsersIcon aria-hidden /><span className="grid min-w-0 flex-1 gap-0.5">
|
||||
<span className="truncate font-medium">{user.name}</span>
|
||||
<span className="truncate text-xs text-muted-foreground" title={nodes.join(", ")}>{[user.login !== user.name && user.login, ...nodes].filter(Boolean).join(" · ")}</span>
|
||||
</span>
|
||||
{selectedUser?.id === user.id ? <Badge variant="secondary" size="sm">На карте</Badge> : <Badge variant="outline" size="sm" title="Привязки интерфейсов">{user.bindings.length} инт.</Badge>}
|
||||
</CommandItem>
|
||||
})}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
<p className="px-3 py-2 text-xs text-muted-foreground">↑ ↓ выбор · Enter открыть · Esc закрыть</p>
|
||||
</Command>
|
||||
</CommandDialog>
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import type { ReactNode } from "react"
|
||||
import { useState, type ReactNode } from "react"
|
||||
import { ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||
import { FramePanel } from "@/components/reui/frame"
|
||||
import { Badge } from "@/components/reui/badge"
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||
@@ -16,7 +17,7 @@ export type MapBottomTab = "flows" | "rtt" | "dest" | "events"
|
||||
|
||||
function Table({ head, cols, empty, children }: { head: string[]; cols: string; empty: string | null; children: ReactNode }) {
|
||||
return (
|
||||
<div className="max-h-[420px] overflow-auto">
|
||||
<div className="max-h-[min(34svh,310px)] overflow-auto">
|
||||
<div className="min-w-[720px]">
|
||||
<div aria-hidden="true" className={cn("bg-muted/55 text-muted-foreground sticky top-0 z-[1] grid h-10 items-center gap-x-3 border-b px-4 text-xs font-medium", cols)}>
|
||||
{head.map((h) => <span key={h}>{h}</span>)}
|
||||
@@ -40,45 +41,53 @@ const EVENT_COLS = "grid-cols-[70px_110px_minmax(200px,1.4fr)_minmax(200px,2fr)]
|
||||
* Рабочая панель под картой (макет v3): потоки NetFlow, RTT каналов, назначения и события.
|
||||
* Строки выбранного объекта подсвечены.
|
||||
*/
|
||||
export function MapBottomPanel({ tab, onTab, flows, rtt, destinations, events, onEvent, eventsError, stat }: {
|
||||
export function MapBottomPanel({ tab, onTab, open, onOpenChange, flows, rtt, destinations, events, onEvent, onFlow, onDestination, eventsError, stat }: {
|
||||
tab: MapBottomTab
|
||||
onTab: (tab: MapBottomTab) => void
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
flows: MapFlowRow[]
|
||||
rtt: MapRttRow[]
|
||||
destinations: MapDestRow[]
|
||||
events: MapEventRow[]
|
||||
onEvent: (event: MapEventRow) => void
|
||||
onFlow: (id: string) => void
|
||||
onDestination: (id: string) => void
|
||||
eventsError: string | null
|
||||
stat: string
|
||||
}) {
|
||||
const [showRoutineEvents, setShowRoutineEvents] = useState(false)
|
||||
const incidentEvents = events.filter(event => event.tone === "er" || event.tone === "wn")
|
||||
const visibleEvents = showRoutineEvents ? events : incidentEvents
|
||||
const tabs: Array<{ id: MapBottomTab; label: string; count: number }> = [
|
||||
{ id: "flows", label: "Потоки NetFlow", count: flows.length },
|
||||
{ id: "rtt", label: "RTT каналов", count: rtt.length },
|
||||
{ id: "dest", label: "Назначения", count: destinations.length },
|
||||
{ id: "events", label: "События", count: events.length },
|
||||
{ id: "events", label: "События", count: visibleEvents.length },
|
||||
]
|
||||
return (
|
||||
<SectionFrame aria-label="Рабочая панель карты" bare>
|
||||
<Tabs value={tab} onValueChange={(value) => onTab(value as MapBottomTab)} className="gap-1">
|
||||
<div className="flex flex-wrap items-center gap-3 px-2 pt-1.5 pb-1">
|
||||
<TabsList aria-label="Рабочая панель">
|
||||
<SectionFrame aria-label="Рабочая панель карты" bare className="min-w-0 shrink-0">
|
||||
<Tabs value={tab} onValueChange={(value) => { onTab(value as MapBottomTab); onOpenChange(true) }} className="gap-1">
|
||||
<div className="flex min-w-0 items-center gap-2 px-2 py-1">
|
||||
<div className="min-w-0 flex-1 overflow-x-auto"><TabsList aria-label="Рабочая панель">
|
||||
{tabs.map((t) => (
|
||||
<TabsTrigger key={t.id} value={t.id} className="px-2.5">
|
||||
<TabsTrigger key={t.id} value={t.id} className="px-2.5" onClick={() => onOpenChange(true)}>
|
||||
{t.label}
|
||||
<Badge variant="secondary" size="sm" className="font-mono">{t.count}</Badge>
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
<span className="text-muted-foreground ml-auto text-xs">{stat}</span>
|
||||
</TabsList></div>
|
||||
{open && <span className="hidden text-xs text-muted-foreground xl:inline">{stat}</span>}
|
||||
<Button type="button" variant="ghost" size="icon-sm" aria-expanded={open} aria-controls="network-map-analysis" aria-label={open ? "Свернуть рабочую панель" : "Открыть рабочую панель"} onClick={() => onOpenChange(!open)}>{open ? <ChevronDownIcon /> : <ChevronUpIcon />}</Button>
|
||||
</div>
|
||||
<FramePanel className="p-0">
|
||||
<FramePanel id="network-map-analysis" hidden={!open} className="p-0">
|
||||
<TabsContent value="flows">
|
||||
<Table head={["Пользователь", "Выход / экспортёр", "Назначение", "Скорость", "Объём"]} cols={FLOW_COLS} empty={flows.length ? null : "NetFlow за окно не прислал потоков к назначениям"}>
|
||||
{flows.map((r) => (
|
||||
<Row key={r.id} cols={FLOW_COLS} hl={r.hl}>
|
||||
<span className="truncate font-mono">{r.client}</span>
|
||||
<span className="truncate font-mono">{r.exit}</span>
|
||||
<span className="truncate">{r.dest}</span>
|
||||
<Button type="button" variant="link" size="xs" className="min-w-0 justify-start" onClick={() => onFlow(r.id)}><span className="truncate">{r.dest}</span></Button>
|
||||
<span className="font-mono tabular-nums">{r.rate}</span>
|
||||
<span className="text-muted-foreground font-mono tabular-nums">{r.volume}</span>
|
||||
</Row>
|
||||
@@ -102,7 +111,7 @@ export function MapBottomPanel({ tab, onTab, flows, rtt, destinations, events, o
|
||||
<Table head={["Назначение", "Категория", "Скорость", "Доля окна"]} cols={DEST_COLS} empty={destinations.length ? null : "Назначений за окно нет"}>
|
||||
{destinations.map((r) => (
|
||||
<Row key={r.id} cols={DEST_COLS} hl={r.hl}>
|
||||
<span className="truncate font-medium">{r.label}</span>
|
||||
<Button type="button" variant="link" size="xs" className="min-w-0 justify-start" onClick={() => onDestination(r.id)}><span className="truncate">{r.label}</span></Button>
|
||||
<span className="text-muted-foreground truncate">{r.category}</span>
|
||||
<span className="font-mono tabular-nums">{r.rate}</span>
|
||||
<span className="flex items-center gap-2">
|
||||
@@ -114,8 +123,13 @@ export function MapBottomPanel({ tab, onTab, flows, rtt, destinations, events, o
|
||||
</Table>
|
||||
</TabsContent>
|
||||
<TabsContent value="events">
|
||||
<Table head={["Время", "Тип", "Событие", "Подробности"]} cols={EVENT_COLS} empty={eventsError ? `События недоступны: ${eventsError}` : events.length ? null : "Событий пока нет"}>
|
||||
{events.map((r) => (
|
||||
<div className="flex items-center gap-2 border-b px-3 py-1">
|
||||
<Button type="button" size="xs" variant={showRoutineEvents ? "outline" : "secondary"} aria-pressed={!showRoutineEvents} onClick={() => setShowRoutineEvents(false)}>Сбои и предупреждения</Button>
|
||||
<Button type="button" size="xs" variant={showRoutineEvents ? "secondary" : "outline"} aria-pressed={showRoutineEvents} onClick={() => setShowRoutineEvents(true)}>Все события</Button>
|
||||
</div>
|
||||
{eventsError && <p role="status" className="px-3 py-1 text-xs text-muted-foreground">{eventsError}</p>}
|
||||
<Table head={["Время", "Тип", "Событие", "Подробности"]} cols={EVENT_COLS} empty={visibleEvents.length ? null : eventsError ? "Нет подтверждённых событий" : showRoutineEvents ? "Событий пока нет" : "В полученных событиях нет сбоев и предупреждений"}>
|
||||
{visibleEvents.map((r) => (
|
||||
<Row key={r.id} cols={EVENT_COLS}>
|
||||
<time dateTime={new Date(r.ts).toISOString()} className="text-muted-foreground font-mono text-xs">{new Date(r.ts).toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" })}</time>
|
||||
<span><ToneBadge tone={r.tone} mark={false}>{r.label}</ToneBadge></span>
|
||||
@@ -135,35 +149,45 @@ export function MapBottomPanel({ tab, onTab, flows, rtt, destinations, events, o
|
||||
* «Момент времени» (макет v3): инциденты за 24 часа на шкале и текущий Live-снимок.
|
||||
* Архив снимков карты не хранится, поэтому прошлые моменты не выбираются.
|
||||
*/
|
||||
export function MapTimeline({ events, now, onPick }: { events: MapEventRow[]; now: number; onPick: (event: MapEventRow) => void }) {
|
||||
export function MapTimeline({ events, now, state, onPick }: { events: MapEventRow[]; now: number; state?: string; onPick: (event: MapEventRow) => void }) {
|
||||
const from = now - 24 * 3_600_000
|
||||
const marks = events.filter((e) => e.ts >= from && e.ts <= now)
|
||||
const hours = new Map<number, MapEventRow[]>()
|
||||
for (const event of events) {
|
||||
if (event.ts < from || event.ts > now || event.tone !== "er" && event.tone !== "wn") continue
|
||||
const hour = Math.min(23, Math.floor((event.ts - from) / 3_600_000))
|
||||
const group = hours.get(hour) ?? []
|
||||
group.push(event)
|
||||
hours.set(hour, group)
|
||||
}
|
||||
const at = (t: number) => `calc(10px + (100% - 20px) * ${t.toFixed(4)})`
|
||||
// Шкала макета v3: остановки (кружок и подпись под ним), инциденты — цветные засечки над линией.
|
||||
const stop = "absolute top-[7px] flex -translate-x-1/2 flex-col items-center gap-1 text-[11px] leading-none whitespace-nowrap"
|
||||
return (
|
||||
<div className="flex shrink-0 items-center gap-3 border-t px-3 pt-1.5 pb-1">
|
||||
<small className="text-muted-foreground text-xs whitespace-nowrap">Момент времени</small>
|
||||
<small className="flex flex-col text-xs text-muted-foreground" title={state}>Инциденты{state ? <span role="status" className="hidden sm:inline">{state}</span> : null}</small>
|
||||
<div role="group" aria-label="Инциденты карты за 24 часа" className="relative mx-3.5 h-9 min-w-0 flex-1">
|
||||
<span aria-hidden="true" className="bg-border absolute inset-x-2.5 top-[11px] h-0.5 rounded-full" />
|
||||
{[["−24 ч", 0], ["−6 ч", 0.75], ["−1 ч", 0.9583]].map(([label, t]) => (
|
||||
<span key={label} aria-hidden="true" className={cn(stop, "text-muted-foreground")} style={{ left: at(Number(t)) }}>
|
||||
<i className="bg-card border-muted-foreground block size-2.5 rounded-full border-2" />{label}
|
||||
<i className="bg-card border-muted-foreground block size-2.5 rounded-full border-2" />{label === "−1 ч" ? <span className="hidden xl:inline">{label}</span> : label}
|
||||
</span>
|
||||
))}
|
||||
{marks.map((e) => (
|
||||
{[...hours].map(([hour, group]) => {
|
||||
const e = group.find(event => event.tone === "er") ?? group[0]
|
||||
const label = `${new Date(e.ts).toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" })} · ${e.title}${group.length > 1 ? ` · ещё ${group.length - 1}` : ""}`
|
||||
return (
|
||||
<button
|
||||
key={e.id}
|
||||
type="button"
|
||||
onClick={() => onPick(e)}
|
||||
aria-label={`${new Date(e.ts).toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" })} · ${e.title}`}
|
||||
title={`${new Date(e.ts).toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" })} · ${e.title}`}
|
||||
aria-label={label}
|
||||
title={label}
|
||||
className="focus-visible:ring-ring absolute top-1 flex h-4 w-3 -translate-x-1/2 justify-center rounded-sm outline-none focus-visible:ring-2"
|
||||
style={{ left: at((e.ts - from) / (now - from)) }}
|
||||
style={{ left: at((hour + 0.5) / 24) }}
|
||||
>
|
||||
<span aria-hidden="true" className="block h-full w-1.5 rounded-sm" style={{ background: TONE_COLOR[e.tone] }} />
|
||||
</button>
|
||||
))}
|
||||
)})}
|
||||
<span className={cn(stop, "text-foreground font-semibold")} style={{ left: at(1) }}>
|
||||
<i className="bg-success border-success block size-2.5 rounded-full border-2 shadow-[0_0_0_4px_color-mix(in_oklch,var(--success)_25%,transparent)]" />Live
|
||||
</span>
|
||||
|
||||
Reference in new issue
Block a user