wulf-pulse/components/ui/multi-select.tsx
lorentz 9bfb57553d feat(design): nav/visual overhaul — brand layer, /status route, KPI dashboard, TanStack DataTable
Major UI refresh on the nav-design-improvements branch.  Drops 2013-era
inline styles and consolidates patterns behind shared primitives.

Foundation
- New Wulf brand layer in app/styles/brand.css repointing --primary to
  the standards-guide blue (#0075AD) with utility classes for numerics
  (.num / .num-lg / .num-xl), metric labels, surface tints, and the
  wolf-mark watermark
- Switch primary face to IBM Plex Sans + IBM Plex Mono via next/font;
  Helvetica/Arial stays in the fallback chain for brand fidelity
- Wordmark subtitle changed from "PSA Management System" to
  "Operations console" everywhere it appeared
- Tagline footer ("Don't be afraid to cry") on every non-mobile page

Status moved out of /dashboard
- New /status route with integration tiles grouped by category, sync
  health table, worker pulse cards (analyzer / RMM / sync scheduler),
  token-expiry section, conditional alert banner
- Top-bar StatusIndicator polls integration health every 60s and links
  to /status
- INTEGRATIONS_DISABLED env var suppresses operator-disabled
  integrations (e.g. SentinelOne) — no failure noise from broken-on-
  purpose entries.  Aliases supported (sentinelone → s1, etc.)

Dashboard rebuilt around KPIs
- /api/dashboard/overview adds today snapshot (opened, resolved, open
  total, SLA breaches) with delta math
- /api/dashboard/trends backs queue × priority heatmap, 30-day volume
  area chart, 30-day mean resolution time line chart, today's active
  engineers leaderboard

Components
- StatusBadge driven by lib/status-registry.ts (priority, ticket
  status, classification, source, company type, publish, active /
  yes-no / billable / approved registries)
- StatusLight (8px geometric square, five states, three sizes)
- EmptyState (shared dashed panel with icon + headline + optional CTA)
- KpiCard with delta indicator and tonal left border
- WulfMark (mark / wordmark variants from /public/branding)
- Skeleton helpers (SkeletonRow / Rows / Card / Chart / Header / Table)

Navigation
- Admin flat link → dropdown with seven shortcuts
- New UserMenu (initials avatar, role badge, settings + sign-out)
- Active-route highlight is now a 2px Wulf-blue underline echoing the
  PageHeader rule (consistent across flat links and submenu triggers);
  active children inside dropdowns use bg-primary/10
- Submenu width is content-driven (min-w 320 / max-w 440, single col)
- Mobile hamburger via Sheet, reuses the same nav config

Pages migrated
- 16 admin sub-pages adopt PageHeader (with accent prop)
- /addigy-devices: shadcn Table + Checkbox; PageHeader; status badges
- 10 raw <table> blocks across admin/sync/* migrated to shadcn Table
- /veeam-analysis migrated to shadcn Table (kept its expansion logic)
- Detail routes (analyzer ticket, analyzer analysis) get breadcrumbs

DataTable
- Rewritten on @tanstack/react-table v8 in manual mode; external API
  unchanged so all 10+ data-browser pages keep working
- New optional props for drill-down rows: getRowCanExpand + renderSubRow

Mobile
- Multi-select Popover gets max-w-[calc(100vw-1rem)] and
  collisionPadding so dropdowns can't overflow narrow viewports
- CI filter bar wraps and shrinks; stat pill flows below

Docs
- New ARCHITECTURE.md (load-bearing reference for runtime, data flow,
  workers, analyzer pipeline, auth, deployment, gotchas)
- New DESIGN.md (tokens, layout, navigation IA, component vocabulary,
  rolling backlog of remaining cleanup)
- CLAUDE.md refreshed with pointers to the two new docs and the
  INTEGRATIONS_DISABLED operator config note
- shadcn registry registered as project-level MCP server (.mcp.json)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 09:33:13 -04:00

163 lines
5 KiB
TypeScript

'use client';
import { useMemo, useState } from 'react';
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Badge } from '@/components/ui/badge';
import { Check, ChevronDown, Search, X } from 'lucide-react';
export interface MultiSelectOption {
value: string;
label: string;
}
interface Props {
options: MultiSelectOption[];
value: string[];
onChange: (next: string[]) => void;
placeholder?: string;
searchPlaceholder?: string;
className?: string;
/** Hide the search box when option count is below this threshold. */
searchThreshold?: number;
/** Optional max-height for the option list (px). */
maxListHeight?: number;
}
export function MultiSelect({
options,
value,
onChange,
placeholder = 'Any',
searchPlaceholder = 'Search…',
className = '',
searchThreshold = 8,
maxListHeight = 300,
}: Props) {
const [open, setOpen] = useState(false);
const [search, setSearch] = useState('');
const valueSet = useMemo(() => new Set(value), [value]);
const filtered = useMemo(() => {
const s = search.trim().toLowerCase();
if (!s) return options;
return options.filter((o) => o.label.toLowerCase().includes(s));
}, [options, search]);
const selectedLabels = useMemo(() => {
if (value.length === 0) return null;
if (value.length === 1) {
return options.find((o) => o.value === value[0])?.label ?? value[0];
}
return `${value.length} selected`;
}, [value, options]);
function toggle(optValue: string) {
if (valueSet.has(optValue)) {
onChange(value.filter((v) => v !== optValue));
} else {
onChange([...value, optValue]);
}
}
function clear(e: React.MouseEvent) {
e.stopPropagation();
onChange([]);
}
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
variant="outline"
className={`justify-between font-normal ${className}`}
>
<span className="truncate">
{selectedLabels ?? (
<span className="text-muted-foreground">{placeholder}</span>
)}
</span>
<span className="flex items-center gap-1 shrink-0 ml-2">
{value.length > 0 && (
<Badge
variant="secondary"
className="h-5 px-1.5 text-xs hover:bg-destructive hover:text-destructive-foreground"
onClick={clear}
>
<X className="w-3 h-3" />
</Badge>
)}
<ChevronDown className="w-4 h-4 opacity-50" />
</span>
</Button>
</PopoverTrigger>
<PopoverContent
className="p-0 w-[var(--radix-popover-trigger-width)] min-w-[260px] max-w-[calc(100vw-1rem)]"
align="start"
collisionPadding={8}
>
{options.length >= searchThreshold && (
<div className="p-2 border-b">
<div className="relative">
<Search className="w-4 h-4 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground" />
<Input
value={search}
onChange={(e) => setSearch(e.target.value)}
placeholder={searchPlaceholder}
className="pl-8 h-8"
/>
</div>
</div>
)}
<div
className="overflow-y-auto py-1"
style={{ maxHeight: maxListHeight }}
>
{filtered.length === 0 ? (
<div className="px-3 py-6 text-sm text-muted-foreground text-center">
No matches
</div>
) : (
filtered.map((opt) => {
const checked = valueSet.has(opt.value);
return (
<div
key={opt.value}
role="option"
aria-selected={checked}
tabIndex={0}
onClick={() => toggle(opt.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
toggle(opt.value);
}
}}
className="flex items-center gap-2 w-full px-3 py-1.5 text-sm hover:bg-accent cursor-pointer select-none focus:bg-accent focus:outline-none"
>
<span
className={`w-4 h-4 shrink-0 rounded-sm border flex items-center justify-center transition ${
checked
? 'bg-primary border-primary text-primary-foreground'
: 'border-input bg-background'
}`}
aria-hidden="true"
>
{checked && <Check className="w-3 h-3" strokeWidth={3} />}
</span>
<span className="truncate">{opt.label}</span>
</div>
);
})
)}
</div>
</PopoverContent>
</Popover>
);
}