@contractspec/example.analytics-dashboard 1.57.0 → 1.58.0

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 (173) hide show
  1. package/dist/browser/dashboard/dashboard.enum.js +34 -0
  2. package/dist/browser/dashboard/dashboard.operation.js +289 -0
  3. package/dist/browser/dashboard/dashboard.presentation.js +197 -0
  4. package/dist/browser/dashboard/dashboard.schema.js +126 -0
  5. package/dist/browser/dashboard/dashboard.test-spec.js +213 -0
  6. package/dist/browser/dashboard/index.js +299 -0
  7. package/dist/browser/dashboard.feature.js +84 -0
  8. package/dist/browser/datasource/posthog-datasource.js +289 -0
  9. package/dist/browser/docs/analytics-dashboard.docblock.js +103 -0
  10. package/dist/browser/docs/index.js +103 -0
  11. package/dist/browser/events.js +81 -0
  12. package/dist/browser/example.js +42 -0
  13. package/dist/browser/handlers/analytics.handlers.js +278 -0
  14. package/dist/browser/handlers/index.js +571 -0
  15. package/dist/browser/handlers/query.handlers.js +294 -0
  16. package/dist/browser/index.js +1677 -0
  17. package/dist/browser/query/index.js +159 -0
  18. package/dist/browser/query/query.enum.js +11 -0
  19. package/dist/browser/query/query.operation.js +154 -0
  20. package/dist/browser/query/query.presentation.js +119 -0
  21. package/dist/browser/query/query.schema.js +70 -0
  22. package/dist/browser/query/query.test-spec.js +113 -0
  23. package/dist/browser/query-engine/index.js +491 -0
  24. package/dist/browser/seeders/index.js +20 -0
  25. package/dist/browser/ui/AnalyticsDashboard.js +394 -0
  26. package/dist/browser/ui/hooks/index.js +69 -0
  27. package/dist/browser/ui/hooks/useAnalyticsData.js +66 -0
  28. package/dist/browser/ui/index.js +671 -0
  29. package/dist/browser/ui/renderers/analytics.markdown.js +275 -0
  30. package/dist/browser/ui/renderers/index.js +275 -0
  31. package/dist/dashboard/dashboard.enum.d.ts +3 -8
  32. package/dist/dashboard/dashboard.enum.d.ts.map +1 -1
  33. package/dist/dashboard/dashboard.enum.js +31 -39
  34. package/dist/dashboard/dashboard.operation.d.ts +444 -450
  35. package/dist/dashboard/dashboard.operation.d.ts.map +1 -1
  36. package/dist/dashboard/dashboard.operation.js +284 -207
  37. package/dist/dashboard/dashboard.presentation.d.ts +3 -8
  38. package/dist/dashboard/dashboard.presentation.d.ts.map +1 -1
  39. package/dist/dashboard/dashboard.presentation.js +193 -85
  40. package/dist/dashboard/dashboard.schema.d.ts +289 -294
  41. package/dist/dashboard/dashboard.schema.d.ts.map +1 -1
  42. package/dist/dashboard/dashboard.schema.js +119 -228
  43. package/dist/dashboard/dashboard.test-spec.d.ts +4 -9
  44. package/dist/dashboard/dashboard.test-spec.d.ts.map +1 -1
  45. package/dist/dashboard/dashboard.test-spec.js +209 -228
  46. package/dist/dashboard/index.d.ts +7 -4
  47. package/dist/dashboard/index.d.ts.map +1 -0
  48. package/dist/dashboard/index.js +299 -4
  49. package/dist/dashboard.feature.d.ts +1 -6
  50. package/dist/dashboard.feature.d.ts.map +1 -1
  51. package/dist/dashboard.feature.js +83 -175
  52. package/dist/datasource/posthog-datasource.d.ts +15 -19
  53. package/dist/datasource/posthog-datasource.d.ts.map +1 -1
  54. package/dist/datasource/posthog-datasource.js +274 -238
  55. package/dist/docs/analytics-dashboard.docblock.d.ts +2 -1
  56. package/dist/docs/analytics-dashboard.docblock.d.ts.map +1 -0
  57. package/dist/docs/analytics-dashboard.docblock.js +45 -56
  58. package/dist/docs/index.d.ts +2 -1
  59. package/dist/docs/index.d.ts.map +1 -0
  60. package/dist/docs/index.js +104 -1
  61. package/dist/events.d.ts +109 -115
  62. package/dist/events.d.ts.map +1 -1
  63. package/dist/events.js +74 -120
  64. package/dist/example.d.ts +2 -6
  65. package/dist/example.d.ts.map +1 -1
  66. package/dist/example.js +41 -55
  67. package/dist/handlers/analytics.handlers.d.ts +110 -109
  68. package/dist/handlers/analytics.handlers.d.ts.map +1 -1
  69. package/dist/handlers/analytics.handlers.js +267 -298
  70. package/dist/handlers/index.d.ts +3 -3
  71. package/dist/handlers/index.d.ts.map +1 -0
  72. package/dist/handlers/index.js +571 -3
  73. package/dist/handlers/query.handlers.d.ts +7 -11
  74. package/dist/handlers/query.handlers.d.ts.map +1 -1
  75. package/dist/handlers/query.handlers.js +292 -7
  76. package/dist/index.d.ts +12 -13
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +1678 -14
  79. package/dist/node/dashboard/dashboard.enum.js +34 -0
  80. package/dist/node/dashboard/dashboard.operation.js +289 -0
  81. package/dist/node/dashboard/dashboard.presentation.js +197 -0
  82. package/dist/node/dashboard/dashboard.schema.js +126 -0
  83. package/dist/node/dashboard/dashboard.test-spec.js +213 -0
  84. package/dist/node/dashboard/index.js +299 -0
  85. package/dist/node/dashboard.feature.js +84 -0
  86. package/dist/node/datasource/posthog-datasource.js +289 -0
  87. package/dist/node/docs/analytics-dashboard.docblock.js +103 -0
  88. package/dist/node/docs/index.js +103 -0
  89. package/dist/node/events.js +81 -0
  90. package/dist/node/example.js +42 -0
  91. package/dist/node/handlers/analytics.handlers.js +278 -0
  92. package/dist/node/handlers/index.js +571 -0
  93. package/dist/node/handlers/query.handlers.js +294 -0
  94. package/dist/node/index.js +1677 -0
  95. package/dist/node/query/index.js +159 -0
  96. package/dist/node/query/query.enum.js +11 -0
  97. package/dist/node/query/query.operation.js +154 -0
  98. package/dist/node/query/query.presentation.js +119 -0
  99. package/dist/node/query/query.schema.js +70 -0
  100. package/dist/node/query/query.test-spec.js +113 -0
  101. package/dist/node/query-engine/index.js +491 -0
  102. package/dist/node/seeders/index.js +20 -0
  103. package/dist/node/ui/AnalyticsDashboard.js +394 -0
  104. package/dist/node/ui/hooks/index.js +69 -0
  105. package/dist/node/ui/hooks/useAnalyticsData.js +66 -0
  106. package/dist/node/ui/index.js +671 -0
  107. package/dist/node/ui/renderers/analytics.markdown.js +275 -0
  108. package/dist/node/ui/renderers/index.js +275 -0
  109. package/dist/query/index.d.ts +7 -4
  110. package/dist/query/index.d.ts.map +1 -0
  111. package/dist/query/index.js +159 -4
  112. package/dist/query/query.enum.d.ts +1 -6
  113. package/dist/query/query.enum.d.ts.map +1 -1
  114. package/dist/query/query.enum.js +10 -14
  115. package/dist/query/query.operation.d.ts +148 -154
  116. package/dist/query/query.operation.d.ts.map +1 -1
  117. package/dist/query/query.operation.js +151 -109
  118. package/dist/query/query.presentation.d.ts +2 -7
  119. package/dist/query/query.presentation.d.ts.map +1 -1
  120. package/dist/query/query.presentation.js +116 -56
  121. package/dist/query/query.schema.d.ts +121 -126
  122. package/dist/query/query.schema.d.ts.map +1 -1
  123. package/dist/query/query.schema.js +66 -152
  124. package/dist/query/query.test-spec.d.ts +2 -7
  125. package/dist/query/query.test-spec.d.ts.map +1 -1
  126. package/dist/query/query.test-spec.js +111 -121
  127. package/dist/query-engine/index.d.ts +84 -88
  128. package/dist/query-engine/index.d.ts.map +1 -1
  129. package/dist/query-engine/index.js +489 -188
  130. package/dist/seeders/index.d.ts +4 -8
  131. package/dist/seeders/index.d.ts.map +1 -1
  132. package/dist/seeders/index.js +18 -16
  133. package/dist/ui/AnalyticsDashboard.d.ts +1 -6
  134. package/dist/ui/AnalyticsDashboard.d.ts.map +1 -1
  135. package/dist/ui/AnalyticsDashboard.js +389 -259
  136. package/dist/ui/hooks/index.d.ts +2 -2
  137. package/dist/ui/hooks/index.d.ts.map +1 -0
  138. package/dist/ui/hooks/index.js +69 -4
  139. package/dist/ui/hooks/useAnalyticsData.d.ts +16 -20
  140. package/dist/ui/hooks/useAnalyticsData.d.ts.map +1 -1
  141. package/dist/ui/hooks/useAnalyticsData.js +63 -69
  142. package/dist/ui/index.d.ts +7 -6
  143. package/dist/ui/index.d.ts.map +1 -0
  144. package/dist/ui/index.js +671 -5
  145. package/dist/ui/renderers/analytics.markdown.d.ts +13 -14
  146. package/dist/ui/renderers/analytics.markdown.d.ts.map +1 -1
  147. package/dist/ui/renderers/analytics.markdown.js +266 -254
  148. package/dist/ui/renderers/index.d.ts +2 -2
  149. package/dist/ui/renderers/index.d.ts.map +1 -0
  150. package/dist/ui/renderers/index.js +275 -2
  151. package/package.json +328 -67
  152. package/dist/dashboard/dashboard.enum.js.map +0 -1
  153. package/dist/dashboard/dashboard.operation.js.map +0 -1
  154. package/dist/dashboard/dashboard.presentation.js.map +0 -1
  155. package/dist/dashboard/dashboard.schema.js.map +0 -1
  156. package/dist/dashboard/dashboard.test-spec.js.map +0 -1
  157. package/dist/dashboard.feature.js.map +0 -1
  158. package/dist/datasource/posthog-datasource.js.map +0 -1
  159. package/dist/docs/analytics-dashboard.docblock.js.map +0 -1
  160. package/dist/events.js.map +0 -1
  161. package/dist/example.js.map +0 -1
  162. package/dist/handlers/analytics.handlers.js.map +0 -1
  163. package/dist/handlers/query.handlers.js.map +0 -1
  164. package/dist/query/query.enum.js.map +0 -1
  165. package/dist/query/query.operation.js.map +0 -1
  166. package/dist/query/query.presentation.js.map +0 -1
  167. package/dist/query/query.schema.js.map +0 -1
  168. package/dist/query/query.test-spec.js.map +0 -1
  169. package/dist/query-engine/index.js.map +0 -1
  170. package/dist/seeders/index.js.map +0 -1
  171. package/dist/ui/AnalyticsDashboard.js.map +0 -1
  172. package/dist/ui/hooks/useAnalyticsData.js.map +0 -1
  173. package/dist/ui/renderers/analytics.markdown.js.map +0 -1
@@ -0,0 +1,671 @@
1
+ // src/ui/renderers/analytics.markdown.ts
2
+ var mockDashboards = [
3
+ {
4
+ id: "dash-1",
5
+ name: "Sales Overview",
6
+ slug: "sales-overview",
7
+ status: "PUBLISHED",
8
+ widgetCount: 8,
9
+ viewCount: 1250,
10
+ lastViewedAt: "2024-01-16T12:00:00Z"
11
+ },
12
+ {
13
+ id: "dash-2",
14
+ name: "User Engagement",
15
+ slug: "user-engagement",
16
+ status: "PUBLISHED",
17
+ widgetCount: 6,
18
+ viewCount: 890,
19
+ lastViewedAt: "2024-01-16T10:00:00Z"
20
+ },
21
+ {
22
+ id: "dash-3",
23
+ name: "Product Analytics",
24
+ slug: "product-analytics",
25
+ status: "PUBLISHED",
26
+ widgetCount: 10,
27
+ viewCount: 560,
28
+ lastViewedAt: "2024-01-15T14:00:00Z"
29
+ },
30
+ {
31
+ id: "dash-4",
32
+ name: "Finance Report",
33
+ slug: "finance-report",
34
+ status: "DRAFT",
35
+ widgetCount: 4,
36
+ viewCount: 0,
37
+ lastViewedAt: null
38
+ }
39
+ ];
40
+ var mockWidgets = [
41
+ {
42
+ id: "w-1",
43
+ dashboardId: "dash-1",
44
+ name: "Total Revenue",
45
+ type: "METRIC",
46
+ value: 125000,
47
+ change: 12.5
48
+ },
49
+ {
50
+ id: "w-2",
51
+ dashboardId: "dash-1",
52
+ name: "Active Users",
53
+ type: "METRIC",
54
+ value: 4500,
55
+ change: 8.2
56
+ },
57
+ {
58
+ id: "w-3",
59
+ dashboardId: "dash-1",
60
+ name: "Revenue Trend",
61
+ type: "LINE_CHART",
62
+ dataPoints: 30
63
+ },
64
+ {
65
+ id: "w-4",
66
+ dashboardId: "dash-1",
67
+ name: "Top Products",
68
+ type: "BAR_CHART",
69
+ dataPoints: 10
70
+ },
71
+ {
72
+ id: "w-5",
73
+ dashboardId: "dash-2",
74
+ name: "Daily Active Users",
75
+ type: "LINE_CHART",
76
+ dataPoints: 30
77
+ },
78
+ {
79
+ id: "w-6",
80
+ dashboardId: "dash-2",
81
+ name: "Session Duration",
82
+ type: "METRIC",
83
+ value: 245,
84
+ change: -3.1
85
+ }
86
+ ];
87
+ var mockQueries = [
88
+ {
89
+ id: "q-1",
90
+ name: "Monthly Revenue",
91
+ type: "AGGREGATION",
92
+ isShared: true,
93
+ executionCount: 1500
94
+ },
95
+ {
96
+ id: "q-2",
97
+ name: "User Growth",
98
+ type: "METRIC",
99
+ isShared: true,
100
+ executionCount: 890
101
+ },
102
+ {
103
+ id: "q-3",
104
+ name: "Product Sales",
105
+ type: "SQL",
106
+ isShared: false,
107
+ executionCount: 340
108
+ },
109
+ {
110
+ id: "q-4",
111
+ name: "Conversion Funnel",
112
+ type: "AGGREGATION",
113
+ isShared: true,
114
+ executionCount: 450
115
+ }
116
+ ];
117
+ function formatNumber(value) {
118
+ if (value >= 1e6) {
119
+ return `${(value / 1e6).toFixed(1)}M`;
120
+ }
121
+ if (value >= 1000) {
122
+ return `${(value / 1000).toFixed(1)}K`;
123
+ }
124
+ return value.toString();
125
+ }
126
+ function formatChange(change) {
127
+ const icon = change >= 0 ? "\uD83D\uDCC8" : "\uD83D\uDCC9";
128
+ const sign = change >= 0 ? "+" : "";
129
+ return `${icon} ${sign}${change.toFixed(1)}%`;
130
+ }
131
+ var analyticsDashboardMarkdownRenderer = {
132
+ target: "markdown",
133
+ render: async (desc) => {
134
+ if (desc.source.type !== "component" || desc.source.componentKey !== "AnalyticsDashboard") {
135
+ throw new Error("analyticsDashboardMarkdownRenderer: not AnalyticsDashboard");
136
+ }
137
+ const dashboards = mockDashboards;
138
+ const widgets = mockWidgets;
139
+ const queries = mockQueries;
140
+ const dashboard = dashboards[0];
141
+ if (!dashboard) {
142
+ return {
143
+ mimeType: "text/markdown",
144
+ body: `# No Dashboards
145
+
146
+ No dashboards available.`
147
+ };
148
+ }
149
+ const dashboardWidgets = widgets.filter((w) => w.dashboardId === dashboard.id);
150
+ const publishedDashboards = dashboards.filter((d) => d.status === "PUBLISHED");
151
+ const totalViews = dashboards.reduce((sum, d) => sum + d.viewCount, 0);
152
+ const sharedQueries = queries.filter((q) => q.isShared);
153
+ const lines = [
154
+ `# ${dashboard.name}`,
155
+ "",
156
+ "> Analytics dashboard overview",
157
+ "",
158
+ "## Key Metrics",
159
+ ""
160
+ ];
161
+ const metricWidgets = dashboardWidgets.filter((w) => w.type === "METRIC");
162
+ for (const widget of metricWidgets) {
163
+ const w = widget;
164
+ lines.push(`### ${w.name}`);
165
+ lines.push(`**${formatNumber(w.value)}** ${formatChange(w.change)}`);
166
+ lines.push("");
167
+ }
168
+ lines.push("## Visualizations");
169
+ lines.push("");
170
+ const chartWidgets = dashboardWidgets.filter((w) => w.type !== "METRIC");
171
+ for (const widget of chartWidgets) {
172
+ const w = widget;
173
+ lines.push(`- **${w.name}** (${w.type.replace("_", " ")}) - ${w.dataPoints} data points`);
174
+ }
175
+ lines.push("");
176
+ lines.push("## Dashboard Stats");
177
+ lines.push("");
178
+ lines.push("| Metric | Value |");
179
+ lines.push("|--------|-------|");
180
+ lines.push(`| Total Dashboards | ${dashboards.length} |`);
181
+ lines.push(`| Published | ${publishedDashboards.length} |`);
182
+ lines.push(`| Total Views | ${totalViews.toLocaleString()} |`);
183
+ lines.push(`| Shared Queries | ${sharedQueries.length} |`);
184
+ return {
185
+ mimeType: "text/markdown",
186
+ body: lines.join(`
187
+ `)
188
+ };
189
+ }
190
+ };
191
+ var dashboardListMarkdownRenderer = {
192
+ target: "markdown",
193
+ render: async (desc) => {
194
+ if (desc.source.type !== "component" || desc.source.componentKey !== "DashboardList") {
195
+ throw new Error("dashboardListMarkdownRenderer: not DashboardList");
196
+ }
197
+ const dashboards = mockDashboards;
198
+ const lines = [
199
+ "# Dashboards",
200
+ "",
201
+ "> Browse and manage analytics dashboards",
202
+ "",
203
+ "| Dashboard | Widgets | Views | Status | Last Viewed |",
204
+ "|-----------|---------|-------|--------|-------------|"
205
+ ];
206
+ for (const dashboard of dashboards) {
207
+ const lastViewed = dashboard.lastViewedAt ? new Date(dashboard.lastViewedAt).toLocaleDateString() : "Never";
208
+ const statusIcon = dashboard.status === "PUBLISHED" ? "\uD83D\uDFE2" : "⚫";
209
+ lines.push(`| [${dashboard.name}](/dashboards/${dashboard.slug}) | ${dashboard.widgetCount} | ${dashboard.viewCount.toLocaleString()} | ${statusIcon} ${dashboard.status} | ${lastViewed} |`);
210
+ }
211
+ lines.push("");
212
+ lines.push("## Quick Actions");
213
+ lines.push("");
214
+ lines.push("- **Create Dashboard** - Start with a blank canvas");
215
+ lines.push("- **Import Template** - Use a pre-built template");
216
+ lines.push("- **Clone Dashboard** - Duplicate an existing dashboard");
217
+ return {
218
+ mimeType: "text/markdown",
219
+ body: lines.join(`
220
+ `)
221
+ };
222
+ }
223
+ };
224
+ var queryBuilderMarkdownRenderer = {
225
+ target: "markdown",
226
+ render: async (desc) => {
227
+ if (desc.source.type !== "component" || desc.source.componentKey !== "QueryBuilder") {
228
+ throw new Error("queryBuilderMarkdownRenderer: not QueryBuilder");
229
+ }
230
+ const queries = mockQueries;
231
+ const lines = [
232
+ "# Query Builder",
233
+ "",
234
+ "> Create and manage data queries",
235
+ "",
236
+ "## Saved Queries",
237
+ "",
238
+ "| Query | Type | Shared | Executions |",
239
+ "|-------|------|--------|------------|"
240
+ ];
241
+ for (const query of queries) {
242
+ const sharedIcon = query.isShared ? "\uD83C\uDF10" : "\uD83D\uDD12";
243
+ lines.push(`| ${query.name} | ${query.type} | ${sharedIcon} | ${query.executionCount.toLocaleString()} |`);
244
+ }
245
+ lines.push("");
246
+ lines.push("## Query Types");
247
+ lines.push("");
248
+ lines.push("### METRIC");
249
+ lines.push("Query usage metrics from the metering system.");
250
+ lines.push("");
251
+ lines.push("### AGGREGATION");
252
+ lines.push("Build aggregations with measures and dimensions without writing SQL.");
253
+ lines.push("");
254
+ lines.push("### SQL");
255
+ lines.push("Write custom SQL queries for advanced analysis.");
256
+ lines.push("");
257
+ lines.push("## Features");
258
+ lines.push("");
259
+ lines.push("- Visual query builder");
260
+ lines.push("- Auto-complete for fields and functions");
261
+ lines.push("- Query validation and optimization");
262
+ lines.push("- Result caching");
263
+ lines.push("- Query sharing and collaboration");
264
+ return {
265
+ mimeType: "text/markdown",
266
+ body: lines.join(`
267
+ `)
268
+ };
269
+ }
270
+ };
271
+ // src/ui/hooks/useAnalyticsData.ts
272
+ import { useCallback, useEffect, useState } from "react";
273
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
274
+ "use client";
275
+ function useAnalyticsData(projectId = "local-project") {
276
+ const { handlers } = useTemplateRuntime();
277
+ const analytics = handlers.analytics;
278
+ const [dashboards, setDashboards] = useState([]);
279
+ const [queries, setQueries] = useState([]);
280
+ const [selectedDashboard, setSelectedDashboard] = useState(null);
281
+ const [widgets, setWidgets] = useState([]);
282
+ const [loading, setLoading] = useState(true);
283
+ const [error, setError] = useState(null);
284
+ const fetchData = useCallback(async () => {
285
+ try {
286
+ setLoading(true);
287
+ setError(null);
288
+ const [dashResult, queryResult] = await Promise.all([
289
+ analytics.listDashboards({ projectId, limit: 100 }),
290
+ analytics.listQueries({ projectId, limit: 100 })
291
+ ]);
292
+ setDashboards(dashResult.dashboards);
293
+ setQueries(queryResult.queries);
294
+ if (dashResult.dashboards.length > 0 && !selectedDashboard) {
295
+ const first = dashResult.dashboards[0];
296
+ if (first) {
297
+ setSelectedDashboard(first);
298
+ const dashboardWidgets = await analytics.getWidgets(first.id);
299
+ setWidgets(dashboardWidgets);
300
+ }
301
+ }
302
+ } catch (err) {
303
+ setError(err instanceof Error ? err : new Error("Failed to load analytics"));
304
+ } finally {
305
+ setLoading(false);
306
+ }
307
+ }, [analytics, projectId, selectedDashboard]);
308
+ useEffect(() => {
309
+ fetchData();
310
+ }, [fetchData]);
311
+ const selectDashboard = useCallback(async (dashboard) => {
312
+ setSelectedDashboard(dashboard);
313
+ const dashboardWidgets = await analytics.getWidgets(dashboard.id);
314
+ setWidgets(dashboardWidgets);
315
+ }, [analytics]);
316
+ const stats = {
317
+ totalDashboards: dashboards.length,
318
+ publishedDashboards: dashboards.filter((d) => d.status === "PUBLISHED").length,
319
+ totalQueries: queries.length,
320
+ sharedQueries: queries.filter((q) => q.isShared).length
321
+ };
322
+ return {
323
+ dashboards,
324
+ queries,
325
+ selectedDashboard,
326
+ widgets,
327
+ loading,
328
+ error,
329
+ stats,
330
+ refetch: fetchData,
331
+ selectDashboard
332
+ };
333
+ }
334
+
335
+ // src/ui/AnalyticsDashboard.tsx
336
+ import { useState as useState2 } from "react";
337
+ import {
338
+ Button,
339
+ ErrorState,
340
+ LoaderBlock,
341
+ StatCard,
342
+ StatCardGroup
343
+ } from "@contractspec/lib.design-system";
344
+ import { jsxDEV } from "react/jsx-dev-runtime";
345
+ "use client";
346
+ var STATUS_COLORS = {
347
+ PUBLISHED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
348
+ DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
349
+ ARCHIVED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"
350
+ };
351
+ var WIDGET_ICONS = {
352
+ LINE_CHART: "\uD83D\uDCC8",
353
+ BAR_CHART: "\uD83D\uDCCA",
354
+ PIE_CHART: "\uD83E\uDD67",
355
+ AREA_CHART: "\uD83D\uDCC9",
356
+ SCATTER_PLOT: "⚬",
357
+ METRIC: "\uD83D\uDD22",
358
+ TABLE: "\uD83D\uDCCB",
359
+ HEATMAP: "\uD83D\uDDFA️",
360
+ FUNNEL: "⏬",
361
+ MAP: "\uD83C\uDF0D",
362
+ TEXT: "\uD83D\uDCDD",
363
+ EMBED: "\uD83D\uDD17"
364
+ };
365
+ var QUERY_TYPE_COLORS = {
366
+ SQL: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
367
+ METRIC: "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",
368
+ AGGREGATION: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
369
+ CUSTOM: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"
370
+ };
371
+ function AnalyticsDashboard() {
372
+ const [activeTab, setActiveTab] = useState2("dashboards");
373
+ const {
374
+ dashboards,
375
+ queries,
376
+ selectedDashboard,
377
+ widgets,
378
+ loading,
379
+ error,
380
+ stats,
381
+ refetch,
382
+ selectDashboard
383
+ } = useAnalyticsData();
384
+ const tabs = [
385
+ { id: "dashboards", label: "Dashboards", icon: "\uD83D\uDCCA" },
386
+ { id: "queries", label: "Queries", icon: "\uD83D\uDD0D" }
387
+ ];
388
+ if (loading) {
389
+ return /* @__PURE__ */ jsxDEV(LoaderBlock, {
390
+ label: "Loading Analytics..."
391
+ }, undefined, false, undefined, this);
392
+ }
393
+ if (error) {
394
+ return /* @__PURE__ */ jsxDEV(ErrorState, {
395
+ title: "Failed to load Analytics",
396
+ description: error.message,
397
+ onRetry: refetch,
398
+ retryLabel: "Retry"
399
+ }, undefined, false, undefined, this);
400
+ }
401
+ return /* @__PURE__ */ jsxDEV("div", {
402
+ className: "space-y-6",
403
+ children: [
404
+ /* @__PURE__ */ jsxDEV("div", {
405
+ className: "flex items-center justify-between",
406
+ children: [
407
+ /* @__PURE__ */ jsxDEV("h2", {
408
+ className: "text-2xl font-bold",
409
+ children: "Analytics Dashboard"
410
+ }, undefined, false, undefined, this),
411
+ /* @__PURE__ */ jsxDEV(Button, {
412
+ onClick: () => alert("Create dashboard modal"),
413
+ children: [
414
+ /* @__PURE__ */ jsxDEV("span", {
415
+ className: "mr-2",
416
+ children: "+"
417
+ }, undefined, false, undefined, this),
418
+ " New Dashboard"
419
+ ]
420
+ }, undefined, true, undefined, this)
421
+ ]
422
+ }, undefined, true, undefined, this),
423
+ /* @__PURE__ */ jsxDEV(StatCardGroup, {
424
+ children: [
425
+ /* @__PURE__ */ jsxDEV(StatCard, {
426
+ label: "Dashboards",
427
+ value: stats.totalDashboards,
428
+ hint: `${stats.publishedDashboards} published`
429
+ }, undefined, false, undefined, this),
430
+ /* @__PURE__ */ jsxDEV(StatCard, {
431
+ label: "Queries",
432
+ value: stats.totalQueries,
433
+ hint: `${stats.sharedQueries} shared`
434
+ }, undefined, false, undefined, this),
435
+ /* @__PURE__ */ jsxDEV(StatCard, {
436
+ label: "Widgets",
437
+ value: widgets.length,
438
+ hint: "on current dashboard"
439
+ }, undefined, false, undefined, this)
440
+ ]
441
+ }, undefined, true, undefined, this),
442
+ /* @__PURE__ */ jsxDEV("nav", {
443
+ className: "bg-muted flex gap-1 rounded-lg p-1",
444
+ role: "tablist",
445
+ children: tabs.map((tab) => /* @__PURE__ */ jsxDEV(Button, {
446
+ type: "button",
447
+ role: "tab",
448
+ "aria-selected": activeTab === tab.id,
449
+ onClick: () => setActiveTab(tab.id),
450
+ className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 text-sm font-medium transition-colors ${activeTab === tab.id ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
451
+ children: [
452
+ /* @__PURE__ */ jsxDEV("span", {
453
+ children: tab.icon
454
+ }, undefined, false, undefined, this),
455
+ tab.label
456
+ ]
457
+ }, tab.id, true, undefined, this))
458
+ }, undefined, false, undefined, this),
459
+ /* @__PURE__ */ jsxDEV("div", {
460
+ className: "min-h-[400px]",
461
+ role: "tabpanel",
462
+ children: [
463
+ activeTab === "dashboards" && /* @__PURE__ */ jsxDEV("div", {
464
+ className: "space-y-6",
465
+ children: [
466
+ /* @__PURE__ */ jsxDEV("div", {
467
+ className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
468
+ children: [
469
+ dashboards.map((dashboard) => /* @__PURE__ */ jsxDEV("div", {
470
+ onClick: () => selectDashboard(dashboard),
471
+ className: `border-border bg-card cursor-pointer rounded-lg border p-4 transition-all ${selectedDashboard?.id === dashboard.id ? "ring-primary ring-2" : "hover:bg-muted/50"}`,
472
+ role: "button",
473
+ tabIndex: 0,
474
+ onKeyDown: (e) => {
475
+ if (e.key === "Enter" || e.key === " ")
476
+ selectDashboard(dashboard);
477
+ },
478
+ children: [
479
+ /* @__PURE__ */ jsxDEV("div", {
480
+ className: "mb-2 flex items-center justify-between",
481
+ children: [
482
+ /* @__PURE__ */ jsxDEV("h3", {
483
+ className: "font-medium",
484
+ children: dashboard.name
485
+ }, undefined, false, undefined, this),
486
+ /* @__PURE__ */ jsxDEV("span", {
487
+ className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[dashboard.status] ?? ""}`,
488
+ children: dashboard.status
489
+ }, undefined, false, undefined, this)
490
+ ]
491
+ }, undefined, true, undefined, this),
492
+ /* @__PURE__ */ jsxDEV("p", {
493
+ className: "text-muted-foreground mb-3 text-sm",
494
+ children: dashboard.description
495
+ }, undefined, false, undefined, this),
496
+ /* @__PURE__ */ jsxDEV("div", {
497
+ className: "text-muted-foreground flex items-center justify-between text-xs",
498
+ children: [
499
+ /* @__PURE__ */ jsxDEV("span", {
500
+ children: [
501
+ "/",
502
+ dashboard.slug
503
+ ]
504
+ }, undefined, true, undefined, this),
505
+ dashboard.isPublic && /* @__PURE__ */ jsxDEV("span", {
506
+ className: "text-green-600 dark:text-green-400",
507
+ children: "\uD83C\uDF10 Public"
508
+ }, undefined, false, undefined, this)
509
+ ]
510
+ }, undefined, true, undefined, this)
511
+ ]
512
+ }, dashboard.id, true, undefined, this)),
513
+ dashboards.length === 0 && /* @__PURE__ */ jsxDEV("div", {
514
+ className: "text-muted-foreground col-span-full flex h-64 items-center justify-center",
515
+ children: "No dashboards created yet"
516
+ }, undefined, false, undefined, this)
517
+ ]
518
+ }, undefined, true, undefined, this),
519
+ selectedDashboard && widgets.length > 0 && /* @__PURE__ */ jsxDEV("div", {
520
+ children: [
521
+ /* @__PURE__ */ jsxDEV("h3", {
522
+ className: "mb-4 text-lg font-semibold",
523
+ children: [
524
+ 'Widgets in "',
525
+ selectedDashboard.name,
526
+ '"'
527
+ ]
528
+ }, undefined, true, undefined, this),
529
+ /* @__PURE__ */ jsxDEV("div", {
530
+ className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
531
+ children: widgets.map((widget) => /* @__PURE__ */ jsxDEV("div", {
532
+ className: "border-border bg-card rounded-lg border p-4",
533
+ children: [
534
+ /* @__PURE__ */ jsxDEV("div", {
535
+ className: "mb-2 flex items-center gap-2",
536
+ children: [
537
+ /* @__PURE__ */ jsxDEV("span", {
538
+ className: "text-xl",
539
+ children: WIDGET_ICONS[widget.type] ?? "\uD83D\uDCCA"
540
+ }, undefined, false, undefined, this),
541
+ /* @__PURE__ */ jsxDEV("span", {
542
+ className: "font-medium",
543
+ children: widget.name
544
+ }, undefined, false, undefined, this)
545
+ ]
546
+ }, undefined, true, undefined, this),
547
+ /* @__PURE__ */ jsxDEV("div", {
548
+ className: "text-muted-foreground text-sm",
549
+ children: widget.type.replace(/_/g, " ")
550
+ }, undefined, false, undefined, this),
551
+ /* @__PURE__ */ jsxDEV("div", {
552
+ className: "text-muted-foreground mt-2 text-xs",
553
+ children: [
554
+ "Position: (",
555
+ widget.gridX,
556
+ ", ",
557
+ widget.gridY,
558
+ ") •",
559
+ " ",
560
+ widget.gridWidth,
561
+ "x",
562
+ widget.gridHeight
563
+ ]
564
+ }, undefined, true, undefined, this)
565
+ ]
566
+ }, widget.id, true, undefined, this))
567
+ }, undefined, false, undefined, this)
568
+ ]
569
+ }, undefined, true, undefined, this)
570
+ ]
571
+ }, undefined, true, undefined, this),
572
+ activeTab === "queries" && /* @__PURE__ */ jsxDEV("div", {
573
+ className: "border-border rounded-lg border",
574
+ children: /* @__PURE__ */ jsxDEV("table", {
575
+ className: "w-full",
576
+ children: [
577
+ /* @__PURE__ */ jsxDEV("thead", {
578
+ className: "border-border bg-muted/30 border-b",
579
+ children: /* @__PURE__ */ jsxDEV("tr", {
580
+ children: [
581
+ /* @__PURE__ */ jsxDEV("th", {
582
+ className: "px-4 py-3 text-left text-sm font-medium",
583
+ children: "Query"
584
+ }, undefined, false, undefined, this),
585
+ /* @__PURE__ */ jsxDEV("th", {
586
+ className: "px-4 py-3 text-left text-sm font-medium",
587
+ children: "Type"
588
+ }, undefined, false, undefined, this),
589
+ /* @__PURE__ */ jsxDEV("th", {
590
+ className: "px-4 py-3 text-left text-sm font-medium",
591
+ children: "Cache TTL"
592
+ }, undefined, false, undefined, this),
593
+ /* @__PURE__ */ jsxDEV("th", {
594
+ className: "px-4 py-3 text-left text-sm font-medium",
595
+ children: "Shared"
596
+ }, undefined, false, undefined, this)
597
+ ]
598
+ }, undefined, true, undefined, this)
599
+ }, undefined, false, undefined, this),
600
+ /* @__PURE__ */ jsxDEV("tbody", {
601
+ className: "divide-border divide-y",
602
+ children: [
603
+ queries.map((query) => /* @__PURE__ */ jsxDEV("tr", {
604
+ className: "hover:bg-muted/50",
605
+ children: [
606
+ /* @__PURE__ */ jsxDEV("td", {
607
+ className: "px-4 py-3",
608
+ children: [
609
+ /* @__PURE__ */ jsxDEV("div", {
610
+ className: "font-medium",
611
+ children: query.name
612
+ }, undefined, false, undefined, this),
613
+ /* @__PURE__ */ jsxDEV("div", {
614
+ className: "text-muted-foreground text-sm",
615
+ children: query.description
616
+ }, undefined, false, undefined, this)
617
+ ]
618
+ }, undefined, true, undefined, this),
619
+ /* @__PURE__ */ jsxDEV("td", {
620
+ className: "px-4 py-3",
621
+ children: /* @__PURE__ */ jsxDEV("span", {
622
+ className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${QUERY_TYPE_COLORS[query.type] ?? ""}`,
623
+ children: query.type
624
+ }, undefined, false, undefined, this)
625
+ }, undefined, false, undefined, this),
626
+ /* @__PURE__ */ jsxDEV("td", {
627
+ className: "text-muted-foreground px-4 py-3 text-sm",
628
+ children: [
629
+ query.cacheTtlSeconds,
630
+ "s"
631
+ ]
632
+ }, undefined, true, undefined, this),
633
+ /* @__PURE__ */ jsxDEV("td", {
634
+ className: "px-4 py-3",
635
+ children: query.isShared ? /* @__PURE__ */ jsxDEV("span", {
636
+ className: "text-green-600 dark:text-green-400",
637
+ children: "✓"
638
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV("span", {
639
+ className: "text-muted-foreground",
640
+ children: "—"
641
+ }, undefined, false, undefined, this)
642
+ }, undefined, false, undefined, this)
643
+ ]
644
+ }, query.id, true, undefined, this)),
645
+ queries.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
646
+ children: /* @__PURE__ */ jsxDEV("td", {
647
+ colSpan: 4,
648
+ className: "text-muted-foreground px-4 py-8 text-center",
649
+ children: "No queries saved"
650
+ }, undefined, false, undefined, this)
651
+ }, undefined, false, undefined, this)
652
+ ]
653
+ }, undefined, true, undefined, this)
654
+ ]
655
+ }, undefined, true, undefined, this)
656
+ }, undefined, false, undefined, this)
657
+ ]
658
+ }, undefined, true, undefined, this)
659
+ ]
660
+ }, undefined, true, undefined, this);
661
+ }
662
+
663
+ // src/ui/hooks/index.ts
664
+ "use client";
665
+ export {
666
+ useAnalyticsData,
667
+ queryBuilderMarkdownRenderer,
668
+ dashboardListMarkdownRenderer,
669
+ analyticsDashboardMarkdownRenderer,
670
+ AnalyticsDashboard
671
+ };