|
|
@@ -0,0 +1,101 @@
|
|
|
+import { useState } from 'react'
|
|
|
+import { Boxes } from 'lucide-react'
|
|
|
+import { useTranslation } from 'react-i18next'
|
|
|
+import type { WorkloadItem, WorkloadsInfo } from '@/data/types'
|
|
|
+import { SectionHeader } from '@/components/SectionHeader'
|
|
|
+import { StatusPill } from '@/components/StatusPill'
|
|
|
+import type { PillTone } from '@/components/StatusPill'
|
|
|
+import { cn } from '@/lib/utils'
|
|
|
+
|
|
|
+/** How many guests the collapsed panel lists before "show all". A node's
|
|
|
+ * real workload list runs into the hundreds; the page stays a dashboard
|
|
|
+ * first and a manifest on demand. */
|
|
|
+const COLLAPSED_LIMIT = 10
|
|
|
+
|
|
|
+/** One workload's verdict pill. Unknown states stay visible and neutral:
|
|
|
+ * the producer normalizes, and an unlisted string is a producer bug we
|
|
|
+ * must not paint over with green. */
|
|
|
+function stateInfo(state: string | undefined): { key: string; tone: PillTone } {
|
|
|
+ switch (state) {
|
|
|
+ case 'running':
|
|
|
+ return { key: 'routerDetail.workloads.state.running', tone: 'ok' }
|
|
|
+ case 'pending':
|
|
|
+ return { key: 'routerDetail.workloads.state.pending', tone: 'info' }
|
|
|
+ case 'stopped':
|
|
|
+ return { key: 'routerDetail.workloads.state.stopped', tone: 'muted' }
|
|
|
+ default:
|
|
|
+ return { key: 'routerDetail.workloads.state.unknown', tone: 'muted' }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function WorkloadRow({ w }: { w: WorkloadItem }) {
|
|
|
+ const { t } = useTranslation()
|
|
|
+ const s = stateInfo(w.state)
|
|
|
+ return (
|
|
|
+ <li className="flex flex-wrap items-center gap-x-2.5 gap-y-1 py-2">
|
|
|
+ <span
|
|
|
+ className={cn(
|
|
|
+ 'h-2 w-2 shrink-0 rounded-full',
|
|
|
+ s.tone === 'ok' ? 'bg-ok' : s.tone === 'info' ? 'bg-info' : 'bg-text-muted',
|
|
|
+ )}
|
|
|
+ aria-hidden="true"
|
|
|
+ />
|
|
|
+ <span className="min-w-0 font-mono text-mono-sm text-text-primary">{w.name}</span>
|
|
|
+ {w.kind && <span className="text-caption text-text-muted">{w.kind}</span>}
|
|
|
+ <span className="flex-1" />
|
|
|
+ <StatusPill tone={s.tone} label={t(s.key)} />
|
|
|
+ </li>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * The nested guests a hypervisor-class host runs (#2227): pods of a node,
|
|
|
+ * VMs of a hypervisor, containers of a Docker box.
|
|
|
+ *
|
|
|
+ * Census, not topology: these live on the host and never join the graph,
|
|
|
+ * which is why they arrive in the detail payload and nowhere else. The
|
|
|
+ * list is read from the host's own pusher, exactly as it reported it.
|
|
|
+ */
|
|
|
+export function WorkloadsPanel({ info }: { info: WorkloadsInfo }) {
|
|
|
+ const { t } = useTranslation()
|
|
|
+ const [showAll, setShowAll] = useState(false)
|
|
|
+ // Defensive: the section comes from a pusher. Items absent means the
|
|
|
+ // unit reported and runs nothing; render the empty verdict, not a hole.
|
|
|
+ const items = [...(info?.items ?? [])].sort((a, b) => a.name.localeCompare(b.name))
|
|
|
+ const shown = showAll ? items : items.slice(0, COLLAPSED_LIMIT)
|
|
|
+
|
|
|
+ return (
|
|
|
+ <section className="rounded-2xl border border-border bg-surface p-5 md:p-6 lg:col-span-12">
|
|
|
+ <div className="flex flex-wrap items-center justify-between gap-2">
|
|
|
+ <div className="flex items-center gap-2">
|
|
|
+ <Boxes className="h-4 w-4 text-text-muted" strokeWidth={1.75} aria-hidden="true" />
|
|
|
+ <SectionHeader title={t('routerDetail.workloads.title')} />
|
|
|
+ </div>
|
|
|
+ <StatusPill tone={items.length > 0 ? 'accent' : 'muted'} label={t('routerDetail.workloads.total', { count: items.length })} />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {items.length === 0 ? (
|
|
|
+ <p className="mt-3 text-caption text-text-muted">{t('routerDetail.workloads.empty')}</p>
|
|
|
+ ) : (
|
|
|
+ <>
|
|
|
+ <ul className="mt-3 divide-y divide-border/60">
|
|
|
+ {shown.map((w) => (
|
|
|
+ <WorkloadRow key={w.id || w.name} w={w} />
|
|
|
+ ))}
|
|
|
+ </ul>
|
|
|
+ {items.length > COLLAPSED_LIMIT && (
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ onClick={() => setShowAll((v) => !v)}
|
|
|
+ className="mt-2 text-caption font-semibold text-accent transition-colors hover:text-accent/80"
|
|
|
+ >
|
|
|
+ {showAll ? t('routerDetail.workloads.collapse') : t('routerDetail.workloads.showAll', { n: items.length })}
|
|
|
+ </button>
|
|
|
+ )}
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+
|
|
|
+ <p className="mt-3 text-caption text-text-muted">{t('routerDetail.workloads.source')}</p>
|
|
|
+ </section>
|
|
|
+ )
|
|
|
+}
|