Files
oikos/web/src/pages/Signals.svelte
dtoro cbfd09c5df
Some checks failed
ci / build-test (push) Has been cancelled
ci / docker-build (push) Has been cancelled
feat: redesign toward shadcn-svelte dashboard-01 (inset sidebar, gradient stat cards)
Problem: requested visual alignment with the shadcn-svelte dashboard-01
reference block (shadcn-svelte.com/blocks#dashboard-01) — the app's
sidebar/header shell and Overview stat cards looked plain by comparison.

Change: pulled the actual reference source (app-sidebar.svelte,
nav-main.svelte, site-header.svelte, section-cards.svelte from
huntabyte/shadcn-svelte) rather than approximating from screenshots.

- App.svelte: Sidebar.Root now uses variant="inset" (the floating,
  rounded, shadowed content panel — already fully built into the
  existing Sidebar.Inset component via peer-data selectors, just never
  enabled). Brand mark is now a proper Sidebar.MenuButton matching the
  reference's padding/hover treatment; "New chat" uses the reference's
  primary-colored button styling. Header matches the reference exactly:
  h-(--header-height) (48px, was 44px), vertical separator after the
  sidebar trigger, right-aligned actions group.
- Overview.svelte: stat cards rebuilt to match section-cards.svelte —
  gradient background, Card.Action badge, Card.Footer with a bold line
  + muted context line, tabular-nums, responsive @container grid
  (1/2/4 columns). Deliberately did NOT copy the reference's fake
  trend-percentage badges (Oikos doesn't track historical trends, and
  this project's whole thrust has been eliminating dishonest UI state —
  see 279549c). Badges instead reflect real current-state signals
  (healthy/degraded/down, clear/needs-review) computed from the actual
  dashboard summary.
- EntityDetailContent.svelte + Entities/Signals/Ops/Events/Agent/
  Audit/Knowledge pages: normalized root padding to p-4 md:p-6 (was a
  flat p-6) to match the reference's responsive py-4 md:py-6 convention.

Risk: reversible_low (UI-only, no data or behavior changes).

Verification: npx tsc --noEmit clean (excluding pre-existing unrelated
.svelte type-resolution warnings, same as prior commits). go build/vet
clean (backend untouched, sanity check only). Manually verified in the
browser preview at 1400px: inset sidebar's margin/rounded-corner/shadow
classes confirmed applied via computed styles; Overview cards render
with real live numbers from the now-fixed dashboard summary endpoint;
Signals/Ops pages confirmed visually consistent with the new spacing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-09 00:54:51 +02:00

172 lines
5.8 KiB
Svelte

<script lang="ts">
import { onMount } from 'svelte'
import { fetchSignals, ackSignal, resolveSignal, muteSignal, type Signal } from '$lib/api'
import { liveEvents, subscribeEvents } from '$lib/stores/events'
import * as Tabs from '$lib/components/ui/tabs'
import * as Table from '$lib/components/ui/table'
import { Badge } from '$lib/components/ui/badge'
import { Button } from '$lib/components/ui/button'
import * as Select from '$lib/components/ui/select'
import { toast } from 'svelte-sonner'
let signals = $state<Signal[]>([])
let severityFilter = $state('all')
let acting = $state<string | null>(null)
async function load() {
signals = await fetchSignals()
}
onMount(() => {
load()
const unsubscribe = subscribeEvents()
return unsubscribe
})
$effect(() => {
const ev = $liveEvents[0]
if (!ev || !ev.type.startsWith('signal.')) return
load()
})
async function ack(id: string) {
acting = id
const result = await ackSignal(id)
acting = null
if (result) {
toast.success('Signal acknowledged')
load()
} else {
toast.error('Acknowledge failed')
}
}
async function resolve(id: string) {
acting = id
const result = await resolveSignal(id)
acting = null
if (result) {
toast.success('Signal resolved')
load()
} else {
toast.error('Resolve failed')
}
}
async function mute(id: string) {
acting = id
const muteUntil = new Date(Date.now() + 60 * 60 * 1000).toISOString()
const result = await muteSignal(id, muteUntil)
acting = null
if (result) {
toast.success('Signal muted for 1h')
load()
} else {
toast.error('Mute failed')
}
}
function severityVariant(sev: string): 'default' | 'secondary' | 'destructive' {
if (sev === 'critical') return 'destructive'
if (sev === 'warning') return 'secondary'
return 'default'
}
function bySeverity(list: Signal[]) {
return severityFilter === 'all' ? list : list.filter((s) => s.severity === severityFilter)
}
const open = $derived(bySeverity(signals.filter((s) => ['raised', 'acknowledged', 'acting'].includes(s.state))))
const muted = $derived(bySeverity(signals.filter((s) => s.state === 'muted')))
const resolved = $derived(bySeverity(signals.filter((s) => ['resolved', 'failed'].includes(s.state))))
</script>
{#snippet signalTable(list: Signal[], showActions: boolean)}
<div class="rounded-md border">
<Table.Root>
<Table.Header>
<Table.Row>
<Table.Head>Target</Table.Head>
<Table.Head>Kind</Table.Head>
<Table.Head>Severity</Table.Head>
<Table.Head>State</Table.Head>
<Table.Head>Occurrences</Table.Head>
<Table.Head>Last seen</Table.Head>
{#if showActions}
<Table.Head class="text-right">Actions</Table.Head>
{/if}
</Table.Row>
</Table.Header>
<Table.Body>
{#each list as signal (signal.id)}
<Table.Row>
<Table.Cell class="font-mono text-xs">{signal.target ?? '—'}</Table.Cell>
<Table.Cell>{signal.kind}</Table.Cell>
<Table.Cell><Badge variant={severityVariant(signal.severity)}>{signal.severity}</Badge></Table.Cell>
<Table.Cell><Badge variant="outline">{signal.state}</Badge></Table.Cell>
<Table.Cell>{signal.occurrence_count}</Table.Cell>
<Table.Cell class="text-xs text-muted-foreground"
>{new Date(signal.last_seen_at).toLocaleString()}</Table.Cell
>
{#if showActions}
<Table.Cell class="flex justify-end gap-2">
{#if signal.state === 'raised'}
<Button size="sm" variant="outline" disabled={acting === signal.id} onclick={() => ack(signal.id)}
>Ack</Button
>
{/if}
<Button size="sm" variant="outline" disabled={acting === signal.id} onclick={() => mute(signal.id)}
>Mute 1h</Button
>
<Button size="sm" disabled={acting === signal.id} onclick={() => resolve(signal.id)}>Resolve</Button>
</Table.Cell>
{/if}
</Table.Row>
{:else}
<Table.Row>
<Table.Cell colspan={showActions ? 7 : 6} class="text-center text-muted-foreground"
>No signals.</Table.Cell
>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
</div>
{/snippet}
<div class="flex h-full flex-col gap-4 p-4 md:p-6">
<div class="flex items-center justify-between">
<h1 class="text-lg font-semibold">Signals</h1>
<Select.Root type="single" bind:value={severityFilter}>
<Select.Trigger class="w-40">
{severityFilter === 'all' ? 'All severities' : severityFilter}
</Select.Trigger>
<Select.Content>
<Select.Item value="all">All severities</Select.Item>
<Select.Item value="critical">Critical</Select.Item>
<Select.Item value="warning">Warning</Select.Item>
<Select.Item value="info">Info</Select.Item>
</Select.Content>
</Select.Root>
</div>
<Tabs.Root value="open" class="flex flex-1 flex-col overflow-hidden">
<Tabs.List>
<Tabs.Trigger value="open">
Open {#if open.length}<Badge variant="destructive" class="ml-1">{open.length}</Badge>{/if}
</Tabs.Trigger>
<Tabs.Trigger value="muted">Muted</Tabs.Trigger>
<Tabs.Trigger value="resolved">Resolved</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="open" class="flex-1 overflow-auto">
{@render signalTable(open, true)}
</Tabs.Content>
<Tabs.Content value="muted" class="flex-1 overflow-auto">
{@render signalTable(muted, true)}
</Tabs.Content>
<Tabs.Content value="resolved" class="flex-1 overflow-auto">
{@render signalTable(resolved, false)}
</Tabs.Content>
</Tabs.Root>
</div>