Refactor server dashboard pages with reusable UI blocks.
Publish telemt-api gateway Docker image / test (push) Successful in 27s
Publish telemt-api gateway Docker image / build-and-push (push) Successful in 2m28s

Extract shared header, query-state, and JSON panel components, then apply them across server runtime/security/upstreams/update/config views for consistent Telemt panel UX.

Made-with: Cursor
This commit is contained in:
Denozordec
2026-04-09 23:00:01 +07:00
parent e1f16799ba
commit 5564ab8a62
8 changed files with 217 additions and 122 deletions
@@ -0,0 +1,40 @@
<script lang="ts">
import type { Snippet } from 'svelte';
import type { KpiAccentKey } from '$lib/kpi-accents.js';
import KpiPanelCard from '$lib/components/kpi-panel-card.svelte';
import BracesIcon from '@lucide/svelte/icons/braces';
let {
title,
description,
accent = 'info',
payload,
class: className,
preClass = 'max-h-[70vh]',
iconSnippet
}: {
title: string;
description?: string;
accent?: KpiAccentKey;
payload: unknown;
class?: string;
preClass?: string;
iconSnippet?: Snippet;
} = $props();
</script>
<KpiPanelCard {accent} {title} {description} class={className} contentClass="p-0">
{#snippet icon()}
{#if iconSnippet}
{@render iconSnippet()}
{:else}
<BracesIcon class="size-5" aria-hidden="true" />
{/if}
{/snippet}
<pre
class={[
preClass,
'overflow-auto rounded-md border border-border bg-muted/40 p-4 text-xs leading-relaxed'
]}
>{JSON.stringify(payload, null, 2)}</pre>
</KpiPanelCard>
@@ -0,0 +1,39 @@
<script lang="ts">
import type { Snippet } from 'svelte';
import { Button } from '$lib/components/ui/button/index.js';
import RefreshCwIcon from '@lucide/svelte/icons/refresh-cw';
let {
title,
subtitle,
loading = false,
showRefresh = true,
onRefresh,
actions
}: {
title: string;
subtitle?: string;
loading?: boolean;
showRefresh?: boolean;
onRefresh?: () => void | Promise<void>;
actions?: Snippet;
} = $props();
</script>
<div class="mb-6 flex flex-wrap items-center justify-between gap-4">
<div class="space-y-1">
<h1 class="text-2xl font-semibold tracking-tight">{title}</h1>
{#if subtitle}
<p class="text-sm text-muted-foreground">{subtitle}</p>
{/if}
</div>
<div class="flex items-center gap-2">
{@render actions?.()}
{#if showRefresh}
<Button variant="outline" size="sm" onclick={onRefresh} disabled={loading || !onRefresh}>
<RefreshCwIcon class={['mr-1 size-4', loading && 'animate-spin']} />
Обновить
</Button>
{/if}
</div>
</div>
@@ -0,0 +1,62 @@
<script lang="ts">
import type { Snippet } from 'svelte';
import { Alert, AlertDescription, AlertTitle } from '$lib/components/ui/alert/index.js';
import KpiPanelCard from '$lib/components/kpi-panel-card.svelte';
import LoaderCircleIcon from '@lucide/svelte/icons/loader-circle';
import InboxIcon from '@lucide/svelte/icons/inbox';
let {
loading = false,
err = null,
isEmpty = false,
loadingTitle = 'Загрузка данных',
loadingDescription = 'Пожалуйста, подождите...',
emptyTitle = 'Нет данных',
emptyDescription = 'По этому endpoint пока нет содержимого.',
children
}: {
loading?: boolean;
err?: string | null;
isEmpty?: boolean;
loadingTitle?: string;
loadingDescription?: string;
emptyTitle?: string;
emptyDescription?: string;
children?: Snippet;
} = $props();
</script>
{#if err}
<Alert variant="destructive" class="mb-4">
<AlertTitle>Ошибка</AlertTitle>
<AlertDescription>{err}</AlertDescription>
</Alert>
{/if}
{#if loading}
<KpiPanelCard
accent="neutral"
title={loadingTitle}
description={loadingDescription}
contentClass="pt-0 text-sm text-muted-foreground"
>
{#snippet icon()}
<LoaderCircleIcon class="size-5 animate-spin" aria-hidden="true" />
{/snippet}
Идет запрос к ноде, обновляем показатели dashboard.
</KpiPanelCard>
{:else if !err && isEmpty}
<KpiPanelCard
accent="neutral"
title={emptyTitle}
description={emptyDescription}
contentClass="pt-0 text-sm text-muted-foreground"
>
{#snippet icon()}
<InboxIcon class="size-5" aria-hidden="true" />
{/snippet}
Проверьте параметры запроса или состояние сервера.
</KpiPanelCard>
{:else if !loading && !isEmpty}
{@render children?.()}
{/if}
@@ -1,22 +1,25 @@
<script lang="ts">
import { page } from '$app/state';
import KpiPanelCard from '$lib/components/kpi-panel-card.svelte';
import ServerPageHeader from '$lib/components/server-page-header.svelte';
import SettingsIcon from '@lucide/svelte/icons/settings';
const alias = $derived(page.params.alias ?? '');
</script>
<div class="mb-6">
<h1 class="mb-2 text-2xl font-semibold tracking-tight">Configuration</h1>
<p class="text-sm text-muted-foreground">
Конфигурация Telemt на ноде <span class="font-mono text-foreground">{alias}</span> не доступна через API
— правьте <code class="rounded bg-muted px-1">config.toml</code> на сервере.
</p>
</div>
<ServerPageHeader
title="Configuration"
subtitle="Конфигурация этой ноды не отдается через Control API"
showRefresh={false}
/>
<KpiPanelCard accent="neutral" title="Конфигурация" description="Настройка на сервере" contentClass="text-sm text-muted-foreground">
{#snippet icon()}
<SettingsIcon class="size-5" aria-hidden="true" />
{/snippet}
<p class="mb-2">
Конфигурация Telemt на ноде <span class="font-mono text-foreground">{alias}</span> не доступна через API.
Правьте <code class="rounded bg-muted px-1">config.toml</code> на сервере.
</p>
См. <a
class="text-primary underline"
href="https://github.com/telemt/telemt/blob/main/docs/API.md"
@@ -3,13 +3,14 @@
import { ApiError, fetchTelemt } from '$lib/api/client.js';
import type { DcStatusData, RuntimeGatesData } from '$lib/api/telemt-v1.js';
import KpiPanelCard from '$lib/components/kpi-panel-card.svelte';
import ServerPageHeader from '$lib/components/server-page-header.svelte';
import ServerQueryState from '$lib/components/server-query-state.svelte';
import ServerJsonCard from '$lib/components/server-json-card.svelte';
import BuildingIcon from '@lucide/svelte/icons/building-2';
import BracesIcon from '@lucide/svelte/icons/braces';
import { Alert, AlertDescription, AlertTitle } from '$lib/components/ui/alert/index.js';
import { Alert, AlertDescription } from '$lib/components/ui/alert/index.js';
import { Badge } from '$lib/components/ui/badge/index.js';
import { Button } from '$lib/components/ui/button/index.js';
import * as Table from '$lib/components/ui/table/index.js';
import RefreshCwIcon from '@lucide/svelte/icons/refresh-cw';
const alias = $derived(page.params.alias ?? '');
@@ -56,22 +57,10 @@
}
</script>
<div class="mb-6 flex items-center justify-between">
<h1 class="text-2xl font-semibold tracking-tight">Runtime</h1>
<Button variant="outline" size="sm" onclick={load} disabled={loading}>
<RefreshCwIcon class="mr-1 size-4 {loading ? 'animate-spin' : ''}" />
Обновить
</Button>
</div>
<ServerPageHeader title="Runtime" {loading} onRefresh={load} />
{#if err}
<Alert variant="destructive">
<AlertTitle>Ошибка</AlertTitle>
<AlertDescription>{err}</AlertDescription>
</Alert>
{:else if loading}
<p class="text-muted-foreground">Загрузка…</p>
{:else}
<ServerQueryState {loading} {err} isEmpty={false}>
{#snippet children()}
<div class="mb-4 flex flex-wrap gap-2">
{#if gates}
<Badge variant="secondary" class="px-3 py-1">accepting: {onOff(gates.accepting_new_connections)}</Badge>
@@ -118,14 +107,10 @@
</Alert>
{/if}
<KpiPanelCard accent="violet" title="ME pool state" description="Сырой JSON" contentClass="">
{#snippet icon()}
<ServerJsonCard accent="violet" title="ME pool state" description="Сырой JSON" payload={pool} preClass="max-h-[480px]">
{#snippet iconSnippet()}
<BracesIcon class="size-5" aria-hidden="true" />
{/snippet}
<pre class="max-h-[480px] overflow-auto rounded-md border border-border bg-muted/40 p-3 text-xs">{JSON.stringify(
pool,
null,
2
)}</pre>
</KpiPanelCard>
{/if}
</ServerJsonCard>
{/snippet}
</ServerQueryState>
@@ -1,11 +1,10 @@
<script lang="ts">
import { page } from '$app/state';
import { ApiError, fetchTelemt } from '$lib/api/client.js';
import KpiPanelCard from '$lib/components/kpi-panel-card.svelte';
import ServerPageHeader from '$lib/components/server-page-header.svelte';
import ServerQueryState from '$lib/components/server-query-state.svelte';
import ServerJsonCard from '$lib/components/server-json-card.svelte';
import ShieldIcon from '@lucide/svelte/icons/shield';
import { Alert, AlertDescription, AlertTitle } from '$lib/components/ui/alert/index.js';
import { Button } from '$lib/components/ui/button/index.js';
import RefreshCwIcon from '@lucide/svelte/icons/refresh-cw';
const alias = $derived(page.params.alias ?? '');
@@ -39,30 +38,16 @@
}
</script>
<div class="mb-6 flex items-center justify-between">
<h1 class="text-2xl font-semibold tracking-tight">Security</h1>
<Button variant="outline" size="sm" onclick={load} disabled={loading}>
<RefreshCwIcon class="mr-1 size-4 {loading ? 'animate-spin' : ''}" />
Обновить
</Button>
</div>
<ServerPageHeader title="Security" {loading} onRefresh={load} />
{#if err}
<Alert variant="destructive">
<AlertTitle>Ошибка</AlertTitle>
<AlertDescription>{err}</AlertDescription>
</Alert>
{:else if loading}
<p class="text-muted-foreground">Загрузка…</p>
{:else if data}
<KpiPanelCard accent="danger" title="Security posture" description="POST /security/posture" contentClass="p-0">
{#snippet icon()}
<ShieldIcon class="size-5" aria-hidden="true" />
{/snippet}
<pre class="overflow-auto rounded-md border border-border bg-muted/40 p-4 text-xs">{JSON.stringify(
data,
null,
2
)}</pre>
</KpiPanelCard>
{/if}
<ServerQueryState {loading} {err} isEmpty={!data} emptyDescription="Endpoint вернул пустой ответ.">
{#snippet children()}
{#if data}
<ServerJsonCard accent="danger" title="Security posture" description="POST /security/posture" payload={data}>
{#snippet iconSnippet()}
<ShieldIcon class="size-5" aria-hidden="true" />
{/snippet}
</ServerJsonCard>
{/if}
{/snippet}
</ServerQueryState>
@@ -3,10 +3,9 @@
import { ApiError, fetchTelemt } from '$lib/api/client.js';
import type { SystemInfoData } from '$lib/api/telemt-v1.js';
import KpiPanelCard from '$lib/components/kpi-panel-card.svelte';
import ServerPageHeader from '$lib/components/server-page-header.svelte';
import ServerQueryState from '$lib/components/server-query-state.svelte';
import PackageIcon from '@lucide/svelte/icons/package';
import { Alert, AlertDescription, AlertTitle } from '$lib/components/ui/alert/index.js';
import { Button } from '$lib/components/ui/button/index.js';
import RefreshCwIcon from '@lucide/svelte/icons/refresh-cw';
const alias = $derived(page.params.alias ?? '');
@@ -40,29 +39,20 @@
}
</script>
<div class="mb-6 flex items-center justify-between">
<h1 class="text-2xl font-semibold tracking-tight">Update</h1>
<Button variant="outline" size="sm" onclick={load} disabled={loading}>
<RefreshCwIcon class="mr-1 size-4 {loading ? 'animate-spin' : ''}" />
Обновить
</Button>
</div>
<ServerPageHeader title="Update" {loading} onRefresh={load} />
{#if err}
<Alert variant="destructive">
<AlertTitle>Ошибка</AlertTitle>
<AlertDescription>{err}</AlertDescription>
</Alert>
{:else if loading}
<p class="text-muted-foreground">Загрузка…</p>
{:else if sys}
<KpiPanelCard accent="teal" title="Версия бинарника" description="system/info" contentClass="space-y-2 text-sm">
{#snippet icon()}
<PackageIcon class="size-5" aria-hidden="true" />
{/snippet}
<p><span class="text-muted-foreground">version</span> {sys.version}</p>
<p><span class="text-muted-foreground">git</span> {sys.git_commit ?? '—'}</p>
<p><span class="text-muted-foreground">build</span> {sys.build_time_utc ?? '—'}</p>
<p><span class="text-muted-foreground">rustc</span> {sys.rustc_version ?? '—'}</p>
</KpiPanelCard>
{/if}
<ServerQueryState {loading} {err} isEmpty={!sys} emptyDescription="Информация о бинарнике не получена.">
{#snippet children()}
{#if sys}
<KpiPanelCard accent="teal" title="Версия бинарника" description="system/info" contentClass="space-y-2 text-sm">
{#snippet icon()}
<PackageIcon class="size-5" aria-hidden="true" />
{/snippet}
<p><span class="text-muted-foreground">version</span> {sys.version}</p>
<p><span class="text-muted-foreground">git</span> {sys.git_commit ?? '—'}</p>
<p><span class="text-muted-foreground">build</span> {sys.build_time_utc ?? '—'}</p>
<p><span class="text-muted-foreground">rustc</span> {sys.rustc_version ?? '—'}</p>
</KpiPanelCard>
{/if}
{/snippet}
</ServerQueryState>
@@ -1,11 +1,10 @@
<script lang="ts">
import { page } from '$app/state';
import { ApiError, fetchTelemt } from '$lib/api/client.js';
import KpiPanelCard from '$lib/components/kpi-panel-card.svelte';
import ServerPageHeader from '$lib/components/server-page-header.svelte';
import ServerQueryState from '$lib/components/server-query-state.svelte';
import ServerJsonCard from '$lib/components/server-json-card.svelte';
import Share2Icon from '@lucide/svelte/icons/share-2';
import { Alert, AlertDescription, AlertTitle } from '$lib/components/ui/alert/index.js';
import { Button } from '$lib/components/ui/button/index.js';
import RefreshCwIcon from '@lucide/svelte/icons/refresh-cw';
const alias = $derived(page.params.alias ?? '');
@@ -39,30 +38,22 @@
}
</script>
<div class="mb-6 flex items-center justify-between">
<h1 class="text-2xl font-semibold tracking-tight">Upstreams &amp; DCs</h1>
<Button variant="outline" size="sm" onclick={load} disabled={loading}>
<RefreshCwIcon class="mr-1 size-4 {loading ? 'animate-spin' : ''}" />
Обновить
</Button>
</div>
<ServerPageHeader title="Upstreams &amp; DCs" {loading} onRefresh={load} />
{#if err}
<Alert variant="destructive">
<AlertTitle>Ошибка</AlertTitle>
<AlertDescription>{err}</AlertDescription>
</Alert>
{:else if loading}
<p class="text-muted-foreground">Загрузка…</p>
{:else if data}
<KpiPanelCard accent="info" title="Upstreams &amp; DCs" description="stats/upstreams" contentClass="p-0">
{#snippet icon()}
<Share2Icon class="size-5" aria-hidden="true" />
{/snippet}
<pre class="max-h-[70vh] overflow-auto rounded-md border border-border bg-muted/40 p-4 text-xs">{JSON.stringify(
data,
null,
2
)}</pre>
</KpiPanelCard>
{/if}
<ServerQueryState {loading} {err} isEmpty={!data} emptyDescription="Статистика upstream-ов пока не доступна.">
{#snippet children()}
{#if data}
<ServerJsonCard
accent="info"
title="Upstreams &amp; DCs"
description="stats/upstreams"
payload={data}
preClass="max-h-[70vh]"
>
{#snippet iconSnippet()}
<Share2Icon class="size-5" aria-hidden="true" />
{/snippet}
</ServerJsonCard>
{/if}
{/snippet}
</ServerQueryState>