@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
package/dist/browser/ui/index.js
CHANGED
|
@@ -1,276 +1,786 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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."
|
|
11
19
|
},
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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."
|
|
20
45
|
},
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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."
|
|
29
84
|
},
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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." }
|
|
38
96
|
}
|
|
39
|
-
|
|
40
|
-
var
|
|
41
|
-
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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."
|
|
48
106
|
},
|
|
49
|
-
{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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."
|
|
56
154
|
},
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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."
|
|
63
189
|
},
|
|
64
|
-
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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."
|
|
70
222
|
},
|
|
71
|
-
{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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."
|
|
77
252
|
},
|
|
78
|
-
{
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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." }
|
|
85
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
|
|
86
340
|
];
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
+
]
|
|
94
358
|
},
|
|
95
|
-
{
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
+
]
|
|
101
367
|
},
|
|
102
|
-
{
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
+
]
|
|
108
375
|
},
|
|
109
|
-
{
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
]
|
|
123
441
|
}
|
|
124
|
-
|
|
442
|
+
};
|
|
443
|
+
function refOf(spec) {
|
|
444
|
+
return { key: spec.meta.key, version: spec.meta.version };
|
|
125
445
|
}
|
|
126
|
-
function
|
|
127
|
-
|
|
128
|
-
const sign = change >= 0 ? "+" : "";
|
|
129
|
-
return `${icon} ${sign}${change.toFixed(1)}%`;
|
|
446
|
+
function visualizationRefKey(ref) {
|
|
447
|
+
return `${ref.key}.v${ref.version}`;
|
|
130
448
|
}
|
|
131
|
-
var analyticsDashboardMarkdownRenderer = {
|
|
132
|
-
target: "markdown",
|
|
133
|
-
render: async (desc) => {
|
|
134
|
-
if (desc.source.type !== "component" || desc.source.componentKey !== "AnalyticsDashboard") {
|
|
135
|
-
throw new Error("analyticsDashboardMarkdownRenderer: not AnalyticsDashboard");
|
|
136
|
-
}
|
|
137
|
-
const dashboards = mockDashboards;
|
|
138
|
-
const widgets = mockWidgets;
|
|
139
|
-
const queries = mockQueries;
|
|
140
|
-
const dashboard = dashboards[0];
|
|
141
|
-
if (!dashboard) {
|
|
142
|
-
return {
|
|
143
|
-
mimeType: "text/markdown",
|
|
144
|
-
body: `# No Dashboards
|
|
145
449
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
"",
|
|
158
|
-
"## Key Metrics",
|
|
159
|
-
""
|
|
160
|
-
];
|
|
161
|
-
const metricWidgets = dashboardWidgets.filter((w) => w.type === "METRIC");
|
|
162
|
-
for (const widget of metricWidgets) {
|
|
163
|
-
const w = widget;
|
|
164
|
-
lines.push(`### ${w.name}`);
|
|
165
|
-
lines.push(`**${formatNumber(w.value)}** ${formatChange(w.change)}`);
|
|
166
|
-
lines.push("");
|
|
167
|
-
}
|
|
168
|
-
lines.push("## Visualizations");
|
|
169
|
-
lines.push("");
|
|
170
|
-
const chartWidgets = dashboardWidgets.filter((w) => w.type !== "METRIC");
|
|
171
|
-
for (const widget of chartWidgets) {
|
|
172
|
-
const w = widget;
|
|
173
|
-
lines.push(`- **${w.name}** (${w.type.replace("_", " ")}) - ${w.dataPoints} data points`);
|
|
174
|
-
}
|
|
175
|
-
lines.push("");
|
|
176
|
-
lines.push("## Dashboard Stats");
|
|
177
|
-
lines.push("");
|
|
178
|
-
lines.push("| Metric | Value |");
|
|
179
|
-
lines.push("|--------|-------|");
|
|
180
|
-
lines.push(`| Total Dashboards | ${dashboards.length} |`);
|
|
181
|
-
lines.push(`| Published | ${publishedDashboards.length} |`);
|
|
182
|
-
lines.push(`| Total Views | ${totalViews.toLocaleString()} |`);
|
|
183
|
-
lines.push(`| Shared Queries | ${sharedQueries.length} |`);
|
|
184
|
-
return {
|
|
185
|
-
mimeType: "text/markdown",
|
|
186
|
-
body: lines.join(`
|
|
187
|
-
`)
|
|
188
|
-
};
|
|
189
|
-
}
|
|
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)
|
|
190
461
|
};
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
"",
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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;
|
|
217
525
|
return {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
|
221
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;
|
|
222
551
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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);
|
|
269
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"
|
|
270
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
|
+
|
|
271
781
|
// src/ui/hooks/useAnalyticsData.ts
|
|
272
|
-
import { useCallback, useEffect, useState } from "react";
|
|
273
782
|
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
783
|
+
import { useCallback, useEffect, useState } from "react";
|
|
274
784
|
"use client";
|
|
275
785
|
function useAnalyticsData(projectId = "local-project") {
|
|
276
786
|
const { handlers } = useTemplateRuntime();
|
|
@@ -296,7 +806,7 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
296
806
|
if (first) {
|
|
297
807
|
setSelectedDashboard(first);
|
|
298
808
|
const dashboardWidgets = await analytics.getWidgets(first.id);
|
|
299
|
-
setWidgets(dashboardWidgets);
|
|
809
|
+
setWidgets(dashboardWidgets.length > 0 ? dashboardWidgets : createExampleWidgets(first.id));
|
|
300
810
|
}
|
|
301
811
|
}
|
|
302
812
|
} catch (err) {
|
|
@@ -311,7 +821,7 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
311
821
|
const selectDashboard = useCallback(async (dashboard) => {
|
|
312
822
|
setSelectedDashboard(dashboard);
|
|
313
823
|
const dashboardWidgets = await analytics.getWidgets(dashboard.id);
|
|
314
|
-
setWidgets(dashboardWidgets);
|
|
824
|
+
setWidgets(dashboardWidgets.length > 0 ? dashboardWidgets : createExampleWidgets(dashboard.id));
|
|
315
825
|
}, [analytics]);
|
|
316
826
|
const stats = {
|
|
317
827
|
totalDashboards: dashboards.length,
|
|
@@ -333,7 +843,6 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
333
843
|
}
|
|
334
844
|
|
|
335
845
|
// src/ui/AnalyticsDashboard.tsx
|
|
336
|
-
import { useState as useState2 } from "react";
|
|
337
846
|
import {
|
|
338
847
|
Button,
|
|
339
848
|
ErrorState,
|
|
@@ -341,33 +850,14 @@ import {
|
|
|
341
850
|
StatCard,
|
|
342
851
|
StatCardGroup
|
|
343
852
|
} from "@contractspec/lib.design-system";
|
|
344
|
-
import {
|
|
853
|
+
import { useMemo, useState as useState2 } from "react";
|
|
854
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
345
855
|
"use client";
|
|
346
856
|
var STATUS_COLORS = {
|
|
347
857
|
PUBLISHED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
|
|
348
858
|
DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
|
|
349
859
|
ARCHIVED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"
|
|
350
860
|
};
|
|
351
|
-
var WIDGET_ICONS = {
|
|
352
|
-
LINE_CHART: "\uD83D\uDCC8",
|
|
353
|
-
BAR_CHART: "\uD83D\uDCCA",
|
|
354
|
-
PIE_CHART: "\uD83E\uDD67",
|
|
355
|
-
AREA_CHART: "\uD83D\uDCC9",
|
|
356
|
-
SCATTER_PLOT: "⚬",
|
|
357
|
-
METRIC: "\uD83D\uDD22",
|
|
358
|
-
TABLE: "\uD83D\uDCCB",
|
|
359
|
-
HEATMAP: "\uD83D\uDDFA️",
|
|
360
|
-
FUNNEL: "⏬",
|
|
361
|
-
MAP: "\uD83C\uDF0D",
|
|
362
|
-
TEXT: "\uD83D\uDCDD",
|
|
363
|
-
EMBED: "\uD83D\uDD17"
|
|
364
|
-
};
|
|
365
|
-
var QUERY_TYPE_COLORS = {
|
|
366
|
-
SQL: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
|
|
367
|
-
METRIC: "bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400",
|
|
368
|
-
AGGREGATION: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
|
|
369
|
-
CUSTOM: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"
|
|
370
|
-
};
|
|
371
861
|
function AnalyticsDashboard() {
|
|
372
862
|
const [activeTab, setActiveTab] = useState2("dashboards");
|
|
373
863
|
const {
|
|
@@ -385,33 +875,34 @@ function AnalyticsDashboard() {
|
|
|
385
875
|
{ id: "dashboards", label: "Dashboards", icon: "\uD83D\uDCCA" },
|
|
386
876
|
{ id: "queries", label: "Queries", icon: "\uD83D\uDD0D" }
|
|
387
877
|
];
|
|
878
|
+
const resolvedWidgets = useMemo(() => widgets.map((widget2) => resolveAnalyticsWidget(widget2)).filter((widget2) => Boolean(widget2)), [widgets]);
|
|
388
879
|
if (loading) {
|
|
389
|
-
return /* @__PURE__ */
|
|
880
|
+
return /* @__PURE__ */ jsxDEV3(LoaderBlock, {
|
|
390
881
|
label: "Loading Analytics..."
|
|
391
882
|
}, undefined, false, undefined, this);
|
|
392
883
|
}
|
|
393
884
|
if (error) {
|
|
394
|
-
return /* @__PURE__ */
|
|
885
|
+
return /* @__PURE__ */ jsxDEV3(ErrorState, {
|
|
395
886
|
title: "Failed to load Analytics",
|
|
396
887
|
description: error.message,
|
|
397
888
|
onRetry: refetch,
|
|
398
889
|
retryLabel: "Retry"
|
|
399
890
|
}, undefined, false, undefined, this);
|
|
400
891
|
}
|
|
401
|
-
return /* @__PURE__ */
|
|
892
|
+
return /* @__PURE__ */ jsxDEV3("div", {
|
|
402
893
|
className: "space-y-6",
|
|
403
894
|
children: [
|
|
404
|
-
/* @__PURE__ */
|
|
895
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
405
896
|
className: "flex items-center justify-between",
|
|
406
897
|
children: [
|
|
407
|
-
/* @__PURE__ */
|
|
408
|
-
className: "text-2xl
|
|
898
|
+
/* @__PURE__ */ jsxDEV3("h2", {
|
|
899
|
+
className: "font-bold text-2xl",
|
|
409
900
|
children: "Analytics Dashboard"
|
|
410
901
|
}, undefined, false, undefined, this),
|
|
411
|
-
/* @__PURE__ */
|
|
902
|
+
/* @__PURE__ */ jsxDEV3(Button, {
|
|
412
903
|
onClick: () => alert("Create dashboard modal"),
|
|
413
904
|
children: [
|
|
414
|
-
/* @__PURE__ */
|
|
905
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
415
906
|
className: "mr-2",
|
|
416
907
|
children: "+"
|
|
417
908
|
}, undefined, false, undefined, this),
|
|
@@ -420,55 +911,55 @@ function AnalyticsDashboard() {
|
|
|
420
911
|
}, undefined, true, undefined, this)
|
|
421
912
|
]
|
|
422
913
|
}, undefined, true, undefined, this),
|
|
423
|
-
/* @__PURE__ */
|
|
914
|
+
/* @__PURE__ */ jsxDEV3(StatCardGroup, {
|
|
424
915
|
children: [
|
|
425
|
-
/* @__PURE__ */
|
|
916
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
426
917
|
label: "Dashboards",
|
|
427
918
|
value: stats.totalDashboards,
|
|
428
919
|
hint: `${stats.publishedDashboards} published`
|
|
429
920
|
}, undefined, false, undefined, this),
|
|
430
|
-
/* @__PURE__ */
|
|
921
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
431
922
|
label: "Queries",
|
|
432
923
|
value: stats.totalQueries,
|
|
433
924
|
hint: `${stats.sharedQueries} shared`
|
|
434
925
|
}, undefined, false, undefined, this),
|
|
435
|
-
/* @__PURE__ */
|
|
926
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
436
927
|
label: "Widgets",
|
|
437
928
|
value: widgets.length,
|
|
438
929
|
hint: "on current dashboard"
|
|
439
930
|
}, undefined, false, undefined, this)
|
|
440
931
|
]
|
|
441
932
|
}, undefined, true, undefined, this),
|
|
442
|
-
/* @__PURE__ */
|
|
443
|
-
className: "
|
|
933
|
+
/* @__PURE__ */ jsxDEV3("nav", {
|
|
934
|
+
className: "flex gap-1 rounded-lg bg-muted p-1",
|
|
444
935
|
role: "tablist",
|
|
445
|
-
children: tabs.map((tab) => /* @__PURE__ */
|
|
936
|
+
children: tabs.map((tab) => /* @__PURE__ */ jsxDEV3(Button, {
|
|
446
937
|
type: "button",
|
|
447
938
|
role: "tab",
|
|
448
939
|
"aria-selected": activeTab === tab.id,
|
|
449
940
|
onClick: () => setActiveTab(tab.id),
|
|
450
|
-
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"}`,
|
|
451
942
|
children: [
|
|
452
|
-
/* @__PURE__ */
|
|
943
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
453
944
|
children: tab.icon
|
|
454
945
|
}, undefined, false, undefined, this),
|
|
455
946
|
tab.label
|
|
456
947
|
]
|
|
457
948
|
}, tab.id, true, undefined, this))
|
|
458
949
|
}, undefined, false, undefined, this),
|
|
459
|
-
/* @__PURE__ */
|
|
950
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
460
951
|
className: "min-h-[400px]",
|
|
461
952
|
role: "tabpanel",
|
|
462
953
|
children: [
|
|
463
|
-
activeTab === "dashboards" && /* @__PURE__ */
|
|
954
|
+
activeTab === "dashboards" && /* @__PURE__ */ jsxDEV3("div", {
|
|
464
955
|
className: "space-y-6",
|
|
465
956
|
children: [
|
|
466
|
-
/* @__PURE__ */
|
|
957
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
467
958
|
className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
468
959
|
children: [
|
|
469
|
-
dashboards.map((dashboard) => /* @__PURE__ */
|
|
960
|
+
dashboards.map((dashboard) => /* @__PURE__ */ jsxDEV3("div", {
|
|
470
961
|
onClick: () => selectDashboard(dashboard),
|
|
471
|
-
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"}`,
|
|
472
963
|
role: "button",
|
|
473
964
|
tabIndex: 0,
|
|
474
965
|
onKeyDown: (e) => {
|
|
@@ -476,33 +967,33 @@ function AnalyticsDashboard() {
|
|
|
476
967
|
selectDashboard(dashboard);
|
|
477
968
|
},
|
|
478
969
|
children: [
|
|
479
|
-
/* @__PURE__ */
|
|
970
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
480
971
|
className: "mb-2 flex items-center justify-between",
|
|
481
972
|
children: [
|
|
482
|
-
/* @__PURE__ */
|
|
973
|
+
/* @__PURE__ */ jsxDEV3("h3", {
|
|
483
974
|
className: "font-medium",
|
|
484
975
|
children: dashboard.name
|
|
485
976
|
}, undefined, false, undefined, this),
|
|
486
|
-
/* @__PURE__ */
|
|
487
|
-
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] ?? ""}`,
|
|
488
979
|
children: dashboard.status
|
|
489
980
|
}, undefined, false, undefined, this)
|
|
490
981
|
]
|
|
491
982
|
}, undefined, true, undefined, this),
|
|
492
|
-
/* @__PURE__ */
|
|
493
|
-
className: "text-muted-foreground
|
|
983
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
984
|
+
className: "mb-3 text-muted-foreground text-sm",
|
|
494
985
|
children: dashboard.description
|
|
495
986
|
}, undefined, false, undefined, this),
|
|
496
|
-
/* @__PURE__ */
|
|
497
|
-
className: "
|
|
987
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
988
|
+
className: "flex items-center justify-between text-muted-foreground text-xs",
|
|
498
989
|
children: [
|
|
499
|
-
/* @__PURE__ */
|
|
990
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
500
991
|
children: [
|
|
501
992
|
"/",
|
|
502
993
|
dashboard.slug
|
|
503
994
|
]
|
|
504
995
|
}, undefined, true, undefined, this),
|
|
505
|
-
dashboard.isPublic && /* @__PURE__ */
|
|
996
|
+
dashboard.isPublic && /* @__PURE__ */ jsxDEV3("span", {
|
|
506
997
|
className: "text-green-600 dark:text-green-400",
|
|
507
998
|
children: "\uD83C\uDF10 Public"
|
|
508
999
|
}, undefined, false, undefined, this)
|
|
@@ -510,149 +1001,20 @@ function AnalyticsDashboard() {
|
|
|
510
1001
|
}, undefined, true, undefined, this)
|
|
511
1002
|
]
|
|
512
1003
|
}, dashboard.id, true, undefined, this)),
|
|
513
|
-
dashboards.length === 0 && /* @__PURE__ */
|
|
514
|
-
className: "
|
|
1004
|
+
dashboards.length === 0 && /* @__PURE__ */ jsxDEV3("div", {
|
|
1005
|
+
className: "col-span-full flex h-64 items-center justify-center text-muted-foreground",
|
|
515
1006
|
children: "No dashboards created yet"
|
|
516
1007
|
}, undefined, false, undefined, this)
|
|
517
1008
|
]
|
|
518
1009
|
}, undefined, true, undefined, this),
|
|
519
|
-
selectedDashboard
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
children: [
|
|
524
|
-
'Widgets in "',
|
|
525
|
-
selectedDashboard.name,
|
|
526
|
-
'"'
|
|
527
|
-
]
|
|
528
|
-
}, undefined, true, undefined, this),
|
|
529
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
530
|
-
className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
531
|
-
children: widgets.map((widget) => /* @__PURE__ */ jsxDEV("div", {
|
|
532
|
-
className: "border-border bg-card rounded-lg border p-4",
|
|
533
|
-
children: [
|
|
534
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
535
|
-
className: "mb-2 flex items-center gap-2",
|
|
536
|
-
children: [
|
|
537
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
538
|
-
className: "text-xl",
|
|
539
|
-
children: WIDGET_ICONS[widget.type] ?? "\uD83D\uDCCA"
|
|
540
|
-
}, undefined, false, undefined, this),
|
|
541
|
-
/* @__PURE__ */ jsxDEV("span", {
|
|
542
|
-
className: "font-medium",
|
|
543
|
-
children: widget.name
|
|
544
|
-
}, undefined, false, undefined, this)
|
|
545
|
-
]
|
|
546
|
-
}, undefined, true, undefined, this),
|
|
547
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
548
|
-
className: "text-muted-foreground text-sm",
|
|
549
|
-
children: widget.type.replace(/_/g, " ")
|
|
550
|
-
}, undefined, false, undefined, this),
|
|
551
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
552
|
-
className: "text-muted-foreground mt-2 text-xs",
|
|
553
|
-
children: [
|
|
554
|
-
"Position: (",
|
|
555
|
-
widget.gridX,
|
|
556
|
-
", ",
|
|
557
|
-
widget.gridY,
|
|
558
|
-
") •",
|
|
559
|
-
" ",
|
|
560
|
-
widget.gridWidth,
|
|
561
|
-
"x",
|
|
562
|
-
widget.gridHeight
|
|
563
|
-
]
|
|
564
|
-
}, undefined, true, undefined, this)
|
|
565
|
-
]
|
|
566
|
-
}, widget.id, true, undefined, this))
|
|
567
|
-
}, undefined, false, undefined, this)
|
|
568
|
-
]
|
|
569
|
-
}, undefined, true, undefined, this)
|
|
1010
|
+
selectedDashboard ? /* @__PURE__ */ jsxDEV3(AnalyticsWidgetBoard, {
|
|
1011
|
+
dashboardName: selectedDashboard.name,
|
|
1012
|
+
widgets: resolvedWidgets
|
|
1013
|
+
}, undefined, false, undefined, this) : null
|
|
570
1014
|
]
|
|
571
1015
|
}, undefined, true, undefined, this),
|
|
572
|
-
activeTab === "queries" && /* @__PURE__ */
|
|
573
|
-
|
|
574
|
-
children: /* @__PURE__ */ jsxDEV("table", {
|
|
575
|
-
className: "w-full",
|
|
576
|
-
children: [
|
|
577
|
-
/* @__PURE__ */ jsxDEV("thead", {
|
|
578
|
-
className: "border-border bg-muted/30 border-b",
|
|
579
|
-
children: /* @__PURE__ */ jsxDEV("tr", {
|
|
580
|
-
children: [
|
|
581
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
582
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
583
|
-
children: "Query"
|
|
584
|
-
}, undefined, false, undefined, this),
|
|
585
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
586
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
587
|
-
children: "Type"
|
|
588
|
-
}, undefined, false, undefined, this),
|
|
589
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
590
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
591
|
-
children: "Cache TTL"
|
|
592
|
-
}, undefined, false, undefined, this),
|
|
593
|
-
/* @__PURE__ */ jsxDEV("th", {
|
|
594
|
-
className: "px-4 py-3 text-left text-sm font-medium",
|
|
595
|
-
children: "Shared"
|
|
596
|
-
}, undefined, false, undefined, this)
|
|
597
|
-
]
|
|
598
|
-
}, undefined, true, undefined, this)
|
|
599
|
-
}, undefined, false, undefined, this),
|
|
600
|
-
/* @__PURE__ */ jsxDEV("tbody", {
|
|
601
|
-
className: "divide-border divide-y",
|
|
602
|
-
children: [
|
|
603
|
-
queries.map((query) => /* @__PURE__ */ jsxDEV("tr", {
|
|
604
|
-
className: "hover:bg-muted/50",
|
|
605
|
-
children: [
|
|
606
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
607
|
-
className: "px-4 py-3",
|
|
608
|
-
children: [
|
|
609
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
610
|
-
className: "font-medium",
|
|
611
|
-
children: query.name
|
|
612
|
-
}, undefined, false, undefined, this),
|
|
613
|
-
/* @__PURE__ */ jsxDEV("div", {
|
|
614
|
-
className: "text-muted-foreground text-sm",
|
|
615
|
-
children: query.description
|
|
616
|
-
}, undefined, false, undefined, this)
|
|
617
|
-
]
|
|
618
|
-
}, undefined, true, undefined, this),
|
|
619
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
620
|
-
className: "px-4 py-3",
|
|
621
|
-
children: /* @__PURE__ */ jsxDEV("span", {
|
|
622
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${QUERY_TYPE_COLORS[query.type] ?? ""}`,
|
|
623
|
-
children: query.type
|
|
624
|
-
}, undefined, false, undefined, this)
|
|
625
|
-
}, undefined, false, undefined, this),
|
|
626
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
627
|
-
className: "text-muted-foreground px-4 py-3 text-sm",
|
|
628
|
-
children: [
|
|
629
|
-
query.cacheTtlSeconds,
|
|
630
|
-
"s"
|
|
631
|
-
]
|
|
632
|
-
}, undefined, true, undefined, this),
|
|
633
|
-
/* @__PURE__ */ jsxDEV("td", {
|
|
634
|
-
className: "px-4 py-3",
|
|
635
|
-
children: query.isShared ? /* @__PURE__ */ jsxDEV("span", {
|
|
636
|
-
className: "text-green-600 dark:text-green-400",
|
|
637
|
-
children: "✓"
|
|
638
|
-
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV("span", {
|
|
639
|
-
className: "text-muted-foreground",
|
|
640
|
-
children: "—"
|
|
641
|
-
}, undefined, false, undefined, this)
|
|
642
|
-
}, undefined, false, undefined, this)
|
|
643
|
-
]
|
|
644
|
-
}, query.id, true, undefined, this)),
|
|
645
|
-
queries.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
|
|
646
|
-
children: /* @__PURE__ */ jsxDEV("td", {
|
|
647
|
-
colSpan: 4,
|
|
648
|
-
className: "text-muted-foreground px-4 py-8 text-center",
|
|
649
|
-
children: "No queries saved"
|
|
650
|
-
}, undefined, false, undefined, this)
|
|
651
|
-
}, undefined, false, undefined, this)
|
|
652
|
-
]
|
|
653
|
-
}, undefined, true, undefined, this)
|
|
654
|
-
]
|
|
655
|
-
}, undefined, true, undefined, this)
|
|
1016
|
+
activeTab === "queries" && /* @__PURE__ */ jsxDEV3(AnalyticsQueriesTable, {
|
|
1017
|
+
queries
|
|
656
1018
|
}, undefined, false, undefined, this)
|
|
657
1019
|
]
|
|
658
1020
|
}, undefined, true, undefined, this)
|
|
@@ -662,6 +1024,168 @@ function AnalyticsDashboard() {
|
|
|
662
1024
|
|
|
663
1025
|
// src/ui/hooks/index.ts
|
|
664
1026
|
"use client";
|
|
1027
|
+
|
|
1028
|
+
// src/ui/renderers/analytics.markdown.ts
|
|
1029
|
+
var mockDashboards = [
|
|
1030
|
+
{
|
|
1031
|
+
id: "dash-1",
|
|
1032
|
+
name: "Sales Overview",
|
|
1033
|
+
slug: "sales-overview",
|
|
1034
|
+
status: "PUBLISHED",
|
|
1035
|
+
widgetCount: 11,
|
|
1036
|
+
viewCount: 1250,
|
|
1037
|
+
lastViewedAt: "2026-03-18T12:00:00Z"
|
|
1038
|
+
},
|
|
1039
|
+
{
|
|
1040
|
+
id: "dash-2",
|
|
1041
|
+
name: "User Engagement",
|
|
1042
|
+
slug: "user-engagement",
|
|
1043
|
+
status: "PUBLISHED",
|
|
1044
|
+
widgetCount: 8,
|
|
1045
|
+
viewCount: 890,
|
|
1046
|
+
lastViewedAt: "2026-03-18T10:00:00Z"
|
|
1047
|
+
}
|
|
1048
|
+
];
|
|
1049
|
+
var mockQueries = [
|
|
1050
|
+
{
|
|
1051
|
+
id: "q-1",
|
|
1052
|
+
name: "Monthly Revenue",
|
|
1053
|
+
type: "AGGREGATION",
|
|
1054
|
+
isShared: true,
|
|
1055
|
+
executionCount: 1500
|
|
1056
|
+
},
|
|
1057
|
+
{
|
|
1058
|
+
id: "q-2",
|
|
1059
|
+
name: "User Growth",
|
|
1060
|
+
type: "METRIC",
|
|
1061
|
+
isShared: true,
|
|
1062
|
+
executionCount: 890
|
|
1063
|
+
},
|
|
1064
|
+
{
|
|
1065
|
+
id: "q-3",
|
|
1066
|
+
name: "Product Sales",
|
|
1067
|
+
type: "SQL",
|
|
1068
|
+
isShared: false,
|
|
1069
|
+
executionCount: 340
|
|
1070
|
+
},
|
|
1071
|
+
{
|
|
1072
|
+
id: "q-4",
|
|
1073
|
+
name: "Conversion Funnel",
|
|
1074
|
+
type: "AGGREGATION",
|
|
1075
|
+
isShared: true,
|
|
1076
|
+
executionCount: 450
|
|
1077
|
+
}
|
|
1078
|
+
];
|
|
1079
|
+
function dashboardWidgets(dashboardId) {
|
|
1080
|
+
return createExampleWidgets(dashboardId).map((widget2) => resolveAnalyticsWidget(widget2)).filter((widget2) => Boolean(widget2));
|
|
1081
|
+
}
|
|
1082
|
+
var analyticsDashboardMarkdownRenderer = {
|
|
1083
|
+
target: "markdown",
|
|
1084
|
+
render: async (desc) => {
|
|
1085
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "AnalyticsDashboard") {
|
|
1086
|
+
throw new Error("analyticsDashboardMarkdownRenderer: not AnalyticsDashboard");
|
|
1087
|
+
}
|
|
1088
|
+
const dashboard = mockDashboards[0];
|
|
1089
|
+
if (!dashboard) {
|
|
1090
|
+
return {
|
|
1091
|
+
mimeType: "text/markdown",
|
|
1092
|
+
body: `# No Dashboards
|
|
1093
|
+
|
|
1094
|
+
No dashboards available.`
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
const widgets = dashboardWidgets(dashboard.id);
|
|
1098
|
+
const metricWidgets = widgets.filter((widget2) => widget2.bindings[0]?.spec.visualization.kind === "metric");
|
|
1099
|
+
const lines = [
|
|
1100
|
+
`# ${dashboard.name}`,
|
|
1101
|
+
"",
|
|
1102
|
+
"> Contract-backed analytics dashboard overview.",
|
|
1103
|
+
"",
|
|
1104
|
+
"## Key Metrics",
|
|
1105
|
+
""
|
|
1106
|
+
];
|
|
1107
|
+
for (const widget2 of metricWidgets) {
|
|
1108
|
+
const binding2 = widget2.bindings[0];
|
|
1109
|
+
if (!binding2)
|
|
1110
|
+
continue;
|
|
1111
|
+
lines.push(`- **${widget2.name}** via \`${binding2.spec.meta.key}\``);
|
|
1112
|
+
}
|
|
1113
|
+
lines.push("");
|
|
1114
|
+
lines.push("## Visual Blocks");
|
|
1115
|
+
lines.push("");
|
|
1116
|
+
for (const widget2 of widgets) {
|
|
1117
|
+
const kinds = widget2.bindings.map((binding2) => binding2.spec.visualization.kind).join(", ");
|
|
1118
|
+
lines.push(`- **${widget2.name}** (${widget2.layout}) → ${kinds}`);
|
|
1119
|
+
}
|
|
1120
|
+
lines.push("");
|
|
1121
|
+
lines.push("## Dashboard Stats");
|
|
1122
|
+
lines.push("");
|
|
1123
|
+
lines.push("| Metric | Value |");
|
|
1124
|
+
lines.push("|--------|-------|");
|
|
1125
|
+
lines.push(`| Total Dashboards | ${mockDashboards.length} |`);
|
|
1126
|
+
lines.push(`| Published | ${mockDashboards.filter((item) => item.status === "PUBLISHED").length} |`);
|
|
1127
|
+
lines.push(`| Shared Queries | ${mockQueries.filter((query) => query.isShared).length} |`);
|
|
1128
|
+
return {
|
|
1129
|
+
mimeType: "text/markdown",
|
|
1130
|
+
body: lines.join(`
|
|
1131
|
+
`)
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
var dashboardListMarkdownRenderer = {
|
|
1136
|
+
target: "markdown",
|
|
1137
|
+
render: async (desc) => {
|
|
1138
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "DashboardList") {
|
|
1139
|
+
throw new Error("dashboardListMarkdownRenderer: not DashboardList");
|
|
1140
|
+
}
|
|
1141
|
+
const lines = [
|
|
1142
|
+
"# Dashboards",
|
|
1143
|
+
"",
|
|
1144
|
+
"> Browse and manage analytics dashboards",
|
|
1145
|
+
"",
|
|
1146
|
+
"| Dashboard | Widgets | Views | Status | Last Viewed |",
|
|
1147
|
+
"|-----------|---------|-------|--------|-------------|"
|
|
1148
|
+
];
|
|
1149
|
+
for (const dashboard of mockDashboards) {
|
|
1150
|
+
const lastViewed = dashboard.lastViewedAt ? new Date(dashboard.lastViewedAt).toLocaleDateString() : "Never";
|
|
1151
|
+
const statusIcon = dashboard.status === "PUBLISHED" ? "\uD83D\uDFE2" : "⚫";
|
|
1152
|
+
lines.push(`| [${dashboard.name}](/dashboards/${dashboard.slug}) | ${dashboard.widgetCount} | ${dashboard.viewCount.toLocaleString()} | ${statusIcon} ${dashboard.status} | ${lastViewed} |`);
|
|
1153
|
+
}
|
|
1154
|
+
return {
|
|
1155
|
+
mimeType: "text/markdown",
|
|
1156
|
+
body: lines.join(`
|
|
1157
|
+
`)
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
var queryBuilderMarkdownRenderer = {
|
|
1162
|
+
target: "markdown",
|
|
1163
|
+
render: async (desc) => {
|
|
1164
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "QueryBuilder") {
|
|
1165
|
+
throw new Error("queryBuilderMarkdownRenderer: not QueryBuilder");
|
|
1166
|
+
}
|
|
1167
|
+
const lines = [
|
|
1168
|
+
"# Query Builder",
|
|
1169
|
+
"",
|
|
1170
|
+
"> Create and manage reusable data queries.",
|
|
1171
|
+
"",
|
|
1172
|
+
"| Query | Type | Shared | Executions |",
|
|
1173
|
+
"|-------|------|--------|------------|"
|
|
1174
|
+
];
|
|
1175
|
+
for (const query of mockQueries) {
|
|
1176
|
+
lines.push(`| ${query.name} | ${query.type} | ${query.isShared ? "\uD83C\uDF10" : "\uD83D\uDD12"} | ${query.executionCount.toLocaleString()} |`);
|
|
1177
|
+
}
|
|
1178
|
+
lines.push("");
|
|
1179
|
+
lines.push("## Visualization Contracts");
|
|
1180
|
+
lines.push("");
|
|
1181
|
+
lines.push("Widgets reference `VisualizationSpec` contracts instead of rendering ad-hoc widget types.");
|
|
1182
|
+
return {
|
|
1183
|
+
mimeType: "text/markdown",
|
|
1184
|
+
body: lines.join(`
|
|
1185
|
+
`)
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
665
1189
|
export {
|
|
666
1190
|
useAnalyticsData,
|
|
667
1191
|
queryBuilderMarkdownRenderer,
|