Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions apps/web/src/builtin-widgets/tailscale-overview.widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,29 @@ const ConfigSchema = z.object({

type TailscaleWidgetConfig = Infer<typeof ConfigSchema>

/** Unboxed reading: a quiet label over a large tabular number. */
function StatItem({ highlight, label, value }: { highlight?: boolean; label: string; value: string }) {
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: 2,
padding: '8px 10px',
borderRadius: 8,
border: '1px solid var(--border)',
backgroundColor: 'var(--muted)'
}}
>
<span style={{ fontSize: 11, color: 'var(--muted-foreground)' }}>{label}</span>
<div style={{ display: 'flex', flexDirection: 'column', gap: 6, minWidth: 0 }}>
<span
style={{
fontSize: 12,
color: 'var(--muted-foreground)',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}}
>
{label}
</span>
<span
style={{
fontSize: 18,
fontSize: 24,
fontWeight: 600,
lineHeight: 1,
letterSpacing: '-0.04em',
fontVariantNumeric: 'tabular-nums',
color: highlight ? '#d97706' : 'var(--foreground)'
color: highlight ? 'var(--status-warning-text, #b45309)' : 'var(--foreground)'
}}
>
{value}
Expand All @@ -66,14 +69,13 @@ function TailscaleOverviewWidget({ config }: WidgetComponentProps<TailscaleWidge
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
gap: 12,
height: '100%',
padding: 12,
fontFamily: 'system-ui, sans-serif',
color: 'var(--foreground)'
}}
>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 }}>
<span style={{ fontSize: 14, fontWeight: 600 }}>{config.title}</span>
<div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 8 }}>
<span style={{ fontSize: 13, fontWeight: 500 }}>{config.title}</span>
{data?.configured && (
<span
style={{
Expand Down Expand Up @@ -108,8 +110,7 @@ function TailscaleOverviewWidget({ config }: WidgetComponentProps<TailscaleWidge
style={{
display: 'grid',
gridTemplateColumns: 'repeat(3, minmax(0, 1fr))',
gap: 8,
marginTop: 8
gap: 16
}}
>
<StatItem label="Online / Total" value={`${data.online_devices} / ${data.total_devices}`} />
Expand Down
7 changes: 6 additions & 1 deletion apps/web/src/components/dashboard/dashboard-card.tsx
Original file line number Diff line number Diff line change
@@ -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 <div className={cn(DASHBOARD_CARD_CLASS_NAME, className)} data-slot="dashboard-card" {...props} />
Expand Down
8 changes: 5 additions & 3 deletions apps/web/src/components/dashboard/module-widget-host.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -19,7 +21,7 @@ const NOOP_ACTIONS: ActionsHelper = {

function Placeholder({ message }: { message: string }) {
return (
<DashboardCard className="flex h-full items-center justify-center border-dashed bg-card p-4 text-center text-muted-foreground text-sm">
<DashboardCard className="flex h-full items-center justify-center border border-border border-dashed bg-card p-5 text-center text-muted-foreground text-sm shadow-none">
{message}
</DashboardCard>
)
Expand Down Expand Up @@ -63,8 +65,8 @@ export function ModuleWidgetHost({ widget, servers: _servers }: ModuleWidgetHost
const Component = entry.module.component
const title = widget.title || entry.manifest.name
return (
<DashboardCard className="flex h-full flex-col bg-card p-4">
<div className="mb-3 min-w-0 truncate font-semibold text-sm">{title}</div>
<DashboardCard className={cn('flex h-full flex-col gap-3 bg-card', WIDGET_PADDING_CLASS_NAME)}>
<WidgetHeader title={title} />
<ScrollArea className="min-h-0 flex-1">
<Component
actions={NOOP_ACTIONS}
Expand Down
95 changes: 95 additions & 0 deletions apps/web/src/components/dashboard/widget-chrome.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type { ComponentProps, ReactNode } from 'react'
import { DashboardCard } from '@/components/dashboard/dashboard-card'
import { Skeleton } from '@/components/ui/skeleton'
import { cn } from '@/lib/utils'

/** Inner padding shared by every built-in widget card. */
export const WIDGET_PADDING_CLASS_NAME = 'p-5'

interface WidgetHeaderProps {
/** Right-aligned secondary text or controls (counts, ranges, legends). */
aside?: ReactNode
className?: string
/** Scope of the reading, e.g. the server name. Rendered after a middle dot. */
context?: ReactNode
title: ReactNode
}

/**
* Title row for built-in widgets: a quiet label instead of a bold heading, so
* the reading below it carries the visual weight.
*/
export function WidgetHeader({ aside, className, context, title }: WidgetHeaderProps) {
return (
<div className={cn('flex min-w-0 items-baseline gap-3', className)}>
<h3 className="min-w-0 truncate font-medium text-[13px] text-foreground/75 leading-5">
{title}
{context ? <span className="font-normal text-muted-foreground"> · {context}</span> : null}
</h3>
{aside ? <div className="ml-auto shrink-0 text-muted-foreground text-xs leading-5">{aside}</div> : null}
</div>
)
}

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<ComponentProps<'p'>, '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 (
<p className={cn('truncate font-semibold tabular-nums leading-none tracking-[-0.04em]', className)} {...props}>
{value}
{unit ? (
<span className={cn('font-medium text-[0.55em] text-muted-foreground tracking-[-0.01em]', unitClassName)}>
{unit}
</span>
) : null}
</p>
)
}

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 (
<div className={cn('flex flex-1 flex-col items-center justify-center gap-1.5 px-4 text-center', className)}>
{icon ? <div className="mb-1 text-muted-foreground">{icon}</div> : null}
<p className="font-medium text-foreground/80 text-sm">{title}</p>
{description ? <p className="max-w-64 text-muted-foreground text-xs">{description}</p> : null}
</div>
)
}

/** Loading placeholder for chart widgets: a header line above the chart body. */
export function WidgetSkeleton() {
return (
<DashboardCard className={cn('flex h-full flex-col gap-4 bg-card', WIDGET_PADDING_CLASS_NAME)}>
<Skeleton className="h-4 w-32" />
<Skeleton className="flex-1 rounded-xl" />
</DashboardCard>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/dashboard/widget-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class WidgetErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundarySta

function ErrorFallback() {
return (
<DashboardCard className="flex h-full items-center justify-center border-destructive/30 bg-card p-4 text-destructive text-sm">
<DashboardCard className="flex h-full items-center justify-center bg-card p-5 text-destructive text-sm ring-1 ring-destructive/30">
Widget failed to render
</DashboardCard>
)
Expand Down
104 changes: 61 additions & 43 deletions apps/web/src/components/dashboard/widgets/alert-list.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -48,56 +51,71 @@ export function AlertListWidget({ config, servers }: AlertListWidgetProps) {

if (!events) {
return (
<DashboardCard className="flex h-full flex-col bg-card p-4">
<h3 className="mb-3 font-semibold text-sm">{t('widgets.alertList.title')}</h3>
<div className="flex flex-1 items-center justify-center text-muted-foreground text-xs">
{t('states.loading')}
</div>
<DashboardCard className="flex h-full flex-col bg-card p-5">
<WidgetHeader title={t('widgets.alertList.title')} />
<WidgetMessage title={t('states.loading')} />
</DashboardCard>
)
}

const firingCount = filtered.filter((event) => event.status === 'firing').length

return (
<DashboardCard className="flex h-full flex-col bg-card p-4">
<h3 className="mb-3 font-semibold text-sm">{t('widgets.alertList.title')}</h3>
<DashboardCard className="flex h-full flex-col bg-card p-5">
<WidgetHeader
aside={
firingCount > 0 ? (
<span className="font-medium text-status-danger-text">
{t('widgets.alertList.firingCount', { count: firingCount })}
</span>
) : null
}
title={t('widgets.alertList.title')}
/>
{filtered.length === 0 ? (
<div className="flex flex-1 items-center justify-center text-muted-foreground text-xs">
{t('widgets.alertList.empty.noEvents')}
</div>
<WidgetMessage
description={t('widgets.alertList.empty.noEvents')}
icon={<CircleCheck aria-hidden="true" className="size-6 text-status-healthy" />}
title={t('widgets.alertList.empty.allClear')}
/>
) : (
<ScrollArea className="flex-1" contentClassName="flex flex-col gap-1.5">
{filtered.map((event) => {
const isFiring = event.status === 'firing'
const isResolved = event.status === 'resolved'
const statusLabel = t(`widgets.alertList.status.${event.status}`, { defaultValue: event.status })
let statusColor = 'bg-muted-foreground'
if (isFiring) {
statusColor = 'bg-red-500'
} else if (isResolved) {
statusColor = 'bg-green-500'
}
const serverName = serverNameMap.get(event.server_id) ?? event.server_name
return (
<div
className="flex items-center gap-2 rounded-md px-2 py-1.5 text-xs hover:bg-muted/50"
key={event.alert_key ?? `${event.rule_id}-${event.server_id}-${event.event_at}-${event.status}`}
>
<span
aria-label={statusLabel}
className={`inline-block size-2 shrink-0 rounded-full ${statusColor}`}
role="img"
title={statusLabel}
/>
<span className="min-w-0 flex-1 truncate">
<span className="font-medium">{event.rule_name}</span>
<span className="text-muted-foreground"> - {serverName}</span>
</span>
<span className="shrink-0 text-muted-foreground tabular-nums">
{formatRelativeTime(event.event_at)}
</span>
</div>
)
})}
<ScrollArea className="mt-2 min-h-0 flex-1">
<ul className="flex flex-col">
{filtered.map((event) => {
const isFiring = event.status === 'firing'
const isResolved = event.status === 'resolved'
const statusLabel = t(`widgets.alertList.status.${event.status}`, { defaultValue: event.status })
let statusColor = 'bg-muted-foreground/50'
if (isFiring) {
statusColor = 'bg-status-danger'
} else if (isResolved) {
statusColor = 'bg-status-healthy'
}
const serverName = serverNameMap.get(event.server_id) ?? event.server_name
return (
<li
className="flex items-center gap-3 border-border/60 border-t py-2"
key={event.alert_key ?? `${event.rule_id}-${event.server_id}-${event.event_at}-${event.status}`}
>
<span
aria-label={statusLabel}
className={cn('inline-block size-2 shrink-0 rounded-full', statusColor)}
role="img"
title={statusLabel}
/>
<span className="flex min-w-0 flex-1 flex-col">
<span className={cn('truncate font-medium text-sm', !isFiring && 'text-foreground/80')}>
{event.rule_name}
</span>
<span className="truncate text-muted-foreground text-xs">{serverName}</span>
</span>
<span className="shrink-0 text-muted-foreground text-xs tabular-nums">
{formatRelativeTime(event.event_at)}
</span>
</li>
)
})}
</ul>
</ScrollArea>
)}
</DashboardCard>
Expand Down
Loading
Loading