Files
shared/media-webui/src/lib/components/StatusDialog.svelte
T

102 lines
3.6 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { AlertCircle, AlertTriangle, CheckCircle2, CircleHelp, LoaderCircle, RefreshCw, X } from '@lucide/svelte'
import Button from '$lib/components/ui/button.svelte'
import type { StatusProbe, StatusSnapshot } from '$lib/status'
let {
open = $bindable(false),
status,
onRefresh,
}: {
open?: boolean
status: StatusSnapshot
onRefresh: () => Promise<void>
} = $props()
const levelLabel = {
checking: 'Checking',
healthy: 'Healthy',
degraded: 'Degraded',
offline: 'Offline',
}
const levelClass = {
checking: 'text-muted-fg',
healthy: 'text-success',
degraded: 'text-warning',
offline: 'text-danger',
}
function probeLabel(probe: StatusProbe | null) {
if (!probe) return 'Not checked'
if (probe.ok) return 'OK'
if (probe.error) return probe.error
return probe.httpStatus ? `HTTP ${probe.httpStatus}` : 'Unavailable'
}
</script>
{#if open}
<div
class="fixed inset-0 z-50 grid place-items-center bg-black/70 px-4"
role="presentation"
onclick={(event) => event.target === event.currentTarget && (open = false)}
>
<div
class="w-full max-w-lg rounded-xl border border-border bg-bg p-6 text-fg shadow-2xl"
role="dialog"
aria-modal="true"
aria-labelledby="status-dialog-title"
>
<div class="mb-5 flex items-start justify-between gap-3">
<div>
<h2 id="status-dialog-title" class="text-xl font-semibold">Service status</h2>
<p class="mt-1 text-sm text-muted-fg">Live liveness and database readiness checks.</p>
</div>
<Button variant="ghost" size="icon" aria-label="Close" onclick={() => (open = false)}>
<X class="size-4" />
</Button>
</div>
<div class="mb-5 flex items-center gap-3 rounded-lg border border-border bg-surface p-3" aria-live="polite">
{#if status.loading && status.level === 'checking'}
<LoaderCircle class="size-5 animate-spin text-muted-fg" />
{:else if status.level === 'healthy'}
<CheckCircle2 class="size-5 text-success" />
{:else if status.level === 'degraded'}
<AlertTriangle class="size-5 text-warning" />
{:else if status.level === 'offline'}
<AlertCircle class="size-5 text-danger" />
{:else}
<CircleHelp class="size-5 text-muted-fg" />
{/if}
<span class={`font-medium ${levelClass[status.level]}`}>{levelLabel[status.level]}</span>
{#if status.checkedAt}
<span class="ml-auto text-xs text-muted-fg">{new Date(status.checkedAt).toLocaleTimeString()}</span>
{/if}
</div>
<div class="space-y-2 text-sm">
{#each [{ label: 'Liveness', probe: status.health }, { label: 'Readiness / database', probe: status.readiness }] as item (item.label)}
<div class="flex items-center justify-between gap-4 rounded-md border border-border px-3 py-2">
<span>{item.label}</span>
<span class={item.probe?.ok ? 'text-success' : 'text-danger'}>{probeLabel(item.probe)}</span>
</div>
{/each}
</div>
{#if status.health?.service || status.readiness?.service}
<p class="mt-4 text-xs text-muted-fg">
Service: {status.health?.service || status.readiness?.service}
</p>
{/if}
<div class="mt-6 flex justify-end gap-2">
<Button variant="outline" disabled={status.loading} onclick={() => void onRefresh()}>
<RefreshCw class={status.loading ? 'animate-spin' : ''} />
Refresh
</Button>
<Button variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
</div>
</div>
</div>
{/if}