@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,6 +1,786 @@
|
|
|
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
|
+
}
|
|
592
|
+
// src/ui/AnalyticsDashboard.widgets.tsx
|
|
593
|
+
import {
|
|
594
|
+
ComparisonView,
|
|
595
|
+
TimelineView,
|
|
596
|
+
VisualizationCard,
|
|
597
|
+
VisualizationGrid
|
|
598
|
+
} from "@contractspec/lib.design-system";
|
|
599
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
600
|
+
"use client";
|
|
601
|
+
function AnalyticsWidgetBoard({
|
|
602
|
+
dashboardName,
|
|
603
|
+
widgets
|
|
604
|
+
}) {
|
|
605
|
+
if (!widgets.length) {
|
|
606
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
607
|
+
className: "rounded-lg border border-dashed p-10 text-center text-muted-foreground",
|
|
608
|
+
children: [
|
|
609
|
+
'No visualization widgets configured for "',
|
|
610
|
+
dashboardName,
|
|
611
|
+
'".'
|
|
612
|
+
]
|
|
613
|
+
}, undefined, true, undefined, this);
|
|
614
|
+
}
|
|
615
|
+
return /* @__PURE__ */ jsxDEV("div", {
|
|
616
|
+
children: [
|
|
617
|
+
/* @__PURE__ */ jsxDEV("h3", {
|
|
618
|
+
className: "mb-4 font-semibold text-lg",
|
|
619
|
+
children: [
|
|
620
|
+
'Widgets in "',
|
|
621
|
+
dashboardName,
|
|
622
|
+
'"'
|
|
623
|
+
]
|
|
624
|
+
}, undefined, true, undefined, this),
|
|
625
|
+
/* @__PURE__ */ jsxDEV(VisualizationGrid, {
|
|
626
|
+
children: widgets.map((widget2) => /* @__PURE__ */ jsxDEV("div", {
|
|
627
|
+
className: gridSpanClass(widget2.gridWidth),
|
|
628
|
+
children: renderVisualizationWidget(widget2)
|
|
629
|
+
}, widget2.id, false, undefined, this))
|
|
630
|
+
}, undefined, false, undefined, this)
|
|
631
|
+
]
|
|
632
|
+
}, undefined, true, undefined, this);
|
|
633
|
+
}
|
|
634
|
+
function renderVisualizationWidget(widget2) {
|
|
635
|
+
const footer = /* @__PURE__ */ jsxDEV("span", {
|
|
636
|
+
className: "text-muted-foreground text-xs",
|
|
637
|
+
children: [
|
|
638
|
+
"Position: (",
|
|
639
|
+
widget2.gridX,
|
|
640
|
+
", ",
|
|
641
|
+
widget2.gridY,
|
|
642
|
+
") • ",
|
|
643
|
+
widget2.gridWidth,
|
|
644
|
+
"x",
|
|
645
|
+
widget2.gridHeight
|
|
646
|
+
]
|
|
647
|
+
}, undefined, true, undefined, this);
|
|
648
|
+
if (widget2.layout === "comparison") {
|
|
649
|
+
return /* @__PURE__ */ jsxDEV(ComparisonView, {
|
|
650
|
+
description: widget2.description,
|
|
651
|
+
items: widget2.bindings.map((binding3) => ({ ...binding3, footer })),
|
|
652
|
+
title: widget2.name
|
|
653
|
+
}, undefined, false, undefined, this);
|
|
654
|
+
}
|
|
655
|
+
if (widget2.layout === "timeline") {
|
|
656
|
+
return /* @__PURE__ */ jsxDEV(TimelineView, {
|
|
657
|
+
description: widget2.description,
|
|
658
|
+
items: widget2.bindings.map((binding3) => ({ ...binding3, footer })),
|
|
659
|
+
title: widget2.name
|
|
660
|
+
}, undefined, false, undefined, this);
|
|
661
|
+
}
|
|
662
|
+
const binding2 = widget2.bindings[0];
|
|
663
|
+
if (!binding2)
|
|
664
|
+
return null;
|
|
665
|
+
return /* @__PURE__ */ jsxDEV(VisualizationCard, {
|
|
666
|
+
data: binding2.data,
|
|
667
|
+
description: widget2.description ?? binding2.description,
|
|
668
|
+
footer,
|
|
669
|
+
height: binding2.height,
|
|
670
|
+
spec: binding2.spec,
|
|
671
|
+
title: widget2.name
|
|
672
|
+
}, undefined, false, undefined, this);
|
|
673
|
+
}
|
|
674
|
+
function gridSpanClass(gridWidth) {
|
|
675
|
+
if (gridWidth >= 12)
|
|
676
|
+
return "md:col-span-2 xl:col-span-3";
|
|
677
|
+
if (gridWidth >= 8)
|
|
678
|
+
return "xl:col-span-2";
|
|
679
|
+
if (gridWidth >= 6)
|
|
680
|
+
return "md:col-span-2";
|
|
681
|
+
return "";
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// src/ui/AnalyticsQueriesTable.tsx
|
|
685
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
686
|
+
"use client";
|
|
687
|
+
var QUERY_TYPE_COLORS = {
|
|
688
|
+
SQL: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
|
|
689
|
+
METRIC: "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",
|
|
690
|
+
AGGREGATION: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
|
|
691
|
+
CUSTOM: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"
|
|
692
|
+
};
|
|
693
|
+
function AnalyticsQueriesTable({ queries }) {
|
|
694
|
+
return /* @__PURE__ */ jsxDEV2("div", {
|
|
695
|
+
className: "rounded-lg border border-border",
|
|
696
|
+
children: /* @__PURE__ */ jsxDEV2("table", {
|
|
697
|
+
className: "w-full",
|
|
698
|
+
children: [
|
|
699
|
+
/* @__PURE__ */ jsxDEV2("thead", {
|
|
700
|
+
className: "border-border border-b bg-muted/30",
|
|
701
|
+
children: /* @__PURE__ */ jsxDEV2("tr", {
|
|
702
|
+
children: [
|
|
703
|
+
/* @__PURE__ */ jsxDEV2("th", {
|
|
704
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
705
|
+
children: "Query"
|
|
706
|
+
}, undefined, false, undefined, this),
|
|
707
|
+
/* @__PURE__ */ jsxDEV2("th", {
|
|
708
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
709
|
+
children: "Type"
|
|
710
|
+
}, undefined, false, undefined, this),
|
|
711
|
+
/* @__PURE__ */ jsxDEV2("th", {
|
|
712
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
713
|
+
children: "Cache TTL"
|
|
714
|
+
}, undefined, false, undefined, this),
|
|
715
|
+
/* @__PURE__ */ jsxDEV2("th", {
|
|
716
|
+
className: "px-4 py-3 text-left font-medium text-sm",
|
|
717
|
+
children: "Shared"
|
|
718
|
+
}, undefined, false, undefined, this)
|
|
719
|
+
]
|
|
720
|
+
}, undefined, true, undefined, this)
|
|
721
|
+
}, undefined, false, undefined, this),
|
|
722
|
+
/* @__PURE__ */ jsxDEV2("tbody", {
|
|
723
|
+
className: "divide-y divide-border",
|
|
724
|
+
children: [
|
|
725
|
+
queries.map((query) => /* @__PURE__ */ jsxDEV2("tr", {
|
|
726
|
+
className: "hover:bg-muted/50",
|
|
727
|
+
children: [
|
|
728
|
+
/* @__PURE__ */ jsxDEV2("td", {
|
|
729
|
+
className: "px-4 py-3",
|
|
730
|
+
children: [
|
|
731
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
732
|
+
className: "font-medium",
|
|
733
|
+
children: query.name
|
|
734
|
+
}, undefined, false, undefined, this),
|
|
735
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
736
|
+
className: "text-muted-foreground text-sm",
|
|
737
|
+
children: query.description
|
|
738
|
+
}, undefined, false, undefined, this)
|
|
739
|
+
]
|
|
740
|
+
}, undefined, true, undefined, this),
|
|
741
|
+
/* @__PURE__ */ jsxDEV2("td", {
|
|
742
|
+
className: "px-4 py-3",
|
|
743
|
+
children: /* @__PURE__ */ jsxDEV2("span", {
|
|
744
|
+
className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${QUERY_TYPE_COLORS[query.type] ?? ""}`,
|
|
745
|
+
children: query.type
|
|
746
|
+
}, undefined, false, undefined, this)
|
|
747
|
+
}, undefined, false, undefined, this),
|
|
748
|
+
/* @__PURE__ */ jsxDEV2("td", {
|
|
749
|
+
className: "px-4 py-3 text-muted-foreground text-sm",
|
|
750
|
+
children: [
|
|
751
|
+
query.cacheTtlSeconds,
|
|
752
|
+
"s"
|
|
753
|
+
]
|
|
754
|
+
}, undefined, true, undefined, this),
|
|
755
|
+
/* @__PURE__ */ jsxDEV2("td", {
|
|
756
|
+
className: "px-4 py-3",
|
|
757
|
+
children: query.isShared ? /* @__PURE__ */ jsxDEV2("span", {
|
|
758
|
+
className: "text-green-600 dark:text-green-400",
|
|
759
|
+
children: "✓"
|
|
760
|
+
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV2("span", {
|
|
761
|
+
className: "text-muted-foreground",
|
|
762
|
+
children: "—"
|
|
763
|
+
}, undefined, false, undefined, this)
|
|
764
|
+
}, undefined, false, undefined, this)
|
|
765
|
+
]
|
|
766
|
+
}, query.id, true, undefined, this)),
|
|
767
|
+
queries.length === 0 && /* @__PURE__ */ jsxDEV2("tr", {
|
|
768
|
+
children: /* @__PURE__ */ jsxDEV2("td", {
|
|
769
|
+
colSpan: 4,
|
|
770
|
+
className: "px-4 py-8 text-center text-muted-foreground",
|
|
771
|
+
children: "No queries saved"
|
|
772
|
+
}, undefined, false, undefined, this)
|
|
773
|
+
}, undefined, false, undefined, this)
|
|
774
|
+
]
|
|
775
|
+
}, undefined, true, undefined, this)
|
|
776
|
+
]
|
|
777
|
+
}, undefined, true, undefined, this)
|
|
778
|
+
}, undefined, false, undefined, this);
|
|
779
|
+
}
|
|
780
|
+
|
|
1
781
|
// src/ui/hooks/useAnalyticsData.ts
|
|
2
|
-
import { useCallback, useEffect, useState } from "react";
|
|
3
782
|
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
783
|
+
import { useCallback, useEffect, useState } from "react";
|
|
4
784
|
"use client";
|
|
5
785
|
function useAnalyticsData(projectId = "local-project") {
|
|
6
786
|
const { handlers } = useTemplateRuntime();
|
|
@@ -26,7 +806,7 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
26
806
|
if (first) {
|
|
27
807
|
setSelectedDashboard(first);
|
|
28
808
|
const dashboardWidgets = await analytics.getWidgets(first.id);
|
|
29
|
-
setWidgets(dashboardWidgets);
|
|
809
|
+
setWidgets(dashboardWidgets.length > 0 ? dashboardWidgets : createExampleWidgets(first.id));
|
|
30
810
|
}
|
|
31
811
|
}
|
|
32
812
|
} catch (err) {
|
|
@@ -41,7 +821,7 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
41
821
|
const selectDashboard = useCallback(async (dashboard) => {
|
|
42
822
|
setSelectedDashboard(dashboard);
|
|
43
823
|
const dashboardWidgets = await analytics.getWidgets(dashboard.id);
|
|
44
|
-
setWidgets(dashboardWidgets);
|
|
824
|
+
setWidgets(dashboardWidgets.length > 0 ? dashboardWidgets : createExampleWidgets(dashboard.id));
|
|
45
825
|
}, [analytics]);
|
|
46
826
|
const stats = {
|
|
47
827
|
totalDashboards: dashboards.length,
|
|
@@ -63,7 +843,6 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
63
843
|
}
|
|
64
844
|
|
|
65
845
|
// src/ui/AnalyticsDashboard.tsx
|
|
66
|
-
import { useState as useState2 } from "react";
|
|
67
846
|
import {
|
|
68
847
|
Button,
|
|
69
848
|
ErrorState,
|
|
@@ -71,33 +850,14 @@ import {
|
|
|
71
850
|
StatCard,
|
|
72
851
|
StatCardGroup
|
|
73
852
|
} from "@contractspec/lib.design-system";
|
|
74
|
-
import {
|
|
853
|
+
import { useMemo, useState as useState2 } from "react";
|
|
854
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
75
855
|
"use client";
|
|
76
856
|
var STATUS_COLORS = {
|
|
77
857
|
PUBLISHED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
|
|
78
858
|
DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
|
|
79
859
|
ARCHIVED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"
|
|
80
860
|
};
|
|
81
|
-
var WIDGET_ICONS = {
|
|
82
|
-
LINE_CHART: "\uD83D\uDCC8",
|
|
83
|
-
BAR_CHART: "\uD83D\uDCCA",
|
|
84
|
-
PIE_CHART: "\uD83E\uDD67",
|
|
85
|
-
AREA_CHART: "\uD83D\uDCC9",
|
|
86
|
-
SCATTER_PLOT: "⚬",
|
|
87
|
-
METRIC: "\uD83D\uDD22",
|
|
88
|
-
TABLE: "\uD83D\uDCCB",
|
|
89
|
-
HEATMAP: "\uD83D\uDDFA️",
|
|
90
|
-
FUNNEL: "⏬",
|
|
91
|
-
MAP: "\uD83C\uDF0D",
|
|
92
|
-
TEXT: "\uD83D\uDCDD",
|
|
93
|
-
EMBED: "\uD83D\uDD17"
|
|
94
|
-
};
|
|
95
|
-
var QUERY_TYPE_COLORS = {
|
|
96
|
-
SQL: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
|
|
97
|
-
METRIC: "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",
|
|
98
|
-
AGGREGATION: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
|
|
99
|
-
CUSTOM: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"
|
|
100
|
-
};
|
|
101
861
|
function AnalyticsDashboard() {
|
|
102
862
|
const [activeTab, setActiveTab] = useState2("dashboards");
|
|
103
863
|
const {
|
|
@@ -115,33 +875,34 @@ function AnalyticsDashboard() {
|
|
|
115
875
|
{ id: "dashboards", label: "Dashboards", icon: "\uD83D\uDCCA" },
|
|
116
876
|
{ id: "queries", label: "Queries", icon: "\uD83D\uDD0D" }
|
|
117
877
|
];
|
|
878
|
+
const resolvedWidgets = useMemo(() => widgets.map((widget2) => resolveAnalyticsWidget(widget2)).filter((widget2) => Boolean(widget2)), [widgets]);
|
|
118
879
|
if (loading) {
|
|
119
|
-
return /* @__PURE__ */
|
|
880
|
+
return /* @__PURE__ */ jsxDEV3(LoaderBlock, {
|
|
120
881
|
label: "Loading Analytics..."
|
|
121
882
|
}, undefined, false, undefined, this);
|
|
122
883
|
}
|
|
123
884
|
if (error) {
|
|
124
|
-
return /* @__PURE__ */
|
|
885
|
+
return /* @__PURE__ */ jsxDEV3(ErrorState, {
|
|
125
886
|
title: "Failed to load Analytics",
|
|
126
887
|
description: error.message,
|
|
127
888
|
onRetry: refetch,
|
|
128
889
|
retryLabel: "Retry"
|
|
129
890
|
}, undefined, false, undefined, this);
|
|
130
891
|
}
|
|
131
|
-
return /* @__PURE__ */
|
|
892
|
+
return /* @__PURE__ */ jsxDEV3("div", {
|
|
132
893
|
className: "space-y-6",
|
|
133
894
|
children: [
|
|
134
|
-
/* @__PURE__ */
|
|
895
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
135
896
|
className: "flex items-center justify-between",
|
|
136
897
|
children: [
|
|
137
|
-
/* @__PURE__ */
|
|
138
|
-
className: "text-2xl
|
|
898
|
+
/* @__PURE__ */ jsxDEV3("h2", {
|
|
899
|
+
className: "font-bold text-2xl",
|
|
139
900
|
children: "Analytics Dashboard"
|
|
140
901
|
}, undefined, false, undefined, this),
|
|
141
|
-
/* @__PURE__ */
|
|
902
|
+
/* @__PURE__ */ jsxDEV3(Button, {
|
|
142
903
|
onClick: () => alert("Create dashboard modal"),
|
|
143
904
|
children: [
|
|
144
|
-
/* @__PURE__ */
|
|
905
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
145
906
|
className: "mr-2",
|
|
146
907
|
children: "+"
|
|
147
908
|
}, undefined, false, undefined, this),
|
|
@@ -150,55 +911,55 @@ function AnalyticsDashboard() {
|
|
|
150
911
|
}, undefined, true, undefined, this)
|
|
151
912
|
]
|
|
152
913
|
}, undefined, true, undefined, this),
|
|
153
|
-
/* @__PURE__ */
|
|
914
|
+
/* @__PURE__ */ jsxDEV3(StatCardGroup, {
|
|
154
915
|
children: [
|
|
155
|
-
/* @__PURE__ */
|
|
916
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
156
917
|
label: "Dashboards",
|
|
157
918
|
value: stats.totalDashboards,
|
|
158
919
|
hint: `${stats.publishedDashboards} published`
|
|
159
920
|
}, undefined, false, undefined, this),
|
|
160
|
-
/* @__PURE__ */
|
|
921
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
161
922
|
label: "Queries",
|
|
162
923
|
value: stats.totalQueries,
|
|
163
924
|
hint: `${stats.sharedQueries} shared`
|
|
164
925
|
}, undefined, false, undefined, this),
|
|
165
|
-
/* @__PURE__ */
|
|
926
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
166
927
|
label: "Widgets",
|
|
167
928
|
value: widgets.length,
|
|
168
929
|
hint: "on current dashboard"
|
|
169
930
|
}, undefined, false, undefined, this)
|
|
170
931
|
]
|
|
171
932
|
}, undefined, true, undefined, this),
|
|
172
|
-
/* @__PURE__ */
|
|
173
|
-
className: "
|
|
933
|
+
/* @__PURE__ */ jsxDEV3("nav", {
|
|
934
|
+
className: "flex gap-1 rounded-lg bg-muted p-1",
|
|
174
935
|
role: "tablist",
|
|
175
|
-
children: tabs.map((tab) => /* @__PURE__ */
|
|
936
|
+
children: tabs.map((tab) => /* @__PURE__ */ jsxDEV3(Button, {
|
|
176
937
|
type: "button",
|
|
177
938
|
role: "tab",
|
|
178
939
|
"aria-selected": activeTab === tab.id,
|
|
179
940
|
onClick: () => setActiveTab(tab.id),
|
|
180
|
-
className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 text-sm
|
|
941
|
+
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"}`,
|
|
181
942
|
children: [
|
|
182
|
-
/* @__PURE__ */
|
|
943
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
183
944
|
children: tab.icon
|
|
184
945
|
}, undefined, false, undefined, this),
|
|
185
946
|
tab.label
|
|
186
947
|
]
|
|
187
948
|
}, tab.id, true, undefined, this))
|
|
188
949
|
}, undefined, false, undefined, this),
|
|
189
|
-
/* @__PURE__ */
|
|
950
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
190
951
|
className: "min-h-[400px]",
|
|
191
952
|
role: "tabpanel",
|
|
192
953
|
children: [
|
|
193
|
-
activeTab === "dashboards" && /* @__PURE__ */
|
|
954
|
+
activeTab === "dashboards" && /* @__PURE__ */ jsxDEV3("div", {
|
|
194
955
|
className: "space-y-6",
|
|
195
956
|
children: [
|
|
196
|
-
/* @__PURE__ */
|
|
957
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
197
958
|
className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
198
959
|
children: [
|
|
199
|
-
dashboards.map((dashboard) => /* @__PURE__ */
|
|
960
|
+
dashboards.map((dashboard) => /* @__PURE__ */ jsxDEV3("div", {
|
|
200
961
|
onClick: () => selectDashboard(dashboard),
|
|
201
|
-
className: `
|
|
962
|
+
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"}`,
|
|
202
963
|
role: "button",
|
|
203
964
|
tabIndex: 0,
|
|
204
965
|
onKeyDown: (e) => {
|
|
@@ -206,33 +967,33 @@ function AnalyticsDashboard() {
|
|
|
206
967
|
selectDashboard(dashboard);
|
|
207
968
|
},
|
|
208
969
|
children: [
|
|
209
|
-
/* @__PURE__ */
|
|
970
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
210
971
|
className: "mb-2 flex items-center justify-between",
|
|
211
972
|
children: [
|
|
212
|
-
/* @__PURE__ */
|
|
973
|
+
/* @__PURE__ */ jsxDEV3("h3", {
|
|
213
974
|
className: "font-medium",
|
|
214
975
|
children: dashboard.name
|
|
215
976
|
}, undefined, false, undefined, this),
|
|
216
|
-
/* @__PURE__ */
|
|
217
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs
|
|
977
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
978
|
+
className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${STATUS_COLORS[dashboard.status] ?? ""}`,
|
|
218
979
|
children: dashboard.status
|
|
219
980
|
}, undefined, false, undefined, this)
|
|
220
981
|
]
|
|
221
982
|
}, undefined, true, undefined, this),
|
|
222
|
-
/* @__PURE__ */
|
|
223
|
-
className: "text-muted-foreground
|
|
983
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
984
|
+
className: "mb-3 text-muted-foreground text-sm",
|
|
224
985
|
children: dashboard.description
|
|
225
986
|
}, undefined, false, undefined, this),
|
|
226
|
-
/* @__PURE__ */
|
|
227
|
-
className: "
|
|
987
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
988
|
+
className: "flex items-center justify-between text-muted-foreground text-xs",
|
|
228
989
|
children: [
|
|
229
|
-
/* @__PURE__ */
|
|
990
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
230
991
|
children: [
|
|
231
992
|
"/",
|
|
232
993
|
dashboard.slug
|
|
233
994
|
]
|
|
234
995
|
}, undefined, true, undefined, this),
|
|
235
|
-
dashboard.isPublic && /* @__PURE__ */
|
|
996
|
+
dashboard.isPublic && /* @__PURE__ */ jsxDEV3("span", {
|
|
236
997
|
className: "text-green-600 dark:text-green-400",
|
|
237
998
|
children: "\uD83C\uDF10 Public"
|
|
238
999
|
}, undefined, false, undefined, this)
|
|
@@ -240,149 +1001,20 @@ function AnalyticsDashboard() {
|
|
|
240
1001
|
}, undefined, true, undefined, this)
|
|
241
1002
|
]
|
|
242
1003
|
}, dashboard.id, true, undefined, this)),
|
|
243
|
-
dashboards.length === 0 && /* @__PURE__ */
|
|
244
|
-
className: "
|
|
1004
|
+
dashboards.length === 0 && /* @__PURE__ */ jsxDEV3("div", {
|
|
1005
|
+
className: "col-span-full flex h-64 items-center justify-center text-muted-foreground",
|
|
245
1006
|
children: "No dashboards created yet"
|
|
246
1007
|
}, undefined, false, undefined, this)
|
|
247
1008
|
]
|
|
248
1009
|
}, undefined, true, undefined, this),
|
|
249
|
-
selectedDashboard
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
children: [
|
|
254
|
-
'Widgets in "',
|
|
255
|
-
selectedDashboard.name,
|
|
256
|
-
'"'
|
|
257
|
-
]
|
|
258
|
-
}, undefined, true, undefined, this),
|
|
259
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
260
|
-
className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
261
|
-
children: widgets.map((widget) => /* @__PURE__ */ jsxDEV("div", {
|
|
262
|
-
className: "border-border bg-card rounded-lg border p-4",
|
|
263
|
-
children: [
|
|
264
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
265
|
-
className: "mb-2 flex items-center gap-2",
|
|
266
|
-
children: [
|
|
267
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
268
|
-
className: "text-xl",
|
|
269
|
-
children: WIDGET_ICONS[widget.type] ?? "\uD83D\uDCCA"
|
|
270
|
-
}, undefined, false, undefined, this),
|
|
271
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
272
|
-
className: "font-medium",
|
|
273
|
-
children: widget.name
|
|
274
|
-
}, undefined, false, undefined, this)
|
|
275
|
-
]
|
|
276
|
-
}, undefined, true, undefined, this),
|
|
277
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
278
|
-
className: "text-muted-foreground text-sm",
|
|
279
|
-
children: widget.type.replace(/_/g, " ")
|
|
280
|
-
}, undefined, false, undefined, this),
|
|
281
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
282
|
-
className: "text-muted-foreground mt-2 text-xs",
|
|
283
|
-
children: [
|
|
284
|
-
"Position: (",
|
|
285
|
-
widget.gridX,
|
|
286
|
-
", ",
|
|
287
|
-
widget.gridY,
|
|
288
|
-
") •",
|
|
289
|
-
" ",
|
|
290
|
-
widget.gridWidth,
|
|
291
|
-
"x",
|
|
292
|
-
widget.gridHeight
|
|
293
|
-
]
|
|
294
|
-
}, undefined, true, undefined, this)
|
|
295
|
-
]
|
|
296
|
-
}, widget.id, true, undefined, this))
|
|
297
|
-
}, undefined, false, undefined, this)
|
|
298
|
-
]
|
|
299
|
-
}, undefined, true, undefined, this)
|
|
1010
|
+
selectedDashboard ? /* @__PURE__ */ jsxDEV3(AnalyticsWidgetBoard, {
|
|
1011
|
+
dashboardName: selectedDashboard.name,
|
|
1012
|
+
widgets: resolvedWidgets
|
|
1013
|
+
}, undefined, false, undefined, this) : null
|
|
300
1014
|
]
|
|
301
1015
|
}, undefined, true, undefined, this),
|
|
302
|
-
activeTab === "queries" && /* @__PURE__ */
|
|
303
|
-
|
|
304
|
-
children: /* @__PURE__ */ jsxDEV("table", {
|
|
305
|
-
className: "w-full",
|
|
306
|
-
children: [
|
|
307
|
-
/* @__PURE__ */ jsxDEV("thead", {
|
|
308
|
-
className: "border-border bg-muted/30 border-b",
|
|
309
|
-
children: /* @__PURE__ */ jsxDEV("tr", {
|
|
310
|
-
children: [
|
|
311
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
312
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
313
|
-
children: "Query"
|
|
314
|
-
}, undefined, false, undefined, this),
|
|
315
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
316
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
317
|
-
children: "Type"
|
|
318
|
-
}, undefined, false, undefined, this),
|
|
319
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
320
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
321
|
-
children: "Cache TTL"
|
|
322
|
-
}, undefined, false, undefined, this),
|
|
323
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
324
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
325
|
-
children: "Shared"
|
|
326
|
-
}, undefined, false, undefined, this)
|
|
327
|
-
]
|
|
328
|
-
}, undefined, true, undefined, this)
|
|
329
|
-
}, undefined, false, undefined, this),
|
|
330
|
-
/* @__PURE__ */ jsxDEV("tbody", {
|
|
331
|
-
className: "divide-border divide-y",
|
|
332
|
-
children: [
|
|
333
|
-
queries.map((query) => /* @__PURE__ */ jsxDEV("tr", {
|
|
334
|
-
className: "hover:bg-muted/50",
|
|
335
|
-
children: [
|
|
336
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
337
|
-
className: "px-4 py-3",
|
|
338
|
-
children: [
|
|
339
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
340
|
-
className: "font-medium",
|
|
341
|
-
children: query.name
|
|
342
|
-
}, undefined, false, undefined, this),
|
|
343
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
344
|
-
className: "text-muted-foreground text-sm",
|
|
345
|
-
children: query.description
|
|
346
|
-
}, undefined, false, undefined, this)
|
|
347
|
-
]
|
|
348
|
-
}, undefined, true, undefined, this),
|
|
349
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
350
|
-
className: "px-4 py-3",
|
|
351
|
-
children: /* @__PURE__ */ jsxDEV("span", {
|
|
352
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${QUERY_TYPE_COLORS[query.type] ?? ""}`,
|
|
353
|
-
children: query.type
|
|
354
|
-
}, undefined, false, undefined, this)
|
|
355
|
-
}, undefined, false, undefined, this),
|
|
356
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
357
|
-
className: "text-muted-foreground px-4 py-3 text-sm",
|
|
358
|
-
children: [
|
|
359
|
-
query.cacheTtlSeconds,
|
|
360
|
-
"s"
|
|
361
|
-
]
|
|
362
|
-
}, undefined, true, undefined, this),
|
|
363
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
364
|
-
className: "px-4 py-3",
|
|
365
|
-
children: query.isShared ? /* @__PURE__ */ jsxDEV("span", {
|
|
366
|
-
className: "text-green-600 dark:text-green-400",
|
|
367
|
-
children: "✓"
|
|
368
|
-
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV("span", {
|
|
369
|
-
className: "text-muted-foreground",
|
|
370
|
-
children: "—"
|
|
371
|
-
}, undefined, false, undefined, this)
|
|
372
|
-
}, undefined, false, undefined, this)
|
|
373
|
-
]
|
|
374
|
-
}, query.id, true, undefined, this)),
|
|
375
|
-
queries.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
|
|
376
|
-
children: /* @__PURE__ */ jsxDEV("td", {
|
|
377
|
-
colSpan: 4,
|
|
378
|
-
className: "text-muted-foreground px-4 py-8 text-center",
|
|
379
|
-
children: "No queries saved"
|
|
380
|
-
}, undefined, false, undefined, this)
|
|
381
|
-
}, undefined, false, undefined, this)
|
|
382
|
-
]
|
|
383
|
-
}, undefined, true, undefined, this)
|
|
384
|
-
]
|
|
385
|
-
}, undefined, true, undefined, this)
|
|
1016
|
+
activeTab === "queries" && /* @__PURE__ */ jsxDEV3(AnalyticsQueriesTable, {
|
|
1017
|
+
queries
|
|
386
1018
|
}, undefined, false, undefined, this)
|
|
387
1019
|
]
|
|
388
1020
|
}, undefined, true, undefined, this)
|