diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..9c45a50 --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,21 @@ +{ + "permissions": { + "allow": [ + "Bash(bash \"C:/Users/Hendrik/.claude/plugins/cache/claude-plugins-official/superpowers/5.0.4/skills/brainstorming/scripts/start-server.sh\" --project-dir \"C:/Users/Hendrik/Documents/projects/design-system\")", + "Bash(npm create:*)", + "Bash(node:*)", + "Bash(npm show:*)", + "Bash(npm install:*)", + "Bash(npm audit:*)", + "Bash(timeout 10 npm run dev)", + "Bash(npx vitest:*)", + "Bash(npx tsc:*)", + "Bash(npm run:*)", + "Bash(find C:/Users/Hendrik/Documents/projects/design-system/.worktrees/gap-fill -name *.test.tsx)", + "Bash(echo \"EXIT:$?\")", + "Bash(bash \"C:\\\\Users\\\\Hendrik\\\\.claude\\\\plugins\\\\cache\\\\claude-plugins-official\\\\superpowers\\\\5.0.4\\\\scripts\\\\start-server.sh\" --project-dir \"C:\\\\Users\\\\Hendrik\\\\Documents\\\\projects\\\\design-system\")", + "Bash(echo \"EXIT_CODE=$?\")", + "Bash(echo \"EXIT=$?\")" + ] + } +} diff --git a/COMPONENT_GUIDE.md b/COMPONENT_GUIDE.md index b78b474..c380d29 100644 --- a/COMPONENT_GUIDE.md +++ b/COMPONENT_GUIDE.md @@ -34,10 +34,10 @@ - Removable label → **Tag** ### "I need navigation" -- App-level sidebar nav → **Sidebar** (via AppShell) +- App-level sidebar nav → **Sidebar** (via AppShell) — hierarchical trees with starring - Breadcrumb trail → **Breadcrumb** - Paginated data → **Pagination** (standalone) or **DataTable** (built-in pagination) -- Hierarchical tree navigation → **TreeView** +- Hierarchical tree navigation → **TreeView** (generic) or **SidebarTree** (sidebar-specific, internal) ### "I need floating content" - Tooltip on hover → **Tooltip** @@ -186,7 +186,7 @@ TreeView for hierarchical data (Application → Routes → Processors) | Component | Purpose | |-----------|---------| | AppShell | Page shell: sidebar + topbar + main + optional detail panel | -| Sidebar | App navigation with apps, routes, agents sections | +| Sidebar | Hierarchical navigation with Applications/Agents trees, starring, search filter, bottom links. Props: `apps: SidebarApp[]` (hierarchical — apps contain routes and agents) | | TopBar | Header bar with breadcrumb, environment, user info | ## Import Paths diff --git a/docs/superpowers/specs/2026-03-18-sidebar-redesign.md b/docs/superpowers/specs/2026-03-18-sidebar-redesign.md new file mode 100644 index 0000000..a4ca09d --- /dev/null +++ b/docs/superpowers/specs/2026-03-18-sidebar-redesign.md @@ -0,0 +1,307 @@ +# Sidebar Redesign — Hierarchical Navigation with Starring + +## Context + +The Cameleer3 Sidebar currently renders flat lists of applications, routes, and agents as separate sections. This doesn't reflect the hierarchical relationship in Apache Camel where routes and agents belong to applications. The redesign restructures navigation into expandable trees, adds a starring/favorites system, and adds bottom navigation links (Admin, API Docs). + +This project is primarily a design system with a mock application showcasing how all pieces come together. Stub pages will be created for new routes to demonstrate the full navigation flow. + +## Sidebar Structure + +``` +┌─────────────────────────┐ +│ cameleer v3.2.1 │ Logo (fixed) +├─────────────────────────┤ +│ Filter... │ Search (fixed) +├─────────────────────────┤ +│ NAVIGATION │ Section header +│ │ +│ ▾ Applications │ Tree (expandable) +│ ● order-svc 1.2k │ App (health dot + exchangeCount) +│ ▶ ingest 540 │ Route (arrow + exchangeCount) +│ ▶ notify 320 │ +│ ● payment-svc 800 │ +│ ▶ validate 800 │ +│ │ +│ ▾ Agents │ Tree (expandable) +│ ● order-svc 2/3 live│ App (health dot + live count) +│ agent-1 42 tps │ Agent (name + tps) +│ agent-2 38 tps │ +│ ● payment-svc 1/1 ...│ +│ agent-3 12 tps │ +│ │ +│ ▦ Dashboards │ Standalone nav link (not a tree node) +│ ↕ scrollable │ +├─────────────────────────┤ +│ ★ STARRED │ Section header (hidden when empty) +│ Applications │ Group label +│ ● order-svc │ +│ Routes │ Group label +│ ▶ ingest │ +│ Agents │ Group label +│ agent-prod-1 │ +│ ↕ scrollable │ +├─────────────────────────┤ +│ ⚙ Admin │ Bottom link → /admin (fixed) +│ 📄 API Docs │ Bottom link → /api-docs (fixed) +└─────────────────────────┘ +``` + +**Width:** 220px (unchanged) + +**Scroll regions:** +- Navigation: `flex: 1; overflow-y: auto; min-height: 0` +- Starred: `max-height: 30vh; overflow-y: auto` (entire section hidden when no items are starred) +- Logo, Search, Bottom: fixed (`flex-shrink: 0`) + +## Data Model + +### New interfaces (replace current flat App/Route/Agent) + +```ts +interface SidebarApp { + id: string + name: string + health: 'live' | 'stale' | 'dead' + exchangeCount: number + routes: SidebarRoute[] + agents: SidebarAgent[] +} + +interface SidebarRoute { + id: string + name: string + exchangeCount: number +} + +interface SidebarAgent { + id: string + name: string + status: 'live' | 'stale' | 'dead' + tps: string +} + +interface SidebarProps { + apps: SidebarApp[] + activeItemId?: string // highlighted item; derived from URL if omitted + className?: string +} +``` + +**Key changes from current:** +- Routes and agents nested inside apps (was: three flat arrays) +- `onItemClick` removed — Sidebar navigates internally via `useNavigate()` +- Active item derived from `useLocation().pathname` if `activeItemId` not provided +- Route health is out of scope — routes show a static arrow icon (no StatusDot) + +### Agent type migration + +The current `src/mocks/agents.ts` has `AgentHealth extends Agent` where `Agent` is imported from Sidebar. Since `SidebarAgent` is now a minimal type (just id, name, status, tps), `AgentHealth` must become self-contained: + +```ts +// src/mocks/agents.ts — no longer extends Sidebar's Agent type +export interface AgentHealth { + id: string + name: string + service: string + version: string + tps: string + lastSeen: string + status: 'live' | 'stale' | 'dead' + errorRate?: string + uptime: string + memoryUsagePct: number + cpuUsagePct: number + activeRoutes: number + totalRoutes: number +} +``` + +## Components + +### SidebarTree (`src/design-system/layout/Sidebar/SidebarTree.tsx`) + +A sidebar-specific tree component. NOT the generic TreeView — optimized for sidebar rendering with health dots, count badges, and star buttons. + +**Props:** +```ts +interface SidebarTreeNode { + id: string + label: string + icon?: ReactNode // StatusDot, arrow icon, etc. + badge?: string // right-aligned text ("1.2k", "42 tps", "2/3 live") + path?: string // navigation path on click + starrable?: boolean // whether star toggle appears (default false) + children?: SidebarTreeNode[] +} + +interface SidebarTreeProps { + nodes: SidebarTreeNode[] + selectedId?: string + isStarred: (id: string) => boolean + onToggleStar: (id: string) => void + onNavigate?: (path: string) => void + className?: string + filterQuery?: string // when set, auto-expands matching parents +} +``` + +**Styling:** All SidebarTree styles go in `Sidebar.module.css` (SidebarTree is a private component of Sidebar, not independently used). + +**Behaviors:** +- **Expand/collapse:** Chevron click only. Row click navigates (if `path` set). +- **Parent nodes without `path`:** Click does nothing (only chevron toggles). The "Applications" and "Agents" root headers are not clickable or starrable — they're just section labels with a toggle chevron. +- **Star toggle:** Star icon appears on hover (right side, after badge). Filled star always visible on starred items. Click stops propagation (doesn't navigate). +- **Leaf nodes with no children:** Render without chevron. App nodes with empty `routes[]` or `agents[]` render as leaf nodes (no expand arrow). +- **Search filter:** When `filterQuery` is set, only nodes matching the query (or with matching descendants) are shown. Matching parents auto-expand. When no matches, the tree is empty (the Sidebar shows a "No results" message). +- **Keyboard nav:** ArrowUp/Down to move focus, ArrowRight to expand, ArrowLeft to collapse, Enter to navigate/select, Home/End to jump. +- **ARIA:** `role="tree"`, `role="treeitem"`, `aria-expanded`, `aria-selected`. +- **Styling:** Uses `--sidebar-*` CSS tokens. Active item gets amber highlight. + +### useStarred (`src/design-system/layout/Sidebar/useStarred.ts`) + +```ts +function useStarred(): { + starredIds: Set + isStarred: (id: string) => boolean + toggleStar: (id: string) => void +} +``` + +- Reads/writes `localStorage` key `"cameleer:starred"` (JSON string array) +- Returns a `Set` for O(1) lookups +- `toggleStar` updates both React state and localStorage +- **Error handling:** Wraps `localStorage` read/write in try/catch — falls back to in-memory state if localStorage is unavailable (private browsing, quota exceeded) +- Cross-tab sync is out of scope for now + +### Sidebar (rewritten) + +The Sidebar assembles the SidebarTree data from `SidebarApp[]` props: + +1. **Applications tree:** Maps each app to a parent node with route children. App nodes show `StatusDot` + name + exchangeCount badge. Route nodes show arrow icon + name + exchangeCount badge. Both apps and routes are `starrable: true`. + +2. **Agents tree:** Maps each app to a parent node with agent children. App nodes show `StatusDot` + name + "X/Y live" badge (computed: count agents where `status === 'live'` / total agents). Agent nodes show name + tps badge. Both apps and agents are `starrable: true`. + +3. **Dashboards:** A standalone nav link (not part of any tree), rendered as a simple clickable row below the trees. Uses `▦` icon. Note: the current top-level Metrics and Agents nav links are intentionally removed — Metrics will be displayed contextually within app/route/agent detail views, and Agents are accessible via the Agents tree. + +4. **Starred section:** Reads `starredIds` from `useStarred()`, looks up items in the apps data, groups by type (Applications, Routes, Agents in that order). Orphaned IDs (starred item no longer in data) are silently ignored. If a starred app appears in both the Applications and Agents trees, it shows only under "Applications" in the starred section. The entire section (header + content) is hidden when no items are starred. + +5. **Search:** Filters both trees. When query matches a route/agent name, its parent app stays visible and auto-expands. Placeholder text: "Filter...". On clear, restore previous expand/collapse state. + +## Star Icon + +Inline SVG (no icon library). Outline star for unstarred, filled star for starred. Amber color (`var(--amber)`). + +```html + + + + + + + + + +``` + +**Visibility rules:** +- Unstarred items: star appears on row `:hover` only +- Starred items: filled star always visible +- Star button: `opacity: 0` → `opacity: 1` on hover transition (0.15s) + +## Navigation Paths + +| Item type | Click navigates to | Route exists? | +|-----------|-------------------|---------------| +| App (in Applications tree) | `/apps/{id}` | New stub page | +| Route | `/routes/{id}` | Existing | +| App (in Agents tree) | `/apps/{id}` | Same stub page | +| Agent | `/agents/{id}` | New — currently only `/agents` (list) exists | +| Dashboards | `/` | Existing (Dashboard) | +| Admin | `/admin` | New stub page | +| API Docs | `/api-docs` | New stub page | + +### Stub pages needed + +Minimal placeholder pages using the design system's `EmptyState` component: + +- **AppDetail** (`src/pages/AppDetail/AppDetail.tsx`) — route `/apps/:id`, shows app name from URL param + EmptyState "App detail coming soon" +- **AgentDetail** (`src/pages/AgentDetail/AgentDetail.tsx`) — route `/agents/:id`, shows agent name + EmptyState +- **Admin** (`src/pages/Admin/Admin.tsx`) — route `/admin`, EmptyState "Admin panel coming soon" +- **ApiDocs** (`src/pages/ApiDocs/ApiDocs.tsx`) — route `/api-docs`, EmptyState "API documentation coming soon" + +All stub pages use `` with `` to demonstrate the full navigation flow. + +## Search Behavior + +- Case-insensitive substring match on node labels +- When a child matches, its parent node is shown and auto-expanded +- When no matches, show "No results" text in the navigation area +- Search clears when input is emptied +- On clear, restore previous expand/collapse state +- Search filters both the Applications and Agents trees simultaneously + +## Mock Data + +### New file: `src/mocks/sidebar.ts` + +Exports `SIDEBAR_APPS: SidebarApp[]` — consolidates the duplicated APPS, SIDEBAR_ROUTES, and agents data currently scattered across 6 page files. Each app contains its routes and agents nested inside. + +All consumer pages + Inventory demo will import from this single source. + +## Files to Create + +| File | Purpose | +|------|---------| +| `src/design-system/layout/Sidebar/SidebarTree.tsx` | Tree component with health dots, badges, star toggle | +| `src/design-system/layout/Sidebar/useStarred.ts` | localStorage hook for starred item IDs | +| `src/mocks/sidebar.ts` | Shared hierarchical sidebar mock data | +| `src/pages/AppDetail/AppDetail.tsx` | Stub page for `/apps/:id` | +| `src/pages/AgentDetail/AgentDetail.tsx` | Stub page for `/agents/:id` | +| `src/pages/Admin/Admin.tsx` | Stub page for `/admin` | +| `src/pages/ApiDocs/ApiDocs.tsx` | Stub page for `/api-docs` | +| `src/design-system/layout/Sidebar/Sidebar.test.tsx` | Tests for Sidebar | +| `src/design-system/layout/Sidebar/useStarred.test.ts` | Tests for useStarred hook | + +## Files to Modify + +| File | Changes | +|------|---------| +| `src/design-system/layout/Sidebar/Sidebar.tsx` | Rewrite: new props, SidebarTree, starred section, bottom links | +| `src/design-system/layout/Sidebar/Sidebar.module.css` | Add tree styles, starred section, star button, bottom links, SidebarTree styles | +| `src/design-system/layout/index.ts` | Export new types (SidebarApp, SidebarRoute, SidebarAgent) | +| `src/App.tsx` | Add routes: `/apps/:id`, `/agents/:id`, `/admin`, `/api-docs` | +| `src/pages/Dashboard/Dashboard.tsx` | Simplify to `` | +| `src/pages/RouteDetail/RouteDetail.tsx` | Same simplification | +| `src/pages/ExchangeDetail/ExchangeDetail.tsx` | Same simplification | +| `src/pages/AgentHealth/AgentHealth.tsx` | Same simplification | +| `src/pages/Metrics/Metrics.tsx` | Same simplification | +| `src/pages/Inventory/sections/LayoutSection.tsx` | Update demo data to hierarchical shape | +| `src/mocks/agents.ts` | Make AgentHealth self-contained (no longer extends Sidebar's Agent) | +| `COMPONENT_GUIDE.md` | Update Sidebar and navigation descriptions | + +## Implementation Order + +1. **Mock data** (`src/mocks/sidebar.ts`) — needed for development and testing +2. **Agent type fix** (`src/mocks/agents.ts`) — make AgentHealth self-contained +3. **useStarred hook** + tests — standalone, no dependencies +4. **SidebarTree component** — depends on useStarred interface +5. **Sidebar rewrite** + CSS — composes SidebarTree + useStarred +6. **Stub pages** — AppDetail, AgentDetail, Admin, ApiDocs +7. **App.tsx routes** — register new routes +8. **Consumer migration** — update all 6 pages to use `` +9. **Inventory update** — update LayoutSection demo data +10. **Type exports** — update layout barrel export +11. **Sidebar tests** — integration tests for Sidebar component +12. **Docs** — update COMPONENT_GUIDE.md + +## Verification + +1. `npx tsc --noEmit` — zero TypeScript errors +2. `npx vitest run` — all tests pass (existing + new) +3. `npm run build` — clean Vite build +4. Manual: open `/inventory` → Layout section → verify Sidebar demo renders correctly +5. Manual: open `/` → verify sidebar trees expand/collapse, starring persists across refresh, search filters both trees, navigation to all routes works +6. Manual: verify starred section hides when empty, shows grouped items when populated +7. Manual: verify dark theme rendering (sidebar uses `--sidebar-*` tokens) +8. `grep -r "onItemClick\|routes={.*SIDEBAR\|agents={.*agents" src/design-system/layout/Sidebar/` — zero hits (old API removed) diff --git a/src/App.tsx b/src/App.tsx index 2107880..763d8f6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,6 +5,10 @@ import { RouteDetail } from './pages/RouteDetail/RouteDetail' import { ExchangeDetail } from './pages/ExchangeDetail/ExchangeDetail' import { AgentHealth } from './pages/AgentHealth/AgentHealth' import { Inventory } from './pages/Inventory/Inventory' +import { AppDetail } from './pages/AppDetail/AppDetail' +import { AgentDetail } from './pages/AgentDetail/AgentDetail' +import { Admin } from './pages/Admin/Admin' +import { ApiDocs } from './pages/ApiDocs/ApiDocs' export default function App() { return ( @@ -14,6 +18,10 @@ export default function App() { } /> } /> } /> + } /> + } /> + } /> + } /> } /> ) diff --git a/src/design-system/layout/Sidebar/Sidebar.module.css b/src/design-system/layout/Sidebar/Sidebar.module.css index 6cede03..943b64a 100644 --- a/src/design-system/layout/Sidebar/Sidebar.module.css +++ b/src/design-system/layout/Sidebar/Sidebar.module.css @@ -1,5 +1,5 @@ .sidebar { - width: 220px; + width: 260px; flex-shrink: 0; background: var(--sidebar-bg); display: flex; @@ -102,7 +102,7 @@ padding: 0 6px; } -/* Nav item */ +/* Nav item (flat links like Dashboards) */ .item { display: flex; align-items: center; @@ -129,16 +129,6 @@ border-left-color: var(--amber); } -.item.active .itemCount { - background: rgba(198, 130, 14, 0.2); - color: var(--amber-light); -} - -/* Indented route items */ -.indented { - padding-left: 22px; -} - .navIcon { font-size: 14px; width: 18px; @@ -154,6 +144,7 @@ .routeArrow { color: var(--sidebar-muted); font-size: 10px; + flex-shrink: 0; } /* Item sub-elements */ @@ -169,143 +160,278 @@ text-overflow: ellipsis; } -.itemMeta { - font-size: 11px; +/* No results */ +.noResults { + padding: 16px 18px; + font-size: 12px; color: var(--sidebar-muted); - font-family: var(--font-mono); + text-align: center; } -.itemCount { - font-family: var(--font-mono); - font-size: 11px; - color: var(--sidebar-muted); - background: rgba(255, 255, 255, 0.06); - padding: 1px 6px; - border-radius: 10px; - flex-shrink: 0; +/* ── SidebarTree styles ──────────────────────────────────────────────────── */ + +.treeSection { + padding: 0 6px; + margin-bottom: 4px; } -/* Health dots */ -.healthDot { - width: 7px; - height: 7px; - border-radius: 50%; - flex-shrink: 0; -} - -.healthLive { - background: #5db866; - box-shadow: 0 0 6px rgba(93, 184, 102, 0.4); -} - -.healthStale { - background: var(--warning); -} - -.healthDead { - background: var(--sidebar-muted); -} - -/* Divider */ -.divider { - height: 1px; - background: rgba(255, 255, 255, 0.06); - margin: 6px 12px; -} - -/* Agents header */ -.agentsHeader { - padding: 14px 12px 6px; +.treeSectionLabel { + padding: 10px 12px 4px; font-size: 10px; font-weight: 600; text-transform: uppercase; - letter-spacing: 1.2px; + letter-spacing: 1px; color: var(--sidebar-muted); - display: flex; - align-items: center; - justify-content: space-between; - flex-shrink: 0; } -.agentBadge { - font-family: var(--font-mono); +/* Collapsible section toggle */ +.treeSectionToggle { + display: flex; + align-items: center; + gap: 6px; + width: 100%; + padding: 8px 12px 4px; font-size: 10px; - padding: 1px 6px; - border-radius: 10px; - background: rgba(93, 184, 102, 0.15); - color: #5db866; + font-weight: 600; + text-transform: uppercase; + letter-spacing: 1px; + color: var(--sidebar-muted); + background: none; + border: none; + cursor: pointer; + text-align: left; + transition: color 0.12s; } -/* Agents list */ -.agentsList { - padding: 0 0 6px; - overflow-y: auto; - max-height: 180px; - flex-shrink: 0; +.treeSectionToggle:hover { + color: var(--sidebar-text); } -.agentItem { +.treeSectionChevron { + font-size: 9px; + width: 10px; + display: inline-flex; + align-items: center; + justify-content: center; +} + +.tree { + list-style: none; + margin: 0; + padding: 0; +} + +.treeGroup { + list-style: none; + margin: 0; + padding: 0; +} + +.treeRow { display: flex; align-items: center; - gap: 8px; - padding: 6px 12px; - margin: 0 6px 2px; + gap: 6px; + padding: 5px 8px; border-radius: var(--radius-sm); - font-size: 11px; color: var(--sidebar-text); - transition: background 0.1s; + font-size: 12px; + cursor: pointer; + transition: background 0.12s; + border-left: 3px solid transparent; + margin-bottom: 1px; + user-select: none; + position: relative; } -.agentItem:hover { +.treeRow:hover { background: var(--sidebar-hover); } -.agentDot { - width: 6px; - height: 6px; - border-radius: 50%; - flex-shrink: 0; +.treeRowActive { + background: var(--sidebar-active); + color: var(--amber-light); + border-left-color: var(--amber); } -.agentInfo { +.treeRowActive .treeBadge { + background: rgba(198, 130, 14, 0.2); + color: var(--amber-light); +} + +/* Chevron */ +.treeChevronSlot { + width: 14px; + flex-shrink: 0; + display: flex; + align-items: center; + justify-content: center; +} + +.treeChevron { + background: none; + border: none; + padding: 0; + margin: 0; + color: var(--sidebar-muted); + font-size: 11px; + cursor: pointer; + line-height: 1; + display: flex; + align-items: center; + justify-content: center; +} + +.treeChevron:hover { + color: var(--sidebar-text); +} + +/* Icon slot */ +.treeIcon { + flex-shrink: 0; + display: flex; + align-items: center; +} + +/* Label */ +.treeLabel { flex: 1; min-width: 0; -} - -.agentName { - font-family: var(--font-mono); - font-size: 11px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } -.agentDetail { - font-size: 10px; - color: var(--sidebar-muted); -} - -.agentStats { - text-align: right; +/* Badge */ +.treeBadge { font-family: var(--font-mono); font-size: 10px; color: var(--sidebar-muted); + background: rgba(255, 255, 255, 0.06); + padding: 1px 6px; + border-radius: 10px; + flex-shrink: 0; + white-space: nowrap; } -.agentTps { - color: var(--sidebar-text); -} - -.agentLastSeen { +/* Star button */ +.treeStar { + background: none; + border: none; + padding: 0; + margin: 0; color: var(--sidebar-muted); + cursor: pointer; + opacity: 0; + transition: opacity 0.15s, color 0.15s; + display: flex; + align-items: center; + flex-shrink: 0; } -.agentError { +.treeStarActive { + opacity: 1; + color: var(--amber); +} + +.treeRow:hover .treeStar { + opacity: 1; +} + +.treeStar:hover { + color: var(--amber-light); +} + +/* ── Starred section ─────────────────────────────────────────────────────── */ + +.starredSection { + border-top: 1px solid rgba(255, 255, 255, 0.06); + margin-top: 4px; +} + +.starredHeader { + color: var(--amber); +} + +.starredList { + padding: 0 6px 6px; +} + +.starredGroup { + margin-bottom: 4px; +} + +.starredGroupLabel { + padding: 4px 12px 2px; + font-size: 10px; + color: var(--sidebar-muted); + font-weight: 500; +} + +.starredItem { + display: flex; + align-items: center; + gap: 8px; + padding: 4px 12px; + border-radius: var(--radius-sm); + color: var(--sidebar-text); + font-size: 12px; + cursor: pointer; + transition: background 0.12s; + user-select: none; +} + +.starredItem:hover { + background: var(--sidebar-hover); +} + +.starredItemInfo { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; +} + +.starredItemName { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + font-weight: 500; +} + +.starredItemContext { + font-size: 10px; + color: var(--sidebar-muted); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +/* Remove button */ +.starredRemove { + background: none; + border: none; + padding: 2px; + margin: 0; + color: var(--sidebar-muted); + cursor: pointer; + opacity: 0; + transition: opacity 0.15s, color 0.15s; + display: flex; + align-items: center; + flex-shrink: 0; +} + +.starredItem:hover .starredRemove { + opacity: 1; +} + +.starredRemove:hover { color: var(--error); } -/* Bottom links */ +/* ── Bottom links ────────────────────────────────────────────────────────── */ + .bottom { border-top: 1px solid rgba(255, 255, 255, 0.06); padding: 6px; @@ -331,6 +457,12 @@ color: var(--sidebar-text); } +.bottomItemActive { + background: var(--sidebar-active); + color: var(--amber-light); + border-left-color: var(--amber); +} + .bottomIcon { font-size: 13px; width: 18px; diff --git a/src/design-system/layout/Sidebar/Sidebar.test.tsx b/src/design-system/layout/Sidebar/Sidebar.test.tsx new file mode 100644 index 0000000..4a519b5 --- /dev/null +++ b/src/design-system/layout/Sidebar/Sidebar.test.tsx @@ -0,0 +1,172 @@ +import { describe, it, expect, beforeEach } from 'vitest' +import { render, screen } from '@testing-library/react' +import userEvent from '@testing-library/user-event' +import { MemoryRouter } from 'react-router-dom' +import { Sidebar, type SidebarApp } from './Sidebar' +import { ThemeProvider } from '../../providers/ThemeProvider' + +const TEST_APPS: SidebarApp[] = [ + { + id: 'order-service', + name: 'order-service', + health: 'live', + exchangeCount: 1433, + routes: [ + { id: 'order-intake', name: 'order-intake', exchangeCount: 892 }, + { id: 'order-enrichment', name: 'order-enrichment', exchangeCount: 541 }, + ], + agents: [ + { id: 'prod-1', name: 'prod-1', status: 'live', tps: '14.2/s' }, + { id: 'prod-2', name: 'prod-2', status: 'live', tps: '11.8/s' }, + ], + }, + { + id: 'payment-svc', + name: 'payment-svc', + health: 'live', + exchangeCount: 912, + routes: [ + { id: 'payment-process', name: 'payment-process', exchangeCount: 414 }, + ], + agents: [], + }, +] + +function renderSidebar(props: Partial[0]> = {}) { + return render( + + + + + , + ) +} + +describe('Sidebar', () => { + beforeEach(() => { + localStorage.clear() + sessionStorage.clear() + }) + + it('renders the logo and brand name', () => { + renderSidebar() + expect(screen.getByText('cameleer')).toBeInTheDocument() + expect(screen.getByText('v3.2.1')).toBeInTheDocument() + }) + + it('renders the search input', () => { + renderSidebar() + expect(screen.getByPlaceholderText('Filter...')).toBeInTheDocument() + }) + + it('renders Navigation section header', () => { + renderSidebar() + expect(screen.getByText('Navigation')).toBeInTheDocument() + }) + + it('renders Applications tree section', () => { + renderSidebar() + expect(screen.getByText('Applications')).toBeInTheDocument() + }) + + it('renders Agents tree section', () => { + renderSidebar() + expect(screen.getByText('Agents')).toBeInTheDocument() + }) + + it('renders Dashboards nav link', () => { + renderSidebar() + expect(screen.getByText('Dashboards')).toBeInTheDocument() + }) + + it('renders bottom links', () => { + renderSidebar() + expect(screen.getByText('Admin')).toBeInTheDocument() + expect(screen.getByText('API Docs')).toBeInTheDocument() + }) + + it('renders app names in the Applications tree', () => { + renderSidebar() + // order-service appears in both Applications and Agents trees + expect(screen.getAllByText('order-service').length).toBeGreaterThanOrEqual(1) + expect(screen.getByText('payment-svc')).toBeInTheDocument() + }) + + it('renders exchange count badges', () => { + renderSidebar() + expect(screen.getByText('1.4k')).toBeInTheDocument() + }) + + it('renders agent live count badge in Agents tree', () => { + renderSidebar() + expect(screen.getByText('2/2 live')).toBeInTheDocument() + }) + + it('does not show starred section when nothing is starred', () => { + renderSidebar() + expect(screen.queryByText('★ Starred')).not.toBeInTheDocument() + }) + + it('shows starred section after starring an item', async () => { + const user = userEvent.setup() + renderSidebar() + + // Find the first app row (order-service in Applications tree) and hover to reveal star + const appRows = screen.getAllByText('order-service') + const appRow = appRows[0].closest('[role="treeitem"]')! + await user.hover(appRow) + + // Click the star button + const starBtn = appRow.querySelector('button[aria-label="Add to starred"]')! + await user.click(starBtn) + + expect(screen.getByText('★ Starred')).toBeInTheDocument() + }) + + it('filters tree items by search', async () => { + const user = userEvent.setup() + renderSidebar() + + const searchInput = screen.getByPlaceholderText('Filter...') + await user.type(searchInput, 'payment') + + // payment-svc should still be visible + expect(screen.getByText('payment-svc')).toBeInTheDocument() + }) + + it('expands tree to show children when chevron is clicked', async () => { + const user = userEvent.setup() + renderSidebar() + + // Find the expand button for order-service in Applications tree + const expandBtns = screen.getAllByLabelText('Expand') + await user.click(expandBtns[0]) + + // Routes should now be visible + expect(screen.getByText('order-intake')).toBeInTheDocument() + expect(screen.getByText('order-enrichment')).toBeInTheDocument() + }) + + it('collapses expanded tree when chevron is clicked again', async () => { + const user = userEvent.setup() + renderSidebar() + + const expandBtns = screen.getAllByLabelText('Expand') + await user.click(expandBtns[0]) + expect(screen.getByText('order-intake')).toBeInTheDocument() + + const collapseBtn = screen.getByLabelText('Collapse') + await user.click(collapseBtn) + expect(screen.queryByText('order-intake')).not.toBeInTheDocument() + }) + + it('does not render apps with no agents in the Agents tree', () => { + renderSidebar() + // payment-svc has no agents, so it shouldn't appear under the Agents section header + // But it still appears under Applications. Let's check the agent tree specifically. + const agentBadges = screen.queryAllByText(/\/.*live/) + // Only order-service should have an agent badge + expect(agentBadges).toHaveLength(1) + expect(agentBadges[0].textContent).toBe('2/2 live') + }) +}) diff --git a/src/design-system/layout/Sidebar/Sidebar.tsx b/src/design-system/layout/Sidebar/Sidebar.tsx index 616feb9..1bc4ed6 100644 --- a/src/design-system/layout/Sidebar/Sidebar.tsx +++ b/src/design-system/layout/Sidebar/Sidebar.tsx @@ -1,89 +1,222 @@ -import { useState } from 'react' +import { useState, useMemo } from 'react' import { useNavigate, useLocation } from 'react-router-dom' import styles from './Sidebar.module.css' import camelLogoUrl from '../../../assets/camel-logo.svg' +import { SidebarTree, type SidebarTreeNode } from './SidebarTree' +import { useStarred } from './useStarred' +import { StatusDot } from '../../primitives/StatusDot/StatusDot' -export interface App { +// ── Types ──────────────────────────────────────────────────────────────────── + +export interface SidebarApp { id: string name: string - agentCount: number health: 'live' | 'stale' | 'dead' exchangeCount: number + routes: SidebarRoute[] + agents: SidebarAgent[] } -export interface Route { +export interface SidebarRoute { id: string name: string exchangeCount: number } -export interface Agent { +export interface SidebarAgent { id: string name: string - service: string - version: string - tps: string - lastSeen: string status: 'live' | 'stale' | 'dead' - errorRate?: string + tps: string } interface SidebarProps { - apps: App[] - routes: Route[] - agents: Agent[] - activeItem?: string - onItemClick?: (id: string) => void + apps: SidebarApp[] + className?: string } -function HealthDot({ status }: { status: 'live' | 'stale' | 'dead' }) { +// ── Helpers ────────────────────────────────────────────────────────────────── + +function formatCount(n: number): string { + if (n >= 1000) return `${(n / 1000).toFixed(1)}k` + return String(n) +} + +function buildAppTreeNodes(apps: SidebarApp[]): SidebarTreeNode[] { + return apps.map((app) => ({ + id: `app:${app.id}`, + label: app.name, + icon: , + badge: formatCount(app.exchangeCount), + path: `/apps/${app.id}`, + starrable: true, + starKey: app.id, + children: app.routes.map((route) => ({ + id: `route:${app.id}:${route.id}`, + starKey: `${app.id}:${route.id}`, + label: route.name, + icon: , + badge: formatCount(route.exchangeCount), + path: `/routes/${route.id}`, + starrable: true, + })), + })) +} + +function buildAgentTreeNodes(apps: SidebarApp[]): SidebarTreeNode[] { + return apps + .filter((app) => app.agents.length > 0) + .map((app) => { + const liveCount = app.agents.filter((a) => a.status === 'live').length + return { + id: `agents:${app.id}`, + label: app.name, + icon: , + badge: `${liveCount}/${app.agents.length} live`, + path: `/agents/${app.id}`, + starrable: true, + starKey: `agents:${app.id}`, + children: app.agents.map((agent) => ({ + id: `agent:${app.id}:${agent.id}`, + starKey: `${app.id}:${agent.id}`, + label: agent.name, + badge: agent.tps, + path: `/agents/${agent.id}`, + starrable: true, + })), + } + }) +} + +// ── Starred section helpers ────────────────────────────────────────────────── + +interface StarredItem { + starKey: string + label: string + icon?: React.ReactNode + path: string + type: 'application' | 'route' | 'agent' + parentApp?: string +} + +function collectStarredItems(apps: SidebarApp[], starredIds: Set): StarredItem[] { + const items: StarredItem[] = [] + + for (const app of apps) { + if (starredIds.has(app.id)) { + items.push({ + starKey: app.id, + label: app.name, + icon: , + path: `/apps/${app.id}`, + type: 'application', + }) + } + for (const route of app.routes) { + const key = `${app.id}:${route.id}` + if (starredIds.has(key)) { + items.push({ + starKey: key, + label: route.name, + path: `/routes/${route.id}`, + type: 'route', + parentApp: app.name, + }) + } + } + for (const agent of app.agents) { + const key = `${app.id}:${agent.id}` + if (starredIds.has(key)) { + items.push({ + starKey: key, + label: agent.name, + path: `/agents/${agent.id}`, + type: 'agent', + parentApp: app.name, + }) + } + } + } + + return items +} + +// ── StarredGroup ───────────────────────────────────────────────────────────── + +function StarredGroup({ + label, + items, + onNavigate, + onRemove, +}: { + label: string + items: StarredItem[] + onNavigate: (path: string) => void + onRemove: (starKey: string) => void +}) { return ( - +
+
{label}
+ {items.map((item) => ( +
onNavigate(item.path)} + role="button" + tabIndex={0} + onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') onNavigate(item.path) }} + > + {item.icon} +
+ {item.label} + {item.parentApp && ( + {item.parentApp} + )} +
+ +
+ ))} +
) } -interface NavItem { - id: string - label: string - path: string - icon: string -} +// ── Sidebar ────────────────────────────────────────────────────────────────── -const NAV_ITEMS: NavItem[] = [ - { id: 'dashboard', label: 'Dashboard', path: '/', icon: '▦' }, - { id: 'metrics', label: 'Metrics', path: '/metrics', icon: '◔' }, - { id: 'agents', label: 'Agents', path: '/agents', icon: '⬡' }, -] - -export function Sidebar({ - apps, - routes, - agents, - activeItem, - onItemClick, -}: SidebarProps) { +export function Sidebar({ apps, className }: SidebarProps) { const [search, setSearch] = useState('') + const [appsCollapsed, setAppsCollapsed] = useState(false) + const [agentsCollapsed, setAgentsCollapsed] = useState(false) const navigate = useNavigate() const location = useLocation() + const { starredIds, isStarred, toggleStar } = useStarred() - const liveCount = agents.filter((a) => a.status === 'live').length - const agentBadge = `${liveCount}/${agents.length} live` + // Build tree data + const appNodes = useMemo(() => buildAppTreeNodes(apps), [apps]) + const agentNodes = useMemo(() => buildAgentTreeNodes(apps), [apps]) - const filteredApps = search - ? apps.filter((a) => a.name.toLowerCase().includes(search.toLowerCase())) - : apps + // Build starred items + const starredItems = useMemo( + () => collectStarredItems(apps, starredIds), + [apps, starredIds], + ) + + const starredApps = starredItems.filter((i) => i.type === 'application') + const starredRoutes = starredItems.filter((i) => i.type === 'route') + const starredAgents = starredItems.filter((i) => i.type === 'agent') + const hasStarred = starredItems.length > 0 return ( -