From 2a56a166770811e7101d28dc3c101984fbbe6f8e Mon Sep 17 00:00:00 2001 From: ZingerLittleBee <6970999@gmail.com> Date: Thu, 26 Nov 2026 00:39:30 +0800 Subject: [PATCH 01/11] feat(web): add quiet widget chrome and borderless card surface Widgets share a quiet title row, large tabular readings with a muted unit, centered status messages and a loading skeleton. Cards drop the border for a hairline ring so spacing carries the hierarchy. --- .../components/dashboard/dashboard-card.tsx | 7 +- .../dashboard/module-widget-host.tsx | 8 +- .../components/dashboard/widget-chrome.tsx | 95 +++++++++++++++++++ .../components/dashboard/widget-renderer.tsx | 2 +- .../dashboard/widgets/server-cards.tsx | 8 +- apps/web/src/lib/widget-helpers.ts | 14 +++ apps/web/src/locales/en/dashboard.json | 5 + apps/web/src/locales/zh/dashboard.json | 4 + 8 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 apps/web/src/components/dashboard/widget-chrome.tsx diff --git a/apps/web/src/components/dashboard/dashboard-card.tsx b/apps/web/src/components/dashboard/dashboard-card.tsx index d715c273f..c50891028 100644 --- a/apps/web/src/components/dashboard/dashboard-card.tsx +++ b/apps/web/src/components/dashboard/dashboard-card.tsx @@ -1,7 +1,12 @@ import type { ComponentProps } from 'react' import { cn } from '@/lib/utils' -export const DASHBOARD_CARD_CLASS_NAME = 'min-w-0 rounded-xl border border-border/70 shadow-sm' +/** + * Borderless widget surface: a hairline ring plus a soft drop in light mode, + * a faint ring in dark mode. Layout rhythm comes from spacing, not borders. + */ +export const DASHBOARD_CARD_CLASS_NAME = + 'min-w-0 rounded-2xl shadow-[0_0_0_1px_rgb(0_0_0/0.06),0_1px_3px_rgb(0_0_0/0.05)] dark:shadow-[0_0_0_1px_rgb(255_255_255/0.07)]' export function DashboardCard({ className, ...props }: ComponentProps<'div'>) { return
diff --git a/apps/web/src/components/dashboard/module-widget-host.tsx b/apps/web/src/components/dashboard/module-widget-host.tsx index 39b21e809..3e8a3d558 100644 --- a/apps/web/src/components/dashboard/module-widget-host.tsx +++ b/apps/web/src/components/dashboard/module-widget-host.tsx @@ -2,8 +2,10 @@ import type { ActionsHelper } from '@serverbee/widget-sdk' import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import { DashboardCard } from '@/components/dashboard/dashboard-card' +import { WIDGET_PADDING_CLASS_NAME, WidgetHeader } from '@/components/dashboard/widget-chrome' import { ScrollArea } from '@/components/ui/scroll-area' import type { ServerMetrics } from '@/lib/server-catalog' +import { cn } from '@/lib/utils' import { parseConfig } from '@/lib/widget-helpers' import type { DashboardWidget } from '@/lib/widget-types' import { useWidgetRegistry } from '@/widgets-runtime/registry' @@ -19,7 +21,7 @@ const NOOP_ACTIONS: ActionsHelper = { function Placeholder({ message }: { message: string }) { return ( - + {message} ) @@ -63,8 +65,8 @@ export function ModuleWidgetHost({ widget, servers: _servers }: ModuleWidgetHost const Component = entry.module.component const title = widget.title || entry.manifest.name return ( - -
{title}
+ + +

+ {title} + {context ? · {context} : null} +

+ {aside ?
{aside}
: null} +
+ ) +} + +const VALUE_UNIT_RE = /^([+\-−]?\d[\d.,]*)(.*)$/ + +/** Split a formatted reading such as `75.3%` or `1.1 MB/s` into number and unit. */ +export function splitValueUnit(formatted: string): { unit: string; value: string } { + const match = VALUE_UNIT_RE.exec(formatted) + if (!match) { + return { value: formatted, unit: '' } + } + return { value: match[1], unit: match[2] } +} + +interface WidgetValueProps extends Omit, 'children'> { + /** Pre-formatted reading; a leading number keeps full size, the rest shrinks. */ + formatted: string + unitClassName?: string +} + +/** + * Large tabular reading with a de-emphasized unit. Size comes from the caller's + * `text-*` class; the unit scales with it. + */ +export function WidgetValue({ className, formatted, unitClassName, ...props }: WidgetValueProps) { + const { value, unit } = splitValueUnit(formatted) + return ( +

+ {value} + {unit ? ( + + {unit} + + ) : null} +

+ ) +} + +interface WidgetMessageProps { + className?: string + description?: ReactNode + icon?: ReactNode + title: ReactNode +} + +/** Centered empty / status message that states what the absence means. */ +export function WidgetMessage({ className, description, icon, title }: WidgetMessageProps) { + return ( +
+ {icon ?
{icon}
: null} +

{title}

+ {description ?

{description}

: null} +
+ ) +} + +/** Loading placeholder for chart widgets: a header line above the chart body. */ +export function WidgetSkeleton() { + return ( + + + + + ) +} diff --git a/apps/web/src/components/dashboard/widget-renderer.tsx b/apps/web/src/components/dashboard/widget-renderer.tsx index 2dde4cbf5..5d3e0ee0f 100644 --- a/apps/web/src/components/dashboard/widget-renderer.tsx +++ b/apps/web/src/components/dashboard/widget-renderer.tsx @@ -77,7 +77,7 @@ class WidgetErrorBoundary extends Component + Widget failed to render ) diff --git a/apps/web/src/components/dashboard/widgets/server-cards.tsx b/apps/web/src/components/dashboard/widgets/server-cards.tsx index c637a5e42..3fc882451 100644 --- a/apps/web/src/components/dashboard/widgets/server-cards.tsx +++ b/apps/web/src/components/dashboard/widgets/server-cards.tsx @@ -163,11 +163,9 @@ export function ServerCardsWidget({ config, servers }: ServerCardsWidgetProps) { // offline tiles match even when body sections differ.
diff --git a/apps/web/src/lib/widget-helpers.ts b/apps/web/src/lib/widget-helpers.ts index a1e3190ca..76b4f29da 100644 --- a/apps/web/src/lib/widget-helpers.ts +++ b/apps/web/src/lib/widget-helpers.ts @@ -30,6 +30,20 @@ export function metricLabel(metric: string, t: (key: string) => string): string return key ? t(key) : metric } +/** + * Compact history range for widget headers: `6h`, `24h`, `3 days`, or + * `Realtime` for the live (0 hour) network range. + */ +export function widgetRangeLabel(hours: number, t: (key: string, options?: Record) => string): string { + if (hours <= 0) { + return t('common.timeRange.realtime') + } + if (hours >= 48 && hours % 24 === 0) { + return t('widgets.common.range.days', { count: hours / 24 }) + } + return t('widgets.common.range.hours', { count: hours }) +} + export const METRIC_UNITS: Record = { cpu: '%', memory: '%', diff --git a/apps/web/src/locales/en/dashboard.json b/apps/web/src/locales/en/dashboard.json index 6803d81ff..636f61d5c 100644 --- a/apps/web/src/locales/en/dashboard.json +++ b/apps/web/src/locales/en/dashboard.json @@ -243,6 +243,11 @@ "desc": "Highest first", "asc": "Lowest first" }, + "range": { + "hours": "{{count}}h", + "days_one": "{{count}} day", + "days_other": "{{count}} days" + }, "hints": { "allServersWhenEmpty": "Leave empty to include all servers", "allMonitorsWhenEmpty": "Leave empty to include all monitors" diff --git a/apps/web/src/locales/zh/dashboard.json b/apps/web/src/locales/zh/dashboard.json index 2c2906e59..6fe69651d 100644 --- a/apps/web/src/locales/zh/dashboard.json +++ b/apps/web/src/locales/zh/dashboard.json @@ -243,6 +243,10 @@ "desc": "从高到低", "asc": "从低到高" }, + "range": { + "hours": "{{count}} 小时", + "days": "{{count}} 天" + }, "hints": { "allServersWhenEmpty": "留空表示包含所有服务器", "allMonitorsWhenEmpty": "留空表示包含所有监控项" From 664eed11fd76aae69f63d516306db864f6f8427e Mon Sep 17 00:00:00 2001 From: ZingerLittleBee <6970999@gmail.com> Date: Thu, 26 Nov 2026 00:39:39 +0800 Subject: [PATCH 02/11] feat(web): restyle stat number widget as a quiet reading Drop the icon tile and gradient; color the value only when it signals load or offline servers. --- .../dashboard/widgets/stat-number.test.tsx | 1 - .../dashboard/widgets/stat-number.tsx | 134 ++++++++---------- 2 files changed, 61 insertions(+), 74 deletions(-) diff --git a/apps/web/src/components/dashboard/widgets/stat-number.test.tsx b/apps/web/src/components/dashboard/widgets/stat-number.test.tsx index fbef30f45..e410faf99 100644 --- a/apps/web/src/components/dashboard/widgets/stat-number.test.tsx +++ b/apps/web/src/components/dashboard/widgets/stat-number.test.tsx @@ -79,7 +79,6 @@ describe('StatNumberWidget', () => { expect(screen.getByTestId('stat-number-label')).toHaveTextContent('Fleet Coverage') expect(screen.getByTestId('stat-number-value')).toHaveTextContent('1 / 2') expect(screen.getByTestId('stat-number-supporting')).toHaveTextContent('1 offline') - expect(screen.getByTestId('stat-number-icon-shell')).toBeInTheDocument() }) it('reports the offline count instead of a constant health word', () => { diff --git a/apps/web/src/components/dashboard/widgets/stat-number.tsx b/apps/web/src/components/dashboard/widgets/stat-number.tsx index 744502bd4..795041b4d 100644 --- a/apps/web/src/components/dashboard/widgets/stat-number.tsx +++ b/apps/web/src/components/dashboard/widgets/stat-number.tsx @@ -1,7 +1,8 @@ -import { Activity, Cpu, MemoryStick, Server, Wifi } from 'lucide-react' import { useTranslation } from 'react-i18next' import { DashboardCard } from '@/components/dashboard/dashboard-card' +import { WidgetValue } from '@/components/dashboard/widget-chrome' import type { ServerMetrics } from '@/lib/server-catalog' +import { getUtilizationTextColor } from '@/lib/utilization-colors' import { cn, formatBytes } from '@/lib/utils' import type { StatNumberConfig } from '@/lib/widget-types' @@ -11,90 +12,89 @@ interface StatNumberWidgetProps { title?: string | null } -const METRIC_ICONS: Record = { - server_count: Server, - avg_cpu: Cpu, - avg_memory: MemoryStick, - total_bandwidth: Wifi, - health: Activity +type StatTone = 'healthy' | 'danger' | null + +interface StatResult { + supporting: string + /** Status dot before the supporting line; null when the metric has no status. */ + tone: StatTone + value: string + /** Text color for the value; only set when the reading crosses a threshold. */ + valueClassName?: string } -const METRIC_STYLES: Record = { - server_count: { - icon: 'text-primary', - iconBg: 'bg-primary/10', - surface: 'border-border/70 bg-gradient-to-br from-primary/10 via-card to-card' - }, - avg_cpu: { - icon: 'text-chart-4', - iconBg: 'bg-chart-4/10', - surface: 'border-border/70 bg-gradient-to-br from-chart-4/10 via-card to-card' - }, - avg_memory: { - icon: 'text-chart-3', - iconBg: 'bg-chart-3/10', - surface: 'border-border/70 bg-gradient-to-br from-chart-3/12 via-card to-card' - }, - total_bandwidth: { - icon: 'text-chart-1', - iconBg: 'bg-chart-1/10', - surface: 'border-border/70 bg-gradient-to-br from-chart-1/10 via-card to-card' - }, - health: { - icon: 'text-chart-2', - iconBg: 'bg-chart-2/10', - surface: 'border-border/70 bg-gradient-to-br from-chart-2/12 via-card to-card' - } +const TONE_DOT_CLASS: Record, string> = { + healthy: 'bg-status-healthy', + danger: 'bg-status-danger' } function computeMetric( metric: string, servers: ServerMetrics[], t: (key: string, options?: Record) => string -): { supporting: string; value: string } { +): StatResult { const online = servers.filter((server) => server.online) const onlineCount = online.length const onlineSummary = t('servers_online', { online: onlineCount, total: servers.length }) + const fleetTone: StatTone = onlineCount === servers.length ? 'healthy' : 'danger' switch (metric) { case 'server_count': return { value: `${onlineCount} / ${servers.length}`, - supporting: t('offline_count', { count: servers.length - onlineCount }) + supporting: t('offline_count', { count: servers.length - onlineCount }), + tone: servers.length === 0 ? null : fleetTone } case 'avg_cpu': { if (onlineCount === 0) { - return { value: '0.0%', supporting: onlineSummary } + return { value: '0.0%', supporting: onlineSummary, tone: null } } const average = online.reduce((sum, server) => sum + server.cpu, 0) / onlineCount - return { value: `${average.toFixed(1)}%`, supporting: onlineSummary } + return { + value: `${average.toFixed(1)}%`, + supporting: onlineSummary, + tone: null, + valueClassName: getUtilizationTextColor(average) + } } case 'avg_memory': { if (onlineCount === 0) { - return { value: '0.0%', supporting: onlineSummary } + return { value: '0.0%', supporting: onlineSummary, tone: null } } const average = online.reduce((sum, server) => { return sum + (server.mem_total > 0 ? (server.mem_used / server.mem_total) * 100 : 0) }, 0) / onlineCount - return { value: `${average.toFixed(1)}%`, supporting: onlineSummary } + return { + value: `${average.toFixed(1)}%`, + supporting: onlineSummary, + tone: null, + valueClassName: getUtilizationTextColor(average) + } } case 'total_bandwidth': { - const total = online.reduce((sum, server) => sum + server.net_in_speed + server.net_out_speed, 0) - return { value: formatBytes(total), supporting: t('per_second') } + const inbound = online.reduce((sum, server) => sum + server.net_in_speed, 0) + const outbound = online.reduce((sum, server) => sum + server.net_out_speed, 0) + return { + value: `${formatBytes(inbound + outbound)}${t('per_second')}`, + supporting: `↓ ${formatBytes(inbound)} · ↑ ${formatBytes(outbound)}`, + tone: null + } } case 'health': { if (servers.length === 0) { - return { value: t('no_data'), supporting: onlineSummary } + return { value: t('no_data'), supporting: onlineSummary, tone: null } } const offlineCount = servers.length - onlineCount return { value: offlineCount === 0 ? t('healthy') : t('offline_count', { count: offlineCount }), - supporting: onlineSummary + supporting: onlineSummary, + tone: fleetTone, + valueClassName: offlineCount === 0 ? undefined : 'text-status-danger-text' } } default: - return { value: '--', supporting: onlineSummary } + return { value: '--', supporting: onlineSummary, tone: null } } } @@ -109,44 +109,32 @@ const METRIC_LABELS: Record = { export function StatNumberWidget({ config, servers, title }: StatNumberWidgetProps) { const { t } = useTranslation('dashboard') const { metric } = config - const Icon = METRIC_ICONS[metric] ?? Server - const metricStyles = METRIC_STYLES[metric] ?? METRIC_STYLES.server_count const result = computeMetric(metric, servers, t) const label = title ?? config.label ?? t(METRIC_LABELS[metric] ?? metric) return ( -
+ {label} +

+ +

- -

- -
-

- {label} -

-

- {result.value} -

-

- {result.supporting} -

-
+ {result.tone ? ( +
) } From 5a0aa9895da01cb59600f65b005aebc5c395b034 Mon Sep 17 00:00:00 2001 From: ZingerLittleBee <6970999@gmail.com> Date: Thu, 26 Nov 2026 00:39:39 +0800 Subject: [PATCH 03/11] feat(web): restyle metric card with a full-bleed area chart --- .../dashboard/widgets/metric-card.tsx | 72 ++++++++++--------- .../widgets/metric-card/metric-card-config.ts | 15 +--- .../metric-card/metric-card-header.tsx | 26 ------- .../widgets/metric-card/metric-card-stats.tsx | 32 --------- .../widgets/metric-card/metric-card-value.tsx | 55 +++++--------- apps/web/src/locales/en/dashboard.json | 4 +- apps/web/src/locales/zh/dashboard.json | 4 +- 7 files changed, 65 insertions(+), 143 deletions(-) delete mode 100644 apps/web/src/components/dashboard/widgets/metric-card/metric-card-header.tsx delete mode 100644 apps/web/src/components/dashboard/widgets/metric-card/metric-card-stats.tsx diff --git a/apps/web/src/components/dashboard/widgets/metric-card.tsx b/apps/web/src/components/dashboard/widgets/metric-card.tsx index ee9228c35..909689d1c 100644 --- a/apps/web/src/components/dashboard/widgets/metric-card.tsx +++ b/apps/web/src/components/dashboard/widgets/metric-card.tsx @@ -1,17 +1,16 @@ import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import { DashboardCard } from '@/components/dashboard/dashboard-card' +import { WidgetHeader, WidgetMessage, WidgetValue } from '@/components/dashboard/widget-chrome' import { useServerRecords } from '@/hooks/use-api' import { useMetricSeries } from '@/hooks/use-metric-series' import type { ServerMetrics } from '@/lib/server-catalog' import { cn } from '@/lib/utils' import { normalizeWidgetColor } from '@/lib/widget-color' import type { MetricCardConfig } from '@/lib/widget-types' -import { METRIC_CARD_SPECS } from './metric-card/metric-card-config' -import { MetricCardHeader } from './metric-card/metric-card-header' +import { METRIC_CARD_ACCENT, METRIC_CARD_SPECS } from './metric-card/metric-card-config' import { MetricCardSparkline } from './metric-card/metric-card-sparkline' -import { MetricCardStats } from './metric-card/metric-card-stats' -import { MetricCardValue } from './metric-card/metric-card-value' +import { MetricCardDelta } from './metric-card/metric-card-value' interface MetricCardWidgetProps { config: MetricCardConfig @@ -38,22 +37,16 @@ export function MetricCardWidget({ config, servers }: MetricCardWidgetProps) { if (!spec) { return ( - - {t('metricCard.unknownMetric')} + + ) } if (!server) { return ( - - {t('metricCard.unknownServer')} + + ) } @@ -63,33 +56,46 @@ export function MetricCardWidget({ config, servers }: MetricCardWidgetProps) { const formattedValue = dimmed ? '—' : spec.formatValue(series.current) const formattedPeak = formatStat(series.peak, spec.formatValue) const formattedAvg = formatStat(series.avg, spec.formatValue) - // Custom hex wins; otherwise keep the metric's CSS-variable accent token. - const customColor = normalizeWidgetColor(config.color) - const accent = customColor ?? `var(${spec.accent})` + // A custom hex wins; otherwise every metric uses the shared accent. + const accent = normalizeWidgetColor(config.color) ?? METRIC_CARD_ACCENT return ( - - -
+
+ + +
+ +

+ {t('metricCard.peak')}{' '} + + {formattedPeak} + + {' · '} + {t('metricCard.avg')}{' '} + + {formattedAvg} + +

+
+
+ {/* Full-bleed: the trend runs to the card edges so the reading above stays the focus. */} +
- ) } diff --git a/apps/web/src/components/dashboard/widgets/metric-card/metric-card-config.ts b/apps/web/src/components/dashboard/widgets/metric-card/metric-card-config.ts index ecb220ce9..8fb400eba 100644 --- a/apps/web/src/components/dashboard/widgets/metric-card/metric-card-config.ts +++ b/apps/web/src/components/dashboard/widgets/metric-card/metric-card-config.ts @@ -1,5 +1,3 @@ -import type { LucideIcon } from 'lucide-react' -import { Cpu, HardDriveDownload, MemoryStick, Network } from 'lucide-react' import { formatSpeed } from '@/lib/utils' import type { MetricCardMetric } from '@/lib/widget-types' @@ -7,44 +5,37 @@ export type DeltaUnit = 'pp' | 'percent' export type DeltaTone = 'semantic' | 'neutral' export interface MetricCardSpec { - accent: string deltaTone: DeltaTone deltaUnit: DeltaUnit formatValue: (n: number) => string - icon: LucideIcon labelKey: string } +/** Every metric shares one accent; status colors are reserved for the delta. */ +export const METRIC_CARD_ACCENT = 'var(--chart-1)' + const formatPercent = (n: number) => `${n.toFixed(1)}%` export const METRIC_CARD_SPECS: Record = { cpu: { - icon: Cpu, - accent: '--chart-4', formatValue: formatPercent, deltaUnit: 'pp', deltaTone: 'semantic', labelKey: 'metricCard.metric.cpu' }, memory: { - icon: MemoryStick, - accent: '--chart-3', formatValue: formatPercent, deltaUnit: 'pp', deltaTone: 'semantic', labelKey: 'metricCard.metric.memory' }, network: { - icon: Network, - accent: '--chart-1', formatValue: formatSpeed, deltaUnit: 'percent', deltaTone: 'neutral', labelKey: 'metricCard.metric.network' }, disk_io: { - icon: HardDriveDownload, - accent: '--chart-2', formatValue: formatSpeed, deltaUnit: 'percent', deltaTone: 'neutral', diff --git a/apps/web/src/components/dashboard/widgets/metric-card/metric-card-header.tsx b/apps/web/src/components/dashboard/widgets/metric-card/metric-card-header.tsx deleted file mode 100644 index 2b2353069..000000000 --- a/apps/web/src/components/dashboard/widgets/metric-card/metric-card-header.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import type { LucideIcon } from 'lucide-react' -import { cn } from '@/lib/utils' - -interface MetricCardHeaderProps { - accent: string - Icon: LucideIcon - label: string - serverName: string -} - -/** `accent` is a full CSS color (`#RRGGBB` or `var(--chart-1)`). */ -export function MetricCardHeader({ Icon, label, serverName, accent }: MetricCardHeaderProps) { - return ( -
-
- -
- {label} - {serverName} -
- ) -} diff --git a/apps/web/src/components/dashboard/widgets/metric-card/metric-card-stats.tsx b/apps/web/src/components/dashboard/widgets/metric-card/metric-card-stats.tsx deleted file mode 100644 index 5a9da7267..000000000 --- a/apps/web/src/components/dashboard/widgets/metric-card/metric-card-stats.tsx +++ /dev/null @@ -1,32 +0,0 @@ -interface StatProps { - caption: string - kind: 'peak' | 'avg' - value: string -} - -function Stat({ caption, kind, value }: StatProps) { - return ( -
-

{caption}

-

- {value} -

-
- ) -} - -interface MetricCardStatsProps { - avg: string - avgCaption: string - peak: string - peakCaption: string -} - -export function MetricCardStats({ peakCaption, avgCaption, peak, avg }: MetricCardStatsProps) { - return ( -
- - -
- ) -} diff --git a/apps/web/src/components/dashboard/widgets/metric-card/metric-card-value.tsx b/apps/web/src/components/dashboard/widgets/metric-card/metric-card-value.tsx index cf74bb671..8df834790 100644 --- a/apps/web/src/components/dashboard/widgets/metric-card/metric-card-value.tsx +++ b/apps/web/src/components/dashboard/widgets/metric-card/metric-card-value.tsx @@ -1,12 +1,10 @@ -import { TrendingDown, TrendingUp } from 'lucide-react' import { cn } from '@/lib/utils' import type { DeltaTone, DeltaUnit } from './metric-card-config' -interface MetricCardValueProps { +interface MetricCardDeltaProps { delta: number | null deltaTone: DeltaTone deltaUnit: DeltaUnit - formattedValue: string pastLabel: string } @@ -19,42 +17,27 @@ function formatDelta(delta: number, unit: DeltaUnit): string { return `${sign}${magnitude.toFixed(0)}%` } -function deltaColor(delta: number, tone: DeltaTone): string { - if (tone === 'neutral') { - return 'text-muted-foreground' +/** Rising utilization reads as a warning; falling reads as relief. Throughput stays neutral. */ +function deltaPillClass(delta: number, tone: DeltaTone): string { + if (tone === 'neutral' || delta === 0) { + return 'bg-muted text-muted-foreground' } - if (delta === 0) { - return 'text-muted-foreground' - } - return delta > 0 ? 'text-destructive' : 'text-emerald-500' + return delta > 0 ? 'bg-status-warning/15 text-status-warning-text' : 'bg-status-healthy/15 text-status-healthy-text' } -export function MetricCardValue({ formattedValue, delta, deltaUnit, deltaTone, pastLabel }: MetricCardValueProps) { +export function MetricCardDelta({ delta, deltaUnit, deltaTone, pastLabel }: MetricCardDeltaProps) { return ( -
-

- {formattedValue} -

-

- {delta === null ? ( - — - ) : ( - <> - {delta < 0 ? : } - {formatDelta(delta, deltaUnit)} - - )} - · {pastLabel} -

-
+

+ {delta === null ? ( + — + ) : ( + + {delta > 0 ? '▲ ' : ''} + {delta < 0 ? '▼ ' : ''} + {formatDelta(delta, deltaUnit)} + + )} + {pastLabel} +

) } diff --git a/apps/web/src/locales/en/dashboard.json b/apps/web/src/locales/en/dashboard.json index 636f61d5c..4b02449ea 100644 --- a/apps/web/src/locales/en/dashboard.json +++ b/apps/web/src/locales/en/dashboard.json @@ -334,8 +334,8 @@ "diskIo": "Disk I/O" }, "past1h": "past 1h", - "peak": "24H PEAK", - "avg": "24H AVG", + "peak": "Peak", + "avg": "Avg", "unknownServer": "Unknown server", "unknownMetric": "Metric not configured" }, diff --git a/apps/web/src/locales/zh/dashboard.json b/apps/web/src/locales/zh/dashboard.json index 6fe69651d..f2472696f 100644 --- a/apps/web/src/locales/zh/dashboard.json +++ b/apps/web/src/locales/zh/dashboard.json @@ -333,8 +333,8 @@ "diskIo": "磁盘 I/O" }, "past1h": "过去 1 小时", - "peak": "24H 峰值", - "avg": "24H 均值", + "peak": "峰值", + "avg": "均值", "unknownServer": "未知服务器", "unknownMetric": "未配置指标" }, From afc179ae145bc2eaf75c2eade9915251c25d65bf Mon Sep 17 00:00:00 2001 From: ZingerLittleBee <6970999@gmail.com> Date: Thu, 26 Nov 2026 00:39:39 +0800 Subject: [PATCH 04/11] feat(web): restyle gauge as a thin ring with a severity word --- .../components/dashboard/widgets/gauge.tsx | 124 ++++++++---------- apps/web/src/locales/en/dashboard.json | 6 + apps/web/src/locales/zh/dashboard.json | 6 + 3 files changed, 65 insertions(+), 71 deletions(-) diff --git a/apps/web/src/components/dashboard/widgets/gauge.tsx b/apps/web/src/components/dashboard/widgets/gauge.tsx index 1e4af1212..ee4e3e014 100644 --- a/apps/web/src/components/dashboard/widgets/gauge.tsx +++ b/apps/web/src/components/dashboard/widgets/gauge.tsx @@ -1,9 +1,10 @@ -import { Activity, Cpu, Gauge as GaugeIcon, HardDrive, MemoryStick, Network } from 'lucide-react' import { useId, useMemo } from 'react' import { useTranslation } from 'react-i18next' import { DashboardCard } from '@/components/dashboard/dashboard-card' +import { splitValueUnit, WidgetMessage } from '@/components/dashboard/widget-chrome' import type { ServerMetrics } from '@/lib/server-catalog' -import { getUtilizationRingColor } from '@/lib/utilization-colors' +import { getUtilizationRingColor, getUtilizationSeverity } from '@/lib/utilization-colors' +import { cn } from '@/lib/utils' import { normalizeWidgetColor } from '@/lib/widget-color' import { extractLiveMetric, metricLabel } from '@/lib/widget-helpers' import type { GaugeConfig } from '@/lib/widget-types' @@ -19,7 +20,7 @@ const CENTER = VIEWBOX / 2 // Radius pushes the ring close to the viewBox edge so the gauge fills the // card; clamped so the round linecap (STROKE/2 outward) still fits inside. const RADIUS = 44 -const STROKE = 8 +const STROKE = 6 // 270° sweep, gap centered at bottom. Angles in degrees, clockwise from 12 o'clock. // Start at 7:30 (225°), sweep clockwise past 9, 12, 3 to 4:30 (135°), leaving a // 90° gap centered at 6 o'clock — matches the reference horseshoe orientation. @@ -41,28 +42,6 @@ function getGaugeGradient(value: number, overrideColor?: string): Gradient { return { start: color, end: color } } -function getMetricIcon(metric: string) { - switch (metric) { - case 'cpu': - return Cpu - case 'memory': - case 'swap': - return MemoryStick - case 'disk': - return HardDrive - case 'load1': - case 'load5': - case 'load15': - return Activity - case 'net_in': - case 'net_out': - case 'bandwidth': - return Network - default: - return GaugeIcon - } -} - // Convert a polar coordinate (angle in degrees, clockwise from 12 o'clock) to cartesian SVG coords. function polarToCartesian(cx: number, cy: number, r: number, angleDeg: number) { const angleRad = ((angleDeg - 90) * Math.PI) / 180 @@ -100,15 +79,18 @@ export function GaugeWidget({ config, servers }: GaugeWidgetProps) { if (!server) { return ( - - {t('widgets.common.empty.serverNotFound')} + + ) } const label = config.label ?? metricLabel(metric, t) const gradient = getGaugeGradient(value, config.color) - const Icon = getMetricIcon(metric) + const percent = max > 0 ? (value / max) * 100 : 0 + const severity = getUtilizationSeverity(percent) + const reading = splitValueUnit(`${value.toFixed(1)}%`) + const [whole, fraction = ''] = reading.value.split('.') const progressSweep = max > 0 ? (value / max) * SWEEP : 0 const trackEnd = START_ANGLE + SWEEP @@ -119,46 +101,10 @@ export function GaugeWidget({ config, servers }: GaugeWidgetProps) { const showProgress = value > 0 - const mainText = ( - <> -