@exxatdesignux/ui 0.0.6 → 0.0.8

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,960 @@
1
+ "use client"
2
+
3
+ /**
4
+ * Compliance **Data** view dashboard — filtered compliance rows with the same canvas as Placements/Team.
5
+ */
6
+
7
+ import * as React from "react"
8
+ import {
9
+ closestCorners,
10
+ DndContext,
11
+ type DragEndEvent,
12
+ KeyboardSensor,
13
+ PointerSensor,
14
+ useSensor,
15
+ useSensors,
16
+ } from "@dnd-kit/core"
17
+ import {
18
+ arrayMove,
19
+ rectSortingStrategy,
20
+ SortableContext,
21
+ sortableKeyboardCoordinates,
22
+ useSortable,
23
+ } from "@dnd-kit/sortable"
24
+ import { CSS } from "@dnd-kit/utilities"
25
+ import { Bar, BarChart, CartesianGrid, Cell, Pie, PieChart, XAxis, YAxis } from "recharts"
26
+ import { ChartCard, ChartDataTable, ChartFigure, type ChartLeoInsight } from "@/components/charts-overview"
27
+ import { useChartVariant } from "@/contexts/chart-variant-context"
28
+ import { KeyMetrics, type MetricInsight, type MetricItem } from "@/components/key-metrics"
29
+ import { Button } from "@/components/ui/button"
30
+ import {
31
+ DropdownMenu,
32
+ DropdownMenuContent,
33
+ DropdownMenuItem,
34
+ DropdownMenuTrigger,
35
+ } from "@/components/ui/dropdown-menu"
36
+ import { ViewSegmentedControl } from "@/components/ui/view-segmented-control"
37
+ import { Tip } from "@/components/ui/tip"
38
+ import { DragHandleGripIcon } from "@/components/ui/drag-handle-grip"
39
+ import {
40
+ ChartContainer,
41
+ ChartTooltip,
42
+ chartTooltipKeyboardSyncProps,
43
+ ChartTooltipContent,
44
+ type ChartConfig,
45
+ } from "@/components/ui/chart"
46
+ import {
47
+ KEY_METRICS_KPI_COUNT_DEFAULT,
48
+ KEY_METRICS_KPI_COUNT_MAX,
49
+ KEY_METRICS_KPI_COUNT_MIN,
50
+ mergeDashboardLayoutGeneric,
51
+ } from "@/lib/dashboard-layout-merge"
52
+ import { cn } from "@/lib/utils"
53
+ import type { ComplianceItem } from "@/lib/mock/compliance"
54
+ import {
55
+ KEY_METRICS_CARD_ID,
56
+ applyVisibleReorder,
57
+ type ChartType,
58
+ type DashboardLayout,
59
+ } from "@/components/data-view-dashboard-charts"
60
+ import {
61
+ CHART_KBD_ACTIVE_BAR,
62
+ CHART_KBD_ACTIVE_PIE_SHAPE,
63
+ } from "@/lib/chart-keyboard-selection"
64
+ import {
65
+ loadDataViewLayout,
66
+ saveDataViewLayout,
67
+ } from "@/lib/data-view-dashboard-storage"
68
+
69
+ const STATUS_CFG: ChartConfig = {
70
+ value: { label: "Items", color: "var(--primary)" },
71
+ }
72
+
73
+ const CAT_CFG: ChartConfig = {
74
+ value: { label: "Items", color: "var(--primary)" },
75
+ }
76
+
77
+ interface ComplianceDashboardCardDef {
78
+ id: string
79
+ title: string
80
+ description: string
81
+ defaultSpan: 1 | 2
82
+ defaultChartType: ChartType
83
+ chartTypes: { type: ChartType; label: string; icon: string }[]
84
+ }
85
+
86
+ export const ALL_COMPLIANCE_DASHBOARD_CARDS: ComplianceDashboardCardDef[] = [
87
+ {
88
+ id: KEY_METRICS_CARD_ID,
89
+ title: "Key metrics",
90
+ description: "Summary KPIs for filtered obligations",
91
+ defaultSpan: 2,
92
+ defaultChartType: "bar",
93
+ chartTypes: [],
94
+ },
95
+ {
96
+ id: "compliance-by-status",
97
+ title: "Items by status",
98
+ description: "Filtered compliance obligations",
99
+ defaultSpan: 1,
100
+ defaultChartType: "bar",
101
+ chartTypes: [
102
+ { type: "bar", label: "Bar", icon: "fa-light fa-chart-bar" },
103
+ { type: "horizontal-bar", label: "Horizontal Bar", icon: "fa-light fa-chart-bar fa-rotate-90" },
104
+ { type: "pie", label: "Donut", icon: "fa-light fa-chart-pie" },
105
+ ],
106
+ },
107
+ {
108
+ id: "compliance-by-category",
109
+ title: "Items by category",
110
+ description: "Top categories in this view",
111
+ defaultSpan: 1,
112
+ defaultChartType: "horizontal-bar",
113
+ chartTypes: [
114
+ { type: "horizontal-bar", label: "Horizontal Bar", icon: "fa-light fa-chart-bar fa-rotate-90" },
115
+ { type: "bar", label: "Bar", icon: "fa-light fa-chart-bar" },
116
+ { type: "pie", label: "Donut", icon: "fa-light fa-chart-pie" },
117
+ ],
118
+ },
119
+ ]
120
+
121
+ export const DEFAULT_COMPLIANCE_VISIBLE_CARDS = ALL_COMPLIANCE_DASHBOARD_CARDS.map(c => c.id)
122
+ export const DEFAULT_COMPLIANCE_SPANS: Record<string, 1 | 2> = Object.fromEntries(
123
+ ALL_COMPLIANCE_DASHBOARD_CARDS.map(c => [c.id, c.defaultSpan]),
124
+ )
125
+ export const DEFAULT_COMPLIANCE_CHART_TYPES: Record<string, ChartType> = Object.fromEntries(
126
+ ALL_COMPLIANCE_DASHBOARD_CARDS.map(c => [c.id, c.defaultChartType]),
127
+ )
128
+
129
+ const COMPLIANCE_CHART_LEO_INSIGHTS: Partial<Record<string, ChartLeoInsight>> = {
130
+ "compliance-by-status": {
131
+ headline: "Overdue and at-risk items stand out in this mix",
132
+ explanation:
133
+ "When overdue or expiring-soon slices are visible, renewal timing may be out of sync with the cohort. Tightening reminders or batch renewals often reduces last-minute spikes.",
134
+ },
135
+ "compliance-by-category": {
136
+ headline: "Workload clusters in a few categories",
137
+ explanation:
138
+ "Heavy bars in one or two categories usually signal template or training gaps—not random noise. Leo can help outline how to spread load or simplify the noisiest obligation types.",
139
+ },
140
+ }
141
+
142
+ export function loadComplianceDashboardLayout(): DashboardLayout | null {
143
+ const v = loadDataViewLayout("compliance")
144
+ if (!v) return null
145
+ return {
146
+ visible: v.visible,
147
+ order: v.order,
148
+ spans: v.spans,
149
+ chartTypes: v.chartTypes as Record<string, ChartType> | undefined,
150
+ keyMetricsKpiCount: v.keyMetricsKpiCount,
151
+ }
152
+ }
153
+
154
+ export function mergeComplianceDashboardLayout(saved: DashboardLayout | null): DashboardLayout {
155
+ const defaults = {
156
+ visible: [...DEFAULT_COMPLIANCE_VISIBLE_CARDS],
157
+ order: ALL_COMPLIANCE_DASHBOARD_CARDS.map(c => c.id),
158
+ spans: { ...DEFAULT_COMPLIANCE_SPANS },
159
+ chartTypes: { ...DEFAULT_COMPLIANCE_CHART_TYPES } as Record<string, string>,
160
+ keyMetricsKpiCount: KEY_METRICS_KPI_COUNT_DEFAULT,
161
+ }
162
+ const ids = ALL_COMPLIANCE_DASHBOARD_CARDS.map(c => c.id)
163
+ const m = mergeDashboardLayoutGeneric(saved, defaults, ids)
164
+ return {
165
+ visible: m.visible,
166
+ order: m.order,
167
+ spans: m.spans as Record<string, 1 | 2>,
168
+ chartTypes: m.chartTypes as Record<string, ChartType>,
169
+ keyMetricsKpiCount: m.keyMetricsKpiCount,
170
+ }
171
+ }
172
+
173
+ export function saveComplianceDashboardLayout(layout: DashboardLayout) {
174
+ saveDataViewLayout("compliance", {
175
+ visible: layout.visible,
176
+ order: layout.order,
177
+ spans: layout.spans,
178
+ chartTypes: layout.chartTypes as Record<string, string> | undefined,
179
+ keyMetricsKpiCount: layout.keyMetricsKpiCount,
180
+ })
181
+ }
182
+
183
+ function EmptyChart({ message = "No items in this view." }: { message?: string }) {
184
+ return (
185
+ <div className="flex h-[200px] items-center justify-center text-sm text-muted-foreground" role="status">
186
+ {message}
187
+ </div>
188
+ )
189
+ }
190
+
191
+ const PIE_FILLS = [
192
+ "var(--color-chart-1)",
193
+ "var(--color-chart-2)",
194
+ "var(--color-chart-3)",
195
+ "var(--color-chart-4)",
196
+ "var(--color-chart-5)",
197
+ ]
198
+
199
+ function ComplianceByStatusChart({ rows, chartType }: { rows: ComplianceItem[]; chartType: ChartType }) {
200
+ const byStatus = React.useMemo(() => {
201
+ const c = { compliant: 0, due_soon: 0, overdue: 0, pending: 0 }
202
+ for (const r of rows) c[r.status]++
203
+ return [
204
+ { name: "Compliant", value: c.compliant },
205
+ { name: "Due soon", value: c.due_soon },
206
+ { name: "Overdue", value: c.overdue },
207
+ { name: "Pending", value: c.pending },
208
+ ]
209
+ }, [rows])
210
+
211
+ if (rows.length === 0) return <EmptyChart />
212
+
213
+ const statusSummary = `Compliance status: ${byStatus.map(d => `${d.name} ${d.value}`).join(", ")}. Total ${rows.length} items.`
214
+
215
+ if (chartType === "pie") {
216
+ return (
217
+ <ChartFigure label="Items by status" summary={statusSummary} dataLength={byStatus.length}>
218
+ {(activeIndex) => (
219
+ <>
220
+ <ChartContainer config={STATUS_CFG} className="mx-auto aspect-square max-h-[220px] w-full">
221
+ <PieChart>
222
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
223
+ <Pie
224
+ data={byStatus}
225
+ dataKey="value"
226
+ nameKey="name"
227
+ innerRadius={48}
228
+ outerRadius={80}
229
+ strokeWidth={2}
230
+ stroke="var(--card)"
231
+ activeIndex={activeIndex ?? undefined}
232
+ activeShape={CHART_KBD_ACTIVE_PIE_SHAPE}
233
+ >
234
+ {byStatus.map((_, i) => (
235
+ <Cell key={i} fill={PIE_FILLS[i % PIE_FILLS.length]} />
236
+ ))}
237
+ </Pie>
238
+ </PieChart>
239
+ </ChartContainer>
240
+ <ChartDataTable
241
+ caption="Items by status"
242
+ headers={["Status", "Count"]}
243
+ rows={byStatus.map(d => [d.name, d.value])}
244
+ />
245
+ </>
246
+ )}
247
+ </ChartFigure>
248
+ )
249
+ }
250
+
251
+ if (chartType === "horizontal-bar") {
252
+ return (
253
+ <ChartFigure label="Items by status" summary={statusSummary} dataLength={byStatus.length}>
254
+ {(activeIndex) => (
255
+ <>
256
+ <ChartContainer config={STATUS_CFG} className="h-[220px] w-full">
257
+ <BarChart data={byStatus} layout="vertical" margin={{ top: 8, right: 8, left: 0, bottom: 0 }}>
258
+ <CartesianGrid horizontal={false} strokeDasharray="3 3" className="stroke-border" />
259
+ <XAxis type="number" allowDecimals={false} tick={{ fontSize: 11 }} tickLine={false} axisLine={false} />
260
+ <YAxis type="category" dataKey="name" width={88} tick={{ fontSize: 11 }} tickLine={false} axisLine={false} />
261
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
262
+ <Bar
263
+ dataKey="value"
264
+ fill="var(--color-chart-2)"
265
+ radius={[0, 4, 4, 0]}
266
+ maxBarSize={22}
267
+ activeBar={CHART_KBD_ACTIVE_BAR}
268
+ activeIndex={activeIndex ?? undefined}
269
+ >
270
+ {byStatus.map((_, i) => (
271
+ <Cell key={i} fill="var(--color-chart-2)" />
272
+ ))}
273
+ </Bar>
274
+ </BarChart>
275
+ </ChartContainer>
276
+ <ChartDataTable
277
+ caption="Items by status"
278
+ headers={["Status", "Count"]}
279
+ rows={byStatus.map(d => [d.name, d.value])}
280
+ />
281
+ </>
282
+ )}
283
+ </ChartFigure>
284
+ )
285
+ }
286
+
287
+ return (
288
+ <ChartFigure label="Items by status" summary={statusSummary} dataLength={byStatus.length}>
289
+ {(activeIndex) => (
290
+ <>
291
+ <ChartContainer config={STATUS_CFG} className="h-[220px] w-full">
292
+ <BarChart data={byStatus} margin={{ top: 8, right: 8, left: 0, bottom: 0 }}>
293
+ <CartesianGrid vertical={false} strokeDasharray="3 3" className="stroke-border" />
294
+ <XAxis dataKey="name" tick={{ fontSize: 11 }} tickLine={false} axisLine={false} />
295
+ <YAxis allowDecimals={false} width={32} tick={{ fontSize: 12 }} tickLine={false} axisLine={false} />
296
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
297
+ <Bar
298
+ dataKey="value"
299
+ fill="var(--color-chart-2)"
300
+ radius={[4, 4, 0, 0]}
301
+ maxBarSize={40}
302
+ activeBar={CHART_KBD_ACTIVE_BAR}
303
+ activeIndex={activeIndex ?? undefined}
304
+ >
305
+ {byStatus.map((_, i) => (
306
+ <Cell key={i} fill="var(--color-chart-2)" />
307
+ ))}
308
+ </Bar>
309
+ </BarChart>
310
+ </ChartContainer>
311
+ <ChartDataTable
312
+ caption="Items by status"
313
+ headers={["Status", "Count"]}
314
+ rows={byStatus.map(d => [d.name, d.value])}
315
+ />
316
+ </>
317
+ )}
318
+ </ChartFigure>
319
+ )
320
+ }
321
+
322
+ function ComplianceByCategoryChart({ rows, chartType }: { rows: ComplianceItem[]; chartType: ChartType }) {
323
+ const byCategory = React.useMemo(() => {
324
+ const map = new Map<string, number>()
325
+ for (const r of rows) map.set(r.category, (map.get(r.category) ?? 0) + 1)
326
+ return [...map.entries()]
327
+ .map(([name, value]) => ({ name: name.length > 24 ? `${name.slice(0, 22)}…` : name, value }))
328
+ .sort((a, b) => b.value - a.value)
329
+ }, [rows])
330
+
331
+ if (rows.length === 0) return <EmptyChart />
332
+
333
+ const categorySummary = `${byCategory.length} categories. Total ${rows.length} items.`
334
+
335
+ if (chartType === "pie") {
336
+ return (
337
+ <ChartFigure label="Items by category" summary={categorySummary} dataLength={byCategory.length}>
338
+ {(activeIndex) => (
339
+ <>
340
+ <ChartContainer config={CAT_CFG} className="mx-auto aspect-square max-h-[220px] w-full">
341
+ <PieChart>
342
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
343
+ <Pie
344
+ data={byCategory}
345
+ dataKey="value"
346
+ nameKey="name"
347
+ innerRadius={48}
348
+ outerRadius={80}
349
+ strokeWidth={2}
350
+ stroke="var(--card)"
351
+ activeIndex={activeIndex ?? undefined}
352
+ activeShape={CHART_KBD_ACTIVE_PIE_SHAPE}
353
+ >
354
+ {byCategory.map((_, i) => (
355
+ <Cell key={i} fill={PIE_FILLS[i % PIE_FILLS.length]} />
356
+ ))}
357
+ </Pie>
358
+ </PieChart>
359
+ </ChartContainer>
360
+ <ChartDataTable
361
+ caption="Items by category"
362
+ headers={["Category", "Count"]}
363
+ rows={byCategory.map(d => [d.name, d.value])}
364
+ />
365
+ </>
366
+ )}
367
+ </ChartFigure>
368
+ )
369
+ }
370
+
371
+ if (chartType === "bar") {
372
+ return (
373
+ <ChartFigure label="Items by category" summary={categorySummary} dataLength={byCategory.length}>
374
+ {(activeIndex) => (
375
+ <>
376
+ <ChartContainer config={CAT_CFG} className="h-[220px] w-full">
377
+ <BarChart data={byCategory} margin={{ top: 8, right: 8, left: 0, bottom: 0 }}>
378
+ <CartesianGrid vertical={false} strokeDasharray="3 3" className="stroke-border" />
379
+ <XAxis dataKey="name" tick={{ fontSize: 11 }} tickLine={false} axisLine={false} />
380
+ <YAxis allowDecimals={false} width={32} tick={{ fontSize: 12 }} tickLine={false} axisLine={false} />
381
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
382
+ <Bar
383
+ dataKey="value"
384
+ fill="var(--color-chart-4)"
385
+ radius={[4, 4, 0, 0]}
386
+ maxBarSize={40}
387
+ activeBar={CHART_KBD_ACTIVE_BAR}
388
+ activeIndex={activeIndex ?? undefined}
389
+ >
390
+ {byCategory.map((_, i) => (
391
+ <Cell key={i} fill="var(--color-chart-4)" />
392
+ ))}
393
+ </Bar>
394
+ </BarChart>
395
+ </ChartContainer>
396
+ <ChartDataTable
397
+ caption="Items by category"
398
+ headers={["Category", "Count"]}
399
+ rows={byCategory.map(d => [d.name, d.value])}
400
+ />
401
+ </>
402
+ )}
403
+ </ChartFigure>
404
+ )
405
+ }
406
+
407
+ return (
408
+ <ChartFigure label="Items by category" summary={categorySummary} dataLength={byCategory.length}>
409
+ {(activeIndex) => (
410
+ <>
411
+ <ChartContainer config={CAT_CFG} className="h-[220px] w-full">
412
+ <BarChart data={byCategory} layout="vertical" margin={{ top: 8, right: 8, left: 4, bottom: 0 }}>
413
+ <CartesianGrid horizontal={false} strokeDasharray="3 3" className="stroke-border" />
414
+ <XAxis type="number" allowDecimals={false} tick={{ fontSize: 12 }} tickLine={false} axisLine={false} />
415
+ <YAxis type="category" dataKey="name" width={100} tick={{ fontSize: 11 }} tickLine={false} axisLine={false} />
416
+ <ChartTooltip key={chartTooltipKeyboardSyncProps(activeIndex).key} {...chartTooltipKeyboardSyncProps(activeIndex).props} content={<ChartTooltipContent />} />
417
+ <Bar
418
+ dataKey="value"
419
+ fill="var(--color-chart-4)"
420
+ radius={[0, 4, 4, 0]}
421
+ maxBarSize={22}
422
+ activeBar={CHART_KBD_ACTIVE_BAR}
423
+ activeIndex={activeIndex ?? undefined}
424
+ >
425
+ {byCategory.map((_, i) => (
426
+ <Cell key={i} fill="var(--color-chart-4)" />
427
+ ))}
428
+ </Bar>
429
+ </BarChart>
430
+ </ChartContainer>
431
+ <ChartDataTable
432
+ caption="Items by category"
433
+ headers={["Category", "Count"]}
434
+ rows={byCategory.map(d => [d.name, d.value])}
435
+ />
436
+ </>
437
+ )}
438
+ </ChartFigure>
439
+ )
440
+ }
441
+
442
+ const COMPLIANCE_CHART_RENDERERS: Record<string, React.FC<{ rows: ComplianceItem[]; chartType: ChartType }>> = {
443
+ "compliance-by-status": ComplianceByStatusChart,
444
+ "compliance-by-category": ComplianceByCategoryChart,
445
+ }
446
+
447
+ function SortableComplianceDashboardCard({
448
+ card,
449
+ rows,
450
+ span,
451
+ chartType,
452
+ cardIndex,
453
+ totalCards,
454
+ onSpanChange,
455
+ onChartTypeChange,
456
+ onRemove,
457
+ onMoveStep,
458
+ keyMetrics,
459
+ keyMetricsKpiCount,
460
+ onKeyMetricsKpiCountChange,
461
+ }: {
462
+ card: ComplianceDashboardCardDef
463
+ rows: ComplianceItem[]
464
+ span: 1 | 2
465
+ chartType: ChartType
466
+ cardIndex: number
467
+ totalCards: number
468
+ onSpanChange: (id: string, span: 1 | 2) => void
469
+ onChartTypeChange: (id: string, t: ChartType) => void
470
+ onRemove: (id: string) => void
471
+ onMoveStep: (direction: -1 | 1) => void
472
+ keyMetrics?: { metrics: MetricItem[]; insight: MetricInsight } | null
473
+ keyMetricsKpiCount: number
474
+ onKeyMetricsKpiCountChange?: (n: number) => void
475
+ }) {
476
+ const {
477
+ attributes,
478
+ listeners,
479
+ setNodeRef,
480
+ setActivatorNodeRef,
481
+ transform,
482
+ transition,
483
+ isDragging,
484
+ } = useSortable({ id: card.id })
485
+ const { chartVariant } = useChartVariant()
486
+
487
+ const style: React.CSSProperties = {
488
+ ...(transform ? { transform: CSS.Transform.toString(transform) } : {}),
489
+ transition,
490
+ }
491
+
492
+ const isKeyMetrics = card.id === KEY_METRICS_CARD_ID
493
+ const Renderer = isKeyMetrics ? null : COMPLIANCE_CHART_RENDERERS[card.id]
494
+ if (!isKeyMetrics && !Renderer) return null
495
+ if (isKeyMetrics && !keyMetrics) return null
496
+
497
+ const canMoveEarlier = cardIndex > 0
498
+ const canMoveLater = cardIndex < totalCards - 1
499
+ const chartLeoInsight = COMPLIANCE_CHART_LEO_INSIGHTS[card.id]
500
+
501
+ return (
502
+ <div
503
+ ref={setNodeRef}
504
+ style={style}
505
+ className={cn(
506
+ "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",
507
+ span === 2 ? "lg:col-span-2" : undefined,
508
+ isDragging && "z-20 opacity-95 ring-2 ring-ring",
509
+ )}
510
+ >
511
+ <div className="mb-2 flex w-full min-w-0 flex-wrap items-center gap-2" role="toolbar" aria-label={`${card.title} layout controls`}>
512
+ <div className="flex min-w-0 flex-1 flex-wrap items-center gap-2">
513
+ <Tip label="Drag to reorder" side="top">
514
+ <button
515
+ type="button"
516
+ ref={setActivatorNodeRef}
517
+ 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"
518
+ aria-label={`Drag to reorder ${card.title}`}
519
+ {...attributes}
520
+ {...listeners}
521
+ >
522
+ <DragHandleGripIcon className="text-[15px]" />
523
+ </button>
524
+ </Tip>
525
+ {card.chartTypes.length > 0 ? (
526
+ <ViewSegmentedControl
527
+ aria-label={`Chart type for ${card.title}`}
528
+ iconOnly
529
+ value={chartType}
530
+ onValueChange={v => onChartTypeChange(card.id, v as ChartType)}
531
+ options={card.chartTypes.map(opt => ({
532
+ value: opt.type,
533
+ label: opt.label,
534
+ icon: opt.icon,
535
+ }))}
536
+ />
537
+ ) : null}
538
+ {isKeyMetrics && onKeyMetricsKpiCountChange ? (
539
+ <ViewSegmentedControl
540
+ aria-label="Number of KPIs to show"
541
+ iconOnly={false}
542
+ value={String(keyMetricsKpiCount)}
543
+ onValueChange={v => onKeyMetricsKpiCountChange(Number(v))}
544
+ options={Array.from(
545
+ { length: KEY_METRICS_KPI_COUNT_MAX - KEY_METRICS_KPI_COUNT_MIN + 1 },
546
+ (_, i) => {
547
+ const n = KEY_METRICS_KPI_COUNT_MIN + i
548
+ return { value: String(n), label: String(n) }
549
+ },
550
+ )}
551
+ />
552
+ ) : null}
553
+ <ViewSegmentedControl
554
+ aria-label={`Width for ${card.title}`}
555
+ iconOnly
556
+ value={String(span) as "1" | "2"}
557
+ onValueChange={v => onSpanChange(card.id, Number(v) as 1 | 2)}
558
+ options={[
559
+ { value: "1", label: "Half width", icon: "fa-light fa-table-columns" },
560
+ { value: "2", label: "Full width (all columns)", icon: "fa-light fa-maximize" },
561
+ ]}
562
+ />
563
+ </div>
564
+ <div className="ml-auto flex shrink-0 items-center gap-1">
565
+ <div
566
+ 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"
567
+ role="group"
568
+ aria-label={`Reorder ${card.title}`}
569
+ >
570
+ <div className="flex items-center gap-0.5 lg:hidden">
571
+ <Tip label="Move up" side="top">
572
+ <Button
573
+ type="button"
574
+ variant="ghost"
575
+ size="icon-sm"
576
+ className="size-7 shrink-0"
577
+ disabled={!canMoveEarlier}
578
+ aria-label={`Move ${card.title} up`}
579
+ onClick={() => onMoveStep(-1)}
580
+ >
581
+ <i className="fa-light fa-chevron-up text-xs" aria-hidden="true" />
582
+ </Button>
583
+ </Tip>
584
+ <Tip label="Move down" side="top">
585
+ <Button
586
+ type="button"
587
+ variant="ghost"
588
+ size="icon-sm"
589
+ className="size-7 shrink-0"
590
+ disabled={!canMoveLater}
591
+ aria-label={`Move ${card.title} down`}
592
+ onClick={() => onMoveStep(1)}
593
+ >
594
+ <i className="fa-light fa-chevron-down text-xs" aria-hidden="true" />
595
+ </Button>
596
+ </Tip>
597
+ </div>
598
+ <div className="hidden items-center gap-0.5 lg:flex">
599
+ <Tip label="Move left" side="top">
600
+ <Button
601
+ type="button"
602
+ variant="ghost"
603
+ size="icon-sm"
604
+ className="size-7 shrink-0"
605
+ disabled={!canMoveEarlier}
606
+ aria-label={`Move ${card.title} left`}
607
+ onClick={() => onMoveStep(-1)}
608
+ >
609
+ <i className="fa-light fa-chevron-left text-xs" aria-hidden="true" />
610
+ </Button>
611
+ </Tip>
612
+ <Tip label="Move right" side="top">
613
+ <Button
614
+ type="button"
615
+ variant="ghost"
616
+ size="icon-sm"
617
+ className="size-7 shrink-0"
618
+ disabled={!canMoveLater}
619
+ aria-label={`Move ${card.title} right`}
620
+ onClick={() => onMoveStep(1)}
621
+ >
622
+ <i className="fa-light fa-chevron-right text-xs" aria-hidden="true" />
623
+ </Button>
624
+ </Tip>
625
+ </div>
626
+ </div>
627
+ <Tip label={`Remove ${card.title}`} side="top">
628
+ <Button
629
+ type="button"
630
+ variant="ghost"
631
+ size="icon-sm"
632
+ className="size-8 shrink-0 text-muted-foreground hover:text-destructive"
633
+ aria-label={`Remove ${card.title} from dashboard`}
634
+ onClick={() => onRemove(card.id)}
635
+ >
636
+ <i className="fa-light fa-trash text-[13px]" aria-hidden="true" />
637
+ </Button>
638
+ </Tip>
639
+ </div>
640
+ </div>
641
+ {isKeyMetrics && keyMetrics ? (
642
+ <KeyMetrics
643
+ variant="card"
644
+ title={card.title}
645
+ description={card.description}
646
+ metrics={keyMetrics.metrics.slice(0, keyMetricsKpiCount)}
647
+ insight={keyMetrics.insight}
648
+ metricsSingleRow
649
+ metricsHalfWidthLayout={span === 1}
650
+ className="w-full min-w-0"
651
+ />
652
+ ) : (
653
+ <ChartCard
654
+ variant={chartVariant}
655
+ title={card.title}
656
+ description={card.description}
657
+ className="!h-auto min-h-0 shrink-0"
658
+ leoInsight={chartLeoInsight}
659
+ >
660
+ {Renderer ? <Renderer rows={rows} chartType={chartType} /> : null}
661
+ </ChartCard>
662
+ )}
663
+ </div>
664
+ )
665
+ }
666
+
667
+ export interface ComplianceDashboardChartsSectionProps {
668
+ rows: ComplianceItem[]
669
+ keyMetrics: { metrics: MetricItem[]; insight: MetricInsight }
670
+ visibleCards: string[]
671
+ cardOrder: string[]
672
+ cardSpans?: Record<string, 1 | 2>
673
+ cardChartTypes?: Record<string, ChartType>
674
+ keyMetricsKpiCount?: number
675
+ layoutEditMode?: boolean
676
+ onVisibleChange?: (visible: string[]) => void
677
+ onOrderChange?: (order: string[]) => void
678
+ onSpanChange?: (id: string, span: 1 | 2) => void
679
+ onChartTypeChange?: (id: string, chartType: ChartType) => void
680
+ onKeyMetricsKpiCountChange?: (count: number) => void
681
+ onResetLayout?: () => void
682
+ onLayoutEditDone?: () => void
683
+ onLayoutEditCancel?: () => void
684
+ }
685
+
686
+ export function ComplianceDashboardChartsSection({
687
+ rows,
688
+ keyMetrics,
689
+ visibleCards,
690
+ cardOrder,
691
+ cardSpans = DEFAULT_COMPLIANCE_SPANS,
692
+ cardChartTypes = DEFAULT_COMPLIANCE_CHART_TYPES,
693
+ keyMetricsKpiCount = KEY_METRICS_KPI_COUNT_DEFAULT,
694
+ layoutEditMode = false,
695
+ onVisibleChange,
696
+ onOrderChange,
697
+ onSpanChange,
698
+ onChartTypeChange,
699
+ onKeyMetricsKpiCountChange,
700
+ onResetLayout,
701
+ onLayoutEditDone,
702
+ onLayoutEditCancel,
703
+ }: ComplianceDashboardChartsSectionProps) {
704
+ const { chartVariant } = useChartVariant()
705
+ const defs = React.useMemo(() => new Map(ALL_COMPLIANCE_DASHBOARD_CARDS.map(c => [c.id, c])), [])
706
+
707
+ const orderedCards = React.useMemo(() => {
708
+ return cardOrder
709
+ .filter(id => visibleCards.includes(id) && defs.has(id))
710
+ .map(id => defs.get(id)!)
711
+ }, [visibleCards, cardOrder, defs])
712
+
713
+ const hiddenCardDefs = React.useMemo(
714
+ () => ALL_COMPLIANCE_DASHBOARD_CARDS.filter(c => !visibleCards.includes(c.id)),
715
+ [visibleCards],
716
+ )
717
+
718
+ const sortableIds = React.useMemo(() => orderedCards.map(c => c.id), [orderedCards])
719
+
720
+ const sensors = useSensors(
721
+ useSensor(PointerSensor, { activationConstraint: { distance: 8 } }),
722
+ useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
723
+ )
724
+
725
+ const handleDragEnd = React.useCallback(
726
+ (event: DragEndEvent) => {
727
+ if (!onOrderChange) return
728
+ const { active, over } = event
729
+ if (!over || active.id === over.id) return
730
+ const oldIndex = sortableIds.indexOf(String(active.id))
731
+ const newIndex = sortableIds.indexOf(String(over.id))
732
+ if (oldIndex < 0 || newIndex < 0) return
733
+ const nextVisibleOrder = arrayMove(sortableIds, oldIndex, newIndex)
734
+ const visibleSet = new Set(visibleCards)
735
+ onOrderChange(applyVisibleReorder(cardOrder, visibleSet, nextVisibleOrder))
736
+ },
737
+ [cardOrder, onOrderChange, sortableIds, visibleCards],
738
+ )
739
+
740
+ const moveStep = React.useCallback(
741
+ (id: string, direction: -1 | 1) => {
742
+ if (!onOrderChange) return
743
+ const idx = sortableIds.indexOf(id)
744
+ if (idx < 0) return
745
+ const newIdx = idx + direction
746
+ if (newIdx < 0 || newIdx >= sortableIds.length) return
747
+ const nextVisibleOrder = arrayMove(sortableIds, idx, newIdx)
748
+ const visibleSet = new Set(visibleCards)
749
+ onOrderChange(applyVisibleReorder(cardOrder, visibleSet, nextVisibleOrder))
750
+ },
751
+ [cardOrder, onOrderChange, sortableIds, visibleCards],
752
+ )
753
+
754
+ const addCard = React.useCallback(
755
+ (id: string) => {
756
+ if (!onVisibleChange) return
757
+ if (visibleCards.includes(id)) return
758
+ onVisibleChange([...visibleCards, id])
759
+ },
760
+ [onVisibleChange, visibleCards],
761
+ )
762
+
763
+ const removeCard = React.useCallback(
764
+ (id: string) => {
765
+ if (!onVisibleChange) return
766
+ onVisibleChange(visibleCards.filter(v => v !== id))
767
+ },
768
+ [onVisibleChange, visibleCards],
769
+ )
770
+
771
+ if (orderedCards.length === 0) {
772
+ return (
773
+ <div className="flex flex-col items-center justify-center gap-3 px-4 py-12 text-center lg:px-6">
774
+ <i className="fa-light fa-chart-column text-2xl text-muted-foreground/40" aria-hidden="true" />
775
+ <p className="text-sm text-muted-foreground">
776
+ No widgets on the dashboard.
777
+ {layoutEditMode && hiddenCardDefs.length > 0 ? " Add a widget below." : " Turn on Edit layout and add widgets back."}
778
+ </p>
779
+ {layoutEditMode && hiddenCardDefs.length > 0 && onVisibleChange ? (
780
+ <DropdownMenu>
781
+ <DropdownMenuTrigger asChild>
782
+ <Button type="button" variant="outline" size="sm" className="size-9 p-0" aria-label="Add widget">
783
+ <i className="fa-light fa-plus text-sm" aria-hidden="true" />
784
+ </Button>
785
+ </DropdownMenuTrigger>
786
+ <DropdownMenuContent align="center">
787
+ {hiddenCardDefs.map(c => (
788
+ <DropdownMenuItem key={c.id} onSelect={() => addCard(c.id)}>
789
+ {c.title}
790
+ </DropdownMenuItem>
791
+ ))}
792
+ </DropdownMenuContent>
793
+ </DropdownMenu>
794
+ ) : null}
795
+ </div>
796
+ )
797
+ }
798
+
799
+ const grid = (
800
+ <div
801
+ className={cn(
802
+ "grid grid-cols-1 gap-4 lg:grid-cols-2",
803
+ layoutEditMode && "lg:items-start lg:content-start lg:auto-rows-min",
804
+ )}
805
+ >
806
+ {orderedCards.map((card, cardIndex) => {
807
+ const isKeyMetricsCard = card.id === KEY_METRICS_CARD_ID
808
+ const Renderer = isKeyMetricsCard ? null : COMPLIANCE_CHART_RENDERERS[card.id]
809
+ if (!isKeyMetricsCard && !Renderer) return null
810
+ const span = cardSpans[card.id] ?? card.defaultSpan
811
+ const requestedType = cardChartTypes[card.id] ?? card.defaultChartType
812
+ const allowedTypes = card.chartTypes.map(o => o.type)
813
+ const chartType =
814
+ allowedTypes.length === 0
815
+ ? card.defaultChartType
816
+ : allowedTypes.includes(requestedType)
817
+ ? requestedType
818
+ : card.defaultChartType
819
+
820
+ if (
821
+ layoutEditMode &&
822
+ onOrderChange &&
823
+ onSpanChange &&
824
+ onChartTypeChange &&
825
+ onVisibleChange
826
+ ) {
827
+ return (
828
+ <SortableComplianceDashboardCard
829
+ key={card.id}
830
+ card={card}
831
+ rows={rows}
832
+ span={span}
833
+ chartType={chartType}
834
+ cardIndex={cardIndex}
835
+ totalCards={orderedCards.length}
836
+ onSpanChange={onSpanChange}
837
+ onChartTypeChange={onChartTypeChange}
838
+ onRemove={removeCard}
839
+ onMoveStep={dir => moveStep(card.id, dir)}
840
+ keyMetrics={isKeyMetricsCard ? keyMetrics : null}
841
+ keyMetricsKpiCount={keyMetricsKpiCount}
842
+ onKeyMetricsKpiCountChange={
843
+ isKeyMetricsCard ? onKeyMetricsKpiCountChange : undefined
844
+ }
845
+ />
846
+ )
847
+ }
848
+
849
+ return (
850
+ <div
851
+ key={card.id}
852
+ className={cn(span === 2 ? "lg:col-span-2" : undefined)}
853
+ >
854
+ {isKeyMetricsCard ? (
855
+ <KeyMetrics
856
+ variant="card"
857
+ title={card.title}
858
+ description={card.description}
859
+ metrics={keyMetrics.metrics.slice(0, keyMetricsKpiCount)}
860
+ insight={keyMetrics.insight}
861
+ metricsSingleRow
862
+ metricsHalfWidthLayout={span === 1}
863
+ className="w-full min-w-0"
864
+ />
865
+ ) : (
866
+ <ChartCard
867
+ variant={chartVariant}
868
+ title={card.title}
869
+ description={card.description}
870
+ leoInsight={COMPLIANCE_CHART_LEO_INSIGHTS[card.id]}
871
+ >
872
+ {Renderer ? <Renderer rows={rows} chartType={chartType} /> : null}
873
+ </ChartCard>
874
+ )}
875
+ </div>
876
+ )
877
+ })}
878
+ </div>
879
+ )
880
+
881
+ const editToolbar =
882
+ layoutEditMode && onVisibleChange && onResetLayout ? (
883
+ <div
884
+ className="mb-3 flex flex-wrap items-center justify-between gap-3 rounded-lg border border-border bg-transparent px-3 py-2"
885
+ role="region"
886
+ aria-label="Dashboard layout options"
887
+ >
888
+ <p className="text-xs text-muted-foreground">Drag cards to reorder. Changes save automatically.</p>
889
+ <div className="flex flex-wrap items-center justify-end gap-2">
890
+ <Button
891
+ type="button"
892
+ size="sm"
893
+ variant="ghost"
894
+ className="h-8 text-xs"
895
+ onClick={() => onVisibleChange(ALL_COMPLIANCE_DASHBOARD_CARDS.map(c => c.id))}
896
+ >
897
+ Show all
898
+ </Button>
899
+ <Button type="button" size="sm" variant="ghost" className="h-8 text-xs" onClick={() => onVisibleChange([])}>
900
+ Hide all
901
+ </Button>
902
+ <Tip side="bottom" label="Reset visibility, order, widths, and chart types">
903
+ <Button type="button" size="sm" variant="ghost" className="h-8 px-2 text-xs" onClick={onResetLayout}>
904
+ <i className="fa-light fa-rotate-left mr-1 text-xs" aria-hidden="true" />
905
+ Reset
906
+ </Button>
907
+ </Tip>
908
+ {hiddenCardDefs.length > 0 ? (
909
+ <DropdownMenu>
910
+ <DropdownMenuTrigger asChild>
911
+ <Button type="button" variant="outline" size="sm" className="size-8 p-0" aria-label="Add widget">
912
+ <i className="fa-light fa-plus text-[13px]" aria-hidden="true" />
913
+ </Button>
914
+ </DropdownMenuTrigger>
915
+ <DropdownMenuContent align="end">
916
+ {hiddenCardDefs.map(c => (
917
+ <DropdownMenuItem key={c.id} onSelect={() => addCard(c.id)}>
918
+ {c.title}
919
+ </DropdownMenuItem>
920
+ ))}
921
+ </DropdownMenuContent>
922
+ </DropdownMenu>
923
+ ) : null}
924
+ {onLayoutEditCancel ? (
925
+ <Button type="button" size="sm" variant="outline" className="h-8 text-xs" onClick={onLayoutEditCancel}>
926
+ Cancel
927
+ </Button>
928
+ ) : null}
929
+ {onLayoutEditDone ? (
930
+ <Button type="button" size="sm" className="h-8 text-xs" onClick={onLayoutEditDone}>
931
+ Done
932
+ </Button>
933
+ ) : null}
934
+ </div>
935
+ </div>
936
+ ) : null
937
+
938
+ const gridBody =
939
+ layoutEditMode && onOrderChange ? (
940
+ <DndContext sensors={sensors} collisionDetection={closestCorners} onDragEnd={handleDragEnd}>
941
+ <SortableContext items={sortableIds} strategy={rectSortingStrategy}>
942
+ {grid}
943
+ </SortableContext>
944
+ </DndContext>
945
+ ) : (
946
+ grid
947
+ )
948
+
949
+ return (
950
+ <div
951
+ className={cn(
952
+ "flex flex-col gap-4 px-4 pb-2 lg:px-6",
953
+ layoutEditMode && "rounded-xl border border-dashed border-border/80 bg-transparent py-3",
954
+ )}
955
+ >
956
+ {editToolbar}
957
+ {gridBody}
958
+ </div>
959
+ )
960
+ }