@exxatdesignux/ui 0.0.5 → 0.0.7

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 (264) hide show
  1. package/bin/init.mjs +29 -0
  2. package/package.json +7 -2
  3. package/template/.nvmrc +1 -0
  4. package/template/.prettierignore +7 -0
  5. package/template/.prettierrc +11 -0
  6. package/template/AGENTS.md +485 -0
  7. package/template/Logo/Exxat_Prism.svg +39 -0
  8. package/template/Logo/Exxat_one.svg +36 -0
  9. package/template/README.md +58 -0
  10. package/template/app/(app)/compliance/page.tsx +10 -0
  11. package/template/app/(app)/dashboard/loading.tsx +18 -0
  12. package/template/app/(app)/dashboard/page.tsx +36 -0
  13. package/template/app/(app)/data-list/[id]/page.tsx +28 -0
  14. package/template/app/(app)/data-list/new/page.tsx +31 -0
  15. package/template/app/(app)/data-list/page.tsx +10 -0
  16. package/template/app/(app)/error.tsx +43 -0
  17. package/template/app/(app)/help/page.tsx +34 -0
  18. package/template/app/(app)/layout.tsx +54 -0
  19. package/template/app/(app)/loading.tsx +18 -0
  20. package/template/app/(app)/question-bank/page.tsx +10 -0
  21. package/template/app/(app)/rotations/page.tsx +15 -0
  22. package/template/app/(app)/settings/page.tsx +17 -0
  23. package/template/app/(app)/sites/all/page.tsx +13 -0
  24. package/template/app/(app)/team/page.tsx +10 -0
  25. package/template/app/favicon.ico +0 -0
  26. package/template/app/globals.css +1811 -0
  27. package/template/app/layout.tsx +95 -0
  28. package/template/app/page.tsx +9 -0
  29. package/template/components/.gitkeep +0 -0
  30. package/template/components/app-sidebar-dynamic.tsx +15 -0
  31. package/template/components/app-sidebar.tsx +901 -0
  32. package/template/components/ask-leo-composer.tsx +216 -0
  33. package/template/components/ask-leo-sidebar.tsx +509 -0
  34. package/template/components/chart-area-interactive.tsx +293 -0
  35. package/template/components/charts-overview.tsx +2321 -0
  36. package/template/components/command-menu-01.tsx +133 -0
  37. package/template/components/command-menu-02.tsx +386 -0
  38. package/template/components/command-menu.tsx +182 -0
  39. package/template/components/compliance-board-view.tsx +134 -0
  40. package/template/components/compliance-client.tsx +92 -0
  41. package/template/components/compliance-list-view.tsx +59 -0
  42. package/template/components/compliance-page-header.tsx +89 -0
  43. package/template/components/compliance-table.tsx +525 -0
  44. package/template/components/dashboard-onboarding-gallery.tsx +13 -0
  45. package/template/components/dashboard-onboarding.tsx +21 -0
  46. package/template/components/dashboard-promo-banner.tsx +67 -0
  47. package/template/components/dashboard-quota-progress-card.tsx +369 -0
  48. package/template/components/dashboard-report-charts.tsx +69 -0
  49. package/template/components/dashboard-section-heading.tsx +68 -0
  50. package/template/components/dashboard-tabs.tsx +598 -0
  51. package/template/components/data-list-client.tsx +239 -0
  52. package/template/components/data-list-table-cells.test.tsx +22 -0
  53. package/template/components/data-list-table-cells.tsx +173 -0
  54. package/template/components/data-list-table.tsx +879 -0
  55. package/template/components/data-table/filter-date-calendar.tsx +38 -0
  56. package/template/components/data-table/filter-text-value-input.tsx +77 -0
  57. package/template/components/data-table/index.tsx +1612 -0
  58. package/template/components/data-table/pagination.tsx +256 -0
  59. package/template/components/data-table/types.ts +91 -0
  60. package/template/components/data-table/use-table-state.ts +566 -0
  61. package/template/components/data-view-dashboard-charts-compliance.tsx +960 -0
  62. package/template/components/data-view-dashboard-charts-team.tsx +968 -0
  63. package/template/components/data-view-dashboard-charts.tsx +1668 -0
  64. package/template/components/data-views/board-card-primitives.tsx +93 -0
  65. package/template/components/data-views/index.ts +41 -0
  66. package/template/components/data-views/list-page-board-card.tsx +192 -0
  67. package/template/components/data-views/list-page-board-template.tsx +122 -0
  68. package/template/components/data-views/placement-board-card.tsx +262 -0
  69. package/template/components/export-drawer.tsx +375 -0
  70. package/template/components/exxat-product-logo.tsx +453 -0
  71. package/template/components/form-layout-01.tsx +131 -0
  72. package/template/components/getting-started.tsx +625 -0
  73. package/template/components/key-metrics.tsx +920 -0
  74. package/template/components/leo-insight-indicator.tsx +364 -0
  75. package/template/components/leo-typing-dots.tsx +121 -0
  76. package/template/components/list-hub-status-badge.tsx +51 -0
  77. package/template/components/list-page-dashboard-charts.tsx +18 -0
  78. package/template/components/nav-documents.tsx +89 -0
  79. package/template/components/nav-main.tsx +58 -0
  80. package/template/components/nav-secondary.tsx +64 -0
  81. package/template/components/nav-user.tsx +190 -0
  82. package/template/components/new-placement-back-btn.tsx +28 -0
  83. package/template/components/new-placement-form.tsx +1066 -0
  84. package/template/components/onboarding/index.ts +4 -0
  85. package/template/components/onboarding/onboarding-01.tsx +7 -0
  86. package/template/components/onboarding/onboarding-02.tsx +7 -0
  87. package/template/components/onboarding/onboarding-03.tsx +7 -0
  88. package/template/components/onboarding/onboarding-04.tsx +7 -0
  89. package/template/components/page-header.tsx +57 -0
  90. package/template/components/placement-detail.tsx +438 -0
  91. package/template/components/placements-board-view.tsx +404 -0
  92. package/template/components/placements-list-view.tsx +285 -0
  93. package/template/components/placements-page-header.tsx +160 -0
  94. package/template/components/placements-table-columns.tsx +639 -0
  95. package/template/components/product-switcher.tsx +116 -0
  96. package/template/components/question-bank-board-view.tsx +205 -0
  97. package/template/components/question-bank-client.tsx +77 -0
  98. package/template/components/question-bank-list-view.tsx +59 -0
  99. package/template/components/question-bank-page-header.tsx +89 -0
  100. package/template/components/question-bank-table.tsx +586 -0
  101. package/template/components/rotations-empty-state.tsx +47 -0
  102. package/template/components/rotations-panel-activator.tsx +8 -0
  103. package/template/components/secondary-nav.tsx +394 -0
  104. package/template/components/secondary-panel.tsx +239 -0
  105. package/template/components/section-cards.tsx +106 -0
  106. package/template/components/settings-appearance-card.tsx +424 -0
  107. package/template/components/settings-client.tsx +537 -0
  108. package/template/components/settings-form-row.tsx +42 -0
  109. package/template/components/sidebar-auto-collapse.tsx +23 -0
  110. package/template/components/sidebar-auto-open.tsx +18 -0
  111. package/template/components/sidebar-shell.tsx +37 -0
  112. package/template/components/site-header.tsx +93 -0
  113. package/template/components/sites-all-client.tsx +154 -0
  114. package/template/components/sites-board-view.tsx +67 -0
  115. package/template/components/sites-list-view.tsx +47 -0
  116. package/template/components/sites-table.tsx +312 -0
  117. package/template/components/system-banner-slot.tsx +66 -0
  118. package/template/components/table-properties/column-row.tsx +90 -0
  119. package/template/components/table-properties/draggable-list.ts +49 -0
  120. package/template/components/table-properties/drawer-button.tsx +231 -0
  121. package/template/components/table-properties/drawer.tsx +1102 -0
  122. package/template/components/table-properties/filter-card.tsx +251 -0
  123. package/template/components/table-properties/index.ts +22 -0
  124. package/template/components/table-properties/sort-card.tsx +59 -0
  125. package/template/components/table-properties/types.ts +124 -0
  126. package/template/components/task-list-panel.tsx +98 -0
  127. package/template/components/task-priority-badge.tsx +28 -0
  128. package/template/components/team-board-view.tsx +114 -0
  129. package/template/components/team-client.tsx +93 -0
  130. package/template/components/team-list-view.tsx +62 -0
  131. package/template/components/team-page-header.tsx +92 -0
  132. package/template/components/team-table.tsx +525 -0
  133. package/template/components/templates/list-page.tsx +576 -0
  134. package/template/components/templates/primary-page-template.tsx +56 -0
  135. package/template/components/theme-color-sync.tsx +32 -0
  136. package/template/components/theme-provider.tsx +71 -0
  137. package/template/components/tinted-icon-disc.tsx +53 -0
  138. package/template/components/ui/ai-thinking-surface.tsx +121 -0
  139. package/template/components/ui/avatar.tsx +1 -0
  140. package/template/components/ui/badge.tsx +1 -0
  141. package/template/components/ui/banner.tsx +1 -0
  142. package/template/components/ui/breadcrumb.tsx +1 -0
  143. package/template/components/ui/button.tsx +1 -0
  144. package/template/components/ui/calendar.tsx +1 -0
  145. package/template/components/ui/card.tsx +1 -0
  146. package/template/components/ui/chart.tsx +1 -0
  147. package/template/components/ui/checkbox.tsx +1 -0
  148. package/template/components/ui/coach-mark.tsx +1 -0
  149. package/template/components/ui/collapsible.tsx +1 -0
  150. package/template/components/ui/command.tsx +1 -0
  151. package/template/components/ui/date-picker-field.tsx +1 -0
  152. package/template/components/ui/dialog.tsx +1 -0
  153. package/template/components/ui/dot-pattern.tsx +159 -0
  154. package/template/components/ui/drag-handle-grip.tsx +1 -0
  155. package/template/components/ui/drawer.tsx +1 -0
  156. package/template/components/ui/dropdown-menu.tsx +1 -0
  157. package/template/components/ui/field.tsx +1 -0
  158. package/template/components/ui/form.tsx +1 -0
  159. package/template/components/ui/input-group.tsx +1 -0
  160. package/template/components/ui/input-mask.tsx +1 -0
  161. package/template/components/ui/input.tsx +1 -0
  162. package/template/components/ui/kbd.tsx +1 -0
  163. package/template/components/ui/label.tsx +1 -0
  164. package/template/components/ui/leo-icon.tsx +726 -0
  165. package/template/components/ui/payment-card-fields.tsx +1 -0
  166. package/template/components/ui/popover.tsx +1 -0
  167. package/template/components/ui/radio-group.tsx +1 -0
  168. package/template/components/ui/select.tsx +1 -0
  169. package/template/components/ui/selection-tile-grid.tsx +1 -0
  170. package/template/components/ui/separator.tsx +1 -0
  171. package/template/components/ui/sheet.tsx +1 -0
  172. package/template/components/ui/sidebar.tsx +1 -0
  173. package/template/components/ui/skeleton.tsx +1 -0
  174. package/template/components/ui/sonner.tsx +1 -0
  175. package/template/components/ui/status-badge.tsx +1 -0
  176. package/template/components/ui/table.tsx +1 -0
  177. package/template/components/ui/tabs.tsx +1 -0
  178. package/template/components/ui/textarea.tsx +1 -0
  179. package/template/components/ui/tip.tsx +1 -0
  180. package/template/components/ui/toggle-group.tsx +1 -0
  181. package/template/components/ui/toggle-switch.tsx +1 -0
  182. package/template/components/ui/toggle.tsx +1 -0
  183. package/template/components/ui/tooltip.tsx +1 -0
  184. package/template/components/ui/view-segmented-control.tsx +1 -0
  185. package/template/components.json +27 -0
  186. package/template/contexts/chart-variant-context.tsx +35 -0
  187. package/template/contexts/command-menu-context.tsx +28 -0
  188. package/template/contexts/dashboard-view-context.tsx +35 -0
  189. package/template/contexts/product-context.tsx +38 -0
  190. package/template/contexts/system-banner-context.tsx +127 -0
  191. package/template/docs/command-menu-pattern.md +45 -0
  192. package/template/docs/data-views-pattern.md +160 -0
  193. package/template/ecosystem.config.cjs +20 -0
  194. package/template/eslint.config.mjs +18 -0
  195. package/template/fontawesome-subset.manifest.json +190 -0
  196. package/template/hooks/.gitkeep +0 -0
  197. package/template/hooks/use-app-theme.ts +1 -0
  198. package/template/hooks/use-coach-mark.ts +1 -0
  199. package/template/hooks/use-mobile.ts +1 -0
  200. package/template/hooks/use-mod-key-label.ts +1 -0
  201. package/template/lib/.gitkeep +0 -0
  202. package/template/lib/ask-leo-route-context.ts +133 -0
  203. package/template/lib/chart-keyboard-selection.test.ts +20 -0
  204. package/template/lib/chart-keyboard-selection.ts +17 -0
  205. package/template/lib/chart-line-dash.ts +16 -0
  206. package/template/lib/coach-mark-registry.ts +68 -0
  207. package/template/lib/command-menu-config.ts +127 -0
  208. package/template/lib/command-menu-search-data.ts +44 -0
  209. package/template/lib/conditional-rule-match.ts +32 -0
  210. package/template/lib/dashboard-customize-coach-mark.ts +18 -0
  211. package/template/lib/dashboard-layout-merge.ts +63 -0
  212. package/template/lib/data-list-display-options.ts +35 -0
  213. package/template/lib/data-list-persistence.ts +280 -0
  214. package/template/lib/data-list-view-surface.ts +58 -0
  215. package/template/lib/data-list-view.ts +29 -0
  216. package/template/lib/data-view-dashboard-storage.ts +101 -0
  217. package/template/lib/date-filter.ts +8 -0
  218. package/template/lib/dev-log.test.ts +28 -0
  219. package/template/lib/dev-log.ts +8 -0
  220. package/template/lib/editable-target.ts +10 -0
  221. package/template/lib/floating-sheet-panel.ts +72 -0
  222. package/template/lib/initials-from-name.ts +7 -0
  223. package/template/lib/list-page-table-properties.ts +52 -0
  224. package/template/lib/list-status-badges.ts +168 -0
  225. package/template/lib/logo-dev.ts +12 -0
  226. package/template/lib/mock/compliance-kpi.ts +61 -0
  227. package/template/lib/mock/compliance.ts +146 -0
  228. package/template/lib/mock/dashboard.ts +105 -0
  229. package/template/lib/mock/navigation.tsx +231 -0
  230. package/template/lib/mock/placements-kpi.ts +134 -0
  231. package/template/lib/mock/placements.ts +183 -0
  232. package/template/lib/mock/question-bank-kpi.ts +61 -0
  233. package/template/lib/mock/question-bank.ts +142 -0
  234. package/template/lib/mock/sites-directory.ts +16 -0
  235. package/template/lib/mock/sites-kpi.ts +25 -0
  236. package/template/lib/mock/team-kpi.ts +60 -0
  237. package/template/lib/mock/team.ts +118 -0
  238. package/template/lib/motion-ui.ts +17 -0
  239. package/template/lib/placement-board-card-layout.ts +79 -0
  240. package/template/lib/placement-lifecycle.ts +5 -0
  241. package/template/lib/row-height.ts +10 -0
  242. package/template/lib/stock-portrait.ts +11 -0
  243. package/template/lib/utils.test.ts +13 -0
  244. package/template/lib/utils.ts +1 -0
  245. package/template/next.config.mjs +15 -0
  246. package/template/package.json +83 -0
  247. package/template/postcss.config.mjs +8 -0
  248. package/template/public/.gitkeep +0 -0
  249. package/template/public/Illustration/Rotation.svg +74 -0
  250. package/template/public/avatars/user.svg +11 -0
  251. package/template/public/favicon/favicon.ico +0 -0
  252. package/template/public/favicon.ico +0 -0
  253. package/template/public/logos/exxat-one.svg +36 -0
  254. package/template/public/logos/exxat-prism.svg +39 -0
  255. package/template/public/mock-schools/emory.svg +4 -0
  256. package/template/public/mock-schools/rush.svg +4 -0
  257. package/template/scripts/fontawesome-subset-audit.mjs +190 -0
  258. package/template/scripts/pm2-startup-macos.sh +13 -0
  259. package/template/skills-lock.json +10 -0
  260. package/template/stores/app-store.ts +33 -0
  261. package/template/tests/setup.ts +1 -0
  262. package/template/tsconfig.json +35 -0
  263. package/template/types/react-payment-inputs.d.ts +19 -0
  264. package/template/vitest.config.ts +18 -0
@@ -0,0 +1,968 @@
1
+ "use client"
2
+
3
+ /**
4
+ * Team **Data** view dashboard — filtered `TeamMember[]` with the same canvas pattern as Placements:
5
+ * key metrics + charts, show/hide, reorder, width, chart type, persistence.
6
+ */
7
+
8
+ import * as React from "react"
9
+ import {
10
+ closestCorners,
11
+ DndContext,
12
+ type DragEndEvent,
13
+ KeyboardSensor,
14
+ PointerSensor,
15
+ useSensor,
16
+ useSensors,
17
+ } from "@dnd-kit/core"
18
+ import {
19
+ arrayMove,
20
+ rectSortingStrategy,
21
+ SortableContext,
22
+ sortableKeyboardCoordinates,
23
+ useSortable,
24
+ } from "@dnd-kit/sortable"
25
+ import { CSS } from "@dnd-kit/utilities"
26
+ import { Bar, BarChart, CartesianGrid, Cell, Pie, PieChart, XAxis, YAxis } from "recharts"
27
+ import { ChartCard, ChartDataTable, ChartFigure, type ChartLeoInsight } from "@/components/charts-overview"
28
+ import { useChartVariant } from "@/contexts/chart-variant-context"
29
+ import { KeyMetrics, type MetricInsight, type MetricItem } from "@/components/key-metrics"
30
+ import { Button } from "@/components/ui/button"
31
+ import {
32
+ DropdownMenu,
33
+ DropdownMenuContent,
34
+ DropdownMenuItem,
35
+ DropdownMenuTrigger,
36
+ } from "@/components/ui/dropdown-menu"
37
+ import { ViewSegmentedControl } from "@/components/ui/view-segmented-control"
38
+ import { Tip } from "@/components/ui/tip"
39
+ import { DragHandleGripIcon } from "@/components/ui/drag-handle-grip"
40
+ import {
41
+ ChartContainer,
42
+ ChartTooltip,
43
+ chartTooltipKeyboardSyncProps,
44
+ ChartTooltipContent,
45
+ type ChartConfig,
46
+ } from "@/components/ui/chart"
47
+ import {
48
+ KEY_METRICS_KPI_COUNT_DEFAULT,
49
+ KEY_METRICS_KPI_COUNT_MAX,
50
+ KEY_METRICS_KPI_COUNT_MIN,
51
+ mergeDashboardLayoutGeneric,
52
+ } from "@/lib/dashboard-layout-merge"
53
+ import { cn } from "@/lib/utils"
54
+ import type { TeamMember } from "@/lib/mock/team"
55
+ import {
56
+ KEY_METRICS_CARD_ID,
57
+ applyVisibleReorder,
58
+ type ChartType,
59
+ type DashboardLayout,
60
+ } from "@/components/data-view-dashboard-charts"
61
+ import {
62
+ CHART_KBD_ACTIVE_BAR,
63
+ CHART_KBD_ACTIVE_PIE_SHAPE,
64
+ } from "@/lib/chart-keyboard-selection"
65
+ import {
66
+ loadDataViewLayout,
67
+ saveDataViewLayout,
68
+ } from "@/lib/data-view-dashboard-storage"
69
+
70
+ const STATUS_CHART_CFG: ChartConfig = {
71
+ value: { label: "Members", color: "var(--primary)" },
72
+ }
73
+
74
+ const ROLE_CHART_CFG: ChartConfig = {
75
+ value: { label: "Members", color: "var(--primary)" },
76
+ }
77
+
78
+ interface TeamDashboardCardDef {
79
+ id: string
80
+ title: string
81
+ description: string
82
+ defaultSpan: 1 | 2
83
+ defaultChartType: ChartType
84
+ chartTypes: { type: ChartType; label: string; icon: string }[]
85
+ }
86
+
87
+ export const ALL_TEAM_DASHBOARD_CARDS: TeamDashboardCardDef[] = [
88
+ {
89
+ id: KEY_METRICS_CARD_ID,
90
+ title: "Key metrics",
91
+ description: "Summary KPIs for the filtered roster",
92
+ defaultSpan: 2,
93
+ defaultChartType: "bar",
94
+ chartTypes: [],
95
+ },
96
+ {
97
+ id: "team-by-status",
98
+ title: "Members by status",
99
+ description: "Active, away, and invited in this view",
100
+ defaultSpan: 1,
101
+ defaultChartType: "bar",
102
+ chartTypes: [
103
+ { type: "bar", label: "Bar", icon: "fa-light fa-chart-bar" },
104
+ { type: "horizontal-bar", label: "Horizontal Bar", icon: "fa-light fa-chart-bar fa-rotate-90" },
105
+ { type: "pie", label: "Donut", icon: "fa-light fa-chart-pie" },
106
+ ],
107
+ },
108
+ {
109
+ id: "team-by-role",
110
+ title: "Members by role",
111
+ description: "Top roles in the filtered roster",
112
+ defaultSpan: 1,
113
+ defaultChartType: "horizontal-bar",
114
+ chartTypes: [
115
+ { type: "horizontal-bar", label: "Horizontal Bar", icon: "fa-light fa-chart-bar fa-rotate-90" },
116
+ { type: "bar", label: "Bar", icon: "fa-light fa-chart-bar" },
117
+ { type: "pie", label: "Donut", icon: "fa-light fa-chart-pie" },
118
+ ],
119
+ },
120
+ ]
121
+
122
+ export const DEFAULT_TEAM_VISIBLE_CARDS = ALL_TEAM_DASHBOARD_CARDS.map(c => c.id)
123
+ export const DEFAULT_TEAM_SPANS: Record<string, 1 | 2> = Object.fromEntries(
124
+ ALL_TEAM_DASHBOARD_CARDS.map(c => [c.id, c.defaultSpan]),
125
+ )
126
+ export const DEFAULT_TEAM_CHART_TYPES: Record<string, ChartType> = Object.fromEntries(
127
+ ALL_TEAM_DASHBOARD_CARDS.map(c => [c.id, c.defaultChartType]),
128
+ )
129
+
130
+ const TEAM_CHART_LEO_INSIGHTS: Partial<Record<string, ChartLeoInsight>> = {
131
+ "team-by-status": {
132
+ headline: "Invited members may be waiting on acceptance",
133
+ explanation:
134
+ "A noticeable invited slice often means stale invites or slow onboarding. Clearing or re-sending can tighten roster accuracy for permissions and assignments.",
135
+ },
136
+ "team-by-role": {
137
+ headline: "A few roles carry most of the roster",
138
+ explanation:
139
+ "When bars skew toward a small set of roles, turnover in those groups has an outsized impact. Leo can suggest backup owners or cross-training patterns to reduce single points of failure.",
140
+ },
141
+ }
142
+
143
+ export function loadTeamDashboardLayout(): DashboardLayout | null {
144
+ const v = loadDataViewLayout("team")
145
+ if (!v) return null
146
+ return {
147
+ visible: v.visible,
148
+ order: v.order,
149
+ spans: v.spans,
150
+ chartTypes: v.chartTypes as Record<string, ChartType> | undefined,
151
+ keyMetricsKpiCount: v.keyMetricsKpiCount,
152
+ }
153
+ }
154
+
155
+ export function mergeTeamDashboardLayout(saved: DashboardLayout | null): DashboardLayout {
156
+ const defaults = {
157
+ visible: [...DEFAULT_TEAM_VISIBLE_CARDS],
158
+ order: ALL_TEAM_DASHBOARD_CARDS.map(c => c.id),
159
+ spans: { ...DEFAULT_TEAM_SPANS },
160
+ chartTypes: { ...DEFAULT_TEAM_CHART_TYPES } as Record<string, string>,
161
+ keyMetricsKpiCount: KEY_METRICS_KPI_COUNT_DEFAULT,
162
+ }
163
+ const ids = ALL_TEAM_DASHBOARD_CARDS.map(c => c.id)
164
+ const m = mergeDashboardLayoutGeneric(saved, defaults, ids)
165
+ return {
166
+ visible: m.visible,
167
+ order: m.order,
168
+ spans: m.spans as Record<string, 1 | 2>,
169
+ chartTypes: m.chartTypes as Record<string, ChartType>,
170
+ keyMetricsKpiCount: m.keyMetricsKpiCount,
171
+ }
172
+ }
173
+
174
+ export function saveTeamDashboardLayout(layout: DashboardLayout) {
175
+ saveDataViewLayout("team", {
176
+ visible: layout.visible,
177
+ order: layout.order,
178
+ spans: layout.spans,
179
+ chartTypes: layout.chartTypes as Record<string, string> | undefined,
180
+ keyMetricsKpiCount: layout.keyMetricsKpiCount,
181
+ })
182
+ }
183
+
184
+ function EmptyChart({ message = "No team members match the current filters." }: { message?: string }) {
185
+ return (
186
+ <div className="flex h-[200px] items-center justify-center text-sm text-muted-foreground" role="status">
187
+ {message}
188
+ </div>
189
+ )
190
+ }
191
+
192
+ function TeamByStatusChart({ members, chartType }: { members: TeamMember[]; chartType: ChartType }) {
193
+ const byStatus = React.useMemo(() => {
194
+ let active = 0
195
+ let away = 0
196
+ let invited = 0
197
+ for (const m of members) {
198
+ if (m.status === "active") active++
199
+ else if (m.status === "away") away++
200
+ else invited++
201
+ }
202
+ return [
203
+ { name: "Active", value: active },
204
+ { name: "Away", value: away },
205
+ { name: "Invited", value: invited },
206
+ ]
207
+ }, [members])
208
+
209
+ if (members.length === 0) return <EmptyChart />
210
+
211
+ const statusSummary = `Roster distribution: ${byStatus.map(d => `${d.name} ${d.value}`).join(", ")}. Total ${members.length} members.`
212
+
213
+ if (chartType === "pie") {
214
+ return (
215
+ <ChartFigure label="Members by status" summary={statusSummary} dataLength={byStatus.length}>
216
+ {(activeIndex) => (
217
+ <>
218
+ <ChartContainer config={STATUS_CHART_CFG} className="mx-auto aspect-square max-h-[220px] w-full">
219
+ <PieChart>
220
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
221
+ <Pie
222
+ data={byStatus}
223
+ dataKey="value"
224
+ nameKey="name"
225
+ innerRadius={48}
226
+ outerRadius={80}
227
+ strokeWidth={2}
228
+ stroke="var(--card)"
229
+ activeIndex={activeIndex ?? undefined}
230
+ activeShape={CHART_KBD_ACTIVE_PIE_SHAPE}
231
+ >
232
+ {byStatus.map((_, i) => (
233
+ <Cell
234
+ key={i}
235
+ fill={i === 0 ? "var(--color-chart-2)" : i === 1 ? "var(--color-chart-3)" : "var(--color-chart-4)"}
236
+ />
237
+ ))}
238
+ </Pie>
239
+ </PieChart>
240
+ </ChartContainer>
241
+ <ChartDataTable
242
+ caption="Members by status"
243
+ headers={["Status", "Members"]}
244
+ rows={byStatus.map(d => [d.name, d.value])}
245
+ />
246
+ </>
247
+ )}
248
+ </ChartFigure>
249
+ )
250
+ }
251
+
252
+ if (chartType === "horizontal-bar") {
253
+ return (
254
+ <ChartFigure label="Members by status" summary={statusSummary} dataLength={byStatus.length}>
255
+ {(activeIndex) => (
256
+ <>
257
+ <ChartContainer config={STATUS_CHART_CFG} className="h-[220px] w-full">
258
+ <BarChart data={byStatus} layout="vertical" margin={{ top: 8, right: 8, left: 0, bottom: 0 }}>
259
+ <CartesianGrid horizontal={false} strokeDasharray="3 3" className="stroke-border" />
260
+ <XAxis type="number" allowDecimals={false} tick={{ fontSize: 12 }} tickLine={false} axisLine={false} />
261
+ <YAxis type="category" dataKey="name" width={72} tick={{ fontSize: 12 }} tickLine={false} axisLine={false} />
262
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
263
+ <Bar
264
+ dataKey="value"
265
+ fill="var(--color-chart-2)"
266
+ radius={[0, 4, 4, 0]}
267
+ maxBarSize={22}
268
+ activeBar={CHART_KBD_ACTIVE_BAR}
269
+ activeIndex={activeIndex ?? undefined}
270
+ >
271
+ {byStatus.map((_, i) => (
272
+ <Cell key={i} fill="var(--color-chart-2)" />
273
+ ))}
274
+ </Bar>
275
+ </BarChart>
276
+ </ChartContainer>
277
+ <ChartDataTable
278
+ caption="Members by status"
279
+ headers={["Status", "Members"]}
280
+ rows={byStatus.map(d => [d.name, d.value])}
281
+ />
282
+ </>
283
+ )}
284
+ </ChartFigure>
285
+ )
286
+ }
287
+
288
+ return (
289
+ <ChartFigure label="Members by status" summary={statusSummary} dataLength={byStatus.length}>
290
+ {(activeIndex) => (
291
+ <>
292
+ <ChartContainer config={STATUS_CHART_CFG} className="h-[220px] w-full">
293
+ <BarChart data={byStatus} margin={{ top: 8, right: 8, left: 0, bottom: 0 }}>
294
+ <CartesianGrid vertical={false} strokeDasharray="3 3" className="stroke-border" />
295
+ <XAxis dataKey="name" tick={{ fontSize: 12 }} tickLine={false} axisLine={false} />
296
+ <YAxis allowDecimals={false} width={36} tick={{ fontSize: 12 }} tickLine={false} axisLine={false} />
297
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
298
+ <Bar
299
+ dataKey="value"
300
+ fill="var(--color-chart-2)"
301
+ radius={[4, 4, 0, 0]}
302
+ maxBarSize={48}
303
+ activeBar={CHART_KBD_ACTIVE_BAR}
304
+ activeIndex={activeIndex ?? undefined}
305
+ >
306
+ {byStatus.map((_, i) => (
307
+ <Cell key={i} fill="var(--color-chart-2)" />
308
+ ))}
309
+ </Bar>
310
+ </BarChart>
311
+ </ChartContainer>
312
+ <ChartDataTable
313
+ caption="Members by status"
314
+ headers={["Status", "Members"]}
315
+ rows={byStatus.map(d => [d.name, d.value])}
316
+ />
317
+ </>
318
+ )}
319
+ </ChartFigure>
320
+ )
321
+ }
322
+
323
+ function TeamByRoleChart({ members, chartType }: { members: TeamMember[]; chartType: ChartType }) {
324
+ const byRole = React.useMemo(() => {
325
+ const map = new Map<string, number>()
326
+ for (const m of members) map.set(m.role, (map.get(m.role) ?? 0) + 1)
327
+ return [...map.entries()]
328
+ .map(([name, value]) => ({
329
+ name: name.length > 28 ? `${name.slice(0, 26)}…` : name,
330
+ value,
331
+ }))
332
+ .sort((a, b) => b.value - a.value)
333
+ .slice(0, 10)
334
+ }, [members])
335
+
336
+ if (members.length === 0) return <EmptyChart />
337
+
338
+ const roleSummary = `Top ${byRole.length} roles by member count.`
339
+
340
+ if (chartType === "pie") {
341
+ return (
342
+ <ChartFigure label="Members by role" summary={roleSummary} dataLength={byRole.length}>
343
+ {(activeIndex) => (
344
+ <>
345
+ <ChartContainer config={ROLE_CHART_CFG} className="mx-auto aspect-square max-h-[220px] w-full">
346
+ <PieChart>
347
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
348
+ <Pie
349
+ data={byRole}
350
+ dataKey="value"
351
+ nameKey="name"
352
+ innerRadius={48}
353
+ outerRadius={80}
354
+ strokeWidth={2}
355
+ stroke="var(--card)"
356
+ activeIndex={activeIndex ?? undefined}
357
+ activeShape={CHART_KBD_ACTIVE_PIE_SHAPE}
358
+ >
359
+ {byRole.map((_, i) => (
360
+ <Cell
361
+ key={i}
362
+ fill={["var(--color-chart-1)", "var(--color-chart-2)", "var(--color-chart-3)", "var(--color-chart-4)", "var(--color-chart-5)"][i % 5]}
363
+ />
364
+ ))}
365
+ </Pie>
366
+ </PieChart>
367
+ </ChartContainer>
368
+ <ChartDataTable
369
+ caption="Members by role"
370
+ headers={["Role", "Members"]}
371
+ rows={byRole.map(d => [d.name, d.value])}
372
+ />
373
+ </>
374
+ )}
375
+ </ChartFigure>
376
+ )
377
+ }
378
+
379
+ if (chartType === "bar") {
380
+ return (
381
+ <ChartFigure label="Members by role" summary={roleSummary} dataLength={byRole.length}>
382
+ {(activeIndex) => (
383
+ <>
384
+ <ChartContainer config={ROLE_CHART_CFG} className="h-[220px] w-full">
385
+ <BarChart data={byRole} margin={{ top: 8, right: 8, left: 0, bottom: 0 }}>
386
+ <CartesianGrid vertical={false} strokeDasharray="3 3" className="stroke-border" />
387
+ <XAxis dataKey="name" tick={{ fontSize: 11 }} tickLine={false} axisLine={false} />
388
+ <YAxis allowDecimals={false} width={32} tick={{ fontSize: 12 }} tickLine={false} axisLine={false} />
389
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
390
+ <Bar
391
+ dataKey="value"
392
+ fill="var(--color-chart-4)"
393
+ radius={[4, 4, 0, 0]}
394
+ maxBarSize={40}
395
+ activeBar={CHART_KBD_ACTIVE_BAR}
396
+ activeIndex={activeIndex ?? undefined}
397
+ >
398
+ {byRole.map((_, i) => (
399
+ <Cell key={i} fill="var(--color-chart-4)" />
400
+ ))}
401
+ </Bar>
402
+ </BarChart>
403
+ </ChartContainer>
404
+ <ChartDataTable
405
+ caption="Members by role"
406
+ headers={["Role", "Members"]}
407
+ rows={byRole.map(d => [d.name, d.value])}
408
+ />
409
+ </>
410
+ )}
411
+ </ChartFigure>
412
+ )
413
+ }
414
+
415
+ return (
416
+ <ChartFigure label="Members by role" summary={roleSummary} dataLength={byRole.length}>
417
+ {(activeIndex) => (
418
+ <>
419
+ <ChartContainer config={ROLE_CHART_CFG} className="h-[220px] w-full">
420
+ <BarChart data={byRole} layout="vertical" margin={{ top: 8, right: 8, left: 4, bottom: 0 }}>
421
+ <CartesianGrid horizontal={false} strokeDasharray="3 3" className="stroke-border" />
422
+ <XAxis type="number" allowDecimals={false} tick={{ fontSize: 12 }} tickLine={false} axisLine={false} />
423
+ <YAxis type="category" dataKey="name" width={120} tick={{ fontSize: 11 }} tickLine={false} axisLine={false} />
424
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
425
+ <Bar
426
+ dataKey="value"
427
+ fill="var(--color-chart-4)"
428
+ radius={[0, 4, 4, 0]}
429
+ maxBarSize={22}
430
+ activeBar={CHART_KBD_ACTIVE_BAR}
431
+ activeIndex={activeIndex ?? undefined}
432
+ >
433
+ {byRole.map((_, i) => (
434
+ <Cell key={i} fill="var(--color-chart-4)" />
435
+ ))}
436
+ </Bar>
437
+ </BarChart>
438
+ </ChartContainer>
439
+ <ChartDataTable
440
+ caption="Members by role"
441
+ headers={["Role", "Members"]}
442
+ rows={byRole.map(d => [d.name, d.value])}
443
+ />
444
+ </>
445
+ )}
446
+ </ChartFigure>
447
+ )
448
+ }
449
+
450
+ const TEAM_CHART_RENDERERS: Record<string, React.FC<{ members: TeamMember[]; chartType: ChartType }>> = {
451
+ "team-by-status": TeamByStatusChart,
452
+ "team-by-role": TeamByRoleChart,
453
+ }
454
+
455
+ function SortableTeamDashboardCard({
456
+ card,
457
+ members,
458
+ span,
459
+ chartType,
460
+ cardIndex,
461
+ totalCards,
462
+ onSpanChange,
463
+ onChartTypeChange,
464
+ onRemove,
465
+ onMoveStep,
466
+ keyMetrics,
467
+ keyMetricsKpiCount,
468
+ onKeyMetricsKpiCountChange,
469
+ }: {
470
+ card: TeamDashboardCardDef
471
+ members: TeamMember[]
472
+ span: 1 | 2
473
+ chartType: ChartType
474
+ cardIndex: number
475
+ totalCards: number
476
+ onSpanChange: (id: string, span: 1 | 2) => void
477
+ onChartTypeChange: (id: string, t: ChartType) => void
478
+ onRemove: (id: string) => void
479
+ onMoveStep: (direction: -1 | 1) => void
480
+ keyMetrics?: { metrics: MetricItem[]; insight: MetricInsight } | null
481
+ keyMetricsKpiCount: number
482
+ onKeyMetricsKpiCountChange?: (n: number) => void
483
+ }) {
484
+ const {
485
+ attributes,
486
+ listeners,
487
+ setNodeRef,
488
+ setActivatorNodeRef,
489
+ transform,
490
+ transition,
491
+ isDragging,
492
+ } = useSortable({ id: card.id })
493
+ const { chartVariant } = useChartVariant()
494
+
495
+ const style: React.CSSProperties = {
496
+ ...(transform ? { transform: CSS.Transform.toString(transform) } : {}),
497
+ transition,
498
+ }
499
+
500
+ const isKeyMetrics = card.id === KEY_METRICS_CARD_ID
501
+ const Renderer = isKeyMetrics ? null : TEAM_CHART_RENDERERS[card.id]
502
+ if (!isKeyMetrics && !Renderer) return null
503
+ if (isKeyMetrics && !keyMetrics) return null
504
+
505
+ const canMoveEarlier = cardIndex > 0
506
+ const canMoveLater = cardIndex < totalCards - 1
507
+ const chartLeoInsight = TEAM_CHART_LEO_INSIGHTS[card.id]
508
+
509
+ return (
510
+ <div
511
+ ref={setNodeRef}
512
+ style={style}
513
+ className={cn(
514
+ "group flex min-h-0 w-full min-w-0 flex-col self-start rounded-xl border-2 border-dashed border-border bg-transparent p-2",
515
+ span === 2 ? "lg:col-span-2" : undefined,
516
+ isDragging && "z-20 opacity-95 ring-2 ring-ring",
517
+ )}
518
+ >
519
+ <div className="mb-2 flex w-full min-w-0 flex-wrap items-center gap-2" role="toolbar" aria-label={`${card.title} layout controls`}>
520
+ <div className="flex min-w-0 flex-1 flex-wrap items-center gap-2">
521
+ <Tip label="Drag to reorder" side="top">
522
+ <button
523
+ type="button"
524
+ ref={setActivatorNodeRef}
525
+ className="inline-flex size-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
526
+ aria-label={`Drag to reorder ${card.title}`}
527
+ {...attributes}
528
+ {...listeners}
529
+ >
530
+ <DragHandleGripIcon className="text-[15px]" />
531
+ </button>
532
+ </Tip>
533
+ {card.chartTypes.length > 0 ? (
534
+ <ViewSegmentedControl
535
+ aria-label={`Chart type for ${card.title}`}
536
+ iconOnly
537
+ value={chartType}
538
+ onValueChange={v => onChartTypeChange(card.id, v as ChartType)}
539
+ options={card.chartTypes.map(opt => ({
540
+ value: opt.type,
541
+ label: opt.label,
542
+ icon: opt.icon,
543
+ }))}
544
+ />
545
+ ) : null}
546
+ {isKeyMetrics && onKeyMetricsKpiCountChange ? (
547
+ <ViewSegmentedControl
548
+ aria-label="Number of KPIs to show"
549
+ iconOnly={false}
550
+ value={String(keyMetricsKpiCount)}
551
+ onValueChange={v => onKeyMetricsKpiCountChange(Number(v))}
552
+ options={Array.from(
553
+ { length: KEY_METRICS_KPI_COUNT_MAX - KEY_METRICS_KPI_COUNT_MIN + 1 },
554
+ (_, i) => {
555
+ const n = KEY_METRICS_KPI_COUNT_MIN + i
556
+ return { value: String(n), label: String(n) }
557
+ },
558
+ )}
559
+ />
560
+ ) : null}
561
+ <ViewSegmentedControl
562
+ aria-label={`Width for ${card.title}`}
563
+ iconOnly
564
+ value={String(span) as "1" | "2"}
565
+ onValueChange={v => onSpanChange(card.id, Number(v) as 1 | 2)}
566
+ options={[
567
+ { value: "1", label: "Half width", icon: "fa-light fa-table-columns" },
568
+ { value: "2", label: "Full width (all columns)", icon: "fa-light fa-maximize" },
569
+ ]}
570
+ />
571
+ </div>
572
+ <div className="ml-auto flex shrink-0 items-center gap-1">
573
+ <div
574
+ className="pointer-events-none flex items-center gap-0.5 opacity-0 transition-opacity duration-150 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100"
575
+ role="group"
576
+ aria-label={`Reorder ${card.title}`}
577
+ >
578
+ <div className="flex items-center gap-0.5 lg:hidden">
579
+ <Tip label="Move up" side="top">
580
+ <Button
581
+ type="button"
582
+ variant="ghost"
583
+ size="icon-sm"
584
+ className="size-7 shrink-0"
585
+ disabled={!canMoveEarlier}
586
+ aria-label={`Move ${card.title} up`}
587
+ onClick={() => onMoveStep(-1)}
588
+ >
589
+ <i className="fa-light fa-chevron-up text-xs" aria-hidden="true" />
590
+ </Button>
591
+ </Tip>
592
+ <Tip label="Move down" side="top">
593
+ <Button
594
+ type="button"
595
+ variant="ghost"
596
+ size="icon-sm"
597
+ className="size-7 shrink-0"
598
+ disabled={!canMoveLater}
599
+ aria-label={`Move ${card.title} down`}
600
+ onClick={() => onMoveStep(1)}
601
+ >
602
+ <i className="fa-light fa-chevron-down text-xs" aria-hidden="true" />
603
+ </Button>
604
+ </Tip>
605
+ </div>
606
+ <div className="hidden items-center gap-0.5 lg:flex">
607
+ <Tip label="Move left" side="top">
608
+ <Button
609
+ type="button"
610
+ variant="ghost"
611
+ size="icon-sm"
612
+ className="size-7 shrink-0"
613
+ disabled={!canMoveEarlier}
614
+ aria-label={`Move ${card.title} left`}
615
+ onClick={() => onMoveStep(-1)}
616
+ >
617
+ <i className="fa-light fa-chevron-left text-xs" aria-hidden="true" />
618
+ </Button>
619
+ </Tip>
620
+ <Tip label="Move right" side="top">
621
+ <Button
622
+ type="button"
623
+ variant="ghost"
624
+ size="icon-sm"
625
+ className="size-7 shrink-0"
626
+ disabled={!canMoveLater}
627
+ aria-label={`Move ${card.title} right`}
628
+ onClick={() => onMoveStep(1)}
629
+ >
630
+ <i className="fa-light fa-chevron-right text-xs" aria-hidden="true" />
631
+ </Button>
632
+ </Tip>
633
+ </div>
634
+ </div>
635
+ <Tip label={`Remove ${card.title}`} side="top">
636
+ <Button
637
+ type="button"
638
+ variant="ghost"
639
+ size="icon-sm"
640
+ className="size-8 shrink-0 text-muted-foreground hover:text-destructive"
641
+ aria-label={`Remove ${card.title} from dashboard`}
642
+ onClick={() => onRemove(card.id)}
643
+ >
644
+ <i className="fa-light fa-trash text-[13px]" aria-hidden="true" />
645
+ </Button>
646
+ </Tip>
647
+ </div>
648
+ </div>
649
+ {isKeyMetrics && keyMetrics ? (
650
+ <KeyMetrics
651
+ variant="card"
652
+ title={card.title}
653
+ description={card.description}
654
+ metrics={keyMetrics.metrics.slice(0, keyMetricsKpiCount)}
655
+ insight={keyMetrics.insight}
656
+ metricsSingleRow
657
+ metricsHalfWidthLayout={span === 1}
658
+ className="w-full min-w-0"
659
+ />
660
+ ) : (
661
+ <ChartCard
662
+ variant={chartVariant}
663
+ title={card.title}
664
+ description={card.description}
665
+ className="!h-auto min-h-0 shrink-0"
666
+ leoInsight={chartLeoInsight}
667
+ >
668
+ {Renderer ? <Renderer members={members} chartType={chartType} /> : null}
669
+ </ChartCard>
670
+ )}
671
+ </div>
672
+ )
673
+ }
674
+
675
+ export interface TeamDashboardChartsSectionProps {
676
+ members: TeamMember[]
677
+ keyMetrics: { metrics: MetricItem[]; insight: MetricInsight }
678
+ visibleCards: string[]
679
+ cardOrder: string[]
680
+ cardSpans?: Record<string, 1 | 2>
681
+ cardChartTypes?: Record<string, ChartType>
682
+ keyMetricsKpiCount?: number
683
+ layoutEditMode?: boolean
684
+ onVisibleChange?: (visible: string[]) => void
685
+ onOrderChange?: (order: string[]) => void
686
+ onSpanChange?: (id: string, span: 1 | 2) => void
687
+ onChartTypeChange?: (id: string, chartType: ChartType) => void
688
+ onKeyMetricsKpiCountChange?: (count: number) => void
689
+ onResetLayout?: () => void
690
+ onLayoutEditDone?: () => void
691
+ onLayoutEditCancel?: () => void
692
+ }
693
+
694
+ export function TeamDashboardChartsSection({
695
+ members,
696
+ keyMetrics,
697
+ visibleCards,
698
+ cardOrder,
699
+ cardSpans = DEFAULT_TEAM_SPANS,
700
+ cardChartTypes = DEFAULT_TEAM_CHART_TYPES,
701
+ keyMetricsKpiCount = KEY_METRICS_KPI_COUNT_DEFAULT,
702
+ layoutEditMode = false,
703
+ onVisibleChange,
704
+ onOrderChange,
705
+ onSpanChange,
706
+ onChartTypeChange,
707
+ onKeyMetricsKpiCountChange,
708
+ onResetLayout,
709
+ onLayoutEditDone,
710
+ onLayoutEditCancel,
711
+ }: TeamDashboardChartsSectionProps) {
712
+ const { chartVariant } = useChartVariant()
713
+ const defs = React.useMemo(() => new Map(ALL_TEAM_DASHBOARD_CARDS.map(c => [c.id, c])), [])
714
+
715
+ const orderedCards = React.useMemo(() => {
716
+ return cardOrder
717
+ .filter(id => visibleCards.includes(id) && defs.has(id))
718
+ .map(id => defs.get(id)!)
719
+ }, [visibleCards, cardOrder, defs])
720
+
721
+ const hiddenCardDefs = React.useMemo(
722
+ () => ALL_TEAM_DASHBOARD_CARDS.filter(c => !visibleCards.includes(c.id)),
723
+ [visibleCards],
724
+ )
725
+
726
+ const sortableIds = React.useMemo(() => orderedCards.map(c => c.id), [orderedCards])
727
+
728
+ const sensors = useSensors(
729
+ useSensor(PointerSensor, { activationConstraint: { distance: 8 } }),
730
+ useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
731
+ )
732
+
733
+ const handleDragEnd = React.useCallback(
734
+ (event: DragEndEvent) => {
735
+ if (!onOrderChange) return
736
+ const { active, over } = event
737
+ if (!over || active.id === over.id) return
738
+ const oldIndex = sortableIds.indexOf(String(active.id))
739
+ const newIndex = sortableIds.indexOf(String(over.id))
740
+ if (oldIndex < 0 || newIndex < 0) return
741
+ const nextVisibleOrder = arrayMove(sortableIds, oldIndex, newIndex)
742
+ const visibleSet = new Set(visibleCards)
743
+ onOrderChange(applyVisibleReorder(cardOrder, visibleSet, nextVisibleOrder))
744
+ },
745
+ [cardOrder, onOrderChange, sortableIds, visibleCards],
746
+ )
747
+
748
+ const moveStep = React.useCallback(
749
+ (id: string, direction: -1 | 1) => {
750
+ if (!onOrderChange) return
751
+ const idx = sortableIds.indexOf(id)
752
+ if (idx < 0) return
753
+ const newIdx = idx + direction
754
+ if (newIdx < 0 || newIdx >= sortableIds.length) return
755
+ const nextVisibleOrder = arrayMove(sortableIds, idx, newIdx)
756
+ const visibleSet = new Set(visibleCards)
757
+ onOrderChange(applyVisibleReorder(cardOrder, visibleSet, nextVisibleOrder))
758
+ },
759
+ [cardOrder, onOrderChange, sortableIds, visibleCards],
760
+ )
761
+
762
+ const addCard = React.useCallback(
763
+ (id: string) => {
764
+ if (!onVisibleChange) return
765
+ if (visibleCards.includes(id)) return
766
+ onVisibleChange([...visibleCards, id])
767
+ },
768
+ [onVisibleChange, visibleCards],
769
+ )
770
+
771
+ const removeCard = React.useCallback(
772
+ (id: string) => {
773
+ if (!onVisibleChange) return
774
+ onVisibleChange(visibleCards.filter(v => v !== id))
775
+ },
776
+ [onVisibleChange, visibleCards],
777
+ )
778
+
779
+ if (orderedCards.length === 0) {
780
+ return (
781
+ <div className="flex flex-col items-center justify-center gap-3 px-4 py-12 text-center lg:px-6">
782
+ <i className="fa-light fa-chart-column text-2xl text-muted-foreground/40" aria-hidden="true" />
783
+ <p className="text-sm text-muted-foreground">
784
+ No widgets on the dashboard.
785
+ {layoutEditMode && hiddenCardDefs.length > 0 ? " Add a widget below." : " Turn on Edit layout and add widgets back."}
786
+ </p>
787
+ {layoutEditMode && hiddenCardDefs.length > 0 && onVisibleChange ? (
788
+ <DropdownMenu>
789
+ <DropdownMenuTrigger asChild>
790
+ <Button type="button" variant="outline" size="sm" className="size-9 p-0" aria-label="Add widget">
791
+ <i className="fa-light fa-plus text-sm" aria-hidden="true" />
792
+ </Button>
793
+ </DropdownMenuTrigger>
794
+ <DropdownMenuContent align="center">
795
+ {hiddenCardDefs.map(c => (
796
+ <DropdownMenuItem key={c.id} onSelect={() => addCard(c.id)}>
797
+ {c.title}
798
+ </DropdownMenuItem>
799
+ ))}
800
+ </DropdownMenuContent>
801
+ </DropdownMenu>
802
+ ) : null}
803
+ </div>
804
+ )
805
+ }
806
+
807
+ const grid = (
808
+ <div
809
+ className={cn(
810
+ "grid grid-cols-1 gap-4 lg:grid-cols-2",
811
+ layoutEditMode && "lg:items-start lg:content-start lg:auto-rows-min",
812
+ )}
813
+ >
814
+ {orderedCards.map((card, cardIndex) => {
815
+ const isKeyMetricsCard = card.id === KEY_METRICS_CARD_ID
816
+ const Renderer = isKeyMetricsCard ? null : TEAM_CHART_RENDERERS[card.id]
817
+ if (!isKeyMetricsCard && !Renderer) return null
818
+ const span = cardSpans[card.id] ?? card.defaultSpan
819
+ const requestedType = cardChartTypes[card.id] ?? card.defaultChartType
820
+ const allowedTypes = card.chartTypes.map(o => o.type)
821
+ const chartType =
822
+ allowedTypes.length === 0
823
+ ? card.defaultChartType
824
+ : allowedTypes.includes(requestedType)
825
+ ? requestedType
826
+ : card.defaultChartType
827
+
828
+ if (
829
+ layoutEditMode &&
830
+ onOrderChange &&
831
+ onSpanChange &&
832
+ onChartTypeChange &&
833
+ onVisibleChange
834
+ ) {
835
+ return (
836
+ <SortableTeamDashboardCard
837
+ key={card.id}
838
+ card={card}
839
+ members={members}
840
+ span={span}
841
+ chartType={chartType}
842
+ cardIndex={cardIndex}
843
+ totalCards={orderedCards.length}
844
+ onSpanChange={onSpanChange}
845
+ onChartTypeChange={onChartTypeChange}
846
+ onRemove={removeCard}
847
+ onMoveStep={dir => moveStep(card.id, dir)}
848
+ keyMetrics={isKeyMetricsCard ? keyMetrics : null}
849
+ keyMetricsKpiCount={keyMetricsKpiCount}
850
+ onKeyMetricsKpiCountChange={
851
+ isKeyMetricsCard ? onKeyMetricsKpiCountChange : undefined
852
+ }
853
+ />
854
+ )
855
+ }
856
+
857
+ return (
858
+ <div
859
+ key={card.id}
860
+ className={cn(span === 2 ? "lg:col-span-2" : undefined)}
861
+ >
862
+ {isKeyMetricsCard ? (
863
+ <KeyMetrics
864
+ variant="card"
865
+ title={card.title}
866
+ description={card.description}
867
+ metrics={keyMetrics.metrics.slice(0, keyMetricsKpiCount)}
868
+ insight={keyMetrics.insight}
869
+ metricsSingleRow
870
+ metricsHalfWidthLayout={span === 1}
871
+ className="w-full min-w-0"
872
+ />
873
+ ) : (
874
+ <ChartCard
875
+ variant={chartVariant}
876
+ title={card.title}
877
+ description={card.description}
878
+ leoInsight={TEAM_CHART_LEO_INSIGHTS[card.id]}
879
+ >
880
+ {Renderer ? <Renderer members={members} chartType={chartType} /> : null}
881
+ </ChartCard>
882
+ )}
883
+ </div>
884
+ )
885
+ })}
886
+ </div>
887
+ )
888
+
889
+ const editToolbar =
890
+ layoutEditMode && onVisibleChange && onResetLayout ? (
891
+ <div
892
+ className="mb-3 flex flex-wrap items-center justify-between gap-3 rounded-lg border border-border bg-transparent px-3 py-2"
893
+ role="region"
894
+ aria-label="Dashboard layout options"
895
+ >
896
+ <p className="text-xs text-muted-foreground">Drag cards to reorder. Changes save automatically.</p>
897
+ <div className="flex flex-wrap items-center justify-end gap-2">
898
+ <Button
899
+ type="button"
900
+ size="sm"
901
+ variant="ghost"
902
+ className="h-8 text-xs"
903
+ onClick={() => onVisibleChange(ALL_TEAM_DASHBOARD_CARDS.map(c => c.id))}
904
+ >
905
+ Show all
906
+ </Button>
907
+ <Button type="button" size="sm" variant="ghost" className="h-8 text-xs" onClick={() => onVisibleChange([])}>
908
+ Hide all
909
+ </Button>
910
+ <Tip side="bottom" label="Reset visibility, order, widths, and chart types">
911
+ <Button type="button" size="sm" variant="ghost" className="h-8 px-2 text-xs" onClick={onResetLayout}>
912
+ <i className="fa-light fa-rotate-left mr-1 text-xs" aria-hidden="true" />
913
+ Reset
914
+ </Button>
915
+ </Tip>
916
+ {hiddenCardDefs.length > 0 ? (
917
+ <DropdownMenu>
918
+ <DropdownMenuTrigger asChild>
919
+ <Button type="button" variant="outline" size="sm" className="size-8 p-0" aria-label="Add widget">
920
+ <i className="fa-light fa-plus text-[13px]" aria-hidden="true" />
921
+ </Button>
922
+ </DropdownMenuTrigger>
923
+ <DropdownMenuContent align="end">
924
+ {hiddenCardDefs.map(c => (
925
+ <DropdownMenuItem key={c.id} onSelect={() => addCard(c.id)}>
926
+ {c.title}
927
+ </DropdownMenuItem>
928
+ ))}
929
+ </DropdownMenuContent>
930
+ </DropdownMenu>
931
+ ) : null}
932
+ {onLayoutEditCancel ? (
933
+ <Button type="button" size="sm" variant="outline" className="h-8 text-xs" onClick={onLayoutEditCancel}>
934
+ Cancel
935
+ </Button>
936
+ ) : null}
937
+ {onLayoutEditDone ? (
938
+ <Button type="button" size="sm" className="h-8 text-xs" onClick={onLayoutEditDone}>
939
+ Done
940
+ </Button>
941
+ ) : null}
942
+ </div>
943
+ </div>
944
+ ) : null
945
+
946
+ const gridBody =
947
+ layoutEditMode && onOrderChange ? (
948
+ <DndContext sensors={sensors} collisionDetection={closestCorners} onDragEnd={handleDragEnd}>
949
+ <SortableContext items={sortableIds} strategy={rectSortingStrategy}>
950
+ {grid}
951
+ </SortableContext>
952
+ </DndContext>
953
+ ) : (
954
+ grid
955
+ )
956
+
957
+ return (
958
+ <div
959
+ className={cn(
960
+ "flex flex-col gap-4 px-4 pb-2 lg:px-6",
961
+ layoutEditMode && "rounded-xl border border-dashed border-border/80 bg-transparent py-3",
962
+ )}
963
+ >
964
+ {editToolbar}
965
+ {gridBody}
966
+ </div>
967
+ )
968
+ }