From fa016a1948a80e3a87a070c71f1184d886437c93 Mon Sep 17 00:00:00 2001 From: Xylo01 Date: Sat, 28 Nov 2026 23:09:43 +0000 Subject: [PATCH] feat(web): redesign dashboard shell, menus and status pages with the Taste skill - Shell: grouped sidebar (Monitoring, Publish, Workspace, Instance) with live counts, collapsible icon rail with tooltips, breadcrumb top bar, mobile drawer with focus trap and scroll lock - Menus: accessible Menu (keyboard, portal, click-outside) for org switcher, account and row actions; Ctrl/Cmd+K command menu for pages, monitors, status pages and actions - Shared primitives: PageHeader, Dialog (native ), EmptyState, segmented control, skeletons, z-index and motion tokens - Public status page: plain status summary, Subscribe and Feeds menu in the header, distinct Classic/Signal/Flat/Spark layouts, accessible uptime bars with tooltips and keyboard, loading/error/locked states - Status page editor: tabs for pages and maintenance, compact page rows with overflow menu, radio-card pickers for layout, palette and bar style, clearer Structure & Categories editor - Monitors, overview, detail, new monitor, incidents, probes, integrations, organization, security, admin and auth: consistent headers, empty/loading/error states, confirm dialogs instead of window.confirm, 390px layouts - Copy: no em/en dashes, sentence case; forest muted text raised to 7:1; dev proxy target configurable via UPTIME_API_URL --- web/index.html | 4 +- web/src/App.tsx | 4 +- web/src/components/AppShell.tsx | 809 +++--- web/src/components/CommandPalette.tsx | 271 ++ web/src/components/Dialog.tsx | 73 + web/src/components/EmptyState.tsx | 34 + web/src/components/Menu.tsx | 314 +++ web/src/components/PageHeader.tsx | 26 + web/src/components/navigation.ts | 97 + web/src/index.css | 586 +++- web/src/lib/status-themes.ts | 48 +- web/src/lib/time.ts | 19 + web/src/pages/AdminPage.tsx | 556 ++-- web/src/pages/AuthPage.tsx | 406 +-- web/src/pages/IncidentsPage.tsx | 822 ++++-- web/src/pages/IntegrationsPage.tsx | 1319 +++++---- web/src/pages/MonitorDetailPage.tsx | 1204 ++++---- web/src/pages/MonitorsPage.tsx | 1165 ++++---- web/src/pages/NewMonitorPage.tsx | 1911 ++++++------- web/src/pages/OrganizationPage.tsx | 526 ++-- web/src/pages/OverviewPage.tsx | 730 ++--- web/src/pages/PublicStatusPage.tsx | 2597 +++++++++++------- web/src/pages/SecurityPage.tsx | 952 ++++--- web/src/pages/StatusPagesPage.tsx | 3638 +++++++++++++++---------- web/src/pages/WorkersPage.tsx | 647 +++-- web/vite.config.ts | 9 +- 26 files changed, 11574 insertions(+), 7193 deletions(-) create mode 100644 web/src/components/CommandPalette.tsx create mode 100644 web/src/components/Dialog.tsx create mode 100644 web/src/components/EmptyState.tsx create mode 100644 web/src/components/Menu.tsx create mode 100644 web/src/components/PageHeader.tsx create mode 100644 web/src/components/navigation.ts create mode 100644 web/src/lib/time.ts diff --git a/web/index.html b/web/index.html index 22e0e1e..b27ff33 100644 --- a/web/index.html +++ b/web/index.html @@ -1,9 +1,9 @@ - + - Uptime — Distributed uptime monitoring and status pages + Uptime: self-hosted uptime monitoring and status pages @@ -151,6 +152,7 @@ function ProtectedApp() { diff --git a/web/src/components/AppShell.tsx b/web/src/components/AppShell.tsx index c4a826b..50714c9 100644 --- a/web/src/components/AppShell.tsx +++ b/web/src/components/AppShell.tsx @@ -1,77 +1,158 @@ import { - Activity, - AlertTriangle, - Bell, Building2, - ChevronDown, - Globe, + ChevronsUpDown, KeyRound, - LayoutDashboard, LogOut, - Menu, + Menu as MenuIcon, + PanelLeftClose, + PanelLeftOpen, Plus, - Server, - Shield, + Search, X, } from "lucide-react"; -import { useEffect, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { Link, NavLink, useLocation, useNavigate } from "react-router-dom"; -import type { AuthMeResponse } from "../lib/api"; +import { type AuthMeResponse, type OverviewStats, api } from "../lib/api"; import { authClient } from "../lib/auth-client"; import { BrandMark } from "./BrandMark"; +import { CommandPalette } from "./CommandPalette"; +import { Dialog } from "./Dialog"; +import { Menu, type MenuEntry } from "./Menu"; +import { NAV_GROUPS, locate } from "./navigation"; interface AppShellProps { me: AuthMeResponse; liveConnected: boolean; + liveTick: number; onRefreshMe: () => Promise; onSwitchOrg: (orgId: string) => Promise; children: React.ReactNode; } +const COLLAPSE_KEY = "uptime.sidebar.collapsed"; +const isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform); + export function AppShell({ me, liveConnected, + liveTick, onRefreshMe, onSwitchOrg, children, }: AppShellProps) { const navigate = useNavigate(); const location = useLocation(); - const [orgMenuOpen, setOrgMenuOpen] = useState(false); - const [mobileNavOpen, setMobileNavOpen] = useState(false); - const [creatingOrg, setCreatingOrg] = useState(false); + const [drawerOpen, setDrawerOpen] = useState(false); + const [collapsed, setCollapsed] = useState( + () => typeof localStorage !== "undefined" && localStorage.getItem(COLLAPSE_KEY) === "1", + ); + const [commandOpen, setCommandOpen] = useState(false); + const [createOrgOpen, setCreateOrgOpen] = useState(false); const [newOrgName, setNewOrgName] = useState(""); const [orgErr, setOrgErr] = useState(null); + const [creatingOrg, setCreatingOrg] = useState(false); + const [counts, setCounts] = useState | null>(null); + const drawerRef = useRef(null); + const drawerToggleRef = useRef(null); + // Close the drawer on navigation. useEffect(() => { - setMobileNavOpen(false); - setOrgMenuOpen(false); + setDrawerOpen(false); }, [location.pathname]); + // Live counts for the nav (open incidents, down monitors); refreshed on every live event. + useEffect(() => { + let cancelled = false; + const t = setTimeout(() => { + api("/api/v1/overview") + .then((s) => { + if (!cancelled) setCounts({ open_incidents: s.open_incidents, down_monitors: s.down_monitors }); + }) + .catch(() => {}); + }, 250); + return () => { + cancelled = true; + clearTimeout(t); + }; + }, [liveTick, me.active_organization_id]); + + // Global shortcut: Ctrl+K / Cmd+K opens the command menu. useEffect(() => { const onKey = (e: KeyboardEvent) => { - if (e.key === "Escape") { - setMobileNavOpen(false); - setOrgMenuOpen(false); + if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") { + e.preventDefault(); + setCommandOpen((o) => !o); } }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, []); + // Drawer: lock page scroll, trap focus, Escape closes, focus returns to the toggle. + useEffect(() => { + if (!drawerOpen) return; + const prevOverflow = document.body.style.overflow; + document.body.style.overflow = "hidden"; + const panel = drawerRef.current; + panel?.querySelector("button, a")?.focus(); + const onKey = (e: KeyboardEvent) => { + if (e.key === "Escape") { + setDrawerOpen(false); + return; + } + if (e.key !== "Tab" || !panel) return; + const focusables = Array.from( + panel.querySelectorAll("a[href], button:not([disabled]), input, [tabindex='0']"), + ); + if (focusables.length === 0) return; + const first = focusables[0]; + const last = focusables[focusables.length - 1]; + if (e.shiftKey && document.activeElement === first) { + e.preventDefault(); + last.focus(); + } else if (!e.shiftKey && document.activeElement === last) { + e.preventDefault(); + first.focus(); + } + }; + document.addEventListener("keydown", onKey); + const toggle = drawerToggleRef.current; + return () => { + document.body.style.overflow = prevOverflow; + document.removeEventListener("keydown", onKey); + toggle?.focus(); + }; + }, [drawerOpen]); + + const toggleCollapsed = () => { + setCollapsed((c) => { + localStorage.setItem(COLLAPSE_KEY, c ? "0" : "1"); + return !c; + }); + }; + const activeOrg = me.memberships.find((m) => m.organizationId === me.active_organization_id) ?? me.memberships[0]; + const roleLabel = + me.active_organization_role ?? (me.is_server_admin ? "Server admin" : "Member"); - const handleSignOut = async () => { + const handleSignOut = useCallback(async () => { await authClient.signOut(); navigate("/login"); - }; + }, [navigate]); const handleCreateOrg = async (e: React.FormEvent) => { e.preventDefault(); - if (!newOrgName.trim()) return; + if (!newOrgName.trim()) { + setOrgErr("Write a name for the organization."); + return; + } setOrgErr(null); + setCreatingOrg(true); const slug = newOrgName .trim() .toLowerCase() @@ -81,413 +162,373 @@ export function AppShell({ name: newOrgName.trim(), slug: `${slug || "org"}-${Math.random().toString(36).slice(2, 6)}`, }); + setCreatingOrg(false); if (res.error) { - setOrgErr(res.error.message || "Failed to create organization"); + setOrgErr(res.error.message || "Could not create the organization. Try again."); return; } if (res.data?.id) { await onSwitchOrg(res.data.id); } setNewOrgName(""); - setCreatingOrg(false); - setOrgMenuOpen(false); + setCreateOrgOpen(false); await onRefreshMe(); }; - const navItems = [ - { to: "/", label: "Overview", icon: LayoutDashboard, end: true }, - { to: "/monitors", label: "Monitors", icon: Activity }, - { to: "/incidents", label: "Incidents", icon: AlertTriangle }, - { to: "/status-pages", label: "Status pages", icon: Globe }, - { to: "/workers", label: "Probes", icon: Server }, - { to: "/integrations", label: "Integrations", icon: Bell }, - { to: "/organization", label: "Organization", icon: Building2 }, - { to: "/security", label: "Security & API", icon: KeyRound }, + const { item: currentItem, sub } = locate(location.pathname); + + const orgMenu: MenuEntry[] = [ + { heading: "Switch organization" }, + ...me.memberships.map((m) => ({ + label: m.name, + hint: m.role, + checked: m.organizationId === activeOrg?.organizationId, + onSelect: () => onSwitchOrg(m.organizationId), + })), + { separator: true }, + { label: "Organization settings", icon: Building2, to: "/organization" }, + { label: "Create organization", icon: Plus, onSelect: () => setCreateOrgOpen(true) }, + ]; + + const userMenu: MenuEntry[] = [ + { heading: me.user.email }, + { label: "Security & API", icon: KeyRound, to: "/security" }, + { label: "Organization", icon: Building2, to: "/organization" }, + { separator: true }, + { label: "Sign out", icon: LogOut, danger: true, onSelect: handleSignOut }, ]; - const sidebarContent = ( + const initials = + me.user.name + .split(/\s+/) + .filter(Boolean) + .slice(0, 2) + .map((p) => p[0]?.toUpperCase()) + .join("") || me.user.email[0]?.toUpperCase(); + + const renderSidebar = (rail: boolean) => (
- {/* Brand header */} -
- - -
-
- Uptime -
-
-
-
- - + + {!rail && ( + <> + + + {activeOrg?.name ?? "No organization"} + + + {roleLabel} + + +
- {/* Organization Switcher */} -
- - - {orgMenuOpen && ( -
-
- Organizations -
-
- {me.memberships.map((m) => { - const isCurrent = m.organizationId === activeOrg?.organizationId; - return ( - - ); - })} -
-
- {creatingOrg ? ( -
- - setNewOrgName(e.target.value)} - placeholder="Organization name" - className="pg-input min-h-[38px] text-[14px]" - /> - {orgErr && ( -

- {orgErr} -

- )} -
- -
-
- ) : ( - - )} + ) : ( +
+ {group.label} +
+ ))} +
    + {items.map((item) => { + const Icon = item.icon; + const count = + item.to === "/incidents" + ? counts?.open_incidents + : item.to === "/monitors" + ? counts?.down_monitors + : undefined; + const countLabel = + item.to === "/incidents" ? "open incidents" : "monitors down"; + return ( +
  • + + +
  • + ); + })} +
-
- )} -
- - {/* Navigation */} - - {/* Account Footer */} -
-
+ -
-
- - {me.user.name} - - {me.is_server_admin && ( - - Admin + + {!rail && ( + <> + + {me.user.name} + + {me.user.email} - )} -
-
- {me.user.email} -
-
- -
+ +
); return ( -
+
Skip to content - {/* Mobile / tablet fixed header */} -
+ {renderSidebar(collapsed)} + + + {/* Mobile / tablet drawer */} +
setDrawerOpen(false)} + aria-hidden="true" + /> + + +
+ {/* Top bar: context on the left, search and live state on the right */} +
+ + + + + + + + + - Uptime + - - -
- {/* Mobile slide-over drawer */} - {mobileNavOpen && ( -
-
setMobileNavOpen(false)} - aria-hidden="true" - /> - -
- )} +
- {/* Desktop persistent rail */} -
+ + setCommandOpen(false)} + isServerAdmin={me.is_server_admin} + onSignOut={handleSignOut} + /> + + { + setCreateOrgOpen(false); + setOrgErr(null); }} + title="Create organization" + description="A separate workspace with its own monitors, status pages and members. You become its owner." > - {sidebarContent} - - - {/* Main Content */} -
-
- {children} -
-
+
+
+ + setNewOrgName(e.target.value)} + aria-invalid={orgErr ? true : undefined} + aria-describedby={orgErr ? "new-org-error" : undefined} + autoComplete="organization" + className="pg-input" + /> + {orgErr && ( + + )} +
+
+ + +
+
+
); } diff --git a/web/src/components/CommandPalette.tsx b/web/src/components/CommandPalette.tsx new file mode 100644 index 0000000..7bb7583 --- /dev/null +++ b/web/src/components/CommandPalette.tsx @@ -0,0 +1,271 @@ +import { ArrowRight, CalendarClock, ExternalLink, LogOut, Plus, Search } from "lucide-react"; +import { type ComponentType, useEffect, useId, useMemo, useRef, useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { type MonitorItem, type StatusPageItem, api } from "../lib/api"; +import { NAV_GROUPS } from "./navigation"; + +interface Command { + id: string; + group: string; + label: string; + hint?: string; + keywords?: string; + icon: ComponentType<{ className?: string }>; + run: () => void; +} + +interface CommandPaletteProps { + open: boolean; + onClose: () => void; + isServerAdmin: boolean; + onSignOut: () => void; +} + +const STATUS_HINT: Record = { + up: "Operational", + degraded: "Degraded", + down: "Down", + maintenance: "Maintenance", + pending: "Pending", +}; + +/** + * Command menu (Ctrl+K / Cmd+K): jump to any page, monitor or public status page, or start a + * common action. Combobox + listbox pattern; arrows move, Enter runs, Escape closes. + */ +export function CommandPalette({ open, onClose, isServerAdmin, onSignOut }: CommandPaletteProps) { + const ref = useRef(null); + const inputRef = useRef(null); + const listRef = useRef(null); + const navigate = useNavigate(); + const [query, setQuery] = useState(""); + const [active, setActive] = useState(0); + const [monitors, setMonitors] = useState(null); + const [pages, setPages] = useState(null); + const listId = useId(); + + useEffect(() => { + const d = ref.current; + if (!d) return; + if (open && !d.open) { + d.showModal(); + setQuery(""); + setActive(0); + inputRef.current?.focus(); + api("/api/v1/monitors").then(setMonitors).catch(() => setMonitors([])); + api("/api/v1/status-pages").then(setPages).catch(() => setPages([])); + } + if (!open && d.open) d.close(); + }, [open]); + + const commands = useMemo(() => { + const go = (to: string) => () => { + onClose(); + navigate(to); + }; + const list: Command[] = [ + { + id: "act-monitor", + group: "Actions", + label: "Add monitor", + keywords: "new create check", + icon: Plus, + run: go("/monitors/new"), + }, + { + id: "act-maintenance", + group: "Actions", + label: "Schedule maintenance", + keywords: "window downtime planned", + icon: CalendarClock, + run: go("/status-pages#maintenance"), + }, + ]; + for (const g of NAV_GROUPS) { + for (const item of g.items) { + if (item.adminOnly && !isServerAdmin) continue; + list.push({ + id: `nav-${item.to}`, + group: "Go to", + label: item.label, + hint: g.label, + keywords: item.keywords, + icon: item.icon, + run: go(item.to), + }); + } + } + for (const m of monitors ?? []) { + list.push({ + id: `mon-${m.id}`, + group: "Monitors", + label: m.name, + hint: m.paused ? "Paused" : (STATUS_HINT[m.status] ?? m.status), + keywords: `${m.monitor_type} ${m.tags.join(" ")}`, + icon: ArrowRight, + run: go(`/monitors/${m.id}`), + }); + } + for (const p of pages ?? []) { + list.push({ + id: `page-${p.id}`, + group: "Public status pages", + label: p.title, + hint: `/status/${p.slug}`, + keywords: `${p.slug} ${p.custom_domain ?? ""}`, + icon: ExternalLink, + run: () => { + onClose(); + window.open(`/status/${p.slug}`, "_blank", "noopener"); + }, + }); + } + list.push({ + id: "act-signout", + group: "Account", + label: "Sign out", + keywords: "logout log out", + icon: LogOut, + run: () => { + onClose(); + onSignOut(); + }, + }); + return list; + }, [monitors, pages, isServerAdmin, navigate, onClose, onSignOut]); + + const filtered = useMemo(() => { + const q = query.trim().toLowerCase(); + if (!q) return commands.filter((c) => c.group !== "Monitors" && c.group !== "Public status pages"); + const words = q.split(/\s+/); + return commands.filter((c) => { + const hay = `${c.label} ${c.hint ?? ""} ${c.keywords ?? ""} ${c.group}`.toLowerCase(); + return words.every((w) => hay.includes(w)); + }); + }, [commands, query]); + + useEffect(() => { + setActive(0); + }, [query]); + + useEffect(() => { + listRef.current + ?.querySelector(`[data-index="${active}"]`) + ?.scrollIntoView({ block: "nearest" }); + }, [active]); + + const onKeyDown = (e: React.KeyboardEvent) => { + if (e.key === "ArrowDown") { + e.preventDefault(); + setActive((a) => Math.min(a + 1, filtered.length - 1)); + } else if (e.key === "ArrowUp") { + e.preventDefault(); + setActive((a) => Math.max(a - 1, 0)); + } else if (e.key === "Home") { + e.preventDefault(); + setActive(0); + } else if (e.key === "End") { + e.preventDefault(); + setActive(filtered.length - 1); + } else if (e.key === "Enter") { + e.preventDefault(); + filtered[active]?.run(); + } + }; + + let lastGroup = ""; + + return ( + { + if (e.target === e.currentTarget) onClose(); + }} + > +
+
+
+ {filtered.length === 0 && ( +

+ Nothing matches “{query}”. Try a monitor name, a page or an action. +

+ )} + {filtered.map((c, i) => { + const heading = c.group !== lastGroup ? c.group : null; + lastGroup = c.group; + const Icon = c.icon; + return ( +
+ {heading && ( +
+ {heading} +
+ )} +
setActive(i)} + onClick={() => c.run()} + > + + {c.label} + {c.hint && {c.hint}} +
+
+ ); + })} +
+ +
+ ); +} diff --git a/web/src/components/Dialog.tsx b/web/src/components/Dialog.tsx new file mode 100644 index 0000000..57c789b --- /dev/null +++ b/web/src/components/Dialog.tsx @@ -0,0 +1,73 @@ +import { X } from "lucide-react"; +import { type ReactNode, useEffect, useId, useRef } from "react"; + +interface DialogProps { + open: boolean; + onClose: () => void; + title: string; + description?: ReactNode; + children: ReactNode; + /** Wider body for editors (default 520px). */ + width?: number; +} + +/** + * Modal built on the native : the browser traps focus, Escape closes it and focus returns + * to the control that opened it. A click on the backdrop closes it too. + */ +export function Dialog({ open, onClose, title, description, children, width }: DialogProps) { + const ref = useRef(null); + const titleId = useId(); + const descId = useId(); + + useEffect(() => { + const d = ref.current; + if (!d) return; + if (open && !d.open) d.showModal(); + if (!open && d.open) d.close(); + }, [open]); + + return ( + { + if (e.target === e.currentTarget) onClose(); + }} + > + {open && ( +
+
+
+

+ {title} +

+ {description && ( +

+ {description} +

+ )} +
+ +
+ {children} +
+ )} +
+ ); +} diff --git a/web/src/components/EmptyState.tsx b/web/src/components/EmptyState.tsx new file mode 100644 index 0000000..fbcd6fa --- /dev/null +++ b/web/src/components/EmptyState.tsx @@ -0,0 +1,34 @@ +import type { ComponentType, ReactNode } from "react"; + +interface EmptyStateProps { + icon?: ComponentType<{ className?: string }>; + title: string; + children?: ReactNode; + /** One action that fills the empty space, e.g. a primary link. */ + action?: ReactNode; +} + +/** A composed "nothing here yet" block that says how to populate the view. */ +export function EmptyState({ icon: Icon, title, children, action }: EmptyStateProps) { + return ( +
+ {Icon && ( + + )} +
+

{title}

+ {children && ( +

+ {children} +

+ )} +
+ {action} +
+ ); +} diff --git a/web/src/components/Menu.tsx b/web/src/components/Menu.tsx new file mode 100644 index 0000000..1ecdd90 --- /dev/null +++ b/web/src/components/Menu.tsx @@ -0,0 +1,314 @@ +import { + type ComponentType, + type KeyboardEvent as ReactKeyboardEvent, + type ReactNode, + useCallback, + useEffect, + useId, + useLayoutEffect, + useRef, + useState, +} from "react"; +import { createPortal } from "react-dom"; +import { Link } from "react-router-dom"; +import { Check } from "lucide-react"; + +type Icon = ComponentType<{ className?: string }>; + +export interface MenuAction { + label: string; + icon?: Icon; + /** Right-aligned quiet text, e.g. a role or a shortcut. */ + hint?: string; + /** Run on select. */ + onSelect?: () => void | Promise; + /** In-app route (react-router). */ + to?: string; + /** External URL, opens in a new tab. */ + href?: string; + danger?: boolean; + disabled?: boolean; + /** Renders as a radio item with this checked state (org switcher, choices). */ + checked?: boolean; +} + +export type MenuEntry = + | MenuAction + | { separator: true } + | { heading: string }; + +interface MenuProps { + /** Accessible name of the menu (and of the trigger when it has no text). */ + label: string; + items: MenuEntry[]; + /** Trigger content; the trigger is a + ); + })} + , + portalTarget, + ) + : null; + + return ( + <> + + {menu} + + ); +} diff --git a/web/src/components/PageHeader.tsx b/web/src/components/PageHeader.tsx new file mode 100644 index 0000000..84af153 --- /dev/null +++ b/web/src/components/PageHeader.tsx @@ -0,0 +1,26 @@ +import type { ReactNode } from "react"; + +interface PageHeaderProps { + title: ReactNode; + description?: ReactNode; + /** Small line above the title: a back link, a status line or a breadcrumb. */ + eyebrow?: ReactNode; + /** Buttons on the right edge; one primary at most. */ + actions?: ReactNode; +} + +/** One header recipe for every dashboard view: h1, a short description, actions right. */ +export function PageHeader({ title, description, eyebrow, actions }: PageHeaderProps) { + return ( +
+
+ {eyebrow &&
{eyebrow}
} +

{title}

+ {description &&

{description}

} +
+ {actions && ( +
{actions}
+ )} +
+ ); +} diff --git a/web/src/components/navigation.ts b/web/src/components/navigation.ts new file mode 100644 index 0000000..0516548 --- /dev/null +++ b/web/src/components/navigation.ts @@ -0,0 +1,97 @@ +import { + Activity, + AlertTriangle, + Bell, + Building2, + Globe, + KeyRound, + LayoutDashboard, + Server, + Shield, +} from "lucide-react"; +import type { ComponentType } from "react"; + +export interface NavItem { + to: string; + label: string; + icon: ComponentType<{ className?: string }>; + end?: boolean; + /** Extra words the command menu matches on. */ + keywords?: string; + adminOnly?: boolean; +} + +export interface NavGroup { + /** Heading shown above the group; the first group has none. */ + label?: string; + items: NavItem[]; +} + +/** One navigation model for the sidebar, the breadcrumb and the command menu. */ +export const NAV_GROUPS: NavGroup[] = [ + { + items: [ + { to: "/", label: "Overview", icon: LayoutDashboard, end: true, keywords: "home dashboard" }, + ], + }, + { + label: "Monitoring", + items: [ + { to: "/monitors", label: "Monitors", icon: Activity, keywords: "checks targets uptime" }, + { to: "/incidents", label: "Incidents", icon: AlertTriangle, keywords: "outages alerts" }, + { to: "/workers", label: "Probes", icon: Server, keywords: "workers regions agents" }, + ], + }, + { + label: "Publish", + items: [ + { + to: "/status-pages", + label: "Status pages", + icon: Globe, + keywords: "public maintenance subscribers", + }, + ], + }, + { + label: "Workspace", + items: [ + { + to: "/integrations", + label: "Integrations", + icon: Bell, + keywords: "notifications channels slack discord webhook alertmanager", + }, + { to: "/organization", label: "Organization", icon: Building2, keywords: "members invite team" }, + { + to: "/security", + label: "Security & API", + icon: KeyRound, + keywords: "2fa two-factor tokens password", + }, + ], + }, + { + label: "Instance", + items: [ + { + to: "/admin", + label: "Server admin", + icon: Shield, + keywords: "users organizations ban", + adminOnly: true, + }, + ], + }, +]; + +/** The page a path belongs to, plus a sub-page label for nested routes. */ +export function locate(pathname: string): { item?: NavItem; sub?: string } { + const items = NAV_GROUPS.flatMap((g) => g.items); + const item = + items.find((i) => (i.end ? pathname === i.to : pathname === i.to || pathname.startsWith(`${i.to}/`))) ?? + undefined; + if (pathname === "/monitors/new") return { item, sub: "New monitor" }; + if (pathname.startsWith("/monitors/")) return { item, sub: "Monitor details" }; + return { item }; +} diff --git a/web/src/index.css b/web/src/index.css index 60d3053..084fc38 100644 --- a/web/src/index.css +++ b/web/src/index.css @@ -13,7 +13,7 @@ --p-surface: #162a17; --p-surface-2: #1c341d; --p-ink: #ffffff; - --p-muted: #9aa39a; + --p-muted: #abb4ab; --p-accent: #c6f19d; --p-accent-ink: #0f1f10; --p-action: #c6f19d; @@ -73,6 +73,16 @@ --m-in: 150ms; --m-out: 120ms; --m-press: 90ms; + --m-panel: 200ms; + --m-close: 120ms; + --m-slide: 240ms; + + /* Layer scale: sticky bars, drawers, menus, dialogs, skip link */ + --z-sticky: 20; + --z-drawer: 40; + --z-menu: 50; + --z-dialog: 60; + --z-skip: 70; } /* Optional light theme for public status pages */ @@ -272,7 +282,7 @@ position: fixed; top: 12px; left: 12px; - z-index: 60; + z-index: var(--z-skip); padding: 10px 16px; border-radius: var(--r-btn); background: var(--p-action); @@ -549,6 +559,578 @@ color: var(--p-muted); white-space: nowrap; } + + /* Touch: every standalone control reaches 44px */ + @media (pointer: coarse) { + .pg-icon-btn { + width: 44px; + height: 44px; + } + } + + /* Page header: one h1 scale, one description measure, actions on the right edge */ + .pg-page-title { + font-size: 26px; + line-height: 1.12; + letter-spacing: var(--display-tracking); + text-wrap: balance; + } + + @media (min-width: 640px) { + .pg-page-title { + font-size: 30px; + } + } + + .pg-page-desc { + margin-top: 6px; + max-width: 68ch; + font-size: 15px; + line-height: 1.55; + color: var(--p-muted); + text-wrap: pretty; + } + + /* Section heading inside a panel (h2) */ + .pg-section-title { + font-size: 16px; + font-weight: 500; + line-height: 1.3; + letter-spacing: -0.01em; + } + + /* Keyboard hint */ + .pg-kbd { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 20px; + height: 20px; + padding: 0 5px; + border-radius: var(--r-sm); + border: 1px solid var(--p-line-strong); + background-color: var(--p-bg); + font-family: var(--font-mono); + font-size: 12px; + line-height: 1; + color: var(--p-muted); + } + + /* Menus: org switcher, user menu, row and card overflow actions */ + .pg-menu { + position: fixed; + z-index: var(--z-menu); + min-width: 220px; + max-height: min(420px, calc(100dvh - 24px)); + overflow-y: auto; + padding: 6px; + border-radius: var(--r-md); + border: 1px solid var(--p-line-strong); + background-color: var(--p-surface); + color: var(--p-ink); + box-shadow: 0 16px 40px -16px color-mix(in srgb, var(--p-bg) 60%, rgb(0 0 0 / 0.9)); + animation: pg-menu-in var(--m-panel) var(--ease) both; + } + + .pg-menu-heading { + padding: 8px 10px 4px; + font-size: 13px; + font-weight: 500; + color: var(--p-muted); + } + + .pg-menu-item { + display: flex; + align-items: center; + gap: 10px; + width: 100%; + min-height: 38px; + padding: 0 10px; + border: 0; + border-radius: var(--r-sm); + background: transparent; + color: var(--p-ink); + font-family: var(--font-text); + font-size: 14px; + font-weight: 400; + text-align: left; + text-decoration: none; + cursor: pointer; + } + + .pg-menu-item svg { + width: 16px; + height: 16px; + flex-shrink: 0; + color: var(--p-muted); + } + + .pg-menu-item:focus-visible, + .pg-menu-item[data-highlighted="true"] { + outline: none; + background-color: color-mix(in srgb, var(--p-ink) 8%, transparent); + } + + @media (hover: hover) and (pointer: fine) { + .pg-menu-item:hover { + background-color: color-mix(in srgb, var(--p-ink) 8%, transparent); + } + } + + .pg-menu-item[aria-disabled="true"] { + opacity: 0.45; + cursor: not-allowed; + } + + .pg-menu-item--danger, + .pg-menu-item--danger svg { + color: var(--st-down); + } + + .pg-menu-item__hint { + margin-left: auto; + padding-left: 12px; + font-family: var(--font-mono); + font-size: 12px; + color: var(--p-muted); + } + + .pg-menu-sep { + height: 1px; + margin: 6px -6px; + background-color: var(--p-line); + } + + @media (pointer: coarse) { + .pg-menu-item { + min-height: 44px; + } + } + + /* Dialogs (native ) */ + .pg-dialog { + width: min(520px, calc(100vw - 32px)); + max-height: calc(100dvh - 48px); + margin: auto; + padding: 0; + border-radius: var(--r-lg); + border: 1px solid var(--p-line-strong); + background-color: var(--p-surface); + color: var(--p-ink); + box-shadow: 0 24px 64px -24px rgb(0 0 0 / 0.7); + } + + .pg-dialog[open] { + animation: pg-menu-in var(--m-panel) var(--ease) both; + } + + .pg-dialog::backdrop { + background: rgb(4 8 4 / 0.62); + } + + /* Segmented control / tabs: one look for filters, tab sets and toggles */ + .pg-segmented { + display: inline-flex; + flex-wrap: wrap; + gap: 2px; + padding: 3px; + border-radius: var(--r-md); + border: 1px solid var(--p-line); + background-color: var(--p-bg); + } + + .pg-segmented__item { + display: inline-flex; + align-items: center; + gap: 6px; + min-height: 34px; + padding: 0 12px; + border: 1px solid transparent; + border-radius: var(--r-sm); + background: transparent; + color: var(--p-muted); + font-family: var(--font-text); + font-size: 14px; + font-weight: 500; + white-space: nowrap; + cursor: pointer; + transition: + background-color var(--m-out) var(--ease), + color var(--m-out) var(--ease); + } + + @media (hover: hover) and (pointer: fine) { + .pg-segmented__item:hover { + color: var(--p-ink); + transition-duration: var(--m-in); + } + } + + .pg-segmented__item[aria-pressed="true"], + .pg-segmented__item[aria-selected="true"], + .pg-segmented__item[aria-current="page"] { + background-color: var(--p-surface-2); + border-color: var(--p-line); + color: var(--p-ink); + } + + @media (pointer: coarse) { + .pg-segmented__item { + min-height: 40px; + } + } + + /* Loading skeleton shaped like the content it stands in for */ + .pg-skeleton { + border-radius: var(--r-sm); + background: linear-gradient( + 90deg, + var(--p-surface-2) 0%, + color-mix(in srgb, var(--p-surface-2) 70%, var(--p-ink) 6%) 50%, + var(--p-surface-2) 100% + ); + background-size: 200% 100%; + animation: pg-shimmer 1.4s linear infinite; + } + + /* Empty state */ + .pg-empty { + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 12px; + padding: 32px 24px; + } + + .pg-empty__icon { + display: inline-flex; + align-items: center; + justify-content: center; + width: 40px; + height: 40px; + border-radius: var(--r-md); + border: 1px solid var(--p-line); + background-color: var(--p-bg); + color: var(--p-muted); + } + + /* ---------- App shell: sidebar, rail, drawer, top bar, command menu ---------- */ + .pg-sidebar { + width: 252px; + transition: width var(--m-slide) var(--ease); + } + + .pg-sidebar[data-collapsed="true"] { + width: 68px; + } + + .pg-org-trigger { + display: flex; + align-items: center; + gap: 10px; + width: 100%; + min-height: 44px; + padding: 6px 8px; + border: 1px solid transparent; + border-radius: var(--r-md); + background: transparent; + color: var(--p-ink); + cursor: pointer; + transition: + background-color var(--m-out) var(--ease), + border-color var(--m-out) var(--ease); + } + + .pg-org-trigger--rail { + justify-content: center; + width: 44px; + padding: 0; + margin-inline: auto; + } + + .pg-org-trigger[aria-expanded="true"] { + background-color: color-mix(in srgb, var(--p-ink) 6%, transparent); + border-color: var(--p-line); + } + + @media (hover: hover) and (pointer: fine) { + .pg-org-trigger:hover { + background-color: color-mix(in srgb, var(--p-ink) 6%, transparent); + transition-duration: var(--m-in); + } + } + + .pg-avatar { + display: inline-flex; + align-items: center; + justify-content: center; + width: 30px; + height: 30px; + flex-shrink: 0; + border-radius: var(--r-md); + background-color: var(--p-active); + border: 1px solid var(--p-line-strong); + color: var(--p-accent); + font-family: var(--font-mono); + font-size: 13px; + font-weight: 500; + } + + .pg-nav-heading { + padding: 18px 10px 6px; + font-size: 13px; + font-weight: 400; + color: var(--p-muted); + } + + .pg-nav-item { + position: relative; + display: flex; + align-items: center; + gap: 10px; + min-height: 38px; + padding: 0 10px; + border-radius: var(--r-sm); + color: color-mix(in srgb, var(--p-ink) 80%, var(--p-surface)); + font-size: 14px; + font-weight: 500; + text-decoration: none; + transition: + background-color var(--m-out) var(--ease), + color var(--m-out) var(--ease); + } + + .pg-nav-item svg { + width: 16px; + height: 16px; + flex-shrink: 0; + color: var(--p-muted); + } + + @media (hover: hover) and (pointer: fine) { + .pg-nav-item:hover { + color: var(--p-ink); + background-color: color-mix(in srgb, var(--p-ink) 5%, transparent); + transition-duration: var(--m-in); + } + } + + .pg-nav-item[aria-current="page"] { + color: var(--p-ink); + background-color: var(--p-active); + } + + .pg-nav-item[aria-current="page"] svg { + color: var(--p-accent); + } + + .pg-nav-item[aria-current="page"]::before { + content: ""; + position: absolute; + top: 9px; + bottom: 9px; + left: -12px; + width: 2px; + border-radius: 0 2px 2px 0; + background-color: var(--p-accent); + } + + .pg-nav-item--rail { + justify-content: center; + width: 44px; + min-height: 40px; + padding: 0; + margin-inline: auto; + } + + .pg-nav-item--rail[aria-current="page"]::before { + left: -10px; + } + + /* Rail tooltips: shown on hover and keyboard focus */ + .pg-nav-item[data-tip]::after { + content: attr(data-tip); + position: absolute; + top: 50%; + left: calc(100% + 12px); + z-index: var(--z-menu); + padding: 6px 10px; + border-radius: var(--r-sm); + border: 1px solid var(--p-line-strong); + background-color: var(--p-surface-2); + color: var(--p-ink); + font-size: 13px; + white-space: nowrap; + pointer-events: none; + opacity: 0; + transform: translate(-4px, -50%); + transition: + opacity var(--m-out) var(--ease), + transform var(--m-out) var(--ease); + } + + .pg-nav-item[data-tip]:hover::after, + .pg-nav-item[data-tip]:focus-visible::after { + opacity: 1; + transform: translate(0, -50%); + transition-duration: var(--m-in); + } + + .pg-nav-count { + display: inline-flex; + align-items: center; + justify-content: center; + min-width: 20px; + height: 20px; + margin-left: auto; + padding: 0 6px; + border-radius: var(--r-sm); + border: 1px solid var(--st-down-line); + background-color: var(--st-down-bg); + color: var(--st-down); + font-family: var(--font-mono); + font-size: 12px; + line-height: 1; + } + + .pg-nav-count--rail { + position: absolute; + top: -2px; + right: -4px; + min-width: 18px; + height: 18px; + padding: 0 4px; + font-size: 11px; + } + + @media (pointer: coarse) { + .pg-nav-item { + min-height: 44px; + } + } + + .pg-drawer { + position: fixed; + top: 0; + bottom: 0; + left: 0; + z-index: var(--z-drawer); + width: min(320px, 86vw); + border-right: 1px solid var(--p-line-strong); + background-color: var(--p-surface); + transform: translateX(-100%); + visibility: hidden; + transition: + transform var(--m-slide) var(--ease), + visibility 0s linear var(--m-slide); + } + + .pg-drawer[data-open="true"] { + transform: none; + visibility: visible; + transition: transform var(--m-slide) var(--ease); + } + + .pg-drawer-backdrop { + position: fixed; + inset: 0; + z-index: calc(var(--z-drawer) - 1); + background: rgb(4 8 4 / 0.62); + opacity: 0; + pointer-events: none; + transition: opacity var(--m-slide) var(--ease); + } + + .pg-drawer-backdrop[data-open="true"] { + opacity: 1; + pointer-events: auto; + } + + .pg-search-trigger { + display: inline-flex; + align-items: center; + justify-content: center; + gap: 8px; + width: 44px; + height: 38px; + flex-shrink: 0; + padding: 0; + border-radius: var(--r-md); + border: 1px solid var(--p-line-strong); + background-color: var(--p-surface); + color: var(--p-muted); + font-family: var(--font-text); + font-size: 14px; + cursor: pointer; + transition: + border-color var(--m-out) var(--ease), + color var(--m-out) var(--ease); + } + + @media (min-width: 640px) { + .pg-search-trigger { + justify-content: flex-start; + width: 260px; + padding: 0 6px 0 12px; + } + } + + @media (pointer: coarse) { + .pg-search-trigger { + height: 44px; + } + } + + @media (hover: hover) and (pointer: fine) { + .pg-search-trigger:hover { + border-color: color-mix(in srgb, var(--p-ink) 38%, transparent); + color: var(--p-ink); + transition-duration: var(--m-in); + } + } + + .pg-crumb { + color: var(--p-muted); + text-decoration: none; + transition: color var(--m-out) var(--ease); + } + + @media (hover: hover) and (pointer: fine) { + .pg-crumb:hover { + color: var(--p-ink); + text-decoration: underline; + text-underline-offset: 4px; + } + } + + .pg-command { + width: min(640px, calc(100vw - 24px)); + margin-top: 12vh; + } + + .pg-command .pg-menu-item { + min-height: 42px; + } +} + +@keyframes pg-menu-in { + from { + opacity: 0; + transform: translateY(-6px); + } + to { + opacity: 1; + transform: translateY(0); + } +} + +@keyframes pg-shimmer { + from { + background-position: 100% 0; + } + to { + background-position: -100% 0; + } } /* Subtle entrance for top-level views (once on mount) */ diff --git a/web/src/lib/status-themes.ts b/web/src/lib/status-themes.ts index f76ff42..bfa51e6 100644 --- a/web/src/lib/status-themes.ts +++ b/web/src/lib/status-themes.ts @@ -24,13 +24,13 @@ export interface BarStyleOption { export const COLOR_THEMES: ColorThemeOption[] = [ { id: "forest", - label: "Forest Dark", + label: "Forest", mode: "dark", bg: "#0f1f10", surface: "#162a17", ink: "#ffffff", accent: "#c6f19d", - description: "Deep forest canvas with pale lime telemetry", + description: "Deep green ground with a pale lime accent", }, { id: "dark", @@ -40,57 +40,57 @@ export const COLOR_THEMES: ColorThemeOption[] = [ surface: "#13181c", ink: "#f4f7f9", accent: "#34d399", - description: "Charcoal neutral ground with emerald signals", + description: "Neutral charcoal with emerald status colors", }, { id: "slate", - label: "Midnight Slate", + label: "Midnight slate", mode: "dark", bg: "#0d1520", surface: "#142030", ink: "#f0f6fc", accent: "#38bdf8", - description: "Deep maritime slate with sky blue highlights", + description: "Navy slate with a sky blue accent", }, { id: "terminal", - label: "CRT Amber", + label: "Amber terminal", mode: "dark", bg: "#0e0d0a", surface: "#171510", ink: "#f7f3e8", accent: "#f3c969", - description: "Warm instrument ink with amber phosphor accents", + description: "Warm near-black with an amber accent", }, { id: "light", - label: "Paper Light", + label: "Paper light", mode: "light", bg: "#f6f8f5", surface: "#ffffff", ink: "#0f1f10", accent: "#1f5c2e", - description: "Warm off-white editorial surface with deep forest ink", + description: "Soft off-white with deep forest ink", }, { id: "minimal-light", - label: "Pure White", + label: "Pure white", mode: "light", bg: "#ffffff", surface: "#f7f9f8", ink: "#11181c", accent: "#0f766e", - description: "Crisp white canvas with clean teal status tones", + description: "Crisp white with teal status colors", }, { id: "system", - label: "System Auto", + label: "Match system", mode: "system", bg: "#0f1f10", surface: "#f6f8f5", ink: "#ffffff", accent: "#c6f19d", - description: "Follows each visitor's OS light or dark preference", + description: "Follows each visitor's light or dark preference", }, ]; @@ -98,42 +98,40 @@ export const LAYOUT_THEMES: LayoutThemeOption[] = [ { id: "classic", label: "Classic", - summary: "Editorial cards per category with full uptime history bars", + summary: "A card per section with full uptime history under every component", }, { id: "signal", label: "Signal", - summary: - "Compact operational hierarchy with section rollups and collapsible rows", + summary: "Dense rows with section rollups; sections collapse to their status", }, { id: "flat", label: "Flat", - summary: "Minimal border-ruled layout with crisp 1px dividers and no cards", + summary: "No cards: sections separated by thin rules and plenty of space", }, { id: "spark", label: "Spark", - summary: - "Incident-first dashboard with live KPI summary strip and 2-column grid", + summary: "Key numbers up top, then components in a two-column grid", }, ]; export const BAR_STYLES: BarStyleOption[] = [ { id: "bars", - label: "Classic Bars", - summary: "Distinct vertical bars per day", + label: "Bars", + summary: "One rounded bar per day", }, { id: "signal", - label: "Signal Ribbon", - summary: "Connected seamless segments for matching status runs", + label: "Ribbon", + summary: "One continuous strip; days with the same status merge", }, { id: "blocks", - label: "Compact Blocks", - summary: "Sharp-cornered dense telemetry blocks", + label: "Blocks", + summary: "Small square blocks for a denser history", }, ]; diff --git a/web/src/lib/time.ts b/web/src/lib/time.ts new file mode 100644 index 0000000..03e7279 --- /dev/null +++ b/web/src/lib/time.ts @@ -0,0 +1,19 @@ +/** Compact duration: "45s", "12m", "2h 10m", "3d 4h". Negative input counts as zero. */ +export function formatDuration(ms: number): string { + const s = Math.max(0, Math.round(ms / 1000)); + const m = Math.floor(s / 60); + const h = Math.floor(m / 60); + const d = Math.floor(h / 24); + if (d > 0) return `${d}d ${h % 24}h`; + if (h > 0) return `${h}h ${m % 60}m`; + if (m > 0) return `${m}m`; + return `${s}s`; +} + +/** Time since an ISO timestamp: "just now", "3m ago", "2h 10m ago"; future times read "in 5m". */ +export function relativeTime(iso: string): string { + const diff = Date.now() - new Date(iso).getTime(); + if (Number.isNaN(diff)) return ""; + if (Math.abs(diff) < 45_000) return "just now"; + return diff > 0 ? `${formatDuration(diff)} ago` : `in ${formatDuration(-diff)}`; +} diff --git a/web/src/pages/AdminPage.tsx b/web/src/pages/AdminPage.tsx index 29d1bc0..d409638 100644 --- a/web/src/pages/AdminPage.tsx +++ b/web/src/pages/AdminPage.tsx @@ -1,17 +1,39 @@ -import { Ban, ShieldCheck } from "lucide-react"; +import { Ban, Building2, MoreHorizontal, ShieldCheck, ShieldOff, UserCheck, Users } from "lucide-react"; import { useEffect, useState } from "react"; -import { - type AdminOrg, - type AdminStats, - type AdminUser, - api, -} from "../lib/api"; +import { Dialog } from "../components/Dialog"; +import { EmptyState } from "../components/EmptyState"; +import { Menu } from "../components/Menu"; +import { PageHeader } from "../components/PageHeader"; +import { type AdminOrg, type AdminStats, type AdminUser, api } from "../lib/api"; +import { relativeTime } from "../lib/time"; + +type PendingAction = { kind: "ban" | "role"; user: AdminUser }; + +const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? "" : "s"}`; + +function Tag({ tone, children }: { tone: "warn" | "down"; children: string }) { + return ( + + {children} + + ); +} export function AdminPage({ currentUserId }: { currentUserId: string }) { const [stats, setStats] = useState(null); - const [users, setUsers] = useState([]); - const [orgs, setOrgs] = useState([]); + const [users, setUsers] = useState(null); + const [orgs, setOrgs] = useState(null); const [error, setError] = useState(null); + const [pending, setPending] = useState(null); + const [actionBusy, setActionBusy] = useState(false); + const [actionError, setActionError] = useState(null); const load = () => { Promise.all([ @@ -23,8 +45,9 @@ export function AdminPage({ currentUserId }: { currentUserId: string }) { setStats(s); setUsers(u); setOrgs(o); + setError(null); }) - .catch((e) => setError(e.message)); + .catch((e) => setError(e instanceof Error ? e.message : "Could not load admin data")); }; useEffect(load, []); @@ -35,7 +58,6 @@ export function AdminPage({ currentUserId }: { currentUserId: string }) { method: "PATCH", body: JSON.stringify({ role: nextRole }), }); - load(); }; const toggleBan = async (u: AdminUser) => { @@ -46,225 +68,351 @@ export function AdminPage({ currentUserId }: { currentUserId: string }) { reason: "Updated by Server Admin", }), }); - load(); }; - if (error) { - return ( -
- {error} -
- ); - } + const run = async (fn: () => Promise) => { + setActionBusy(true); + setActionError(null); + try { + await fn(); + setPending(null); + load(); + } catch (err) { + setActionError(err instanceof Error ? err.message : "Action failed"); + } finally { + setActionBusy(false); + } + }; + + const statItems = [ + { label: "Users", value: stats ? String(stats.total_users) : null }, + { label: "Organizations", value: stats ? String(stats.total_organizations) : null }, + { label: "Monitors", value: stats ? String(stats.total_monitors) : null }, + { + label: "Probes online", + value: stats ? `${stats.online_workers} / ${stats.total_workers}` : null, + }, + { + label: "Checks, last 24h", + value: stats ? stats.checks_last_24h.toLocaleString() : null, + }, + ]; + + const pendingUser = pending?.user; + const promoting = pendingUser?.role !== "admin"; return (
-
+ + Instance admin + + } + title="Server admin" + description="Users, organizations, probes and check volume across this whole Uptime instance." + /> + + {error && (
- Instance-wide governance + {error} +
-

- Server admin console -

-

- Manage users, organizations, global probes, and check volume across - this Uptime instance. -

-
+ )} - {/* Unified KPI strip */} -
-
-
+ {/* Stats strip */} +
+
+ {statItems.map((s, i) => ( +
+
+ {s.label} +
+
+ {s.value ?? } +
+
+ ))} +
+
+ + {/* Users */} +
+
+

Users -

-
- {stats?.total_users ?? 0} -
-
-
-
- Organizations -
-
- {stats?.total_organizations ?? 0} -
-
-
-
- Monitors -
-
- {stats?.total_monitors ?? 0} -
+ + {users && ( + + {users.length} + + )}
-
-
- Checks (24h) + {users === null ? ( +
    + {[0, 1, 2].map((i) => ( +
  • +
    +
    +
  • + ))} +
+ ) : users.length === 0 ? ( +
+ + People appear here once they register on this instance. +
-
- {stats?.checks_last_24h ?? 0} -
-
-
- - {/* Users Directory */} -
-
-

- Server users ({users.length}) -

-
-
- {users.map((u) => ( -
-
-
- {u.name} - {u.role === "admin" && ( - - Server admin - - )} - {u.banned && ( - - Banned - - )} -
-
+ {users.map((u) => { + const isSelf = u.id === currentUserId; + return ( +
  • - {u.email} · {u.org_count} org{u.org_count === 1 ? "" : "s"} -
  • -
    - - {u.id !== currentUserId && ( -
    - - -
    - )} -
    - ))} -
    + Joined + {relativeTime(u.created_at)} +
    +
    + {!isSelf && ( + { + setActionError(null); + setPending({ kind: "role", user: u }); + }, + } + : { + label: "Make server admin", + icon: ShieldCheck, + onSelect: () => { + setActionError(null); + setPending({ kind: "role", user: u }); + }, + }, + { separator: true }, + u.banned + ? { + label: "Unban user", + icon: UserCheck, + onSelect: () => run(() => toggleBan(u)), + } + : { + label: "Ban user", + icon: Ban, + danger: true, + onSelect: () => { + setActionError(null); + setPending({ kind: "ban", user: u }); + }, + }, + ]} + > + + + )} +
    + + ); + })} + + )} + {actionError && !pending && ( +

    + {actionError} +

    + )} - {/* Organizations Directory */} -
    + {/* Organizations */} +
    +
    +

    + Organizations +

    + {orgs && ( + + {orgs.length} + + )} +
    -
    - {orgs.map((o) => ( -
    -
    -
    {o.name}
    -
    - {o.slug ?? "—"} -
    -
    -
    + {[0, 1].map((i) => ( +
  • +
    +
    +
  • + ))} + + ) : orgs.length === 0 ? ( +
    + + Workspaces appear here once someone creates one. + +
    + ) : ( +
      + {orgs.map((o) => ( +
    • - - {o.member_count} member{o.member_count === 1 ? "" : "s"} + {o.name} + + {o.slug ?? "No slug"} - - {o.monitor_count} monitor{o.monitor_count === 1 ? "" : "s"} + + {plural(o.member_count, "member")} + {o.member_count} -
    -
    - ))} -
    + + {plural(o.monitor_count, "monitor")} + {o.monitor_count} + + + Created + {relativeTime(o.created_at)} + + + ))} + + )}
    + + setPending(null)} + title={ + pending?.kind === "ban" + ? "Ban user" + : promoting + ? "Make server admin" + : "Remove server admin" + } + description={ + pendingUser + ? pending?.kind === "ban" + ? `${pendingUser.name} cannot sign in until you unban them.` + : promoting + ? `${pendingUser.name} gets full control of this instance: every user, organization and global probe.` + : `${pendingUser.name} keeps their workspace roles but loses instance-wide admin access.` + : undefined + } + > + {actionError && ( +

    + {actionError} +

    + )} +
    + + +
    +
    ); } diff --git a/web/src/pages/AuthPage.tsx b/web/src/pages/AuthPage.tsx index ba9e672..88c5d71 100644 --- a/web/src/pages/AuthPage.tsx +++ b/web/src/pages/AuthPage.tsx @@ -1,5 +1,5 @@ -import { KeyRound, ShieldCheck } from "lucide-react"; -import { useEffect, useState } from "react"; +import { Eye, EyeOff, KeyRound, ShieldCheck } from "lucide-react"; +import { type ReactNode, useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import { ArrowGlyph, BrandMark } from "../components/BrandMark"; import { type AuthProvidersResponse, api } from "../lib/api"; @@ -7,9 +7,9 @@ import { authClient } from "../lib/auth-client"; const CAPABILITIES = [ { - code: "16 protocols", + code: "17 monitor types", detail: - "HTTP(S), multi-step synthetic, TCP/UDP, ICMP, gRPC, DNS, TLS, RDAP, heartbeats, and 4 game server engines.", + "HTTP(S), keyword and JSON checks, multi-step synthetic, TCP/UDP, ICMP, gRPC, DNS, TLS and domain expiry, heartbeats, status feeds and 4 game server engines.", }, { code: "WebSocket sync", @@ -19,10 +19,27 @@ const CAPABILITIES = [ { code: "Region quorum", detail: - "Multi-region confirmation, scheduled maintenance suppression, and Prometheus metrics built in.", + "Multi-region confirmation, scheduled maintenance suppression and Prometheus metrics built in.", }, ]; +function FormError({ children, id }: { children: ReactNode; id?: string }) { + return ( + + ); +} + export function AuthPage({ mode, onSuccess, @@ -34,7 +51,9 @@ export function AuthPage({ const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); + const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); + const [ssoPending, setSsoPending] = useState(null); const [error, setError] = useState(null); // OIDC / Social providers discovered from auth service @@ -58,6 +77,11 @@ export function AuthPage({ .catch(() => {}); }, []); + // Clear a stale error when switching between sign in and register. + useEffect(() => { + setError(null); + }, [mode]); + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); @@ -127,6 +151,7 @@ export function AuthPage({ const handleSsoSignIn = async (providerId: string) => { setError(null); + setSsoPending(providerId); try { const res = await authClient.signIn.social({ provider: providerId, @@ -134,110 +159,63 @@ export function AuthPage({ }); if (res.error) { setError(res.error.message || `SSO sign-in failed (${providerId})`); + setSsoPending(null); } } catch (err) { setError(err instanceof Error ? err.message : "SSO redirect failed"); + setSsoPending(null); } }; + const isRegister = mode === "register"; + const errorId = "auth-error"; + return (
    - {/* Left editorial & telemetry column */} -
    -
    + {/* Authentication surface: first on mobile, right column on desktop */} +
    +
    - - Uptime - -
    - -
    -

    - Distributed uptime monitoring for ops teams. -

    -

    - Self-hosted Rust probes, TimescaleDB latency history, and public - status pages in one workspace. -

    - -
    - {CAPABILITIES.map((cap) => ( -
    -
    - {cap.code} -
    -
    - {cap.detail} -
    -
    - ))} -
    -
    - -
    - PostgreSQL + TimescaleDB · Better Auth RBAC + OIDC/2FA · Axum WebSocket - Hub + Uptime
    -
    - {/* Right authentication surface */} -
    -
    +
    {needsTwoFactor ? ( <>
    - +
    -

    - {useBackupCode - ? "Enter a backup code" - : "Enter authenticator code"} -

    +

    + {useBackupCode ? "Enter a backup code" : "Enter authenticator code"} +

    {useBackupCode - ? "Use one of your saved single-use recovery codes to complete sign-in." - : "Open your TOTP authenticator app and enter the 6-digit code for Uptime."} + ? "Use one of your saved single-use recovery codes to finish signing in." + : "Open your authenticator app and enter the 6-digit code for Uptime."}

    -
    +
    setTotpCode(e.target.value)} placeholder={useBackupCode ? "xxxx-xxxx" : "123456"} + aria-invalid={error ? true : undefined} + aria-describedby={error ? errorId : undefined} className="pg-input font-mono text-[16px] tracking-[0.14em]" />
    -
    + {isRegister ? "Already have an account?" : "Need a workspace account?"}{" "} + +

    )} )}
    + + {/* Product summary: below the form on mobile, left column on desktop */} +
    +
    + + Uptime +
    + +
    +

    + Distributed uptime monitoring for ops teams. +

    +

    + Self-hosted Rust probes, long-term latency history and public status + pages in one workspace. +

    + +
    + {CAPABILITIES.map((cap) => ( +
    +
    + {cap.code} +
    +
    + {cap.detail} +
    +
    + ))} +
    +
    +
    ); } diff --git a/web/src/pages/IncidentsPage.tsx b/web/src/pages/IncidentsPage.tsx index 4fc38f4..acc962f 100644 --- a/web/src/pages/IncidentsPage.tsx +++ b/web/src/pages/IncidentsPage.tsx @@ -1,247 +1,489 @@ -import { AlertTriangle, CheckCircle2, Pencil } from "lucide-react"; -import { useEffect, useState } from "react"; +import { AlertTriangle, CheckCircle2, Pencil, Siren } from "lucide-react"; +import { type FormEvent, useEffect, useMemo, useRef, useState } from "react"; +import { Link } from "react-router-dom"; import { ArrowGlyph } from "../components/BrandMark"; -import { type IncidentDetail, type IncidentItem, api } from "../lib/api"; +import { Dialog } from "../components/Dialog"; +import { EmptyState } from "../components/EmptyState"; +import { PageHeader } from "../components/PageHeader"; +import { + type IncidentDetail, + type IncidentItem, + type MonitorItem, + api, +} from "../lib/api"; +import { formatDuration, relativeTime } from "../lib/time"; + +type Tone = "up" | "warn" | "down" | "info" | "muted"; +type Filter = "open" | "resolved" | "all"; + +const SEVERITY_TONE: Record = { + critical: "down", + major: "warn", + minor: "info", +}; + +const STATUS_TONE: Record = { + investigating: "down", + acknowledged: "warn", + identified: "warn", + monitoring: "info", + resolved: "up", +}; + +const UPDATE_STATUSES = [ + "investigating", + "acknowledged", + "identified", + "monitoring", + "resolved", +] as const; + +function toneStyle(tone: Tone) { + if (tone === "muted") { + return { color: "var(--p-muted)", backgroundColor: "var(--p-hover)", borderColor: "var(--p-line)" }; + } + return { + color: `var(--st-${tone})`, + backgroundColor: `var(--st-${tone}-bg)`, + borderColor: `var(--st-${tone}-line)`, + }; +} + +function Pill({ tone, children }: { tone: Tone; children: string }) { + return ( + + + ); +} + +function fullDate(iso: string) { + return new Date(iso).toLocaleString(); +} + +function ErrorLine({ children }: { children: string }) { + return ( +

    + {children} +

    + ); +} + +function errText(err: unknown, fallback: string) { + return err instanceof Error ? err.message : fallback; +} export function IncidentsPage({ liveTick }: { liveTick: number }) { - const [incidents, setIncidents] = useState([]); + const [incidents, setIncidents] = useState(null); + const [listError, setListError] = useState(null); + const [monitors, setMonitors] = useState([]); + const [filter, setFilter] = useState("open"); const [selected, setSelected] = useState(null); + const [detailError, setDetailError] = useState(null); + const [showNew, setShowNew] = useState(false); const [title, setTitle] = useState(""); const [severity, setSeverity] = useState("major"); const [message, setMessage] = useState(""); + const [createError, setCreateError] = useState(null); + const [creating, setCreating] = useState(false); + const [updateStatus, setUpdateStatus] = useState("identified"); const [updateMsg, setUpdateMsg] = useState(""); + const [posting, setPosting] = useState(false); + const [updateError, setUpdateError] = useState(null); + const [editing, setEditing] = useState(false); const [editTitle, setEditTitle] = useState(""); const [editSeverity, setEditSeverity] = useState("major"); + const [editError, setEditError] = useState(null); + + const [resolveOpen, setResolveOpen] = useState(false); + const [resolveMsg, setResolveMsg] = useState(""); + const [resolveError, setResolveError] = useState(null); + const [resolving, setResolving] = useState(false); + + const detailRef = useRef(null); + const selectedId = selected?.id; const load = () => { - api("/api/v1/incidents").then(setIncidents).catch(() => {}); + api("/api/v1/incidents") + .then((rows) => { + setIncidents(rows); + setListError(null); + }) + .catch((err) => { + setIncidents((prev) => prev ?? []); + setListError(errText(err, "Could not load incidents")); + }); }; - useEffect(load, [liveTick]); - - const openDetail = async (id: string) => { - const d = await api(`/api/v1/incidents/${id}`); - setSelected(d); - setEditing(false); - setEditTitle(d.title); - setEditSeverity(d.severity); + + // biome-ignore lint/correctness/useExhaustiveDependencies: reload on live ticks + useEffect(() => { + load(); + if (selectedId) { + api(`/api/v1/incidents/${selectedId}`) + .then(setSelected) + .catch(() => {}); + } + }, [liveTick]); + + useEffect(() => { + api("/api/v1/monitors").then(setMonitors).catch(() => {}); + }, []); + + const monitorNames = useMemo( + () => new Map(monitors.map((m) => [m.id, m.name])), + [monitors], + ); + + const counts = useMemo(() => { + const list = incidents ?? []; + const open = list.filter((i) => !i.resolved_at).length; + return { open, resolved: list.length - open, all: list.length }; + }, [incidents]); + + const visible = useMemo(() => { + const list = incidents ?? []; + if (filter === "open") return list.filter((i) => !i.resolved_at); + if (filter === "resolved") return list.filter((i) => i.resolved_at); + return list; + }, [incidents, filter]); + + const openDetail = async (id: string, reveal = false) => { + try { + const d = await api(`/api/v1/incidents/${id}`); + setSelected(d); + setDetailError(null); + setEditing(false); + setEditError(null); + setUpdateError(null); + setEditTitle(d.title); + setEditSeverity(d.severity); + if (reveal && window.matchMedia("(max-width: 1023px)").matches) { + requestAnimationFrame(() => detailRef.current?.scrollIntoView({ block: "start" })); + } + } catch (err) { + setDetailError(errText(err, "Could not load the incident")); + } }; - const handleSaveEdit = async (e: React.FormEvent) => { + const handleSaveEdit = async (e: FormEvent) => { e.preventDefault(); if (!selected) return; - await api(`/api/v1/incidents/${selected.id}`, { - method: "PATCH", - body: JSON.stringify({ title: editTitle, severity: editSeverity }), - }); - setEditing(false); - await openDetail(selected.id); - load(); + setEditError(null); + try { + await api(`/api/v1/incidents/${selected.id}`, { + method: "PATCH", + body: JSON.stringify({ title: editTitle, severity: editSeverity }), + }); + setEditing(false); + await openDetail(selected.id); + load(); + } catch (err) { + setEditError(errText(err, "Could not save the incident")); + } }; - const handleCreate = async (e: React.FormEvent) => { + const handleCreate = async (e: FormEvent) => { e.preventDefault(); - const created = await api("/api/v1/incidents", { - method: "POST", - body: JSON.stringify({ - title, - severity, - status: "investigating", - message, - }), - }); - setShowNew(false); - setTitle(""); - setMessage(""); - setSelected(created); - load(); + setCreateError(null); + setCreating(true); + try { + const created = await api("/api/v1/incidents", { + method: "POST", + body: JSON.stringify({ + title, + severity, + status: "investigating", + message, + }), + }); + setShowNew(false); + setTitle(""); + setMessage(""); + setSelected(created); + setEditTitle(created.title); + setEditSeverity(created.severity); + setFilter((f) => (f === "resolved" ? "open" : f)); + load(); + } catch (err) { + setCreateError(errText(err, "Could not declare the incident")); + } finally { + setCreating(false); + } }; - const handlePostUpdate = async (e: React.FormEvent) => { - e.preventDefault(); + const postUpdate = async (status: string, msg: string) => { if (!selected) return; await api(`/api/v1/incidents/${selected.id}/updates`, { method: "POST", - body: JSON.stringify({ status: updateStatus, message: updateMsg }), + body: JSON.stringify({ status, message: msg }), }); - setUpdateMsg(""); await openDetail(selected.id); load(); }; + const handlePostUpdate = async (e: FormEvent) => { + e.preventDefault(); + setUpdateError(null); + setPosting(true); + try { + await postUpdate(updateStatus, updateMsg); + setUpdateMsg(""); + } catch (err) { + setUpdateError(errText(err, "Could not post the update")); + } finally { + setPosting(false); + } + }; + + const handleResolve = async (e: FormEvent) => { + e.preventDefault(); + setResolveError(null); + setResolving(true); + try { + await postUpdate("resolved", resolveMsg); + setResolveOpen(false); + setResolveMsg(""); + } catch (err) { + setResolveError(errText(err, "Could not resolve the incident")); + } finally { + setResolving(false); + } + }; + + const now = Date.now(); + const filters: Array<{ id: Filter; label: string; count: number }> = [ + { id: "open", label: "Open", count: counts.open }, + { id: "resolved", label: "Resolved", count: counts.resolved }, + { id: "all", label: "All", count: counts.all }, + ]; + return (
    -
    -
    -

    Incidents

    -

    { + setCreateError(null); + setShowNew(true); + }} + className="pg-btn pg-btn--primary" > - Opened automatically on multi-region quorum failures, AlertManager - webhooks, or declared manually for status pages. -

    -
    - -
    + Declare incident + + + } + /> - {showNew && ( - -

    Declare incident

    -
    -
    - - setTitle(e.target.value)} - placeholder="Elevated API timeouts in eu-central" - className="pg-input" - /> -
    -
    - - -
    + setShowNew(false)} + title="Declare incident" + description="It starts as investigating. Post more updates from its timeline as you learn more." + > + +
    + + setTitle(e.target.value)} + placeholder="Elevated API timeouts in eu-central" + className="pg-input" + /> +
    +
    + +