@contractspec/example.analytics-dashboard 3.7.6 → 3.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -271
- package/dist/browser/dashboard.feature.js +592 -0
- package/dist/browser/docs/analytics-dashboard.docblock.js +2 -1
- package/dist/browser/docs/index.js +2 -1
- package/dist/browser/events.js +1 -1
- package/dist/browser/index.js +1260 -627
- package/dist/browser/ui/AnalyticsDashboard.js +915 -194
- package/dist/browser/ui/AnalyticsDashboard.widgets.js +94 -0
- package/dist/browser/ui/AnalyticsQueriesTable.js +188 -0
- package/dist/browser/ui/hooks/index.js +594 -3
- package/dist/browser/ui/hooks/useAnalyticsData.js +594 -3
- package/dist/browser/ui/index.js +1053 -440
- package/dist/browser/ui/renderers/analytics.markdown.js +620 -138
- package/dist/browser/ui/renderers/index.js +620 -138
- package/dist/browser/visualizations/catalog.js +457 -0
- package/dist/browser/visualizations/index.js +611 -0
- package/dist/browser/visualizations/specs.breakdown.js +140 -0
- package/dist/browser/visualizations/specs.performance.js +198 -0
- package/dist/browser/visualizations/widgets.js +595 -0
- package/dist/dashboard/index.d.ts +3 -3
- package/dist/dashboard.feature.js +592 -0
- package/dist/docs/analytics-dashboard.docblock.js +2 -1
- package/dist/docs/index.js +2 -1
- package/dist/events.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1260 -627
- package/dist/node/dashboard.feature.js +592 -0
- package/dist/node/docs/analytics-dashboard.docblock.js +2 -1
- package/dist/node/docs/index.js +2 -1
- package/dist/node/events.js +1 -1
- package/dist/node/index.js +1260 -627
- package/dist/node/ui/AnalyticsDashboard.js +915 -194
- package/dist/node/ui/AnalyticsDashboard.widgets.js +94 -0
- package/dist/node/ui/AnalyticsQueriesTable.js +188 -0
- package/dist/node/ui/hooks/index.js +594 -3
- package/dist/node/ui/hooks/useAnalyticsData.js +594 -3
- package/dist/node/ui/index.js +1053 -440
- package/dist/node/ui/renderers/analytics.markdown.js +620 -138
- package/dist/node/ui/renderers/index.js +620 -138
- package/dist/node/visualizations/catalog.js +457 -0
- package/dist/node/visualizations/index.js +611 -0
- package/dist/node/visualizations/specs.breakdown.js +140 -0
- package/dist/node/visualizations/specs.performance.js +198 -0
- package/dist/node/visualizations/widgets.js +595 -0
- package/dist/query/index.d.ts +1 -1
- package/dist/query-engine/index.d.ts +1 -1
- package/dist/ui/AnalyticsDashboard.js +915 -194
- package/dist/ui/AnalyticsDashboard.widgets.d.ts +5 -0
- package/dist/ui/AnalyticsDashboard.widgets.js +95 -0
- package/dist/ui/AnalyticsQueriesTable.d.ts +4 -0
- package/dist/ui/AnalyticsQueriesTable.js +189 -0
- package/dist/ui/AnalyticsQueriesTable.smoke.test.d.ts +1 -0
- package/dist/ui/hooks/index.d.ts +1 -1
- package/dist/ui/hooks/index.js +594 -3
- package/dist/ui/hooks/useAnalyticsData.js +594 -3
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +1053 -440
- package/dist/ui/renderers/analytics.markdown.d.ts +0 -9
- package/dist/ui/renderers/analytics.markdown.js +620 -138
- package/dist/ui/renderers/index.js +620 -138
- package/dist/visualizations/catalog.d.ts +9 -0
- package/dist/visualizations/catalog.js +458 -0
- package/dist/visualizations/index.d.ts +4 -0
- package/dist/visualizations/index.js +612 -0
- package/dist/visualizations/specs.breakdown.d.ts +4 -0
- package/dist/visualizations/specs.breakdown.js +141 -0
- package/dist/visualizations/specs.performance.d.ts +5 -0
- package/dist/visualizations/specs.performance.js +199 -0
- package/dist/visualizations/widgets.d.ts +24 -0
- package/dist/visualizations/widgets.js +596 -0
- package/dist/visualizations/widgets.test.d.ts +1 -0
- package/package.json +111 -11
package/dist/browser/index.js
CHANGED
|
@@ -1,3 +1,594 @@
|
|
|
1
|
+
// src/visualizations/specs.breakdown.ts
|
|
2
|
+
import { defineVisualization } from "@contractspec/lib.contracts-spec/visualizations";
|
|
3
|
+
var QUERY_REF = { key: "analytics.query.execute", version: "1.0.0" };
|
|
4
|
+
var META = {
|
|
5
|
+
version: "1.0.0",
|
|
6
|
+
domain: "analytics",
|
|
7
|
+
stability: "experimental",
|
|
8
|
+
owners: ["@example.analytics-dashboard"],
|
|
9
|
+
tags: ["analytics", "dashboard", "visualization"]
|
|
10
|
+
};
|
|
11
|
+
var ChannelMixVisualization = defineVisualization({
|
|
12
|
+
meta: {
|
|
13
|
+
...META,
|
|
14
|
+
key: "analytics.visualization.channel-mix",
|
|
15
|
+
title: "Channel Mix",
|
|
16
|
+
description: "Session distribution across acquisition channels.",
|
|
17
|
+
goal: "Explain which channels currently drive the largest share of traffic.",
|
|
18
|
+
context: "Marketing attribution dashboard."
|
|
19
|
+
},
|
|
20
|
+
source: { primary: QUERY_REF, resultPath: "data" },
|
|
21
|
+
visualization: {
|
|
22
|
+
kind: "pie",
|
|
23
|
+
nameDimension: "channel",
|
|
24
|
+
valueMeasure: "sessions",
|
|
25
|
+
dimensions: [
|
|
26
|
+
{
|
|
27
|
+
key: "channel",
|
|
28
|
+
label: "Channel",
|
|
29
|
+
dataPath: "channel",
|
|
30
|
+
type: "category"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
measures: [{ key: "sessions", label: "Sessions", dataPath: "sessions" }],
|
|
34
|
+
table: { caption: "Sessions by acquisition channel." }
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
var EngagementHeatmapVisualization = defineVisualization({
|
|
38
|
+
meta: {
|
|
39
|
+
...META,
|
|
40
|
+
key: "analytics.visualization.engagement-heatmap",
|
|
41
|
+
title: "Engagement Heatmap",
|
|
42
|
+
description: "Average engagement score by weekday and time band.",
|
|
43
|
+
goal: "Reveal the highest-engagement time windows for product activity.",
|
|
44
|
+
context: "Usage analytics dashboard."
|
|
45
|
+
},
|
|
46
|
+
source: { primary: QUERY_REF, resultPath: "data" },
|
|
47
|
+
visualization: {
|
|
48
|
+
kind: "heatmap",
|
|
49
|
+
xDimension: "timeBand",
|
|
50
|
+
yDimension: "weekday",
|
|
51
|
+
valueMeasure: "engagementScore",
|
|
52
|
+
dimensions: [
|
|
53
|
+
{
|
|
54
|
+
key: "timeBand",
|
|
55
|
+
label: "Time Band",
|
|
56
|
+
dataPath: "timeBand",
|
|
57
|
+
type: "category"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: "weekday",
|
|
61
|
+
label: "Weekday",
|
|
62
|
+
dataPath: "weekday",
|
|
63
|
+
type: "category"
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
measures: [
|
|
67
|
+
{
|
|
68
|
+
key: "engagementScore",
|
|
69
|
+
label: "Engagement",
|
|
70
|
+
dataPath: "engagementScore"
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
table: { caption: "Engagement score by weekday and time band." }
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
var ConversionFunnelVisualization = defineVisualization({
|
|
77
|
+
meta: {
|
|
78
|
+
...META,
|
|
79
|
+
key: "analytics.visualization.conversion-funnel",
|
|
80
|
+
title: "Conversion Funnel",
|
|
81
|
+
description: "Progression through the main acquisition funnel.",
|
|
82
|
+
goal: "Show where the product is losing the largest share of prospects.",
|
|
83
|
+
context: "Growth dashboard."
|
|
84
|
+
},
|
|
85
|
+
source: { primary: QUERY_REF, resultPath: "data" },
|
|
86
|
+
visualization: {
|
|
87
|
+
kind: "funnel",
|
|
88
|
+
nameDimension: "stage",
|
|
89
|
+
valueMeasure: "users",
|
|
90
|
+
sort: "descending",
|
|
91
|
+
dimensions: [
|
|
92
|
+
{ key: "stage", label: "Stage", dataPath: "stage", type: "category" }
|
|
93
|
+
],
|
|
94
|
+
measures: [{ key: "users", label: "Users", dataPath: "users" }],
|
|
95
|
+
table: { caption: "Users per conversion stage." }
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
var AccountCoverageGeoVisualization = defineVisualization({
|
|
99
|
+
meta: {
|
|
100
|
+
...META,
|
|
101
|
+
key: "analytics.visualization.account-coverage-geo",
|
|
102
|
+
title: "Account Coverage",
|
|
103
|
+
description: "High-value accounts plotted on a slippy-map surface.",
|
|
104
|
+
goal: "Locate where active commercial concentration is strongest.",
|
|
105
|
+
context: "Territory coverage dashboard."
|
|
106
|
+
},
|
|
107
|
+
source: { primary: QUERY_REF, resultPath: "data" },
|
|
108
|
+
visualization: {
|
|
109
|
+
kind: "geo",
|
|
110
|
+
mode: "slippy-map",
|
|
111
|
+
variant: "scatter",
|
|
112
|
+
nameDimension: "city",
|
|
113
|
+
latitudeDimension: "latitude",
|
|
114
|
+
longitudeDimension: "longitude",
|
|
115
|
+
valueMeasure: "accounts",
|
|
116
|
+
dimensions: [
|
|
117
|
+
{ key: "city", label: "City", dataPath: "city", type: "category" },
|
|
118
|
+
{
|
|
119
|
+
key: "latitude",
|
|
120
|
+
label: "Latitude",
|
|
121
|
+
dataPath: "latitude",
|
|
122
|
+
type: "latitude"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
key: "longitude",
|
|
126
|
+
label: "Longitude",
|
|
127
|
+
dataPath: "longitude",
|
|
128
|
+
type: "longitude"
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
measures: [{ key: "accounts", label: "Accounts", dataPath: "accounts" }],
|
|
132
|
+
table: { caption: "Account concentration by city." }
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// src/visualizations/specs.performance.ts
|
|
137
|
+
import { defineVisualization as defineVisualization2 } from "@contractspec/lib.contracts-spec/visualizations";
|
|
138
|
+
var QUERY_REF2 = { key: "analytics.query.execute", version: "1.0.0" };
|
|
139
|
+
var META2 = {
|
|
140
|
+
version: "1.0.0",
|
|
141
|
+
domain: "analytics",
|
|
142
|
+
stability: "experimental",
|
|
143
|
+
owners: ["@example.analytics-dashboard"],
|
|
144
|
+
tags: ["analytics", "dashboard", "visualization"]
|
|
145
|
+
};
|
|
146
|
+
var RevenueMetricVisualization = defineVisualization2({
|
|
147
|
+
meta: {
|
|
148
|
+
...META2,
|
|
149
|
+
key: "analytics.visualization.revenue-metric",
|
|
150
|
+
title: "Revenue Snapshot",
|
|
151
|
+
description: "Current recurring revenue with prior-period comparison.",
|
|
152
|
+
goal: "Highlight the headline commercial metric for the dashboard.",
|
|
153
|
+
context: "Executive revenue overview."
|
|
154
|
+
},
|
|
155
|
+
source: { primary: QUERY_REF2, resultPath: "data" },
|
|
156
|
+
visualization: {
|
|
157
|
+
kind: "metric",
|
|
158
|
+
measure: "totalRevenue",
|
|
159
|
+
comparisonMeasure: "priorRevenue",
|
|
160
|
+
dimensions: [
|
|
161
|
+
{ key: "period", label: "Period", dataPath: "period", type: "time" }
|
|
162
|
+
],
|
|
163
|
+
measures: [
|
|
164
|
+
{
|
|
165
|
+
key: "totalRevenue",
|
|
166
|
+
label: "Revenue",
|
|
167
|
+
dataPath: "totalRevenue",
|
|
168
|
+
format: "currency"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
key: "priorRevenue",
|
|
172
|
+
label: "Prior Revenue",
|
|
173
|
+
dataPath: "priorRevenue",
|
|
174
|
+
format: "currency"
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
sparkline: { dimension: "period", measure: "totalRevenue" },
|
|
178
|
+
table: { caption: "Revenue trend and prior period values." }
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
var RevenueTrendVisualization = defineVisualization2({
|
|
182
|
+
meta: {
|
|
183
|
+
...META2,
|
|
184
|
+
key: "analytics.visualization.revenue-trend",
|
|
185
|
+
title: "Revenue Trend",
|
|
186
|
+
description: "Monthly revenue progression for the current quarter.",
|
|
187
|
+
goal: "Track whether revenue growth is accelerating or stalling.",
|
|
188
|
+
context: "Quarterly commercial dashboard."
|
|
189
|
+
},
|
|
190
|
+
source: { primary: QUERY_REF2, resultPath: "data" },
|
|
191
|
+
visualization: {
|
|
192
|
+
kind: "cartesian",
|
|
193
|
+
variant: "line",
|
|
194
|
+
xDimension: "date",
|
|
195
|
+
yMeasures: ["revenue"],
|
|
196
|
+
dimensions: [
|
|
197
|
+
{ key: "date", label: "Month", dataPath: "date", type: "time" }
|
|
198
|
+
],
|
|
199
|
+
measures: [
|
|
200
|
+
{
|
|
201
|
+
key: "revenue",
|
|
202
|
+
label: "Revenue",
|
|
203
|
+
dataPath: "revenue",
|
|
204
|
+
format: "currency",
|
|
205
|
+
color: "#0f766e"
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
thresholds: [
|
|
209
|
+
{ key: "target", value: 140000, label: "Target", color: "#dc2626" }
|
|
210
|
+
],
|
|
211
|
+
table: { caption: "Monthly revenue values." }
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
var RegionalRevenueVisualization = defineVisualization2({
|
|
215
|
+
meta: {
|
|
216
|
+
...META2,
|
|
217
|
+
key: "analytics.visualization.regional-revenue",
|
|
218
|
+
title: "Regional Revenue",
|
|
219
|
+
description: "Revenue split by sales territory.",
|
|
220
|
+
goal: "Compare the strongest and weakest performing territories.",
|
|
221
|
+
context: "Territory planning and commercial comparison."
|
|
222
|
+
},
|
|
223
|
+
source: { primary: QUERY_REF2, resultPath: "data" },
|
|
224
|
+
visualization: {
|
|
225
|
+
kind: "cartesian",
|
|
226
|
+
variant: "bar",
|
|
227
|
+
xDimension: "region",
|
|
228
|
+
yMeasures: ["revenue"],
|
|
229
|
+
dimensions: [
|
|
230
|
+
{ key: "region", label: "Region", dataPath: "region", type: "category" }
|
|
231
|
+
],
|
|
232
|
+
measures: [
|
|
233
|
+
{
|
|
234
|
+
key: "revenue",
|
|
235
|
+
label: "Revenue",
|
|
236
|
+
dataPath: "revenue",
|
|
237
|
+
format: "currency",
|
|
238
|
+
color: "#1d4ed8"
|
|
239
|
+
}
|
|
240
|
+
],
|
|
241
|
+
table: { caption: "Revenue by region." }
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
var RetentionAreaVisualization = defineVisualization2({
|
|
245
|
+
meta: {
|
|
246
|
+
...META2,
|
|
247
|
+
key: "analytics.visualization.retention-area",
|
|
248
|
+
title: "Retention Curve",
|
|
249
|
+
description: "Weekly retention progression across the active cohort.",
|
|
250
|
+
goal: "Show whether user retention remains above the desired floor.",
|
|
251
|
+
context: "Product health dashboard."
|
|
252
|
+
},
|
|
253
|
+
source: { primary: QUERY_REF2, resultPath: "data" },
|
|
254
|
+
visualization: {
|
|
255
|
+
kind: "cartesian",
|
|
256
|
+
variant: "area",
|
|
257
|
+
xDimension: "week",
|
|
258
|
+
yMeasures: ["retentionRate"],
|
|
259
|
+
dimensions: [
|
|
260
|
+
{ key: "week", label: "Week", dataPath: "week", type: "category" }
|
|
261
|
+
],
|
|
262
|
+
measures: [
|
|
263
|
+
{
|
|
264
|
+
key: "retentionRate",
|
|
265
|
+
label: "Retention",
|
|
266
|
+
dataPath: "retentionRate",
|
|
267
|
+
format: "percentage",
|
|
268
|
+
color: "#16a34a"
|
|
269
|
+
}
|
|
270
|
+
],
|
|
271
|
+
thresholds: [
|
|
272
|
+
{ key: "floor", value: 0.5, label: "Floor", color: "#f59e0b" }
|
|
273
|
+
],
|
|
274
|
+
table: { caption: "Weekly retention rate." }
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
var PipelineScatterVisualization = defineVisualization2({
|
|
278
|
+
meta: {
|
|
279
|
+
...META2,
|
|
280
|
+
key: "analytics.visualization.pipeline-scatter",
|
|
281
|
+
title: "Pipeline Velocity",
|
|
282
|
+
description: "Deal-cycle length against win rate for active accounts.",
|
|
283
|
+
goal: "Spot outliers where the sales cycle is long but conversion remains weak.",
|
|
284
|
+
context: "Commercial operations dashboard."
|
|
285
|
+
},
|
|
286
|
+
source: { primary: QUERY_REF2, resultPath: "data" },
|
|
287
|
+
visualization: {
|
|
288
|
+
kind: "cartesian",
|
|
289
|
+
variant: "scatter",
|
|
290
|
+
xDimension: "cycleDays",
|
|
291
|
+
yMeasures: ["winRate"],
|
|
292
|
+
dimensions: [
|
|
293
|
+
{
|
|
294
|
+
key: "cycleDays",
|
|
295
|
+
label: "Cycle Days",
|
|
296
|
+
dataPath: "cycleDays",
|
|
297
|
+
type: "number"
|
|
298
|
+
}
|
|
299
|
+
],
|
|
300
|
+
measures: [
|
|
301
|
+
{
|
|
302
|
+
key: "winRate",
|
|
303
|
+
label: "Win Rate",
|
|
304
|
+
dataPath: "winRate",
|
|
305
|
+
format: "percentage",
|
|
306
|
+
color: "#7c3aed"
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
key: "arr",
|
|
310
|
+
label: "ARR",
|
|
311
|
+
dataPath: "arr",
|
|
312
|
+
format: "currency"
|
|
313
|
+
}
|
|
314
|
+
],
|
|
315
|
+
series: [
|
|
316
|
+
{
|
|
317
|
+
key: "pipeline",
|
|
318
|
+
label: "Accounts",
|
|
319
|
+
measure: "winRate",
|
|
320
|
+
type: "scatter",
|
|
321
|
+
color: "#7c3aed"
|
|
322
|
+
}
|
|
323
|
+
],
|
|
324
|
+
table: { caption: "Sales cycle and win rate per account." }
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// src/visualizations/catalog.ts
|
|
329
|
+
import { VisualizationRegistry } from "@contractspec/lib.contracts-spec/visualizations";
|
|
330
|
+
var AnalyticsVisualizationSpecs = [
|
|
331
|
+
RevenueMetricVisualization,
|
|
332
|
+
RevenueTrendVisualization,
|
|
333
|
+
RegionalRevenueVisualization,
|
|
334
|
+
RetentionAreaVisualization,
|
|
335
|
+
PipelineScatterVisualization,
|
|
336
|
+
ChannelMixVisualization,
|
|
337
|
+
EngagementHeatmapVisualization,
|
|
338
|
+
ConversionFunnelVisualization,
|
|
339
|
+
AccountCoverageGeoVisualization
|
|
340
|
+
];
|
|
341
|
+
var AnalyticsVisualizationRegistry = new VisualizationRegistry([
|
|
342
|
+
...AnalyticsVisualizationSpecs
|
|
343
|
+
]);
|
|
344
|
+
var AnalyticsVisualizationRefs = AnalyticsVisualizationSpecs.map((spec) => refOf(spec));
|
|
345
|
+
var AnalyticsVisualizationSpecMap = new Map(AnalyticsVisualizationSpecs.map((spec) => [
|
|
346
|
+
visualizationRefKey(spec.meta),
|
|
347
|
+
spec
|
|
348
|
+
]));
|
|
349
|
+
var AnalyticsVisualizationSampleData = {
|
|
350
|
+
[visualizationRefKey(RevenueMetricVisualization.meta)]: {
|
|
351
|
+
data: [
|
|
352
|
+
{ period: "2025-11-01", totalRevenue: 112000, priorRevenue: 103000 },
|
|
353
|
+
{ period: "2025-12-01", totalRevenue: 119000, priorRevenue: 110000 },
|
|
354
|
+
{ period: "2026-01-01", totalRevenue: 126500, priorRevenue: 116000 },
|
|
355
|
+
{ period: "2026-02-01", totalRevenue: 133000, priorRevenue: 124000 },
|
|
356
|
+
{ period: "2026-03-01", totalRevenue: 145500, priorRevenue: 133000 }
|
|
357
|
+
]
|
|
358
|
+
},
|
|
359
|
+
[visualizationRefKey(RevenueTrendVisualization.meta)]: {
|
|
360
|
+
data: [
|
|
361
|
+
{ date: "2025-11-01", revenue: 112000 },
|
|
362
|
+
{ date: "2025-12-01", revenue: 119000 },
|
|
363
|
+
{ date: "2026-01-01", revenue: 126500 },
|
|
364
|
+
{ date: "2026-02-01", revenue: 133000 },
|
|
365
|
+
{ date: "2026-03-01", revenue: 145500 }
|
|
366
|
+
]
|
|
367
|
+
},
|
|
368
|
+
[visualizationRefKey(RegionalRevenueVisualization.meta)]: {
|
|
369
|
+
data: [
|
|
370
|
+
{ region: "North America", revenue: 210000 },
|
|
371
|
+
{ region: "EMEA", revenue: 174000 },
|
|
372
|
+
{ region: "APAC", revenue: 132000 },
|
|
373
|
+
{ region: "LATAM", revenue: 88000 }
|
|
374
|
+
]
|
|
375
|
+
},
|
|
376
|
+
[visualizationRefKey(RetentionAreaVisualization.meta)]: {
|
|
377
|
+
data: [
|
|
378
|
+
{ week: "Week 1", retentionRate: 0.71 },
|
|
379
|
+
{ week: "Week 2", retentionRate: 0.66 },
|
|
380
|
+
{ week: "Week 3", retentionRate: 0.62 },
|
|
381
|
+
{ week: "Week 4", retentionRate: 0.58 },
|
|
382
|
+
{ week: "Week 5", retentionRate: 0.55 },
|
|
383
|
+
{ week: "Week 6", retentionRate: 0.53 }
|
|
384
|
+
]
|
|
385
|
+
},
|
|
386
|
+
[visualizationRefKey(PipelineScatterVisualization.meta)]: {
|
|
387
|
+
data: [
|
|
388
|
+
{ cycleDays: 18, winRate: 0.31, arr: 82000 },
|
|
389
|
+
{ cycleDays: 26, winRate: 0.44, arr: 65000 },
|
|
390
|
+
{ cycleDays: 33, winRate: 0.27, arr: 91000 },
|
|
391
|
+
{ cycleDays: 14, winRate: 0.56, arr: 47000 },
|
|
392
|
+
{ cycleDays: 21, winRate: 0.48, arr: 59000 },
|
|
393
|
+
{ cycleDays: 39, winRate: 0.22, arr: 114000 }
|
|
394
|
+
]
|
|
395
|
+
},
|
|
396
|
+
[visualizationRefKey(ChannelMixVisualization.meta)]: {
|
|
397
|
+
data: [
|
|
398
|
+
{ channel: "Direct", sessions: 4200 },
|
|
399
|
+
{ channel: "Organic Search", sessions: 3600 },
|
|
400
|
+
{ channel: "Paid Search", sessions: 2100 },
|
|
401
|
+
{ channel: "Partner", sessions: 1400 },
|
|
402
|
+
{ channel: "Referral", sessions: 900 }
|
|
403
|
+
]
|
|
404
|
+
},
|
|
405
|
+
[visualizationRefKey(EngagementHeatmapVisualization.meta)]: {
|
|
406
|
+
data: [
|
|
407
|
+
{ weekday: "Mon", timeBand: "09:00", engagementScore: 74 },
|
|
408
|
+
{ weekday: "Mon", timeBand: "13:00", engagementScore: 82 },
|
|
409
|
+
{ weekday: "Tue", timeBand: "09:00", engagementScore: 69 },
|
|
410
|
+
{ weekday: "Tue", timeBand: "13:00", engagementScore: 88 },
|
|
411
|
+
{ weekday: "Wed", timeBand: "09:00", engagementScore: 77 },
|
|
412
|
+
{ weekday: "Wed", timeBand: "13:00", engagementScore: 91 },
|
|
413
|
+
{ weekday: "Thu", timeBand: "09:00", engagementScore: 72 },
|
|
414
|
+
{ weekday: "Thu", timeBand: "13:00", engagementScore: 86 },
|
|
415
|
+
{ weekday: "Fri", timeBand: "09:00", engagementScore: 65 },
|
|
416
|
+
{ weekday: "Fri", timeBand: "13:00", engagementScore: 79 }
|
|
417
|
+
]
|
|
418
|
+
},
|
|
419
|
+
[visualizationRefKey(ConversionFunnelVisualization.meta)]: {
|
|
420
|
+
data: [
|
|
421
|
+
{ stage: "Visited Site", users: 12000 },
|
|
422
|
+
{ stage: "Started Trial", users: 4200 },
|
|
423
|
+
{ stage: "Activated Workspace", users: 2400 },
|
|
424
|
+
{ stage: "Requested Demo", users: 980 },
|
|
425
|
+
{ stage: "Closed Won", users: 310 }
|
|
426
|
+
]
|
|
427
|
+
},
|
|
428
|
+
[visualizationRefKey(AccountCoverageGeoVisualization.meta)]: {
|
|
429
|
+
data: [
|
|
430
|
+
{ city: "Paris", latitude: 48.8566, longitude: 2.3522, accounts: 48 },
|
|
431
|
+
{ city: "London", latitude: 51.5072, longitude: -0.1276, accounts: 62 },
|
|
432
|
+
{ city: "New York", latitude: 40.7128, longitude: -74.006, accounts: 71 },
|
|
433
|
+
{ city: "Toronto", latitude: 43.6532, longitude: -79.3832, accounts: 36 },
|
|
434
|
+
{
|
|
435
|
+
city: "Singapore",
|
|
436
|
+
latitude: 1.3521,
|
|
437
|
+
longitude: 103.8198,
|
|
438
|
+
accounts: 29
|
|
439
|
+
}
|
|
440
|
+
]
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
function refOf(spec) {
|
|
444
|
+
return { key: spec.meta.key, version: spec.meta.version };
|
|
445
|
+
}
|
|
446
|
+
function visualizationRefKey(ref) {
|
|
447
|
+
return `${ref.key}.v${ref.version}`;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// src/visualizations/widgets.ts
|
|
451
|
+
var LEGACY_VISUALIZATION_REFS = {
|
|
452
|
+
METRIC: refOf(RevenueMetricVisualization),
|
|
453
|
+
LINE_CHART: refOf(RevenueTrendVisualization),
|
|
454
|
+
BAR_CHART: refOf(RegionalRevenueVisualization),
|
|
455
|
+
AREA_CHART: refOf(RetentionAreaVisualization),
|
|
456
|
+
SCATTER_PLOT: refOf(PipelineScatterVisualization),
|
|
457
|
+
PIE_CHART: refOf(ChannelMixVisualization),
|
|
458
|
+
HEATMAP: refOf(EngagementHeatmapVisualization),
|
|
459
|
+
FUNNEL: refOf(ConversionFunnelVisualization),
|
|
460
|
+
MAP: refOf(AccountCoverageGeoVisualization)
|
|
461
|
+
};
|
|
462
|
+
function createExampleWidgets(dashboardId) {
|
|
463
|
+
return [
|
|
464
|
+
widget(dashboardId, "widget_revenue_metric", "Revenue Snapshot", "METRIC", 0, 0, 4, 2, {
|
|
465
|
+
layout: "single",
|
|
466
|
+
bindings: [binding(RevenueMetricVisualization, 200)]
|
|
467
|
+
}),
|
|
468
|
+
widget(dashboardId, "widget_revenue_trend", "Revenue Trend", "LINE_CHART", 4, 0, 8, 4, {
|
|
469
|
+
layout: "single",
|
|
470
|
+
bindings: [binding(RevenueTrendVisualization)]
|
|
471
|
+
}),
|
|
472
|
+
widget(dashboardId, "widget_regional_revenue", "Regional Revenue", "BAR_CHART", 0, 2, 6, 4, {
|
|
473
|
+
layout: "single",
|
|
474
|
+
bindings: [binding(RegionalRevenueVisualization)]
|
|
475
|
+
}),
|
|
476
|
+
widget(dashboardId, "widget_channel_mix", "Channel Mix", "PIE_CHART", 6, 2, 6, 4, {
|
|
477
|
+
layout: "single",
|
|
478
|
+
bindings: [binding(ChannelMixVisualization)]
|
|
479
|
+
}),
|
|
480
|
+
widget(dashboardId, "widget_retention", "Retention Curve", "AREA_CHART", 0, 6, 6, 4, {
|
|
481
|
+
layout: "single",
|
|
482
|
+
bindings: [binding(RetentionAreaVisualization)]
|
|
483
|
+
}),
|
|
484
|
+
widget(dashboardId, "widget_pipeline", "Pipeline Velocity", "SCATTER_PLOT", 6, 6, 6, 4, {
|
|
485
|
+
layout: "single",
|
|
486
|
+
bindings: [binding(PipelineScatterVisualization)]
|
|
487
|
+
}),
|
|
488
|
+
widget(dashboardId, "widget_heatmap", "Engagement Heatmap", "HEATMAP", 0, 10, 8, 4, {
|
|
489
|
+
layout: "single",
|
|
490
|
+
bindings: [binding(EngagementHeatmapVisualization)]
|
|
491
|
+
}),
|
|
492
|
+
widget(dashboardId, "widget_funnel", "Conversion Funnel", "FUNNEL", 8, 10, 4, 4, {
|
|
493
|
+
layout: "single",
|
|
494
|
+
bindings: [binding(ConversionFunnelVisualization)]
|
|
495
|
+
}),
|
|
496
|
+
widget(dashboardId, "widget_geo", "Account Coverage", "MAP", 0, 14, 12, 5, {
|
|
497
|
+
layout: "single",
|
|
498
|
+
bindings: [binding(AccountCoverageGeoVisualization, 360)]
|
|
499
|
+
}),
|
|
500
|
+
widget(dashboardId, "widget_comparison", "Commercial Comparison", "EMBED", 0, 19, 12, 6, {
|
|
501
|
+
layout: "comparison",
|
|
502
|
+
description: "Compare regional distribution, channel balance, and funnel shape.",
|
|
503
|
+
bindings: [
|
|
504
|
+
binding(RegionalRevenueVisualization, 240),
|
|
505
|
+
binding(ChannelMixVisualization, 240),
|
|
506
|
+
binding(ConversionFunnelVisualization, 240)
|
|
507
|
+
]
|
|
508
|
+
}),
|
|
509
|
+
widget(dashboardId, "widget_timeline", "Growth Timeline", "EMBED", 0, 25, 12, 6, {
|
|
510
|
+
layout: "timeline",
|
|
511
|
+
description: "Track revenue and retention over the same reporting cadence.",
|
|
512
|
+
bindings: [
|
|
513
|
+
binding(RevenueTrendVisualization, 220),
|
|
514
|
+
binding(RetentionAreaVisualization, 220)
|
|
515
|
+
]
|
|
516
|
+
})
|
|
517
|
+
];
|
|
518
|
+
}
|
|
519
|
+
function resolveAnalyticsWidget(widget) {
|
|
520
|
+
const config = parseWidgetConfig(widget);
|
|
521
|
+
const bindings = config.bindings.map((binding) => {
|
|
522
|
+
const spec = AnalyticsVisualizationSpecMap.get(visualizationRefKey(binding.ref));
|
|
523
|
+
if (!spec)
|
|
524
|
+
return null;
|
|
525
|
+
return {
|
|
526
|
+
key: `${widget.id}:${visualizationRefKey(binding.ref)}`,
|
|
527
|
+
spec,
|
|
528
|
+
data: binding.data,
|
|
529
|
+
title: binding.title ?? spec.meta.title,
|
|
530
|
+
description: binding.description ?? spec.meta.description,
|
|
531
|
+
height: binding.height
|
|
532
|
+
};
|
|
533
|
+
}).filter((binding) => Boolean(binding));
|
|
534
|
+
if (!bindings.length)
|
|
535
|
+
return null;
|
|
536
|
+
return {
|
|
537
|
+
id: widget.id,
|
|
538
|
+
name: widget.name,
|
|
539
|
+
description: config.description,
|
|
540
|
+
layout: config.layout,
|
|
541
|
+
gridX: widget.gridX,
|
|
542
|
+
gridY: widget.gridY,
|
|
543
|
+
gridWidth: widget.gridWidth,
|
|
544
|
+
gridHeight: widget.gridHeight,
|
|
545
|
+
bindings
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
function parseWidgetConfig(widget) {
|
|
549
|
+
if (isAnalyticsWidgetConfig(widget.config)) {
|
|
550
|
+
return widget.config;
|
|
551
|
+
}
|
|
552
|
+
const legacyRef = LEGACY_VISUALIZATION_REFS[widget.type];
|
|
553
|
+
return legacyRef ? {
|
|
554
|
+
layout: "single",
|
|
555
|
+
bindings: [
|
|
556
|
+
{
|
|
557
|
+
ref: legacyRef,
|
|
558
|
+
data: AnalyticsVisualizationSampleData[visualizationRefKey(legacyRef)]
|
|
559
|
+
}
|
|
560
|
+
]
|
|
561
|
+
} : { layout: "single", bindings: [] };
|
|
562
|
+
}
|
|
563
|
+
function binding(spec, height = 280) {
|
|
564
|
+
return {
|
|
565
|
+
ref: refOf(spec),
|
|
566
|
+
data: AnalyticsVisualizationSampleData[visualizationRefKey(spec.meta)],
|
|
567
|
+
height
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function widget(dashboardId, id, name, type, gridX, gridY, gridWidth, gridHeight, config) {
|
|
571
|
+
const now = new Date;
|
|
572
|
+
return {
|
|
573
|
+
id,
|
|
574
|
+
dashboardId,
|
|
575
|
+
name,
|
|
576
|
+
type,
|
|
577
|
+
gridX,
|
|
578
|
+
gridY,
|
|
579
|
+
gridWidth,
|
|
580
|
+
gridHeight,
|
|
581
|
+
config,
|
|
582
|
+
createdAt: now,
|
|
583
|
+
updatedAt: now
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
function isAnalyticsWidgetConfig(value) {
|
|
587
|
+
if (!value || typeof value !== "object")
|
|
588
|
+
return false;
|
|
589
|
+
const candidate = value;
|
|
590
|
+
return (candidate.layout === "single" || candidate.layout === "comparison" || candidate.layout === "timeline") && Array.isArray(candidate.bindings);
|
|
591
|
+
}
|
|
1
592
|
// src/dashboard.feature.ts
|
|
2
593
|
import { defineFeature } from "@contractspec/lib.contracts-spec";
|
|
3
594
|
var AnalyticsDashboardFeature = defineFeature({
|
|
@@ -31,6 +622,7 @@ var AnalyticsDashboardFeature = defineFeature({
|
|
|
31
622
|
{ key: "analytics.query.list", version: "1.0.0" },
|
|
32
623
|
{ key: "analytics.query.builder", version: "1.0.0" }
|
|
33
624
|
],
|
|
625
|
+
visualizations: [...AnalyticsVisualizationRefs],
|
|
34
626
|
opToPresentation: [
|
|
35
627
|
{
|
|
36
628
|
op: { key: "analytics.dashboard.list", version: "1.0.0" },
|
|
@@ -799,279 +1391,486 @@ var ExecuteQueryContract = defineQuery({
|
|
|
799
1391
|
]
|
|
800
1392
|
}
|
|
801
1393
|
});
|
|
802
|
-
// src/
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
id: "dash-2",
|
|
815
|
-
name: "User Engagement",
|
|
816
|
-
slug: "user-engagement",
|
|
817
|
-
status: "PUBLISHED",
|
|
818
|
-
widgetCount: 6,
|
|
819
|
-
viewCount: 890,
|
|
820
|
-
lastViewedAt: "2024-01-16T10:00:00Z"
|
|
821
|
-
},
|
|
822
|
-
{
|
|
823
|
-
id: "dash-3",
|
|
824
|
-
name: "Product Analytics",
|
|
825
|
-
slug: "product-analytics",
|
|
826
|
-
status: "PUBLISHED",
|
|
827
|
-
widgetCount: 10,
|
|
828
|
-
viewCount: 560,
|
|
829
|
-
lastViewedAt: "2024-01-15T14:00:00Z"
|
|
830
|
-
},
|
|
831
|
-
{
|
|
832
|
-
id: "dash-4",
|
|
833
|
-
name: "Finance Report",
|
|
834
|
-
slug: "finance-report",
|
|
835
|
-
status: "DRAFT",
|
|
836
|
-
widgetCount: 4,
|
|
837
|
-
viewCount: 0,
|
|
838
|
-
lastViewedAt: null
|
|
839
|
-
}
|
|
840
|
-
];
|
|
841
|
-
var mockWidgets = [
|
|
842
|
-
{
|
|
843
|
-
id: "w-1",
|
|
844
|
-
dashboardId: "dash-1",
|
|
845
|
-
name: "Total Revenue",
|
|
846
|
-
type: "METRIC",
|
|
847
|
-
value: 125000,
|
|
848
|
-
change: 12.5
|
|
849
|
-
},
|
|
850
|
-
{
|
|
851
|
-
id: "w-2",
|
|
852
|
-
dashboardId: "dash-1",
|
|
853
|
-
name: "Active Users",
|
|
854
|
-
type: "METRIC",
|
|
855
|
-
value: 4500,
|
|
856
|
-
change: 8.2
|
|
857
|
-
},
|
|
858
|
-
{
|
|
859
|
-
id: "w-3",
|
|
860
|
-
dashboardId: "dash-1",
|
|
861
|
-
name: "Revenue Trend",
|
|
862
|
-
type: "LINE_CHART",
|
|
863
|
-
dataPoints: 30
|
|
864
|
-
},
|
|
865
|
-
{
|
|
866
|
-
id: "w-4",
|
|
867
|
-
dashboardId: "dash-1",
|
|
868
|
-
name: "Top Products",
|
|
869
|
-
type: "BAR_CHART",
|
|
870
|
-
dataPoints: 10
|
|
871
|
-
},
|
|
872
|
-
{
|
|
873
|
-
id: "w-5",
|
|
874
|
-
dashboardId: "dash-2",
|
|
875
|
-
name: "Daily Active Users",
|
|
876
|
-
type: "LINE_CHART",
|
|
877
|
-
dataPoints: 30
|
|
878
|
-
},
|
|
879
|
-
{
|
|
880
|
-
id: "w-6",
|
|
881
|
-
dashboardId: "dash-2",
|
|
882
|
-
name: "Session Duration",
|
|
883
|
-
type: "METRIC",
|
|
884
|
-
value: 245,
|
|
885
|
-
change: -3.1
|
|
886
|
-
}
|
|
887
|
-
];
|
|
888
|
-
var mockQueries = [
|
|
889
|
-
{
|
|
890
|
-
id: "q-1",
|
|
891
|
-
name: "Monthly Revenue",
|
|
892
|
-
type: "AGGREGATION",
|
|
893
|
-
isShared: true,
|
|
894
|
-
executionCount: 1500
|
|
895
|
-
},
|
|
896
|
-
{
|
|
897
|
-
id: "q-2",
|
|
898
|
-
name: "User Growth",
|
|
899
|
-
type: "METRIC",
|
|
900
|
-
isShared: true,
|
|
901
|
-
executionCount: 890
|
|
902
|
-
},
|
|
903
|
-
{
|
|
904
|
-
id: "q-3",
|
|
905
|
-
name: "Product Sales",
|
|
906
|
-
type: "SQL",
|
|
907
|
-
isShared: false,
|
|
908
|
-
executionCount: 340
|
|
909
|
-
},
|
|
910
|
-
{
|
|
911
|
-
id: "q-4",
|
|
912
|
-
name: "Conversion Funnel",
|
|
913
|
-
type: "AGGREGATION",
|
|
914
|
-
isShared: true,
|
|
915
|
-
executionCount: 450
|
|
1394
|
+
// src/query-engine/index.ts
|
|
1395
|
+
class InMemoryQueryCache {
|
|
1396
|
+
cache = new Map;
|
|
1397
|
+
async get(key) {
|
|
1398
|
+
const entry = this.cache.get(key);
|
|
1399
|
+
if (!entry)
|
|
1400
|
+
return null;
|
|
1401
|
+
if (entry.expiresAt < new Date) {
|
|
1402
|
+
this.cache.delete(key);
|
|
1403
|
+
return null;
|
|
1404
|
+
}
|
|
1405
|
+
return { ...entry.result, cached: true, cachedAt: entry.expiresAt };
|
|
916
1406
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
return `${(value / 1e6).toFixed(1)}M`;
|
|
1407
|
+
async set(key, result, ttlSeconds) {
|
|
1408
|
+
const expiresAt = new Date(Date.now() + ttlSeconds * 1000);
|
|
1409
|
+
this.cache.set(key, { result, expiresAt });
|
|
921
1410
|
}
|
|
922
|
-
|
|
923
|
-
|
|
1411
|
+
async invalidate(pattern) {
|
|
1412
|
+
const regex = new RegExp(pattern);
|
|
1413
|
+
for (const key of this.cache.keys()) {
|
|
1414
|
+
if (regex.test(key)) {
|
|
1415
|
+
this.cache.delete(key);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
924
1418
|
}
|
|
925
|
-
return value.toString();
|
|
926
|
-
}
|
|
927
|
-
function formatChange(change) {
|
|
928
|
-
const icon = change >= 0 ? "\uD83D\uDCC8" : "\uD83D\uDCC9";
|
|
929
|
-
const sign = change >= 0 ? "+" : "";
|
|
930
|
-
return `${icon} ${sign}${change.toFixed(1)}%`;
|
|
931
1419
|
}
|
|
932
|
-
var analyticsDashboardMarkdownRenderer = {
|
|
933
|
-
target: "markdown",
|
|
934
|
-
render: async (desc) => {
|
|
935
|
-
if (desc.source.type !== "component" || desc.source.componentKey !== "AnalyticsDashboard") {
|
|
936
|
-
throw new Error("analyticsDashboardMarkdownRenderer: not AnalyticsDashboard");
|
|
937
|
-
}
|
|
938
|
-
const dashboards = mockDashboards;
|
|
939
|
-
const widgets = mockWidgets;
|
|
940
|
-
const queries = mockQueries;
|
|
941
|
-
const dashboard = dashboards[0];
|
|
942
|
-
if (!dashboard) {
|
|
943
|
-
return {
|
|
944
|
-
mimeType: "text/markdown",
|
|
945
|
-
body: `# No Dashboards
|
|
946
1420
|
|
|
947
|
-
|
|
1421
|
+
class BasicQueryEngine {
|
|
1422
|
+
cache;
|
|
1423
|
+
constructor(cache) {
|
|
1424
|
+
this.cache = cache ?? new InMemoryQueryCache;
|
|
1425
|
+
}
|
|
1426
|
+
async execute(definition, params) {
|
|
1427
|
+
const startTime = Date.now();
|
|
1428
|
+
const validation = this.validateQuery(definition);
|
|
1429
|
+
if (!validation.valid) {
|
|
1430
|
+
return {
|
|
1431
|
+
data: [],
|
|
1432
|
+
columns: [],
|
|
1433
|
+
rowCount: 0,
|
|
1434
|
+
executionTimeMs: Date.now() - startTime,
|
|
1435
|
+
cached: false,
|
|
1436
|
+
error: validation.errors.join(", ")
|
|
948
1437
|
};
|
|
949
1438
|
}
|
|
950
|
-
const
|
|
951
|
-
const
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
const lines = [
|
|
955
|
-
`# ${dashboard.name}`,
|
|
956
|
-
"",
|
|
957
|
-
"> Analytics dashboard overview",
|
|
958
|
-
"",
|
|
959
|
-
"## Key Metrics",
|
|
960
|
-
""
|
|
961
|
-
];
|
|
962
|
-
const metricWidgets = dashboardWidgets.filter((w) => w.type === "METRIC");
|
|
963
|
-
for (const widget of metricWidgets) {
|
|
964
|
-
const w = widget;
|
|
965
|
-
lines.push(`### ${w.name}`);
|
|
966
|
-
lines.push(`**${formatNumber(w.value)}** ${formatChange(w.change)}`);
|
|
967
|
-
lines.push("");
|
|
1439
|
+
const cacheKey = this.buildCacheKey(definition, params);
|
|
1440
|
+
const cachedResult = await this.cache.get(cacheKey);
|
|
1441
|
+
if (cachedResult) {
|
|
1442
|
+
return cachedResult;
|
|
968
1443
|
}
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1444
|
+
let result;
|
|
1445
|
+
switch (definition.type) {
|
|
1446
|
+
case "AGGREGATION":
|
|
1447
|
+
if (!definition.aggregation) {
|
|
1448
|
+
throw new Error("Aggregation definition is missing");
|
|
1449
|
+
}
|
|
1450
|
+
result = await this.executeAggregation(definition.aggregation, params);
|
|
1451
|
+
break;
|
|
1452
|
+
case "METRIC":
|
|
1453
|
+
if (!definition.metricIds) {
|
|
1454
|
+
throw new Error("Metric IDs are missing");
|
|
1455
|
+
}
|
|
1456
|
+
result = await this.executeMetric(definition.metricIds, params);
|
|
1457
|
+
break;
|
|
1458
|
+
case "SQL":
|
|
1459
|
+
if (!definition.sql) {
|
|
1460
|
+
throw new Error("SQL query is missing");
|
|
1461
|
+
}
|
|
1462
|
+
result = await this.executeSql(definition.sql, params);
|
|
1463
|
+
break;
|
|
1464
|
+
default:
|
|
1465
|
+
result = {
|
|
1466
|
+
data: [],
|
|
1467
|
+
columns: [],
|
|
1468
|
+
rowCount: 0,
|
|
1469
|
+
executionTimeMs: Date.now() - startTime,
|
|
1470
|
+
cached: false,
|
|
1471
|
+
error: `Unknown query type: ${definition.type}`
|
|
1472
|
+
};
|
|
975
1473
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
lines.push("|--------|-------|");
|
|
981
|
-
lines.push(`| Total Dashboards | ${dashboards.length} |`);
|
|
982
|
-
lines.push(`| Published | ${publishedDashboards.length} |`);
|
|
983
|
-
lines.push(`| Total Views | ${totalViews.toLocaleString()} |`);
|
|
984
|
-
lines.push(`| Shared Queries | ${sharedQueries.length} |`);
|
|
985
|
-
return {
|
|
986
|
-
mimeType: "text/markdown",
|
|
987
|
-
body: lines.join(`
|
|
988
|
-
`)
|
|
989
|
-
};
|
|
1474
|
+
result.executionTimeMs = Date.now() - startTime;
|
|
1475
|
+
result.cached = false;
|
|
1476
|
+
await this.cache.set(cacheKey, result, 300);
|
|
1477
|
+
return result;
|
|
990
1478
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
if (desc.source.type !== "component" || desc.source.componentKey !== "DashboardList") {
|
|
996
|
-
throw new Error("dashboardListMarkdownRenderer: not DashboardList");
|
|
1479
|
+
validateQuery(definition) {
|
|
1480
|
+
const errors = [];
|
|
1481
|
+
if (!definition.type) {
|
|
1482
|
+
errors.push("Query type is required");
|
|
997
1483
|
}
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1484
|
+
switch (definition.type) {
|
|
1485
|
+
case "SQL":
|
|
1486
|
+
if (!definition.sql) {
|
|
1487
|
+
errors.push("SQL query is required for SQL type");
|
|
1488
|
+
}
|
|
1489
|
+
break;
|
|
1490
|
+
case "METRIC":
|
|
1491
|
+
if (!definition.metricIds || definition.metricIds.length === 0) {
|
|
1492
|
+
errors.push("Metric IDs are required for METRIC type");
|
|
1493
|
+
}
|
|
1494
|
+
break;
|
|
1495
|
+
case "AGGREGATION":
|
|
1496
|
+
if (!definition.aggregation) {
|
|
1497
|
+
errors.push("Aggregation definition is required for AGGREGATION type");
|
|
1498
|
+
} else {
|
|
1499
|
+
if (!definition.aggregation.source) {
|
|
1500
|
+
errors.push("Aggregation source is required");
|
|
1501
|
+
}
|
|
1502
|
+
if (!definition.aggregation.measures || definition.aggregation.measures.length === 0) {
|
|
1503
|
+
errors.push("At least one measure is required");
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
break;
|
|
1011
1507
|
}
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1508
|
+
return { valid: errors.length === 0, errors };
|
|
1509
|
+
}
|
|
1510
|
+
buildCacheKey(definition, params) {
|
|
1511
|
+
return JSON.stringify({ definition, params });
|
|
1512
|
+
}
|
|
1513
|
+
async executeAggregation(aggregation, params) {
|
|
1514
|
+
const columns = [
|
|
1515
|
+
...aggregation.dimensions.map((d) => ({
|
|
1516
|
+
name: d.name,
|
|
1517
|
+
type: d.type === "NUMBER" ? "NUMBER" : d.type === "TIME" ? "DATE" : "STRING",
|
|
1518
|
+
label: d.name
|
|
1519
|
+
})),
|
|
1520
|
+
...aggregation.measures.map((m) => ({
|
|
1521
|
+
name: m.name,
|
|
1522
|
+
type: "NUMBER",
|
|
1523
|
+
label: m.name,
|
|
1524
|
+
format: m.format
|
|
1525
|
+
}))
|
|
1526
|
+
];
|
|
1527
|
+
const data = this.generateMockData(aggregation, params);
|
|
1018
1528
|
return {
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1529
|
+
data,
|
|
1530
|
+
columns,
|
|
1531
|
+
rowCount: data.length,
|
|
1532
|
+
executionTimeMs: 0,
|
|
1533
|
+
cached: false
|
|
1022
1534
|
};
|
|
1023
1535
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
}
|
|
1031
|
-
const queries = mockQueries;
|
|
1032
|
-
const lines = [
|
|
1033
|
-
"# Query Builder",
|
|
1034
|
-
"",
|
|
1035
|
-
"> Create and manage data queries",
|
|
1036
|
-
"",
|
|
1037
|
-
"## Saved Queries",
|
|
1038
|
-
"",
|
|
1039
|
-
"| Query | Type | Shared | Executions |",
|
|
1040
|
-
"|-------|------|--------|------------|"
|
|
1041
|
-
];
|
|
1042
|
-
for (const query of queries) {
|
|
1043
|
-
const sharedIcon = query.isShared ? "\uD83C\uDF10" : "\uD83D\uDD12";
|
|
1044
|
-
lines.push(`| ${query.name} | ${query.type} | ${sharedIcon} | ${query.executionCount.toLocaleString()} |`);
|
|
1045
|
-
}
|
|
1046
|
-
lines.push("");
|
|
1047
|
-
lines.push("## Query Types");
|
|
1048
|
-
lines.push("");
|
|
1049
|
-
lines.push("### METRIC");
|
|
1050
|
-
lines.push("Query usage metrics from the metering system.");
|
|
1051
|
-
lines.push("");
|
|
1052
|
-
lines.push("### AGGREGATION");
|
|
1053
|
-
lines.push("Build aggregations with measures and dimensions without writing SQL.");
|
|
1054
|
-
lines.push("");
|
|
1055
|
-
lines.push("### SQL");
|
|
1056
|
-
lines.push("Write custom SQL queries for advanced analysis.");
|
|
1057
|
-
lines.push("");
|
|
1058
|
-
lines.push("## Features");
|
|
1059
|
-
lines.push("");
|
|
1060
|
-
lines.push("- Visual query builder");
|
|
1061
|
-
lines.push("- Auto-complete for fields and functions");
|
|
1062
|
-
lines.push("- Query validation and optimization");
|
|
1063
|
-
lines.push("- Result caching");
|
|
1064
|
-
lines.push("- Query sharing and collaboration");
|
|
1536
|
+
async executeMetric(metricIds, _params) {
|
|
1537
|
+
const data = metricIds.map((id) => ({
|
|
1538
|
+
metricId: id,
|
|
1539
|
+
value: Math.random() * 1000,
|
|
1540
|
+
change: (Math.random() - 0.5) * 20
|
|
1541
|
+
}));
|
|
1065
1542
|
return {
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1543
|
+
data,
|
|
1544
|
+
columns: [
|
|
1545
|
+
{ name: "metricId", type: "STRING" },
|
|
1546
|
+
{ name: "value", type: "NUMBER" },
|
|
1547
|
+
{ name: "change", type: "NUMBER" }
|
|
1548
|
+
],
|
|
1549
|
+
rowCount: data.length,
|
|
1550
|
+
executionTimeMs: 0,
|
|
1551
|
+
cached: false
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
async executeSql(_sql, _params) {
|
|
1555
|
+
return {
|
|
1556
|
+
data: [],
|
|
1557
|
+
columns: [],
|
|
1558
|
+
rowCount: 0,
|
|
1559
|
+
executionTimeMs: 0,
|
|
1560
|
+
cached: false,
|
|
1561
|
+
error: "SQL execution not implemented in demo"
|
|
1069
1562
|
};
|
|
1070
1563
|
}
|
|
1564
|
+
generateMockData(aggregation, params) {
|
|
1565
|
+
const data = [];
|
|
1566
|
+
const rowCount = 10;
|
|
1567
|
+
const timeDimension = aggregation.dimensions.find((d) => d.type === "TIME");
|
|
1568
|
+
for (let i = 0;i < rowCount; i++) {
|
|
1569
|
+
const row = {};
|
|
1570
|
+
for (const dim of aggregation.dimensions) {
|
|
1571
|
+
if (dim.type === "TIME") {
|
|
1572
|
+
const date = new Date(params.dateRange?.start ?? new Date);
|
|
1573
|
+
date.setDate(date.getDate() + i);
|
|
1574
|
+
row[dim.name] = date.toISOString().split("T")[0];
|
|
1575
|
+
} else {
|
|
1576
|
+
row[dim.name] = `${dim.name}_${i % 5}`;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
for (const measure of aggregation.measures) {
|
|
1580
|
+
const baseValue = timeDimension ? 100 + i * 10 : Math.random() * 1000;
|
|
1581
|
+
const noise = (Math.random() - 0.5) * 20;
|
|
1582
|
+
row[measure.name] = Math.round((baseValue + noise) * 100) / 100;
|
|
1583
|
+
}
|
|
1584
|
+
data.push(row);
|
|
1585
|
+
}
|
|
1586
|
+
return data;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
function createQueryEngine(cache) {
|
|
1590
|
+
return new BasicQueryEngine(cache);
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
// src/ui/AnalyticsDashboard.widgets.tsx
|
|
1594
|
+
import {
|
|
1595
|
+
ComparisonView,
|
|
1596
|
+
TimelineView,
|
|
1597
|
+
VisualizationCard,
|
|
1598
|
+
VisualizationGrid
|
|
1599
|
+
} from "@contractspec/lib.design-system";
|
|
1600
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
1601
|
+
"use client";
|
|
1602
|
+
function AnalyticsWidgetBoard({
|
|
1603
|
+
dashboardName,
|
|
1604
|
+
widgets
|
|
1605
|
+
}) {
|
|
1606
|
+
if (!widgets.length) {
|
|
1607
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
1608
|
+
className: "rounded-lg border border-dashed p-10 text-center text-muted-foreground",
|
|
1609
|
+
children: [
|
|
1610
|
+
'No visualization widgets configured for "',
|
|
1611
|
+
dashboardName,
|
|
1612
|
+
'".'
|
|
1613
|
+
]
|
|
1614
|
+
}, undefined, true, undefined, this);
|
|
1615
|
+
}
|
|
1616
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
1617
|
+
children: [
|
|
1618
|
+
/* @__PURE__ */ jsxDEV("h3", {
|
|
1619
|
+
className: "mb-4 font-semibold text-lg",
|
|
1620
|
+
children: [
|
|
1621
|
+
'Widgets in "',
|
|
1622
|
+
dashboardName,
|
|
1623
|
+
'"'
|
|
1624
|
+
]
|
|
1625
|
+
}, undefined, true, undefined, this),
|
|
1626
|
+
/* @__PURE__ */ jsxDEV(VisualizationGrid, {
|
|
1627
|
+
children: widgets.map((widget2) => /* @__PURE__ */ jsxDEV("div", {
|
|
1628
|
+
className: gridSpanClass(widget2.gridWidth),
|
|
1629
|
+
children: renderVisualizationWidget(widget2)
|
|
1630
|
+
}, widget2.id, false, undefined, this))
|
|
1631
|
+
}, undefined, false, undefined, this)
|
|
1632
|
+
]
|
|
1633
|
+
}, undefined, true, undefined, this);
|
|
1634
|
+
}
|
|
1635
|
+
function renderVisualizationWidget(widget2) {
|
|
1636
|
+
const footer = /* @__PURE__ */ jsxDEV("span", {
|
|
1637
|
+
className: "text-muted-foreground text-xs",
|
|
1638
|
+
children: [
|
|
1639
|
+
"Position: (",
|
|
1640
|
+
widget2.gridX,
|
|
1641
|
+
", ",
|
|
1642
|
+
widget2.gridY,
|
|
1643
|
+
") • ",
|
|
1644
|
+
widget2.gridWidth,
|
|
1645
|
+
"x",
|
|
1646
|
+
widget2.gridHeight
|
|
1647
|
+
]
|
|
1648
|
+
}, undefined, true, undefined, this);
|
|
1649
|
+
if (widget2.layout === "comparison") {
|
|
1650
|
+
return /* @__PURE__ */ jsxDEV(ComparisonView, {
|
|
1651
|
+
description: widget2.description,
|
|
1652
|
+
items: widget2.bindings.map((binding3) => ({ ...binding3, footer })),
|
|
1653
|
+
title: widget2.name
|
|
1654
|
+
}, undefined, false, undefined, this);
|
|
1655
|
+
}
|
|
1656
|
+
if (widget2.layout === "timeline") {
|
|
1657
|
+
return /* @__PURE__ */ jsxDEV(TimelineView, {
|
|
1658
|
+
description: widget2.description,
|
|
1659
|
+
items: widget2.bindings.map((binding3) => ({ ...binding3, footer })),
|
|
1660
|
+
title: widget2.name
|
|
1661
|
+
}, undefined, false, undefined, this);
|
|
1662
|
+
}
|
|
1663
|
+
const binding2 = widget2.bindings[0];
|
|
1664
|
+
if (!binding2)
|
|
1665
|
+
return null;
|
|
1666
|
+
return /* @__PURE__ */ jsxDEV(VisualizationCard, {
|
|
1667
|
+
data: binding2.data,
|
|
1668
|
+
description: widget2.description ?? binding2.description,
|
|
1669
|
+
footer,
|
|
1670
|
+
height: binding2.height,
|
|
1671
|
+
spec: binding2.spec,
|
|
1672
|
+
title: widget2.name
|
|
1673
|
+
}, undefined, false, undefined, this);
|
|
1674
|
+
}
|
|
1675
|
+
function gridSpanClass(gridWidth) {
|
|
1676
|
+
if (gridWidth >= 12)
|
|
1677
|
+
return "md:col-span-2 xl:col-span-3";
|
|
1678
|
+
if (gridWidth >= 8)
|
|
1679
|
+
return "xl:col-span-2";
|
|
1680
|
+
if (gridWidth >= 6)
|
|
1681
|
+
return "md:col-span-2";
|
|
1682
|
+
return "";
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
// src/ui/AnalyticsQueriesTable.tsx
|
|
1686
|
+
import { DataTable } from "@contractspec/lib.design-system";
|
|
1687
|
+
import { useContractTable } from "@contractspec/lib.presentation-runtime-react";
|
|
1688
|
+
import { Badge } from "@contractspec/lib.ui-kit-web/ui/badge";
|
|
1689
|
+
import { HStack, VStack } from "@contractspec/lib.ui-kit-web/ui/stack";
|
|
1690
|
+
import { Text } from "@contractspec/lib.ui-kit-web/ui/text";
|
|
1691
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
1692
|
+
"use client";
|
|
1693
|
+
var QUERY_TYPE_COLORS = {
|
|
1694
|
+
SQL: "default",
|
|
1695
|
+
METRIC: "secondary",
|
|
1696
|
+
AGGREGATION: "secondary",
|
|
1697
|
+
CUSTOM: "outline"
|
|
1071
1698
|
};
|
|
1699
|
+
function formatJson(value) {
|
|
1700
|
+
return JSON.stringify(value, null, 2);
|
|
1701
|
+
}
|
|
1702
|
+
function AnalyticsQueriesTable({ queries }) {
|
|
1703
|
+
const controller = useContractTable({
|
|
1704
|
+
data: queries,
|
|
1705
|
+
columns: [
|
|
1706
|
+
{
|
|
1707
|
+
id: "query",
|
|
1708
|
+
header: "Query",
|
|
1709
|
+
label: "Query",
|
|
1710
|
+
accessor: (query) => query.name,
|
|
1711
|
+
cell: ({ item }) => /* @__PURE__ */ jsxDEV2(VStack, {
|
|
1712
|
+
gap: "xs",
|
|
1713
|
+
children: [
|
|
1714
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
1715
|
+
className: "font-medium text-sm",
|
|
1716
|
+
children: item.name
|
|
1717
|
+
}, undefined, false, undefined, this),
|
|
1718
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
1719
|
+
className: "text-muted-foreground text-xs",
|
|
1720
|
+
children: [
|
|
1721
|
+
"Updated ",
|
|
1722
|
+
item.updatedAt.toLocaleDateString()
|
|
1723
|
+
]
|
|
1724
|
+
}, undefined, true, undefined, this)
|
|
1725
|
+
]
|
|
1726
|
+
}, undefined, true, undefined, this),
|
|
1727
|
+
size: 240,
|
|
1728
|
+
minSize: 180,
|
|
1729
|
+
canSort: true,
|
|
1730
|
+
canPin: true,
|
|
1731
|
+
canResize: true
|
|
1732
|
+
},
|
|
1733
|
+
{
|
|
1734
|
+
id: "description",
|
|
1735
|
+
header: "Description",
|
|
1736
|
+
label: "Description",
|
|
1737
|
+
accessor: (query) => query.description ?? "",
|
|
1738
|
+
cell: ({ value }) => /* @__PURE__ */ jsxDEV2(Text, {
|
|
1739
|
+
className: "line-clamp-2 text-muted-foreground text-sm",
|
|
1740
|
+
children: String(value || "No description")
|
|
1741
|
+
}, undefined, false, undefined, this),
|
|
1742
|
+
size: 300,
|
|
1743
|
+
minSize: 220,
|
|
1744
|
+
canSort: false,
|
|
1745
|
+
canHide: true,
|
|
1746
|
+
canResize: true
|
|
1747
|
+
},
|
|
1748
|
+
{
|
|
1749
|
+
id: "type",
|
|
1750
|
+
header: "Type",
|
|
1751
|
+
label: "Type",
|
|
1752
|
+
accessorKey: "type",
|
|
1753
|
+
cell: ({ value }) => /* @__PURE__ */ jsxDEV2(Badge, {
|
|
1754
|
+
variant: QUERY_TYPE_COLORS[String(value)],
|
|
1755
|
+
children: String(value)
|
|
1756
|
+
}, undefined, false, undefined, this),
|
|
1757
|
+
size: 150,
|
|
1758
|
+
canSort: true,
|
|
1759
|
+
canHide: true,
|
|
1760
|
+
canResize: true
|
|
1761
|
+
},
|
|
1762
|
+
{
|
|
1763
|
+
id: "cacheTtlSeconds",
|
|
1764
|
+
header: "Cache TTL",
|
|
1765
|
+
label: "Cache TTL",
|
|
1766
|
+
accessorKey: "cacheTtlSeconds",
|
|
1767
|
+
cell: ({ value }) => `${String(value)}s`,
|
|
1768
|
+
align: "right",
|
|
1769
|
+
size: 140,
|
|
1770
|
+
canSort: true,
|
|
1771
|
+
canResize: true
|
|
1772
|
+
},
|
|
1773
|
+
{
|
|
1774
|
+
id: "isShared",
|
|
1775
|
+
header: "Shared",
|
|
1776
|
+
label: "Shared",
|
|
1777
|
+
accessorKey: "isShared",
|
|
1778
|
+
cell: ({ value }) => /* @__PURE__ */ jsxDEV2(Badge, {
|
|
1779
|
+
variant: value ? "default" : "outline",
|
|
1780
|
+
children: value ? "Shared" : "Private"
|
|
1781
|
+
}, undefined, false, undefined, this),
|
|
1782
|
+
size: 140,
|
|
1783
|
+
canSort: true,
|
|
1784
|
+
canHide: true,
|
|
1785
|
+
canResize: true
|
|
1786
|
+
}
|
|
1787
|
+
],
|
|
1788
|
+
initialState: {
|
|
1789
|
+
pagination: { pageIndex: 0, pageSize: 3 },
|
|
1790
|
+
columnVisibility: { description: false },
|
|
1791
|
+
columnPinning: { left: ["query"], right: [] }
|
|
1792
|
+
},
|
|
1793
|
+
renderExpandedContent: (query) => /* @__PURE__ */ jsxDEV2(VStack, {
|
|
1794
|
+
gap: "sm",
|
|
1795
|
+
className: "py-2",
|
|
1796
|
+
children: [
|
|
1797
|
+
/* @__PURE__ */ jsxDEV2(VStack, {
|
|
1798
|
+
gap: "xs",
|
|
1799
|
+
children: [
|
|
1800
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
1801
|
+
className: "font-medium text-sm",
|
|
1802
|
+
children: "Description"
|
|
1803
|
+
}, undefined, false, undefined, this),
|
|
1804
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
1805
|
+
className: "text-muted-foreground text-sm",
|
|
1806
|
+
children: query.description ?? "No description"
|
|
1807
|
+
}, undefined, false, undefined, this)
|
|
1808
|
+
]
|
|
1809
|
+
}, undefined, true, undefined, this),
|
|
1810
|
+
query.sql ? /* @__PURE__ */ jsxDEV2(VStack, {
|
|
1811
|
+
gap: "xs",
|
|
1812
|
+
children: [
|
|
1813
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
1814
|
+
className: "font-medium text-sm",
|
|
1815
|
+
children: "SQL"
|
|
1816
|
+
}, undefined, false, undefined, this),
|
|
1817
|
+
/* @__PURE__ */ jsxDEV2("pre", {
|
|
1818
|
+
className: "overflow-auto rounded-md bg-muted/40 p-3 text-xs",
|
|
1819
|
+
children: query.sql
|
|
1820
|
+
}, undefined, false, undefined, this)
|
|
1821
|
+
]
|
|
1822
|
+
}, undefined, true, undefined, this) : null,
|
|
1823
|
+
/* @__PURE__ */ jsxDEV2(VStack, {
|
|
1824
|
+
gap: "xs",
|
|
1825
|
+
children: [
|
|
1826
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
1827
|
+
className: "font-medium text-sm",
|
|
1828
|
+
children: "Definition"
|
|
1829
|
+
}, undefined, false, undefined, this),
|
|
1830
|
+
/* @__PURE__ */ jsxDEV2("pre", {
|
|
1831
|
+
className: "overflow-auto rounded-md bg-muted/40 p-3 text-xs",
|
|
1832
|
+
children: formatJson(query.definition)
|
|
1833
|
+
}, undefined, false, undefined, this)
|
|
1834
|
+
]
|
|
1835
|
+
}, undefined, true, undefined, this)
|
|
1836
|
+
]
|
|
1837
|
+
}, undefined, true, undefined, this),
|
|
1838
|
+
getCanExpand: () => true
|
|
1839
|
+
});
|
|
1840
|
+
return /* @__PURE__ */ jsxDEV2(DataTable, {
|
|
1841
|
+
controller,
|
|
1842
|
+
title: "Saved Queries",
|
|
1843
|
+
description: "Client-mode table using the shared ContractSpec controller and renderer.",
|
|
1844
|
+
toolbar: /* @__PURE__ */ jsxDEV2(HStack, {
|
|
1845
|
+
gap: "sm",
|
|
1846
|
+
className: "flex-wrap",
|
|
1847
|
+
children: [
|
|
1848
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
1849
|
+
className: "text-muted-foreground text-sm",
|
|
1850
|
+
children: [
|
|
1851
|
+
queries.length,
|
|
1852
|
+
" queries"
|
|
1853
|
+
]
|
|
1854
|
+
}, undefined, true, undefined, this),
|
|
1855
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
1856
|
+
className: "text-muted-foreground text-sm",
|
|
1857
|
+
children: [
|
|
1858
|
+
queries.filter((query) => query.isShared).length,
|
|
1859
|
+
" shared"
|
|
1860
|
+
]
|
|
1861
|
+
}, undefined, true, undefined, this)
|
|
1862
|
+
]
|
|
1863
|
+
}, undefined, true, undefined, this),
|
|
1864
|
+
emptyState: /* @__PURE__ */ jsxDEV2("div", {
|
|
1865
|
+
className: "rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",
|
|
1866
|
+
children: "No queries saved"
|
|
1867
|
+
}, undefined, false, undefined, this)
|
|
1868
|
+
}, undefined, false, undefined, this);
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1072
1871
|
// src/ui/hooks/useAnalyticsData.ts
|
|
1073
|
-
import { useCallback, useEffect, useState } from "react";
|
|
1074
1872
|
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
1873
|
+
import { useCallback, useEffect, useState } from "react";
|
|
1075
1874
|
"use client";
|
|
1076
1875
|
function useAnalyticsData(projectId = "local-project") {
|
|
1077
1876
|
const { handlers } = useTemplateRuntime();
|
|
@@ -1097,7 +1896,7 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
1097
1896
|
if (first) {
|
|
1098
1897
|
setSelectedDashboard(first);
|
|
1099
1898
|
const dashboardWidgets = await analytics.getWidgets(first.id);
|
|
1100
|
-
setWidgets(dashboardWidgets);
|
|
1899
|
+
setWidgets(dashboardWidgets.length > 0 ? dashboardWidgets : createExampleWidgets(first.id));
|
|
1101
1900
|
}
|
|
1102
1901
|
}
|
|
1103
1902
|
} catch (err) {
|
|
@@ -1112,7 +1911,7 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
1112
1911
|
const selectDashboard = useCallback(async (dashboard) => {
|
|
1113
1912
|
setSelectedDashboard(dashboard);
|
|
1114
1913
|
const dashboardWidgets = await analytics.getWidgets(dashboard.id);
|
|
1115
|
-
setWidgets(dashboardWidgets);
|
|
1914
|
+
setWidgets(dashboardWidgets.length > 0 ? dashboardWidgets : createExampleWidgets(dashboard.id));
|
|
1116
1915
|
}, [analytics]);
|
|
1117
1916
|
const stats = {
|
|
1118
1917
|
totalDashboards: dashboards.length,
|
|
@@ -1134,7 +1933,6 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
1134
1933
|
}
|
|
1135
1934
|
|
|
1136
1935
|
// src/ui/AnalyticsDashboard.tsx
|
|
1137
|
-
import { useState as useState2 } from "react";
|
|
1138
1936
|
import {
|
|
1139
1937
|
Button,
|
|
1140
1938
|
ErrorState,
|
|
@@ -1142,33 +1940,14 @@ import {
|
|
|
1142
1940
|
StatCard,
|
|
1143
1941
|
StatCardGroup
|
|
1144
1942
|
} from "@contractspec/lib.design-system";
|
|
1145
|
-
import {
|
|
1943
|
+
import { useMemo, useState as useState2 } from "react";
|
|
1944
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
1146
1945
|
"use client";
|
|
1147
1946
|
var STATUS_COLORS = {
|
|
1148
1947
|
PUBLISHED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
|
|
1149
1948
|
DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
|
|
1150
1949
|
ARCHIVED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"
|
|
1151
1950
|
};
|
|
1152
|
-
var WIDGET_ICONS = {
|
|
1153
|
-
LINE_CHART: "\uD83D\uDCC8",
|
|
1154
|
-
BAR_CHART: "\uD83D\uDCCA",
|
|
1155
|
-
PIE_CHART: "\uD83E\uDD67",
|
|
1156
|
-
AREA_CHART: "\uD83D\uDCC9",
|
|
1157
|
-
SCATTER_PLOT: "⚬",
|
|
1158
|
-
METRIC: "\uD83D\uDD22",
|
|
1159
|
-
TABLE: "\uD83D\uDCCB",
|
|
1160
|
-
HEATMAP: "\uD83D\uDDFA️",
|
|
1161
|
-
FUNNEL: "⏬",
|
|
1162
|
-
MAP: "\uD83C\uDF0D",
|
|
1163
|
-
TEXT: "\uD83D\uDCDD",
|
|
1164
|
-
EMBED: "\uD83D\uDD17"
|
|
1165
|
-
};
|
|
1166
|
-
var QUERY_TYPE_COLORS = {
|
|
1167
|
-
SQL: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
|
|
1168
|
-
METRIC: "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",
|
|
1169
|
-
AGGREGATION: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
|
|
1170
|
-
CUSTOM: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"
|
|
1171
|
-
};
|
|
1172
1951
|
function AnalyticsDashboard() {
|
|
1173
1952
|
const [activeTab, setActiveTab] = useState2("dashboards");
|
|
1174
1953
|
const {
|
|
@@ -1186,33 +1965,34 @@ function AnalyticsDashboard() {
|
|
|
1186
1965
|
{ id: "dashboards", label: "Dashboards", icon: "\uD83D\uDCCA" },
|
|
1187
1966
|
{ id: "queries", label: "Queries", icon: "\uD83D\uDD0D" }
|
|
1188
1967
|
];
|
|
1968
|
+
const resolvedWidgets = useMemo(() => widgets.map((widget2) => resolveAnalyticsWidget(widget2)).filter((widget2) => Boolean(widget2)), [widgets]);
|
|
1189
1969
|
if (loading) {
|
|
1190
|
-
return /* @__PURE__ */
|
|
1970
|
+
return /* @__PURE__ */ jsxDEV3(LoaderBlock, {
|
|
1191
1971
|
label: "Loading Analytics..."
|
|
1192
1972
|
}, undefined, false, undefined, this);
|
|
1193
1973
|
}
|
|
1194
1974
|
if (error) {
|
|
1195
|
-
return /* @__PURE__ */
|
|
1975
|
+
return /* @__PURE__ */ jsxDEV3(ErrorState, {
|
|
1196
1976
|
title: "Failed to load Analytics",
|
|
1197
1977
|
description: error.message,
|
|
1198
1978
|
onRetry: refetch,
|
|
1199
1979
|
retryLabel: "Retry"
|
|
1200
1980
|
}, undefined, false, undefined, this);
|
|
1201
1981
|
}
|
|
1202
|
-
return /* @__PURE__ */
|
|
1982
|
+
return /* @__PURE__ */ jsxDEV3("div", {
|
|
1203
1983
|
className: "space-y-6",
|
|
1204
1984
|
children: [
|
|
1205
|
-
/* @__PURE__ */
|
|
1985
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
1206
1986
|
className: "flex items-center justify-between",
|
|
1207
1987
|
children: [
|
|
1208
|
-
/* @__PURE__ */
|
|
1209
|
-
className: "text-2xl
|
|
1988
|
+
/* @__PURE__ */ jsxDEV3("h2", {
|
|
1989
|
+
className: "font-bold text-2xl",
|
|
1210
1990
|
children: "Analytics Dashboard"
|
|
1211
1991
|
}, undefined, false, undefined, this),
|
|
1212
|
-
/* @__PURE__ */
|
|
1992
|
+
/* @__PURE__ */ jsxDEV3(Button, {
|
|
1213
1993
|
onClick: () => alert("Create dashboard modal"),
|
|
1214
1994
|
children: [
|
|
1215
|
-
/* @__PURE__ */
|
|
1995
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
1216
1996
|
className: "mr-2",
|
|
1217
1997
|
children: "+"
|
|
1218
1998
|
}, undefined, false, undefined, this),
|
|
@@ -1221,55 +2001,55 @@ function AnalyticsDashboard() {
|
|
|
1221
2001
|
}, undefined, true, undefined, this)
|
|
1222
2002
|
]
|
|
1223
2003
|
}, undefined, true, undefined, this),
|
|
1224
|
-
/* @__PURE__ */
|
|
2004
|
+
/* @__PURE__ */ jsxDEV3(StatCardGroup, {
|
|
1225
2005
|
children: [
|
|
1226
|
-
/* @__PURE__ */
|
|
2006
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
1227
2007
|
label: "Dashboards",
|
|
1228
2008
|
value: stats.totalDashboards,
|
|
1229
2009
|
hint: `${stats.publishedDashboards} published`
|
|
1230
2010
|
}, undefined, false, undefined, this),
|
|
1231
|
-
/* @__PURE__ */
|
|
2011
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
1232
2012
|
label: "Queries",
|
|
1233
2013
|
value: stats.totalQueries,
|
|
1234
2014
|
hint: `${stats.sharedQueries} shared`
|
|
1235
2015
|
}, undefined, false, undefined, this),
|
|
1236
|
-
/* @__PURE__ */
|
|
2016
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
1237
2017
|
label: "Widgets",
|
|
1238
2018
|
value: widgets.length,
|
|
1239
2019
|
hint: "on current dashboard"
|
|
1240
2020
|
}, undefined, false, undefined, this)
|
|
1241
2021
|
]
|
|
1242
2022
|
}, undefined, true, undefined, this),
|
|
1243
|
-
/* @__PURE__ */
|
|
1244
|
-
className: "
|
|
2023
|
+
/* @__PURE__ */ jsxDEV3("nav", {
|
|
2024
|
+
className: "flex gap-1 rounded-lg bg-muted p-1",
|
|
1245
2025
|
role: "tablist",
|
|
1246
|
-
children: tabs.map((tab) => /* @__PURE__ */
|
|
2026
|
+
children: tabs.map((tab) => /* @__PURE__ */ jsxDEV3(Button, {
|
|
1247
2027
|
type: "button",
|
|
1248
2028
|
role: "tab",
|
|
1249
2029
|
"aria-selected": activeTab === tab.id,
|
|
1250
2030
|
onClick: () => setActiveTab(tab.id),
|
|
1251
|
-
className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 text-sm
|
|
2031
|
+
className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 font-medium text-sm transition-colors ${activeTab === tab.id ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
|
|
1252
2032
|
children: [
|
|
1253
|
-
/* @__PURE__ */
|
|
2033
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
1254
2034
|
children: tab.icon
|
|
1255
2035
|
}, undefined, false, undefined, this),
|
|
1256
2036
|
tab.label
|
|
1257
2037
|
]
|
|
1258
2038
|
}, tab.id, true, undefined, this))
|
|
1259
2039
|
}, undefined, false, undefined, this),
|
|
1260
|
-
/* @__PURE__ */
|
|
2040
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
1261
2041
|
className: "min-h-[400px]",
|
|
1262
2042
|
role: "tabpanel",
|
|
1263
2043
|
children: [
|
|
1264
|
-
activeTab === "dashboards" && /* @__PURE__ */
|
|
2044
|
+
activeTab === "dashboards" && /* @__PURE__ */ jsxDEV3("div", {
|
|
1265
2045
|
className: "space-y-6",
|
|
1266
2046
|
children: [
|
|
1267
|
-
/* @__PURE__ */
|
|
2047
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
1268
2048
|
className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
1269
2049
|
children: [
|
|
1270
|
-
dashboards.map((dashboard) => /* @__PURE__ */
|
|
2050
|
+
dashboards.map((dashboard) => /* @__PURE__ */ jsxDEV3("div", {
|
|
1271
2051
|
onClick: () => selectDashboard(dashboard),
|
|
1272
|
-
className: `
|
|
2052
|
+
className: `cursor-pointer rounded-lg border border-border bg-card p-4 transition-all ${selectedDashboard?.id === dashboard.id ? "ring-2 ring-primary" : "hover:bg-muted/50"}`,
|
|
1273
2053
|
role: "button",
|
|
1274
2054
|
tabIndex: 0,
|
|
1275
2055
|
onKeyDown: (e) => {
|
|
@@ -1277,33 +2057,33 @@ function AnalyticsDashboard() {
|
|
|
1277
2057
|
selectDashboard(dashboard);
|
|
1278
2058
|
},
|
|
1279
2059
|
children: [
|
|
1280
|
-
/* @__PURE__ */
|
|
2060
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
1281
2061
|
className: "mb-2 flex items-center justify-between",
|
|
1282
2062
|
children: [
|
|
1283
|
-
/* @__PURE__ */
|
|
2063
|
+
/* @__PURE__ */ jsxDEV3("h3", {
|
|
1284
2064
|
className: "font-medium",
|
|
1285
2065
|
children: dashboard.name
|
|
1286
2066
|
}, undefined, false, undefined, this),
|
|
1287
|
-
/* @__PURE__ */
|
|
1288
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs
|
|
2067
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
2068
|
+
className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${STATUS_COLORS[dashboard.status] ?? ""}`,
|
|
1289
2069
|
children: dashboard.status
|
|
1290
2070
|
}, undefined, false, undefined, this)
|
|
1291
2071
|
]
|
|
1292
2072
|
}, undefined, true, undefined, this),
|
|
1293
|
-
/* @__PURE__ */
|
|
1294
|
-
className: "text-muted-foreground
|
|
2073
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
2074
|
+
className: "mb-3 text-muted-foreground text-sm",
|
|
1295
2075
|
children: dashboard.description
|
|
1296
2076
|
}, undefined, false, undefined, this),
|
|
1297
|
-
/* @__PURE__ */
|
|
1298
|
-
className: "
|
|
2077
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
2078
|
+
className: "flex items-center justify-between text-muted-foreground text-xs",
|
|
1299
2079
|
children: [
|
|
1300
|
-
/* @__PURE__ */
|
|
2080
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
1301
2081
|
children: [
|
|
1302
2082
|
"/",
|
|
1303
2083
|
dashboard.slug
|
|
1304
2084
|
]
|
|
1305
2085
|
}, undefined, true, undefined, this),
|
|
1306
|
-
dashboard.isPublic && /* @__PURE__ */
|
|
2086
|
+
dashboard.isPublic && /* @__PURE__ */ jsxDEV3("span", {
|
|
1307
2087
|
className: "text-green-600 dark:text-green-400",
|
|
1308
2088
|
children: "\uD83C\uDF10 Public"
|
|
1309
2089
|
}, undefined, false, undefined, this)
|
|
@@ -1311,149 +2091,20 @@ function AnalyticsDashboard() {
|
|
|
1311
2091
|
}, undefined, true, undefined, this)
|
|
1312
2092
|
]
|
|
1313
2093
|
}, dashboard.id, true, undefined, this)),
|
|
1314
|
-
dashboards.length === 0 && /* @__PURE__ */
|
|
1315
|
-
className: "
|
|
2094
|
+
dashboards.length === 0 && /* @__PURE__ */ jsxDEV3("div", {
|
|
2095
|
+
className: "col-span-full flex h-64 items-center justify-center text-muted-foreground",
|
|
1316
2096
|
children: "No dashboards created yet"
|
|
1317
2097
|
}, undefined, false, undefined, this)
|
|
1318
2098
|
]
|
|
1319
2099
|
}, undefined, true, undefined, this),
|
|
1320
|
-
selectedDashboard
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
children: [
|
|
1325
|
-
'Widgets in "',
|
|
1326
|
-
selectedDashboard.name,
|
|
1327
|
-
'"'
|
|
1328
|
-
]
|
|
1329
|
-
}, undefined, true, undefined, this),
|
|
1330
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1331
|
-
className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
1332
|
-
children: widgets.map((widget) => /* @__PURE__ */ jsxDEV("div", {
|
|
1333
|
-
className: "border-border bg-card rounded-lg border p-4",
|
|
1334
|
-
children: [
|
|
1335
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1336
|
-
className: "mb-2 flex items-center gap-2",
|
|
1337
|
-
children: [
|
|
1338
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
1339
|
-
className: "text-xl",
|
|
1340
|
-
children: WIDGET_ICONS[widget.type] ?? "\uD83D\uDCCA"
|
|
1341
|
-
}, undefined, false, undefined, this),
|
|
1342
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
1343
|
-
className: "font-medium",
|
|
1344
|
-
children: widget.name
|
|
1345
|
-
}, undefined, false, undefined, this)
|
|
1346
|
-
]
|
|
1347
|
-
}, undefined, true, undefined, this),
|
|
1348
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1349
|
-
className: "text-muted-foreground text-sm",
|
|
1350
|
-
children: widget.type.replace(/_/g, " ")
|
|
1351
|
-
}, undefined, false, undefined, this),
|
|
1352
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1353
|
-
className: "text-muted-foreground mt-2 text-xs",
|
|
1354
|
-
children: [
|
|
1355
|
-
"Position: (",
|
|
1356
|
-
widget.gridX,
|
|
1357
|
-
", ",
|
|
1358
|
-
widget.gridY,
|
|
1359
|
-
") •",
|
|
1360
|
-
" ",
|
|
1361
|
-
widget.gridWidth,
|
|
1362
|
-
"x",
|
|
1363
|
-
widget.gridHeight
|
|
1364
|
-
]
|
|
1365
|
-
}, undefined, true, undefined, this)
|
|
1366
|
-
]
|
|
1367
|
-
}, widget.id, true, undefined, this))
|
|
1368
|
-
}, undefined, false, undefined, this)
|
|
1369
|
-
]
|
|
1370
|
-
}, undefined, true, undefined, this)
|
|
2100
|
+
selectedDashboard ? /* @__PURE__ */ jsxDEV3(AnalyticsWidgetBoard, {
|
|
2101
|
+
dashboardName: selectedDashboard.name,
|
|
2102
|
+
widgets: resolvedWidgets
|
|
2103
|
+
}, undefined, false, undefined, this) : null
|
|
1371
2104
|
]
|
|
1372
2105
|
}, undefined, true, undefined, this),
|
|
1373
|
-
activeTab === "queries" && /* @__PURE__ */
|
|
1374
|
-
|
|
1375
|
-
children: /* @__PURE__ */ jsxDEV("table", {
|
|
1376
|
-
className: "w-full",
|
|
1377
|
-
children: [
|
|
1378
|
-
/* @__PURE__ */ jsxDEV("thead", {
|
|
1379
|
-
className: "border-border bg-muted/30 border-b",
|
|
1380
|
-
children: /* @__PURE__ */ jsxDEV("tr", {
|
|
1381
|
-
children: [
|
|
1382
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
1383
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1384
|
-
children: "Query"
|
|
1385
|
-
}, undefined, false, undefined, this),
|
|
1386
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
1387
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1388
|
-
children: "Type"
|
|
1389
|
-
}, undefined, false, undefined, this),
|
|
1390
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
1391
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1392
|
-
children: "Cache TTL"
|
|
1393
|
-
}, undefined, false, undefined, this),
|
|
1394
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
1395
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
1396
|
-
children: "Shared"
|
|
1397
|
-
}, undefined, false, undefined, this)
|
|
1398
|
-
]
|
|
1399
|
-
}, undefined, true, undefined, this)
|
|
1400
|
-
}, undefined, false, undefined, this),
|
|
1401
|
-
/* @__PURE__ */ jsxDEV("tbody", {
|
|
1402
|
-
className: "divide-border divide-y",
|
|
1403
|
-
children: [
|
|
1404
|
-
queries.map((query) => /* @__PURE__ */ jsxDEV("tr", {
|
|
1405
|
-
className: "hover:bg-muted/50",
|
|
1406
|
-
children: [
|
|
1407
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
1408
|
-
className: "px-4 py-3",
|
|
1409
|
-
children: [
|
|
1410
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1411
|
-
className: "font-medium",
|
|
1412
|
-
children: query.name
|
|
1413
|
-
}, undefined, false, undefined, this),
|
|
1414
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
1415
|
-
className: "text-muted-foreground text-sm",
|
|
1416
|
-
children: query.description
|
|
1417
|
-
}, undefined, false, undefined, this)
|
|
1418
|
-
]
|
|
1419
|
-
}, undefined, true, undefined, this),
|
|
1420
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
1421
|
-
className: "px-4 py-3",
|
|
1422
|
-
children: /* @__PURE__ */ jsxDEV("span", {
|
|
1423
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${QUERY_TYPE_COLORS[query.type] ?? ""}`,
|
|
1424
|
-
children: query.type
|
|
1425
|
-
}, undefined, false, undefined, this)
|
|
1426
|
-
}, undefined, false, undefined, this),
|
|
1427
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
1428
|
-
className: "text-muted-foreground px-4 py-3 text-sm",
|
|
1429
|
-
children: [
|
|
1430
|
-
query.cacheTtlSeconds,
|
|
1431
|
-
"s"
|
|
1432
|
-
]
|
|
1433
|
-
}, undefined, true, undefined, this),
|
|
1434
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
1435
|
-
className: "px-4 py-3",
|
|
1436
|
-
children: query.isShared ? /* @__PURE__ */ jsxDEV("span", {
|
|
1437
|
-
className: "text-green-600 dark:text-green-400",
|
|
1438
|
-
children: "✓"
|
|
1439
|
-
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV("span", {
|
|
1440
|
-
className: "text-muted-foreground",
|
|
1441
|
-
children: "—"
|
|
1442
|
-
}, undefined, false, undefined, this)
|
|
1443
|
-
}, undefined, false, undefined, this)
|
|
1444
|
-
]
|
|
1445
|
-
}, query.id, true, undefined, this)),
|
|
1446
|
-
queries.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
|
|
1447
|
-
children: /* @__PURE__ */ jsxDEV("td", {
|
|
1448
|
-
colSpan: 4,
|
|
1449
|
-
className: "text-muted-foreground px-4 py-8 text-center",
|
|
1450
|
-
children: "No queries saved"
|
|
1451
|
-
}, undefined, false, undefined, this)
|
|
1452
|
-
}, undefined, false, undefined, this)
|
|
1453
|
-
]
|
|
1454
|
-
}, undefined, true, undefined, this)
|
|
1455
|
-
]
|
|
1456
|
-
}, undefined, true, undefined, this)
|
|
2106
|
+
activeTab === "queries" && /* @__PURE__ */ jsxDEV3(AnalyticsQueriesTable, {
|
|
2107
|
+
queries
|
|
1457
2108
|
}, undefined, false, undefined, this)
|
|
1458
2109
|
]
|
|
1459
2110
|
}, undefined, true, undefined, this)
|
|
@@ -1463,222 +2114,204 @@ function AnalyticsDashboard() {
|
|
|
1463
2114
|
|
|
1464
2115
|
// src/ui/hooks/index.ts
|
|
1465
2116
|
"use client";
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
2117
|
+
|
|
2118
|
+
// src/ui/renderers/analytics.markdown.ts
|
|
2119
|
+
var mockDashboards = [
|
|
2120
|
+
{
|
|
2121
|
+
id: "dash-1",
|
|
2122
|
+
name: "Sales Overview",
|
|
2123
|
+
slug: "sales-overview",
|
|
2124
|
+
status: "PUBLISHED",
|
|
2125
|
+
widgetCount: 11,
|
|
2126
|
+
viewCount: 1250,
|
|
2127
|
+
lastViewedAt: "2026-03-18T12:00:00Z"
|
|
2128
|
+
},
|
|
2129
|
+
{
|
|
2130
|
+
id: "dash-2",
|
|
2131
|
+
name: "User Engagement",
|
|
2132
|
+
slug: "user-engagement",
|
|
2133
|
+
status: "PUBLISHED",
|
|
2134
|
+
widgetCount: 8,
|
|
2135
|
+
viewCount: 890,
|
|
2136
|
+
lastViewedAt: "2026-03-18T10:00:00Z"
|
|
1482
2137
|
}
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
2138
|
+
];
|
|
2139
|
+
var mockQueries = [
|
|
2140
|
+
{
|
|
2141
|
+
id: "q-1",
|
|
2142
|
+
name: "Monthly Revenue",
|
|
2143
|
+
type: "AGGREGATION",
|
|
2144
|
+
isShared: true,
|
|
2145
|
+
executionCount: 1500
|
|
2146
|
+
},
|
|
2147
|
+
{
|
|
2148
|
+
id: "q-2",
|
|
2149
|
+
name: "User Growth",
|
|
2150
|
+
type: "METRIC",
|
|
2151
|
+
isShared: true,
|
|
2152
|
+
executionCount: 890
|
|
2153
|
+
},
|
|
2154
|
+
{
|
|
2155
|
+
id: "q-3",
|
|
2156
|
+
name: "Product Sales",
|
|
2157
|
+
type: "SQL",
|
|
2158
|
+
isShared: false,
|
|
2159
|
+
executionCount: 340
|
|
2160
|
+
},
|
|
2161
|
+
{
|
|
2162
|
+
id: "q-4",
|
|
2163
|
+
name: "Conversion Funnel",
|
|
2164
|
+
type: "AGGREGATION",
|
|
2165
|
+
isShared: true,
|
|
2166
|
+
executionCount: 450
|
|
1490
2167
|
}
|
|
2168
|
+
];
|
|
2169
|
+
function dashboardWidgets(dashboardId) {
|
|
2170
|
+
return createExampleWidgets(dashboardId).map((widget2) => resolveAnalyticsWidget(widget2)).filter((widget2) => Boolean(widget2));
|
|
1491
2171
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
const validation = this.validateQuery(definition);
|
|
1501
|
-
if (!validation.valid) {
|
|
2172
|
+
var analyticsDashboardMarkdownRenderer = {
|
|
2173
|
+
target: "markdown",
|
|
2174
|
+
render: async (desc) => {
|
|
2175
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "AnalyticsDashboard") {
|
|
2176
|
+
throw new Error("analyticsDashboardMarkdownRenderer: not AnalyticsDashboard");
|
|
2177
|
+
}
|
|
2178
|
+
const dashboard = mockDashboards[0];
|
|
2179
|
+
if (!dashboard) {
|
|
1502
2180
|
return {
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
cached: false,
|
|
1508
|
-
error: validation.errors.join(", ")
|
|
2181
|
+
mimeType: "text/markdown",
|
|
2182
|
+
body: `# No Dashboards
|
|
2183
|
+
|
|
2184
|
+
No dashboards available.`
|
|
1509
2185
|
};
|
|
1510
2186
|
}
|
|
1511
|
-
const
|
|
1512
|
-
const
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
throw new Error("Metric IDs are missing");
|
|
1527
|
-
}
|
|
1528
|
-
result = await this.executeMetric(definition.metricIds, params);
|
|
1529
|
-
break;
|
|
1530
|
-
case "SQL":
|
|
1531
|
-
if (!definition.sql) {
|
|
1532
|
-
throw new Error("SQL query is missing");
|
|
1533
|
-
}
|
|
1534
|
-
result = await this.executeSql(definition.sql, params);
|
|
1535
|
-
break;
|
|
1536
|
-
default:
|
|
1537
|
-
result = {
|
|
1538
|
-
data: [],
|
|
1539
|
-
columns: [],
|
|
1540
|
-
rowCount: 0,
|
|
1541
|
-
executionTimeMs: Date.now() - startTime,
|
|
1542
|
-
cached: false,
|
|
1543
|
-
error: `Unknown query type: ${definition.type}`
|
|
1544
|
-
};
|
|
1545
|
-
}
|
|
1546
|
-
result.executionTimeMs = Date.now() - startTime;
|
|
1547
|
-
result.cached = false;
|
|
1548
|
-
await this.cache.set(cacheKey, result, 300);
|
|
1549
|
-
return result;
|
|
1550
|
-
}
|
|
1551
|
-
validateQuery(definition) {
|
|
1552
|
-
const errors = [];
|
|
1553
|
-
if (!definition.type) {
|
|
1554
|
-
errors.push("Query type is required");
|
|
2187
|
+
const widgets = dashboardWidgets(dashboard.id);
|
|
2188
|
+
const metricWidgets = widgets.filter((widget2) => widget2.bindings[0]?.spec.visualization.kind === "metric");
|
|
2189
|
+
const lines = [
|
|
2190
|
+
`# ${dashboard.name}`,
|
|
2191
|
+
"",
|
|
2192
|
+
"> Contract-backed analytics dashboard overview.",
|
|
2193
|
+
"",
|
|
2194
|
+
"## Key Metrics",
|
|
2195
|
+
""
|
|
2196
|
+
];
|
|
2197
|
+
for (const widget2 of metricWidgets) {
|
|
2198
|
+
const binding2 = widget2.bindings[0];
|
|
2199
|
+
if (!binding2)
|
|
2200
|
+
continue;
|
|
2201
|
+
lines.push(`- **${widget2.name}** via \`${binding2.spec.meta.key}\``);
|
|
1555
2202
|
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
case "METRIC":
|
|
1563
|
-
if (!definition.metricIds || definition.metricIds.length === 0) {
|
|
1564
|
-
errors.push("Metric IDs are required for METRIC type");
|
|
1565
|
-
}
|
|
1566
|
-
break;
|
|
1567
|
-
case "AGGREGATION":
|
|
1568
|
-
if (!definition.aggregation) {
|
|
1569
|
-
errors.push("Aggregation definition is required for AGGREGATION type");
|
|
1570
|
-
} else {
|
|
1571
|
-
if (!definition.aggregation.source) {
|
|
1572
|
-
errors.push("Aggregation source is required");
|
|
1573
|
-
}
|
|
1574
|
-
if (!definition.aggregation.measures || definition.aggregation.measures.length === 0) {
|
|
1575
|
-
errors.push("At least one measure is required");
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1578
|
-
break;
|
|
2203
|
+
lines.push("");
|
|
2204
|
+
lines.push("## Visual Blocks");
|
|
2205
|
+
lines.push("");
|
|
2206
|
+
for (const widget2 of widgets) {
|
|
2207
|
+
const kinds = widget2.bindings.map((binding2) => binding2.spec.visualization.kind).join(", ");
|
|
2208
|
+
lines.push(`- **${widget2.name}** (${widget2.layout}) → ${kinds}`);
|
|
1579
2209
|
}
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
name: d.name,
|
|
1589
|
-
type: d.type === "NUMBER" ? "NUMBER" : d.type === "TIME" ? "DATE" : "STRING",
|
|
1590
|
-
label: d.name
|
|
1591
|
-
})),
|
|
1592
|
-
...aggregation.measures.map((m) => ({
|
|
1593
|
-
name: m.name,
|
|
1594
|
-
type: "NUMBER",
|
|
1595
|
-
label: m.name,
|
|
1596
|
-
format: m.format
|
|
1597
|
-
}))
|
|
1598
|
-
];
|
|
1599
|
-
const data = this.generateMockData(aggregation, params);
|
|
2210
|
+
lines.push("");
|
|
2211
|
+
lines.push("## Dashboard Stats");
|
|
2212
|
+
lines.push("");
|
|
2213
|
+
lines.push("| Metric | Value |");
|
|
2214
|
+
lines.push("|--------|-------|");
|
|
2215
|
+
lines.push(`| Total Dashboards | ${mockDashboards.length} |`);
|
|
2216
|
+
lines.push(`| Published | ${mockDashboards.filter((item) => item.status === "PUBLISHED").length} |`);
|
|
2217
|
+
lines.push(`| Shared Queries | ${mockQueries.filter((query) => query.isShared).length} |`);
|
|
1600
2218
|
return {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
executionTimeMs: 0,
|
|
1605
|
-
cached: false
|
|
2219
|
+
mimeType: "text/markdown",
|
|
2220
|
+
body: lines.join(`
|
|
2221
|
+
`)
|
|
1606
2222
|
};
|
|
1607
2223
|
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
2224
|
+
};
|
|
2225
|
+
var dashboardListMarkdownRenderer = {
|
|
2226
|
+
target: "markdown",
|
|
2227
|
+
render: async (desc) => {
|
|
2228
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "DashboardList") {
|
|
2229
|
+
throw new Error("dashboardListMarkdownRenderer: not DashboardList");
|
|
2230
|
+
}
|
|
2231
|
+
const lines = [
|
|
2232
|
+
"# Dashboards",
|
|
2233
|
+
"",
|
|
2234
|
+
"> Browse and manage analytics dashboards",
|
|
2235
|
+
"",
|
|
2236
|
+
"| Dashboard | Widgets | Views | Status | Last Viewed |",
|
|
2237
|
+
"|-----------|---------|-------|--------|-------------|"
|
|
2238
|
+
];
|
|
2239
|
+
for (const dashboard of mockDashboards) {
|
|
2240
|
+
const lastViewed = dashboard.lastViewedAt ? new Date(dashboard.lastViewedAt).toLocaleDateString() : "Never";
|
|
2241
|
+
const statusIcon = dashboard.status === "PUBLISHED" ? "\uD83D\uDFE2" : "⚫";
|
|
2242
|
+
lines.push(`| [${dashboard.name}](/dashboards/${dashboard.slug}) | ${dashboard.widgetCount} | ${dashboard.viewCount.toLocaleString()} | ${statusIcon} ${dashboard.status} | ${lastViewed} |`);
|
|
2243
|
+
}
|
|
1614
2244
|
return {
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
{ name: "value", type: "NUMBER" },
|
|
1619
|
-
{ name: "change", type: "NUMBER" }
|
|
1620
|
-
],
|
|
1621
|
-
rowCount: data.length,
|
|
1622
|
-
executionTimeMs: 0,
|
|
1623
|
-
cached: false
|
|
2245
|
+
mimeType: "text/markdown",
|
|
2246
|
+
body: lines.join(`
|
|
2247
|
+
`)
|
|
1624
2248
|
};
|
|
1625
2249
|
}
|
|
1626
|
-
|
|
2250
|
+
};
|
|
2251
|
+
var queryBuilderMarkdownRenderer = {
|
|
2252
|
+
target: "markdown",
|
|
2253
|
+
render: async (desc) => {
|
|
2254
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "QueryBuilder") {
|
|
2255
|
+
throw new Error("queryBuilderMarkdownRenderer: not QueryBuilder");
|
|
2256
|
+
}
|
|
2257
|
+
const lines = [
|
|
2258
|
+
"# Query Builder",
|
|
2259
|
+
"",
|
|
2260
|
+
"> Create and manage reusable data queries.",
|
|
2261
|
+
"",
|
|
2262
|
+
"| Query | Type | Shared | Executions |",
|
|
2263
|
+
"|-------|------|--------|------------|"
|
|
2264
|
+
];
|
|
2265
|
+
for (const query of mockQueries) {
|
|
2266
|
+
lines.push(`| ${query.name} | ${query.type} | ${query.isShared ? "\uD83C\uDF10" : "\uD83D\uDD12"} | ${query.executionCount.toLocaleString()} |`);
|
|
2267
|
+
}
|
|
2268
|
+
lines.push("");
|
|
2269
|
+
lines.push("## Visualization Contracts");
|
|
2270
|
+
lines.push("");
|
|
2271
|
+
lines.push("Widgets reference `VisualizationSpec` contracts instead of rendering ad-hoc widget types.");
|
|
1627
2272
|
return {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
executionTimeMs: 0,
|
|
1632
|
-
cached: false,
|
|
1633
|
-
error: "SQL execution not implemented in demo"
|
|
2273
|
+
mimeType: "text/markdown",
|
|
2274
|
+
body: lines.join(`
|
|
2275
|
+
`)
|
|
1634
2276
|
};
|
|
1635
2277
|
}
|
|
1636
|
-
|
|
1637
|
-
const data = [];
|
|
1638
|
-
const rowCount = 10;
|
|
1639
|
-
const timeDimension = aggregation.dimensions.find((d) => d.type === "TIME");
|
|
1640
|
-
for (let i = 0;i < rowCount; i++) {
|
|
1641
|
-
const row = {};
|
|
1642
|
-
for (const dim of aggregation.dimensions) {
|
|
1643
|
-
if (dim.type === "TIME") {
|
|
1644
|
-
const date = new Date(params.dateRange?.start ?? new Date);
|
|
1645
|
-
date.setDate(date.getDate() + i);
|
|
1646
|
-
row[dim.name] = date.toISOString().split("T")[0];
|
|
1647
|
-
} else {
|
|
1648
|
-
row[dim.name] = `${dim.name}_${i % 5}`;
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
for (const measure of aggregation.measures) {
|
|
1652
|
-
const baseValue = timeDimension ? 100 + i * 10 : Math.random() * 1000;
|
|
1653
|
-
const noise = (Math.random() - 0.5) * 20;
|
|
1654
|
-
row[measure.name] = Math.round((baseValue + noise) * 100) / 100;
|
|
1655
|
-
}
|
|
1656
|
-
data.push(row);
|
|
1657
|
-
}
|
|
1658
|
-
return data;
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
function createQueryEngine(cache) {
|
|
1662
|
-
return new BasicQueryEngine(cache);
|
|
1663
|
-
}
|
|
2278
|
+
};
|
|
1664
2279
|
export {
|
|
2280
|
+
visualizationRefKey,
|
|
1665
2281
|
useAnalyticsData,
|
|
2282
|
+
resolveAnalyticsWidget,
|
|
2283
|
+
refOf,
|
|
1666
2284
|
queryBuilderMarkdownRenderer,
|
|
1667
2285
|
dashboardListMarkdownRenderer,
|
|
1668
2286
|
createQueryEngine,
|
|
1669
2287
|
createPosthogQueryEngine,
|
|
2288
|
+
createExampleWidgets,
|
|
1670
2289
|
createAnalyticsHandlers,
|
|
1671
2290
|
analyticsDashboardMarkdownRenderer,
|
|
2291
|
+
RevenueTrendVisualization,
|
|
2292
|
+
RevenueMetricVisualization,
|
|
2293
|
+
RetentionAreaVisualization,
|
|
2294
|
+
RegionalRevenueVisualization,
|
|
1672
2295
|
QueryTypeEnum,
|
|
1673
2296
|
QueryResultModel,
|
|
1674
2297
|
QueryModel,
|
|
1675
2298
|
PosthogQueryEngine,
|
|
2299
|
+
PipelineScatterVisualization,
|
|
1676
2300
|
InMemoryQueryCache,
|
|
1677
2301
|
ExecuteQueryInputModel,
|
|
1678
2302
|
ExecuteQueryContract,
|
|
2303
|
+
EngagementHeatmapVisualization,
|
|
1679
2304
|
CreateQueryInputModel,
|
|
1680
2305
|
CreateQueryContract,
|
|
2306
|
+
ConversionFunnelVisualization,
|
|
2307
|
+
ChannelMixVisualization,
|
|
1681
2308
|
BasicQueryEngine,
|
|
2309
|
+
AnalyticsVisualizationSpecs,
|
|
2310
|
+
AnalyticsVisualizationSpecMap,
|
|
2311
|
+
AnalyticsVisualizationSampleData,
|
|
2312
|
+
AnalyticsVisualizationRegistry,
|
|
2313
|
+
AnalyticsVisualizationRefs,
|
|
1682
2314
|
AnalyticsDashboardFeature,
|
|
1683
|
-
AnalyticsDashboard
|
|
2315
|
+
AnalyticsDashboard,
|
|
2316
|
+
AccountCoverageGeoVisualization
|
|
1684
2317
|
};
|