@contractspec/example.analytics-dashboard 1.57.0 → 1.59.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
@@ -1,265 +1,395 @@
1
- 'use client';
2
-
3
- import { useAnalyticsData } from "./hooks/useAnalyticsData.js";
4
- import { useState } from "react";
5
- import { Button, ErrorState, LoaderBlock, StatCard, StatCardGroup } from "@contractspec/lib.design-system";
6
- import { jsx, jsxs } from "react/jsx-runtime";
1
+ // @bun
2
+ // src/ui/hooks/useAnalyticsData.ts
3
+ import { useCallback, useEffect, useState } from "react";
4
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
5
+ "use client";
6
+ function useAnalyticsData(projectId = "local-project") {
7
+ const { handlers } = useTemplateRuntime();
8
+ const analytics = handlers.analytics;
9
+ const [dashboards, setDashboards] = useState([]);
10
+ const [queries, setQueries] = useState([]);
11
+ const [selectedDashboard, setSelectedDashboard] = useState(null);
12
+ const [widgets, setWidgets] = useState([]);
13
+ const [loading, setLoading] = useState(true);
14
+ const [error, setError] = useState(null);
15
+ const fetchData = useCallback(async () => {
16
+ try {
17
+ setLoading(true);
18
+ setError(null);
19
+ const [dashResult, queryResult] = await Promise.all([
20
+ analytics.listDashboards({ projectId, limit: 100 }),
21
+ analytics.listQueries({ projectId, limit: 100 })
22
+ ]);
23
+ setDashboards(dashResult.dashboards);
24
+ setQueries(queryResult.queries);
25
+ if (dashResult.dashboards.length > 0 && !selectedDashboard) {
26
+ const first = dashResult.dashboards[0];
27
+ if (first) {
28
+ setSelectedDashboard(first);
29
+ const dashboardWidgets = await analytics.getWidgets(first.id);
30
+ setWidgets(dashboardWidgets);
31
+ }
32
+ }
33
+ } catch (err) {
34
+ setError(err instanceof Error ? err : new Error("Failed to load analytics"));
35
+ } finally {
36
+ setLoading(false);
37
+ }
38
+ }, [analytics, projectId, selectedDashboard]);
39
+ useEffect(() => {
40
+ fetchData();
41
+ }, [fetchData]);
42
+ const selectDashboard = useCallback(async (dashboard) => {
43
+ setSelectedDashboard(dashboard);
44
+ const dashboardWidgets = await analytics.getWidgets(dashboard.id);
45
+ setWidgets(dashboardWidgets);
46
+ }, [analytics]);
47
+ const stats = {
48
+ totalDashboards: dashboards.length,
49
+ publishedDashboards: dashboards.filter((d) => d.status === "PUBLISHED").length,
50
+ totalQueries: queries.length,
51
+ sharedQueries: queries.filter((q) => q.isShared).length
52
+ };
53
+ return {
54
+ dashboards,
55
+ queries,
56
+ selectedDashboard,
57
+ widgets,
58
+ loading,
59
+ error,
60
+ stats,
61
+ refetch: fetchData,
62
+ selectDashboard
63
+ };
64
+ }
7
65
 
8
- //#region src/ui/AnalyticsDashboard.tsx
9
- /**
10
- * Analytics Dashboard
11
- *
12
- * Interactive dashboard for the analytics-dashboard template.
13
- * Displays dashboards, widgets, and queries.
14
- */
15
- const STATUS_COLORS = {
16
- PUBLISHED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
17
- DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
18
- ARCHIVED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"
66
+ // src/ui/AnalyticsDashboard.tsx
67
+ import { useState as useState2 } from "react";
68
+ import {
69
+ Button,
70
+ ErrorState,
71
+ LoaderBlock,
72
+ StatCard,
73
+ StatCardGroup
74
+ } from "@contractspec/lib.design-system";
75
+ import { jsxDEV } from "react/jsx-dev-runtime";
76
+ "use client";
77
+ var STATUS_COLORS = {
78
+ PUBLISHED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
79
+ DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
80
+ ARCHIVED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"
19
81
  };
20
- const WIDGET_ICONS = {
21
- LINE_CHART: "📈",
22
- BAR_CHART: "📊",
23
- PIE_CHART: "🥧",
24
- AREA_CHART: "📉",
25
- SCATTER_PLOT: "",
26
- METRIC: "🔢",
27
- TABLE: "📋",
28
- HEATMAP: "🗺️",
29
- FUNNEL: "",
30
- MAP: "🌍",
31
- TEXT: "📝",
32
- EMBED: "🔗"
82
+ var WIDGET_ICONS = {
83
+ LINE_CHART: "\uD83D\uDCC8",
84
+ BAR_CHART: "\uD83D\uDCCA",
85
+ PIE_CHART: "\uD83E\uDD67",
86
+ AREA_CHART: "\uD83D\uDCC9",
87
+ SCATTER_PLOT: "\u26AC",
88
+ METRIC: "\uD83D\uDD22",
89
+ TABLE: "\uD83D\uDCCB",
90
+ HEATMAP: "\uD83D\uDDFA\uFE0F",
91
+ FUNNEL: "\u23EC",
92
+ MAP: "\uD83C\uDF0D",
93
+ TEXT: "\uD83D\uDCDD",
94
+ EMBED: "\uD83D\uDD17"
33
95
  };
34
- const QUERY_TYPE_COLORS = {
35
- SQL: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
36
- METRIC: "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",
37
- AGGREGATION: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
38
- CUSTOM: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"
96
+ var QUERY_TYPE_COLORS = {
97
+ SQL: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
98
+ METRIC: "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",
99
+ AGGREGATION: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
100
+ CUSTOM: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"
39
101
  };
40
102
  function AnalyticsDashboard() {
41
- const [activeTab, setActiveTab] = useState("dashboards");
42
- const { dashboards, queries, selectedDashboard, widgets, loading, error, stats, refetch, selectDashboard } = useAnalyticsData();
43
- const tabs = [{
44
- id: "dashboards",
45
- label: "Dashboards",
46
- icon: "📊"
47
- }, {
48
- id: "queries",
49
- label: "Queries",
50
- icon: "🔍"
51
- }];
52
- if (loading) return /* @__PURE__ */ jsx(LoaderBlock, { label: "Loading Analytics..." });
53
- if (error) return /* @__PURE__ */ jsx(ErrorState, {
54
- title: "Failed to load Analytics",
55
- description: error.message,
56
- onRetry: refetch,
57
- retryLabel: "Retry"
58
- });
59
- return /* @__PURE__ */ jsxs("div", {
60
- className: "space-y-6",
61
- children: [
62
- /* @__PURE__ */ jsxs("div", {
63
- className: "flex items-center justify-between",
64
- children: [/* @__PURE__ */ jsx("h2", {
65
- className: "text-2xl font-bold",
66
- children: "Analytics Dashboard"
67
- }), /* @__PURE__ */ jsxs(Button, {
68
- onClick: () => alert("Create dashboard modal"),
69
- children: [/* @__PURE__ */ jsx("span", {
70
- className: "mr-2",
71
- children: "+"
72
- }), " New Dashboard"]
73
- })]
74
- }),
75
- /* @__PURE__ */ jsxs(StatCardGroup, { children: [
76
- /* @__PURE__ */ jsx(StatCard, {
77
- label: "Dashboards",
78
- value: stats.totalDashboards,
79
- hint: `${stats.publishedDashboards} published`
80
- }),
81
- /* @__PURE__ */ jsx(StatCard, {
82
- label: "Queries",
83
- value: stats.totalQueries,
84
- hint: `${stats.sharedQueries} shared`
85
- }),
86
- /* @__PURE__ */ jsx(StatCard, {
87
- label: "Widgets",
88
- value: widgets.length,
89
- hint: "on current dashboard"
90
- })
91
- ] }),
92
- /* @__PURE__ */ jsx("nav", {
93
- className: "bg-muted flex gap-1 rounded-lg p-1",
94
- role: "tablist",
95
- children: tabs.map((tab) => /* @__PURE__ */ jsxs(Button, {
96
- type: "button",
97
- role: "tab",
98
- "aria-selected": activeTab === tab.id,
99
- onClick: () => setActiveTab(tab.id),
100
- 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"}`,
101
- children: [/* @__PURE__ */ jsx("span", { children: tab.icon }), tab.label]
102
- }, tab.id))
103
- }),
104
- /* @__PURE__ */ jsxs("div", {
105
- className: "min-h-[400px]",
106
- role: "tabpanel",
107
- children: [activeTab === "dashboards" && /* @__PURE__ */ jsxs("div", {
108
- className: "space-y-6",
109
- children: [/* @__PURE__ */ jsxs("div", {
110
- className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
111
- children: [dashboards.map((dashboard) => /* @__PURE__ */ jsxs("div", {
112
- onClick: () => selectDashboard(dashboard),
113
- 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"}`,
114
- role: "button",
115
- tabIndex: 0,
116
- onKeyDown: (e) => {
117
- if (e.key === "Enter" || e.key === " ") selectDashboard(dashboard);
118
- },
119
- children: [
120
- /* @__PURE__ */ jsxs("div", {
121
- className: "mb-2 flex items-center justify-between",
122
- children: [/* @__PURE__ */ jsx("h3", {
123
- className: "font-medium",
124
- children: dashboard.name
125
- }), /* @__PURE__ */ jsx("span", {
126
- className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[dashboard.status] ?? ""}`,
127
- children: dashboard.status
128
- })]
129
- }),
130
- /* @__PURE__ */ jsx("p", {
131
- className: "text-muted-foreground mb-3 text-sm",
132
- children: dashboard.description
133
- }),
134
- /* @__PURE__ */ jsxs("div", {
135
- className: "text-muted-foreground flex items-center justify-between text-xs",
136
- children: [/* @__PURE__ */ jsxs("span", { children: ["/", dashboard.slug] }), dashboard.isPublic && /* @__PURE__ */ jsx("span", {
137
- className: "text-green-600 dark:text-green-400",
138
- children: "🌐 Public"
139
- })]
140
- })
141
- ]
142
- }, dashboard.id)), dashboards.length === 0 && /* @__PURE__ */ jsx("div", {
143
- className: "text-muted-foreground col-span-full flex h-64 items-center justify-center",
144
- children: "No dashboards created yet"
145
- })]
146
- }), selectedDashboard && widgets.length > 0 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("h3", {
147
- className: "mb-4 text-lg font-semibold",
148
- children: [
149
- "Widgets in \"",
150
- selectedDashboard.name,
151
- "\""
152
- ]
153
- }), /* @__PURE__ */ jsx("div", {
154
- className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
155
- children: widgets.map((widget) => /* @__PURE__ */ jsxs("div", {
156
- className: "border-border bg-card rounded-lg border p-4",
157
- children: [
158
- /* @__PURE__ */ jsxs("div", {
159
- className: "mb-2 flex items-center gap-2",
160
- children: [/* @__PURE__ */ jsx("span", {
161
- className: "text-xl",
162
- children: WIDGET_ICONS[widget.type] ?? "📊"
163
- }), /* @__PURE__ */ jsx("span", {
164
- className: "font-medium",
165
- children: widget.name
166
- })]
167
- }),
168
- /* @__PURE__ */ jsx("div", {
169
- className: "text-muted-foreground text-sm",
170
- children: widget.type.replace(/_/g, " ")
171
- }),
172
- /* @__PURE__ */ jsxs("div", {
173
- className: "text-muted-foreground mt-2 text-xs",
174
- children: [
175
- "Position: (",
176
- widget.gridX,
177
- ", ",
178
- widget.gridY,
179
- ") •",
180
- " ",
181
- widget.gridWidth,
182
- "x",
183
- widget.gridHeight
184
- ]
185
- })
186
- ]
187
- }, widget.id))
188
- })] })]
189
- }), activeTab === "queries" && /* @__PURE__ */ jsx("div", {
190
- className: "border-border rounded-lg border",
191
- children: /* @__PURE__ */ jsxs("table", {
192
- className: "w-full",
193
- children: [/* @__PURE__ */ jsx("thead", {
194
- className: "border-border bg-muted/30 border-b",
195
- children: /* @__PURE__ */ jsxs("tr", { children: [
196
- /* @__PURE__ */ jsx("th", {
197
- className: "px-4 py-3 text-left text-sm font-medium",
198
- children: "Query"
199
- }),
200
- /* @__PURE__ */ jsx("th", {
201
- className: "px-4 py-3 text-left text-sm font-medium",
202
- children: "Type"
203
- }),
204
- /* @__PURE__ */ jsx("th", {
205
- className: "px-4 py-3 text-left text-sm font-medium",
206
- children: "Cache TTL"
207
- }),
208
- /* @__PURE__ */ jsx("th", {
209
- className: "px-4 py-3 text-left text-sm font-medium",
210
- children: "Shared"
211
- })
212
- ] })
213
- }), /* @__PURE__ */ jsxs("tbody", {
214
- className: "divide-border divide-y",
215
- children: [queries.map((query) => /* @__PURE__ */ jsxs("tr", {
216
- className: "hover:bg-muted/50",
217
- children: [
218
- /* @__PURE__ */ jsxs("td", {
219
- className: "px-4 py-3",
220
- children: [/* @__PURE__ */ jsx("div", {
221
- className: "font-medium",
222
- children: query.name
223
- }), /* @__PURE__ */ jsx("div", {
224
- className: "text-muted-foreground text-sm",
225
- children: query.description
226
- })]
227
- }),
228
- /* @__PURE__ */ jsx("td", {
229
- className: "px-4 py-3",
230
- children: /* @__PURE__ */ jsx("span", {
231
- className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${QUERY_TYPE_COLORS[query.type] ?? ""}`,
232
- children: query.type
233
- })
234
- }),
235
- /* @__PURE__ */ jsxs("td", {
236
- className: "text-muted-foreground px-4 py-3 text-sm",
237
- children: [query.cacheTtlSeconds, "s"]
238
- }),
239
- /* @__PURE__ */ jsx("td", {
240
- className: "px-4 py-3",
241
- children: query.isShared ? /* @__PURE__ */ jsx("span", {
242
- className: "text-green-600 dark:text-green-400",
243
- children: ""
244
- }) : /* @__PURE__ */ jsx("span", {
245
- className: "text-muted-foreground",
246
- children: ""
247
- })
248
- })
249
- ]
250
- }, query.id)), queries.length === 0 && /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", {
251
- colSpan: 4,
252
- className: "text-muted-foreground px-4 py-8 text-center",
253
- children: "No queries saved"
254
- }) })]
255
- })]
256
- })
257
- })]
258
- })
259
- ]
260
- });
103
+ const [activeTab, setActiveTab] = useState2("dashboards");
104
+ const {
105
+ dashboards,
106
+ queries,
107
+ selectedDashboard,
108
+ widgets,
109
+ loading,
110
+ error,
111
+ stats,
112
+ refetch,
113
+ selectDashboard
114
+ } = useAnalyticsData();
115
+ const tabs = [
116
+ { id: "dashboards", label: "Dashboards", icon: "\uD83D\uDCCA" },
117
+ { id: "queries", label: "Queries", icon: "\uD83D\uDD0D" }
118
+ ];
119
+ if (loading) {
120
+ return /* @__PURE__ */ jsxDEV(LoaderBlock, {
121
+ label: "Loading Analytics..."
122
+ }, undefined, false, undefined, this);
123
+ }
124
+ if (error) {
125
+ return /* @__PURE__ */ jsxDEV(ErrorState, {
126
+ title: "Failed to load Analytics",
127
+ description: error.message,
128
+ onRetry: refetch,
129
+ retryLabel: "Retry"
130
+ }, undefined, false, undefined, this);
131
+ }
132
+ return /* @__PURE__ */ jsxDEV("div", {
133
+ className: "space-y-6",
134
+ children: [
135
+ /* @__PURE__ */ jsxDEV("div", {
136
+ className: "flex items-center justify-between",
137
+ children: [
138
+ /* @__PURE__ */ jsxDEV("h2", {
139
+ className: "text-2xl font-bold",
140
+ children: "Analytics Dashboard"
141
+ }, undefined, false, undefined, this),
142
+ /* @__PURE__ */ jsxDEV(Button, {
143
+ onClick: () => alert("Create dashboard modal"),
144
+ children: [
145
+ /* @__PURE__ */ jsxDEV("span", {
146
+ className: "mr-2",
147
+ children: "+"
148
+ }, undefined, false, undefined, this),
149
+ " New Dashboard"
150
+ ]
151
+ }, undefined, true, undefined, this)
152
+ ]
153
+ }, undefined, true, undefined, this),
154
+ /* @__PURE__ */ jsxDEV(StatCardGroup, {
155
+ children: [
156
+ /* @__PURE__ */ jsxDEV(StatCard, {
157
+ label: "Dashboards",
158
+ value: stats.totalDashboards,
159
+ hint: `${stats.publishedDashboards} published`
160
+ }, undefined, false, undefined, this),
161
+ /* @__PURE__ */ jsxDEV(StatCard, {
162
+ label: "Queries",
163
+ value: stats.totalQueries,
164
+ hint: `${stats.sharedQueries} shared`
165
+ }, undefined, false, undefined, this),
166
+ /* @__PURE__ */ jsxDEV(StatCard, {
167
+ label: "Widgets",
168
+ value: widgets.length,
169
+ hint: "on current dashboard"
170
+ }, undefined, false, undefined, this)
171
+ ]
172
+ }, undefined, true, undefined, this),
173
+ /* @__PURE__ */ jsxDEV("nav", {
174
+ className: "bg-muted flex gap-1 rounded-lg p-1",
175
+ role: "tablist",
176
+ children: tabs.map((tab) => /* @__PURE__ */ jsxDEV(Button, {
177
+ type: "button",
178
+ role: "tab",
179
+ "aria-selected": activeTab === tab.id,
180
+ onClick: () => setActiveTab(tab.id),
181
+ 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"}`,
182
+ children: [
183
+ /* @__PURE__ */ jsxDEV("span", {
184
+ children: tab.icon
185
+ }, undefined, false, undefined, this),
186
+ tab.label
187
+ ]
188
+ }, tab.id, true, undefined, this))
189
+ }, undefined, false, undefined, this),
190
+ /* @__PURE__ */ jsxDEV("div", {
191
+ className: "min-h-[400px]",
192
+ role: "tabpanel",
193
+ children: [
194
+ activeTab === "dashboards" && /* @__PURE__ */ jsxDEV("div", {
195
+ className: "space-y-6",
196
+ children: [
197
+ /* @__PURE__ */ jsxDEV("div", {
198
+ className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
199
+ children: [
200
+ dashboards.map((dashboard) => /* @__PURE__ */ jsxDEV("div", {
201
+ onClick: () => selectDashboard(dashboard),
202
+ 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"}`,
203
+ role: "button",
204
+ tabIndex: 0,
205
+ onKeyDown: (e) => {
206
+ if (e.key === "Enter" || e.key === " ")
207
+ selectDashboard(dashboard);
208
+ },
209
+ children: [
210
+ /* @__PURE__ */ jsxDEV("div", {
211
+ className: "mb-2 flex items-center justify-between",
212
+ children: [
213
+ /* @__PURE__ */ jsxDEV("h3", {
214
+ className: "font-medium",
215
+ children: dashboard.name
216
+ }, undefined, false, undefined, this),
217
+ /* @__PURE__ */ jsxDEV("span", {
218
+ className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[dashboard.status] ?? ""}`,
219
+ children: dashboard.status
220
+ }, undefined, false, undefined, this)
221
+ ]
222
+ }, undefined, true, undefined, this),
223
+ /* @__PURE__ */ jsxDEV("p", {
224
+ className: "text-muted-foreground mb-3 text-sm",
225
+ children: dashboard.description
226
+ }, undefined, false, undefined, this),
227
+ /* @__PURE__ */ jsxDEV("div", {
228
+ className: "text-muted-foreground flex items-center justify-between text-xs",
229
+ children: [
230
+ /* @__PURE__ */ jsxDEV("span", {
231
+ children: [
232
+ "/",
233
+ dashboard.slug
234
+ ]
235
+ }, undefined, true, undefined, this),
236
+ dashboard.isPublic && /* @__PURE__ */ jsxDEV("span", {
237
+ className: "text-green-600 dark:text-green-400",
238
+ children: "\uD83C\uDF10 Public"
239
+ }, undefined, false, undefined, this)
240
+ ]
241
+ }, undefined, true, undefined, this)
242
+ ]
243
+ }, dashboard.id, true, undefined, this)),
244
+ dashboards.length === 0 && /* @__PURE__ */ jsxDEV("div", {
245
+ className: "text-muted-foreground col-span-full flex h-64 items-center justify-center",
246
+ children: "No dashboards created yet"
247
+ }, undefined, false, undefined, this)
248
+ ]
249
+ }, undefined, true, undefined, this),
250
+ selectedDashboard && widgets.length > 0 && /* @__PURE__ */ jsxDEV("div", {
251
+ children: [
252
+ /* @__PURE__ */ jsxDEV("h3", {
253
+ className: "mb-4 text-lg font-semibold",
254
+ children: [
255
+ 'Widgets in "',
256
+ selectedDashboard.name,
257
+ '"'
258
+ ]
259
+ }, undefined, true, undefined, this),
260
+ /* @__PURE__ */ jsxDEV("div", {
261
+ className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
262
+ children: widgets.map((widget) => /* @__PURE__ */ jsxDEV("div", {
263
+ className: "border-border bg-card rounded-lg border p-4",
264
+ children: [
265
+ /* @__PURE__ */ jsxDEV("div", {
266
+ className: "mb-2 flex items-center gap-2",
267
+ children: [
268
+ /* @__PURE__ */ jsxDEV("span", {
269
+ className: "text-xl",
270
+ children: WIDGET_ICONS[widget.type] ?? "\uD83D\uDCCA"
271
+ }, undefined, false, undefined, this),
272
+ /* @__PURE__ */ jsxDEV("span", {
273
+ className: "font-medium",
274
+ children: widget.name
275
+ }, undefined, false, undefined, this)
276
+ ]
277
+ }, undefined, true, undefined, this),
278
+ /* @__PURE__ */ jsxDEV("div", {
279
+ className: "text-muted-foreground text-sm",
280
+ children: widget.type.replace(/_/g, " ")
281
+ }, undefined, false, undefined, this),
282
+ /* @__PURE__ */ jsxDEV("div", {
283
+ className: "text-muted-foreground mt-2 text-xs",
284
+ children: [
285
+ "Position: (",
286
+ widget.gridX,
287
+ ", ",
288
+ widget.gridY,
289
+ ") \u2022",
290
+ " ",
291
+ widget.gridWidth,
292
+ "x",
293
+ widget.gridHeight
294
+ ]
295
+ }, undefined, true, undefined, this)
296
+ ]
297
+ }, widget.id, true, undefined, this))
298
+ }, undefined, false, undefined, this)
299
+ ]
300
+ }, undefined, true, undefined, this)
301
+ ]
302
+ }, undefined, true, undefined, this),
303
+ activeTab === "queries" && /* @__PURE__ */ jsxDEV("div", {
304
+ className: "border-border rounded-lg border",
305
+ children: /* @__PURE__ */ jsxDEV("table", {
306
+ className: "w-full",
307
+ children: [
308
+ /* @__PURE__ */ jsxDEV("thead", {
309
+ className: "border-border bg-muted/30 border-b",
310
+ children: /* @__PURE__ */ jsxDEV("tr", {
311
+ children: [
312
+ /* @__PURE__ */ jsxDEV("th", {
313
+ className: "px-4 py-3 text-left text-sm font-medium",
314
+ children: "Query"
315
+ }, undefined, false, undefined, this),
316
+ /* @__PURE__ */ jsxDEV("th", {
317
+ className: "px-4 py-3 text-left text-sm font-medium",
318
+ children: "Type"
319
+ }, undefined, false, undefined, this),
320
+ /* @__PURE__ */ jsxDEV("th", {
321
+ className: "px-4 py-3 text-left text-sm font-medium",
322
+ children: "Cache TTL"
323
+ }, undefined, false, undefined, this),
324
+ /* @__PURE__ */ jsxDEV("th", {
325
+ className: "px-4 py-3 text-left text-sm font-medium",
326
+ children: "Shared"
327
+ }, undefined, false, undefined, this)
328
+ ]
329
+ }, undefined, true, undefined, this)
330
+ }, undefined, false, undefined, this),
331
+ /* @__PURE__ */ jsxDEV("tbody", {
332
+ className: "divide-border divide-y",
333
+ children: [
334
+ queries.map((query) => /* @__PURE__ */ jsxDEV("tr", {
335
+ className: "hover:bg-muted/50",
336
+ children: [
337
+ /* @__PURE__ */ jsxDEV("td", {
338
+ className: "px-4 py-3",
339
+ children: [
340
+ /* @__PURE__ */ jsxDEV("div", {
341
+ className: "font-medium",
342
+ children: query.name
343
+ }, undefined, false, undefined, this),
344
+ /* @__PURE__ */ jsxDEV("div", {
345
+ className: "text-muted-foreground text-sm",
346
+ children: query.description
347
+ }, undefined, false, undefined, this)
348
+ ]
349
+ }, undefined, true, undefined, this),
350
+ /* @__PURE__ */ jsxDEV("td", {
351
+ className: "px-4 py-3",
352
+ children: /* @__PURE__ */ jsxDEV("span", {
353
+ className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${QUERY_TYPE_COLORS[query.type] ?? ""}`,
354
+ children: query.type
355
+ }, undefined, false, undefined, this)
356
+ }, undefined, false, undefined, this),
357
+ /* @__PURE__ */ jsxDEV("td", {
358
+ className: "text-muted-foreground px-4 py-3 text-sm",
359
+ children: [
360
+ query.cacheTtlSeconds,
361
+ "s"
362
+ ]
363
+ }, undefined, true, undefined, this),
364
+ /* @__PURE__ */ jsxDEV("td", {
365
+ className: "px-4 py-3",
366
+ children: query.isShared ? /* @__PURE__ */ jsxDEV("span", {
367
+ className: "text-green-600 dark:text-green-400",
368
+ children: "\u2713"
369
+ }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV("span", {
370
+ className: "text-muted-foreground",
371
+ children: "\u2014"
372
+ }, undefined, false, undefined, this)
373
+ }, undefined, false, undefined, this)
374
+ ]
375
+ }, query.id, true, undefined, this)),
376
+ queries.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
377
+ children: /* @__PURE__ */ jsxDEV("td", {
378
+ colSpan: 4,
379
+ className: "text-muted-foreground px-4 py-8 text-center",
380
+ children: "No queries saved"
381
+ }, undefined, false, undefined, this)
382
+ }, undefined, false, undefined, this)
383
+ ]
384
+ }, undefined, true, undefined, this)
385
+ ]
386
+ }, undefined, true, undefined, this)
387
+ }, undefined, false, undefined, this)
388
+ ]
389
+ }, undefined, true, undefined, this)
390
+ ]
391
+ }, undefined, true, undefined, this);
261
392
  }
262
-
263
- //#endregion
264
- export { AnalyticsDashboard };
265
- //# sourceMappingURL=AnalyticsDashboard.js.map
393
+ export {
394
+ AnalyticsDashboard
395
+ };