72 lines
2.7 KiB
Svelte
72 lines
2.7 KiB
Svelte
<script lang="ts">
|
|
import { AlertCircle, AlertTriangle, CheckCircle2, CircleHelp, LoaderCircle, RefreshCw } from '@lucide/svelte';
|
|
import Button from './Button.svelte';
|
|
import Dialog from './Dialog.svelte';
|
|
import type { StatusProbe, StatusSnapshot } from '../types';
|
|
|
|
let {
|
|
onRefresh,
|
|
open = $bindable(false),
|
|
status
|
|
}: {
|
|
onRefresh: () => void | Promise<void>;
|
|
open?: boolean;
|
|
status: StatusSnapshot;
|
|
} = $props();
|
|
|
|
const levelLabel: Record<StatusSnapshot['level'], string> = {
|
|
checking: 'Checking',
|
|
healthy: 'Healthy',
|
|
degraded: 'Degraded',
|
|
offline: 'Offline'
|
|
};
|
|
|
|
function probeLabel(probe: StatusProbe | null): string {
|
|
if (!probe) return 'Not checked';
|
|
if (probe.ok) return 'OK';
|
|
if (probe.error) return probe.error;
|
|
return probe.httpStatus ? `HTTP ${probe.httpStatus}` : 'Unavailable';
|
|
}
|
|
</script>
|
|
|
|
<Dialog bind:open description="Live liveness and database readiness checks." title="Service status">
|
|
<div aria-live="polite" class="sc-status-summary" data-level={status.level}>
|
|
{#if status.loading && status.level === 'checking'}
|
|
<LoaderCircle aria-hidden="true" class="sc-status-icon sc-status-spin" size={20} />
|
|
{:else if status.level === 'healthy'}
|
|
<CheckCircle2 aria-hidden="true" class="sc-status-icon" size={20} />
|
|
{:else if status.level === 'degraded'}
|
|
<AlertTriangle aria-hidden="true" class="sc-status-icon" size={20} />
|
|
{:else if status.level === 'offline'}
|
|
<AlertCircle aria-hidden="true" class="sc-status-icon" size={20} />
|
|
{:else}
|
|
<CircleHelp aria-hidden="true" class="sc-status-icon" size={20} />
|
|
{/if}
|
|
<span class="sc-status-summary-label">{levelLabel[status.level]}</span>
|
|
{#if status.checkedAt}
|
|
<span class="sc-status-summary-time">{new Date(status.checkedAt).toLocaleTimeString()}</span>
|
|
{/if}
|
|
</div>
|
|
|
|
<div class="sc-status-probes">
|
|
{#each [{ label: 'Liveness', probe: status.health }, { label: 'Readiness / database', probe: status.readiness }] as item (item.label)}
|
|
<div class="sc-status-probe">
|
|
<span>{item.label}</span>
|
|
<span data-ok={item.probe?.ok ?? false}>{probeLabel(item.probe)}</span>
|
|
</div>
|
|
{/each}
|
|
</div>
|
|
|
|
{#if status.health?.service || status.readiness?.service}
|
|
<p class="sc-muted sc-status-service">Service: {status.health?.service || status.readiness?.service}</p>
|
|
{/if}
|
|
|
|
{#snippet footer()}
|
|
<Button disabled={status.loading} variant="outline" onclick={() => void onRefresh()}>
|
|
<RefreshCw aria-hidden="true" class={status.loading ? 'sc-status-spin' : ''} size={16} />
|
|
Refresh
|
|
</Button>
|
|
<Button variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
|
|
{/snippet}
|
|
</Dialog>
|