diff --git a/apps/web/src/builtin-widgets/tailscale-overview.widget.tsx b/apps/web/src/builtin-widgets/tailscale-overview.widget.tsx index 6a8d8b056..9bb711069 100644 --- a/apps/web/src/builtin-widgets/tailscale-overview.widget.tsx +++ b/apps/web/src/builtin-widgets/tailscale-overview.widget.tsx @@ -29,26 +29,29 @@ const ConfigSchema = z.object({ type TailscaleWidgetConfig = Infer +/** Unboxed reading: a quiet label over a large tabular number. */ function StatItem({ highlight, label, value }: { highlight?: boolean; label: string; value: string }) { return ( -
- {label} +
+ + {label} + {value} @@ -66,14 +69,13 @@ function TailscaleOverviewWidget({ config }: WidgetComponentProps -
- {config.title} +
+ {config.title} {data?.configured && ( 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-config-dialog.test.tsx b/apps/web/src/components/dashboard/widget-config-dialog.test.tsx index dc415f782..21db55135 100644 --- a/apps/web/src/components/dashboard/widget-config-dialog.test.tsx +++ b/apps/web/src/components/dashboard/widget-config-dialog.test.tsx @@ -292,7 +292,7 @@ describe('WidgetConfigDialog', () => { // Label + ColorPickerPopover trigger both surface the same string. expect(screen.getAllByText('Chart color').length).toBeGreaterThanOrEqual(1) // Trigger shows hex without the leading #. - expect(screen.getByText('8EC5FF')).toBeInTheDocument() + expect(screen.getByText('3E9EF0')).toBeInTheDocument() }) it('renders a chart color field for line-chart widgets', () => { 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/alert-list.tsx b/apps/web/src/components/dashboard/widgets/alert-list.tsx index 582dfcef4..9386eca94 100644 --- a/apps/web/src/components/dashboard/widgets/alert-list.tsx +++ b/apps/web/src/components/dashboard/widgets/alert-list.tsx @@ -1,10 +1,13 @@ import { useQuery } from '@tanstack/react-query' +import { CircleCheck } from 'lucide-react' import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import { DashboardCard } from '@/components/dashboard/dashboard-card' +import { WidgetHeader, WidgetMessage } from '@/components/dashboard/widget-chrome' import { ScrollArea } from '@/components/ui/scroll-area' import { api } from '@/lib/api-client' import type { ServerMetrics } from '@/lib/server-catalog' +import { cn } from '@/lib/utils' import { filterByIds, formatRelativeTime } from '@/lib/widget-helpers' import type { AlertListConfig } from '@/lib/widget-types' @@ -48,56 +51,71 @@ export function AlertListWidget({ config, servers }: AlertListWidgetProps) { if (!events) { return ( - -

{t('widgets.alertList.title')}

-
- {t('states.loading')} -
+ + + ) } + const firingCount = filtered.filter((event) => event.status === 'firing').length + return ( - -

{t('widgets.alertList.title')}

+ + 0 ? ( + + {t('widgets.alertList.firingCount', { count: firingCount })} + + ) : null + } + title={t('widgets.alertList.title')} + /> {filtered.length === 0 ? ( -
- {t('widgets.alertList.empty.noEvents')} -
+
diff --git a/apps/web/src/components/dashboard/widgets/disk-io.tsx b/apps/web/src/components/dashboard/widgets/disk-io.tsx index 23d98c6fe..50433351c 100644 --- a/apps/web/src/components/dashboard/widgets/disk-io.tsx +++ b/apps/web/src/components/dashboard/widgets/disk-io.tsx @@ -1,17 +1,23 @@ import { lazy, Suspense, useMemo } from 'react' import { useTranslation } from 'react-i18next' import { DashboardCard } from '@/components/dashboard/dashboard-card' +import { + WIDGET_PADDING_CLASS_NAME, + WidgetHeader, + WidgetMessage, + WidgetSkeleton +} from '@/components/dashboard/widget-chrome' import { Skeleton } from '@/components/ui/skeleton' import { useServerRecords } from '@/hooks/use-api' import { buildMergedDiskIoSeries } from '@/lib/disk-io' import type { ServerMetrics } from '@/lib/server-catalog' -import { formatSpeed } from '@/lib/utils' +import { cn, formatSpeed } from '@/lib/utils' import { DEFAULT_WIDGET_CHART_COLOR, DEFAULT_WIDGET_CHART_COLOR_SECONDARY, resolveWidgetColor } from '@/lib/widget-color' -import { formatChartTime } from '@/lib/widget-helpers' +import { formatChartTime, widgetRangeLabel } from '@/lib/widget-helpers' import type { DiskIoConfig } from '@/lib/widget-types' interface DiskIoWidgetProps { @@ -63,32 +69,25 @@ export function DiskIoWidget({ config, servers }: DiskIoWidgetProps) { ) if (isLoading) { - return ( - - - - - ) + return } + const header = ( + + ) + if (chartData.length === 0) { return ( - -

{t('widgets.diskIo.title')}

-

{serverName}

-
- {t('widgets.diskIo.empty.noData')} -
+ + {header} + ) } return ( - -
-

{t('widgets.diskIo.title')}

-

{serverName}

-
+ + {header}
}> - {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 = ( - <> -