@contractspec/example.analytics-dashboard 3.7.6 → 3.8.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.
- package/README.md +64 -271
- package/dist/browser/dashboard.feature.js +592 -0
- package/dist/browser/events.js +1 -1
- package/dist/browser/index.js +1171 -627
- package/dist/browser/ui/AnalyticsDashboard.js +826 -194
- package/dist/browser/ui/AnalyticsDashboard.widgets.js +94 -0
- package/dist/browser/ui/AnalyticsQueriesTable.js +99 -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 +964 -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/events.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1171 -627
- package/dist/node/dashboard.feature.js +592 -0
- package/dist/node/events.js +1 -1
- package/dist/node/index.js +1171 -627
- package/dist/node/ui/AnalyticsDashboard.js +826 -194
- package/dist/node/ui/AnalyticsDashboard.widgets.js +94 -0
- package/dist/node/ui/AnalyticsQueriesTable.js +99 -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 +964 -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 +826 -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 +100 -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 +964 -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 +105 -7
|
@@ -1,7 +1,787 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// src/visualizations/specs.breakdown.ts
|
|
3
|
+
import { defineVisualization } from "@contractspec/lib.contracts-spec/visualizations";
|
|
4
|
+
var QUERY_REF = { key: "analytics.query.execute", version: "1.0.0" };
|
|
5
|
+
var META = {
|
|
6
|
+
version: "1.0.0",
|
|
7
|
+
domain: "analytics",
|
|
8
|
+
stability: "experimental",
|
|
9
|
+
owners: ["@example.analytics-dashboard"],
|
|
10
|
+
tags: ["analytics", "dashboard", "visualization"]
|
|
11
|
+
};
|
|
12
|
+
var ChannelMixVisualization = defineVisualization({
|
|
13
|
+
meta: {
|
|
14
|
+
...META,
|
|
15
|
+
key: "analytics.visualization.channel-mix",
|
|
16
|
+
title: "Channel Mix",
|
|
17
|
+
description: "Session distribution across acquisition channels.",
|
|
18
|
+
goal: "Explain which channels currently drive the largest share of traffic.",
|
|
19
|
+
context: "Marketing attribution dashboard."
|
|
20
|
+
},
|
|
21
|
+
source: { primary: QUERY_REF, resultPath: "data" },
|
|
22
|
+
visualization: {
|
|
23
|
+
kind: "pie",
|
|
24
|
+
nameDimension: "channel",
|
|
25
|
+
valueMeasure: "sessions",
|
|
26
|
+
dimensions: [
|
|
27
|
+
{
|
|
28
|
+
key: "channel",
|
|
29
|
+
label: "Channel",
|
|
30
|
+
dataPath: "channel",
|
|
31
|
+
type: "category"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
measures: [{ key: "sessions", label: "Sessions", dataPath: "sessions" }],
|
|
35
|
+
table: { caption: "Sessions by acquisition channel." }
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
var EngagementHeatmapVisualization = defineVisualization({
|
|
39
|
+
meta: {
|
|
40
|
+
...META,
|
|
41
|
+
key: "analytics.visualization.engagement-heatmap",
|
|
42
|
+
title: "Engagement Heatmap",
|
|
43
|
+
description: "Average engagement score by weekday and time band.",
|
|
44
|
+
goal: "Reveal the highest-engagement time windows for product activity.",
|
|
45
|
+
context: "Usage analytics dashboard."
|
|
46
|
+
},
|
|
47
|
+
source: { primary: QUERY_REF, resultPath: "data" },
|
|
48
|
+
visualization: {
|
|
49
|
+
kind: "heatmap",
|
|
50
|
+
xDimension: "timeBand",
|
|
51
|
+
yDimension: "weekday",
|
|
52
|
+
valueMeasure: "engagementScore",
|
|
53
|
+
dimensions: [
|
|
54
|
+
{
|
|
55
|
+
key: "timeBand",
|
|
56
|
+
label: "Time Band",
|
|
57
|
+
dataPath: "timeBand",
|
|
58
|
+
type: "category"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
key: "weekday",
|
|
62
|
+
label: "Weekday",
|
|
63
|
+
dataPath: "weekday",
|
|
64
|
+
type: "category"
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
measures: [
|
|
68
|
+
{
|
|
69
|
+
key: "engagementScore",
|
|
70
|
+
label: "Engagement",
|
|
71
|
+
dataPath: "engagementScore"
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
table: { caption: "Engagement score by weekday and time band." }
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var ConversionFunnelVisualization = defineVisualization({
|
|
78
|
+
meta: {
|
|
79
|
+
...META,
|
|
80
|
+
key: "analytics.visualization.conversion-funnel",
|
|
81
|
+
title: "Conversion Funnel",
|
|
82
|
+
description: "Progression through the main acquisition funnel.",
|
|
83
|
+
goal: "Show where the product is losing the largest share of prospects.",
|
|
84
|
+
context: "Growth dashboard."
|
|
85
|
+
},
|
|
86
|
+
source: { primary: QUERY_REF, resultPath: "data" },
|
|
87
|
+
visualization: {
|
|
88
|
+
kind: "funnel",
|
|
89
|
+
nameDimension: "stage",
|
|
90
|
+
valueMeasure: "users",
|
|
91
|
+
sort: "descending",
|
|
92
|
+
dimensions: [
|
|
93
|
+
{ key: "stage", label: "Stage", dataPath: "stage", type: "category" }
|
|
94
|
+
],
|
|
95
|
+
measures: [{ key: "users", label: "Users", dataPath: "users" }],
|
|
96
|
+
table: { caption: "Users per conversion stage." }
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
var AccountCoverageGeoVisualization = defineVisualization({
|
|
100
|
+
meta: {
|
|
101
|
+
...META,
|
|
102
|
+
key: "analytics.visualization.account-coverage-geo",
|
|
103
|
+
title: "Account Coverage",
|
|
104
|
+
description: "High-value accounts plotted on a slippy-map surface.",
|
|
105
|
+
goal: "Locate where active commercial concentration is strongest.",
|
|
106
|
+
context: "Territory coverage dashboard."
|
|
107
|
+
},
|
|
108
|
+
source: { primary: QUERY_REF, resultPath: "data" },
|
|
109
|
+
visualization: {
|
|
110
|
+
kind: "geo",
|
|
111
|
+
mode: "slippy-map",
|
|
112
|
+
variant: "scatter",
|
|
113
|
+
nameDimension: "city",
|
|
114
|
+
latitudeDimension: "latitude",
|
|
115
|
+
longitudeDimension: "longitude",
|
|
116
|
+
valueMeasure: "accounts",
|
|
117
|
+
dimensions: [
|
|
118
|
+
{ key: "city", label: "City", dataPath: "city", type: "category" },
|
|
119
|
+
{
|
|
120
|
+
key: "latitude",
|
|
121
|
+
label: "Latitude",
|
|
122
|
+
dataPath: "latitude",
|
|
123
|
+
type: "latitude"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
key: "longitude",
|
|
127
|
+
label: "Longitude",
|
|
128
|
+
dataPath: "longitude",
|
|
129
|
+
type: "longitude"
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
measures: [{ key: "accounts", label: "Accounts", dataPath: "accounts" }],
|
|
133
|
+
table: { caption: "Account concentration by city." }
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// src/visualizations/specs.performance.ts
|
|
138
|
+
import { defineVisualization as defineVisualization2 } from "@contractspec/lib.contracts-spec/visualizations";
|
|
139
|
+
var QUERY_REF2 = { key: "analytics.query.execute", version: "1.0.0" };
|
|
140
|
+
var META2 = {
|
|
141
|
+
version: "1.0.0",
|
|
142
|
+
domain: "analytics",
|
|
143
|
+
stability: "experimental",
|
|
144
|
+
owners: ["@example.analytics-dashboard"],
|
|
145
|
+
tags: ["analytics", "dashboard", "visualization"]
|
|
146
|
+
};
|
|
147
|
+
var RevenueMetricVisualization = defineVisualization2({
|
|
148
|
+
meta: {
|
|
149
|
+
...META2,
|
|
150
|
+
key: "analytics.visualization.revenue-metric",
|
|
151
|
+
title: "Revenue Snapshot",
|
|
152
|
+
description: "Current recurring revenue with prior-period comparison.",
|
|
153
|
+
goal: "Highlight the headline commercial metric for the dashboard.",
|
|
154
|
+
context: "Executive revenue overview."
|
|
155
|
+
},
|
|
156
|
+
source: { primary: QUERY_REF2, resultPath: "data" },
|
|
157
|
+
visualization: {
|
|
158
|
+
kind: "metric",
|
|
159
|
+
measure: "totalRevenue",
|
|
160
|
+
comparisonMeasure: "priorRevenue",
|
|
161
|
+
dimensions: [
|
|
162
|
+
{ key: "period", label: "Period", dataPath: "period", type: "time" }
|
|
163
|
+
],
|
|
164
|
+
measures: [
|
|
165
|
+
{
|
|
166
|
+
key: "totalRevenue",
|
|
167
|
+
label: "Revenue",
|
|
168
|
+
dataPath: "totalRevenue",
|
|
169
|
+
format: "currency"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
key: "priorRevenue",
|
|
173
|
+
label: "Prior Revenue",
|
|
174
|
+
dataPath: "priorRevenue",
|
|
175
|
+
format: "currency"
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
sparkline: { dimension: "period", measure: "totalRevenue" },
|
|
179
|
+
table: { caption: "Revenue trend and prior period values." }
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
var RevenueTrendVisualization = defineVisualization2({
|
|
183
|
+
meta: {
|
|
184
|
+
...META2,
|
|
185
|
+
key: "analytics.visualization.revenue-trend",
|
|
186
|
+
title: "Revenue Trend",
|
|
187
|
+
description: "Monthly revenue progression for the current quarter.",
|
|
188
|
+
goal: "Track whether revenue growth is accelerating or stalling.",
|
|
189
|
+
context: "Quarterly commercial dashboard."
|
|
190
|
+
},
|
|
191
|
+
source: { primary: QUERY_REF2, resultPath: "data" },
|
|
192
|
+
visualization: {
|
|
193
|
+
kind: "cartesian",
|
|
194
|
+
variant: "line",
|
|
195
|
+
xDimension: "date",
|
|
196
|
+
yMeasures: ["revenue"],
|
|
197
|
+
dimensions: [
|
|
198
|
+
{ key: "date", label: "Month", dataPath: "date", type: "time" }
|
|
199
|
+
],
|
|
200
|
+
measures: [
|
|
201
|
+
{
|
|
202
|
+
key: "revenue",
|
|
203
|
+
label: "Revenue",
|
|
204
|
+
dataPath: "revenue",
|
|
205
|
+
format: "currency",
|
|
206
|
+
color: "#0f766e"
|
|
207
|
+
}
|
|
208
|
+
],
|
|
209
|
+
thresholds: [
|
|
210
|
+
{ key: "target", value: 140000, label: "Target", color: "#dc2626" }
|
|
211
|
+
],
|
|
212
|
+
table: { caption: "Monthly revenue values." }
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
var RegionalRevenueVisualization = defineVisualization2({
|
|
216
|
+
meta: {
|
|
217
|
+
...META2,
|
|
218
|
+
key: "analytics.visualization.regional-revenue",
|
|
219
|
+
title: "Regional Revenue",
|
|
220
|
+
description: "Revenue split by sales territory.",
|
|
221
|
+
goal: "Compare the strongest and weakest performing territories.",
|
|
222
|
+
context: "Territory planning and commercial comparison."
|
|
223
|
+
},
|
|
224
|
+
source: { primary: QUERY_REF2, resultPath: "data" },
|
|
225
|
+
visualization: {
|
|
226
|
+
kind: "cartesian",
|
|
227
|
+
variant: "bar",
|
|
228
|
+
xDimension: "region",
|
|
229
|
+
yMeasures: ["revenue"],
|
|
230
|
+
dimensions: [
|
|
231
|
+
{ key: "region", label: "Region", dataPath: "region", type: "category" }
|
|
232
|
+
],
|
|
233
|
+
measures: [
|
|
234
|
+
{
|
|
235
|
+
key: "revenue",
|
|
236
|
+
label: "Revenue",
|
|
237
|
+
dataPath: "revenue",
|
|
238
|
+
format: "currency",
|
|
239
|
+
color: "#1d4ed8"
|
|
240
|
+
}
|
|
241
|
+
],
|
|
242
|
+
table: { caption: "Revenue by region." }
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
var RetentionAreaVisualization = defineVisualization2({
|
|
246
|
+
meta: {
|
|
247
|
+
...META2,
|
|
248
|
+
key: "analytics.visualization.retention-area",
|
|
249
|
+
title: "Retention Curve",
|
|
250
|
+
description: "Weekly retention progression across the active cohort.",
|
|
251
|
+
goal: "Show whether user retention remains above the desired floor.",
|
|
252
|
+
context: "Product health dashboard."
|
|
253
|
+
},
|
|
254
|
+
source: { primary: QUERY_REF2, resultPath: "data" },
|
|
255
|
+
visualization: {
|
|
256
|
+
kind: "cartesian",
|
|
257
|
+
variant: "area",
|
|
258
|
+
xDimension: "week",
|
|
259
|
+
yMeasures: ["retentionRate"],
|
|
260
|
+
dimensions: [
|
|
261
|
+
{ key: "week", label: "Week", dataPath: "week", type: "category" }
|
|
262
|
+
],
|
|
263
|
+
measures: [
|
|
264
|
+
{
|
|
265
|
+
key: "retentionRate",
|
|
266
|
+
label: "Retention",
|
|
267
|
+
dataPath: "retentionRate",
|
|
268
|
+
format: "percentage",
|
|
269
|
+
color: "#16a34a"
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
thresholds: [
|
|
273
|
+
{ key: "floor", value: 0.5, label: "Floor", color: "#f59e0b" }
|
|
274
|
+
],
|
|
275
|
+
table: { caption: "Weekly retention rate." }
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
var PipelineScatterVisualization = defineVisualization2({
|
|
279
|
+
meta: {
|
|
280
|
+
...META2,
|
|
281
|
+
key: "analytics.visualization.pipeline-scatter",
|
|
282
|
+
title: "Pipeline Velocity",
|
|
283
|
+
description: "Deal-cycle length against win rate for active accounts.",
|
|
284
|
+
goal: "Spot outliers where the sales cycle is long but conversion remains weak.",
|
|
285
|
+
context: "Commercial operations dashboard."
|
|
286
|
+
},
|
|
287
|
+
source: { primary: QUERY_REF2, resultPath: "data" },
|
|
288
|
+
visualization: {
|
|
289
|
+
kind: "cartesian",
|
|
290
|
+
variant: "scatter",
|
|
291
|
+
xDimension: "cycleDays",
|
|
292
|
+
yMeasures: ["winRate"],
|
|
293
|
+
dimensions: [
|
|
294
|
+
{
|
|
295
|
+
key: "cycleDays",
|
|
296
|
+
label: "Cycle Days",
|
|
297
|
+
dataPath: "cycleDays",
|
|
298
|
+
type: "number"
|
|
299
|
+
}
|
|
300
|
+
],
|
|
301
|
+
measures: [
|
|
302
|
+
{
|
|
303
|
+
key: "winRate",
|
|
304
|
+
label: "Win Rate",
|
|
305
|
+
dataPath: "winRate",
|
|
306
|
+
format: "percentage",
|
|
307
|
+
color: "#7c3aed"
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
key: "arr",
|
|
311
|
+
label: "ARR",
|
|
312
|
+
dataPath: "arr",
|
|
313
|
+
format: "currency"
|
|
314
|
+
}
|
|
315
|
+
],
|
|
316
|
+
series: [
|
|
317
|
+
{
|
|
318
|
+
key: "pipeline",
|
|
319
|
+
label: "Accounts",
|
|
320
|
+
measure: "winRate",
|
|
321
|
+
type: "scatter",
|
|
322
|
+
color: "#7c3aed"
|
|
323
|
+
}
|
|
324
|
+
],
|
|
325
|
+
table: { caption: "Sales cycle and win rate per account." }
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// src/visualizations/catalog.ts
|
|
330
|
+
import { VisualizationRegistry } from "@contractspec/lib.contracts-spec/visualizations";
|
|
331
|
+
var AnalyticsVisualizationSpecs = [
|
|
332
|
+
RevenueMetricVisualization,
|
|
333
|
+
RevenueTrendVisualization,
|
|
334
|
+
RegionalRevenueVisualization,
|
|
335
|
+
RetentionAreaVisualization,
|
|
336
|
+
PipelineScatterVisualization,
|
|
337
|
+
ChannelMixVisualization,
|
|
338
|
+
EngagementHeatmapVisualization,
|
|
339
|
+
ConversionFunnelVisualization,
|
|
340
|
+
AccountCoverageGeoVisualization
|
|
341
|
+
];
|
|
342
|
+
var AnalyticsVisualizationRegistry = new VisualizationRegistry([
|
|
343
|
+
...AnalyticsVisualizationSpecs
|
|
344
|
+
]);
|
|
345
|
+
var AnalyticsVisualizationRefs = AnalyticsVisualizationSpecs.map((spec) => refOf(spec));
|
|
346
|
+
var AnalyticsVisualizationSpecMap = new Map(AnalyticsVisualizationSpecs.map((spec) => [
|
|
347
|
+
visualizationRefKey(spec.meta),
|
|
348
|
+
spec
|
|
349
|
+
]));
|
|
350
|
+
var AnalyticsVisualizationSampleData = {
|
|
351
|
+
[visualizationRefKey(RevenueMetricVisualization.meta)]: {
|
|
352
|
+
data: [
|
|
353
|
+
{ period: "2025-11-01", totalRevenue: 112000, priorRevenue: 103000 },
|
|
354
|
+
{ period: "2025-12-01", totalRevenue: 119000, priorRevenue: 110000 },
|
|
355
|
+
{ period: "2026-01-01", totalRevenue: 126500, priorRevenue: 116000 },
|
|
356
|
+
{ period: "2026-02-01", totalRevenue: 133000, priorRevenue: 124000 },
|
|
357
|
+
{ period: "2026-03-01", totalRevenue: 145500, priorRevenue: 133000 }
|
|
358
|
+
]
|
|
359
|
+
},
|
|
360
|
+
[visualizationRefKey(RevenueTrendVisualization.meta)]: {
|
|
361
|
+
data: [
|
|
362
|
+
{ date: "2025-11-01", revenue: 112000 },
|
|
363
|
+
{ date: "2025-12-01", revenue: 119000 },
|
|
364
|
+
{ date: "2026-01-01", revenue: 126500 },
|
|
365
|
+
{ date: "2026-02-01", revenue: 133000 },
|
|
366
|
+
{ date: "2026-03-01", revenue: 145500 }
|
|
367
|
+
]
|
|
368
|
+
},
|
|
369
|
+
[visualizationRefKey(RegionalRevenueVisualization.meta)]: {
|
|
370
|
+
data: [
|
|
371
|
+
{ region: "North America", revenue: 210000 },
|
|
372
|
+
{ region: "EMEA", revenue: 174000 },
|
|
373
|
+
{ region: "APAC", revenue: 132000 },
|
|
374
|
+
{ region: "LATAM", revenue: 88000 }
|
|
375
|
+
]
|
|
376
|
+
},
|
|
377
|
+
[visualizationRefKey(RetentionAreaVisualization.meta)]: {
|
|
378
|
+
data: [
|
|
379
|
+
{ week: "Week 1", retentionRate: 0.71 },
|
|
380
|
+
{ week: "Week 2", retentionRate: 0.66 },
|
|
381
|
+
{ week: "Week 3", retentionRate: 0.62 },
|
|
382
|
+
{ week: "Week 4", retentionRate: 0.58 },
|
|
383
|
+
{ week: "Week 5", retentionRate: 0.55 },
|
|
384
|
+
{ week: "Week 6", retentionRate: 0.53 }
|
|
385
|
+
]
|
|
386
|
+
},
|
|
387
|
+
[visualizationRefKey(PipelineScatterVisualization.meta)]: {
|
|
388
|
+
data: [
|
|
389
|
+
{ cycleDays: 18, winRate: 0.31, arr: 82000 },
|
|
390
|
+
{ cycleDays: 26, winRate: 0.44, arr: 65000 },
|
|
391
|
+
{ cycleDays: 33, winRate: 0.27, arr: 91000 },
|
|
392
|
+
{ cycleDays: 14, winRate: 0.56, arr: 47000 },
|
|
393
|
+
{ cycleDays: 21, winRate: 0.48, arr: 59000 },
|
|
394
|
+
{ cycleDays: 39, winRate: 0.22, arr: 114000 }
|
|
395
|
+
]
|
|
396
|
+
},
|
|
397
|
+
[visualizationRefKey(ChannelMixVisualization.meta)]: {
|
|
398
|
+
data: [
|
|
399
|
+
{ channel: "Direct", sessions: 4200 },
|
|
400
|
+
{ channel: "Organic Search", sessions: 3600 },
|
|
401
|
+
{ channel: "Paid Search", sessions: 2100 },
|
|
402
|
+
{ channel: "Partner", sessions: 1400 },
|
|
403
|
+
{ channel: "Referral", sessions: 900 }
|
|
404
|
+
]
|
|
405
|
+
},
|
|
406
|
+
[visualizationRefKey(EngagementHeatmapVisualization.meta)]: {
|
|
407
|
+
data: [
|
|
408
|
+
{ weekday: "Mon", timeBand: "09:00", engagementScore: 74 },
|
|
409
|
+
{ weekday: "Mon", timeBand: "13:00", engagementScore: 82 },
|
|
410
|
+
{ weekday: "Tue", timeBand: "09:00", engagementScore: 69 },
|
|
411
|
+
{ weekday: "Tue", timeBand: "13:00", engagementScore: 88 },
|
|
412
|
+
{ weekday: "Wed", timeBand: "09:00", engagementScore: 77 },
|
|
413
|
+
{ weekday: "Wed", timeBand: "13:00", engagementScore: 91 },
|
|
414
|
+
{ weekday: "Thu", timeBand: "09:00", engagementScore: 72 },
|
|
415
|
+
{ weekday: "Thu", timeBand: "13:00", engagementScore: 86 },
|
|
416
|
+
{ weekday: "Fri", timeBand: "09:00", engagementScore: 65 },
|
|
417
|
+
{ weekday: "Fri", timeBand: "13:00", engagementScore: 79 }
|
|
418
|
+
]
|
|
419
|
+
},
|
|
420
|
+
[visualizationRefKey(ConversionFunnelVisualization.meta)]: {
|
|
421
|
+
data: [
|
|
422
|
+
{ stage: "Visited Site", users: 12000 },
|
|
423
|
+
{ stage: "Started Trial", users: 4200 },
|
|
424
|
+
{ stage: "Activated Workspace", users: 2400 },
|
|
425
|
+
{ stage: "Requested Demo", users: 980 },
|
|
426
|
+
{ stage: "Closed Won", users: 310 }
|
|
427
|
+
]
|
|
428
|
+
},
|
|
429
|
+
[visualizationRefKey(AccountCoverageGeoVisualization.meta)]: {
|
|
430
|
+
data: [
|
|
431
|
+
{ city: "Paris", latitude: 48.8566, longitude: 2.3522, accounts: 48 },
|
|
432
|
+
{ city: "London", latitude: 51.5072, longitude: -0.1276, accounts: 62 },
|
|
433
|
+
{ city: "New York", latitude: 40.7128, longitude: -74.006, accounts: 71 },
|
|
434
|
+
{ city: "Toronto", latitude: 43.6532, longitude: -79.3832, accounts: 36 },
|
|
435
|
+
{
|
|
436
|
+
city: "Singapore",
|
|
437
|
+
latitude: 1.3521,
|
|
438
|
+
longitude: 103.8198,
|
|
439
|
+
accounts: 29
|
|
440
|
+
}
|
|
441
|
+
]
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
function refOf(spec) {
|
|
445
|
+
return { key: spec.meta.key, version: spec.meta.version };
|
|
446
|
+
}
|
|
447
|
+
function visualizationRefKey(ref) {
|
|
448
|
+
return `${ref.key}.v${ref.version}`;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// src/visualizations/widgets.ts
|
|
452
|
+
var LEGACY_VISUALIZATION_REFS = {
|
|
453
|
+
METRIC: refOf(RevenueMetricVisualization),
|
|
454
|
+
LINE_CHART: refOf(RevenueTrendVisualization),
|
|
455
|
+
BAR_CHART: refOf(RegionalRevenueVisualization),
|
|
456
|
+
AREA_CHART: refOf(RetentionAreaVisualization),
|
|
457
|
+
SCATTER_PLOT: refOf(PipelineScatterVisualization),
|
|
458
|
+
PIE_CHART: refOf(ChannelMixVisualization),
|
|
459
|
+
HEATMAP: refOf(EngagementHeatmapVisualization),
|
|
460
|
+
FUNNEL: refOf(ConversionFunnelVisualization),
|
|
461
|
+
MAP: refOf(AccountCoverageGeoVisualization)
|
|
462
|
+
};
|
|
463
|
+
function createExampleWidgets(dashboardId) {
|
|
464
|
+
return [
|
|
465
|
+
widget(dashboardId, "widget_revenue_metric", "Revenue Snapshot", "METRIC", 0, 0, 4, 2, {
|
|
466
|
+
layout: "single",
|
|
467
|
+
bindings: [binding(RevenueMetricVisualization, 200)]
|
|
468
|
+
}),
|
|
469
|
+
widget(dashboardId, "widget_revenue_trend", "Revenue Trend", "LINE_CHART", 4, 0, 8, 4, {
|
|
470
|
+
layout: "single",
|
|
471
|
+
bindings: [binding(RevenueTrendVisualization)]
|
|
472
|
+
}),
|
|
473
|
+
widget(dashboardId, "widget_regional_revenue", "Regional Revenue", "BAR_CHART", 0, 2, 6, 4, {
|
|
474
|
+
layout: "single",
|
|
475
|
+
bindings: [binding(RegionalRevenueVisualization)]
|
|
476
|
+
}),
|
|
477
|
+
widget(dashboardId, "widget_channel_mix", "Channel Mix", "PIE_CHART", 6, 2, 6, 4, {
|
|
478
|
+
layout: "single",
|
|
479
|
+
bindings: [binding(ChannelMixVisualization)]
|
|
480
|
+
}),
|
|
481
|
+
widget(dashboardId, "widget_retention", "Retention Curve", "AREA_CHART", 0, 6, 6, 4, {
|
|
482
|
+
layout: "single",
|
|
483
|
+
bindings: [binding(RetentionAreaVisualization)]
|
|
484
|
+
}),
|
|
485
|
+
widget(dashboardId, "widget_pipeline", "Pipeline Velocity", "SCATTER_PLOT", 6, 6, 6, 4, {
|
|
486
|
+
layout: "single",
|
|
487
|
+
bindings: [binding(PipelineScatterVisualization)]
|
|
488
|
+
}),
|
|
489
|
+
widget(dashboardId, "widget_heatmap", "Engagement Heatmap", "HEATMAP", 0, 10, 8, 4, {
|
|
490
|
+
layout: "single",
|
|
491
|
+
bindings: [binding(EngagementHeatmapVisualization)]
|
|
492
|
+
}),
|
|
493
|
+
widget(dashboardId, "widget_funnel", "Conversion Funnel", "FUNNEL", 8, 10, 4, 4, {
|
|
494
|
+
layout: "single",
|
|
495
|
+
bindings: [binding(ConversionFunnelVisualization)]
|
|
496
|
+
}),
|
|
497
|
+
widget(dashboardId, "widget_geo", "Account Coverage", "MAP", 0, 14, 12, 5, {
|
|
498
|
+
layout: "single",
|
|
499
|
+
bindings: [binding(AccountCoverageGeoVisualization, 360)]
|
|
500
|
+
}),
|
|
501
|
+
widget(dashboardId, "widget_comparison", "Commercial Comparison", "EMBED", 0, 19, 12, 6, {
|
|
502
|
+
layout: "comparison",
|
|
503
|
+
description: "Compare regional distribution, channel balance, and funnel shape.",
|
|
504
|
+
bindings: [
|
|
505
|
+
binding(RegionalRevenueVisualization, 240),
|
|
506
|
+
binding(ChannelMixVisualization, 240),
|
|
507
|
+
binding(ConversionFunnelVisualization, 240)
|
|
508
|
+
]
|
|
509
|
+
}),
|
|
510
|
+
widget(dashboardId, "widget_timeline", "Growth Timeline", "EMBED", 0, 25, 12, 6, {
|
|
511
|
+
layout: "timeline",
|
|
512
|
+
description: "Track revenue and retention over the same reporting cadence.",
|
|
513
|
+
bindings: [
|
|
514
|
+
binding(RevenueTrendVisualization, 220),
|
|
515
|
+
binding(RetentionAreaVisualization, 220)
|
|
516
|
+
]
|
|
517
|
+
})
|
|
518
|
+
];
|
|
519
|
+
}
|
|
520
|
+
function resolveAnalyticsWidget(widget) {
|
|
521
|
+
const config = parseWidgetConfig(widget);
|
|
522
|
+
const bindings = config.bindings.map((binding) => {
|
|
523
|
+
const spec = AnalyticsVisualizationSpecMap.get(visualizationRefKey(binding.ref));
|
|
524
|
+
if (!spec)
|
|
525
|
+
return null;
|
|
526
|
+
return {
|
|
527
|
+
key: `${widget.id}:${visualizationRefKey(binding.ref)}`,
|
|
528
|
+
spec,
|
|
529
|
+
data: binding.data,
|
|
530
|
+
title: binding.title ?? spec.meta.title,
|
|
531
|
+
description: binding.description ?? spec.meta.description,
|
|
532
|
+
height: binding.height
|
|
533
|
+
};
|
|
534
|
+
}).filter((binding) => Boolean(binding));
|
|
535
|
+
if (!bindings.length)
|
|
536
|
+
return null;
|
|
537
|
+
return {
|
|
538
|
+
id: widget.id,
|
|
539
|
+
name: widget.name,
|
|
540
|
+
description: config.description,
|
|
541
|
+
layout: config.layout,
|
|
542
|
+
gridX: widget.gridX,
|
|
543
|
+
gridY: widget.gridY,
|
|
544
|
+
gridWidth: widget.gridWidth,
|
|
545
|
+
gridHeight: widget.gridHeight,
|
|
546
|
+
bindings
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
function parseWidgetConfig(widget) {
|
|
550
|
+
if (isAnalyticsWidgetConfig(widget.config)) {
|
|
551
|
+
return widget.config;
|
|
552
|
+
}
|
|
553
|
+
const legacyRef = LEGACY_VISUALIZATION_REFS[widget.type];
|
|
554
|
+
return legacyRef ? {
|
|
555
|
+
layout: "single",
|
|
556
|
+
bindings: [
|
|
557
|
+
{
|
|
558
|
+
ref: legacyRef,
|
|
559
|
+
data: AnalyticsVisualizationSampleData[visualizationRefKey(legacyRef)]
|
|
560
|
+
}
|
|
561
|
+
]
|
|
562
|
+
} : { layout: "single", bindings: [] };
|
|
563
|
+
}
|
|
564
|
+
function binding(spec, height = 280) {
|
|
565
|
+
return {
|
|
566
|
+
ref: refOf(spec),
|
|
567
|
+
data: AnalyticsVisualizationSampleData[visualizationRefKey(spec.meta)],
|
|
568
|
+
height
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
function widget(dashboardId, id, name, type, gridX, gridY, gridWidth, gridHeight, config) {
|
|
572
|
+
const now = new Date;
|
|
573
|
+
return {
|
|
574
|
+
id,
|
|
575
|
+
dashboardId,
|
|
576
|
+
name,
|
|
577
|
+
type,
|
|
578
|
+
gridX,
|
|
579
|
+
gridY,
|
|
580
|
+
gridWidth,
|
|
581
|
+
gridHeight,
|
|
582
|
+
config,
|
|
583
|
+
createdAt: now,
|
|
584
|
+
updatedAt: now
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
function isAnalyticsWidgetConfig(value) {
|
|
588
|
+
if (!value || typeof value !== "object")
|
|
589
|
+
return false;
|
|
590
|
+
const candidate = value;
|
|
591
|
+
return (candidate.layout === "single" || candidate.layout === "comparison" || candidate.layout === "timeline") && Array.isArray(candidate.bindings);
|
|
592
|
+
}
|
|
593
|
+
// src/ui/AnalyticsDashboard.widgets.tsx
|
|
594
|
+
import {
|
|
595
|
+
ComparisonView,
|
|
596
|
+
TimelineView,
|
|
597
|
+
VisualizationCard,
|
|
598
|
+
VisualizationGrid
|
|
599
|
+
} from "@contractspec/lib.design-system";
|
|
600
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
601
|
+
"use client";
|
|
602
|
+
function AnalyticsWidgetBoard({
|
|
603
|
+
dashboardName,
|
|
604
|
+
widgets
|
|
605
|
+
}) {
|
|
606
|
+
if (!widgets.length) {
|
|
607
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
608
|
+
className: "rounded-lg border border-dashed p-10 text-center text-muted-foreground",
|
|
609
|
+
children: [
|
|
610
|
+
'No visualization widgets configured for "',
|
|
611
|
+
dashboardName,
|
|
612
|
+
'".'
|
|
613
|
+
]
|
|
614
|
+
}, undefined, true, undefined, this);
|
|
615
|
+
}
|
|
616
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
617
|
+
children: [
|
|
618
|
+
/* @__PURE__ */ jsxDEV("h3", {
|
|
619
|
+
className: "mb-4 font-semibold text-lg",
|
|
620
|
+
children: [
|
|
621
|
+
'Widgets in "',
|
|
622
|
+
dashboardName,
|
|
623
|
+
'"'
|
|
624
|
+
]
|
|
625
|
+
}, undefined, true, undefined, this),
|
|
626
|
+
/* @__PURE__ */ jsxDEV(VisualizationGrid, {
|
|
627
|
+
children: widgets.map((widget2) => /* @__PURE__ */ jsxDEV("div", {
|
|
628
|
+
className: gridSpanClass(widget2.gridWidth),
|
|
629
|
+
children: renderVisualizationWidget(widget2)
|
|
630
|
+
}, widget2.id, false, undefined, this))
|
|
631
|
+
}, undefined, false, undefined, this)
|
|
632
|
+
]
|
|
633
|
+
}, undefined, true, undefined, this);
|
|
634
|
+
}
|
|
635
|
+
function renderVisualizationWidget(widget2) {
|
|
636
|
+
const footer = /* @__PURE__ */ jsxDEV("span", {
|
|
637
|
+
className: "text-muted-foreground text-xs",
|
|
638
|
+
children: [
|
|
639
|
+
"Position: (",
|
|
640
|
+
widget2.gridX,
|
|
641
|
+
", ",
|
|
642
|
+
widget2.gridY,
|
|
643
|
+
") \u2022 ",
|
|
644
|
+
widget2.gridWidth,
|
|
645
|
+
"x",
|
|
646
|
+
widget2.gridHeight
|
|
647
|
+
]
|
|
648
|
+
}, undefined, true, undefined, this);
|
|
649
|
+
if (widget2.layout === "comparison") {
|
|
650
|
+
return /* @__PURE__ */ jsxDEV(ComparisonView, {
|
|
651
|
+
description: widget2.description,
|
|
652
|
+
items: widget2.bindings.map((binding3) => ({ ...binding3, footer })),
|
|
653
|
+
title: widget2.name
|
|
654
|
+
}, undefined, false, undefined, this);
|
|
655
|
+
}
|
|
656
|
+
if (widget2.layout === "timeline") {
|
|
657
|
+
return /* @__PURE__ */ jsxDEV(TimelineView, {
|
|
658
|
+
description: widget2.description,
|
|
659
|
+
items: widget2.bindings.map((binding3) => ({ ...binding3, footer })),
|
|
660
|
+
title: widget2.name
|
|
661
|
+
}, undefined, false, undefined, this);
|
|
662
|
+
}
|
|
663
|
+
const binding2 = widget2.bindings[0];
|
|
664
|
+
if (!binding2)
|
|
665
|
+
return null;
|
|
666
|
+
return /* @__PURE__ */ jsxDEV(VisualizationCard, {
|
|
667
|
+
data: binding2.data,
|
|
668
|
+
description: widget2.description ?? binding2.description,
|
|
669
|
+
footer,
|
|
670
|
+
height: binding2.height,
|
|
671
|
+
spec: binding2.spec,
|
|
672
|
+
title: widget2.name
|
|
673
|
+
}, undefined, false, undefined, this);
|
|
674
|
+
}
|
|
675
|
+
function gridSpanClass(gridWidth) {
|
|
676
|
+
if (gridWidth >= 12)
|
|
677
|
+
return "md:col-span-2 xl:col-span-3";
|
|
678
|
+
if (gridWidth >= 8)
|
|
679
|
+
return "xl:col-span-2";
|
|
680
|
+
if (gridWidth >= 6)
|
|
681
|
+
return "md:col-span-2";
|
|
682
|
+
return "";
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// src/ui/AnalyticsQueriesTable.tsx
|
|
686
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
687
|
+
"use client";
|
|
688
|
+
var QUERY_TYPE_COLORS = {
|
|
689
|
+
SQL: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
|
|
690
|
+
METRIC: "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",
|
|
691
|
+
AGGREGATION: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
|
|
692
|
+
CUSTOM: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"
|
|
693
|
+
};
|
|
694
|
+
function AnalyticsQueriesTable({ queries }) {
|
|
695
|
+
return /* @__PURE__ */ jsxDEV2("div", {
|
|
696
|
+
className: "rounded-lg border border-border",
|
|
697
|
+
children: /* @__PURE__ */ jsxDEV2("table", {
|
|
698
|
+
className: "w-full",
|
|
699
|
+
children: [
|
|
700
|
+
/* @__PURE__ */ jsxDEV2("thead", {
|
|
701
|
+
className: "border-border border-b bg-muted/30",
|
|
702
|
+
children: /* @__PURE__ */ jsxDEV2("tr", {
|
|
703
|
+
children: [
|
|
704
|
+
/* @__PURE__ */ jsxDEV2("th", {
|
|
705
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
706
|
+
children: "Query"
|
|
707
|
+
}, undefined, false, undefined, this),
|
|
708
|
+
/* @__PURE__ */ jsxDEV2("th", {
|
|
709
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
710
|
+
children: "Type"
|
|
711
|
+
}, undefined, false, undefined, this),
|
|
712
|
+
/* @__PURE__ */ jsxDEV2("th", {
|
|
713
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
714
|
+
children: "Cache TTL"
|
|
715
|
+
}, undefined, false, undefined, this),
|
|
716
|
+
/* @__PURE__ */ jsxDEV2("th", {
|
|
717
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
718
|
+
children: "Shared"
|
|
719
|
+
}, undefined, false, undefined, this)
|
|
720
|
+
]
|
|
721
|
+
}, undefined, true, undefined, this)
|
|
722
|
+
}, undefined, false, undefined, this),
|
|
723
|
+
/* @__PURE__ */ jsxDEV2("tbody", {
|
|
724
|
+
className: "divide-y divide-border",
|
|
725
|
+
children: [
|
|
726
|
+
queries.map((query) => /* @__PURE__ */ jsxDEV2("tr", {
|
|
727
|
+
className: "hover:bg-muted/50",
|
|
728
|
+
children: [
|
|
729
|
+
/* @__PURE__ */ jsxDEV2("td", {
|
|
730
|
+
className: "px-4 py-3",
|
|
731
|
+
children: [
|
|
732
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
733
|
+
className: "font-medium",
|
|
734
|
+
children: query.name
|
|
735
|
+
}, undefined, false, undefined, this),
|
|
736
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
737
|
+
className: "text-muted-foreground text-sm",
|
|
738
|
+
children: query.description
|
|
739
|
+
}, undefined, false, undefined, this)
|
|
740
|
+
]
|
|
741
|
+
}, undefined, true, undefined, this),
|
|
742
|
+
/* @__PURE__ */ jsxDEV2("td", {
|
|
743
|
+
className: "px-4 py-3",
|
|
744
|
+
children: /* @__PURE__ */ jsxDEV2("span", {
|
|
745
|
+
className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${QUERY_TYPE_COLORS[query.type] ?? ""}`,
|
|
746
|
+
children: query.type
|
|
747
|
+
}, undefined, false, undefined, this)
|
|
748
|
+
}, undefined, false, undefined, this),
|
|
749
|
+
/* @__PURE__ */ jsxDEV2("td", {
|
|
750
|
+
className: "px-4 py-3 text-muted-foreground text-sm",
|
|
751
|
+
children: [
|
|
752
|
+
query.cacheTtlSeconds,
|
|
753
|
+
"s"
|
|
754
|
+
]
|
|
755
|
+
}, undefined, true, undefined, this),
|
|
756
|
+
/* @__PURE__ */ jsxDEV2("td", {
|
|
757
|
+
className: "px-4 py-3",
|
|
758
|
+
children: query.isShared ? /* @__PURE__ */ jsxDEV2("span", {
|
|
759
|
+
className: "text-green-600 dark:text-green-400",
|
|
760
|
+
children: "\u2713"
|
|
761
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV2("span", {
|
|
762
|
+
className: "text-muted-foreground",
|
|
763
|
+
children: "\u2014"
|
|
764
|
+
}, undefined, false, undefined, this)
|
|
765
|
+
}, undefined, false, undefined, this)
|
|
766
|
+
]
|
|
767
|
+
}, query.id, true, undefined, this)),
|
|
768
|
+
queries.length === 0 && /* @__PURE__ */ jsxDEV2("tr", {
|
|
769
|
+
children: /* @__PURE__ */ jsxDEV2("td", {
|
|
770
|
+
colSpan: 4,
|
|
771
|
+
className: "px-4 py-8 text-center text-muted-foreground",
|
|
772
|
+
children: "No queries saved"
|
|
773
|
+
}, undefined, false, undefined, this)
|
|
774
|
+
}, undefined, false, undefined, this)
|
|
775
|
+
]
|
|
776
|
+
}, undefined, true, undefined, this)
|
|
777
|
+
]
|
|
778
|
+
}, undefined, true, undefined, this)
|
|
779
|
+
}, undefined, false, undefined, this);
|
|
780
|
+
}
|
|
781
|
+
|
|
2
782
|
// src/ui/hooks/useAnalyticsData.ts
|
|
3
|
-
import { useCallback, useEffect, useState } from "react";
|
|
4
783
|
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
784
|
+
import { useCallback, useEffect, useState } from "react";
|
|
5
785
|
"use client";
|
|
6
786
|
function useAnalyticsData(projectId = "local-project") {
|
|
7
787
|
const { handlers } = useTemplateRuntime();
|
|
@@ -27,7 +807,7 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
27
807
|
if (first) {
|
|
28
808
|
setSelectedDashboard(first);
|
|
29
809
|
const dashboardWidgets = await analytics.getWidgets(first.id);
|
|
30
|
-
setWidgets(dashboardWidgets);
|
|
810
|
+
setWidgets(dashboardWidgets.length > 0 ? dashboardWidgets : createExampleWidgets(first.id));
|
|
31
811
|
}
|
|
32
812
|
}
|
|
33
813
|
} catch (err) {
|
|
@@ -42,7 +822,7 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
42
822
|
const selectDashboard = useCallback(async (dashboard) => {
|
|
43
823
|
setSelectedDashboard(dashboard);
|
|
44
824
|
const dashboardWidgets = await analytics.getWidgets(dashboard.id);
|
|
45
|
-
setWidgets(dashboardWidgets);
|
|
825
|
+
setWidgets(dashboardWidgets.length > 0 ? dashboardWidgets : createExampleWidgets(dashboard.id));
|
|
46
826
|
}, [analytics]);
|
|
47
827
|
const stats = {
|
|
48
828
|
totalDashboards: dashboards.length,
|
|
@@ -64,7 +844,6 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
64
844
|
}
|
|
65
845
|
|
|
66
846
|
// src/ui/AnalyticsDashboard.tsx
|
|
67
|
-
import { useState as useState2 } from "react";
|
|
68
847
|
import {
|
|
69
848
|
Button,
|
|
70
849
|
ErrorState,
|
|
@@ -72,33 +851,14 @@ import {
|
|
|
72
851
|
StatCard,
|
|
73
852
|
StatCardGroup
|
|
74
853
|
} from "@contractspec/lib.design-system";
|
|
75
|
-
import {
|
|
854
|
+
import { useMemo, useState as useState2 } from "react";
|
|
855
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
76
856
|
"use client";
|
|
77
857
|
var STATUS_COLORS = {
|
|
78
858
|
PUBLISHED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
|
|
79
859
|
DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
|
|
80
860
|
ARCHIVED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"
|
|
81
861
|
};
|
|
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"
|
|
95
|
-
};
|
|
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"
|
|
101
|
-
};
|
|
102
862
|
function AnalyticsDashboard() {
|
|
103
863
|
const [activeTab, setActiveTab] = useState2("dashboards");
|
|
104
864
|
const {
|
|
@@ -116,33 +876,34 @@ function AnalyticsDashboard() {
|
|
|
116
876
|
{ id: "dashboards", label: "Dashboards", icon: "\uD83D\uDCCA" },
|
|
117
877
|
{ id: "queries", label: "Queries", icon: "\uD83D\uDD0D" }
|
|
118
878
|
];
|
|
879
|
+
const resolvedWidgets = useMemo(() => widgets.map((widget2) => resolveAnalyticsWidget(widget2)).filter((widget2) => Boolean(widget2)), [widgets]);
|
|
119
880
|
if (loading) {
|
|
120
|
-
return /* @__PURE__ */
|
|
881
|
+
return /* @__PURE__ */ jsxDEV3(LoaderBlock, {
|
|
121
882
|
label: "Loading Analytics..."
|
|
122
883
|
}, undefined, false, undefined, this);
|
|
123
884
|
}
|
|
124
885
|
if (error) {
|
|
125
|
-
return /* @__PURE__ */
|
|
886
|
+
return /* @__PURE__ */ jsxDEV3(ErrorState, {
|
|
126
887
|
title: "Failed to load Analytics",
|
|
127
888
|
description: error.message,
|
|
128
889
|
onRetry: refetch,
|
|
129
890
|
retryLabel: "Retry"
|
|
130
891
|
}, undefined, false, undefined, this);
|
|
131
892
|
}
|
|
132
|
-
return /* @__PURE__ */
|
|
893
|
+
return /* @__PURE__ */ jsxDEV3("div", {
|
|
133
894
|
className: "space-y-6",
|
|
134
895
|
children: [
|
|
135
|
-
/* @__PURE__ */
|
|
896
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
136
897
|
className: "flex items-center justify-between",
|
|
137
898
|
children: [
|
|
138
|
-
/* @__PURE__ */
|
|
139
|
-
className: "text-2xl
|
|
899
|
+
/* @__PURE__ */ jsxDEV3("h2", {
|
|
900
|
+
className: "font-bold text-2xl",
|
|
140
901
|
children: "Analytics Dashboard"
|
|
141
902
|
}, undefined, false, undefined, this),
|
|
142
|
-
/* @__PURE__ */
|
|
903
|
+
/* @__PURE__ */ jsxDEV3(Button, {
|
|
143
904
|
onClick: () => alert("Create dashboard modal"),
|
|
144
905
|
children: [
|
|
145
|
-
/* @__PURE__ */
|
|
906
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
146
907
|
className: "mr-2",
|
|
147
908
|
children: "+"
|
|
148
909
|
}, undefined, false, undefined, this),
|
|
@@ -151,55 +912,55 @@ function AnalyticsDashboard() {
|
|
|
151
912
|
}, undefined, true, undefined, this)
|
|
152
913
|
]
|
|
153
914
|
}, undefined, true, undefined, this),
|
|
154
|
-
/* @__PURE__ */
|
|
915
|
+
/* @__PURE__ */ jsxDEV3(StatCardGroup, {
|
|
155
916
|
children: [
|
|
156
|
-
/* @__PURE__ */
|
|
917
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
157
918
|
label: "Dashboards",
|
|
158
919
|
value: stats.totalDashboards,
|
|
159
920
|
hint: `${stats.publishedDashboards} published`
|
|
160
921
|
}, undefined, false, undefined, this),
|
|
161
|
-
/* @__PURE__ */
|
|
922
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
162
923
|
label: "Queries",
|
|
163
924
|
value: stats.totalQueries,
|
|
164
925
|
hint: `${stats.sharedQueries} shared`
|
|
165
926
|
}, undefined, false, undefined, this),
|
|
166
|
-
/* @__PURE__ */
|
|
927
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
167
928
|
label: "Widgets",
|
|
168
929
|
value: widgets.length,
|
|
169
930
|
hint: "on current dashboard"
|
|
170
931
|
}, undefined, false, undefined, this)
|
|
171
932
|
]
|
|
172
933
|
}, undefined, true, undefined, this),
|
|
173
|
-
/* @__PURE__ */
|
|
174
|
-
className: "
|
|
934
|
+
/* @__PURE__ */ jsxDEV3("nav", {
|
|
935
|
+
className: "flex gap-1 rounded-lg bg-muted p-1",
|
|
175
936
|
role: "tablist",
|
|
176
|
-
children: tabs.map((tab) => /* @__PURE__ */
|
|
937
|
+
children: tabs.map((tab) => /* @__PURE__ */ jsxDEV3(Button, {
|
|
177
938
|
type: "button",
|
|
178
939
|
role: "tab",
|
|
179
940
|
"aria-selected": activeTab === tab.id,
|
|
180
941
|
onClick: () => setActiveTab(tab.id),
|
|
181
|
-
className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 text-sm
|
|
942
|
+
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"}`,
|
|
182
943
|
children: [
|
|
183
|
-
/* @__PURE__ */
|
|
944
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
184
945
|
children: tab.icon
|
|
185
946
|
}, undefined, false, undefined, this),
|
|
186
947
|
tab.label
|
|
187
948
|
]
|
|
188
949
|
}, tab.id, true, undefined, this))
|
|
189
950
|
}, undefined, false, undefined, this),
|
|
190
|
-
/* @__PURE__ */
|
|
951
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
191
952
|
className: "min-h-[400px]",
|
|
192
953
|
role: "tabpanel",
|
|
193
954
|
children: [
|
|
194
|
-
activeTab === "dashboards" && /* @__PURE__ */
|
|
955
|
+
activeTab === "dashboards" && /* @__PURE__ */ jsxDEV3("div", {
|
|
195
956
|
className: "space-y-6",
|
|
196
957
|
children: [
|
|
197
|
-
/* @__PURE__ */
|
|
958
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
198
959
|
className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
199
960
|
children: [
|
|
200
|
-
dashboards.map((dashboard) => /* @__PURE__ */
|
|
961
|
+
dashboards.map((dashboard) => /* @__PURE__ */ jsxDEV3("div", {
|
|
201
962
|
onClick: () => selectDashboard(dashboard),
|
|
202
|
-
className: `
|
|
963
|
+
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"}`,
|
|
203
964
|
role: "button",
|
|
204
965
|
tabIndex: 0,
|
|
205
966
|
onKeyDown: (e) => {
|
|
@@ -207,33 +968,33 @@ function AnalyticsDashboard() {
|
|
|
207
968
|
selectDashboard(dashboard);
|
|
208
969
|
},
|
|
209
970
|
children: [
|
|
210
|
-
/* @__PURE__ */
|
|
971
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
211
972
|
className: "mb-2 flex items-center justify-between",
|
|
212
973
|
children: [
|
|
213
|
-
/* @__PURE__ */
|
|
974
|
+
/* @__PURE__ */ jsxDEV3("h3", {
|
|
214
975
|
className: "font-medium",
|
|
215
976
|
children: dashboard.name
|
|
216
977
|
}, undefined, false, undefined, this),
|
|
217
|
-
/* @__PURE__ */
|
|
218
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs
|
|
978
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
979
|
+
className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${STATUS_COLORS[dashboard.status] ?? ""}`,
|
|
219
980
|
children: dashboard.status
|
|
220
981
|
}, undefined, false, undefined, this)
|
|
221
982
|
]
|
|
222
983
|
}, undefined, true, undefined, this),
|
|
223
|
-
/* @__PURE__ */
|
|
224
|
-
className: "text-muted-foreground
|
|
984
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
985
|
+
className: "mb-3 text-muted-foreground text-sm",
|
|
225
986
|
children: dashboard.description
|
|
226
987
|
}, undefined, false, undefined, this),
|
|
227
|
-
/* @__PURE__ */
|
|
228
|
-
className: "
|
|
988
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
989
|
+
className: "flex items-center justify-between text-muted-foreground text-xs",
|
|
229
990
|
children: [
|
|
230
|
-
/* @__PURE__ */
|
|
991
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
231
992
|
children: [
|
|
232
993
|
"/",
|
|
233
994
|
dashboard.slug
|
|
234
995
|
]
|
|
235
996
|
}, undefined, true, undefined, this),
|
|
236
|
-
dashboard.isPublic && /* @__PURE__ */
|
|
997
|
+
dashboard.isPublic && /* @__PURE__ */ jsxDEV3("span", {
|
|
237
998
|
className: "text-green-600 dark:text-green-400",
|
|
238
999
|
children: "\uD83C\uDF10 Public"
|
|
239
1000
|
}, undefined, false, undefined, this)
|
|
@@ -241,149 +1002,20 @@ function AnalyticsDashboard() {
|
|
|
241
1002
|
}, undefined, true, undefined, this)
|
|
242
1003
|
]
|
|
243
1004
|
}, dashboard.id, true, undefined, this)),
|
|
244
|
-
dashboards.length === 0 && /* @__PURE__ */
|
|
245
|
-
className: "
|
|
1005
|
+
dashboards.length === 0 && /* @__PURE__ */ jsxDEV3("div", {
|
|
1006
|
+
className: "col-span-full flex h-64 items-center justify-center text-muted-foreground",
|
|
246
1007
|
children: "No dashboards created yet"
|
|
247
1008
|
}, undefined, false, undefined, this)
|
|
248
1009
|
]
|
|
249
1010
|
}, undefined, true, undefined, this),
|
|
250
|
-
selectedDashboard
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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)
|
|
1011
|
+
selectedDashboard ? /* @__PURE__ */ jsxDEV3(AnalyticsWidgetBoard, {
|
|
1012
|
+
dashboardName: selectedDashboard.name,
|
|
1013
|
+
widgets: resolvedWidgets
|
|
1014
|
+
}, undefined, false, undefined, this) : null
|
|
301
1015
|
]
|
|
302
1016
|
}, undefined, true, undefined, this),
|
|
303
|
-
activeTab === "queries" && /* @__PURE__ */
|
|
304
|
-
|
|
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)
|
|
1017
|
+
activeTab === "queries" && /* @__PURE__ */ jsxDEV3(AnalyticsQueriesTable, {
|
|
1018
|
+
queries
|
|
387
1019
|
}, undefined, false, undefined, this)
|
|
388
1020
|
]
|
|
389
1021
|
}, undefined, true, undefined, this)
|