"use client" /** * The service detail drawer — a right-side overlay with a service header and a * tab bar. The tab bodies are injected by the host (`tabs[].content`), so the * drawer shell is reusable while the host owns each panel's data (Deployments, * Variables, Metrics, Logs, Domains, SBOM). Self-contained: backdrop, slide-in, * Escape-to-close, and a body-scroll lock — no external drawer dependency. */ import { useEffect, useState } from "react" import type { ReactNode } from "react" import { Text, XStack, YStack } from "@hanzo/gui" import { kindLabel } from "./color" import { kindGlyph } from "./glyphs" import { ServiceStatusBadge } from "./ServiceStatusBadge" import { CanvasStyles } from "./styles" import type { ServiceNodeData, ServiceStatus, StatusPalette } from "./types" const MONO = "ui-monospace, SFMono-Regular, Menlo, monospace" export interface DrawerTab { id: string label: string content: ReactNode badge?: number | string } export interface ServiceDetailDrawerProps { open: boolean onClose: () => void service: ServiceNodeData | null tabs: DrawerTab[] /** Controlled active tab; omit for internal (uncontrolled) tab state. */ activeTab?: string onTabChange?: (id: string) => void width?: number reducedMotion?: boolean statusPalette?: Partial> renderIcon?: (d: ServiceNodeData) => ReactNode /** Extra controls in the header (e.g. a Deploy button). */ headerActions?: ReactNode zIndex?: number } function CloseGlyph() { return ( ) } export function ServiceDetailDrawer({ open, onClose, service, tabs, activeTab, onTabChange, width = 480, reducedMotion, statusPalette, renderIcon, headerActions, zIndex = 1000, }: ServiceDetailDrawerProps) { const [internal, setInternal] = useState(tabs[0]?.id) // Reset the uncontrolled tab when the drawer opens for a different service. useEffect(() => { if (open) setInternal(tabs[0]?.id) // eslint-disable-next-line react-hooks/exhaustive-deps }, [open, service?.id]) // Escape-to-close + body-scroll lock while open. useEffect(() => { if (!open) return const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose() } document.addEventListener("keydown", onKey) const prev = document.body.style.overflow document.body.style.overflow = "hidden" return () => { document.removeEventListener("keydown", onKey) document.body.style.overflow = prev } }, [open, onClose]) if (!open || !service) return null const active = activeTab ?? internal ?? tabs[0]?.id const activePanel = tabs.find((t) => t.id === active) ?? tabs[0] const Glyph = kindGlyph(service.kind) const icon = renderIcon ? renderIcon(service) : const selectTab = (id: string) => { onTabChange?.(id) setInternal(id) } return (
{/* Backdrop */}
{/* Panel */} {/* Header */} {icon} {service.name} {service.typeLabel ?? kindLabel(service.kind)} {service.capability ? ( {service.capability.path ?? `/v1/${service.capability.id}`} ) : null} {headerActions} {/* Tab bar */} {tabs.map((t) => { const on = t.id === active return ( selectTab(t.id)} style={{ cursor: "pointer", borderBottom: `2px solid ${on ? "#8b949e" : "transparent"}`, marginBottom: -1, }} > {t.label} {t.badge != null ? ( {t.badge} ) : null} ) })} {/* Active panel */} {activePanel?.content}
) }