Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bf4144380 | ||
|
|
dba3aa5a85 | ||
|
|
d775df61e4 | ||
|
|
7c6d383ac9 | ||
|
|
70a5106cca | ||
|
|
b0bd9a4ce2 | ||
|
|
df31ec55d8 | ||
|
|
2ed7f8bb0c | ||
|
|
90dee0f43e | ||
|
|
57d60bf2ed | ||
|
|
7e2fce8b14 | ||
|
|
96e5f77a14 | ||
|
|
1c2c00d266 | ||
|
|
70a4db94c1 | ||
|
|
83722aeb7c | ||
|
|
2709d4c164 | ||
|
|
549553c05b | ||
|
|
ac3b69f864 | ||
|
|
a62ff5b064 | ||
|
|
53a9ed015a | ||
|
|
38e42d10bb | ||
|
|
ae420246c8 | ||
|
|
7d9643bd1b | ||
|
|
99ff461d4d | ||
|
|
ce93ba456c | ||
|
|
3fc5fb8267 | ||
|
|
e07afe37f2 | ||
|
|
89453121a0 | ||
|
|
232868b9e7 | ||
|
|
8b32fe3994 | ||
|
|
250cbec7b7 | ||
|
|
dfac0db564 | ||
|
|
bb8e6d9d65 | ||
|
|
fd08d7a552 | ||
|
|
6ea2a29a7c | ||
|
|
51d5d9337a | ||
|
|
cd00a2e0fa | ||
|
|
b443fc787e | ||
|
|
4a6e6dea96 | ||
|
|
638b868649 |
2
.gitignore
vendored
@@ -1,7 +1,9 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
|
.claude/
|
||||||
.superpowers/
|
.superpowers/
|
||||||
.worktrees/
|
.worktrees/
|
||||||
test-results/
|
test-results/
|
||||||
screenshots/
|
screenshots/
|
||||||
.playwright-mcp/
|
.playwright-mcp/
|
||||||
|
.gitnexus
|
||||||
|
|||||||
101
AGENTS.md
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<!-- gitnexus:start -->
|
||||||
|
# GitNexus — Code Intelligence
|
||||||
|
|
||||||
|
This project is indexed by GitNexus as **design-system** (1536 symbols, 2408 relationships, 23 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.
|
||||||
|
|
||||||
|
> If any GitNexus tool warns the index is stale, run `npx gitnexus analyze` in terminal first.
|
||||||
|
|
||||||
|
## Always Do
|
||||||
|
|
||||||
|
- **MUST run impact analysis before editing any symbol.** Before modifying a function, class, or method, run `gitnexus_impact({target: "symbolName", direction: "upstream"})` and report the blast radius (direct callers, affected processes, risk level) to the user.
|
||||||
|
- **MUST run `gitnexus_detect_changes()` before committing** to verify your changes only affect expected symbols and execution flows.
|
||||||
|
- **MUST warn the user** if impact analysis returns HIGH or CRITICAL risk before proceeding with edits.
|
||||||
|
- When exploring unfamiliar code, use `gitnexus_query({query: "concept"})` to find execution flows instead of grepping. It returns process-grouped results ranked by relevance.
|
||||||
|
- When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use `gitnexus_context({name: "symbolName"})`.
|
||||||
|
|
||||||
|
## When Debugging
|
||||||
|
|
||||||
|
1. `gitnexus_query({query: "<error or symptom>"})` — find execution flows related to the issue
|
||||||
|
2. `gitnexus_context({name: "<suspect function>"})` — see all callers, callees, and process participation
|
||||||
|
3. `READ gitnexus://repo/design-system/process/{processName}` — trace the full execution flow step by step
|
||||||
|
4. For regressions: `gitnexus_detect_changes({scope: "compare", base_ref: "main"})` — see what your branch changed
|
||||||
|
|
||||||
|
## When Refactoring
|
||||||
|
|
||||||
|
- **Renaming**: MUST use `gitnexus_rename({symbol_name: "old", new_name: "new", dry_run: true})` first. Review the preview — graph edits are safe, text_search edits need manual review. Then run with `dry_run: false`.
|
||||||
|
- **Extracting/Splitting**: MUST run `gitnexus_context({name: "target"})` to see all incoming/outgoing refs, then `gitnexus_impact({target: "target", direction: "upstream"})` to find all external callers before moving code.
|
||||||
|
- After any refactor: run `gitnexus_detect_changes({scope: "all"})` to verify only expected files changed.
|
||||||
|
|
||||||
|
## Never Do
|
||||||
|
|
||||||
|
- NEVER edit a function, class, or method without first running `gitnexus_impact` on it.
|
||||||
|
- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis.
|
||||||
|
- NEVER rename symbols with find-and-replace — use `gitnexus_rename` which understands the call graph.
|
||||||
|
- NEVER commit changes without running `gitnexus_detect_changes()` to check affected scope.
|
||||||
|
|
||||||
|
## Tools Quick Reference
|
||||||
|
|
||||||
|
| Tool | When to use | Command |
|
||||||
|
|------|-------------|---------|
|
||||||
|
| `query` | Find code by concept | `gitnexus_query({query: "auth validation"})` |
|
||||||
|
| `context` | 360-degree view of one symbol | `gitnexus_context({name: "validateUser"})` |
|
||||||
|
| `impact` | Blast radius before editing | `gitnexus_impact({target: "X", direction: "upstream"})` |
|
||||||
|
| `detect_changes` | Pre-commit scope check | `gitnexus_detect_changes({scope: "staged"})` |
|
||||||
|
| `rename` | Safe multi-file rename | `gitnexus_rename({symbol_name: "old", new_name: "new", dry_run: true})` |
|
||||||
|
| `cypher` | Custom graph queries | `gitnexus_cypher({query: "MATCH ..."})` |
|
||||||
|
|
||||||
|
## Impact Risk Levels
|
||||||
|
|
||||||
|
| Depth | Meaning | Action |
|
||||||
|
|-------|---------|--------|
|
||||||
|
| d=1 | WILL BREAK — direct callers/importers | MUST update these |
|
||||||
|
| d=2 | LIKELY AFFECTED — indirect deps | Should test |
|
||||||
|
| d=3 | MAY NEED TESTING — transitive | Test if critical path |
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
| Resource | Use for |
|
||||||
|
|----------|---------|
|
||||||
|
| `gitnexus://repo/design-system/context` | Codebase overview, check index freshness |
|
||||||
|
| `gitnexus://repo/design-system/clusters` | All functional areas |
|
||||||
|
| `gitnexus://repo/design-system/processes` | All execution flows |
|
||||||
|
| `gitnexus://repo/design-system/process/{name}` | Step-by-step execution trace |
|
||||||
|
|
||||||
|
## Self-Check Before Finishing
|
||||||
|
|
||||||
|
Before completing any code modification task, verify:
|
||||||
|
1. `gitnexus_impact` was run for all modified symbols
|
||||||
|
2. No HIGH/CRITICAL risk warnings were ignored
|
||||||
|
3. `gitnexus_detect_changes()` confirms changes match expected scope
|
||||||
|
4. All d=1 (WILL BREAK) dependents were updated
|
||||||
|
|
||||||
|
## Keeping the Index Fresh
|
||||||
|
|
||||||
|
After committing code changes, the GitNexus index becomes stale. Re-run analyze to update it:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx gitnexus analyze
|
||||||
|
```
|
||||||
|
|
||||||
|
If the index previously included embeddings, preserve them by adding `--embeddings`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx gitnexus analyze --embeddings
|
||||||
|
```
|
||||||
|
|
||||||
|
To check whether embeddings exist, inspect `.gitnexus/meta.json` — the `stats.embeddings` field shows the count (0 means no embeddings). **Running analyze without `--embeddings` will delete any previously generated embeddings.**
|
||||||
|
|
||||||
|
> Claude Code users: A PostToolUse hook handles this automatically after `git commit` and `git merge`.
|
||||||
|
|
||||||
|
## CLI
|
||||||
|
|
||||||
|
| Task | Read this skill file |
|
||||||
|
|------|---------------------|
|
||||||
|
| Understand architecture / "How does X work?" | `.claude/skills/gitnexus/gitnexus-exploring/SKILL.md` |
|
||||||
|
| Blast radius / "What breaks if I change X?" | `.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md` |
|
||||||
|
| Trace bugs / "Why is X failing?" | `.claude/skills/gitnexus/gitnexus-debugging/SKILL.md` |
|
||||||
|
| Rename / extract / split / refactor | `.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md` |
|
||||||
|
| Tools, resources, schema reference | `.claude/skills/gitnexus/gitnexus-guide/SKILL.md` |
|
||||||
|
| Index, status, clean, wiki CLI commands | `.claude/skills/gitnexus/gitnexus-cli/SKILL.md` |
|
||||||
|
|
||||||
|
<!-- gitnexus:end -->
|
||||||
108
CLAUDE.md
@@ -37,8 +37,8 @@ Always read `COMPONENT_GUIDE.md` before building any UI feature. It contains dec
|
|||||||
### Import Paths
|
### Import Paths
|
||||||
```tsx
|
```tsx
|
||||||
import { Button, Input } from '../design-system/primitives'
|
import { Button, Input } from '../design-system/primitives'
|
||||||
import { Modal, DataTable, KpiStrip, SplitPane, EntityList, LogViewer } from '../design-system/composites'
|
import { Modal, DataTable, KpiStrip, SplitPane, EntityList, LogViewer, LineChart, AreaChart, BarChart } from '../design-system/composites'
|
||||||
import type { Column, KpiItem, LogEntry } from '../design-system/composites'
|
import type { Column, KpiItem, LogEntry, ChartSeries } from '../design-system/composites'
|
||||||
import { AppShell } from '../design-system/layout/AppShell'
|
import { AppShell } from '../design-system/layout/AppShell'
|
||||||
import { Sidebar } from '../design-system/layout/Sidebar/Sidebar'
|
import { Sidebar } from '../design-system/layout/Sidebar/Sidebar'
|
||||||
import { SidebarTree } from '../design-system/layout/Sidebar/SidebarTree'
|
import { SidebarTree } from '../design-system/layout/Sidebar/SidebarTree'
|
||||||
@@ -95,7 +95,7 @@ import { Button, AppShell, ThemeProvider } from '@cameleer/design-system'
|
|||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
// All components from single entry
|
// All components from single entry
|
||||||
import { Button, Input, Modal, DataTable, KpiStrip, SplitPane, EntityList, LogViewer, StatusText, AppShell } from '@cameleer/design-system'
|
import { Button, Input, Modal, DataTable, KpiStrip, SplitPane, EntityList, LogViewer, StatusText, AppShell, LineChart, AreaChart, BarChart } from '@cameleer/design-system'
|
||||||
|
|
||||||
// Sidebar (compound component — compose your own navigation)
|
// Sidebar (compound component — compose your own navigation)
|
||||||
import { Sidebar, SidebarTree, useStarred } from '@cameleer/design-system'
|
import { Sidebar, SidebarTree, useStarred } from '@cameleer/design-system'
|
||||||
@@ -128,3 +128,105 @@ import logo512 from '@cameleer/design-system/assets/cameleer3-512.png' // PWA
|
|||||||
import logoSvg from '@cameleer/design-system/assets/cameleer3-logo.svg' // high-detail SVG logo
|
import logoSvg from '@cameleer/design-system/assets/cameleer3-logo.svg' // high-detail SVG logo
|
||||||
import camelSvg from '@cameleer/design-system/assets/camel-logo.svg' // simplified camel SVG
|
import camelSvg from '@cameleer/design-system/assets/camel-logo.svg' // simplified camel SVG
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<!-- gitnexus:start -->
|
||||||
|
# GitNexus — Code Intelligence
|
||||||
|
|
||||||
|
This project is indexed by GitNexus as **design-system** (1536 symbols, 2408 relationships, 23 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.
|
||||||
|
|
||||||
|
> If any GitNexus tool warns the index is stale, run `npx gitnexus analyze` in terminal first.
|
||||||
|
|
||||||
|
## Always Do
|
||||||
|
|
||||||
|
- **MUST run impact analysis before editing any symbol.** Before modifying a function, class, or method, run `gitnexus_impact({target: "symbolName", direction: "upstream"})` and report the blast radius (direct callers, affected processes, risk level) to the user.
|
||||||
|
- **MUST run `gitnexus_detect_changes()` before committing** to verify your changes only affect expected symbols and execution flows.
|
||||||
|
- **MUST warn the user** if impact analysis returns HIGH or CRITICAL risk before proceeding with edits.
|
||||||
|
- When exploring unfamiliar code, use `gitnexus_query({query: "concept"})` to find execution flows instead of grepping. It returns process-grouped results ranked by relevance.
|
||||||
|
- When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use `gitnexus_context({name: "symbolName"})`.
|
||||||
|
|
||||||
|
## When Debugging
|
||||||
|
|
||||||
|
1. `gitnexus_query({query: "<error or symptom>"})` — find execution flows related to the issue
|
||||||
|
2. `gitnexus_context({name: "<suspect function>"})` — see all callers, callees, and process participation
|
||||||
|
3. `READ gitnexus://repo/design-system/process/{processName}` — trace the full execution flow step by step
|
||||||
|
4. For regressions: `gitnexus_detect_changes({scope: "compare", base_ref: "main"})` — see what your branch changed
|
||||||
|
|
||||||
|
## When Refactoring
|
||||||
|
|
||||||
|
- **Renaming**: MUST use `gitnexus_rename({symbol_name: "old", new_name: "new", dry_run: true})` first. Review the preview — graph edits are safe, text_search edits need manual review. Then run with `dry_run: false`.
|
||||||
|
- **Extracting/Splitting**: MUST run `gitnexus_context({name: "target"})` to see all incoming/outgoing refs, then `gitnexus_impact({target: "target", direction: "upstream"})` to find all external callers before moving code.
|
||||||
|
- After any refactor: run `gitnexus_detect_changes({scope: "all"})` to verify only expected files changed.
|
||||||
|
|
||||||
|
## Never Do
|
||||||
|
|
||||||
|
- NEVER edit a function, class, or method without first running `gitnexus_impact` on it.
|
||||||
|
- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis.
|
||||||
|
- NEVER rename symbols with find-and-replace — use `gitnexus_rename` which understands the call graph.
|
||||||
|
- NEVER commit changes without running `gitnexus_detect_changes()` to check affected scope.
|
||||||
|
|
||||||
|
## Tools Quick Reference
|
||||||
|
|
||||||
|
| Tool | When to use | Command |
|
||||||
|
|------|-------------|---------|
|
||||||
|
| `query` | Find code by concept | `gitnexus_query({query: "auth validation"})` |
|
||||||
|
| `context` | 360-degree view of one symbol | `gitnexus_context({name: "validateUser"})` |
|
||||||
|
| `impact` | Blast radius before editing | `gitnexus_impact({target: "X", direction: "upstream"})` |
|
||||||
|
| `detect_changes` | Pre-commit scope check | `gitnexus_detect_changes({scope: "staged"})` |
|
||||||
|
| `rename` | Safe multi-file rename | `gitnexus_rename({symbol_name: "old", new_name: "new", dry_run: true})` |
|
||||||
|
| `cypher` | Custom graph queries | `gitnexus_cypher({query: "MATCH ..."})` |
|
||||||
|
|
||||||
|
## Impact Risk Levels
|
||||||
|
|
||||||
|
| Depth | Meaning | Action |
|
||||||
|
|-------|---------|--------|
|
||||||
|
| d=1 | WILL BREAK — direct callers/importers | MUST update these |
|
||||||
|
| d=2 | LIKELY AFFECTED — indirect deps | Should test |
|
||||||
|
| d=3 | MAY NEED TESTING — transitive | Test if critical path |
|
||||||
|
|
||||||
|
## Resources
|
||||||
|
|
||||||
|
| Resource | Use for |
|
||||||
|
|----------|---------|
|
||||||
|
| `gitnexus://repo/design-system/context` | Codebase overview, check index freshness |
|
||||||
|
| `gitnexus://repo/design-system/clusters` | All functional areas |
|
||||||
|
| `gitnexus://repo/design-system/processes` | All execution flows |
|
||||||
|
| `gitnexus://repo/design-system/process/{name}` | Step-by-step execution trace |
|
||||||
|
|
||||||
|
## Self-Check Before Finishing
|
||||||
|
|
||||||
|
Before completing any code modification task, verify:
|
||||||
|
1. `gitnexus_impact` was run for all modified symbols
|
||||||
|
2. No HIGH/CRITICAL risk warnings were ignored
|
||||||
|
3. `gitnexus_detect_changes()` confirms changes match expected scope
|
||||||
|
4. All d=1 (WILL BREAK) dependents were updated
|
||||||
|
|
||||||
|
## Keeping the Index Fresh
|
||||||
|
|
||||||
|
After committing code changes, the GitNexus index becomes stale. Re-run analyze to update it:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx gitnexus analyze
|
||||||
|
```
|
||||||
|
|
||||||
|
If the index previously included embeddings, preserve them by adding `--embeddings`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx gitnexus analyze --embeddings
|
||||||
|
```
|
||||||
|
|
||||||
|
To check whether embeddings exist, inspect `.gitnexus/meta.json` — the `stats.embeddings` field shows the count (0 means no embeddings). **Running analyze without `--embeddings` will delete any previously generated embeddings.**
|
||||||
|
|
||||||
|
> Claude Code users: A PostToolUse hook handles this automatically after `git commit` and `git merge`.
|
||||||
|
|
||||||
|
## CLI
|
||||||
|
|
||||||
|
| Task | Read this skill file |
|
||||||
|
|------|---------------------|
|
||||||
|
| Understand architecture / "How does X work?" | `.claude/skills/gitnexus/gitnexus-exploring/SKILL.md` |
|
||||||
|
| Blast radius / "What breaks if I change X?" | `.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md` |
|
||||||
|
| Trace bugs / "Why is X failing?" | `.claude/skills/gitnexus/gitnexus-debugging/SKILL.md` |
|
||||||
|
| Rename / extract / split / refactor | `.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md` |
|
||||||
|
| Tools, resources, schema reference | `.claude/skills/gitnexus/gitnexus-guide/SKILL.md` |
|
||||||
|
| Index, status, clean, wiki CLI commands | `.claude/skills/gitnexus/gitnexus-cli/SKILL.md` |
|
||||||
|
|
||||||
|
<!-- gitnexus:end -->
|
||||||
|
|||||||
@@ -54,8 +54,10 @@
|
|||||||
### "I need to display data"
|
### "I need to display data"
|
||||||
- Key metrics → **StatCard** (with optional sparkline/trend)
|
- Key metrics → **StatCard** (with optional sparkline/trend)
|
||||||
- Tabular data → **DataTable** (sortable, paginated)
|
- Tabular data → **DataTable** (sortable, paginated)
|
||||||
- Time series → **LineChart**, **AreaChart**
|
- Time series (quick) → **LineChart** or **AreaChart** (convenience wrappers with series data)
|
||||||
- Categorical comparison → **BarChart**
|
- Categorical comparison (quick) → **BarChart** (convenience wrapper with series data)
|
||||||
|
- Time series (custom) → **ThemedChart** with `<Line>` or `<Area>`
|
||||||
|
- Categorical comparison (custom) → **ThemedChart** with `<Bar>`
|
||||||
- Inline trend → **Sparkline**
|
- Inline trend → **Sparkline**
|
||||||
- Advanced charts (treemap, radar, heatmap, pie, etc.) → **Recharts** with `rechartsTheme` (see [Charting Strategy](#charting-strategy))
|
- Advanced charts (treemap, radar, heatmap, pie, etc.) → **Recharts** with `rechartsTheme` (see [Charting Strategy](#charting-strategy))
|
||||||
- Event log → **EventFeed**
|
- Event log → **EventFeed**
|
||||||
@@ -109,6 +111,9 @@ Sidebar compound API:
|
|||||||
<Sidebar.Section label="str" icon={node} open={bool} onToggle={fn} active={bool}>
|
<Sidebar.Section label="str" icon={node} open={bool} onToggle={fn} active={bool}>
|
||||||
<SidebarTree nodes={[...]} selectedPath="..." filterQuery="..." ... />
|
<SidebarTree nodes={[...]} selectedPath="..." filterQuery="..." ... />
|
||||||
</Sidebar.Section>
|
</Sidebar.Section>
|
||||||
|
<Sidebar.Section label="str" icon={node} open={bool} onToggle={fn} position="bottom" maxHeight="200px">
|
||||||
|
<SidebarTree nodes={[...]} ... />
|
||||||
|
</Sidebar.Section>
|
||||||
<Sidebar.Footer>
|
<Sidebar.Footer>
|
||||||
<Sidebar.FooterLink icon={node} label="str" onClick={fn} active={bool} />
|
<Sidebar.FooterLink icon={node} label="str" onClick={fn} active={bool} />
|
||||||
</Sidebar.Footer>
|
</Sidebar.Footer>
|
||||||
@@ -119,6 +124,11 @@ Notes:
|
|||||||
- Section headers have no chevron — the entire row is clickable to toggle
|
- Section headers have no chevron — the entire row is clickable to toggle
|
||||||
- The app controls all content — sections, order, tree data, collapse state
|
- The app controls all content — sections, order, tree data, collapse state
|
||||||
- Sidebar provides the frame, search input, and icon-rail collapse mode
|
- Sidebar provides the frame, search input, and icon-rail collapse mode
|
||||||
|
- `position="bottom"` stacks sections above the footer; a spacer separates top/bottom groups
|
||||||
|
- `maxHeight` (CSS string) constrains the content area — section header stays visible, children scroll
|
||||||
|
- Both groups scroll independently when the viewport is short
|
||||||
|
- Custom thin scrollbars match the dark sidebar aesthetic
|
||||||
|
- No expand button when collapsed — clicking any section icon expands the sidebar and opens that section
|
||||||
```
|
```
|
||||||
|
|
||||||
### Data page pattern
|
### Data page pattern
|
||||||
@@ -138,7 +148,7 @@ FormField wraps any input (Input, Textarea, Select, RadioGroup, etc.)
|
|||||||
### KPI dashboard
|
### KPI dashboard
|
||||||
```
|
```
|
||||||
Row of StatCard components (each with optional Sparkline and trend)
|
Row of StatCard components (each with optional Sparkline and trend)
|
||||||
Below: charts (AreaChart, LineChart, BarChart)
|
Below: charts (ThemedChart with Line, Area, or Bar)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Master/detail management pattern
|
### Master/detail management pattern
|
||||||
@@ -175,57 +185,83 @@ StatCard strip (top, recalculates per scope)
|
|||||||
→ GroupCard grid (2-col for all, full-width for single app)
|
→ GroupCard grid (2-col for all, full-width for single app)
|
||||||
Each GroupCard: header (app name + count) + meta (TPS, routes) + instance rows
|
Each GroupCard: header (app name + count) + meta (TPS, routes) + instance rows
|
||||||
Instance rows: StatusDot + name + Badge + metrics
|
Instance rows: StatusDot + name + Badge + metrics
|
||||||
Single instance: expanded with LineChart panels
|
Single instance: expanded with ThemedChart panels
|
||||||
→ EventFeed (bottom, filtered by scope)
|
→ EventFeed (bottom, filtered by scope)
|
||||||
URL-driven progressive filtering: /agents → /agents/:appId → /agents/:appId/:instanceId
|
URL-driven progressive filtering: /agents → /agents/:appId → /agents/:appId/:instanceId
|
||||||
```
|
```
|
||||||
|
|
||||||
## Charting Strategy
|
## Charting Strategy
|
||||||
|
|
||||||
The design system includes built-in **AreaChart**, **BarChart**, **LineChart**, and **Sparkline** components for standard use cases. For advanced chart types (treemap, radar, heatmap, pie, sankey, etc.), consuming apps should use **Recharts** directly with the design system's theme preset for visual consistency.
|
The design system provides convenience chart wrappers (**LineChart**, **AreaChart**, **BarChart**) for common use cases, plus a lower-level **ThemedChart** wrapper for full Recharts control. Recharts is bundled as a dependency — consumers do not need to install it separately.
|
||||||
|
|
||||||
**Recharts is the app's dependency, not the design system's.** The design system only exports a theme config object.
|
### Quick Charts (convenience wrappers)
|
||||||
|
|
||||||
### Setup in consuming app
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm install recharts
|
|
||||||
```
|
|
||||||
|
|
||||||
### Usage with theme preset
|
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
import { rechartsTheme, CHART_COLORS } from '@cameleer/design-system'
|
import { LineChart, AreaChart, BarChart } from '@cameleer/design-system'
|
||||||
import {
|
import type { ChartSeries } from '@cameleer/design-system'
|
||||||
ResponsiveContainer, LineChart, Line,
|
|
||||||
CartesianGrid, XAxis, YAxis, Tooltip, Legend,
|
|
||||||
} from 'recharts'
|
|
||||||
|
|
||||||
<ResponsiveContainer width="100%" height={300}>
|
const series: ChartSeries[] = [
|
||||||
<LineChart data={data}>
|
{ label: 'CPU', data: [{ x: '10:00', y: 45 }, { x: '10:05', y: 62 }] },
|
||||||
<CartesianGrid {...rechartsTheme.cartesianGrid} />
|
{ label: 'Memory', data: [{ x: '10:00', y: 70 }, { x: '10:05', y: 72 }] },
|
||||||
<XAxis dataKey="name" {...rechartsTheme.xAxis} />
|
]
|
||||||
<YAxis {...rechartsTheme.yAxis} />
|
|
||||||
<Tooltip {...rechartsTheme.tooltip} />
|
<LineChart series={series} height={200} yLabel="%" />
|
||||||
<Legend {...rechartsTheme.legend} />
|
<AreaChart series={series} height={200} yLabel="%" thresholdValue={85} thresholdLabel="Alert" />
|
||||||
<Line dataKey="value" stroke={CHART_COLORS[0]} strokeWidth={2} dot={false} />
|
<BarChart series={series} height={200} stacked />
|
||||||
<Line dataKey="other" stroke={CHART_COLORS[1]} strokeWidth={2} dot={false} />
|
|
||||||
</LineChart>
|
|
||||||
</ResponsiveContainer>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Exports
|
| Prop | LineChart | AreaChart | BarChart | Description |
|
||||||
|
|------|:---------:|:---------:|:--------:|-------------|
|
||||||
|
| `series` | required | required | required | `ChartSeries[]` — `{ label, data: { x, y }[], color? }` |
|
||||||
|
| `height` | optional | optional | optional | Chart height in pixels |
|
||||||
|
| `width` | optional | optional | optional | Container width in pixels |
|
||||||
|
| `yLabel` | optional | optional | optional | Y-axis label |
|
||||||
|
| `xLabel` | optional | optional | optional | X-axis label |
|
||||||
|
| `className` | optional | optional | optional | Container CSS class |
|
||||||
|
| `threshold` | `{ value, label }` | — | — | Horizontal reference line |
|
||||||
|
| `thresholdValue` | — | optional | — | Threshold y-value |
|
||||||
|
| `thresholdLabel` | — | optional | — | Threshold label |
|
||||||
|
| `stacked` | — | — | optional | Stack bars instead of grouping |
|
||||||
|
|
||||||
| Export | Description |
|
### Custom Charts (ThemedChart)
|
||||||
|--------|-------------|
|
|
||||||
| `rechartsTheme.cartesianGrid` | Dashed gridlines, subtle stroke |
|
```tsx
|
||||||
| `rechartsTheme.xAxis` | Mono font axis ticks, subtle color |
|
import { ThemedChart, Line, Area, ReferenceLine, CHART_COLORS } from '@cameleer/design-system'
|
||||||
| `rechartsTheme.yAxis` | Mono font axis ticks, no axis line |
|
|
||||||
| `rechartsTheme.tooltip` | Surface bg, border, shadow, monospace values |
|
const data = metrics.map(m => ({ time: m.timestamp, cpu: m.value * 100 }))
|
||||||
| `rechartsTheme.legend` | Matching text size and color |
|
|
||||||
| `rechartsTheme.colors` | The 8 `CHART_COLORS` (CSS variables with light/dark support) |
|
<ThemedChart data={data} height={160} xDataKey="time" yLabel="%">
|
||||||
|
<Area dataKey="cpu" stroke={CHART_COLORS[0]} fill={CHART_COLORS[0]} fillOpacity={0.1} />
|
||||||
|
<ReferenceLine y={85} stroke="var(--error)" strokeDasharray="5 3" label="Alert" />
|
||||||
|
</ThemedChart>
|
||||||
|
```
|
||||||
|
|
||||||
|
### ThemedChart Props
|
||||||
|
|
||||||
|
| Prop | Type | Default | Description |
|
||||||
|
|------|------|---------|-------------|
|
||||||
|
| `data` | `Record<string, any>[]` | required | Flat array of data objects |
|
||||||
|
| `height` | `number` | `200` | Chart height in pixels |
|
||||||
|
| `xDataKey` | `string` | `"time"` | Key for x-axis values |
|
||||||
|
| `xType` | `'number' \| 'category'` | `"category"` | X-axis scale type |
|
||||||
|
| `xTickFormatter` | `(value: any) => string` | — | Custom x-axis label formatter |
|
||||||
|
| `yTickFormatter` | `(value: any) => string` | — | Custom y-axis label formatter |
|
||||||
|
| `yLabel` | `string` | — | Y-axis label text |
|
||||||
|
| `children` | `ReactNode` | required | Recharts elements (Line, Area, Bar, etc.) |
|
||||||
|
| `className` | `string` | — | Container CSS class |
|
||||||
|
|
||||||
|
### Available Recharts Re-exports
|
||||||
|
|
||||||
|
`Line`, `Area`, `Bar`, `ReferenceLine`, `ReferenceArea`, `Legend`, `Brush`
|
||||||
|
|
||||||
|
For chart types not covered (treemap, radar, pie, sankey), import from `recharts` directly and use `rechartsTheme` for consistent styling.
|
||||||
|
|
||||||
|
### Theme Utilities
|
||||||
|
|
||||||
|
| Export | Purpose |
|
||||||
|
|--------|---------|
|
||||||
| `CHART_COLORS` | Array of `var(--chart-1)` through `var(--chart-8)` |
|
| `CHART_COLORS` | Array of `var(--chart-1)` through `var(--chart-8)` |
|
||||||
| `ChartSeries` / `DataPoint` | Type interfaces for chart data |
|
| `rechartsTheme` | Pre-configured prop objects for Recharts sub-components |
|
||||||
|
|
||||||
## Component Index
|
## Component Index
|
||||||
|
|
||||||
@@ -234,11 +270,11 @@ import {
|
|||||||
| Accordion | composite | Multiple collapsible sections, single or multi-open mode |
|
| Accordion | composite | Multiple collapsible sections, single or multi-open mode |
|
||||||
| Alert | primitive | Page-level attention banner with variant colors |
|
| Alert | primitive | Page-level attention banner with variant colors |
|
||||||
| AlertDialog | composite | Confirmation dialog for destructive/important actions |
|
| AlertDialog | composite | Confirmation dialog for destructive/important actions |
|
||||||
| AreaChart | composite | Time series visualization with filled area |
|
| AreaChart | composite | Convenience area chart wrapper — pass `series` data, get themed chart with fills |
|
||||||
|
| BarChart | composite | Convenience bar chart wrapper — grouped or `stacked` mode |
|
||||||
| Avatar | primitive | User representation with initials and color |
|
| Avatar | primitive | User representation with initials and color |
|
||||||
| AvatarGroup | composite | Stacked overlapping avatars with overflow count |
|
| AvatarGroup | composite | Stacked overlapping avatars with overflow count |
|
||||||
| Badge | primitive | Labeled status indicator with semantic colors |
|
| Badge | primitive | Labeled status indicator with semantic colors |
|
||||||
| BarChart | composite | Categorical data comparison, optional stacking |
|
|
||||||
| Breadcrumb | composite | Navigation path showing current location |
|
| Breadcrumb | composite | Navigation path showing current location |
|
||||||
| Button | primitive | Action trigger (primary, secondary, danger, ghost) |
|
| Button | primitive | Action trigger (primary, secondary, danger, ghost) |
|
||||||
| ButtonGroup | primitive | Multi-select toggle group with optional colored dot indicators. Props: items (value, label, color?), value (Set), onChange |
|
| ButtonGroup | primitive | Multi-select toggle group with optional colored dot indicators. Props: items (value, label, color?), value (Set), onChange |
|
||||||
@@ -266,7 +302,7 @@ import {
|
|||||||
| KeyboardHint | primitive | Keyboard shortcut display |
|
| KeyboardHint | primitive | Keyboard shortcut display |
|
||||||
| KpiStrip | composite | Horizontal row of KPI cards with colored left border, trend, subtitle, optional sparkline |
|
| KpiStrip | composite | Horizontal row of KPI cards with colored left border, trend, subtitle, optional sparkline |
|
||||||
| Label | primitive | Form label with optional required asterisk |
|
| Label | primitive | Form label with optional required asterisk |
|
||||||
| LineChart | composite | Time series line visualization |
|
| LineChart | composite | Convenience line chart wrapper — pass `series` data, get themed chart with lines |
|
||||||
| LogViewer | composite | Scrollable log output with timestamped, severity-colored monospace entries |
|
| LogViewer | composite | Scrollable log output with timestamped, severity-colored monospace entries |
|
||||||
| MenuItem | composite | Sidebar navigation item with health/count |
|
| MenuItem | composite | Sidebar navigation item with health/count |
|
||||||
| Modal | composite | Generic dialog overlay with backdrop |
|
| Modal | composite | Generic dialog overlay with backdrop |
|
||||||
@@ -303,7 +339,7 @@ import {
|
|||||||
| Component | Purpose |
|
| Component | Purpose |
|
||||||
|-----------|---------|
|
|-----------|---------|
|
||||||
| AppShell | Page shell: sidebar + topbar + main + optional detail panel |
|
| AppShell | Page shell: sidebar + topbar + main + optional detail panel |
|
||||||
| Sidebar | Composable compound sidebar shell with icon-rail collapse mode. Sub-components: `Sidebar.Header`, `Sidebar.Section`, `Sidebar.Footer`, `Sidebar.FooterLink`. The app controls all content via children — the DS provides the frame. |
|
| Sidebar | Composable compound sidebar shell with icon-rail collapse mode. Sub-components: `Sidebar.Header`, `Sidebar.Section` (supports `position="bottom"` and `maxHeight`), `Sidebar.Footer`, `Sidebar.FooterLink`. The app controls all content via children — the DS provides the frame. |
|
||||||
| SidebarTree | Data-driven tree for sidebar sections. Accepts `nodes: SidebarTreeNode[]` with expand/collapse, starring, keyboard nav, search filter, and path-based selection highlighting. |
|
| SidebarTree | Data-driven tree for sidebar sections. Accepts `nodes: SidebarTreeNode[]` with expand/collapse, starring, keyboard nav, search filter, and path-based selection highlighting. |
|
||||||
| useStarred | Hook for localStorage-backed starred item IDs. Returns `{ starredIds, isStarred, toggleStar }`. |
|
| useStarred | Hook for localStorage-backed starred item IDs. Returns `{ starredIds, isStarred, toggleStar }`. |
|
||||||
| TopBar | Header bar with breadcrumb, search trigger, ButtonGroup status filters, time range selector, theme toggle, environment slot (`ReactNode` — pass a string for a static label or a custom dropdown for interactive selection), user avatar |
|
| TopBar | Header bar with breadcrumb, search trigger, ButtonGroup status filters, time range selector, theme toggle, environment slot (`ReactNode` — pass a string for a static label or a custom dropdown for interactive selection), user avatar |
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 941 B After Width: | Height: | Size: 941 B |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 151 KiB After Width: | Height: | Size: 151 KiB |
|
Before Width: | Height: | Size: 342 KiB After Width: | Height: | Size: 342 KiB |
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.5 MiB |
845
docs/superpowers/plans/2026-04-12-recharts-migration.md
Normal file
@@ -0,0 +1,845 @@
|
|||||||
|
# Recharts Migration Implementation Plan
|
||||||
|
|
||||||
|
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||||
|
|
||||||
|
**Goal:** Replace the design system's hand-rolled SVG chart components with a single `ThemedChart` wrapper around Recharts, using Recharts-native data format.
|
||||||
|
|
||||||
|
**Architecture:** Add Recharts as a DS dependency. Create `ThemedChart` component that renders `ResponsiveContainer` + `ComposedChart` with pre-themed grid/axes/tooltip. Consumers compose Recharts elements (`<Line>`, `<Area>`, `<Bar>`, `<ReferenceLine>`) as children. Delete old `LineChart/`, `AreaChart/`, `BarChart/`, `_chart-utils.ts`. Migrate the server UI's `AgentInstance.tsx` to the new API.
|
||||||
|
|
||||||
|
**Tech Stack:** React 19, Recharts, CSS Modules, Vitest
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## File Structure
|
||||||
|
|
||||||
|
**Design System (`C:\Users\Hendrik\Documents\projects\design-system`):**
|
||||||
|
|
||||||
|
| Action | Path | Purpose |
|
||||||
|
|--------|------|---------|
|
||||||
|
| Create | `src/design-system/composites/ThemedChart/ThemedChart.tsx` | Wrapper component: ResponsiveContainer + ComposedChart + themed axes/grid/tooltip |
|
||||||
|
| Create | `src/design-system/composites/ThemedChart/ChartTooltip.tsx` | Custom tooltip with timestamp header + series values |
|
||||||
|
| Create | `src/design-system/composites/ThemedChart/ChartTooltip.module.css` | Tooltip styles using DS tokens |
|
||||||
|
| Create | `src/design-system/composites/ThemedChart/ThemedChart.test.tsx` | Render tests for ThemedChart |
|
||||||
|
| Modify | `src/design-system/utils/rechartsTheme.ts` | Move `CHART_COLORS` definition here (was in `_chart-utils.ts`) |
|
||||||
|
| Modify | `src/design-system/composites/index.ts` | Remove old chart exports, add ThemedChart + Recharts re-exports |
|
||||||
|
| Modify | `COMPONENT_GUIDE.md` | Update charting strategy section |
|
||||||
|
| Modify | `package.json` | Add `recharts` dependency, bump version |
|
||||||
|
| Delete | `src/design-system/composites/LineChart/` | Old hand-rolled SVG line chart |
|
||||||
|
| Delete | `src/design-system/composites/AreaChart/` | Old hand-rolled SVG area chart |
|
||||||
|
| Delete | `src/design-system/composites/BarChart/` | Old hand-rolled SVG bar chart |
|
||||||
|
| Delete | `src/design-system/composites/_chart-utils.ts` | Old chart utilities |
|
||||||
|
|
||||||
|
**Server UI (`C:\Users\Hendrik\Documents\projects\cameleer3-server`):**
|
||||||
|
|
||||||
|
| Action | Path | Purpose |
|
||||||
|
|--------|------|---------|
|
||||||
|
| Modify | `ui/src/pages/AgentInstance/AgentInstance.tsx` | Migrate 6 charts to ThemedChart + Recharts children |
|
||||||
|
| Modify | `ui/package.json` | Update `@cameleer/design-system` to new version |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 1: Add Recharts Dependency and Move CHART_COLORS
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `package.json`
|
||||||
|
- Modify: `src/design-system/utils/rechartsTheme.ts`
|
||||||
|
|
||||||
|
- [ ] **Step 1: Install recharts**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd C:\Users\Hendrik\Documents\projects\design-system
|
||||||
|
npm install recharts
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Move CHART_COLORS into rechartsTheme.ts**
|
||||||
|
|
||||||
|
Replace the entire file `src/design-system/utils/rechartsTheme.ts` with:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
export const CHART_COLORS = [
|
||||||
|
'var(--chart-1)',
|
||||||
|
'var(--chart-2)',
|
||||||
|
'var(--chart-3)',
|
||||||
|
'var(--chart-4)',
|
||||||
|
'var(--chart-5)',
|
||||||
|
'var(--chart-6)',
|
||||||
|
'var(--chart-7)',
|
||||||
|
'var(--chart-8)',
|
||||||
|
]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-configured Recharts prop objects that match the design system's
|
||||||
|
* chart styling. Used internally by ThemedChart and available for
|
||||||
|
* consumers composing Recharts directly.
|
||||||
|
*/
|
||||||
|
export const rechartsTheme = {
|
||||||
|
colors: CHART_COLORS,
|
||||||
|
|
||||||
|
cartesianGrid: {
|
||||||
|
stroke: 'var(--border-subtle)',
|
||||||
|
strokeDasharray: '3 3',
|
||||||
|
vertical: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
xAxis: {
|
||||||
|
tick: { fontSize: 9, fontFamily: 'var(--font-mono)', fill: 'var(--text-faint)' },
|
||||||
|
axisLine: { stroke: 'var(--border-subtle)' },
|
||||||
|
tickLine: false as const,
|
||||||
|
},
|
||||||
|
|
||||||
|
yAxis: {
|
||||||
|
tick: { fontSize: 9, fontFamily: 'var(--font-mono)', fill: 'var(--text-faint)' },
|
||||||
|
axisLine: false as const,
|
||||||
|
tickLine: false as const,
|
||||||
|
},
|
||||||
|
|
||||||
|
tooltip: {
|
||||||
|
contentStyle: {
|
||||||
|
background: 'var(--bg-surface)',
|
||||||
|
border: '1px solid var(--border)',
|
||||||
|
borderRadius: 'var(--radius-sm)',
|
||||||
|
boxShadow: 'var(--shadow-md)',
|
||||||
|
fontSize: 11,
|
||||||
|
padding: '6px 10px',
|
||||||
|
},
|
||||||
|
labelStyle: {
|
||||||
|
color: 'var(--text-muted)',
|
||||||
|
fontSize: 11,
|
||||||
|
marginBottom: 4,
|
||||||
|
},
|
||||||
|
itemStyle: {
|
||||||
|
color: 'var(--text-primary)',
|
||||||
|
fontFamily: 'var(--font-mono)',
|
||||||
|
fontSize: 11,
|
||||||
|
padding: 0,
|
||||||
|
},
|
||||||
|
cursor: { stroke: 'var(--text-faint)' },
|
||||||
|
},
|
||||||
|
|
||||||
|
legend: {
|
||||||
|
wrapperStyle: {
|
||||||
|
fontSize: 11,
|
||||||
|
color: 'var(--text-secondary)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as const
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3: Verify build compiles**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build:lib
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected: Build succeeds. The old chart components still import `CHART_COLORS` from `_chart-utils.ts` which still exists — they'll be deleted in Task 4.
|
||||||
|
|
||||||
|
- [ ] **Step 4: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add package.json package-lock.json src/design-system/utils/rechartsTheme.ts
|
||||||
|
git commit -m "chore: add recharts dependency, move CHART_COLORS to rechartsTheme"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 2: Create ChartTooltip Component
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Create: `src/design-system/composites/ThemedChart/ChartTooltip.tsx`
|
||||||
|
- Create: `src/design-system/composites/ThemedChart/ChartTooltip.module.css`
|
||||||
|
|
||||||
|
- [ ] **Step 1: Create tooltip CSS**
|
||||||
|
|
||||||
|
Create `src/design-system/composites/ThemedChart/ChartTooltip.module.css`:
|
||||||
|
|
||||||
|
```css
|
||||||
|
.tooltip {
|
||||||
|
background: var(--bg-surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
box-shadow: var(--shadow-md);
|
||||||
|
padding: 6px 10px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
margin-bottom: 4px;
|
||||||
|
padding-bottom: 3px;
|
||||||
|
border-bottom: 1px solid var(--border-subtle);
|
||||||
|
}
|
||||||
|
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dot {
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 50%;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
color: var(--text-muted);
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Create ChartTooltip component**
|
||||||
|
|
||||||
|
Create `src/design-system/composites/ThemedChart/ChartTooltip.tsx`:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
import type { TooltipProps } from 'recharts'
|
||||||
|
import styles from './ChartTooltip.module.css'
|
||||||
|
|
||||||
|
function formatValue(val: number): string {
|
||||||
|
if (val >= 1_000_000) return `${(val / 1_000_000).toFixed(1)}M`
|
||||||
|
if (val >= 1000) return `${(val / 1000).toFixed(1)}k`
|
||||||
|
if (Number.isInteger(val)) return String(val)
|
||||||
|
return val.toFixed(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTimestamp(val: unknown): string | null {
|
||||||
|
if (val == null) return null
|
||||||
|
const str = String(val)
|
||||||
|
const ms = typeof val === 'number' && val > 1e12 ? val
|
||||||
|
: typeof val === 'number' && val > 1e9 ? val * 1000
|
||||||
|
: Date.parse(str)
|
||||||
|
if (isNaN(ms)) return str
|
||||||
|
return new Date(ms).toLocaleString([], {
|
||||||
|
month: 'short', day: 'numeric',
|
||||||
|
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ChartTooltip({ active, payload, label }: TooltipProps<number, string>) {
|
||||||
|
if (!active || !payload?.length) return null
|
||||||
|
|
||||||
|
const timeLabel = formatTimestamp(label)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.tooltip}>
|
||||||
|
{timeLabel && <div className={styles.time}>{timeLabel}</div>}
|
||||||
|
{payload.map((entry) => (
|
||||||
|
<div key={entry.dataKey as string} className={styles.row}>
|
||||||
|
<span className={styles.dot} style={{ background: entry.color }} />
|
||||||
|
<span className={styles.label}>{entry.name}:</span>
|
||||||
|
<span className={styles.value}>{formatValue(entry.value as number)}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/design-system/composites/ThemedChart/
|
||||||
|
git commit -m "feat: add ChartTooltip component for ThemedChart"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 3: Create ThemedChart Component
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Create: `src/design-system/composites/ThemedChart/ThemedChart.tsx`
|
||||||
|
- Create: `src/design-system/composites/ThemedChart/ThemedChart.test.tsx`
|
||||||
|
|
||||||
|
- [ ] **Step 1: Create ThemedChart component**
|
||||||
|
|
||||||
|
Create `src/design-system/composites/ThemedChart/ThemedChart.tsx`:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
import {
|
||||||
|
ResponsiveContainer,
|
||||||
|
ComposedChart,
|
||||||
|
CartesianGrid,
|
||||||
|
XAxis,
|
||||||
|
YAxis,
|
||||||
|
Tooltip,
|
||||||
|
} from 'recharts'
|
||||||
|
import { rechartsTheme } from '../../utils/rechartsTheme'
|
||||||
|
import { ChartTooltip } from './ChartTooltip'
|
||||||
|
|
||||||
|
interface ThemedChartProps {
|
||||||
|
data: Record<string, any>[]
|
||||||
|
height?: number
|
||||||
|
xDataKey?: string
|
||||||
|
xType?: 'number' | 'category'
|
||||||
|
xTickFormatter?: (value: any) => string
|
||||||
|
yTickFormatter?: (value: any) => string
|
||||||
|
yLabel?: string
|
||||||
|
children: React.ReactNode
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ThemedChart({
|
||||||
|
data,
|
||||||
|
height = 200,
|
||||||
|
xDataKey = 'time',
|
||||||
|
xType = 'category',
|
||||||
|
xTickFormatter,
|
||||||
|
yTickFormatter,
|
||||||
|
yLabel,
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
}: ThemedChartProps) {
|
||||||
|
if (!data.length) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={className} style={{ width: '100%', height }}>
|
||||||
|
<ResponsiveContainer width="100%" height="100%">
|
||||||
|
<ComposedChart data={data} margin={{ top: 4, right: 8, bottom: 0, left: 0 }}>
|
||||||
|
<CartesianGrid {...rechartsTheme.cartesianGrid} />
|
||||||
|
<XAxis
|
||||||
|
dataKey={xDataKey}
|
||||||
|
type={xType}
|
||||||
|
{...rechartsTheme.xAxis}
|
||||||
|
tickFormatter={xTickFormatter}
|
||||||
|
/>
|
||||||
|
<YAxis
|
||||||
|
{...rechartsTheme.yAxis}
|
||||||
|
tickFormatter={yTickFormatter}
|
||||||
|
label={yLabel ? {
|
||||||
|
value: yLabel,
|
||||||
|
angle: -90,
|
||||||
|
position: 'insideLeft',
|
||||||
|
style: { fontSize: 11, fill: 'var(--text-muted)' },
|
||||||
|
} : undefined}
|
||||||
|
/>
|
||||||
|
<Tooltip content={<ChartTooltip />} cursor={rechartsTheme.tooltip.cursor} />
|
||||||
|
{children}
|
||||||
|
</ComposedChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Write test**
|
||||||
|
|
||||||
|
Create `src/design-system/composites/ThemedChart/ThemedChart.test.tsx`:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { render, screen } from '@testing-library/react'
|
||||||
|
import { ThemedChart } from './ThemedChart'
|
||||||
|
import { Line } from 'recharts'
|
||||||
|
|
||||||
|
// Recharts uses ResizeObserver internally
|
||||||
|
class ResizeObserverMock {
|
||||||
|
observe() {}
|
||||||
|
unobserve() {}
|
||||||
|
disconnect() {}
|
||||||
|
}
|
||||||
|
globalThis.ResizeObserver = ResizeObserverMock as any
|
||||||
|
|
||||||
|
describe('ThemedChart', () => {
|
||||||
|
it('renders nothing when data is empty', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<ThemedChart data={[]}>
|
||||||
|
<Line dataKey="value" />
|
||||||
|
</ThemedChart>,
|
||||||
|
)
|
||||||
|
expect(container.innerHTML).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders a chart container when data is provided', () => {
|
||||||
|
const data = [
|
||||||
|
{ time: '10:00', value: 10 },
|
||||||
|
{ time: '10:01', value: 20 },
|
||||||
|
]
|
||||||
|
const { container } = render(
|
||||||
|
<ThemedChart data={data} height={160}>
|
||||||
|
<Line dataKey="value" />
|
||||||
|
</ThemedChart>,
|
||||||
|
)
|
||||||
|
expect(container.querySelector('.recharts-responsive-container')).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('applies custom className', () => {
|
||||||
|
const data = [{ time: '10:00', value: 5 }]
|
||||||
|
const { container } = render(
|
||||||
|
<ThemedChart data={data} className="my-chart">
|
||||||
|
<Line dataKey="value" />
|
||||||
|
</ThemedChart>,
|
||||||
|
)
|
||||||
|
expect(container.querySelector('.my-chart')).toBeTruthy()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3: Run tests**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx vitest run src/design-system/composites/ThemedChart/ThemedChart.test.tsx
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected: 3 tests pass.
|
||||||
|
|
||||||
|
- [ ] **Step 4: Verify lib build**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build:lib
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected: Build succeeds.
|
||||||
|
|
||||||
|
- [ ] **Step 5: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/design-system/composites/ThemedChart/
|
||||||
|
git commit -m "feat: add ThemedChart wrapper component"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 4: Update Barrel Exports and Delete Old Charts
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/design-system/composites/index.ts`
|
||||||
|
- Delete: `src/design-system/composites/LineChart/`
|
||||||
|
- Delete: `src/design-system/composites/AreaChart/`
|
||||||
|
- Delete: `src/design-system/composites/BarChart/`
|
||||||
|
- Delete: `src/design-system/composites/_chart-utils.ts`
|
||||||
|
|
||||||
|
- [ ] **Step 1: Update composites/index.ts**
|
||||||
|
|
||||||
|
Remove these lines:
|
||||||
|
```
|
||||||
|
export { AreaChart } from './AreaChart/AreaChart'
|
||||||
|
export { BarChart } from './BarChart/BarChart'
|
||||||
|
export { LineChart } from './LineChart/LineChart'
|
||||||
|
export { CHART_COLORS } from './_chart-utils'
|
||||||
|
export type { ChartSeries, DataPoint } from './_chart-utils'
|
||||||
|
```
|
||||||
|
|
||||||
|
Add in their place:
|
||||||
|
```tsx
|
||||||
|
// Charts — ThemedChart wrapper + Recharts re-exports
|
||||||
|
export { ThemedChart } from './ThemedChart/ThemedChart'
|
||||||
|
export { CHART_COLORS, rechartsTheme } from '../utils/rechartsTheme'
|
||||||
|
export {
|
||||||
|
Line, Area, Bar,
|
||||||
|
ReferenceLine, ReferenceArea,
|
||||||
|
Legend, Brush,
|
||||||
|
} from 'recharts'
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Remove the rechartsTheme re-export from main index.ts**
|
||||||
|
|
||||||
|
In `src/design-system/index.ts`, remove this line (it's now re-exported via composites):
|
||||||
|
```
|
||||||
|
export * from './utils/rechartsTheme'
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace with a targeted export that avoids double-exporting `CHART_COLORS`:
|
||||||
|
```tsx
|
||||||
|
export { rechartsTheme } from './utils/rechartsTheme'
|
||||||
|
```
|
||||||
|
|
||||||
|
Wait — actually `composites/index.ts` already re-exports both `CHART_COLORS` and `rechartsTheme`. And `index.ts` does `export * from './composites'`. So the main `index.ts` line `export * from './utils/rechartsTheme'` would cause a duplicate export of both symbols. Remove it entirely:
|
||||||
|
|
||||||
|
Delete this line from `src/design-system/index.ts`:
|
||||||
|
```
|
||||||
|
export * from './utils/rechartsTheme'
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3: Delete old chart directories and utilities**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
rm -rf src/design-system/composites/LineChart
|
||||||
|
rm -rf src/design-system/composites/AreaChart
|
||||||
|
rm -rf src/design-system/composites/BarChart
|
||||||
|
rm src/design-system/composites/_chart-utils.ts
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 4: Verify lib build**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build:lib
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected: Build succeeds. The old components are gone, ThemedChart and Recharts re-exports are the new public API.
|
||||||
|
|
||||||
|
- [ ] **Step 5: Run all tests**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx vitest run
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected: All tests pass. No test files existed for the deleted components.
|
||||||
|
|
||||||
|
- [ ] **Step 6: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add -A
|
||||||
|
git commit -m "feat!: replace custom chart components with ThemedChart + Recharts
|
||||||
|
|
||||||
|
BREAKING: LineChart, AreaChart, BarChart, ChartSeries, DataPoint removed.
|
||||||
|
Use ThemedChart with Recharts children (Line, Area, Bar, etc.) instead."
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 5: Update COMPONENT_GUIDE.md
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `COMPONENT_GUIDE.md`
|
||||||
|
|
||||||
|
- [ ] **Step 1: Update the charting strategy section**
|
||||||
|
|
||||||
|
Find the section starting with `## Charting Strategy` (around line 183) and replace through line 228 with:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
## Charting Strategy
|
||||||
|
|
||||||
|
The design system provides a **ThemedChart** wrapper component that applies consistent styling to Recharts charts. Recharts is bundled as a dependency — consumers do not need to install it separately.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
import { ThemedChart, Line, Area, ReferenceLine, CHART_COLORS } from '@cameleer/design-system'
|
||||||
|
|
||||||
|
const data = metrics.map(m => ({ time: m.timestamp, cpu: m.value * 100 }))
|
||||||
|
|
||||||
|
<ThemedChart data={data} height={160} xDataKey="time" yLabel="%">
|
||||||
|
<Area dataKey="cpu" stroke={CHART_COLORS[0]} fill={CHART_COLORS[0]} fillOpacity={0.1} />
|
||||||
|
<ReferenceLine y={85} stroke="var(--error)" strokeDasharray="5 3" label="Alert" />
|
||||||
|
</ThemedChart>
|
||||||
|
```
|
||||||
|
|
||||||
|
### ThemedChart Props
|
||||||
|
|
||||||
|
| Prop | Type | Default | Description |
|
||||||
|
|------|------|---------|-------------|
|
||||||
|
| `data` | `Record<string, any>[]` | required | Flat array of data objects |
|
||||||
|
| `height` | `number` | `200` | Chart height in pixels |
|
||||||
|
| `xDataKey` | `string` | `"time"` | Key for x-axis values |
|
||||||
|
| `xType` | `'number' \| 'category'` | `"category"` | X-axis scale type |
|
||||||
|
| `xTickFormatter` | `(value: any) => string` | — | Custom x-axis label formatter |
|
||||||
|
| `yTickFormatter` | `(value: any) => string` | — | Custom y-axis label formatter |
|
||||||
|
| `yLabel` | `string` | — | Y-axis label text |
|
||||||
|
| `children` | `ReactNode` | required | Recharts elements (Line, Area, Bar, etc.) |
|
||||||
|
| `className` | `string` | — | Container CSS class |
|
||||||
|
|
||||||
|
### Available Recharts Re-exports
|
||||||
|
|
||||||
|
`Line`, `Area`, `Bar`, `ReferenceLine`, `ReferenceArea`, `Legend`, `Brush`
|
||||||
|
|
||||||
|
For chart types not covered (treemap, radar, pie, sankey), import from `recharts` directly and use `rechartsTheme` for consistent styling.
|
||||||
|
|
||||||
|
### Theme Utilities
|
||||||
|
|
||||||
|
| Export | Purpose |
|
||||||
|
|--------|---------|
|
||||||
|
| `CHART_COLORS` | Array of `var(--chart-1)` through `var(--chart-8)` |
|
||||||
|
| `rechartsTheme` | Pre-configured prop objects for Recharts sub-components |
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Update the component index table**
|
||||||
|
|
||||||
|
Find the rows for `AreaChart`, `BarChart`, `LineChart` in the component index table and replace all three with:
|
||||||
|
|
||||||
|
```
|
||||||
|
| ThemedChart | composite | Recharts wrapper with themed axes, grid, and tooltip |
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3: Update the decision tree**
|
||||||
|
|
||||||
|
Find lines 57-60 (the chart decision tree entries):
|
||||||
|
```
|
||||||
|
- Time series → **LineChart**, **AreaChart**
|
||||||
|
- Categorical comparison → **BarChart**
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace with:
|
||||||
|
```
|
||||||
|
- Time series → **ThemedChart** with `<Line>` or `<Area>`
|
||||||
|
- Categorical comparison → **ThemedChart** with `<Bar>`
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 4: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add COMPONENT_GUIDE.md
|
||||||
|
git commit -m "docs: update COMPONENT_GUIDE for ThemedChart migration"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 6: Publish Design System
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `package.json` (version bump)
|
||||||
|
|
||||||
|
- [ ] **Step 1: Bump version**
|
||||||
|
|
||||||
|
In `package.json`, change `"version"` to `"0.1.47"`.
|
||||||
|
|
||||||
|
- [ ] **Step 2: Build and verify**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build:lib
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3: Commit and tag**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add package.json
|
||||||
|
git commit -m "chore: bump version to 0.1.47"
|
||||||
|
git tag v0.1.47
|
||||||
|
git push && git push --tags
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 4: Wait for CI to publish**
|
||||||
|
|
||||||
|
Wait for the Gitea CI pipeline to build and publish `@cameleer/design-system@0.1.47` to the npm registry. Verify with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm view @cameleer/design-system@0.1.47 version
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 7: Migrate Server UI AgentInstance Charts
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `C:\Users\Hendrik\Documents\projects\cameleer3-server\ui\src\pages\AgentInstance\AgentInstance.tsx`
|
||||||
|
- Modify: `C:\Users\Hendrik\Documents\projects\cameleer3-server\ui\package.json`
|
||||||
|
|
||||||
|
- [ ] **Step 1: Update design system dependency**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd C:\Users\Hendrik\Documents\projects\cameleer3-server\ui
|
||||||
|
npm install @cameleer/design-system@0.1.47
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Update imports in AgentInstance.tsx**
|
||||||
|
|
||||||
|
Replace the chart-related imports:
|
||||||
|
|
||||||
|
Old:
|
||||||
|
```tsx
|
||||||
|
import {
|
||||||
|
StatCard, StatusDot, Badge, LineChart, AreaChart, BarChart,
|
||||||
|
EventFeed, Spinner, EmptyState, SectionHeader, MonoText,
|
||||||
|
LogViewer, ButtonGroup, useGlobalFilters,
|
||||||
|
} from '@cameleer/design-system'
|
||||||
|
```
|
||||||
|
|
||||||
|
New:
|
||||||
|
```tsx
|
||||||
|
import {
|
||||||
|
StatCard, StatusDot, Badge,
|
||||||
|
ThemedChart, Line, Area, ReferenceLine, CHART_COLORS,
|
||||||
|
EventFeed, Spinner, EmptyState, SectionHeader, MonoText,
|
||||||
|
LogViewer, ButtonGroup, useGlobalFilters,
|
||||||
|
} from '@cameleer/design-system'
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3: Replace data prep — JVM metrics**
|
||||||
|
|
||||||
|
Replace the 4 JVM series useMemo blocks (cpuSeries, heapSeries, threadSeries, gcSeries) with flat data builders:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
const formatTime = (t: string) =>
|
||||||
|
new Date(t).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||||
|
|
||||||
|
// JVM chart data — merge all metrics into flat objects by time bucket
|
||||||
|
const cpuData = useMemo(() => {
|
||||||
|
const pts = jvmMetrics?.metrics?.['process.cpu.usage.value'];
|
||||||
|
if (!pts?.length) return [];
|
||||||
|
return pts.map((p: any) => ({ time: p.time, cpu: p.value * 100 }));
|
||||||
|
}, [jvmMetrics]);
|
||||||
|
|
||||||
|
const heapData = useMemo(() => {
|
||||||
|
const pts = jvmMetrics?.metrics?.['jvm.memory.used.value'];
|
||||||
|
if (!pts?.length) return [];
|
||||||
|
return pts.map((p: any) => ({ time: p.time, heap: p.value / (1024 * 1024) }));
|
||||||
|
}, [jvmMetrics]);
|
||||||
|
|
||||||
|
const threadData = useMemo(() => {
|
||||||
|
const pts = jvmMetrics?.metrics?.['jvm.threads.live.value'];
|
||||||
|
if (!pts?.length) return [];
|
||||||
|
return pts.map((p: any) => ({ time: p.time, threads: p.value }));
|
||||||
|
}, [jvmMetrics]);
|
||||||
|
|
||||||
|
const gcData = useMemo(() => {
|
||||||
|
const pts = jvmMetrics?.metrics?.['jvm.gc.pause.total_time'];
|
||||||
|
if (!pts?.length) return [];
|
||||||
|
return pts.map((p: any) => ({ time: p.time, gc: p.value }));
|
||||||
|
}, [jvmMetrics]);
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 4: Replace data prep — throughput and error**
|
||||||
|
|
||||||
|
Replace the throughputSeries and errorSeries useMemo blocks:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
const throughputData = useMemo(() => {
|
||||||
|
if (!chartData.length) return [];
|
||||||
|
return chartData.map((d: any) => ({ time: d.date.toISOString(), throughput: d.throughput }));
|
||||||
|
}, [chartData]);
|
||||||
|
|
||||||
|
const errorData = useMemo(() => {
|
||||||
|
if (!chartData.length) return [];
|
||||||
|
return chartData.map((d: any) => ({ time: d.date.toISOString(), errorPct: d.errorPct }));
|
||||||
|
}, [chartData]);
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 5: Replace chart JSX — CPU Usage**
|
||||||
|
|
||||||
|
Replace the CPU chart card content:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{cpuData.length ? (
|
||||||
|
<ThemedChart data={cpuData} height={160} xDataKey="time"
|
||||||
|
xTickFormatter={formatTime} yLabel="%">
|
||||||
|
<Area dataKey="cpu" name="CPU %" stroke={CHART_COLORS[0]}
|
||||||
|
fill={CHART_COLORS[0]} fillOpacity={0.1} strokeWidth={2} dot={false} />
|
||||||
|
<ReferenceLine y={85} stroke="var(--error)" strokeDasharray="5 3"
|
||||||
|
label={{ value: 'Alert', position: 'right', fill: 'var(--error)', fontSize: 9 }} />
|
||||||
|
</ThemedChart>
|
||||||
|
) : (
|
||||||
|
<EmptyState title="No data" description="No CPU metrics available" />
|
||||||
|
)}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 6: Replace chart JSX — Memory (Heap)**
|
||||||
|
|
||||||
|
Replace the heap chart card content:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{heapData.length ? (
|
||||||
|
<ThemedChart data={heapData} height={160} xDataKey="time"
|
||||||
|
xTickFormatter={formatTime} yLabel="MB">
|
||||||
|
<Area dataKey="heap" name="Heap MB" stroke={CHART_COLORS[0]}
|
||||||
|
fill={CHART_COLORS[0]} fillOpacity={0.1} strokeWidth={2} dot={false} />
|
||||||
|
{heapMax != null && (
|
||||||
|
<ReferenceLine y={heapMax / (1024 * 1024)} stroke="var(--error)" strokeDasharray="5 3"
|
||||||
|
label={{ value: 'Max Heap', position: 'right', fill: 'var(--error)', fontSize: 9 }} />
|
||||||
|
)}
|
||||||
|
</ThemedChart>
|
||||||
|
) : (
|
||||||
|
<EmptyState title="No data" description="No heap metrics available" />
|
||||||
|
)}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 7: Replace chart JSX — Throughput**
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{throughputData.length ? (
|
||||||
|
<ThemedChart data={throughputData} height={160} xDataKey="time"
|
||||||
|
xTickFormatter={formatTime} yLabel="msg/s">
|
||||||
|
<Line dataKey="throughput" name="msg/s" stroke={CHART_COLORS[0]}
|
||||||
|
strokeWidth={2} dot={false} />
|
||||||
|
</ThemedChart>
|
||||||
|
) : (
|
||||||
|
<EmptyState title="No data" description="No throughput data in range" />
|
||||||
|
)}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 8: Replace chart JSX — Error Rate**
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{errorData.length ? (
|
||||||
|
<ThemedChart data={errorData} height={160} xDataKey="time"
|
||||||
|
xTickFormatter={formatTime} yLabel="%">
|
||||||
|
<Line dataKey="errorPct" name="Error %" stroke={CHART_COLORS[0]}
|
||||||
|
strokeWidth={2} dot={false} />
|
||||||
|
</ThemedChart>
|
||||||
|
) : (
|
||||||
|
<EmptyState title="No data" description="No error data in range" />
|
||||||
|
)}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 9: Replace chart JSX — Thread Count**
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{threadData.length ? (
|
||||||
|
<ThemedChart data={threadData} height={160} xDataKey="time"
|
||||||
|
xTickFormatter={formatTime} yLabel="threads">
|
||||||
|
<Line dataKey="threads" name="Threads" stroke={CHART_COLORS[0]}
|
||||||
|
strokeWidth={2} dot={false} />
|
||||||
|
</ThemedChart>
|
||||||
|
) : (
|
||||||
|
<EmptyState title="No data" description="No thread metrics available" />
|
||||||
|
)}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 10: Replace chart JSX — GC Pauses**
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{gcData.length ? (
|
||||||
|
<ThemedChart data={gcData} height={160} xDataKey="time"
|
||||||
|
xTickFormatter={formatTime} yLabel="ms">
|
||||||
|
<Area dataKey="gc" name="GC ms" stroke={CHART_COLORS[1]}
|
||||||
|
fill={CHART_COLORS[1]} fillOpacity={0.1} strokeWidth={2} dot={false} />
|
||||||
|
</ThemedChart>
|
||||||
|
) : (
|
||||||
|
<EmptyState title="No data" description="No GC metrics available" />
|
||||||
|
)}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 11: Update the Thread Count meta display**
|
||||||
|
|
||||||
|
The thread count meta currently reads from `threadSeries`. Update to read from `threadData`:
|
||||||
|
|
||||||
|
Old:
|
||||||
|
```tsx
|
||||||
|
{threadSeries
|
||||||
|
? `${threadSeries[0].data[threadSeries[0].data.length - 1]?.y.toFixed(0)} active`
|
||||||
|
: ''}
|
||||||
|
```
|
||||||
|
|
||||||
|
New:
|
||||||
|
```tsx
|
||||||
|
{threadData.length
|
||||||
|
? `${threadData[threadData.length - 1].threads.toFixed(0)} active`
|
||||||
|
: ''}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 12: Build server UI**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd C:\Users\Hendrik\Documents\projects\cameleer3-server\ui
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected: Build succeeds.
|
||||||
|
|
||||||
|
- [ ] **Step 13: Commit and push**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd C:\Users\Hendrik\Documents\projects\cameleer3-server
|
||||||
|
git add ui/
|
||||||
|
git commit -m "feat: migrate agent charts to ThemedChart + Recharts
|
||||||
|
|
||||||
|
Replace custom LineChart/AreaChart/BarChart usage with ThemedChart
|
||||||
|
wrapper. Data format changed from ChartSeries[] to Recharts-native
|
||||||
|
flat objects. Uses DS v0.1.47."
|
||||||
|
git push
|
||||||
|
```
|
||||||
541
docs/superpowers/plans/2026-04-15-sidebar-section-layout.md
Normal file
@@ -0,0 +1,541 @@
|
|||||||
|
# Sidebar Section Layout Implementation Plan
|
||||||
|
|
||||||
|
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||||
|
|
||||||
|
**Goal:** Add `position` and `maxHeight` props to `Sidebar.Section` so sections can stack at the top or bottom of the sidebar with optional scrollable content areas, and style all scrollbars to match the dark sidebar aesthetic.
|
||||||
|
|
||||||
|
**Architecture:** Extend the existing flexbox column layout inside `SidebarRoot` by partitioning section children into top/bottom groups with a flex spacer between them. Each group wrapper scrolls independently when the viewport is short. `SidebarSection` gets a content wrapper div that accepts an inline `maxHeight` and scrolls its children. Custom thin scrollbar styles are applied via CSS.
|
||||||
|
|
||||||
|
**Tech Stack:** React, CSS Modules, Vitest + React Testing Library
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## File Structure
|
||||||
|
|
||||||
|
| File | Action | Responsibility |
|
||||||
|
|------|--------|----------------|
|
||||||
|
| `src/design-system/layout/Sidebar/Sidebar.tsx` | Modify | Add `position` and `maxHeight` props to `SidebarSectionProps`, wrap children in `.sectionContent` div, partition children in `SidebarRoot` into top/bottom groups |
|
||||||
|
| `src/design-system/layout/Sidebar/Sidebar.module.css` | Modify | Add `.sectionGroup`, `.sectionSpacer`, `.sectionContent` classes, custom scrollbar styles |
|
||||||
|
| `src/design-system/layout/Sidebar/Sidebar.test.tsx` | Modify | Add tests for position partitioning, maxHeight content wrapper, spacer rendering, collapsed behavior |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 1: Add CSS classes for section groups, spacer, content wrapper, and scrollbars
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/design-system/layout/Sidebar/Sidebar.module.css:392` (before the bottom links section)
|
||||||
|
|
||||||
|
- [ ] **Step 1: Add `.sectionGroup`, `.sectionSpacer`, `.sectionContent`, and scrollbar styles**
|
||||||
|
|
||||||
|
Insert the following block before the `/* ── Bottom links */` comment at line 392:
|
||||||
|
|
||||||
|
```css
|
||||||
|
/* ── Section groups (top/bottom positioning) ───────────────────────────── */
|
||||||
|
|
||||||
|
.sectionGroup {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
overflow-y: auto;
|
||||||
|
min-height: 0;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionGroup::-webkit-scrollbar {
|
||||||
|
width: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionGroup::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionGroup::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(255, 255, 255, 0.15);
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionGroup::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionSpacer {
|
||||||
|
flex: 1 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Section content (scrollable maxHeight) ────────────────────────────── */
|
||||||
|
|
||||||
|
.sectionContent {
|
||||||
|
overflow-y: auto;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionContent::-webkit-scrollbar {
|
||||||
|
width: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionContent::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionContent::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(255, 255, 255, 0.15);
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionContent::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.3);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/design-system/layout/Sidebar/Sidebar.module.css
|
||||||
|
git commit -m "style: add section group, spacer, content, and scrollbar CSS classes"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 2: Add `maxHeight` prop and content wrapper to `SidebarSection`
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/design-system/layout/Sidebar/Sidebar.tsx:21-29` (SidebarSectionProps)
|
||||||
|
- Modify: `src/design-system/layout/Sidebar/Sidebar.tsx:78-131` (SidebarSection component)
|
||||||
|
- Test: `src/design-system/layout/Sidebar/Sidebar.test.tsx`
|
||||||
|
|
||||||
|
- [ ] **Step 1: Write the failing tests**
|
||||||
|
|
||||||
|
Add the following tests to the end of the `describe` block in `Sidebar.test.tsx`:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// 17. renders sectionContent wrapper with maxHeight when open
|
||||||
|
it('renders section content wrapper with maxHeight style when open', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section
|
||||||
|
icon={<span>ic</span>}
|
||||||
|
label="Apps"
|
||||||
|
open
|
||||||
|
onToggle={vi.fn()}
|
||||||
|
maxHeight="200px"
|
||||||
|
>
|
||||||
|
<div>child</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const contentWrapper = container.querySelector('.sectionContent')
|
||||||
|
expect(contentWrapper).toBeInTheDocument()
|
||||||
|
expect(contentWrapper).toHaveStyle({ maxHeight: '200px' })
|
||||||
|
expect(screen.getByText('child')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 18. renders sectionContent wrapper without maxHeight when not provided
|
||||||
|
it('renders section content wrapper without inline maxHeight when maxHeight is not provided', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section
|
||||||
|
icon={<span>ic</span>}
|
||||||
|
label="Apps"
|
||||||
|
open
|
||||||
|
onToggle={vi.fn()}
|
||||||
|
>
|
||||||
|
<div>child</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const contentWrapper = container.querySelector('.sectionContent')
|
||||||
|
expect(contentWrapper).toBeInTheDocument()
|
||||||
|
expect(contentWrapper).not.toHaveStyle({ maxHeight: '200px' })
|
||||||
|
expect(screen.getByText('child')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 19. does not render sectionContent wrapper when section is closed
|
||||||
|
it('does not render section content wrapper when section is closed', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section
|
||||||
|
icon={<span>ic</span>}
|
||||||
|
label="Apps"
|
||||||
|
open={false}
|
||||||
|
onToggle={vi.fn()}
|
||||||
|
maxHeight="200px"
|
||||||
|
>
|
||||||
|
<div>child</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const contentWrapper = container.querySelector('.sectionContent')
|
||||||
|
expect(contentWrapper).not.toBeInTheDocument()
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Run tests to verify they fail**
|
||||||
|
|
||||||
|
Run: `npx vitest run src/design-system/layout/Sidebar/Sidebar.test.tsx`
|
||||||
|
Expected: FAIL — `maxHeight` prop is not recognized, no `.sectionContent` wrapper exists.
|
||||||
|
|
||||||
|
- [ ] **Step 3: Add `position` and `maxHeight` to `SidebarSectionProps`**
|
||||||
|
|
||||||
|
Update the interface at line 21:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
interface SidebarSectionProps {
|
||||||
|
icon: ReactNode
|
||||||
|
label: string
|
||||||
|
open: boolean
|
||||||
|
onToggle: () => void
|
||||||
|
active?: boolean
|
||||||
|
children: ReactNode
|
||||||
|
className?: string
|
||||||
|
position?: 'top' | 'bottom'
|
||||||
|
maxHeight?: string
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 4: Update `SidebarSection` to destructure new props and wrap children**
|
||||||
|
|
||||||
|
Update the function signature at line 78 to destructure the new props (they are accepted but `position` is only used by `SidebarRoot`):
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
function SidebarSection({
|
||||||
|
icon,
|
||||||
|
label,
|
||||||
|
open,
|
||||||
|
onToggle,
|
||||||
|
active,
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
position: _position,
|
||||||
|
maxHeight,
|
||||||
|
}: SidebarSectionProps) {
|
||||||
|
```
|
||||||
|
|
||||||
|
Then replace `{open && children}` (line 128) with:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{open && (
|
||||||
|
<div
|
||||||
|
className={styles.sectionContent}
|
||||||
|
style={maxHeight ? { maxHeight } : undefined}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 5: Run tests to verify they pass**
|
||||||
|
|
||||||
|
Run: `npx vitest run src/design-system/layout/Sidebar/Sidebar.test.tsx`
|
||||||
|
Expected: ALL PASS
|
||||||
|
|
||||||
|
- [ ] **Step 6: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/design-system/layout/Sidebar/Sidebar.tsx src/design-system/layout/Sidebar/Sidebar.test.tsx
|
||||||
|
git commit -m "feat: add maxHeight prop with sectionContent wrapper to SidebarSection"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 3: Partition children in `SidebarRoot` into top/bottom groups
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/design-system/layout/Sidebar/Sidebar.tsx:167-244` (SidebarRoot component)
|
||||||
|
- Test: `src/design-system/layout/Sidebar/Sidebar.test.tsx`
|
||||||
|
|
||||||
|
- [ ] **Step 1: Write the failing tests**
|
||||||
|
|
||||||
|
Add the following tests to the end of the `describe` block in `Sidebar.test.tsx`:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// 20. renders top sections in sectionGroup wrapper
|
||||||
|
it('renders sections in top group wrapper by default', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Apps" open onToggle={vi.fn()}>
|
||||||
|
<div>apps content</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const topGroup = container.querySelector('.sectionGroup')
|
||||||
|
expect(topGroup).toBeInTheDocument()
|
||||||
|
expect(topGroup!.textContent).toContain('Apps')
|
||||||
|
})
|
||||||
|
|
||||||
|
// 21. renders bottom sections in separate group with spacer
|
||||||
|
it('renders bottom sections in a separate group with spacer between', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Apps" open onToggle={vi.fn()}>
|
||||||
|
<div>apps content</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Routes" open onToggle={vi.fn()} position="bottom">
|
||||||
|
<div>routes content</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const groups = container.querySelectorAll('.sectionGroup')
|
||||||
|
expect(groups).toHaveLength(2)
|
||||||
|
expect(groups[0].textContent).toContain('Apps')
|
||||||
|
expect(groups[1].textContent).toContain('Routes')
|
||||||
|
|
||||||
|
const spacer = container.querySelector('.sectionSpacer')
|
||||||
|
expect(spacer).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 22. does not render spacer when no bottom sections
|
||||||
|
it('does not render spacer when all sections are top', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Apps" open onToggle={vi.fn()}>
|
||||||
|
<div>apps content</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Agents" open onToggle={vi.fn()}>
|
||||||
|
<div>agents content</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const spacer = container.querySelector('.sectionSpacer')
|
||||||
|
expect(spacer).not.toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 23. collapsed sidebar renders bottom sections in bottom group
|
||||||
|
it('renders bottom sections in bottom group when sidebar is collapsed', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar collapsed onCollapseToggle={vi.fn()}>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Apps" open={false} onToggle={vi.fn()}>
|
||||||
|
<div>apps</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Routes" open={false} onToggle={vi.fn()} position="bottom">
|
||||||
|
<div>routes</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const groups = container.querySelectorAll('.sectionGroup')
|
||||||
|
expect(groups).toHaveLength(2)
|
||||||
|
|
||||||
|
// Bottom group should contain the Routes rail item
|
||||||
|
const bottomGroup = groups[1]
|
||||||
|
expect(bottomGroup.querySelector('[title="Routes"]')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Run tests to verify they fail**
|
||||||
|
|
||||||
|
Run: `npx vitest run src/design-system/layout/Sidebar/Sidebar.test.tsx`
|
||||||
|
Expected: FAIL — no `.sectionGroup` wrappers exist yet, sections render directly in `{rest}`.
|
||||||
|
|
||||||
|
- [ ] **Step 3: Rewrite the child partitioning logic in `SidebarRoot`**
|
||||||
|
|
||||||
|
Replace the entire IIFE inside the `<aside>` (lines 198–240) with the following:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{(() => {
|
||||||
|
const childArray = Children.toArray(children)
|
||||||
|
|
||||||
|
// Extract header
|
||||||
|
const headerIdx = childArray.findIndex(
|
||||||
|
(child) => isValidElement(child) && child.type === SidebarHeader,
|
||||||
|
)
|
||||||
|
const header = headerIdx >= 0 ? childArray[headerIdx] : null
|
||||||
|
const rest = headerIdx >= 0
|
||||||
|
? [...childArray.slice(0, headerIdx), ...childArray.slice(headerIdx + 1)]
|
||||||
|
: childArray
|
||||||
|
|
||||||
|
// Extract footer
|
||||||
|
const footerIdx = rest.findIndex(
|
||||||
|
(child) => isValidElement(child) && child.type === SidebarFooter,
|
||||||
|
)
|
||||||
|
const footer = footerIdx >= 0 ? rest[footerIdx] : null
|
||||||
|
const sections = footerIdx >= 0
|
||||||
|
? [...rest.slice(0, footerIdx), ...rest.slice(footerIdx + 1)]
|
||||||
|
: rest
|
||||||
|
|
||||||
|
// Partition sections into top/bottom by position prop
|
||||||
|
const topSections: typeof sections = []
|
||||||
|
const bottomSections: typeof sections = []
|
||||||
|
for (const child of sections) {
|
||||||
|
if (
|
||||||
|
isValidElement<SidebarSectionProps>(child) &&
|
||||||
|
child.props.position === 'bottom'
|
||||||
|
) {
|
||||||
|
bottomSections.push(child)
|
||||||
|
} else {
|
||||||
|
topSections.push(child)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasBottomSections = bottomSections.length > 0
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{header}
|
||||||
|
{onSearchChange && !collapsed && (
|
||||||
|
<div className={styles.searchWrap}>
|
||||||
|
<div className={styles.searchInner}>
|
||||||
|
<span className={styles.searchIcon} aria-hidden="true">
|
||||||
|
<Search size={12} />
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
className={styles.searchInput}
|
||||||
|
type="text"
|
||||||
|
placeholder="Filter..."
|
||||||
|
value={searchValue ?? ''}
|
||||||
|
onChange={(e) => onSearchChange(e.target.value)}
|
||||||
|
/>
|
||||||
|
{searchValue && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={styles.searchClear}
|
||||||
|
onClick={() => onSearchChange('')}
|
||||||
|
aria-label="Clear search"
|
||||||
|
>
|
||||||
|
<X size={12} />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className={styles.sectionGroup}>
|
||||||
|
{topSections}
|
||||||
|
</div>
|
||||||
|
{hasBottomSections && <div className={styles.sectionSpacer} />}
|
||||||
|
{hasBottomSections && (
|
||||||
|
<div className={styles.sectionGroup}>
|
||||||
|
{bottomSections}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{footer}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
})()}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 4: Run tests to verify they pass**
|
||||||
|
|
||||||
|
Run: `npx vitest run src/design-system/layout/Sidebar/Sidebar.test.tsx`
|
||||||
|
Expected: ALL PASS
|
||||||
|
|
||||||
|
- [ ] **Step 5: Run the full test suite to check for regressions**
|
||||||
|
|
||||||
|
Run: `npx vitest run`
|
||||||
|
Expected: ALL PASS
|
||||||
|
|
||||||
|
- [ ] **Step 6: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/design-system/layout/Sidebar/Sidebar.tsx src/design-system/layout/Sidebar/Sidebar.test.tsx
|
||||||
|
git commit -m "feat: partition sidebar sections into top/bottom groups with spacer"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 4: Update `LayoutShell` to use `position="bottom"` on Routes and Starred sections
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `src/layout/LayoutShell.tsx:378-429` (the Routes and Starred section declarations)
|
||||||
|
|
||||||
|
- [ ] **Step 1: Add `position="bottom"` to the Routes section**
|
||||||
|
|
||||||
|
In `LayoutShell.tsx`, find the Routes `<Sidebar.Section>` (around line 378) and add `position="bottom"`:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
<Sidebar.Section
|
||||||
|
label="Routes"
|
||||||
|
icon={<GitBranch size={14} />}
|
||||||
|
open={!routesCollapsed}
|
||||||
|
onToggle={toggleRoutesCollapsed}
|
||||||
|
active={location.pathname.startsWith('/routes')}
|
||||||
|
position="bottom"
|
||||||
|
>
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Add `position="bottom"` to the Starred section**
|
||||||
|
|
||||||
|
Find the Starred `<Sidebar.Section>` (around line 396) and add `position="bottom"`:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{hasStarred && (
|
||||||
|
<Sidebar.Section
|
||||||
|
label="★ Starred"
|
||||||
|
icon={<span />}
|
||||||
|
open={true}
|
||||||
|
onToggle={() => {}}
|
||||||
|
active={false}
|
||||||
|
position="bottom"
|
||||||
|
>
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3: Run the full test suite**
|
||||||
|
|
||||||
|
Run: `npx vitest run`
|
||||||
|
Expected: ALL PASS
|
||||||
|
|
||||||
|
- [ ] **Step 4: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add src/layout/LayoutShell.tsx
|
||||||
|
git commit -m "feat: position Routes and Starred sections at bottom of sidebar"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 5: Visual verification in the browser
|
||||||
|
|
||||||
|
**Files:** None (manual verification)
|
||||||
|
|
||||||
|
- [ ] **Step 1: Start the dev server**
|
||||||
|
|
||||||
|
Run: `npm run dev`
|
||||||
|
|
||||||
|
- [ ] **Step 2: Verify top/bottom layout**
|
||||||
|
|
||||||
|
Open the app in a browser. Confirm:
|
||||||
|
- Applications and Agents sections are at the top
|
||||||
|
- Routes and Starred sections are at the bottom, above the footer
|
||||||
|
- A flexible gap separates the two groups
|
||||||
|
|
||||||
|
- [ ] **Step 3: Verify scrollbar styling**
|
||||||
|
|
||||||
|
If a section has enough content to overflow (or temporarily add `maxHeight="100px"` to the Applications section in `LayoutShell.tsx`), confirm:
|
||||||
|
- Content scrolls within the section
|
||||||
|
- Scrollbar is thin (4px), with a muted thumb on a transparent track
|
||||||
|
- Scrollbar thumb brightens on hover
|
||||||
|
|
||||||
|
- [ ] **Step 4: Verify collapsed sidebar**
|
||||||
|
|
||||||
|
Collapse the sidebar and confirm:
|
||||||
|
- Top section icons stay at the top
|
||||||
|
- Bottom section icons cluster near the footer
|
||||||
|
- Spacer separates the two groups in the rail
|
||||||
|
|
||||||
|
- [ ] **Step 5: Verify short viewport**
|
||||||
|
|
||||||
|
Resize the browser window very short. Confirm:
|
||||||
|
- Both top and bottom groups scroll independently
|
||||||
|
- No content is permanently clipped or inaccessible
|
||||||
|
|
||||||
|
- [ ] **Step 6: Remove any temporary `maxHeight` props added for testing**
|
||||||
|
|
||||||
|
If you added `maxHeight="100px"` to Applications in Step 3, remove it now.
|
||||||
121
docs/superpowers/specs/2026-04-12-recharts-migration-design.md
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
# Recharts Migration Design
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
|
||||||
|
Replace the design system's hand-rolled SVG chart components (LineChart, AreaChart, BarChart) with Recharts-based implementations. The current custom charts have responsiveness issues (preserveAspectRatio distorting text), limited tooltip/axis formatting, and growing maintenance burden.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
Add Recharts as a DS dependency. Replace the three custom chart components and `_chart-utils.ts` with a single `ThemedChart` wrapper component. Consumers compose Recharts elements (`<Line>`, `<Area>`, `<Bar>`, etc.) as children inside `<ThemedChart>`. The DS re-exports Recharts components so consumers don't need to add Recharts as a separate dependency.
|
||||||
|
|
||||||
|
Sparkline stays hand-rolled SVG (no axes, no tooltips — Recharts is overkill).
|
||||||
|
|
||||||
|
### What gets removed
|
||||||
|
|
||||||
|
- `composites/LineChart/` directory (LineChart.tsx, LineChart.module.css)
|
||||||
|
- `composites/AreaChart/` directory (AreaChart.tsx, AreaChart.module.css)
|
||||||
|
- `composites/BarChart/` directory (BarChart.tsx, BarChart.module.css)
|
||||||
|
- `composites/_chart-utils.ts`
|
||||||
|
- `ChartSeries` and `DataPoint` type exports
|
||||||
|
|
||||||
|
### What gets added
|
||||||
|
|
||||||
|
- `composites/ThemedChart/ThemedChart.tsx` — wrapper component
|
||||||
|
- `composites/ThemedChart/ChartTooltip.tsx` — internal themed tooltip
|
||||||
|
- `composites/ThemedChart/ThemedChart.module.css`
|
||||||
|
- Recharts re-exports from the DS barrel
|
||||||
|
|
||||||
|
### What stays unchanged
|
||||||
|
|
||||||
|
- `utils/rechartsTheme.ts` (now also used internally by ThemedChart)
|
||||||
|
- `CHART_COLORS`
|
||||||
|
- `primitives/Sparkline/`
|
||||||
|
|
||||||
|
## Data Format
|
||||||
|
|
||||||
|
Consumers use Recharts-native flat data format instead of the current `ChartSeries[]`:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// Before (custom)
|
||||||
|
const series = [
|
||||||
|
{ label: 'CPU %', data: pts.map(p => ({ x: new Date(p.time), y: p.value * 100 })) }
|
||||||
|
]
|
||||||
|
<AreaChart series={series} height={160} yLabel="%" />
|
||||||
|
|
||||||
|
// After (Recharts-native)
|
||||||
|
const data = pts.map(p => ({ time: p.time, cpu: p.value * 100 }))
|
||||||
|
<ThemedChart data={data} height={160} xDataKey="time" yLabel="%">
|
||||||
|
<Area dataKey="cpu" stroke={CHART_COLORS[0]} fill={CHART_COLORS[0]} fillOpacity={0.1} />
|
||||||
|
</ThemedChart>
|
||||||
|
```
|
||||||
|
|
||||||
|
This is a breaking change. The migration cost is bounded — only `AgentInstance.tsx` in the server repo uses these components.
|
||||||
|
|
||||||
|
## ThemedChart API
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
interface ThemedChartProps {
|
||||||
|
data: Record<string, any>[]
|
||||||
|
height?: number // default 200
|
||||||
|
xDataKey?: string // default "time"
|
||||||
|
xType?: 'number' | 'category' // default "category"
|
||||||
|
xTickFormatter?: (value: any) => string
|
||||||
|
yTickFormatter?: (value: any) => string
|
||||||
|
yLabel?: string
|
||||||
|
children: React.ReactNode // Recharts elements
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
ThemedChart renders internally:
|
||||||
|
- `ResponsiveContainer` (width 100%, height from prop)
|
||||||
|
- `ComposedChart` (supports mixing Line + Bar + Area in one chart)
|
||||||
|
- `CartesianGrid` with `rechartsTheme.cartesianGrid`
|
||||||
|
- `XAxis` with `rechartsTheme.xAxis` + formatter
|
||||||
|
- `YAxis` with `rechartsTheme.yAxis` + formatter + label
|
||||||
|
- `Tooltip` with custom `ChartTooltip` component
|
||||||
|
|
||||||
|
## Tooltip
|
||||||
|
|
||||||
|
ThemedChart provides a custom `ChartTooltip` component (internal, not exported) that:
|
||||||
|
- Shows the x-value formatted as date/time in a header row (mono font, subtle border separator)
|
||||||
|
- Shows each series with colored dot + label + formatted value
|
||||||
|
- Uses DS tokens for styling (surface bg, border, shadow, mono font)
|
||||||
|
|
||||||
|
Consumers can override by passing their own `<Tooltip content={...} />` as a child. Recharts uses the last Tooltip it finds, so a consumer-provided one replaces the default.
|
||||||
|
|
||||||
|
## DS Re-exports
|
||||||
|
|
||||||
|
Selected Recharts components re-exported so consumers don't need `recharts` in their own package.json:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
export { ThemedChart } from './ThemedChart/ThemedChart'
|
||||||
|
export {
|
||||||
|
Line, Area, Bar, ReferenceLine, ReferenceArea,
|
||||||
|
Legend, Brush, ComposedChart,
|
||||||
|
} from 'recharts'
|
||||||
|
```
|
||||||
|
|
||||||
|
More can be added on demand.
|
||||||
|
|
||||||
|
## Consumer Migration — Server UI
|
||||||
|
|
||||||
|
`AgentInstance.tsx` has 6 charts to migrate:
|
||||||
|
|
||||||
|
| Chart | Before | After |
|
||||||
|
|-------|--------|-------|
|
||||||
|
| CPU Usage | `<AreaChart series={cpuSeries} threshold={...}>` | `<ThemedChart><Area dataKey="cpu" /><ReferenceLine y={85} /></ThemedChart>` |
|
||||||
|
| Memory (Heap) | `<AreaChart series={heapSeries} threshold={...}>` | `<ThemedChart><Area dataKey="heap" /><ReferenceLine y={max} /></ThemedChart>` |
|
||||||
|
| Throughput | `<LineChart series={throughputSeries}>` | `<ThemedChart><Line dataKey="throughput" /></ThemedChart>` |
|
||||||
|
| Error Rate | `<LineChart series={errorSeries}>` | `<ThemedChart><Line dataKey="errorPct" /></ThemedChart>` |
|
||||||
|
| Thread Count | `<LineChart series={threadSeries}>` | `<ThemedChart><Line dataKey="threads" /></ThemedChart>` |
|
||||||
|
| GC Pauses | `<AreaChart series={gcSeries}>` | `<ThemedChart><Area dataKey="gc" /></ThemedChart>` |
|
||||||
|
|
||||||
|
Data prep changes from building `ChartSeries[]` arrays to flat objects with named keys.
|
||||||
|
|
||||||
|
## Not in Scope
|
||||||
|
|
||||||
|
- Sparkline migration (no responsiveness issues, no axes/tooltips)
|
||||||
|
- SaaS UI (no chart component usage)
|
||||||
|
- Dashboard tab (already uses Recharts directly with `rechartsTheme`)
|
||||||
|
- New chart types (treemap, radar, etc. — consumers compose these directly)
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
# Sidebar Section Layout: Top/Bottom Positioning & Scrollable Sections
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
Extend `Sidebar.Section` with two new optional props:
|
||||||
|
|
||||||
|
- `position: 'top' | 'bottom'` — controls whether a section stacks from the top of the sidebar or from the bottom (above the footer). Default: `'top'`.
|
||||||
|
- `maxHeight: string` — CSS length value (e.g. `"250px"`, `"30vh"`) that constrains the section's content area. When content exceeds this height, it scrolls. The section header/toggle always remains visible.
|
||||||
|
|
||||||
|
This enables a layout where primary sections (Applications, Agents) occupy the top of the sidebar, while secondary sections (Routes, Starred) cluster near the bottom — with a flexible spacer absorbing remaining vertical space between the two groups.
|
||||||
|
|
||||||
|
## API Changes
|
||||||
|
|
||||||
|
### `Sidebar.Section` — new optional props
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
interface SidebarSectionProps {
|
||||||
|
icon: ReactNode
|
||||||
|
label: string
|
||||||
|
open: boolean
|
||||||
|
onToggle: () => void
|
||||||
|
active?: boolean
|
||||||
|
children: ReactNode
|
||||||
|
className?: string
|
||||||
|
position?: 'top' | 'bottom' // default: 'top'
|
||||||
|
maxHeight?: string // CSS length, e.g. "250px", "30vh"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
No changes to `Sidebar.Header`, `Sidebar.Footer`, `Sidebar.FooterLink`, or `SidebarRoot` props.
|
||||||
|
|
||||||
|
### Consumer usage
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Header ... />
|
||||||
|
|
||||||
|
<Sidebar.Section label="Applications" ...>
|
||||||
|
<SidebarTree ... />
|
||||||
|
</Sidebar.Section>
|
||||||
|
|
||||||
|
<Sidebar.Section label="Agents" ...>
|
||||||
|
<SidebarTree ... />
|
||||||
|
</Sidebar.Section>
|
||||||
|
|
||||||
|
<Sidebar.Section label="Routes" position="bottom" maxHeight="200px" ...>
|
||||||
|
<SidebarTree ... />
|
||||||
|
</Sidebar.Section>
|
||||||
|
|
||||||
|
<Sidebar.Section label="Starred" position="bottom" ...>
|
||||||
|
...
|
||||||
|
</Sidebar.Section>
|
||||||
|
|
||||||
|
<Sidebar.Footer>...</Sidebar.Footer>
|
||||||
|
</Sidebar>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Layout Model
|
||||||
|
|
||||||
|
### SidebarRoot child partitioning
|
||||||
|
|
||||||
|
`SidebarRoot` already inspects children to extract `Header`. This extends the same pattern:
|
||||||
|
|
||||||
|
1. Extract `Header` children (existing)
|
||||||
|
2. Extract `Footer` children
|
||||||
|
3. Partition remaining children into `topSections` and `bottomSections` based on `position` prop (default `'top'`)
|
||||||
|
|
||||||
|
### Render structure
|
||||||
|
|
||||||
|
```
|
||||||
|
<aside class="sidebar">
|
||||||
|
[collapse toggle]
|
||||||
|
{header}
|
||||||
|
{search bar}
|
||||||
|
<div class="sectionGroup sectionGroupTop">
|
||||||
|
{topSections}
|
||||||
|
</div>
|
||||||
|
<div class="sectionSpacer" />
|
||||||
|
<div class="sectionGroup sectionGroupBottom">
|
||||||
|
{bottomSections}
|
||||||
|
</div>
|
||||||
|
{footer}
|
||||||
|
</aside>
|
||||||
|
```
|
||||||
|
|
||||||
|
When there are no bottom sections, the spacer is omitted. The layout behaves identically to today — footer's `margin-top: auto` handles positioning. Zero breaking changes for existing consumers.
|
||||||
|
|
||||||
|
### SidebarSection content wrapper
|
||||||
|
|
||||||
|
A new `.sectionContent` div wraps only the `children` inside `SidebarSection` (not the toggle header). When `maxHeight` is provided, it receives the value as an inline `max-height` style.
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{open && (
|
||||||
|
<div
|
||||||
|
className={styles.sectionContent}
|
||||||
|
style={maxHeight ? { maxHeight } : undefined}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
```
|
||||||
|
|
||||||
|
## CSS Changes
|
||||||
|
|
||||||
|
### Group wrappers
|
||||||
|
|
||||||
|
```css
|
||||||
|
.sectionGroup {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
overflow-y: auto;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionSpacer {
|
||||||
|
flex: 1 0 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Section content scrolling
|
||||||
|
|
||||||
|
```css
|
||||||
|
.sectionContent {
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`maxHeight` is applied as an inline style, not a CSS class, since it varies per section instance.
|
||||||
|
|
||||||
|
### Custom scrollbars
|
||||||
|
|
||||||
|
Applied to both `.sectionGroup` and `.sectionContent` to keep the dark sidebar aesthetic:
|
||||||
|
|
||||||
|
```css
|
||||||
|
/* Standard (Firefox, modern Chrome/Edge) */
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
|
||||||
|
|
||||||
|
/* WebKit (Safari, older Chrome) */
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(255, 255, 255, 0.15);
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.3);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Collapsed Sidebar Behavior
|
||||||
|
|
||||||
|
In collapsed (icon rail) mode, sections render as single icon buttons with no scrollable content:
|
||||||
|
|
||||||
|
- **`position`**: Respected — bottom sections render in the bottom group, so their icons cluster near the footer in the rail.
|
||||||
|
- **`maxHeight`**: Ignored — no content to constrain.
|
||||||
|
|
||||||
|
The group wrapper and spacer structure remains active in collapsed mode for consistent icon positioning.
|
||||||
|
|
||||||
|
## Edge Cases
|
||||||
|
|
||||||
|
| Scenario | Behavior |
|
||||||
|
|----------|----------|
|
||||||
|
| All sections `"top"` (no bottom sections) | No spacer rendered. Identical to current layout. |
|
||||||
|
| All sections `"bottom"` | Top group empty. Sections cluster above footer. |
|
||||||
|
| `maxHeight` set but content is shorter | No visual effect — wrapper is naturally smaller than max. |
|
||||||
|
| Very short viewport | Both group wrappers scroll independently via `overflow-y: auto` on `.sectionGroup`. |
|
||||||
|
|
||||||
|
## Files Changed
|
||||||
|
|
||||||
|
- `src/design-system/layout/Sidebar/Sidebar.tsx` — add `position` and `maxHeight` props to `SidebarSectionProps`, add `sectionContent` wrapper to `SidebarSection`, partition children in `SidebarRoot`
|
||||||
|
- `src/design-system/layout/Sidebar/Sidebar.module.css` — add `.sectionGroup`, `.sectionSpacer`, `.sectionContent`, custom scrollbar styles
|
||||||
|
- `src/design-system/layout/Sidebar/Sidebar.test.tsx` — new test cases for positioning and scrolling behavior
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
- Section with `maxHeight` renders content wrapper with correct inline style and `overflow-y: auto`
|
||||||
|
- Sections with `position="bottom"` render inside the bottom group wrapper
|
||||||
|
- Default `position` (omitted) renders in the top group
|
||||||
|
- When no bottom sections exist, no spacer is rendered
|
||||||
|
- Collapsed sidebar renders bottom sections in the bottom group
|
||||||
411
package-lock.json
generated
@@ -1,17 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "@cameleer/design-system",
|
"name": "@cameleer/design-system",
|
||||||
"version": "0.1.6",
|
"version": "0.1.46",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@cameleer/design-system",
|
"name": "@cameleer/design-system",
|
||||||
"version": "0.1.6",
|
"version": "0.1.46",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lucide-react": "^1.7.0",
|
"lucide-react": "^1.7.0",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"react-dom": "^19.0.0",
|
"react-dom": "^19.0.0",
|
||||||
"react-router-dom": "^7.0.0"
|
"react-router-dom": "^7.0.0",
|
||||||
|
"recharts": "^3.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "^1.58.2",
|
"@playwright/test": "^1.58.2",
|
||||||
@@ -1012,6 +1013,42 @@
|
|||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@reduxjs/toolkit": {
|
||||||
|
"version": "2.11.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@reduxjs/toolkit/-/toolkit-2.11.2.tgz",
|
||||||
|
"integrity": "sha512-Kd6kAHTA6/nUpp8mySPqj3en3dm0tdMIgbttnQ1xFMVpufoj+ADi8pXLBsd4xzTRHQa7t/Jv8W5UnCuW4kuWMQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@standard-schema/spec": "^1.0.0",
|
||||||
|
"@standard-schema/utils": "^0.3.0",
|
||||||
|
"immer": "^11.0.0",
|
||||||
|
"redux": "^5.0.1",
|
||||||
|
"redux-thunk": "^3.1.0",
|
||||||
|
"reselect": "^5.1.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^16.9.0 || ^17.0.0 || ^18 || ^19",
|
||||||
|
"react-redux": "^7.2.1 || ^8.1.3 || ^9.0.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"react-redux": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@reduxjs/toolkit/node_modules/immer": {
|
||||||
|
"version": "11.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/immer/-/immer-11.1.4.tgz",
|
||||||
|
"integrity": "sha512-XREFCPo6ksxVzP4E0ekD5aMdf8WMwmdNaz6vuvxgI40UaEiu6q3p8X52aU6GdyvLY3XXX/8R7JOTXStz/nBbRw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/immer"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@rolldown/pluginutils": {
|
"node_modules/@rolldown/pluginutils": {
|
||||||
"version": "1.0.0-beta.27",
|
"version": "1.0.0-beta.27",
|
||||||
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.27.tgz",
|
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.27.tgz",
|
||||||
@@ -1519,6 +1556,18 @@
|
|||||||
"string-argv": "~0.3.1"
|
"string-argv": "~0.3.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@standard-schema/spec": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@standard-schema/utils": {
|
||||||
|
"version": "0.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@standard-schema/utils/-/utils-0.3.0.tgz",
|
||||||
|
"integrity": "sha512-e7Mew686owMaPJVNNLs55PUvgz371nKgwsc4vxE49zsODpJEnxgxRo2y/OKrqueavXgZNMDVj3DdHFlaSAeU8g==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@testing-library/dom": {
|
"node_modules/@testing-library/dom": {
|
||||||
"version": "10.4.1",
|
"version": "10.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.4.1.tgz",
|
||||||
@@ -1680,6 +1729,69 @@
|
|||||||
"assertion-error": "^2.0.1"
|
"assertion-error": "^2.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/d3-array": {
|
||||||
|
"version": "3.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-array/-/d3-array-3.2.2.tgz",
|
||||||
|
"integrity": "sha512-hOLWVbm7uRza0BYXpIIW5pxfrKe0W+D5lrFiAEYR+pb6w3N2SwSMaJbXdUfSEv+dT4MfHBLtn5js0LAWaO6otw==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-color": {
|
||||||
|
"version": "3.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-color/-/d3-color-3.1.3.tgz",
|
||||||
|
"integrity": "sha512-iO90scth9WAbmgv7ogoq57O9YpKmFBbmoEoCHDB2xMBY0+/KVrqAaCDyCE16dUspeOvIxFFRI+0sEtqDqy2b4A==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-ease": {
|
||||||
|
"version": "3.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-ease/-/d3-ease-3.0.2.tgz",
|
||||||
|
"integrity": "sha512-NcV1JjO5oDzoK26oMzbILE6HW7uVXOHLQvHshBUW4UMdZGfiY6v5BeQwh9a9tCzv+CeefZQHJt5SRgK154RtiA==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-interpolate": {
|
||||||
|
"version": "3.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-interpolate/-/d3-interpolate-3.0.4.tgz",
|
||||||
|
"integrity": "sha512-mgLPETlrpVV1YRJIglr4Ez47g7Yxjl1lj7YKsiMCb27VJH9W8NVM6Bb9d8kkpG/uAQS5AmbA48q2IAolKKo1MA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-color": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-path": {
|
||||||
|
"version": "3.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-path/-/d3-path-3.1.1.tgz",
|
||||||
|
"integrity": "sha512-VMZBYyQvbGmWyWVea0EHs/BwLgxc+MKi1zLDCONksozI4YJMcTt8ZEuIR4Sb1MMTE8MMW49v0IwI5+b7RmfWlg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-scale": {
|
||||||
|
"version": "4.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-scale/-/d3-scale-4.0.9.tgz",
|
||||||
|
"integrity": "sha512-dLmtwB8zkAeO/juAMfnV+sItKjlsw2lKdZVVy6LRr0cBmegxSABiLEpGVmSJJ8O08i4+sGR6qQtb6WtuwJdvVw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-time": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-shape": {
|
||||||
|
"version": "3.1.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-shape/-/d3-shape-3.1.8.tgz",
|
||||||
|
"integrity": "sha512-lae0iWfcDeR7qt7rA88BNiqdvPS5pFVPpo5OfjElwNaT2yyekbM0C9vK+yqBqEmHr6lDkRnYNoTBYlAgJa7a4w==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-path": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-time": {
|
||||||
|
"version": "3.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-time/-/d3-time-3.0.4.tgz",
|
||||||
|
"integrity": "sha512-yuzZug1nkAAaBlBBikKZTgzCeA+k1uy4ZFwWANOfKw5z5LRhV0gNA7gNkKm7HoK+HRN0wX3EkxGk0fpbWhmB7g==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-timer": {
|
||||||
|
"version": "3.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-timer/-/d3-timer-3.0.2.tgz",
|
||||||
|
"integrity": "sha512-Ps3T8E8dZDam6fUyNiMkekK3XUsaUEik+idO9/YjPtfj2qruF8tFBXS7XhtE4iIXBLxhmLjP3SXpLhVf21I9Lw==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/deep-eql": {
|
"node_modules/@types/deep-eql": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz",
|
||||||
@@ -1708,7 +1820,7 @@
|
|||||||
"version": "19.2.14",
|
"version": "19.2.14",
|
||||||
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.14.tgz",
|
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.14.tgz",
|
||||||
"integrity": "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w==",
|
"integrity": "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w==",
|
||||||
"dev": true,
|
"devOptional": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"csstype": "^3.2.2"
|
"csstype": "^3.2.2"
|
||||||
@@ -1724,6 +1836,12 @@
|
|||||||
"@types/react": "^19.2.0"
|
"@types/react": "^19.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/use-sync-external-store": {
|
||||||
|
"version": "0.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/use-sync-external-store/-/use-sync-external-store-0.0.6.tgz",
|
||||||
|
"integrity": "sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/whatwg-mimetype": {
|
"node_modules/@types/whatwg-mimetype": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/whatwg-mimetype/-/whatwg-mimetype-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/whatwg-mimetype/-/whatwg-mimetype-3.0.2.tgz",
|
||||||
@@ -2319,6 +2437,15 @@
|
|||||||
"node": ">= 16"
|
"node": ">= 16"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/clsx": {
|
||||||
|
"version": "2.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz",
|
||||||
|
"integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/color-convert": {
|
"node_modules/color-convert": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||||
@@ -2399,9 +2526,130 @@
|
|||||||
"version": "3.2.3",
|
"version": "3.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
|
||||||
"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==",
|
"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==",
|
||||||
"dev": true,
|
"devOptional": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/d3-array": {
|
||||||
|
"version": "3.2.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-array/-/d3-array-3.2.4.tgz",
|
||||||
|
"integrity": "sha512-tdQAmyA18i4J7wprpYq8ClcxZy3SC31QMeByyCFyRt7BVHdREQZ5lpzoe5mFEYZUWe+oq8HBvk9JjpibyEV4Jg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"internmap": "1 - 2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-color": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-color/-/d3-color-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-zg/chbXyeBtMQ1LbD/WSoW2DpC3I0mpmPdW+ynRTj/x2DAWYrIY7qeZIHidozwV24m4iavr15lNwIwLxRmOxhA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-ease": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-ease/-/d3-ease-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-wR/XK3D3XcLIZwpbvQwQ5fK+8Ykds1ip7A2Txe0yxncXSdq1L9skcG7blcedkOX+ZcgxGAmLX1FrRGbADwzi0w==",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-format": {
|
||||||
|
"version": "3.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-format/-/d3-format-3.1.2.tgz",
|
||||||
|
"integrity": "sha512-AJDdYOdnyRDV5b6ArilzCPPwc1ejkHcoyFarqlPqT7zRYjhavcT3uSrqcMvsgh2CgoPbK3RCwyHaVyxYcP2Arg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-interpolate": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-interpolate/-/d3-interpolate-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-3bYs1rOD33uo8aqJfKP3JWPAibgw8Zm2+L9vBKEHJ2Rg+viTR7o5Mmv5mZcieN+FRYaAOWX5SJATX6k1PWz72g==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-color": "1 - 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-path": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-path/-/d3-path-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-p3KP5HCf/bvjBSSKuXid6Zqijx7wIfNW+J/maPs+iwR35at5JCbLUT0LzF1cnjbCHWhqzQTIN2Jpe8pRebIEFQ==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-scale": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-scale/-/d3-scale-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-GZW464g1SH7ag3Y7hXjf8RoUuAFIqklOAq3MRl4OaWabTFJY9PN/E1YklhXLh+OQ3fM9yS2nOkCoS+WLZ6kvxQ==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-array": "2.10.0 - 3",
|
||||||
|
"d3-format": "1 - 3",
|
||||||
|
"d3-interpolate": "1.2.0 - 3",
|
||||||
|
"d3-time": "2.1.1 - 3",
|
||||||
|
"d3-time-format": "2 - 4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-shape": {
|
||||||
|
"version": "3.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-shape/-/d3-shape-3.2.0.tgz",
|
||||||
|
"integrity": "sha512-SaLBuwGm3MOViRq2ABk3eLoxwZELpH6zhl3FbAoJ7Vm1gofKx6El1Ib5z23NUEhF9AsGl7y+dzLe5Cw2AArGTA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-path": "^3.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-time": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-time/-/d3-time-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-VqKjzBLejbSMT4IgbmVgDjpkYrNWUYJnbCGo874u7MMKIWsILRX+OpX/gTk8MqjpT1A/c6HY2dCA77ZN0lkQ2Q==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-array": "2 - 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-time-format": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-time-format/-/d3-time-format-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-dJxPBlzC7NugB2PDLwo9Q8JiTR3M3e4/XANkreKSUxF8vvXKqm1Yfq4Q5dl8budlunRVlUUaDUgFt7eA8D6NLg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-time": "1 - 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-timer": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-timer/-/d3-timer-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-ndfJ/JxxMd3nw31uyKoY2naivF+r29V+Lc0svZxe1JvvIRmi8hUsrMvdOwgS1o6uBHmiz91geQ0ylPP0aj1VUA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/de-indent": {
|
"node_modules/de-indent": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz",
|
||||||
@@ -2427,6 +2675,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/decimal.js-light": {
|
||||||
|
"version": "2.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/decimal.js-light/-/decimal.js-light-2.5.1.tgz",
|
||||||
|
"integrity": "sha512-qIMFpTMZmny+MMIitAB6D7iVPEorVw6YQRWkvarTkT4tBeSLLiHzcwj6q0MmYSFCiVpiqPJTJEYIrpcPzVEIvg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/deep-eql": {
|
"node_modules/deep-eql": {
|
||||||
"version": "5.0.2",
|
"version": "5.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz",
|
||||||
@@ -2506,6 +2760,16 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/es-toolkit": {
|
||||||
|
"version": "1.45.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/es-toolkit/-/es-toolkit-1.45.1.tgz",
|
||||||
|
"integrity": "sha512-/jhoOj/Fx+A+IIyDNOvO3TItGmlMKhtX8ISAHKE90c4b/k1tqaqEZ+uUqfpU8DMnW5cgNJv606zS55jGvza0Xw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"workspaces": [
|
||||||
|
"docs",
|
||||||
|
"benchmarks"
|
||||||
|
]
|
||||||
|
},
|
||||||
"node_modules/esbuild": {
|
"node_modules/esbuild": {
|
||||||
"version": "0.25.12",
|
"version": "0.25.12",
|
||||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.12.tgz",
|
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.12.tgz",
|
||||||
@@ -2568,6 +2832,12 @@
|
|||||||
"@types/estree": "^1.0.0"
|
"@types/estree": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/eventemitter3": {
|
||||||
|
"version": "5.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.4.tgz",
|
||||||
|
"integrity": "sha512-mlsTRyGaPBjPedk6Bvw+aqbsXDtoAyAzm5MO7JgU+yVRyMQ5O8bD4Kcci7BS85f93veegeCPkL8R4GLClnjLFw==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/expect-type": {
|
"node_modules/expect-type": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz",
|
||||||
@@ -2814,6 +3084,16 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/immer": {
|
||||||
|
"version": "10.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/immer/-/immer-10.2.0.tgz",
|
||||||
|
"integrity": "sha512-d/+XTN3zfODyjr89gM3mPq1WNX2B8pYsu7eORitdwyA2sBubnTl3laYlBk4sXY5FUa5qTZGBDPJICVbvqzjlbw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/immer"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/import-lazy": {
|
"node_modules/import-lazy": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/import-lazy/-/import-lazy-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/import-lazy/-/import-lazy-4.0.0.tgz",
|
||||||
@@ -2834,6 +3114,15 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/internmap": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/internmap/-/internmap-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-5Hh7Y1wQbvY5ooGgPbDaL5iYLAPzMTUrjMulskHLH6wnv/A+1q5rgEaiuqEjB+oxGXIVZs1FF+R/KPN3ZSQYYg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/is-core-module": {
|
"node_modules/is-core-module": {
|
||||||
"version": "2.16.1",
|
"version": "2.16.1",
|
||||||
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz",
|
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz",
|
||||||
@@ -3476,10 +3765,32 @@
|
|||||||
"version": "17.0.2",
|
"version": "17.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
|
||||||
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
|
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true
|
"peer": true
|
||||||
},
|
},
|
||||||
|
"node_modules/react-redux": {
|
||||||
|
"version": "9.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-9.2.0.tgz",
|
||||||
|
"integrity": "sha512-ROY9fvHhwOD9ySfrF0wmvu//bKCQ6AeZZq1nJNtbDC+kk5DuSuNX/n6YWYF/SYy7bSba4D4FSz8DJeKY/S/r+g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/use-sync-external-store": "^0.0.6",
|
||||||
|
"use-sync-external-store": "^1.4.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": "^18.2.25 || ^19",
|
||||||
|
"react": "^18.0 || ^19",
|
||||||
|
"redux": "^5.0.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"redux": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/react-refresh": {
|
"node_modules/react-refresh": {
|
||||||
"version": "0.17.0",
|
"version": "0.17.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.17.0.tgz",
|
||||||
@@ -3528,6 +3839,36 @@
|
|||||||
"react-dom": ">=18"
|
"react-dom": ">=18"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/recharts": {
|
||||||
|
"version": "3.8.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/recharts/-/recharts-3.8.1.tgz",
|
||||||
|
"integrity": "sha512-mwzmO1s9sFL0TduUpwndxCUNoXsBw3u3E/0+A+cLcrSfQitSG62L32N69GhqUrrT5qKcAE3pCGVINC6pqkBBQg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"workspaces": [
|
||||||
|
"www"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@reduxjs/toolkit": "^1.9.0 || 2.x.x",
|
||||||
|
"clsx": "^2.1.1",
|
||||||
|
"decimal.js-light": "^2.5.1",
|
||||||
|
"es-toolkit": "^1.39.3",
|
||||||
|
"eventemitter3": "^5.0.1",
|
||||||
|
"immer": "^10.1.1",
|
||||||
|
"react-redux": "8.x.x || 9.x.x",
|
||||||
|
"reselect": "5.1.1",
|
||||||
|
"tiny-invariant": "^1.3.3",
|
||||||
|
"use-sync-external-store": "^1.2.2",
|
||||||
|
"victory-vendor": "^37.0.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
||||||
|
"react-dom": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
||||||
|
"react-is": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/redent": {
|
"node_modules/redent": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz",
|
||||||
@@ -3542,6 +3883,21 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/redux": {
|
||||||
|
"version": "5.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz",
|
||||||
|
"integrity": "sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/redux-thunk": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-NW2r5T6ksUKXCabzhL9z+h206HQw/NJkcLm1GPImRQ8IzfXwRGqjVhKJGauHirT0DAuyy6hjdnMZaRoAcy0Klw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"peerDependencies": {
|
||||||
|
"redux": "^5.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/require-from-string": {
|
"node_modules/require-from-string": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
|
||||||
@@ -3552,6 +3908,12 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/reselect": {
|
||||||
|
"version": "5.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/reselect/-/reselect-5.1.1.tgz",
|
||||||
|
"integrity": "sha512-K/BG6eIky/SBpzfHZv/dd+9JBFiS4SWV7FIujVyJRux6e45+73RaUHXLmIR1f7WOMaQ0U1km6qwklRQxpJJY0w==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/resolve": {
|
"node_modules/resolve": {
|
||||||
"version": "1.22.11",
|
"version": "1.22.11",
|
||||||
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.11.tgz",
|
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.11.tgz",
|
||||||
@@ -3921,6 +4283,12 @@
|
|||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/tiny-invariant": {
|
||||||
|
"version": "1.3.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.3.3.tgz",
|
||||||
|
"integrity": "sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/tinybench": {
|
"node_modules/tinybench": {
|
||||||
"version": "2.9.0",
|
"version": "2.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz",
|
||||||
@@ -4051,6 +4419,37 @@
|
|||||||
"browserslist": ">= 4.21.0"
|
"browserslist": ">= 4.21.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/use-sync-external-store": {
|
||||||
|
"version": "1.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz",
|
||||||
|
"integrity": "sha512-Pp6GSwGP/NrPIrxVFAIkOQeyw8lFenOHijQWkUTrDvrF4ALqylP2C/KCkeS9dpUM3KvYRQhna5vt7IL95+ZQ9w==",
|
||||||
|
"license": "MIT",
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/victory-vendor": {
|
||||||
|
"version": "37.3.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/victory-vendor/-/victory-vendor-37.3.6.tgz",
|
||||||
|
"integrity": "sha512-SbPDPdDBYp+5MJHhBCAyI7wKM3d5ivekigc2Dk2s7pgbZ9wIgIBYGVw4zGHBml/qTFbexrofXW6Gu4noGxrOwQ==",
|
||||||
|
"license": "MIT AND ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-array": "^3.0.3",
|
||||||
|
"@types/d3-ease": "^3.0.0",
|
||||||
|
"@types/d3-interpolate": "^3.0.1",
|
||||||
|
"@types/d3-scale": "^4.0.2",
|
||||||
|
"@types/d3-shape": "^3.1.0",
|
||||||
|
"@types/d3-time": "^3.0.0",
|
||||||
|
"@types/d3-timer": "^3.0.0",
|
||||||
|
"d3-array": "^3.1.6",
|
||||||
|
"d3-ease": "^3.0.1",
|
||||||
|
"d3-interpolate": "^3.0.1",
|
||||||
|
"d3-scale": "^4.0.2",
|
||||||
|
"d3-shape": "^3.1.0",
|
||||||
|
"d3-time": "^3.0.0",
|
||||||
|
"d3-timer": "^3.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/vite": {
|
"node_modules/vite": {
|
||||||
"version": "6.4.1",
|
"version": "6.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.1.tgz",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cameleer/design-system",
|
"name": "@cameleer/design-system",
|
||||||
"version": "0.1.6",
|
"version": "0.1.56",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.es.js",
|
"main": "./dist/index.es.js",
|
||||||
"module": "./dist/index.es.js",
|
"module": "./dist/index.es.js",
|
||||||
@@ -40,7 +40,8 @@
|
|||||||
"lucide-react": "^1.7.0",
|
"lucide-react": "^1.7.0",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"react-dom": "^19.0.0",
|
"react-dom": "^19.0.0",
|
||||||
"react-router-dom": "^7.0.0"
|
"react-router-dom": "^7.0.0",
|
||||||
|
"recharts": "^3.8.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
|
|||||||
@@ -1,157 +0,0 @@
|
|||||||
.wrapper {
|
|
||||||
position: relative;
|
|
||||||
display: inline-flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.svg {
|
|
||||||
display: block;
|
|
||||||
overflow: visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
color: var(--text-muted);
|
|
||||||
font-size: 12px;
|
|
||||||
height: 120px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Grid */
|
|
||||||
.gridLine {
|
|
||||||
stroke: var(--border-subtle);
|
|
||||||
stroke-width: 1;
|
|
||||||
stroke-dasharray: 3 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.axisLabel {
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-size: 9px;
|
|
||||||
fill: var(--text-faint);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Threshold line */
|
|
||||||
.thresholdLine {
|
|
||||||
stroke: var(--error);
|
|
||||||
stroke-width: 1.5;
|
|
||||||
stroke-dasharray: 5 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.thresholdLabel {
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-size: 9px;
|
|
||||||
fill: var(--error);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Area + line */
|
|
||||||
.area {
|
|
||||||
opacity: 0.1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.line {
|
|
||||||
stroke-width: 2;
|
|
||||||
stroke-linecap: round;
|
|
||||||
stroke-linejoin: round;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Crosshair */
|
|
||||||
.crosshair {
|
|
||||||
stroke: var(--text-faint);
|
|
||||||
stroke-width: 1;
|
|
||||||
stroke-dasharray: 3 3;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Tooltip */
|
|
||||||
.tooltip {
|
|
||||||
position: absolute;
|
|
||||||
background: var(--bg-surface);
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
box-shadow: var(--shadow-md);
|
|
||||||
padding: 6px 10px;
|
|
||||||
font-size: 12px;
|
|
||||||
pointer-events: none;
|
|
||||||
z-index: 10;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipRow {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
margin-bottom: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipRow:last-child {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipDot {
|
|
||||||
width: 6px;
|
|
||||||
height: 6px;
|
|
||||||
border-radius: 50%;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipLabel {
|
|
||||||
color: var(--text-muted);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipValue {
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--text-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Legend */
|
|
||||||
.legend {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 12px;
|
|
||||||
padding-left: 48px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.legendItem {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--text-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.legendDot {
|
|
||||||
width: 8px;
|
|
||||||
height: 8px;
|
|
||||||
border-radius: 50%;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.legendLabel {
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Axis labels */
|
|
||||||
.yLabel {
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--text-muted);
|
|
||||||
writing-mode: vertical-lr;
|
|
||||||
transform: rotate(180deg);
|
|
||||||
text-align: center;
|
|
||||||
position: absolute;
|
|
||||||
left: 4px;
|
|
||||||
top: 0;
|
|
||||||
bottom: 28px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.xLabel {
|
|
||||||
text-align: center;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--text-muted);
|
|
||||||
padding-left: 48px;
|
|
||||||
}
|
|
||||||
@@ -1,254 +1,107 @@
|
|||||||
import { useState } from 'react'
|
import { useMemo } from 'react'
|
||||||
import styles from './AreaChart.module.css'
|
import { Area, ReferenceLine } from 'recharts'
|
||||||
import {
|
import { ThemedChart } from '../ThemedChart/ThemedChart'
|
||||||
computeYScale,
|
import { CHART_COLORS } from '../../utils/rechartsTheme'
|
||||||
computeXScale,
|
|
||||||
seriesPoints,
|
|
||||||
seriesPath,
|
|
||||||
formatAxisLabel,
|
|
||||||
CHART_COLORS,
|
|
||||||
type ChartSeries,
|
|
||||||
} from '../_chart-utils'
|
|
||||||
|
|
||||||
interface Threshold {
|
export interface DataPoint {
|
||||||
value: number
|
x: any
|
||||||
|
y: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChartSeries {
|
||||||
label: string
|
label: string
|
||||||
|
data: DataPoint[]
|
||||||
|
color?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AreaChartProps {
|
interface AreaChartProps {
|
||||||
series: ChartSeries[]
|
series: ChartSeries[]
|
||||||
xLabel?: string
|
|
||||||
yLabel?: string
|
|
||||||
threshold?: Threshold
|
|
||||||
height?: number
|
height?: number
|
||||||
width?: number
|
width?: number
|
||||||
|
yLabel?: string
|
||||||
|
xLabel?: string
|
||||||
|
thresholdValue?: number
|
||||||
|
thresholdLabel?: string
|
||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const Y_TICK_COUNT = 4
|
function formatTime(d: Date): string {
|
||||||
const DIMS = {
|
const h = String(d.getHours()).padStart(2, '0')
|
||||||
paddingTop: 12,
|
const m = String(d.getMinutes()).padStart(2, '0')
|
||||||
paddingRight: 16,
|
return `${h}:${m}`
|
||||||
paddingBottom: 28,
|
|
||||||
paddingLeft: 48,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AreaChart({
|
export function AreaChart({
|
||||||
series,
|
series,
|
||||||
xLabel,
|
height,
|
||||||
|
width,
|
||||||
yLabel,
|
yLabel,
|
||||||
threshold,
|
xLabel,
|
||||||
height = 200,
|
thresholdValue,
|
||||||
width = 400,
|
thresholdLabel,
|
||||||
className,
|
className,
|
||||||
}: AreaChartProps) {
|
}: AreaChartProps) {
|
||||||
const [tooltip, setTooltip] = useState<{
|
const { data, hasDateX } = useMemo(() => {
|
||||||
x: number
|
const map = new Map<string, Record<string, any>>()
|
||||||
y: number
|
let dateDetected = false
|
||||||
values: { label: string; value: number; color: string }[]
|
|
||||||
} | null>(null)
|
|
||||||
|
|
||||||
const dims = { ...DIMS, width, height }
|
for (const s of series) {
|
||||||
const allData = series.flatMap((s) => s.data)
|
for (const pt of s.data) {
|
||||||
|
const isDate = pt.x instanceof Date
|
||||||
if (allData.length === 0) {
|
if (isDate) dateDetected = true
|
||||||
return <div className={`${styles.empty} ${className ?? ''}`}>No data</div>
|
const key = isDate ? pt.x.getTime().toString() : String(pt.x)
|
||||||
|
if (!map.has(key)) {
|
||||||
|
map.set(key, { _x: isDate ? formatTime(pt.x) : pt.x })
|
||||||
|
}
|
||||||
|
map.get(key)![s.label] = pt.y
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { max, toY } = computeYScale(series, dims, threshold?.value)
|
return { data: Array.from(map.values()), hasDateX: dateDetected }
|
||||||
const { toX } = computeXScale(series, dims)
|
}, [series])
|
||||||
const plotH = height - dims.paddingTop - dims.paddingBottom
|
|
||||||
const plotW = width - dims.paddingLeft - dims.paddingRight
|
|
||||||
const bottomY = dims.paddingTop + plotH
|
|
||||||
|
|
||||||
// Y-axis ticks
|
const chart = (
|
||||||
const yTicks = Array.from({ length: Y_TICK_COUNT + 1 }, (_, i) =>
|
<ThemedChart
|
||||||
Math.round((max / Y_TICK_COUNT) * i),
|
data={data}
|
||||||
)
|
|
||||||
|
|
||||||
// X-axis ticks (first, middle, last)
|
|
||||||
const firstSeries = series[0]
|
|
||||||
const xSamples =
|
|
||||||
firstSeries && firstSeries.data.length > 0
|
|
||||||
? [
|
|
||||||
firstSeries.data[0].x,
|
|
||||||
firstSeries.data[Math.floor(firstSeries.data.length / 2)]?.x,
|
|
||||||
firstSeries.data[firstSeries.data.length - 1].x,
|
|
||||||
].filter(Boolean)
|
|
||||||
: []
|
|
||||||
|
|
||||||
function handleMouseMove(e: React.MouseEvent<SVGSVGElement>) {
|
|
||||||
const rect = e.currentTarget.getBoundingClientRect()
|
|
||||||
const mx = e.clientX - rect.left
|
|
||||||
const my = e.clientY - rect.top
|
|
||||||
|
|
||||||
// Find closest x value
|
|
||||||
const pctX = (mx - dims.paddingLeft) / plotW
|
|
||||||
const values = series.map((s, i) => {
|
|
||||||
const idx = Math.round(pctX * (s.data.length - 1))
|
|
||||||
const clamped = Math.max(0, Math.min(s.data.length - 1, idx))
|
|
||||||
const pt = s.data[clamped]
|
|
||||||
return {
|
|
||||||
label: s.label,
|
|
||||||
value: pt?.y ?? 0,
|
|
||||||
color: s.color ?? CHART_COLORS[i % CHART_COLORS.length],
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
setTooltip({ x: mx, y: my, values })
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={`${styles.wrapper} ${className ?? ''}`}>
|
|
||||||
{yLabel && <div className={styles.yLabel}>{yLabel}</div>}
|
|
||||||
<svg
|
|
||||||
width={width}
|
|
||||||
height={height}
|
height={height}
|
||||||
viewBox={`0 0 ${width} ${height}`}
|
xDataKey="_x"
|
||||||
className={styles.svg}
|
xType={hasDateX ? 'category' : 'category'}
|
||||||
onMouseMove={handleMouseMove}
|
xTickFormatter={hasDateX ? (v: any) => String(v) : undefined}
|
||||||
onMouseLeave={() => setTooltip(null)}
|
yLabel={yLabel}
|
||||||
aria-label="Area chart"
|
className={className}
|
||||||
role="img"
|
|
||||||
>
|
>
|
||||||
{/* Grid lines */}
|
|
||||||
{yTicks.map((val) => {
|
|
||||||
const y = toY(val)
|
|
||||||
return (
|
|
||||||
<g key={val}>
|
|
||||||
<line
|
|
||||||
x1={dims.paddingLeft}
|
|
||||||
y1={y}
|
|
||||||
x2={width - dims.paddingRight}
|
|
||||||
y2={y}
|
|
||||||
className={styles.gridLine}
|
|
||||||
/>
|
|
||||||
<text x={dims.paddingLeft - 6} y={y + 4} className={styles.axisLabel} textAnchor="end">
|
|
||||||
{formatAxisLabel(val)}
|
|
||||||
</text>
|
|
||||||
</g>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
|
|
||||||
{/* X-axis labels */}
|
|
||||||
{xSamples.map((xVal, i) => {
|
|
||||||
const xPos = toX(xVal)
|
|
||||||
const xv = xVal instanceof Date ? xVal : new Date(xVal as number)
|
|
||||||
const label =
|
|
||||||
xVal instanceof Date || (typeof xVal === 'number' && xVal > 1e10)
|
|
||||||
? xv.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
|
||||||
: formatAxisLabel(xVal as number)
|
|
||||||
const anchor = i === 0 ? 'start' : i === xSamples.length - 1 ? 'end' : 'middle'
|
|
||||||
return (
|
|
||||||
<text
|
|
||||||
key={i}
|
|
||||||
x={xPos}
|
|
||||||
y={height - dims.paddingBottom + 16}
|
|
||||||
className={styles.axisLabel}
|
|
||||||
textAnchor={anchor}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</text>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
|
|
||||||
{/* SLA threshold line */}
|
|
||||||
{threshold && (
|
|
||||||
<g>
|
|
||||||
<line
|
|
||||||
x1={dims.paddingLeft}
|
|
||||||
y1={toY(threshold.value)}
|
|
||||||
x2={width - dims.paddingRight}
|
|
||||||
y2={toY(threshold.value)}
|
|
||||||
className={styles.thresholdLine}
|
|
||||||
/>
|
|
||||||
<text
|
|
||||||
x={width - dims.paddingRight - 4}
|
|
||||||
y={toY(threshold.value) - 4}
|
|
||||||
className={styles.thresholdLabel}
|
|
||||||
textAnchor="end"
|
|
||||||
>
|
|
||||||
{threshold.label}
|
|
||||||
</text>
|
|
||||||
</g>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Area fills */}
|
|
||||||
{series.map((s, i) => {
|
{series.map((s, i) => {
|
||||||
const color = s.color ?? CHART_COLORS[i % CHART_COLORS.length]
|
const color = s.color ?? CHART_COLORS[i % CHART_COLORS.length]
|
||||||
const areaD = seriesPath(s, toX, toY, bottomY)
|
|
||||||
return (
|
return (
|
||||||
<path
|
<Area
|
||||||
key={`area-${i}`}
|
key={s.label}
|
||||||
d={areaD}
|
type="monotone"
|
||||||
fill={color}
|
dataKey={s.label}
|
||||||
className={styles.area}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
|
|
||||||
{/* Lines */}
|
|
||||||
{series.map((s, i) => {
|
|
||||||
const color = s.color ?? CHART_COLORS[i % CHART_COLORS.length]
|
|
||||||
const pts = seriesPoints(s, toX, toY)
|
|
||||||
return (
|
|
||||||
<polyline
|
|
||||||
key={`line-${i}`}
|
|
||||||
points={pts}
|
|
||||||
fill="none"
|
|
||||||
stroke={color}
|
stroke={color}
|
||||||
className={styles.line}
|
fill={color}
|
||||||
|
fillOpacity={0.15}
|
||||||
|
strokeWidth={1.5}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
{thresholdValue != null && (
|
||||||
{/* Crosshair */}
|
<ReferenceLine
|
||||||
{tooltip && (
|
y={thresholdValue}
|
||||||
<line
|
stroke="var(--text-muted)"
|
||||||
x1={tooltip.x}
|
strokeDasharray="4 4"
|
||||||
y1={dims.paddingTop}
|
label={thresholdLabel ? {
|
||||||
x2={tooltip.x}
|
value: thresholdLabel,
|
||||||
y2={bottomY}
|
position: 'insideTopRight',
|
||||||
className={styles.crosshair}
|
style: { fontSize: 10, fill: 'var(--text-muted)' },
|
||||||
|
} : undefined}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</svg>
|
</ThemedChart>
|
||||||
|
|
||||||
{/* Tooltip */}
|
|
||||||
{tooltip && (
|
|
||||||
<div
|
|
||||||
className={styles.tooltip}
|
|
||||||
style={{
|
|
||||||
left: tooltip.x + 12,
|
|
||||||
top: tooltip.y,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{tooltip.values.map((v) => (
|
|
||||||
<div key={v.label} className={styles.tooltipRow}>
|
|
||||||
<span className={styles.tooltipDot} style={{ background: v.color }} />
|
|
||||||
<span className={styles.tooltipLabel}>{v.label}:</span>
|
|
||||||
<span className={styles.tooltipValue}>{formatAxisLabel(v.value)}</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Legend */}
|
|
||||||
{series.length > 1 && (
|
|
||||||
<div className={styles.legend}>
|
|
||||||
{series.map((s, i) => (
|
|
||||||
<div key={s.label} className={styles.legendItem}>
|
|
||||||
<span
|
|
||||||
className={styles.legendDot}
|
|
||||||
style={{ background: s.color ?? CHART_COLORS[i % CHART_COLORS.length] }}
|
|
||||||
/>
|
|
||||||
<span className={styles.legendLabel}>{s.label}</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{xLabel && <div className={styles.xLabel}>{xLabel}</div>}
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (width) {
|
||||||
|
return <div style={{ width }}>{chart}</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
return chart
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,143 +0,0 @@
|
|||||||
.wrapper {
|
|
||||||
position: relative;
|
|
||||||
display: inline-flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.svg {
|
|
||||||
display: block;
|
|
||||||
overflow: visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
color: var(--text-muted);
|
|
||||||
font-size: 12px;
|
|
||||||
height: 120px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.gridLine {
|
|
||||||
stroke: var(--border-subtle);
|
|
||||||
stroke-width: 1;
|
|
||||||
stroke-dasharray: 3 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.axisLabel {
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-size: 9px;
|
|
||||||
fill: var(--text-faint);
|
|
||||||
}
|
|
||||||
|
|
||||||
.catLabel {
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-size: 9px;
|
|
||||||
fill: var(--text-faint);
|
|
||||||
}
|
|
||||||
|
|
||||||
.bar {
|
|
||||||
cursor: pointer;
|
|
||||||
transition: opacity 0.1s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bar:hover {
|
|
||||||
opacity: 0.8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltip {
|
|
||||||
position: absolute;
|
|
||||||
background: var(--bg-surface);
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
box-shadow: var(--shadow-md);
|
|
||||||
padding: 6px 10px;
|
|
||||||
font-size: 12px;
|
|
||||||
pointer-events: none;
|
|
||||||
z-index: 10;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipTitle {
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--text-primary);
|
|
||||||
margin-bottom: 4px;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipRow {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
margin-bottom: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipRow:last-child {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipDot {
|
|
||||||
width: 6px;
|
|
||||||
height: 6px;
|
|
||||||
border-radius: 50%;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipLabel {
|
|
||||||
color: var(--text-muted);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipValue {
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--text-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.legend {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 12px;
|
|
||||||
padding-left: 48px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.legendItem {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--text-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.legendDot {
|
|
||||||
width: 8px;
|
|
||||||
height: 8px;
|
|
||||||
border-radius: 50%;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.legendLabel {
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.yLabel {
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--text-muted);
|
|
||||||
writing-mode: vertical-lr;
|
|
||||||
transform: rotate(180deg);
|
|
||||||
text-align: center;
|
|
||||||
position: absolute;
|
|
||||||
left: 4px;
|
|
||||||
top: 0;
|
|
||||||
bottom: 40px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.xLabel {
|
|
||||||
text-align: center;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--text-muted);
|
|
||||||
padding-left: 48px;
|
|
||||||
}
|
|
||||||
@@ -1,241 +1,88 @@
|
|||||||
import { useState } from 'react'
|
import { useMemo } from 'react'
|
||||||
import styles from './BarChart.module.css'
|
import { Bar } from 'recharts'
|
||||||
import { formatAxisLabel, CHART_COLORS } from '../_chart-utils'
|
import { ThemedChart } from '../ThemedChart/ThemedChart'
|
||||||
|
import { CHART_COLORS } from '../../utils/rechartsTheme'
|
||||||
|
|
||||||
interface BarSeries {
|
export interface DataPoint {
|
||||||
|
x: any
|
||||||
|
y: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChartSeries {
|
||||||
label: string
|
label: string
|
||||||
data: { x: string; y: number }[]
|
data: DataPoint[]
|
||||||
color?: string
|
color?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BarChartProps {
|
interface BarChartProps {
|
||||||
series: BarSeries[]
|
series: ChartSeries[]
|
||||||
stacked?: boolean
|
|
||||||
height?: number
|
height?: number
|
||||||
width?: number
|
width?: number
|
||||||
xLabel?: string
|
|
||||||
yLabel?: string
|
yLabel?: string
|
||||||
|
xLabel?: string
|
||||||
|
stacked?: boolean
|
||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const PADDING = { top: 12, right: 16, bottom: 40, left: 48 }
|
function formatTime(d: Date): string {
|
||||||
const Y_TICK_COUNT = 4
|
const h = String(d.getHours()).padStart(2, '0')
|
||||||
const BAR_GAP = 0.2 // fraction of bar group width reserved for gaps
|
const m = String(d.getMinutes()).padStart(2, '0')
|
||||||
|
return `${h}:${m}`
|
||||||
|
}
|
||||||
|
|
||||||
export function BarChart({
|
export function BarChart({
|
||||||
series,
|
series,
|
||||||
stacked = false,
|
height,
|
||||||
height = 200,
|
width,
|
||||||
width = 400,
|
|
||||||
xLabel,
|
|
||||||
yLabel,
|
yLabel,
|
||||||
|
xLabel,
|
||||||
|
stacked,
|
||||||
className,
|
className,
|
||||||
}: BarChartProps) {
|
}: BarChartProps) {
|
||||||
const [tooltip, setTooltip] = useState<{
|
const { data, hasDateX } = useMemo(() => {
|
||||||
x: number
|
const map = new Map<string, Record<string, any>>()
|
||||||
y: number
|
let dateDetected = false
|
||||||
label: string
|
|
||||||
values: { series: string; value: number; color: string }[]
|
|
||||||
} | null>(null)
|
|
||||||
|
|
||||||
if (series.length === 0 || series[0].data.length === 0) {
|
for (const s of series) {
|
||||||
return <div className={`${styles.empty} ${className ?? ''}`}>No data</div>
|
for (const pt of s.data) {
|
||||||
|
const isDate = pt.x instanceof Date
|
||||||
|
if (isDate) dateDetected = true
|
||||||
|
const key = isDate ? pt.x.getTime().toString() : String(pt.x)
|
||||||
|
if (!map.has(key)) {
|
||||||
|
map.set(key, { _x: isDate ? formatTime(pt.x) : pt.x })
|
||||||
|
}
|
||||||
|
map.get(key)![s.label] = pt.y
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect all x categories (union across all series)
|
return { data: Array.from(map.values()), hasDateX: dateDetected }
|
||||||
const categories = Array.from(new Set(series.flatMap((s) => s.data.map((d) => d.x))))
|
}, [series])
|
||||||
const numCats = categories.length
|
|
||||||
|
|
||||||
const plotW = width - PADDING.left - PADDING.right
|
const chart = (
|
||||||
const plotH = height - PADDING.top - PADDING.bottom
|
<ThemedChart
|
||||||
|
data={data}
|
||||||
// Compute max Y
|
|
||||||
let maxY = 0
|
|
||||||
if (stacked) {
|
|
||||||
for (const cat of categories) {
|
|
||||||
const sum = series.reduce((acc, s) => {
|
|
||||||
const pt = s.data.find((d) => d.x === cat)
|
|
||||||
return acc + (pt?.y ?? 0)
|
|
||||||
}, 0)
|
|
||||||
maxY = Math.max(maxY, sum)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
maxY = Math.max(...series.flatMap((s) => s.data.map((d) => d.y)))
|
|
||||||
}
|
|
||||||
maxY = maxY || 1
|
|
||||||
|
|
||||||
const yTicks = Array.from({ length: Y_TICK_COUNT + 1 }, (_, i) =>
|
|
||||||
Math.round((maxY / Y_TICK_COUNT) * i),
|
|
||||||
)
|
|
||||||
const toY = (val: number) => PADDING.top + plotH - (val / maxY) * plotH
|
|
||||||
const bottomY = PADDING.top + plotH
|
|
||||||
|
|
||||||
const catWidth = plotW / numCats
|
|
||||||
const groupGap = catWidth * BAR_GAP
|
|
||||||
const groupW = catWidth - groupGap
|
|
||||||
|
|
||||||
function handleMouseEnter(
|
|
||||||
catLabel: string,
|
|
||||||
mx: number,
|
|
||||||
my: number,
|
|
||||||
values: { series: string; value: number; color: string }[],
|
|
||||||
) {
|
|
||||||
setTooltip({ x: mx, y: my, label: catLabel, values })
|
|
||||||
}
|
|
||||||
|
|
||||||
function showBarTooltip(e: React.MouseEvent<SVGRectElement>, cat: string) {
|
|
||||||
const rect = e.currentTarget.closest('svg')!.getBoundingClientRect()
|
|
||||||
handleMouseEnter(
|
|
||||||
cat,
|
|
||||||
e.clientX - rect.left,
|
|
||||||
e.clientY - rect.top,
|
|
||||||
series.map((ss, ssi) => ({
|
|
||||||
series: ss.label,
|
|
||||||
value: ss.data.find((d) => d.x === cat)?.y ?? 0,
|
|
||||||
color: ss.color ?? CHART_COLORS[ssi % CHART_COLORS.length],
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={`${styles.wrapper} ${className ?? ''}`}>
|
|
||||||
{yLabel && <div className={styles.yLabel}>{yLabel}</div>}
|
|
||||||
<svg
|
|
||||||
width={width}
|
|
||||||
height={height}
|
height={height}
|
||||||
viewBox={`0 0 ${width} ${height}`}
|
xDataKey="_x"
|
||||||
className={styles.svg}
|
xType="category"
|
||||||
onMouseLeave={() => setTooltip(null)}
|
xTickFormatter={hasDateX ? (v: any) => String(v) : undefined}
|
||||||
aria-label="Bar chart"
|
yLabel={yLabel}
|
||||||
role="img"
|
className={className}
|
||||||
>
|
>
|
||||||
{/* Grid lines */}
|
{series.map((s, i) => (
|
||||||
{yTicks.map((val) => {
|
<Bar
|
||||||
const y = toY(val)
|
key={s.label}
|
||||||
return (
|
dataKey={s.label}
|
||||||
<g key={val}>
|
fill={s.color ?? CHART_COLORS[i % CHART_COLORS.length]}
|
||||||
<line
|
radius={[2, 2, 0, 0]}
|
||||||
x1={PADDING.left}
|
{...(stacked ? { stackId: 'stack' } : {})}
|
||||||
y1={y}
|
|
||||||
x2={width - PADDING.right}
|
|
||||||
y2={y}
|
|
||||||
className={styles.gridLine}
|
|
||||||
/>
|
/>
|
||||||
<text x={PADDING.left - 6} y={y + 4} className={styles.axisLabel} textAnchor="end">
|
))}
|
||||||
{formatAxisLabel(val)}
|
</ThemedChart>
|
||||||
</text>
|
|
||||||
</g>
|
|
||||||
)
|
)
|
||||||
})}
|
|
||||||
|
|
||||||
{/* Bars */}
|
if (width) {
|
||||||
{categories.map((cat, ci) => {
|
return <div style={{ width }}>{chart}</div>
|
||||||
const groupX = PADDING.left + ci * catWidth + groupGap / 2
|
|
||||||
|
|
||||||
if (stacked) {
|
|
||||||
let stackY = bottomY
|
|
||||||
return (
|
|
||||||
<g key={cat}>
|
|
||||||
{series.map((s, si) => {
|
|
||||||
const pt = s.data.find((d) => d.x === cat)
|
|
||||||
const val = pt?.y ?? 0
|
|
||||||
const barH = (val / maxY) * plotH
|
|
||||||
const color = s.color ?? CHART_COLORS[si % CHART_COLORS.length]
|
|
||||||
const y = stackY - barH
|
|
||||||
stackY -= barH
|
|
||||||
return (
|
|
||||||
<rect
|
|
||||||
key={si}
|
|
||||||
x={groupX}
|
|
||||||
y={y}
|
|
||||||
width={groupW}
|
|
||||||
height={barH}
|
|
||||||
fill={color}
|
|
||||||
className={styles.bar}
|
|
||||||
onMouseEnter={(e) => showBarTooltip(e, cat)}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
<text
|
|
||||||
x={groupX + groupW / 2}
|
|
||||||
y={bottomY + 14}
|
|
||||||
className={styles.catLabel}
|
|
||||||
textAnchor="middle"
|
|
||||||
>
|
|
||||||
{cat}
|
|
||||||
</text>
|
|
||||||
</g>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grouped
|
return chart
|
||||||
const barW = groupW / series.length
|
|
||||||
return (
|
|
||||||
<g key={cat}>
|
|
||||||
{series.map((s, si) => {
|
|
||||||
const pt = s.data.find((d) => d.x === cat)
|
|
||||||
const val = pt?.y ?? 0
|
|
||||||
const barH = (val / maxY) * plotH
|
|
||||||
const color = s.color ?? CHART_COLORS[si % CHART_COLORS.length]
|
|
||||||
return (
|
|
||||||
<rect
|
|
||||||
key={si}
|
|
||||||
x={groupX + si * barW}
|
|
||||||
y={toY(val)}
|
|
||||||
width={barW - 1}
|
|
||||||
height={barH}
|
|
||||||
fill={color}
|
|
||||||
className={styles.bar}
|
|
||||||
onMouseEnter={(e) => showBarTooltip(e, cat)}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
<text
|
|
||||||
x={groupX + groupW / 2}
|
|
||||||
y={bottomY + 14}
|
|
||||||
className={styles.catLabel}
|
|
||||||
textAnchor="middle"
|
|
||||||
>
|
|
||||||
{cat}
|
|
||||||
</text>
|
|
||||||
</g>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</svg>
|
|
||||||
|
|
||||||
{/* Tooltip */}
|
|
||||||
{tooltip && (
|
|
||||||
<div
|
|
||||||
className={styles.tooltip}
|
|
||||||
style={{ left: tooltip.x + 12, top: tooltip.y }}
|
|
||||||
>
|
|
||||||
<div className={styles.tooltipTitle}>{tooltip.label}</div>
|
|
||||||
{tooltip.values.map((v) => (
|
|
||||||
<div key={v.series} className={styles.tooltipRow}>
|
|
||||||
<span className={styles.tooltipDot} style={{ background: v.color }} />
|
|
||||||
<span className={styles.tooltipLabel}>{v.series}:</span>
|
|
||||||
<span className={styles.tooltipValue}>{formatAxisLabel(v.value)}</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Legend */}
|
|
||||||
{series.length > 1 && (
|
|
||||||
<div className={styles.legend}>
|
|
||||||
{series.map((s, i) => (
|
|
||||||
<div key={s.label} className={styles.legendItem}>
|
|
||||||
<span
|
|
||||||
className={styles.legendDot}
|
|
||||||
style={{ background: s.color ?? CHART_COLORS[i % CHART_COLORS.length] }}
|
|
||||||
/>
|
|
||||||
<span className={styles.legendLabel}>{s.label}</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{xLabel && <div className={styles.xLabel}>{xLabel}</div>}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ interface BreadcrumbItem {
|
|||||||
interface BreadcrumbProps {
|
interface BreadcrumbProps {
|
||||||
items: BreadcrumbItem[]
|
items: BreadcrumbItem[]
|
||||||
className?: string
|
className?: string
|
||||||
|
onNavigate?: (href: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Breadcrumb({ items, className }: BreadcrumbProps) {
|
export function Breadcrumb({ items, className, onNavigate }: BreadcrumbProps) {
|
||||||
return (
|
return (
|
||||||
<nav aria-label="Breadcrumb" className={className}>
|
<nav aria-label="Breadcrumb" className={className}>
|
||||||
<ol className={styles.list}>
|
<ol className={styles.list}>
|
||||||
@@ -22,7 +23,11 @@ export function Breadcrumb({ items, className }: BreadcrumbProps) {
|
|||||||
{isLast ? (
|
{isLast ? (
|
||||||
<span className={styles.active}>{item.label}</span>
|
<span className={styles.active}>{item.label}</span>
|
||||||
) : item.href ? (
|
) : item.href ? (
|
||||||
<a href={item.href} className={styles.link}>
|
<a
|
||||||
|
href={item.href}
|
||||||
|
className={styles.link}
|
||||||
|
onClick={onNavigate ? (e) => { e.preventDefault(); onNavigate(item.href!) } : undefined}
|
||||||
|
>
|
||||||
{item.label}
|
{item.label}
|
||||||
</a>
|
</a>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -1,146 +0,0 @@
|
|||||||
.wrapper {
|
|
||||||
position: relative;
|
|
||||||
display: inline-flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.svg {
|
|
||||||
display: block;
|
|
||||||
overflow: visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
.empty {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
color: var(--text-muted);
|
|
||||||
font-size: 12px;
|
|
||||||
height: 120px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.gridLine {
|
|
||||||
stroke: var(--border-subtle);
|
|
||||||
stroke-width: 1;
|
|
||||||
stroke-dasharray: 3 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.axisLabel {
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-size: 9px;
|
|
||||||
fill: var(--text-faint);
|
|
||||||
}
|
|
||||||
|
|
||||||
.thresholdLine {
|
|
||||||
stroke: var(--error);
|
|
||||||
stroke-width: 1.5;
|
|
||||||
stroke-dasharray: 5 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
.thresholdLabel {
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-size: 9px;
|
|
||||||
fill: var(--error);
|
|
||||||
}
|
|
||||||
|
|
||||||
.line {
|
|
||||||
stroke-width: 2;
|
|
||||||
stroke-linecap: round;
|
|
||||||
stroke-linejoin: round;
|
|
||||||
}
|
|
||||||
|
|
||||||
.crosshair {
|
|
||||||
stroke: var(--text-faint);
|
|
||||||
stroke-width: 1;
|
|
||||||
stroke-dasharray: 3 3;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltip {
|
|
||||||
position: absolute;
|
|
||||||
background: var(--bg-surface);
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
box-shadow: var(--shadow-md);
|
|
||||||
padding: 6px 10px;
|
|
||||||
font-size: 12px;
|
|
||||||
pointer-events: none;
|
|
||||||
z-index: 10;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipRow {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
margin-bottom: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipRow:last-child {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipDot {
|
|
||||||
width: 6px;
|
|
||||||
height: 6px;
|
|
||||||
border-radius: 50%;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipLabel {
|
|
||||||
color: var(--text-muted);
|
|
||||||
}
|
|
||||||
|
|
||||||
.tooltipValue {
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--text-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.legend {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 12px;
|
|
||||||
padding-left: 48px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.legendItem {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--text-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.legendDot {
|
|
||||||
width: 8px;
|
|
||||||
height: 8px;
|
|
||||||
border-radius: 50%;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.legendLabel {
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.yLabel {
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--text-muted);
|
|
||||||
writing-mode: vertical-lr;
|
|
||||||
transform: rotate(180deg);
|
|
||||||
text-align: center;
|
|
||||||
position: absolute;
|
|
||||||
left: 4px;
|
|
||||||
top: 0;
|
|
||||||
bottom: 28px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.xLabel {
|
|
||||||
text-align: center;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--text-muted);
|
|
||||||
padding-left: 48px;
|
|
||||||
}
|
|
||||||
@@ -1,233 +1,101 @@
|
|||||||
import { useState } from 'react'
|
import { useMemo } from 'react'
|
||||||
import styles from './LineChart.module.css'
|
import { Line, ReferenceLine } from 'recharts'
|
||||||
import {
|
import { ThemedChart } from '../ThemedChart/ThemedChart'
|
||||||
computeYScale,
|
import { CHART_COLORS } from '../../utils/rechartsTheme'
|
||||||
computeXScale,
|
|
||||||
seriesPoints,
|
|
||||||
formatAxisLabel,
|
|
||||||
CHART_COLORS,
|
|
||||||
type ChartSeries,
|
|
||||||
} from '../_chart-utils'
|
|
||||||
|
|
||||||
interface Threshold {
|
export interface DataPoint {
|
||||||
value: number
|
x: any
|
||||||
|
y: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChartSeries {
|
||||||
label: string
|
label: string
|
||||||
|
data: DataPoint[]
|
||||||
|
color?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LineChartProps {
|
interface LineChartProps {
|
||||||
series: ChartSeries[]
|
series: ChartSeries[]
|
||||||
xLabel?: string
|
|
||||||
yLabel?: string
|
|
||||||
threshold?: Threshold
|
|
||||||
height?: number
|
height?: number
|
||||||
width?: number
|
width?: number
|
||||||
|
yLabel?: string
|
||||||
|
xLabel?: string
|
||||||
|
threshold?: { value: number; label: string }
|
||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const Y_TICK_COUNT = 4
|
function formatTime(d: Date): string {
|
||||||
const DIMS = {
|
const h = String(d.getHours()).padStart(2, '0')
|
||||||
paddingTop: 12,
|
const m = String(d.getMinutes()).padStart(2, '0')
|
||||||
paddingRight: 16,
|
return `${h}:${m}`
|
||||||
paddingBottom: 28,
|
|
||||||
paddingLeft: 48,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function LineChart({
|
export function LineChart({
|
||||||
series,
|
series,
|
||||||
xLabel,
|
height,
|
||||||
|
width,
|
||||||
yLabel,
|
yLabel,
|
||||||
|
xLabel,
|
||||||
threshold,
|
threshold,
|
||||||
height = 200,
|
|
||||||
width = 400,
|
|
||||||
className,
|
className,
|
||||||
}: LineChartProps) {
|
}: LineChartProps) {
|
||||||
const [tooltip, setTooltip] = useState<{
|
const { data, hasDateX } = useMemo(() => {
|
||||||
x: number
|
const map = new Map<string, Record<string, any>>()
|
||||||
y: number
|
let dateDetected = false
|
||||||
values: { label: string; value: number; color: string }[]
|
|
||||||
} | null>(null)
|
|
||||||
|
|
||||||
const dims = { ...DIMS, width, height }
|
for (const s of series) {
|
||||||
const allData = series.flatMap((s) => s.data)
|
for (const pt of s.data) {
|
||||||
|
const isDate = pt.x instanceof Date
|
||||||
if (allData.length === 0) {
|
if (isDate) dateDetected = true
|
||||||
return <div className={`${styles.empty} ${className ?? ''}`}>No data</div>
|
const key = isDate ? pt.x.getTime().toString() : String(pt.x)
|
||||||
|
if (!map.has(key)) {
|
||||||
|
map.set(key, { _x: isDate ? formatTime(pt.x) : pt.x })
|
||||||
|
}
|
||||||
|
map.get(key)![s.label] = pt.y
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { max, toY } = computeYScale(series, dims, threshold?.value)
|
return { data: Array.from(map.values()), hasDateX: dateDetected }
|
||||||
const { toX } = computeXScale(series, dims)
|
}, [series])
|
||||||
const plotH = height - dims.paddingTop - dims.paddingBottom
|
|
||||||
const plotW = width - dims.paddingLeft - dims.paddingRight
|
|
||||||
const bottomY = dims.paddingTop + plotH
|
|
||||||
|
|
||||||
const yTicks = Array.from({ length: Y_TICK_COUNT + 1 }, (_, i) =>
|
const chart = (
|
||||||
Math.round((max / Y_TICK_COUNT) * i),
|
<ThemedChart
|
||||||
)
|
data={data}
|
||||||
|
|
||||||
const firstSeries = series[0]
|
|
||||||
const xSamples =
|
|
||||||
firstSeries && firstSeries.data.length > 0
|
|
||||||
? [
|
|
||||||
firstSeries.data[0].x,
|
|
||||||
firstSeries.data[Math.floor(firstSeries.data.length / 2)]?.x,
|
|
||||||
firstSeries.data[firstSeries.data.length - 1].x,
|
|
||||||
].filter(Boolean)
|
|
||||||
: []
|
|
||||||
|
|
||||||
function handleMouseMove(e: React.MouseEvent<SVGSVGElement>) {
|
|
||||||
const rect = e.currentTarget.getBoundingClientRect()
|
|
||||||
const mx = e.clientX - rect.left
|
|
||||||
const my = e.clientY - rect.top
|
|
||||||
const pctX = (mx - dims.paddingLeft) / plotW
|
|
||||||
|
|
||||||
const values = series.map((s, i) => {
|
|
||||||
const idx = Math.round(pctX * (s.data.length - 1))
|
|
||||||
const clamped = Math.max(0, Math.min(s.data.length - 1, idx))
|
|
||||||
const pt = s.data[clamped]
|
|
||||||
return {
|
|
||||||
label: s.label,
|
|
||||||
value: pt?.y ?? 0,
|
|
||||||
color: s.color ?? CHART_COLORS[i % CHART_COLORS.length],
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
setTooltip({ x: mx, y: my, values })
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={`${styles.wrapper} ${className ?? ''}`}>
|
|
||||||
{yLabel && <div className={styles.yLabel}>{yLabel}</div>}
|
|
||||||
<svg
|
|
||||||
width={width}
|
|
||||||
height={height}
|
height={height}
|
||||||
viewBox={`0 0 ${width} ${height}`}
|
xDataKey="_x"
|
||||||
className={styles.svg}
|
xType={hasDateX ? 'category' : 'category'}
|
||||||
onMouseMove={handleMouseMove}
|
xTickFormatter={hasDateX ? (v: any) => String(v) : undefined}
|
||||||
onMouseLeave={() => setTooltip(null)}
|
yLabel={yLabel}
|
||||||
aria-label="Line chart"
|
className={className}
|
||||||
role="img"
|
|
||||||
>
|
>
|
||||||
{/* Grid lines */}
|
|
||||||
{yTicks.map((val) => {
|
|
||||||
const y = toY(val)
|
|
||||||
return (
|
|
||||||
<g key={val}>
|
|
||||||
<line
|
|
||||||
x1={dims.paddingLeft}
|
|
||||||
y1={y}
|
|
||||||
x2={width - dims.paddingRight}
|
|
||||||
y2={y}
|
|
||||||
className={styles.gridLine}
|
|
||||||
/>
|
|
||||||
<text x={dims.paddingLeft - 6} y={y + 4} className={styles.axisLabel} textAnchor="end">
|
|
||||||
{formatAxisLabel(val)}
|
|
||||||
</text>
|
|
||||||
</g>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
|
|
||||||
{/* X-axis labels */}
|
|
||||||
{xSamples.map((xVal, i) => {
|
|
||||||
const xPos = toX(xVal)
|
|
||||||
const xv = xVal instanceof Date ? xVal : new Date(xVal as number)
|
|
||||||
const label =
|
|
||||||
xVal instanceof Date || (typeof xVal === 'number' && xVal > 1e10)
|
|
||||||
? xv.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
|
||||||
: formatAxisLabel(xVal as number)
|
|
||||||
const anchor = i === 0 ? 'start' : i === xSamples.length - 1 ? 'end' : 'middle'
|
|
||||||
return (
|
|
||||||
<text
|
|
||||||
key={i}
|
|
||||||
x={xPos}
|
|
||||||
y={height - dims.paddingBottom + 16}
|
|
||||||
className={styles.axisLabel}
|
|
||||||
textAnchor={anchor}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</text>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
|
|
||||||
{/* Threshold line */}
|
|
||||||
{threshold && (
|
|
||||||
<g>
|
|
||||||
<line
|
|
||||||
x1={dims.paddingLeft}
|
|
||||||
y1={toY(threshold.value)}
|
|
||||||
x2={width - dims.paddingRight}
|
|
||||||
y2={toY(threshold.value)}
|
|
||||||
className={styles.thresholdLine}
|
|
||||||
/>
|
|
||||||
<text
|
|
||||||
x={width - dims.paddingRight - 4}
|
|
||||||
y={toY(threshold.value) - 4}
|
|
||||||
className={styles.thresholdLabel}
|
|
||||||
textAnchor="end"
|
|
||||||
>
|
|
||||||
{threshold.label}
|
|
||||||
</text>
|
|
||||||
</g>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Lines only (no area fill) */}
|
|
||||||
{series.map((s, i) => {
|
|
||||||
const color = s.color ?? CHART_COLORS[i % CHART_COLORS.length]
|
|
||||||
const pts = seriesPoints(s, toX, toY)
|
|
||||||
return (
|
|
||||||
<polyline
|
|
||||||
key={`line-${i}`}
|
|
||||||
points={pts}
|
|
||||||
fill="none"
|
|
||||||
stroke={color}
|
|
||||||
className={styles.line}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
|
|
||||||
{/* Crosshair */}
|
|
||||||
{tooltip && (
|
|
||||||
<line
|
|
||||||
x1={tooltip.x}
|
|
||||||
y1={dims.paddingTop}
|
|
||||||
x2={tooltip.x}
|
|
||||||
y2={bottomY}
|
|
||||||
className={styles.crosshair}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</svg>
|
|
||||||
|
|
||||||
{/* Tooltip */}
|
|
||||||
{tooltip && (
|
|
||||||
<div
|
|
||||||
className={styles.tooltip}
|
|
||||||
style={{ left: tooltip.x + 12, top: tooltip.y }}
|
|
||||||
>
|
|
||||||
{tooltip.values.map((v) => (
|
|
||||||
<div key={v.label} className={styles.tooltipRow}>
|
|
||||||
<span className={styles.tooltipDot} style={{ background: v.color }} />
|
|
||||||
<span className={styles.tooltipLabel}>{v.label}:</span>
|
|
||||||
<span className={styles.tooltipValue}>{formatAxisLabel(v.value)}</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Legend */}
|
|
||||||
{series.length > 1 && (
|
|
||||||
<div className={styles.legend}>
|
|
||||||
{series.map((s, i) => (
|
{series.map((s, i) => (
|
||||||
<div key={s.label} className={styles.legendItem}>
|
<Line
|
||||||
<span
|
key={s.label}
|
||||||
className={styles.legendDot}
|
type="monotone"
|
||||||
style={{ background: s.color ?? CHART_COLORS[i % CHART_COLORS.length] }}
|
dataKey={s.label}
|
||||||
|
stroke={s.color ?? CHART_COLORS[i % CHART_COLORS.length]}
|
||||||
|
dot={false}
|
||||||
|
strokeWidth={1.5}
|
||||||
/>
|
/>
|
||||||
<span className={styles.legendLabel}>{s.label}</span>
|
|
||||||
</div>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
{threshold && (
|
||||||
|
<ReferenceLine
|
||||||
|
y={threshold.value}
|
||||||
|
stroke="var(--text-muted)"
|
||||||
|
strokeDasharray="4 4"
|
||||||
|
label={{
|
||||||
|
value: threshold.label,
|
||||||
|
position: 'insideTopRight',
|
||||||
|
style: { fontSize: 10, fill: 'var(--text-muted)' },
|
||||||
|
}}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
|
</ThemedChart>
|
||||||
{xLabel && <div className={styles.xLabel}>{xLabel}</div>}
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (width) {
|
||||||
|
return <div style={{ width }}>{chart}</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
return chart
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,38 @@
|
|||||||
background: color-mix(in srgb, var(--text-faint) 8%, transparent);
|
background: color-mix(in srgb, var(--text-faint) 8%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sourceBadge {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 9px;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
padding: 1px 6px;
|
||||||
|
border-radius: 3px;
|
||||||
|
line-height: 1.5;
|
||||||
|
white-space: nowrap;
|
||||||
|
min-width: 48px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sourceContainer {
|
||||||
|
color: var(--text-muted);
|
||||||
|
background: color-mix(in srgb, var(--text-muted) 10%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sourceApp {
|
||||||
|
color: var(--running);
|
||||||
|
background: color-mix(in srgb, var(--running) 10%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sourceAgent {
|
||||||
|
color: var(--warning);
|
||||||
|
background: color-mix(in srgb, var(--warning) 10%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sourceDefault {
|
||||||
|
color: var(--text-muted);
|
||||||
|
background: color-mix(in srgb, var(--text-muted) 8%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
.message {
|
.message {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-family: var(--font-mono);
|
font-family: var(--font-mono);
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import { render, screen } from '@testing-library/react'
|
|||||||
import { LogViewer, type LogEntry } from './LogViewer'
|
import { LogViewer, type LogEntry } from './LogViewer'
|
||||||
|
|
||||||
const entries: LogEntry[] = [
|
const entries: LogEntry[] = [
|
||||||
{ timestamp: '2024-01-15T10:30:00Z', level: 'info', message: 'Server started' },
|
{ timestamp: '2024-01-15T10:30:00Z', level: 'info', message: 'Server started', source: 'app' },
|
||||||
{ timestamp: '2024-01-15T10:30:05Z', level: 'warn', message: 'High memory usage' },
|
{ timestamp: '2024-01-15T10:30:05Z', level: 'warn', message: 'High memory usage', source: 'container' },
|
||||||
{ timestamp: '2024-01-15T10:30:10Z', level: 'error', message: 'Connection failed' },
|
{ timestamp: '2024-01-15T10:30:10Z', level: 'error', message: 'Connection failed', source: 'agent' },
|
||||||
{ timestamp: '2024-01-15T10:30:15Z', level: 'debug', message: 'Query executed in 3ms' },
|
{ timestamp: '2024-01-15T10:30:15Z', level: 'debug', message: 'Query executed in 3ms' },
|
||||||
{ timestamp: '2024-01-15T10:30:20Z', level: 'trace', message: 'Entering handleRequest()' },
|
{ timestamp: '2024-01-15T10:30:20Z', level: 'trace', message: 'Entering handleRequest()' },
|
||||||
]
|
]
|
||||||
@@ -52,6 +52,23 @@ describe('LogViewer', () => {
|
|||||||
expect(el.classList.contains('custom-class')).toBe(true)
|
expect(el.classList.contains('custom-class')).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('renders source badges when source is provided', () => {
|
||||||
|
render(<LogViewer entries={entries} />)
|
||||||
|
expect(screen.getByText('app')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('container')).toBeInTheDocument()
|
||||||
|
expect(screen.getByText('agent')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('omits source badge when source is not provided', () => {
|
||||||
|
const noSourceEntries: LogEntry[] = [
|
||||||
|
{ timestamp: '2024-01-15T10:30:00Z', level: 'info', message: 'No source here' },
|
||||||
|
]
|
||||||
|
render(<LogViewer entries={noSourceEntries} />)
|
||||||
|
expect(screen.getByText('No source here')).toBeInTheDocument()
|
||||||
|
expect(screen.queryByText('app')).not.toBeInTheDocument()
|
||||||
|
expect(screen.queryByText('container')).not.toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
it('has role="log" for accessibility', () => {
|
it('has role="log" for accessibility', () => {
|
||||||
render(<LogViewer entries={entries} />)
|
render(<LogViewer entries={entries} />)
|
||||||
expect(screen.getByRole('log')).toBeInTheDocument()
|
expect(screen.getByRole('log')).toBeInTheDocument()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export interface LogEntry {
|
|||||||
timestamp: string
|
timestamp: string
|
||||||
level: 'info' | 'warn' | 'error' | 'debug' | 'trace'
|
level: 'info' | 'warn' | 'error' | 'debug' | 'trace'
|
||||||
message: string
|
message: string
|
||||||
|
source?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LogViewerProps {
|
export interface LogViewerProps {
|
||||||
@@ -21,6 +22,12 @@ const LEVEL_CLASS: Record<LogEntry['level'], string> = {
|
|||||||
trace: styles.levelTrace,
|
trace: styles.levelTrace,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SOURCE_CLASS: Record<string, string> = {
|
||||||
|
container: styles.sourceContainer,
|
||||||
|
app: styles.sourceApp,
|
||||||
|
agent: styles.sourceAgent,
|
||||||
|
}
|
||||||
|
|
||||||
function formatTime(iso: string): string {
|
function formatTime(iso: string): string {
|
||||||
try {
|
try {
|
||||||
return new Date(iso).toLocaleTimeString('en-GB', {
|
return new Date(iso).toLocaleTimeString('en-GB', {
|
||||||
@@ -67,6 +74,11 @@ export function LogViewer({ entries, maxHeight = 400, className }: LogViewerProp
|
|||||||
<span className={[styles.levelBadge, LEVEL_CLASS[entry.level]].join(' ')}>
|
<span className={[styles.levelBadge, LEVEL_CLASS[entry.level]].join(' ')}>
|
||||||
{entry.level.toUpperCase()}
|
{entry.level.toUpperCase()}
|
||||||
</span>
|
</span>
|
||||||
|
{entry.source && (
|
||||||
|
<span className={[styles.sourceBadge, SOURCE_CLASS[entry.source] ?? styles.sourceDefault].join(' ')}>
|
||||||
|
{entry.source}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
<span className={styles.message}>{entry.message}</span>
|
<span className={styles.message}>{entry.message}</span>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { ReactNode } from 'react'
|
|||||||
import { Play, Cog, Square, Diamond, AlertTriangle, EllipsisVertical } from 'lucide-react'
|
import { Play, Cog, Square, Diamond, AlertTriangle, EllipsisVertical } from 'lucide-react'
|
||||||
import styles from './RouteFlow.module.css'
|
import styles from './RouteFlow.module.css'
|
||||||
import { Dropdown } from '../Dropdown/Dropdown'
|
import { Dropdown } from '../Dropdown/Dropdown'
|
||||||
|
import { formatDuration } from '../../../utils/format-utils'
|
||||||
|
|
||||||
export interface NodeBadge {
|
export interface NodeBadge {
|
||||||
label: string
|
label: string
|
||||||
@@ -42,12 +43,6 @@ interface RouteFlowProps {
|
|||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDuration(ms: number): string {
|
|
||||||
if (ms >= 60_000) return `${(ms / 1000).toFixed(0)}s`
|
|
||||||
if (ms >= 1000) return `${(ms / 1000).toFixed(2)}s`
|
|
||||||
return `${ms}ms`
|
|
||||||
}
|
|
||||||
|
|
||||||
function durationClass(ms: number, status: string): string {
|
function durationClass(ms: number, status: string): string {
|
||||||
if (status === 'fail') return styles.durBreach
|
if (status === 'fail') return styles.durBreach
|
||||||
if (ms < 50) return styles.durFast
|
if (ms < 50) return styles.durFast
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
.tooltip {
|
||||||
|
background: var(--bg-surface);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
box-shadow: var(--shadow-md);
|
||||||
|
padding: 6px 10px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
margin-bottom: 4px;
|
||||||
|
padding-bottom: 3px;
|
||||||
|
border-bottom: 1px solid var(--border-subtle);
|
||||||
|
}
|
||||||
|
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 5px;
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dot {
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 50%;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
color: var(--text-muted);
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
41
src/design-system/composites/ThemedChart/ChartTooltip.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import type { TooltipProps } from 'recharts'
|
||||||
|
import styles from './ChartTooltip.module.css'
|
||||||
|
|
||||||
|
function formatValue(val: number): string {
|
||||||
|
if (val >= 1_000_000) return `${(val / 1_000_000).toFixed(1)}M`
|
||||||
|
if (val >= 1000) return `${(val / 1000).toFixed(1)}k`
|
||||||
|
if (Number.isInteger(val)) return String(val)
|
||||||
|
return val.toFixed(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTimestamp(val: unknown): string | null {
|
||||||
|
if (val == null) return null
|
||||||
|
const str = String(val)
|
||||||
|
const ms = typeof val === 'number' && val > 1e12 ? val
|
||||||
|
: typeof val === 'number' && val > 1e9 ? val * 1000
|
||||||
|
: Date.parse(str)
|
||||||
|
if (isNaN(ms)) return str
|
||||||
|
return new Date(ms).toLocaleString([], {
|
||||||
|
month: 'short', day: 'numeric',
|
||||||
|
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ChartTooltip({ active, payload, label }: TooltipProps<number, string>) {
|
||||||
|
if (!active || !payload?.length) return null
|
||||||
|
|
||||||
|
const timeLabel = formatTimestamp(label)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.tooltip}>
|
||||||
|
{timeLabel && <div className={styles.time}>{timeLabel}</div>}
|
||||||
|
{payload.map((entry) => (
|
||||||
|
<div key={entry.dataKey as string} className={styles.row}>
|
||||||
|
<span className={styles.dot} style={{ background: entry.color }} />
|
||||||
|
<span className={styles.label}>{entry.name}:</span>
|
||||||
|
<span className={styles.value}>{formatValue(entry.value as number)}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { describe, it, expect } from 'vitest'
|
||||||
|
import { render } from '@testing-library/react'
|
||||||
|
import { ThemedChart } from './ThemedChart'
|
||||||
|
import { Line } from 'recharts'
|
||||||
|
|
||||||
|
// Recharts uses ResizeObserver internally
|
||||||
|
class ResizeObserverMock {
|
||||||
|
observe() {}
|
||||||
|
unobserve() {}
|
||||||
|
disconnect() {}
|
||||||
|
}
|
||||||
|
globalThis.ResizeObserver = ResizeObserverMock as any
|
||||||
|
|
||||||
|
describe('ThemedChart', () => {
|
||||||
|
it('renders nothing when data is empty', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<ThemedChart data={[]}>
|
||||||
|
<Line dataKey="value" />
|
||||||
|
</ThemedChart>,
|
||||||
|
)
|
||||||
|
expect(container.innerHTML).toBe('')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders a chart container when data is provided', () => {
|
||||||
|
const data = [
|
||||||
|
{ time: '10:00', value: 10 },
|
||||||
|
{ time: '10:01', value: 20 },
|
||||||
|
]
|
||||||
|
const { container } = render(
|
||||||
|
<ThemedChart data={data} height={160}>
|
||||||
|
<Line dataKey="value" />
|
||||||
|
</ThemedChart>,
|
||||||
|
)
|
||||||
|
expect(container.querySelector('.recharts-responsive-container')).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('applies custom className', () => {
|
||||||
|
const data = [{ time: '10:00', value: 5 }]
|
||||||
|
const { container } = render(
|
||||||
|
<ThemedChart data={data} className="my-chart">
|
||||||
|
<Line dataKey="value" />
|
||||||
|
</ThemedChart>,
|
||||||
|
)
|
||||||
|
expect(container.querySelector('.my-chart')).toBeTruthy()
|
||||||
|
})
|
||||||
|
})
|
||||||
74
src/design-system/composites/ThemedChart/ThemedChart.tsx
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import {
|
||||||
|
ResponsiveContainer,
|
||||||
|
ComposedChart,
|
||||||
|
CartesianGrid,
|
||||||
|
XAxis,
|
||||||
|
YAxis,
|
||||||
|
Tooltip,
|
||||||
|
} from 'recharts'
|
||||||
|
import { rechartsTheme } from '../../utils/rechartsTheme'
|
||||||
|
import { ChartTooltip } from './ChartTooltip'
|
||||||
|
|
||||||
|
interface ThemedChartProps {
|
||||||
|
data: Record<string, any>[]
|
||||||
|
height?: number
|
||||||
|
xDataKey?: string
|
||||||
|
xType?: 'number' | 'category'
|
||||||
|
xTickFormatter?: (value: any) => string
|
||||||
|
yTickFormatter?: (value: any) => string
|
||||||
|
yLabel?: string
|
||||||
|
children: React.ReactNode
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ThemedChart({
|
||||||
|
data,
|
||||||
|
height = 200,
|
||||||
|
xDataKey = 'time',
|
||||||
|
xType = 'category',
|
||||||
|
xTickFormatter,
|
||||||
|
yTickFormatter,
|
||||||
|
yLabel,
|
||||||
|
children,
|
||||||
|
className,
|
||||||
|
}: ThemedChartProps) {
|
||||||
|
if (!data.length) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show ~5-6 ticks max to avoid label overlap
|
||||||
|
const maxTicks = 6
|
||||||
|
const tickInterval = data.length > maxTicks
|
||||||
|
? Math.ceil(data.length / maxTicks) - 1
|
||||||
|
: 0
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={className} style={{ width: '100%', height }}>
|
||||||
|
<ResponsiveContainer width="100%" height="100%">
|
||||||
|
<ComposedChart data={data} margin={{ top: 4, right: 8, bottom: 0, left: 0 }}>
|
||||||
|
<CartesianGrid {...rechartsTheme.cartesianGrid} />
|
||||||
|
<XAxis
|
||||||
|
dataKey={xDataKey}
|
||||||
|
type={xType}
|
||||||
|
{...rechartsTheme.xAxis}
|
||||||
|
tickFormatter={xTickFormatter}
|
||||||
|
interval={tickInterval}
|
||||||
|
minTickGap={40}
|
||||||
|
/>
|
||||||
|
<YAxis
|
||||||
|
{...rechartsTheme.yAxis}
|
||||||
|
tickFormatter={yTickFormatter}
|
||||||
|
label={yLabel ? {
|
||||||
|
value: yLabel,
|
||||||
|
angle: -90,
|
||||||
|
position: 'insideLeft',
|
||||||
|
style: { fontSize: 11, fill: 'var(--text-muted)' },
|
||||||
|
} : undefined}
|
||||||
|
/>
|
||||||
|
<Tooltip content={<ChartTooltip />} cursor={rechartsTheme.tooltip.cursor} />
|
||||||
|
{children}
|
||||||
|
</ComposedChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -81,8 +81,9 @@ export function ToastProvider({ children }: { children: ReactNode }) {
|
|||||||
const toast = useCallback(
|
const toast = useCallback(
|
||||||
(options: ToastOptions): string => {
|
(options: ToastOptions): string => {
|
||||||
const id = `toast-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`
|
const id = `toast-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`
|
||||||
const duration = options.duration ?? DEFAULT_DURATION
|
|
||||||
const variant = options.variant ?? 'info'
|
const variant = options.variant ?? 'info'
|
||||||
|
// Error toasts persist until manually dismissed; others auto-close after DEFAULT_DURATION
|
||||||
|
const duration = options.duration ?? (variant === 'error' ? 0 : DEFAULT_DURATION)
|
||||||
|
|
||||||
const newToast: ToastItem = {
|
const newToast: ToastItem = {
|
||||||
id,
|
id,
|
||||||
@@ -99,11 +100,13 @@ export function ToastProvider({ children }: { children: ReactNode }) {
|
|||||||
return next.slice(-MAX_TOASTS)
|
return next.slice(-MAX_TOASTS)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Schedule auto-dismiss
|
// Schedule auto-dismiss (duration 0 = persist until manual dismiss)
|
||||||
|
if (duration > 0) {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
dismiss(id)
|
dismiss(id)
|
||||||
}, duration)
|
}, duration)
|
||||||
timersRef.current.set(id, timer)
|
timersRef.current.set(id, timer)
|
||||||
|
}
|
||||||
|
|
||||||
return id
|
return id
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
export interface DataPoint {
|
|
||||||
x: number | Date
|
|
||||||
y: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChartSeries {
|
|
||||||
label: string
|
|
||||||
data: DataPoint[]
|
|
||||||
color?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChartDimensions {
|
|
||||||
width: number
|
|
||||||
height: number
|
|
||||||
paddingTop: number
|
|
||||||
paddingRight: number
|
|
||||||
paddingBottom: number
|
|
||||||
paddingLeft: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export function computeYScale(
|
|
||||||
series: ChartSeries[],
|
|
||||||
dims: ChartDimensions,
|
|
||||||
threshold?: number,
|
|
||||||
) {
|
|
||||||
const allY = series.flatMap((s) => s.data.map((d) => d.y))
|
|
||||||
if (threshold != null) allY.push(threshold)
|
|
||||||
const min = 0
|
|
||||||
const max = Math.max(...allY, 1)
|
|
||||||
const range = max - min
|
|
||||||
|
|
||||||
const plotH = dims.height - dims.paddingTop - dims.paddingBottom
|
|
||||||
const toY = (val: number) => dims.paddingTop + plotH - ((val - min) / range) * plotH
|
|
||||||
|
|
||||||
return { min, max, range, toY }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function computeXScale(series: ChartSeries[], dims: ChartDimensions) {
|
|
||||||
const allX = series.flatMap((s) =>
|
|
||||||
s.data.map((d) => (d.x instanceof Date ? d.x.getTime() : d.x)),
|
|
||||||
)
|
|
||||||
const minX = Math.min(...allX)
|
|
||||||
const maxX = Math.max(...allX)
|
|
||||||
const rangeX = maxX - minX || 1
|
|
||||||
|
|
||||||
const plotW = dims.width - dims.paddingLeft - dims.paddingRight
|
|
||||||
const toX = (val: number | Date) => {
|
|
||||||
const v = val instanceof Date ? val.getTime() : val
|
|
||||||
return dims.paddingLeft + ((v - minX) / rangeX) * plotW
|
|
||||||
}
|
|
||||||
|
|
||||||
return { minX, maxX, rangeX, toX }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function seriesPoints(
|
|
||||||
series: ChartSeries,
|
|
||||||
toX: (v: number | Date) => number,
|
|
||||||
toY: (v: number) => number,
|
|
||||||
): string {
|
|
||||||
return series.data.map((d) => `${toX(d.x).toFixed(1)},${toY(d.y).toFixed(1)}`).join(' ')
|
|
||||||
}
|
|
||||||
|
|
||||||
export function seriesPath(
|
|
||||||
series: ChartSeries,
|
|
||||||
toX: (v: number | Date) => number,
|
|
||||||
toY: (v: number) => number,
|
|
||||||
bottomY: number,
|
|
||||||
): string {
|
|
||||||
if (series.data.length === 0) return ''
|
|
||||||
const pts = series.data.map((d) => `${toX(d.x).toFixed(1)},${toY(d.y).toFixed(1)}`)
|
|
||||||
const firstX = toX(series.data[0].x).toFixed(1)
|
|
||||||
const lastX = toX(series.data[series.data.length - 1].x).toFixed(1)
|
|
||||||
return `M${pts.join(' L')} L${lastX},${bottomY} L${firstX},${bottomY} Z`
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatAxisLabel(val: number): string {
|
|
||||||
if (val >= 1_000_000) return `${(val / 1_000_000).toFixed(1)}M`
|
|
||||||
if (val >= 1000) return `${(val / 1000).toFixed(1)}k`
|
|
||||||
if (Number.isInteger(val)) return String(val)
|
|
||||||
return val.toFixed(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatXLabel(val: number | Date, _totalPoints: number): string {
|
|
||||||
if (val instanceof Date || (typeof val === 'number' && val > 1e10)) {
|
|
||||||
const d = val instanceof Date ? val : new Date(val)
|
|
||||||
return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
|
||||||
}
|
|
||||||
return formatAxisLabel(val as number)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default color tokens for series (fallback when no color given)
|
|
||||||
export const CHART_COLORS = [
|
|
||||||
'var(--chart-1)',
|
|
||||||
'var(--chart-2)',
|
|
||||||
'var(--chart-3)',
|
|
||||||
'var(--chart-4)',
|
|
||||||
'var(--chart-5)',
|
|
||||||
'var(--chart-6)',
|
|
||||||
'var(--chart-7)',
|
|
||||||
'var(--chart-8)',
|
|
||||||
]
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
export { Accordion } from './Accordion/Accordion'
|
export { Accordion } from './Accordion/Accordion'
|
||||||
export { AlertDialog } from './AlertDialog/AlertDialog'
|
export { AlertDialog } from './AlertDialog/AlertDialog'
|
||||||
export { AreaChart } from './AreaChart/AreaChart'
|
|
||||||
export { AvatarGroup } from './AvatarGroup/AvatarGroup'
|
export { AvatarGroup } from './AvatarGroup/AvatarGroup'
|
||||||
export { BarChart } from './BarChart/BarChart'
|
|
||||||
export { Breadcrumb } from './Breadcrumb/Breadcrumb'
|
export { Breadcrumb } from './Breadcrumb/Breadcrumb'
|
||||||
export { CommandPalette } from './CommandPalette/CommandPalette'
|
export { CommandPalette } from './CommandPalette/CommandPalette'
|
||||||
export type { SearchResult, SearchCategory, ScopeFilter } from './CommandPalette/types'
|
export type { SearchResult, SearchCategory, ScopeFilter } from './CommandPalette/types'
|
||||||
@@ -20,7 +18,6 @@ export { KpiStrip } from './KpiStrip/KpiStrip'
|
|||||||
export type { KpiItem, KpiStripProps } from './KpiStrip/KpiStrip'
|
export type { KpiItem, KpiStripProps } from './KpiStrip/KpiStrip'
|
||||||
export type { FeedEvent } from './EventFeed/EventFeed'
|
export type { FeedEvent } from './EventFeed/EventFeed'
|
||||||
export { FilterBar } from './FilterBar/FilterBar'
|
export { FilterBar } from './FilterBar/FilterBar'
|
||||||
export { LineChart } from './LineChart/LineChart'
|
|
||||||
export { LogViewer } from './LogViewer/LogViewer'
|
export { LogViewer } from './LogViewer/LogViewer'
|
||||||
export type { LogEntry, LogViewerProps } from './LogViewer/LogViewer'
|
export type { LogEntry, LogViewerProps } from './LogViewer/LogViewer'
|
||||||
export { LoginDialog } from './LoginForm/LoginDialog'
|
export { LoginDialog } from './LoginForm/LoginDialog'
|
||||||
@@ -43,6 +40,15 @@ export { Tabs } from './Tabs/Tabs'
|
|||||||
export { ToastProvider, useToast } from './Toast/Toast'
|
export { ToastProvider, useToast } from './Toast/Toast'
|
||||||
export { TreeView } from './TreeView/TreeView'
|
export { TreeView } from './TreeView/TreeView'
|
||||||
|
|
||||||
// Chart utilities for consumers using Recharts or custom charts
|
// Charts — ThemedChart wrapper + Recharts re-exports
|
||||||
export { CHART_COLORS } from './_chart-utils'
|
export { ThemedChart } from './ThemedChart/ThemedChart'
|
||||||
export type { ChartSeries, DataPoint } from './_chart-utils'
|
export { LineChart } from './LineChart/LineChart'
|
||||||
|
export { AreaChart } from './AreaChart/AreaChart'
|
||||||
|
export { BarChart } from './BarChart/BarChart'
|
||||||
|
export type { ChartSeries, DataPoint } from './LineChart/LineChart'
|
||||||
|
export { CHART_COLORS, rechartsTheme } from '../utils/rechartsTheme'
|
||||||
|
export {
|
||||||
|
Line, Area, Bar,
|
||||||
|
ReferenceLine, ReferenceArea,
|
||||||
|
Legend, Brush,
|
||||||
|
} from 'recharts'
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ export { BreadcrumbProvider, useBreadcrumb } from './providers/BreadcrumbProvide
|
|||||||
export type { BreadcrumbItem } from './providers/BreadcrumbProvider'
|
export type { BreadcrumbItem } from './providers/BreadcrumbProvider'
|
||||||
export * from './utils/hashColor'
|
export * from './utils/hashColor'
|
||||||
export * from './utils/timePresets'
|
export * from './utils/timePresets'
|
||||||
export * from './utils/rechartsTheme'
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.logoImg {
|
.logoImg {
|
||||||
width: 28px;
|
width: 28px;
|
||||||
height: 24px;
|
height: 24px;
|
||||||
@@ -70,9 +71,10 @@
|
|||||||
|
|
||||||
.version {
|
.version {
|
||||||
font-family: var(--font-mono);
|
font-family: var(--font-mono);
|
||||||
font-size: 12px;
|
font-size: 10px;
|
||||||
color: var(--sidebar-muted);
|
color: var(--sidebar-muted);
|
||||||
margin-left: 4px;
|
margin-left: 8px;
|
||||||
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search */
|
/* Search */
|
||||||
@@ -382,11 +384,67 @@
|
|||||||
color: var(--amber);
|
color: var(--amber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── Section groups (top/bottom positioning) ───────────────────────────── */
|
||||||
|
|
||||||
|
.sectionGroup {
|
||||||
|
flex: 0 1 auto;
|
||||||
|
overflow-y: auto;
|
||||||
|
min-height: 0;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionGroup::-webkit-scrollbar {
|
||||||
|
width: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionGroup::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionGroup::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(255, 255, 255, 0.15);
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionGroup::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionSpacer {
|
||||||
|
flex: 1 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Section content (scrollable maxHeight) ────────────────────────────── */
|
||||||
|
|
||||||
|
.sectionContent {
|
||||||
|
overflow-y: auto;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionContent::-webkit-scrollbar {
|
||||||
|
width: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionContent::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionContent::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(255, 255, 255, 0.15);
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionContent::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
/* ── Bottom links ────────────────────────────────────────────────────────── */
|
/* ── Bottom links ────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
.bottom {
|
.bottom {
|
||||||
border-top: 1px solid rgba(255, 255, 255, 0.06);
|
border-top: 1px solid rgba(255, 255, 255, 0.06);
|
||||||
padding: 6px;
|
padding: 6px 0;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
margin-top: auto;
|
margin-top: auto;
|
||||||
}
|
}
|
||||||
@@ -395,7 +453,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
padding: 7px 12px;
|
padding: 7px 6px;
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
color: var(--sidebar-muted);
|
color: var(--sidebar-muted);
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@@ -417,7 +475,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.bottomIcon {
|
.bottomIcon {
|
||||||
font-size: 13px;
|
display: flex;
|
||||||
width: 18px;
|
align-items: center;
|
||||||
text-align: center;
|
justify-content: center;
|
||||||
|
width: 16px;
|
||||||
|
color: var(--sidebar-muted);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,8 +132,8 @@ describe('Sidebar compound component', () => {
|
|||||||
expect(onCollapseToggle).toHaveBeenCalledTimes(1)
|
expect(onCollapseToggle).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 7. renders expand toggle label when collapsed
|
// 7. hides collapse toggle when sidebar is collapsed
|
||||||
it('renders expand toggle when sidebar is collapsed', () => {
|
it('hides collapse toggle when sidebar is collapsed', () => {
|
||||||
render(
|
render(
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<Sidebar collapsed onCollapseToggle={vi.fn()}>
|
<Sidebar collapsed onCollapseToggle={vi.fn()}>
|
||||||
@@ -141,7 +141,8 @@ describe('Sidebar compound component', () => {
|
|||||||
</Sidebar>
|
</Sidebar>
|
||||||
</Wrapper>,
|
</Wrapper>,
|
||||||
)
|
)
|
||||||
expect(screen.getByRole('button', { name: /expand sidebar/i })).toBeInTheDocument()
|
expect(screen.queryByRole('button', { name: /collapse sidebar/i })).not.toBeInTheDocument()
|
||||||
|
expect(screen.queryByRole('button', { name: /expand sidebar/i })).not.toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
|
||||||
// 8. renders search input and calls onSearchChange
|
// 8. renders search input and calls onSearchChange
|
||||||
@@ -324,4 +325,156 @@ describe('Sidebar compound component', () => {
|
|||||||
const item = screen.getByText('Admin').closest('[role="button"]')!
|
const item = screen.getByText('Admin').closest('[role="button"]')!
|
||||||
expect(item.className).toMatch(/bottomItemActive/)
|
expect(item.className).toMatch(/bottomItemActive/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 17. renders sectionContent wrapper with maxHeight when open
|
||||||
|
it('renders section content wrapper with maxHeight style when open', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section
|
||||||
|
icon={<span>ic</span>}
|
||||||
|
label="Apps"
|
||||||
|
open
|
||||||
|
onToggle={vi.fn()}
|
||||||
|
maxHeight="200px"
|
||||||
|
>
|
||||||
|
<div>child</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const contentWrapper = container.querySelector('.sectionContent')
|
||||||
|
expect(contentWrapper).toBeInTheDocument()
|
||||||
|
expect(contentWrapper).toHaveStyle({ maxHeight: '200px' })
|
||||||
|
expect(screen.getByText('child')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 18. renders sectionContent wrapper without maxHeight when not provided
|
||||||
|
it('renders section content wrapper without inline maxHeight when maxHeight is not provided', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section
|
||||||
|
icon={<span>ic</span>}
|
||||||
|
label="Apps"
|
||||||
|
open
|
||||||
|
onToggle={vi.fn()}
|
||||||
|
>
|
||||||
|
<div>child</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const contentWrapper = container.querySelector('.sectionContent')
|
||||||
|
expect(contentWrapper).toBeInTheDocument()
|
||||||
|
expect(contentWrapper).not.toHaveStyle({ maxHeight: '200px' })
|
||||||
|
expect(screen.getByText('child')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 19. does not render sectionContent wrapper when section is closed
|
||||||
|
it('does not render section content wrapper when section is closed', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section
|
||||||
|
icon={<span>ic</span>}
|
||||||
|
label="Apps"
|
||||||
|
open={false}
|
||||||
|
onToggle={vi.fn()}
|
||||||
|
maxHeight="200px"
|
||||||
|
>
|
||||||
|
<div>child</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const contentWrapper = container.querySelector('.sectionContent')
|
||||||
|
expect(contentWrapper).not.toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 20. renders top sections in sectionGroup wrapper
|
||||||
|
it('renders sections in top group wrapper by default', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Apps" open onToggle={vi.fn()}>
|
||||||
|
<div>apps content</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const topGroup = container.querySelector('.sectionGroup')
|
||||||
|
expect(topGroup).toBeInTheDocument()
|
||||||
|
expect(topGroup!.textContent).toContain('Apps')
|
||||||
|
})
|
||||||
|
|
||||||
|
// 21. renders bottom sections in separate group with spacer
|
||||||
|
it('renders bottom sections in a separate group with spacer between', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Apps" open onToggle={vi.fn()}>
|
||||||
|
<div>apps content</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Routes" open onToggle={vi.fn()} position="bottom">
|
||||||
|
<div>routes content</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const groups = container.querySelectorAll('.sectionGroup')
|
||||||
|
expect(groups).toHaveLength(2)
|
||||||
|
expect(groups[0].textContent).toContain('Apps')
|
||||||
|
expect(groups[1].textContent).toContain('Routes')
|
||||||
|
|
||||||
|
const spacer = container.querySelector('.sectionSpacer')
|
||||||
|
expect(spacer).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 22. does not render spacer when no bottom sections
|
||||||
|
it('does not render spacer when all sections are top', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Apps" open onToggle={vi.fn()}>
|
||||||
|
<div>apps content</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Agents" open onToggle={vi.fn()}>
|
||||||
|
<div>agents content</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const spacer = container.querySelector('.sectionSpacer')
|
||||||
|
expect(spacer).not.toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
// 23. collapsed sidebar renders bottom sections in bottom group
|
||||||
|
it('renders bottom sections in bottom group when sidebar is collapsed', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Wrapper>
|
||||||
|
<Sidebar collapsed onCollapseToggle={vi.fn()}>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Apps" open={false} onToggle={vi.fn()}>
|
||||||
|
<div>apps</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
<Sidebar.Section icon={<span>ic</span>} label="Routes" open={false} onToggle={vi.fn()} position="bottom">
|
||||||
|
<div>routes</div>
|
||||||
|
</Sidebar.Section>
|
||||||
|
</Sidebar>
|
||||||
|
</Wrapper>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const groups = container.querySelectorAll('.sectionGroup')
|
||||||
|
expect(groups).toHaveLength(2)
|
||||||
|
|
||||||
|
// Bottom group should contain the Routes rail item
|
||||||
|
const bottomGroup = groups[1]
|
||||||
|
expect(bottomGroup.querySelector('[title="Routes"]')).toBeInTheDocument()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import {
|
|||||||
Search,
|
Search,
|
||||||
X,
|
X,
|
||||||
ChevronsLeft,
|
ChevronsLeft,
|
||||||
ChevronsRight,
|
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
import styles from './Sidebar.module.css'
|
import styles from './Sidebar.module.css'
|
||||||
import { SidebarContext, useSidebarContext } from './SidebarContext'
|
import { SidebarContext, useSidebarContext } from './SidebarContext'
|
||||||
@@ -26,6 +25,8 @@ interface SidebarSectionProps {
|
|||||||
active?: boolean
|
active?: boolean
|
||||||
children: ReactNode
|
children: ReactNode
|
||||||
className?: string
|
className?: string
|
||||||
|
position?: 'top' | 'bottom'
|
||||||
|
maxHeight?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SidebarFooterProps {
|
interface SidebarFooterProps {
|
||||||
@@ -83,6 +84,8 @@ function SidebarSection({
|
|||||||
active,
|
active,
|
||||||
children,
|
children,
|
||||||
className,
|
className,
|
||||||
|
position: _position,
|
||||||
|
maxHeight,
|
||||||
}: SidebarSectionProps) {
|
}: SidebarSectionProps) {
|
||||||
const { collapsed, onCollapseToggle } = useSidebarContext()
|
const { collapsed, onCollapseToggle } = useSidebarContext()
|
||||||
|
|
||||||
@@ -125,7 +128,14 @@ function SidebarSection({
|
|||||||
{icon && <span className={styles.sectionIcon}>{icon}</span>}
|
{icon && <span className={styles.sectionIcon}>{icon}</span>}
|
||||||
<span className={styles.treeSectionLabel}>{label}</span>
|
<span className={styles.treeSectionLabel}>{label}</span>
|
||||||
</div>
|
</div>
|
||||||
{open && children}
|
{open && (
|
||||||
|
<div
|
||||||
|
className={styles.sectionContent}
|
||||||
|
style={maxHeight ? { maxHeight } : undefined}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -183,20 +193,22 @@ function SidebarRoot({
|
|||||||
className ?? '',
|
className ?? '',
|
||||||
].filter(Boolean).join(' ')}
|
].filter(Boolean).join(' ')}
|
||||||
>
|
>
|
||||||
{/* Collapse toggle */}
|
{/* Collapse toggle (hidden when collapsed — sections expand on click) */}
|
||||||
{onCollapseToggle && (
|
{onCollapseToggle && !collapsed && (
|
||||||
<button
|
<button
|
||||||
className={styles.collapseToggle}
|
className={styles.collapseToggle}
|
||||||
onClick={onCollapseToggle}
|
onClick={onCollapseToggle}
|
||||||
aria-label={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
|
aria-label="Collapse sidebar"
|
||||||
>
|
>
|
||||||
{collapsed ? <ChevronsRight size={14} /> : <ChevronsLeft size={14} />}
|
<ChevronsLeft size={14} />
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Render Header first, then search, then remaining children */}
|
{/* Render Header first, then search, then partitioned sections, then footer */}
|
||||||
{(() => {
|
{(() => {
|
||||||
const childArray = Children.toArray(children)
|
const childArray = Children.toArray(children)
|
||||||
|
|
||||||
|
// Extract header
|
||||||
const headerIdx = childArray.findIndex(
|
const headerIdx = childArray.findIndex(
|
||||||
(child) => isValidElement(child) && child.type === SidebarHeader,
|
(child) => isValidElement(child) && child.type === SidebarHeader,
|
||||||
)
|
)
|
||||||
@@ -205,6 +217,31 @@ function SidebarRoot({
|
|||||||
? [...childArray.slice(0, headerIdx), ...childArray.slice(headerIdx + 1)]
|
? [...childArray.slice(0, headerIdx), ...childArray.slice(headerIdx + 1)]
|
||||||
: childArray
|
: childArray
|
||||||
|
|
||||||
|
// Extract footer
|
||||||
|
const footerIdx = rest.findIndex(
|
||||||
|
(child) => isValidElement(child) && child.type === SidebarFooter,
|
||||||
|
)
|
||||||
|
const footer = footerIdx >= 0 ? rest[footerIdx] : null
|
||||||
|
const sections = footerIdx >= 0
|
||||||
|
? [...rest.slice(0, footerIdx), ...rest.slice(footerIdx + 1)]
|
||||||
|
: rest
|
||||||
|
|
||||||
|
// Partition sections into top/bottom by position prop
|
||||||
|
const topSections: typeof sections = []
|
||||||
|
const bottomSections: typeof sections = []
|
||||||
|
for (const child of sections) {
|
||||||
|
if (
|
||||||
|
isValidElement<SidebarSectionProps>(child) &&
|
||||||
|
child.props.position === 'bottom'
|
||||||
|
) {
|
||||||
|
bottomSections.push(child)
|
||||||
|
} else {
|
||||||
|
topSections.push(child)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasBottomSections = bottomSections.length > 0
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{header}
|
{header}
|
||||||
@@ -234,7 +271,16 @@ function SidebarRoot({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{rest}
|
<div className={styles.sectionGroup}>
|
||||||
|
{topSections}
|
||||||
|
</div>
|
||||||
|
{hasBottomSections && <div className={styles.sectionSpacer} />}
|
||||||
|
{hasBottomSections && (
|
||||||
|
<div className={styles.sectionGroup}>
|
||||||
|
{bottomSections}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{footer}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
})()}
|
})()}
|
||||||
|
|||||||
22
src/design-system/layout/TopBar/AutoRefreshToggle.tsx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import styles from './TopBar.module.css'
|
||||||
|
|
||||||
|
interface AutoRefreshToggleProps {
|
||||||
|
active: boolean
|
||||||
|
onChange: (active: boolean) => void
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AutoRefreshToggle({ active, onChange, className }: AutoRefreshToggleProps) {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
className={`${styles.liveToggle} ${active ? styles.liveToggleActive : ''} ${className ?? ''}`}
|
||||||
|
onClick={() => onChange(!active)}
|
||||||
|
type="button"
|
||||||
|
aria-label={active ? 'Disable auto-refresh' : 'Enable auto-refresh'}
|
||||||
|
title={active ? 'Auto-refresh is on — click to pause' : 'Auto-refresh is paused — click to resume'}
|
||||||
|
>
|
||||||
|
<span className={styles.liveDot} />
|
||||||
|
{active ? 'AUTO' : 'MANUAL'}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
24
src/design-system/layout/TopBar/SearchTrigger.tsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { Search } from 'lucide-react'
|
||||||
|
import styles from './TopBar.module.css'
|
||||||
|
|
||||||
|
interface SearchTriggerProps {
|
||||||
|
onClick: () => void
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SearchTrigger({ onClick, className }: SearchTriggerProps) {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
className={`${styles.search} ${className ?? ''}`}
|
||||||
|
onClick={onClick}
|
||||||
|
type="button"
|
||||||
|
aria-label="Open search"
|
||||||
|
>
|
||||||
|
<span className={styles.searchIcon} aria-hidden="true">
|
||||||
|
<Search size={13} />
|
||||||
|
</span>
|
||||||
|
<span className={styles.searchPlaceholder}>Search... ⌘K</span>
|
||||||
|
<span className={styles.kbd}>Ctrl+K</span>
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -155,17 +155,6 @@
|
|||||||
.env {
|
.env {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 30px;
|
|
||||||
padding: 4px 10px;
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
background: var(--bg-raised);
|
|
||||||
color: var(--text-muted);
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-size: 12px;
|
|
||||||
font-weight: 600;
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 0.5px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.user {
|
.user {
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
import { type ReactNode } from 'react'
|
import { type ReactNode } from 'react'
|
||||||
import { Search, Moon, Sun, Power } from 'lucide-react'
|
import { Moon, Sun, Power } from 'lucide-react'
|
||||||
import styles from './TopBar.module.css'
|
import styles from './TopBar.module.css'
|
||||||
import { Breadcrumb } from '../../composites/Breadcrumb/Breadcrumb'
|
import { Breadcrumb } from '../../composites/Breadcrumb/Breadcrumb'
|
||||||
import { Dropdown } from '../../composites/Dropdown/Dropdown'
|
import { Dropdown } from '../../composites/Dropdown/Dropdown'
|
||||||
import { Avatar } from '../../primitives/Avatar/Avatar'
|
import { Avatar } from '../../primitives/Avatar/Avatar'
|
||||||
import { ButtonGroup } from '../../primitives/ButtonGroup/ButtonGroup'
|
|
||||||
import type { ButtonGroupItem } from '../../primitives/ButtonGroup/ButtonGroup'
|
|
||||||
import { TimeRangeDropdown } from '../../primitives/TimeRangeDropdown/TimeRangeDropdown'
|
|
||||||
import { useGlobalFilters } from '../../providers/GlobalFilterProvider'
|
|
||||||
import { useCommandPalette } from '../../providers/CommandPaletteProvider'
|
|
||||||
import { useTheme } from '../../providers/ThemeProvider'
|
import { useTheme } from '../../providers/ThemeProvider'
|
||||||
import { useBreadcrumbOverride } from '../../providers/BreadcrumbProvider'
|
import { useBreadcrumbOverride } from '../../providers/BreadcrumbProvider'
|
||||||
import type { BreadcrumbItem } from '../../providers/BreadcrumbProvider'
|
import type { BreadcrumbItem } from '../../providers/BreadcrumbProvider'
|
||||||
@@ -19,82 +14,34 @@ interface TopBarProps {
|
|||||||
user?: { name: string }
|
user?: { name: string }
|
||||||
userMenuItems?: import('../../composites/Dropdown/Dropdown').DropdownItem[]
|
userMenuItems?: import('../../composites/Dropdown/Dropdown').DropdownItem[]
|
||||||
onLogout?: () => void
|
onLogout?: () => void
|
||||||
|
onNavigate?: (href: string) => void
|
||||||
className?: string
|
className?: string
|
||||||
|
children?: ReactNode
|
||||||
}
|
}
|
||||||
|
|
||||||
const STATUS_ITEMS: ButtonGroupItem[] = [
|
|
||||||
{ value: 'completed', label: 'OK', color: 'var(--success)' },
|
|
||||||
{ value: 'warning', label: 'Warn', color: 'var(--warning)' },
|
|
||||||
{ value: 'failed', label: 'Error', color: 'var(--error)' },
|
|
||||||
{ value: 'running', label: 'Running', color: 'var(--running)' },
|
|
||||||
]
|
|
||||||
|
|
||||||
export function TopBar({
|
export function TopBar({
|
||||||
breadcrumb,
|
breadcrumb,
|
||||||
environment,
|
environment,
|
||||||
user,
|
user,
|
||||||
userMenuItems,
|
userMenuItems,
|
||||||
onLogout,
|
onLogout,
|
||||||
|
onNavigate,
|
||||||
className,
|
className,
|
||||||
|
children,
|
||||||
}: TopBarProps) {
|
}: TopBarProps) {
|
||||||
const globalFilters = useGlobalFilters()
|
|
||||||
const commandPalette = useCommandPalette()
|
|
||||||
const { theme, toggleTheme } = useTheme()
|
const { theme, toggleTheme } = useTheme()
|
||||||
const breadcrumbOverride = useBreadcrumbOverride()
|
const breadcrumbOverride = useBreadcrumbOverride()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className={`${styles.topbar} ${className ?? ''}`}>
|
<header className={`${styles.topbar} ${className ?? ''}`}>
|
||||||
{/* Left: Breadcrumb */}
|
{/* Left: Breadcrumb */}
|
||||||
<Breadcrumb items={breadcrumbOverride ?? breadcrumb} className={styles.breadcrumb} />
|
<Breadcrumb items={breadcrumbOverride ?? breadcrumb} className={styles.breadcrumb} onNavigate={onNavigate} />
|
||||||
|
|
||||||
{/* Search trigger */}
|
{/* Center: consumer-provided controls */}
|
||||||
<button
|
{children}
|
||||||
className={styles.search}
|
|
||||||
onClick={() => commandPalette.setOpen(true)}
|
|
||||||
type="button"
|
|
||||||
aria-label="Open search"
|
|
||||||
>
|
|
||||||
<span className={styles.searchIcon} aria-hidden="true">
|
|
||||||
<Search size={13} />
|
|
||||||
</span>
|
|
||||||
<span className={styles.searchPlaceholder}>Search... ⌘K</span>
|
|
||||||
<span className={styles.kbd}>Ctrl+K</span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* Status filter group */}
|
{/* Right: theme toggle, env badge, user */}
|
||||||
<ButtonGroup
|
|
||||||
items={STATUS_ITEMS}
|
|
||||||
value={globalFilters.statusFilters}
|
|
||||||
onChange={(selected) => {
|
|
||||||
// Sync with global filter by toggling the diff
|
|
||||||
const current = globalFilters.statusFilters
|
|
||||||
for (const v of selected) {
|
|
||||||
if (!current.has(v)) globalFilters.toggleStatus(v as 'completed' | 'warning' | 'failed' | 'running')
|
|
||||||
}
|
|
||||||
for (const v of current) {
|
|
||||||
if (!selected.has(v)) globalFilters.toggleStatus(v as 'completed' | 'warning' | 'failed' | 'running')
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Time range pills */}
|
|
||||||
<TimeRangeDropdown
|
|
||||||
value={globalFilters.timeRange}
|
|
||||||
onChange={globalFilters.setTimeRange}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Right: auto-refresh toggle, theme toggle, env badge, user */}
|
|
||||||
<div className={styles.right}>
|
<div className={styles.right}>
|
||||||
<button
|
|
||||||
className={`${styles.liveToggle} ${globalFilters.autoRefresh ? styles.liveToggleActive : ''}`}
|
|
||||||
onClick={() => globalFilters.setAutoRefresh(!globalFilters.autoRefresh)}
|
|
||||||
type="button"
|
|
||||||
aria-label={globalFilters.autoRefresh ? 'Disable auto-refresh' : 'Enable auto-refresh'}
|
|
||||||
title={globalFilters.autoRefresh ? 'Auto-refresh is on — click to pause' : 'Auto-refresh is paused — click to resume'}
|
|
||||||
>
|
|
||||||
<span className={styles.liveDot} />
|
|
||||||
{globalFilters.autoRefresh ? 'AUTO' : 'MANUAL'}
|
|
||||||
</button>
|
|
||||||
<button
|
<button
|
||||||
className={styles.themeToggle}
|
className={styles.themeToggle}
|
||||||
onClick={toggleTheme}
|
onClick={toggleTheme}
|
||||||
|
|||||||
@@ -4,3 +4,5 @@ export { SidebarTree } from './Sidebar/SidebarTree'
|
|||||||
export type { SidebarTreeNode } from './Sidebar/SidebarTree'
|
export type { SidebarTreeNode } from './Sidebar/SidebarTree'
|
||||||
export { useStarred } from './Sidebar/useStarred'
|
export { useStarred } from './Sidebar/useStarred'
|
||||||
export { TopBar } from './TopBar/TopBar'
|
export { TopBar } from './TopBar/TopBar'
|
||||||
|
export { SearchTrigger } from './TopBar/SearchTrigger'
|
||||||
|
export { AutoRefreshToggle } from './TopBar/AutoRefreshToggle'
|
||||||
|
|||||||
64
src/design-system/primitives/FileInput/FileInput.module.css
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
.wrap {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border: 1.5px dashed var(--border);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
background: var(--bg-inset);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.15s, background 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wrap:hover {
|
||||||
|
border-color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dragOver {
|
||||||
|
border-color: var(--amber);
|
||||||
|
background: var(--amber-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
color: var(--text-faint);
|
||||||
|
flex-shrink: 0;
|
||||||
|
line-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
font-family: var(--font-body);
|
||||||
|
font-size: 12px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.placeholder {
|
||||||
|
color: var(--text-faint);
|
||||||
|
}
|
||||||
|
|
||||||
|
.fileName {
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.clearBtn {
|
||||||
|
margin-left: auto;
|
||||||
|
flex-shrink: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
border: none;
|
||||||
|
background: none;
|
||||||
|
color: var(--text-muted);
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
padding: 0;
|
||||||
|
transition: color 0.1s, background 0.1s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.clearBtn:hover {
|
||||||
|
color: var(--text-primary);
|
||||||
|
background: var(--bg-hover);
|
||||||
|
}
|
||||||
99
src/design-system/primitives/FileInput/FileInput.tsx
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import styles from './FileInput.module.css'
|
||||||
|
import { forwardRef, useRef, useState, useImperativeHandle, type ReactNode } from 'react'
|
||||||
|
import { X } from 'lucide-react'
|
||||||
|
|
||||||
|
export interface FileInputProps {
|
||||||
|
/** File type filter, e.g. ".pem,.crt,.cer" */
|
||||||
|
accept?: string
|
||||||
|
/** Icon rendered before the label */
|
||||||
|
icon?: ReactNode
|
||||||
|
/** Placeholder text when no file is selected */
|
||||||
|
placeholder?: string
|
||||||
|
/** Additional CSS class */
|
||||||
|
className?: string
|
||||||
|
/** Called when a file is selected or cleared */
|
||||||
|
onChange?: (file: File | null) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FileInputHandle {
|
||||||
|
/** The currently selected File, or null */
|
||||||
|
file: File | null
|
||||||
|
/** Programmatically clear the selection */
|
||||||
|
clear: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FileInput = forwardRef<FileInputHandle, FileInputProps>(
|
||||||
|
({ accept, icon, placeholder = 'Drop file or click to browse', className, onChange }, ref) => {
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null)
|
||||||
|
const [fileName, setFileName] = useState<string | null>(null)
|
||||||
|
const [dragOver, setDragOver] = useState(false)
|
||||||
|
const fileRef = useRef<File | null>(null)
|
||||||
|
|
||||||
|
function select(file: File | null) {
|
||||||
|
fileRef.current = file
|
||||||
|
setFileName(file?.name ?? null)
|
||||||
|
onChange?.(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleInputChange() {
|
||||||
|
select(inputRef.current?.files?.[0] ?? null)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDrop(e: React.DragEvent) {
|
||||||
|
e.preventDefault()
|
||||||
|
setDragOver(false)
|
||||||
|
const file = e.dataTransfer.files[0]
|
||||||
|
if (file && inputRef.current) {
|
||||||
|
const dt = new DataTransfer()
|
||||||
|
dt.items.add(file)
|
||||||
|
inputRef.current.files = dt.files
|
||||||
|
select(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleClear(e: React.MouseEvent) {
|
||||||
|
e.stopPropagation()
|
||||||
|
if (inputRef.current) inputRef.current.value = ''
|
||||||
|
select(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
useImperativeHandle(ref, () => ({
|
||||||
|
get file() { return fileRef.current },
|
||||||
|
clear() {
|
||||||
|
if (inputRef.current) inputRef.current.value = ''
|
||||||
|
select(null)
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
const wrapClass = [styles.wrap, dragOver && styles.dragOver, className].filter(Boolean).join(' ')
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={wrapClass}
|
||||||
|
onClick={() => inputRef.current?.click()}
|
||||||
|
onDragOver={(e) => { e.preventDefault(); setDragOver(true) }}
|
||||||
|
onDragLeave={() => setDragOver(false)}
|
||||||
|
onDrop={handleDrop}
|
||||||
|
>
|
||||||
|
{icon && <span className={styles.icon}>{icon}</span>}
|
||||||
|
<span className={`${styles.label} ${fileName ? styles.fileName : styles.placeholder}`}>
|
||||||
|
{fileName ?? placeholder}
|
||||||
|
</span>
|
||||||
|
{fileName && (
|
||||||
|
<button type="button" className={styles.clearBtn} onClick={handleClear} aria-label="Clear file">
|
||||||
|
<X size={12} />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<input
|
||||||
|
ref={inputRef}
|
||||||
|
type="file"
|
||||||
|
accept={accept}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
style={{ display: 'none' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
FileInput.displayName = 'FileInput'
|
||||||
@@ -5,3 +5,8 @@
|
|||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
animation: spin 0.6s linear infinite;
|
animation: spin 0.6s linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
from { transform: rotate(0deg); }
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ export { Collapsible } from './Collapsible/Collapsible'
|
|||||||
export { DateRangePicker } from './DateRangePicker/DateRangePicker'
|
export { DateRangePicker } from './DateRangePicker/DateRangePicker'
|
||||||
export { DateTimePicker } from './DateTimePicker/DateTimePicker'
|
export { DateTimePicker } from './DateTimePicker/DateTimePicker'
|
||||||
export { EmptyState } from './EmptyState/EmptyState'
|
export { EmptyState } from './EmptyState/EmptyState'
|
||||||
|
export { FileInput } from './FileInput/FileInput'
|
||||||
|
export type { FileInputProps, FileInputHandle } from './FileInput/FileInput'
|
||||||
export { FilterPill } from './FilterPill/FilterPill'
|
export { FilterPill } from './FilterPill/FilterPill'
|
||||||
export { FormField } from './FormField/FormField'
|
export { FormField } from './FormField/FormField'
|
||||||
export { InfoCallout } from './InfoCallout/InfoCallout'
|
export { InfoCallout } from './InfoCallout/InfoCallout'
|
||||||
|
|||||||
@@ -1,22 +1,18 @@
|
|||||||
import { CHART_COLORS } from '../composites/_chart-utils'
|
export const CHART_COLORS = [
|
||||||
|
'var(--chart-1)',
|
||||||
|
'var(--chart-2)',
|
||||||
|
'var(--chart-3)',
|
||||||
|
'var(--chart-4)',
|
||||||
|
'var(--chart-5)',
|
||||||
|
'var(--chart-6)',
|
||||||
|
'var(--chart-7)',
|
||||||
|
'var(--chart-8)',
|
||||||
|
]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pre-configured Recharts prop objects that match the design system's
|
* Pre-configured Recharts prop objects that match the design system's
|
||||||
* chart styling. Spread these onto Recharts sub-components:
|
* chart styling. Used internally by ThemedChart and available for
|
||||||
*
|
* consumers composing Recharts directly.
|
||||||
* ```tsx
|
|
||||||
* import { rechartsTheme, CHART_COLORS } from '@cameleer/design-system'
|
|
||||||
* import { LineChart, Line, CartesianGrid, XAxis, YAxis, Tooltip, Legend } from 'recharts'
|
|
||||||
*
|
|
||||||
* <LineChart data={data}>
|
|
||||||
* <CartesianGrid {...rechartsTheme.cartesianGrid} />
|
|
||||||
* <XAxis dataKey="name" {...rechartsTheme.xAxis} />
|
|
||||||
* <YAxis {...rechartsTheme.yAxis} />
|
|
||||||
* <Tooltip {...rechartsTheme.tooltip} />
|
|
||||||
* <Legend {...rechartsTheme.legend} />
|
|
||||||
* <Line stroke={CHART_COLORS[0]} strokeWidth={2} dot={false} />
|
|
||||||
* </LineChart>
|
|
||||||
* ```
|
|
||||||
*/
|
*/
|
||||||
export const rechartsTheme = {
|
export const rechartsTheme = {
|
||||||
colors: CHART_COLORS,
|
colors: CHART_COLORS,
|
||||||
|
|||||||
@@ -381,6 +381,7 @@ export function LayoutShell() {
|
|||||||
open={!routesCollapsed}
|
open={!routesCollapsed}
|
||||||
onToggle={toggleRoutesCollapsed}
|
onToggle={toggleRoutesCollapsed}
|
||||||
active={location.pathname.startsWith('/routes')}
|
active={location.pathname.startsWith('/routes')}
|
||||||
|
position="bottom"
|
||||||
>
|
>
|
||||||
<SidebarTree
|
<SidebarTree
|
||||||
nodes={routeNodes}
|
nodes={routeNodes}
|
||||||
@@ -400,6 +401,7 @@ export function LayoutShell() {
|
|||||||
open={true}
|
open={true}
|
||||||
onToggle={() => {}}
|
onToggle={() => {}}
|
||||||
active={false}
|
active={false}
|
||||||
|
position="bottom"
|
||||||
>
|
>
|
||||||
<StarredGroup
|
<StarredGroup
|
||||||
label="Applications"
|
label="Applications"
|
||||||
|
|||||||
@@ -3,34 +3,7 @@ import { exchanges, type Exchange } from './exchanges'
|
|||||||
import { routes } from './routes'
|
import { routes } from './routes'
|
||||||
import { agents } from './agents'
|
import { agents } from './agents'
|
||||||
import { SIDEBAR_APPS, buildRouteToAppMap, type SidebarApp } from './sidebar'
|
import { SIDEBAR_APPS, buildRouteToAppMap, type SidebarApp } from './sidebar'
|
||||||
|
import { formatDuration, statusLabel, statusToVariant, formatTimestamp } from '../utils/format-utils'
|
||||||
function formatDuration(ms: number): string {
|
|
||||||
if (ms >= 60_000) return `${(ms / 1000).toFixed(0)}s`
|
|
||||||
if (ms >= 1000) return `${(ms / 1000).toFixed(2)}s`
|
|
||||||
return `${ms}ms`
|
|
||||||
}
|
|
||||||
|
|
||||||
function statusLabel(status: Exchange['status']): string {
|
|
||||||
switch (status) {
|
|
||||||
case 'completed': return 'OK'
|
|
||||||
case 'failed': return 'ERR'
|
|
||||||
case 'running': return 'RUN'
|
|
||||||
case 'warning': return 'WARN'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function statusToVariant(status: Exchange['status']): string {
|
|
||||||
switch (status) {
|
|
||||||
case 'completed': return 'success'
|
|
||||||
case 'failed': return 'error'
|
|
||||||
case 'running': return 'running'
|
|
||||||
case 'warning': return 'warning'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTimestamp(date: Date): string {
|
|
||||||
return date.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
|
||||||
}
|
|
||||||
|
|
||||||
function healthToColor(health: SidebarApp['health']): string {
|
function healthToColor(health: SidebarApp['health']): string {
|
||||||
switch (health) {
|
switch (health) {
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ import { Badge } from '../../design-system/primitives/Badge/Badge'
|
|||||||
// Global filters
|
// Global filters
|
||||||
import { useGlobalFilters } from '../../design-system/providers/GlobalFilterProvider'
|
import { useGlobalFilters } from '../../design-system/providers/GlobalFilterProvider'
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { formatDuration, statusToVariant, statusLabel, toRouteNodeType, durationClass } from '../../utils/format-utils'
|
||||||
|
|
||||||
// Mock data
|
// Mock data
|
||||||
import { exchanges, type Exchange } from '../../mocks/exchanges'
|
import { exchanges, type Exchange } from '../../mocks/exchanges'
|
||||||
import { kpiMetrics, type KpiMetric } from '../../mocks/metrics'
|
import { kpiMetrics, type KpiMetric } from '../../mocks/metrics'
|
||||||
@@ -66,12 +69,6 @@ const kpiItems: KpiItem[] = kpiMetrics.map((m) => ({
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
||||||
function formatDuration(ms: number): string {
|
|
||||||
if (ms >= 60_000) return `${(ms / 1000).toFixed(0)}s`
|
|
||||||
if (ms >= 1000) return `${(ms / 1000).toFixed(2)}s`
|
|
||||||
return `${ms}ms`
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTimestamp(date: Date): string {
|
function formatTimestamp(date: Date): string {
|
||||||
const y = date.getFullYear()
|
const y = date.getFullYear()
|
||||||
const mo = String(date.getMonth() + 1).padStart(2, '0')
|
const mo = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
@@ -82,24 +79,6 @@ function formatTimestamp(date: Date): string {
|
|||||||
return `${y}-${mo}-${d} ${h}:${mi}:${s}`
|
return `${y}-${mo}-${d} ${h}:${mi}:${s}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function statusToVariant(status: Exchange['status']): 'success' | 'error' | 'running' | 'warning' {
|
|
||||||
switch (status) {
|
|
||||||
case 'completed': return 'success'
|
|
||||||
case 'failed': return 'error'
|
|
||||||
case 'running': return 'running'
|
|
||||||
case 'warning': return 'warning'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function statusLabel(status: Exchange['status']): string {
|
|
||||||
switch (status) {
|
|
||||||
case 'completed': return 'OK'
|
|
||||||
case 'failed': return 'ERR'
|
|
||||||
case 'running': return 'RUN'
|
|
||||||
case 'warning': return 'WARN'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ─── Table columns (base, without navigate action) ──────────────────────────
|
// ─── Table columns (base, without navigate action) ──────────────────────────
|
||||||
const BASE_COLUMNS: Column<Exchange>[] = [
|
const BASE_COLUMNS: Column<Exchange>[] = [
|
||||||
{
|
{
|
||||||
@@ -150,7 +129,7 @@ const BASE_COLUMNS: Column<Exchange>[] = [
|
|||||||
header: 'Duration',
|
header: 'Duration',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<MonoText size="sm" className={durationClass(row.durationMs, row.status)}>
|
<MonoText size="sm" className={durationClass(row.durationMs, row.status, styles)}>
|
||||||
{formatDuration(row.durationMs)}
|
{formatDuration(row.durationMs)}
|
||||||
</MonoText>
|
</MonoText>
|
||||||
),
|
),
|
||||||
@@ -167,14 +146,6 @@ const BASE_COLUMNS: Column<Exchange>[] = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
function durationClass(ms: number, status: Exchange['status']): string {
|
|
||||||
if (status === 'failed') return styles.durBreach
|
|
||||||
if (ms < 100) return styles.durFast
|
|
||||||
if (ms < 200) return styles.durNormal
|
|
||||||
if (ms < 300) return styles.durSlow
|
|
||||||
return styles.durBreach
|
|
||||||
}
|
|
||||||
|
|
||||||
const SHORTCUTS = [
|
const SHORTCUTS = [
|
||||||
{ keys: 'Ctrl+K', label: 'Search' },
|
{ keys: 'Ctrl+K', label: 'Search' },
|
||||||
{ keys: '↑↓', label: 'Navigate rows' },
|
{ keys: '↑↓', label: 'Navigate rows' },
|
||||||
@@ -257,16 +228,6 @@ export function Dashboard() {
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map processor types to RouteNode types
|
|
||||||
function toRouteNodeType(procType: string): RouteNode['type'] {
|
|
||||||
switch (procType) {
|
|
||||||
case 'consumer': return 'from'
|
|
||||||
case 'transform': return 'process'
|
|
||||||
case 'enrich': return 'process'
|
|
||||||
default: return procType as RouteNode['type']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build RouteFlow nodes from exchange processors
|
// Build RouteFlow nodes from exchange processors
|
||||||
const routeNodes: RouteNode[] = selectedExchange
|
const routeNodes: RouteNode[] = selectedExchange
|
||||||
? selectedExchange.processors.map((p) => ({
|
? selectedExchange.processors.map((p) => ({
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ import { MonoText } from '../../design-system/primitives/MonoText/MonoText'
|
|||||||
import { CodeBlock } from '../../design-system/primitives/CodeBlock/CodeBlock'
|
import { CodeBlock } from '../../design-system/primitives/CodeBlock/CodeBlock'
|
||||||
import { InfoCallout } from '../../design-system/primitives/InfoCallout/InfoCallout'
|
import { InfoCallout } from '../../design-system/primitives/InfoCallout/InfoCallout'
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { formatDuration, statusToVariant, toRouteNodeType } from '../../utils/format-utils'
|
||||||
|
|
||||||
// Mock data
|
// Mock data
|
||||||
import { exchanges } from '../../mocks/exchanges'
|
import { exchanges } from '../../mocks/exchanges'
|
||||||
import { buildRouteToAppMap } from '../../mocks/sidebar'
|
import { buildRouteToAppMap } from '../../mocks/sidebar'
|
||||||
@@ -25,21 +28,6 @@ import { buildRouteToAppMap } from '../../mocks/sidebar'
|
|||||||
const ROUTE_TO_APP = buildRouteToAppMap()
|
const ROUTE_TO_APP = buildRouteToAppMap()
|
||||||
|
|
||||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||||
function formatDuration(ms: number): string {
|
|
||||||
if (ms >= 60_000) return `${(ms / 1000).toFixed(0)}s`
|
|
||||||
if (ms >= 1000) return `${(ms / 1000).toFixed(2)}s`
|
|
||||||
return `${ms}ms`
|
|
||||||
}
|
|
||||||
|
|
||||||
function statusToVariant(status: 'completed' | 'failed' | 'running' | 'warning'): 'success' | 'error' | 'running' | 'warning' {
|
|
||||||
switch (status) {
|
|
||||||
case 'completed': return 'success'
|
|
||||||
case 'failed': return 'error'
|
|
||||||
case 'running': return 'running'
|
|
||||||
case 'warning': return 'warning'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function statusToLabel(status: 'completed' | 'failed' | 'running' | 'warning'): string {
|
function statusToLabel(status: 'completed' | 'failed' | 'running' | 'warning'): string {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 'completed': return 'COMPLETED'
|
case 'completed': return 'COMPLETED'
|
||||||
@@ -145,16 +133,6 @@ function generateExchangeSnapshotOut(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map processor types to RouteNode types
|
|
||||||
function toRouteNodeType(procType: string): RouteNode['type'] {
|
|
||||||
switch (procType) {
|
|
||||||
case 'consumer': return 'from'
|
|
||||||
case 'transform': return 'process'
|
|
||||||
case 'enrich': return 'process'
|
|
||||||
default: return procType as RouteNode['type']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ─── ExchangeDetail component ─────────────────────────────────────────────────
|
// ─── ExchangeDetail component ─────────────────────────────────────────────────
|
||||||
export function ExchangeDetail() {
|
export function ExchangeDetail() {
|
||||||
const { id } = useParams<{ id: string }>()
|
const { id } = useParams<{ id: string }>()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import styles from './BrandAssetsSection.module.css'
|
import styles from './BrandAssetsSection.module.css'
|
||||||
import camelLogoSvg from '../../../assets/camel-logo.svg'
|
import camelLogoSvg from '../../../assets/camel-logo.svg'
|
||||||
import cameleer3Logo from '../../../assets/cameleer3-logo.png'
|
import cameleerLogo from '../../../assets/cameleer3-logo.png'
|
||||||
import cameleer3LogoSvg from '../../../assets/cameleer3-logo.svg'
|
import cameleerLogoSvg from '../../../assets/cameleer3-logo.svg'
|
||||||
|
|
||||||
const LOGO_SIZES = [16, 32, 48, 180, 192, 512] as const
|
const LOGO_SIZES = [16, 32, 48, 180, 192, 512] as const
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ export function BrandAssetsSection() {
|
|||||||
<h2 className={styles.sectionTitle}>Brand Assets</h2>
|
<h2 className={styles.sectionTitle}>Brand Assets</h2>
|
||||||
|
|
||||||
<div className={styles.componentCard}>
|
<div className={styles.componentCard}>
|
||||||
<h3 className={styles.componentTitle}>Cameleer3 Logo (PNG)</h3>
|
<h3 className={styles.componentTitle}>Cameleer Logo (PNG)</h3>
|
||||||
<p className={styles.componentDesc}>
|
<p className={styles.componentDesc}>
|
||||||
Full-resolution logo and pre-generated size variants for favicons, PWA icons, and social images.
|
Full-resolution logo and pre-generated size variants for favicons, PWA icons, and social images.
|
||||||
Shipped as static assets via <code>@cameleer/design-system/assets/*</code> export.
|
Shipped as static assets via <code>@cameleer/design-system/assets/*</code> export.
|
||||||
@@ -22,27 +22,27 @@ export function BrandAssetsSection() {
|
|||||||
<div key={size} className={styles.logoItem}>
|
<div key={size} className={styles.logoItem}>
|
||||||
<div className={styles.logoPreview}>
|
<div className={styles.logoPreview}>
|
||||||
<img
|
<img
|
||||||
src={cameleer3Logo}
|
src={cameleerLogo}
|
||||||
alt={`Logo ${size}×${size}`}
|
alt={`Logo ${size}×${size}`}
|
||||||
width={Math.min(size, 96)}
|
width={Math.min(size, 96)}
|
||||||
height={Math.min(size, 96)}
|
height={Math.min(size, 96)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span className={styles.logoLabel}>{size}×{size}</span>
|
<span className={styles.logoLabel}>{size}×{size}</span>
|
||||||
<code className={styles.logoExport}>assets/cameleer3-{size}.png</code>
|
<code className={styles.logoExport}>assets/cameleer-{size}.png</code>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
<div className={styles.logoItem}>
|
<div className={styles.logoItem}>
|
||||||
<div className={styles.logoPreview}>
|
<div className={styles.logoPreview}>
|
||||||
<img
|
<img
|
||||||
src={cameleer3Logo}
|
src={cameleerLogo}
|
||||||
alt="Full resolution logo"
|
alt="Full resolution logo"
|
||||||
width={96}
|
width={96}
|
||||||
height={96}
|
height={96}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span className={styles.logoLabel}>Original</span>
|
<span className={styles.logoLabel}>Original</span>
|
||||||
<code className={styles.logoExport}>assets/cameleer3-logo.png</code>
|
<code className={styles.logoExport}>assets/cameleer-logo.png</code>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -57,10 +57,10 @@ export function BrandAssetsSection() {
|
|||||||
<div className={styles.logoGrid}>
|
<div className={styles.logoGrid}>
|
||||||
<div className={styles.logoItem}>
|
<div className={styles.logoItem}>
|
||||||
<div className={styles.logoPreview}>
|
<div className={styles.logoPreview}>
|
||||||
<img src={cameleer3LogoSvg} alt="Cameleer3 SVG logo" width={96} height={96} />
|
<img src={cameleerLogoSvg} alt="Cameleer SVG logo" width={96} height={96} />
|
||||||
</div>
|
</div>
|
||||||
<span className={styles.logoLabel}>Cameleer3 SVG</span>
|
<span className={styles.logoLabel}>Cameleer SVG</span>
|
||||||
<code className={styles.logoExport}>assets/cameleer3-logo.svg</code>
|
<code className={styles.logoExport}>assets/cameleer-logo.svg</code>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.logoItem}>
|
<div className={styles.logoItem}>
|
||||||
<div className={styles.logoPreview}>
|
<div className={styles.logoPreview}>
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import type { SidebarTreeNode } from '../../../design-system/layout/Sidebar/Side
|
|||||||
import { StatusDot } from '../../../design-system/primitives/StatusDot/StatusDot'
|
import { StatusDot } from '../../../design-system/primitives/StatusDot/StatusDot'
|
||||||
import { Box, Settings, FileText, ChevronRight } from 'lucide-react'
|
import { Box, Settings, FileText, ChevronRight } from 'lucide-react'
|
||||||
import { TopBar } from '../../../design-system/layout/TopBar/TopBar'
|
import { TopBar } from '../../../design-system/layout/TopBar/TopBar'
|
||||||
|
import { SearchTrigger } from '../../../design-system/layout/TopBar/SearchTrigger'
|
||||||
|
import { AutoRefreshToggle } from '../../../design-system/layout/TopBar/AutoRefreshToggle'
|
||||||
|
|
||||||
// ── DemoCard helper ──────────────────────────────────────────────────────────
|
// ── DemoCard helper ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -122,7 +124,7 @@ export function LayoutSection() {
|
|||||||
<DemoCard
|
<DemoCard
|
||||||
id="topbar"
|
id="topbar"
|
||||||
title="TopBar"
|
title="TopBar"
|
||||||
description="Top navigation bar with breadcrumb, search trigger, status filters, time range, environment badge, and user avatar."
|
description="Composable top navigation bar. Consumers pass children for the center slot (search, filters, etc.). Shell provides breadcrumb, theme toggle, env badge, and user menu."
|
||||||
>
|
>
|
||||||
<div className={styles.topbarPreview}>
|
<div className={styles.topbarPreview}>
|
||||||
<TopBar
|
<TopBar
|
||||||
@@ -132,9 +134,11 @@ export function LayoutSection() {
|
|||||||
{ label: 'order-ingest' },
|
{ label: 'order-ingest' },
|
||||||
]}
|
]}
|
||||||
environment="production"
|
environment="production"
|
||||||
|
|
||||||
user={{ name: 'Hendrik' }}
|
user={{ name: 'Hendrik' }}
|
||||||
/>
|
>
|
||||||
|
<SearchTrigger onClick={() => {}} />
|
||||||
|
<AutoRefreshToggle active={true} onChange={() => {}} />
|
||||||
|
</TopBar>
|
||||||
</div>
|
</div>
|
||||||
</DemoCard>
|
</DemoCard>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -17,39 +17,14 @@ import { StatusDot } from '../../design-system/primitives/StatusDot/StatusDot'
|
|||||||
import { MonoText } from '../../design-system/primitives/MonoText/MonoText'
|
import { MonoText } from '../../design-system/primitives/MonoText/MonoText'
|
||||||
import { InfoCallout } from '../../design-system/primitives/InfoCallout/InfoCallout'
|
import { InfoCallout } from '../../design-system/primitives/InfoCallout/InfoCallout'
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { formatDuration, statusToVariant, statusLabel, formatTimestamp, durationClass } from '../../utils/format-utils'
|
||||||
|
|
||||||
// Mock data
|
// Mock data
|
||||||
import { routes } from '../../mocks/routes'
|
import { routes } from '../../mocks/routes'
|
||||||
import { exchanges, type Exchange } from '../../mocks/exchanges'
|
import { exchanges, type Exchange } from '../../mocks/exchanges'
|
||||||
|
|
||||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||||
function formatDuration(ms: number): string {
|
|
||||||
if (ms >= 60_000) return `${(ms / 1000).toFixed(0)}s`
|
|
||||||
if (ms >= 1000) return `${(ms / 1000).toFixed(2)}s`
|
|
||||||
return `${ms}ms`
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTimestamp(date: Date): string {
|
|
||||||
return date.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
|
||||||
}
|
|
||||||
|
|
||||||
function statusToVariant(status: Exchange['status']): 'success' | 'error' | 'running' | 'warning' {
|
|
||||||
switch (status) {
|
|
||||||
case 'completed': return 'success'
|
|
||||||
case 'failed': return 'error'
|
|
||||||
case 'running': return 'running'
|
|
||||||
case 'warning': return 'warning'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function statusLabel(status: Exchange['status']): string {
|
|
||||||
switch (status) {
|
|
||||||
case 'completed': return 'OK'
|
|
||||||
case 'failed': return 'ERR'
|
|
||||||
case 'running': return 'RUN'
|
|
||||||
case 'warning': return 'WARN'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function routeStatusVariant(status: 'healthy' | 'degraded' | 'down'): 'success' | 'warning' | 'error' {
|
function routeStatusVariant(status: 'healthy' | 'degraded' | 'down'): 'success' | 'warning' | 'error' {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 'healthy': return 'success'
|
case 'healthy': return 'success'
|
||||||
@@ -58,14 +33,6 @@ function routeStatusVariant(status: 'healthy' | 'degraded' | 'down'): 'success'
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function durationClass(ms: number, status: Exchange['status']): string {
|
|
||||||
if (status === 'failed') return styles.durBreach
|
|
||||||
if (ms < 100) return styles.durFast
|
|
||||||
if (ms < 200) return styles.durNormal
|
|
||||||
if (ms < 300) return styles.durSlow
|
|
||||||
return styles.durBreach
|
|
||||||
}
|
|
||||||
|
|
||||||
// ─── Columns for exchanges table ────────────────────────────────────────────
|
// ─── Columns for exchanges table ────────────────────────────────────────────
|
||||||
const EXCHANGE_COLUMNS: Column<Exchange>[] = [
|
const EXCHANGE_COLUMNS: Column<Exchange>[] = [
|
||||||
{
|
{
|
||||||
@@ -106,7 +73,7 @@ const EXCHANGE_COLUMNS: Column<Exchange>[] = [
|
|||||||
header: 'Duration',
|
header: 'Duration',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
render: (_, row) => (
|
render: (_, row) => (
|
||||||
<MonoText size="sm" className={durationClass(row.durationMs, row.status)}>
|
<MonoText size="sm" className={durationClass(row.durationMs, row.status, styles)}>
|
||||||
{formatDuration(row.durationMs)}
|
{formatDuration(row.durationMs)}
|
||||||
</MonoText>
|
</MonoText>
|
||||||
),
|
),
|
||||||
|
|||||||
55
src/utils/format-utils.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import type { RouteNode } from '../design-system/composites/RouteFlow/RouteFlow'
|
||||||
|
|
||||||
|
export function formatDuration(ms: number): string {
|
||||||
|
if (ms >= 60_000) return `${(ms / 1000).toFixed(0)}s`
|
||||||
|
if (ms >= 1000) return `${(ms / 1000).toFixed(2)}s`
|
||||||
|
return `${ms}ms`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function statusToVariant(status: string): 'success' | 'error' | 'running' | 'warning' {
|
||||||
|
switch (status) {
|
||||||
|
case 'completed': return 'success'
|
||||||
|
case 'failed': return 'error'
|
||||||
|
case 'running': return 'running'
|
||||||
|
case 'warning': return 'warning'
|
||||||
|
default: return 'warning'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function statusLabel(s: string): string {
|
||||||
|
switch (s) {
|
||||||
|
case 'completed': return 'OK'
|
||||||
|
case 'failed': return 'ERR'
|
||||||
|
case 'running': return 'RUN'
|
||||||
|
case 'warning': return 'WARN'
|
||||||
|
default: return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatTimestamp(date: Date): string {
|
||||||
|
return date.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toRouteNodeType(procType: string): RouteNode['type'] {
|
||||||
|
switch (procType) {
|
||||||
|
case 'consumer': return 'from'
|
||||||
|
case 'transform': return 'process'
|
||||||
|
case 'enrich': return 'process'
|
||||||
|
default: return procType as RouteNode['type']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DurationStyles {
|
||||||
|
durBreach: string
|
||||||
|
durFast: string
|
||||||
|
durNormal: string
|
||||||
|
durSlow: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function durationClass(ms: number, status: string, styles: DurationStyles): string {
|
||||||
|
if (status === 'failed') return styles.durBreach
|
||||||
|
if (ms < 100) return styles.durFast
|
||||||
|
if (ms < 200) return styles.durNormal
|
||||||
|
if (ms < 300) return styles.durSlow
|
||||||
|
return styles.durBreach
|
||||||
|
}
|
||||||