@schandlergarcia/sf-web-components 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/.a4drules/features/command-center-dashboard-rule.md +46 -0
  2. package/.a4drules/skills/command-center-builder/SKILL.md +637 -0
  3. package/.a4drules/skills/command-center-project/SKILL.md +103 -0
  4. package/.a4drules/skills/component-library/SKILL.md +1025 -0
  5. package/.a4drules/skills/outer-app/SKILL.md +64 -0
  6. package/README.md +7 -7
  7. package/package.json +1 -1
  8. package/.a4drules/skills/building-data-visualization/SKILL.md +0 -72
  9. package/.a4drules/skills/building-data-visualization/implementation/bar-line-chart.md +0 -316
  10. package/.a4drules/skills/building-data-visualization/implementation/dashboard-layout.md +0 -189
  11. package/.a4drules/skills/building-data-visualization/implementation/donut-chart.md +0 -181
  12. package/.a4drules/skills/building-data-visualization/implementation/stat-card.md +0 -150
  13. package/.a4drules/skills/building-react-components/SKILL.md +0 -96
  14. package/.a4drules/skills/building-react-components/implementation/component.md +0 -78
  15. package/.a4drules/skills/building-react-components/implementation/header-footer.md +0 -132
  16. package/.a4drules/skills/building-react-components/implementation/page.md +0 -93
  17. package/.a4drules/skills/configuring-csp-trusted-sites/SKILL.md +0 -90
  18. package/.a4drules/skills/configuring-csp-trusted-sites/implementation/metadata-format.md +0 -281
  19. package/.a4drules/skills/configuring-webapp-metadata/SKILL.md +0 -158
  20. package/.a4drules/skills/creating-webapp/SKILL.md +0 -140
  21. package/.a4drules/skills/deploying-to-salesforce/SKILL.md +0 -226
  22. package/.a4drules/skills/implementing-file-upload/SKILL.md +0 -396
  23. package/.a4drules/skills/installing-webapp-features/SKILL.md +0 -210
  24. package/.a4drules/skills/managing-agentforce-conversation-client/SKILL.md +0 -186
  25. package/.a4drules/skills/managing-agentforce-conversation-client/references/constraints.md +0 -134
  26. package/.a4drules/skills/managing-agentforce-conversation-client/references/examples.md +0 -132
  27. package/.a4drules/skills/managing-agentforce-conversation-client/references/style-tokens.md +0 -101
  28. package/.a4drules/skills/managing-agentforce-conversation-client/references/troubleshooting.md +0 -57
  29. package/.a4drules/skills/using-salesforce-data/SKILL.md +0 -363
  30. package/.a4drules/skills/using-salesforce-data/graphql-search.sh +0 -139
  31. package/.a4drules/webapp-data.md +0 -353
  32. package/.a4drules/webapp-ui.md +0 -16
@@ -0,0 +1,637 @@
1
+ ---
2
+ name: command-center-builder
3
+ description: >-
4
+ Strict rules for building command center pages, dashboards, components, and
5
+ layouts. Use when creating or editing dashboard pages, choosing components,
6
+ designing layouts, styling with dark mode, or working with charts, tables,
7
+ forms, filters, chat, or navigation in this project.
8
+ ---
9
+
10
+ # Command Center Builder Rules
11
+
12
+ These rules apply when building dashboards rendered by `CommandCenter.tsx`. For full component API details, read the **component-library** skill.
13
+
14
+ ## STOP — READ BEFORE WRITING ANY CODE
15
+
16
+ **Every time you build a dashboard, you MUST follow these non-negotiable rules. Violations are the #1 cause of rejected dashboards.**
17
+
18
+ 1. **Actually write files to disk.** Use the file-writing tools to create `.jsx` files in `src/components/pages/` and update `CommandCenter.tsx` to import your dashboard. If you only describe what you would build without creating the files, the dashboard will not render. Verify the files exist after writing them.
19
+
20
+ 2. **Use ONLY library components** from `@/components/library` for all cards, charts, tables, lists, and feeds. The library has 30+ components — there is no reason to hand-roll HTML. See the component table below.
21
+
22
+ 3. **No navigation inside the dashboard.** No `<nav>`, no header bar, no tab bar acting as page-level navigation. The app shell handles navigation. Your dashboard starts with content.
23
+
24
+ 4. **Max 4 MetricCards per row.** Never 5. Split into two rows if needed.
25
+
26
+ 5. **All charts use `ChartCard` + `D3Chart` or `GeoMap`.** No Recharts, no Chart.js, no custom SVG, no canvas, no hand-drawn paths. The only charting tools allowed are `D3Chart` (with `D3ChartTemplates` or a custom `renderChart` function) and `GeoMap`.
27
+
28
+ 6. **Never `npm install` Salesforce packages.** The `@salesforce/*` packages are platform-provided via broken symlinks. They are stubbed in `src/stubs/` and aliased in `vite.config.ts`. Do not try to install them — they don't exist on npm. If you see a TypeScript error about `@salesforce/vite-plugin-webapp-experimental`, ignore it — the build still succeeds via `vite build` (the `tsc` error is in `vite.config.ts` which is handled separately by `tsconfig.node.json`).
29
+
30
+ If your output violates any of these 6 rules, it will be rejected and you will need to redo the work.
31
+
32
+ ## CRITICAL: Use Library Components — Never Hand-Roll HTML Cards
33
+
34
+ **This is the #1 mistake.** The component library (`@/components/library`) provides pre-built, themed, dark-mode-ready cards for every common dashboard need. You MUST use them instead of writing raw `<div>` cards with custom classes.
35
+
36
+ ### Before writing ANY card-like UI, check this table:
37
+
38
+ | Need | MUST use | NEVER do |
39
+ |------|----------|----------|
40
+ | KPI / stat | `MetricCard` | `<div className="bg-white border ..."><h3>Total Spend</h3><span>$4,903</span></div>` |
41
+ | List of items | `ListCard` | `<div className="bg-white ..."><div className="space-y-3">` with custom item rows |
42
+ | Activity feed | `ActivityCard` or `FeedPanel` | `<div>` with hand-rolled interaction rows |
43
+ | Data table | `TableCard` | `<table>` or custom grid of rows |
44
+ | Stats panel | `WidgetCard` or `SectionCard` | `<div className="bg-white ... p-6">` with label/value pairs |
45
+ | Custom interactive content (expand/collapse, inline details) | `WidgetCard` (sections accept arbitrary JSX) or `ListCard` (with `onItemClick` + `itemActions`) | Hand-rolled `<div>` card with custom expand/collapse logic |
46
+ | Status items | `StatusCard` | `<div>` with custom status badges |
47
+ | Text summary | `NarrativeSummary` / `SectionCard` | `<div>` with headings and paragraphs |
48
+ | Alert / callout | `CalloutCard` | Custom banner div |
49
+
50
+ **Every visible section of a dashboard should be a library component.** If you find yourself writing `<div className="bg-white border rounded-[10px] shadow-sm p-6">` with content inside, STOP — you are hand-rolling a card. Find the library component that fits.
51
+
52
+ ### Correct example:
53
+
54
+ ```jsx
55
+ import { MetricCard, ListCard, ActivityCard, WidgetCard } from "@/components/library";
56
+
57
+ // KPIs — use MetricCard
58
+ <MetricCard title="Active Travelers" value={6} subtitle="Currently traveling" />
59
+
60
+ // List — use ListCard with items array
61
+ <ListCard title="Trip Activity" items={trips.map(t => ({
62
+ id: t.id, title: t.hotel, description: `${t.city} · ${t.dates}`,
63
+ status: t.status, avatar: t.travelerInitials
64
+ }))} />
65
+
66
+ // Activity feed — use ActivityCard
67
+ <ActivityCard title="Eva — Recent Interactions" items={interactions.map(i => ({
68
+ id: i.id, title: i.traveler, description: i.query,
69
+ status: i.status, timestamp: i.time
70
+ }))} />
71
+
72
+ // Stats panel — use WidgetCard
73
+ <WidgetCard title="Company Activity">
74
+ {/* structured content */}
75
+ </WidgetCard>
76
+ ```
77
+
78
+ ### Wrong example (hand-rolled HTML):
79
+
80
+ ```jsx
81
+ // ❌ NEVER DO THIS — this is a hand-rolled card
82
+ <div className="bg-white border border-engine-border rounded-[10px] shadow-sm">
83
+ <div className="p-6 border-b border-engine-border">
84
+ <h2 className="text-lg font-semibold">Trip Activity</h2>
85
+ </div>
86
+ <div className="p-6 space-y-4">
87
+ {trips.map(trip => (
88
+ <div key={trip.id} className="flex gap-4 p-4 rounded-lg border ...">
89
+ ...
90
+ </div>
91
+ ))}
92
+ </div>
93
+ </div>
94
+ ```
95
+
96
+ ## Images (MANDATORY)
97
+
98
+ The only image allowed in dashboards is the **company logo**: `src/assets/images/engine_logo.png`. Import it as a module and use it where a logo is needed (nav header, branding, etc.).
99
+
100
+ ```jsx
101
+ import engineLogo from "@/assets/images/engine_logo.png";
102
+
103
+ <img src={engineLogo} alt="Engine" className="h-8 w-auto" />
104
+ ```
105
+
106
+ - **Do not use external image URLs** (Unsplash, placeholder services, etc.) unless the user explicitly requests images.
107
+ - **Do not use other asset images** (codey-*.png, etc.) unless the user asks for them.
108
+ - **Preserve aspect ratio** — always use `w-auto` with a fixed height, or `h-auto` with a fixed width. Never set both `w-*` and `h-*` to fixed values on the logo or any image, as this distorts the aspect ratio.
109
+
110
+ ```jsx
111
+ // ✅ Correct — aspect ratio preserved
112
+ <img src={engineLogo} alt="Engine" className="h-8 w-auto" />
113
+ <img src={engineLogo} alt="Engine" className="w-24 h-auto" />
114
+
115
+ // ❌ Wrong — aspect ratio distorted
116
+ <img src={engineLogo} alt="Engine" className="w-8 h-8" />
117
+ <div className="w-8 h-8 bg-black rounded" /> // placeholder box instead of logo
118
+ ```
119
+
120
+ ## No Dashboard-Level Navigation (MANDATORY)
121
+
122
+ Dashboard pages must NOT include their own `<nav>`, header bar, or top navigation of any kind. Navigation is handled by `appLayout.tsx`. The dashboard renders inside the app shell — adding a nav inside the dashboard creates a duplicate header, which is the most visually obvious mistake.
123
+
124
+ - ❌ `<nav className="bg-white border-b ...">` inside a dashboard page
125
+ - ❌ A header bar with logo + nav links + user avatar inside the dashboard
126
+ - ❌ Tab bars that act as top-level navigation (Overview, Travelers, Spend, etc.)
127
+ - ❌ `useState("overview")` / `useState("travelers")` to toggle between views — this IS tab navigation even without a `<nav>` element
128
+ - ❌ `{activeView === "overview" && (...)}` / `{activeView === "travelers" && (...)}` — content-swapping IS multi-tab navigation
129
+ - ✅ Dashboard starts directly with content (metrics, then primary content)
130
+ - ✅ If you need sub-sections, use the library `Tabs` component **inside a card** — not as a full-width page-level switcher
131
+ - ✅ Build a single-page dashboard — all content visible by scrolling. Do NOT split into multiple tab "pages" that swap content.
132
+
133
+ **Self-check:** If your dashboard has `useState` for an "active tab" or "active view" that conditionally renders different page sections, you are building multi-tab navigation. Delete it and put all content on one scrollable page.
134
+
135
+ **Self-check:** If your dashboard JSX starts with `<nav>`, a sticky tab bar, or a `<div>` that spans the full width with nav links, you are violating this rule. Delete it.
136
+
137
+ ### Why no multi-tab dashboards?
138
+
139
+ Splitting a dashboard into 5 tab "pages" (Overview, Travelers, Spend, Policy, Eva) means each tab is a separate mini-app. This violates the single-page dashboard pattern. Instead, put **all sections on one scrollable page** using the vertical page structure (metrics → primary content → secondary content). If content is too long, prioritize the most important sections and use cards with `maxBodyHeight` to constrain tall sections.
140
+
141
+ ## Where Dashboards Live & How to Wire Them
142
+
143
+ - Dashboard page files: `src/components/pages/` (e.g. `HelloWorld.jsx`, `FleetDashboard.jsx`)
144
+ - File format: `.jsx` (not `.tsx`) — matches the vendored library convention.
145
+ - `CommandCenter.tsx` wraps with `heroui-scope` + `AppThemeProvider` + `DataModeProvider` + `Toast.Provider`. **Never recreate these providers in dashboard pages.**
146
+
147
+ ### Wiring a new dashboard (REQUIRED STEPS)
148
+
149
+ You must do ALL of these or the dashboard will not render correctly:
150
+
151
+ **Step 1:** Create the dashboard file in `src/components/pages/`:
152
+ ```jsx
153
+ // src/components/pages/MyDashboard.jsx
154
+ import React from "react";
155
+ import { MetricCard, ListCard, ChartCard, D3Chart } from "@/components/library";
156
+
157
+ export default function MyDashboard() {
158
+ return (
159
+ <div className="space-y-6 p-6">
160
+ {/* dashboard content using library components */}
161
+ </div>
162
+ );
163
+ }
164
+ ```
165
+
166
+ **Step 2:** Update `CommandCenter.tsx` to import and render it:
167
+ ```tsx
168
+ // src/components/pages/CommandCenter.tsx
169
+ import AppThemeProvider from "@/components/library/theme/AppThemeProvider";
170
+ import DataModeProvider from "@/components/library/data/DataModeProvider";
171
+ import { Toast } from "@heroui/react";
172
+ import MyDashboard from "./MyDashboard"; // ← change this import
173
+
174
+ export default function CommandCenter() {
175
+ return (
176
+ <div className="heroui-scope">
177
+ <AppThemeProvider initialMode="light">
178
+ <DataModeProvider initialMode="sample">
179
+ <MyDashboard /> {/* ← change this */}
180
+ <Toast.Provider placement="bottom end" />
181
+ </DataModeProvider>
182
+ </AppThemeProvider>
183
+ </div>
184
+ );
185
+ }
186
+ ```
187
+
188
+ **Step 3:** Update `src/routes.tsx` to make the dashboard the home page. Replace the Search page index route with the Home/CommandCenter route:
189
+ ```tsx
190
+ // src/routes.tsx — change the index route
191
+ {
192
+ index: true,
193
+ element: <SuspenseWrap><Home /></SuspenseWrap>,
194
+ handle: { showInNavigation: true, label: 'Dashboard' }
195
+ },
196
+ {
197
+ path: "search",
198
+ element: <SuspenseWrap><Search /></SuspenseWrap>,
199
+ handle: { showInNavigation: true, label: 'Search' }
200
+ },
201
+ ```
202
+
203
+ The `Home` page renders `CommandCenter`, which renders your dashboard. The Search page moves to `/search`.
204
+
205
+ **Verify:** After writing all files, confirm:
206
+ 1. Your dashboard `.jsx` file exists in `src/components/pages/`
207
+ 2. `CommandCenter.tsx` imports your dashboard (not `BlankDashboard`)
208
+ 3. `src/routes.tsx` has `Home` as the index route and `Search` at `/search`
209
+
210
+ ## Page Structure
211
+
212
+ Every page follows this vertical order — never rearrange:
213
+ 1. Context (NarrativeSummary or heading) — optional
214
+ 2. KPI metrics (MetricsStrip or MetricCard grid) — required for dashboards
215
+ 3. Primary content (tables, charts, status)
216
+ 4. Secondary content (lists, logs, supporting data) — optional
217
+ 5. Actions — optional
218
+
219
+ Wrap all page content in `<div className="space-y-6">`. Do NOT use `mb-6` between sections — the wrapper handles spacing.
220
+
221
+ ## Layout Grids
222
+
223
+ Only these grid patterns — do not invent new ones:
224
+
225
+ - **4 metrics (MAXIMUM per row — never 5 or more):** `grid grid-cols-2 gap-3 lg:grid-cols-4`
226
+ - **3 metrics:** `grid grid-cols-1 gap-3 sm:grid-cols-3`
227
+ - **Wide/narrow split:** `grid grid-cols-1 items-start gap-4 lg:grid-cols-3` with `lg:col-span-2` on the wide side
228
+ - **3-col balanced:** `grid grid-cols-1 items-start gap-4 lg:grid-cols-3`
229
+ - **Equal two-col:** `grid grid-cols-1 items-start gap-4 lg:grid-cols-2`
230
+ - **Full-width:** `<div className="w-full">` — charts with 24+ data points
231
+
232
+ `gap-4` for content grids, `gap-3` for metric rows. Start `grid-cols-1` (or `grid-cols-2` for metrics) for mobile. Only `sm:` and `lg:` breakpoints unless justified.
233
+
234
+ **Max 4 KPIs per row — NEVER 5 or more.** If you have 5+ metrics, split into two rows (e.g. 4 + 1, or 3 + 2). Always `items-start` on grids pairing different-height cards. Use `maxBodyHeight={px}` for long card bodies. Actions go in card `actions` slot. Place `FilterBar` near the data it controls.
235
+
236
+ ## Layout Differentiation
237
+
238
+ Every dashboard needs a unique layout structure and at least one domain-specific "signature element" that couldn't exist in another dashboard. Vary section ordering, grid proportions, density, and visual rhythm.
239
+
240
+ ## Map Layout
241
+
242
+ GeoMap should be placed in a **wide/narrow grid** (`lg:grid-cols-3` with `lg:col-span-2`), not full-width hero. Full-width maps dominate the page and waste space.
243
+
244
+ **Pattern: Map + sidebar at matched height**
245
+
246
+ ```jsx
247
+ <div className="grid grid-cols-1 gap-4 lg:grid-cols-3">
248
+ <div className="lg:col-span-2 relative overflow-hidden rounded-xl h-[300px]">
249
+ <GeoMap
250
+ markers={locations}
251
+ arcs={arcs}
252
+ overlays={overlays}
253
+ initialBounds={{ sw: [-130, 24], ne: [-65, 50], padding: 30 }}
254
+ theme="dark"
255
+ width={960}
256
+ height={480}
257
+ zoomable
258
+ className="h-full w-full"
259
+ />
260
+ </div>
261
+ {/* Sidebar card — use maxBodyHeight to match map height */}
262
+ {/* Map h-[300px] ≈ ListCard maxBodyHeight={236} + ~64px header */}
263
+ <ListCard title="Activity" items={items} maxBodyHeight={236} showStatus />
264
+ </div>
265
+ ```
266
+
267
+ Key rules:
268
+ - **Do NOT wrap GeoMap in ChartCard** — GeoMap has its own background/borders
269
+ - **Match heights** — set map `h-[Xpx]` and sidebar `maxBodyHeight` so they align. Account for ~64px card header padding.
270
+ - **Use `initialBounds`** to auto-zoom to the region with data: `{ sw: [lonMin, latMin], ne: [lonMax, latMax], padding: 30 }`
271
+ - **Always pass `arcs`** for flight routes and `overlays` for disruption zones — not just markers
272
+ - **Use ListCard** (not ActivityCard) for the sidebar — ListCard supports `maxBodyHeight` for scroll, ActivityCard does not
273
+ - Keep map height at 280–320px — not 400+
274
+
275
+ ## Component Selection
276
+
277
+ | Need | Component |
278
+ |------|-----------|
279
+ | Single KPI | `MetricCard` |
280
+ | Row of 2–4 KPIs | `MetricsStrip` (schema) / `MetricCard` grid |
281
+ | Tabular data | `TableCard` |
282
+ | Time series / distribution | `ChartCard` + `D3Chart` |
283
+ | Geographic / flight map | `GeoMap` |
284
+ | System health | `StatusCard` |
285
+ | Feed / item list | `ListCard` |
286
+ | Scrollable side panel | `FeedPanel` |
287
+ | Activity feed | `ActivityCard` |
288
+ | User avatar | `Avatar` |
289
+ | Text summary | `NarrativeSummary` (schema) / `SectionCard` |
290
+ | Actions | `ActionList` (schema) / `UIButton` group |
291
+ | Alert / callout | `CalloutCard` |
292
+ | Multi-section panel | `WidgetCard` |
293
+
294
+ ## Component Data Contract
295
+
296
+ Common card props: `title`, `subtitle`, `actions`, `loading`, `error`, `emptyMessage`, `...cardProps`.
297
+
298
+ Item shape (StatusCard, ListCard, ItemList): `{ id?, title, description?, status?, timestamp?, value?, unit?, avatar? }`. `title` is primary; `name` is alias.
299
+
300
+ Never use hardcoded `indigo-*` — use `brand-*` classes.
301
+
302
+ ## Metric Formatting
303
+
304
+ Use `fmtK()` helper — never manually append K/M/B:
305
+
306
+ ```js
307
+ function fmtK(n) {
308
+ if (n >= 1e6) return `${(n / 1e6).toFixed(1)}M`;
309
+ if (n >= 1e3) return `${(n / 1e3).toFixed(1)}K`;
310
+ return n.toLocaleString();
311
+ }
312
+ ```
313
+
314
+ ## Brand & Accent Colors
315
+
316
+ Defined in `global.css` (`--color-brand-*` and `--color-engine-*`), available as Tailwind classes.
317
+
318
+ - `engine-*` for the Engine brand: `engine-teal`, `engine-coral`, `engine-orange`, `engine-savings`, `engine-text`, `engine-muted`, `engine-label`, `engine-border`, `engine-bg`
319
+ - `brand-*` for the legacy command center palette (indigo-based)
320
+ - Tailwind built-in colors for status (green/amber/red). Never use brand for status.
321
+
322
+ ## Semantic Colors
323
+
324
+ - `"default"` — neutral | `"primary"` — brand | `"success"` — healthy | `"warning"` — attention | `"danger"` — critical
325
+
326
+ `changeType` reflects good/bad, not direction. Revenue down = `"negative"`. Incidents down = `"positive"`.
327
+
328
+ ## Status Values
329
+
330
+ Canonical: `"operational"`, `"degraded"`, `"outage"`, `"maintenance"`. Always show color + text label.
331
+
332
+ ## Dark Mode (MANDATORY)
333
+
334
+ Every visible element needs both light and dark styles. Library components handle this automatically — which is another reason to use them.
335
+
336
+ For any custom markup you do write:
337
+
338
+ | Role | Light | Dark |
339
+ |------|-------|------|
340
+ | Background | `bg-white` | `dark:bg-slate-900` |
341
+ | Surface | `bg-slate-50` | `dark:bg-slate-950/30` |
342
+ | Border | `border-slate-200` | `dark:border-slate-800` |
343
+ | Text primary | `text-slate-900` | `dark:text-slate-50` |
344
+ | Text secondary | `text-slate-600` | `dark:text-slate-300` |
345
+ | Text muted | `text-slate-500` | `dark:text-slate-400` |
346
+ | Brand tint | `brand-50` | `brand-950` |
347
+
348
+ **Never use `text-black` or `text-white`.** Use the slate scale. Never use `bg-black` for surfaces — use `bg-slate-900` / `dark:bg-slate-950`.
349
+
350
+ ## Icons (Command Center)
351
+
352
+ **Heroicons 2** (`@heroicons/react`) exclusively inside command center pages. No Lucide, no Font Awesome, no inline SVGs.
353
+
354
+ - `24/outline` — default | `24/solid` — status/active | `20/solid` — chips/badges
355
+ - Sizes: `h-4 w-4` compact, `h-5 w-5` default, `h-6 w-6` emphasis, `h-8 w-8` hero only
356
+ - Always set a color class. Pass rendered elements: `icon={<UsersIcon className="h-5 w-5 text-brand-500" />}`
357
+ - ❌ Never use inline `<svg>` when a Heroicon exists for the same purpose
358
+ - ❌ Never guess icon names — Heroicons uses specific names that don't always match what you'd expect. Common mistakes: `PlaneIcon` (doesn't exist → use `PaperAirplaneIcon`), `FlightIcon` (doesn't exist → use `PaperAirplaneIcon`), `HotelIcon` (doesn't exist → use `BuildingOfficeIcon`), `MoneyIcon` (doesn't exist → use `BanknotesIcon`), `AlertIcon` (doesn't exist → use `ExclamationTriangleIcon`), `PersonIcon` (doesn't exist → use `UserIcon`)
359
+
360
+ ## Fonts
361
+
362
+ Fonts are set in `global.css` via `@theme` block (`--font-sans`, `--font-mono`). No `next/font` in this project (that's the starter). No Google Fonts `<link>` tags.
363
+
364
+ ## Filtering & Data Utilities
365
+
366
+ Three layers: `filterUtils.js` (pure) → `usePageFilters` hook (state) → `FilterBar` + components (UI).
367
+
368
+ - Pass `sortedData` (not `filteredData`) to components
369
+ - Disable `TableCard.searchable` when `FilterBar` provides search
370
+ - Declare filter definitions outside component body (or memoize)
371
+
372
+ ## Data Mode (Sample vs Live)
373
+
374
+ `useDataMode()` returns `{ mode, isSample, isLive, toggle, setMode }`. `useDataSource({ sample, live })` picks based on mode.
375
+
376
+ - Every page works in both modes. Default to `"sample"`.
377
+ - Same layout for both modes — only data changes.
378
+ - Sample data: 10–50 items, realistic, deterministic (no `Math.random()`).
379
+ - Define sample data as constants outside the component body.
380
+
381
+ ```jsx
382
+ // ✅ Correct: data defined outside, selected by mode
383
+ const SAMPLE_TRIPS = [ ... ];
384
+
385
+ export default function Dashboard() {
386
+ const trips = useDataSource({ sample: SAMPLE_TRIPS, live: liveTrips });
387
+ ...
388
+ }
389
+
390
+ // ❌ Wrong: hardcoded data inside the component with no mode switching
391
+ export default function Dashboard() {
392
+ const trips = [ ... ]; // no useDataSource, no mode awareness
393
+ }
394
+ ```
395
+
396
+ ## Forms & Record Modals
397
+
398
+ Schema-driven: `sections[] → fields[]`. Use `FormModal` (modal) or `FormRenderer` (inline). `useFormState` for state.
399
+
400
+ Define schemas outside component body. Always `required: true` on mandatory fields. Submissions enforce 4s minimum spinner.
401
+
402
+ ## AI Chat & Agent
403
+
404
+ Use `ChatBar` (command palette, ⌘K) for dashboards. `ChatPanel` for full-page chat.
405
+
406
+ - Always provide 3–5 `suggestions` for starter prompts
407
+ - Return `components` for structured data — never markdown tables in text
408
+ - Always set height on `ChatPanel`
409
+ - Extract `onSend` handlers to module scope when shared
410
+
411
+ ## Tables
412
+
413
+ `searchable` when 10+ rows (unless `FilterBar` handles search). `sortable` on comparable columns. `paginated` when 10+ rows. Use built-in column `type` before custom `render`.
414
+
415
+ ## Charts & Visualizations (MANDATORY)
416
+
417
+ **All charts, graphs, maps, and visualizations MUST use library components.** Never use Recharts, Chart.js, Nivo, or any third-party charting library. Never hand-roll SVG, canvas, or custom chart markup. The ONLY charting tools allowed are `D3Chart` (via `D3ChartTemplates` or a custom `renderChart` function) and `GeoMap`.
418
+
419
+ | Visualization | MUST use | NEVER do |
420
+ |--------------|----------|----------|
421
+ | Line chart | `ChartCard` + `D3Chart` with `D3ChartTemplates.lineChart` | Custom `<svg>` with hand-drawn paths/circles |
422
+ | Grouped bar chart | `ChartCard` + `D3Chart` with `D3ChartTemplates.groupedBarChart` | Custom `<svg>` bar elements |
423
+ | Map / geographic | `GeoMap` | Custom SVG map or embedded iframe |
424
+ | Custom visualization | `ChartCard` + `D3Chart` with a custom `renderChart` function | Inline SVG/canvas |
425
+
426
+ ### D3Chart API (CRITICAL — read carefully)
427
+
428
+ `D3Chart` does NOT use a `template` prop. It uses a `renderChart` callback function:
429
+
430
+ ```jsx
431
+ <D3Chart
432
+ data={array} // data array
433
+ renderChart={D3ChartTemplates.lineChart} // function reference, NOT a string
434
+ responsive={true} // enables ResizeObserver
435
+ height={280} // height in px
436
+ />
437
+ ```
438
+
439
+ ### ChartCard + D3Chart usage
440
+
441
+ `ChartCard` takes a `chart` prop (a React element). Pass the `D3Chart` as the `chart` value:
442
+
443
+ ```jsx
444
+ import { ChartCard, D3Chart, D3ChartTemplates } from "@/components/library";
445
+
446
+ // ✅ Line chart — data must have { x, y } shape (numeric x)
447
+ const spendData = [
448
+ { x: 1, y: 2400 }, { x: 2, y: 3100 }, { x: 3, y: 2800 }, ...
449
+ ];
450
+ <ChartCard
451
+ title="30-Day Spend"
452
+ subtitle="Engine savings"
453
+ chart={
454
+ <D3Chart
455
+ data={spendData}
456
+ renderChart={D3ChartTemplates.lineChart}
457
+ options={{ stroke: "#5BC8C8", xKey: "x", yKey: "y" }}
458
+ responsive
459
+ height={280}
460
+ />
461
+ }
462
+ />
463
+
464
+ // ✅ Grouped bar chart — data must have { x, group1, group2 } shape
465
+ const monthlyData = [
466
+ { x: "Jan", Hotels: 12000, Flights: 8000 },
467
+ { x: "Feb", Hotels: 14000, Flights: 9000 }, ...
468
+ ];
469
+ <ChartCard
470
+ title="Monthly Spend"
471
+ chart={
472
+ <D3Chart
473
+ data={monthlyData}
474
+ renderChart={D3ChartTemplates.groupedBarChart}
475
+ options={{ xKey: "x", groups: ["Hotels", "Flights"], colors: ["#5BC8C8", "#6366F1"] }}
476
+ responsive
477
+ height={280}
478
+ />
479
+ }
480
+ />
481
+
482
+ // ✅ Custom renderChart function (for donut, horizontal bar, etc.)
483
+ function renderDonut(svgEl, data, dims, opts) {
484
+ // Use d3 to draw into svgEl
485
+ const d3svg = d3.select(svgEl);
486
+ d3svg.selectAll("*").remove();
487
+ // ... d3 drawing code
488
+ }
489
+ <ChartCard title="By Department" chart={<D3Chart data={deptData} renderChart={renderDonut} responsive height={280} />} />
490
+ ```
491
+
492
+ ### Available D3ChartTemplates
493
+
494
+ - `D3ChartTemplates.lineChart` — options: `{ xKey, yKey, stroke, strokeWidth, margin, showAxes, showGrid }`
495
+ - `D3ChartTemplates.groupedBarChart` — options: `{ xKey, groups, colors, barRadius, margin, yFormat, showGrid }`
496
+
497
+ **There is NO `D3ChartTemplates.LINE`, `.BAR`, `.DONUT`, `.AREA`.** Only `lineChart` and `groupedBarChart`. For donut/pie/horizontal bar, write a custom `renderChart` function using d3.
498
+
499
+ ### GeoMap API
500
+
501
+ ```jsx
502
+ import { GeoMap } from "@/components/library";
503
+
504
+ // markers: array of { id, lon, lat, active?, label? }
505
+ const markers = [
506
+ { id: "sf", lon: -122.4, lat: 37.8, active: true, label: "San Francisco" },
507
+ { id: "nyc", lon: -74.0, lat: 40.7, active: true, label: "New York" },
508
+ ];
509
+
510
+ <ChartCard title="Active Locations" chart={
511
+ <GeoMap
512
+ markers={markers}
513
+ theme="dark"
514
+ height={400}
515
+ width={800}
516
+ zoomable
517
+ />
518
+ } />
519
+ ```
520
+
521
+ GeoMap props: `width`, `height`, `projection` (`"naturalEarth"` | `"mercator"` | `"equirectangular"`), `theme` (`"dark"` | `"light"`), `markers`, `arcs`, `overlays`, `zoomable`, `minZoom`, `maxZoom`, `onMarkerClick`.
522
+
523
+ ### Common mistakes
524
+
525
+ ```jsx
526
+ // ❌ WRONG — third-party chart libraries are forbidden
527
+ import { BarChart, Bar } from "recharts";
528
+ <BarChart data={data}><Bar dataKey="count" /></BarChart>
529
+
530
+ // ❌ WRONG — template prop doesn't exist
531
+ <D3Chart template={D3ChartTemplates.LINE} data={data} />
532
+
533
+ // ❌ WRONG — passing as children instead of chart prop
534
+ <ChartCard title="Spend"><D3Chart ... /></ChartCard>
535
+
536
+ // ❌ WRONG — non-numeric x values with lineChart (use groupedBarChart for categorical x)
537
+ <D3Chart data={[{x: "Jan", y: 100}]} renderChart={D3ChartTemplates.lineChart} />
538
+
539
+ // ✅ CORRECT
540
+ <ChartCard title="Spend" chart={<D3Chart data={data} renderChart={D3ChartTemplates.lineChart} responsive height={280} />} />
541
+ ```
542
+
543
+ ## Portals
544
+
545
+ Any `position: fixed` component **must** use `createPortal(... , document.body)`.
546
+
547
+ ## Loading / Error / Empty States
548
+
549
+ Every data component handles loading. Error messages are human-readable. Empty states explain what would appear.
550
+
551
+ ## Pre-Completion Checklist
552
+
553
+ Before finishing a dashboard page, verify ALL of these:
554
+
555
+ - [ ] **Every card/panel is a library component** (MetricCard, ListCard, ActivityCard, WidgetCard, TableCard, etc.) — no hand-rolled `<div className="bg-white border ...">` cards
556
+ - [ ] **Every chart/visualization is a library component** (ChartCard + D3Chart, GeoMap) — no hand-rolled SVG/canvas
557
+ - [ ] **No `<nav>`, header bar, or sticky tab bar** — navigation is handled by appLayout.tsx
558
+ - [ ] **Single scrollable page** — no multi-tab layout that swaps content
559
+ - [ ] **Max 4 KPIs per row** — if 5+, split across rows
560
+ - [ ] **Charts render** — using `renderChart` callback (not `template` prop), data format matches (numeric x for lineChart)
561
+ - [ ] **`<div className="space-y-6">` wraps all content** — no `mb-*` for section spacing
562
+ - [ ] **Dark mode works** — every custom element has `dark:` variants; no `text-black`, `text-white`, or `bg-black`
563
+ - [ ] **No inline `style={{}}` or `<style>` tags** — use Tailwind classes or CSS in global.css
564
+ - [ ] **No inline `<svg>`** — use Heroicons from `@heroicons/react`
565
+ - [ ] **`position: fixed` uses `createPortal`** — FABs, modals, toasts
566
+ - [ ] **Data uses `useDataSource`** — sample data defined outside the component
567
+ - [ ] **Only uses company logo** (`@/assets/images/engine_logo.png`) — no external URLs, no placeholder boxes
568
+ - [ ] **Images preserve aspect ratio** — one dimension auto, never both fixed
569
+ - [ ] **Imports only from `@/components/library`** — no shadcn, no Lucide, no `cn()`
570
+ - [ ] **Grid patterns match the approved list** — no custom grid layouts
571
+
572
+ ## Post-Completion Verification (REQUIRED — MUST RUN BEFORE REPORTING DONE)
573
+
574
+ After building the dashboard, you MUST run the validator and fix ALL errors before reporting the dashboard as complete:
575
+
576
+ ```bash
577
+ # Run from the web app directory
578
+ npm run validate:dashboard
579
+ ```
580
+
581
+ **Do NOT run `npm run build` or `tsc`.** The TypeScript build has known issues with platform-only Salesforce packages that are not relevant to dashboard development. Only run the validator.
582
+
583
+ The validator (`scripts/validate-dashboard.sh`) automatically checks for:
584
+ - Hand-rolled HTML cards, tables, and SVGs (must use library components)
585
+ - Forbidden colors (`text-black`, `text-white`, `bg-black`)
586
+ - Inline `style={{}}` and `<style>` tags
587
+ - Missing `useDataSource` for sample/live mode
588
+ - Grid layouts with 5+ columns
589
+ - `position: fixed` without `createPortal`
590
+ - shadcn/Lucide imports in command center code
591
+ - Missing `space-y-6` wrappers
592
+ - `.tsx` files where `.jsx` is required
593
+ - Dashboard navigation (`<nav>` elements)
594
+
595
+ **If the validator reports errors, you MUST fix them ALL — zero errors required.** Do not report the dashboard as complete with any errors. Do not dismiss errors as "acceptable", "justified", or "expected". Every error has a fix — usually by switching to the correct library component. The validator exits with code 1 on errors — treat this like a failing test.
596
+
597
+ **Common validator errors and their fixes:**
598
+ - **Hand-rolled card** → Wrap content in `WidgetCard`, `ListCard`, `BaseCard`, or another library card component. `WidgetCard` with a single section can wrap any arbitrary JSX content.
599
+ - **Forbidden colors** (`text-white`, `bg-black`) → Use slate scale (`text-slate-50`, `bg-slate-900`)
600
+ - **shadcn/Lucide imports** → Replace with library components and Heroicons
601
+
602
+ **Do not skip or ignore the validator.** Do not run `npm run build` or `tsc` — only run `npm run validate:dashboard`.
603
+
604
+ ## Anti-Patterns (never do these)
605
+
606
+ - Hand-rolling HTML cards instead of using library components (MetricCard, ListCard, etc.)
607
+ - Using Recharts, Chart.js, Nivo, or any chart library other than D3Chart/GeoMap
608
+ - Hand-rolling SVG/canvas charts instead of using ChartCard + D3Chart or GeoMap
609
+ - Adding a `<nav>`, header bar, sticky tab bar, or top navigation inside a dashboard page
610
+ - Multi-tab layouts that swap content (Overview/Travelers/Spend/etc tabs) — build one scrollable page
611
+ - More than 4 KPIs in a single row (max is `lg:grid-cols-4`)
612
+ - Using `template` prop on D3Chart (doesn't exist) — use `renderChart={D3ChartTemplates.lineChart}`
613
+ - Passing D3Chart as children to ChartCard — use `chart={<D3Chart ... />}` prop
614
+ - CSS Modules, styled-components, or inline `style={{}}` for layout
615
+ - `<style>` tags with keyframes or custom CSS inside components
616
+ - Inline `<svg>` elements when a Heroicon exists
617
+ - Importing shadcn components (`src/components/ui/`) into command center pages — `Button`, `Card`, `Input`, `Select`, `Alert`, `Skeleton`, `Label`, `Spinner`, etc. are ALL forbidden. Use the library equivalents from `@/components/library` (`UIButton`, `BaseCard`/`WidgetCard`, `UIInput`, `Select`, `Alert`, `Skeleton`, etc.)
618
+ - Importing Lucide icons (`lucide-react`) into command center pages — use Heroicons (`@heroicons/react`) instead
619
+ - Using `cn()` helper in command center pages (that's shadcn's utility — use Tailwind classes directly)
620
+ - `useEffect` for data in schema components
621
+ - `bg-indigo-*` or raw colors for brand — use `brand-*` or `engine-*`
622
+ - Recreating providers (`AppThemeProvider`, `DataModeProvider`) in dashboard pages — `CommandCenter.tsx` already provides them
623
+ - Tables without search on 10+ rows, charts without tooltips, empty states without messages
624
+ - Hard-coded pixel widths or skipping dark mode
625
+ - `text-black`, `text-white`, `bg-black` — use slate scale
626
+ - `lg:grid-cols-6` for metrics (max 4), manually appending K/M/B
627
+ - `mb-6` between sections instead of `space-y-6` wrapper
628
+ - Same layout across dashboards, no signature element
629
+ - `ChatPanel` in dashboard grid — use `ChatBar`
630
+ - `position: fixed` without `createPortal`
631
+ - `Math.random()` in sample data, different layouts based on data mode
632
+ - Re-declaring filter/form definitions inside component render
633
+ - Dismissing validator errors as "acceptable" or "justified" instead of fixing them — every error has a library component fix
634
+ - Hardcoded data without `useDataSource` for sample/live mode switching
635
+ - External image URLs (Unsplash, placeholders) unless user explicitly requests them
636
+ - Placeholder boxes (`<div className="w-8 h-8 bg-black rounded" />`) instead of the actual logo
637
+ - Fixed width AND height on images — always let one dimension be `auto` to preserve aspect ratio