@contractspec/example.analytics-dashboard 3.7.6 → 3.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -271
- package/dist/browser/dashboard.feature.js +592 -0
- package/dist/browser/docs/analytics-dashboard.docblock.js +2 -1
- package/dist/browser/docs/index.js +2 -1
- package/dist/browser/events.js +1 -1
- package/dist/browser/index.js +1260 -627
- package/dist/browser/ui/AnalyticsDashboard.js +915 -194
- package/dist/browser/ui/AnalyticsDashboard.widgets.js +94 -0
- package/dist/browser/ui/AnalyticsQueriesTable.js +188 -0
- package/dist/browser/ui/hooks/index.js +594 -3
- package/dist/browser/ui/hooks/useAnalyticsData.js +594 -3
- package/dist/browser/ui/index.js +1053 -440
- package/dist/browser/ui/renderers/analytics.markdown.js +620 -138
- package/dist/browser/ui/renderers/index.js +620 -138
- package/dist/browser/visualizations/catalog.js +457 -0
- package/dist/browser/visualizations/index.js +611 -0
- package/dist/browser/visualizations/specs.breakdown.js +140 -0
- package/dist/browser/visualizations/specs.performance.js +198 -0
- package/dist/browser/visualizations/widgets.js +595 -0
- package/dist/dashboard/index.d.ts +3 -3
- package/dist/dashboard.feature.js +592 -0
- package/dist/docs/analytics-dashboard.docblock.js +2 -1
- package/dist/docs/index.js +2 -1
- package/dist/events.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1260 -627
- package/dist/node/dashboard.feature.js +592 -0
- package/dist/node/docs/analytics-dashboard.docblock.js +2 -1
- package/dist/node/docs/index.js +2 -1
- package/dist/node/events.js +1 -1
- package/dist/node/index.js +1260 -627
- package/dist/node/ui/AnalyticsDashboard.js +915 -194
- package/dist/node/ui/AnalyticsDashboard.widgets.js +94 -0
- package/dist/node/ui/AnalyticsQueriesTable.js +188 -0
- package/dist/node/ui/hooks/index.js +594 -3
- package/dist/node/ui/hooks/useAnalyticsData.js +594 -3
- package/dist/node/ui/index.js +1053 -440
- package/dist/node/ui/renderers/analytics.markdown.js +620 -138
- package/dist/node/ui/renderers/index.js +620 -138
- package/dist/node/visualizations/catalog.js +457 -0
- package/dist/node/visualizations/index.js +611 -0
- package/dist/node/visualizations/specs.breakdown.js +140 -0
- package/dist/node/visualizations/specs.performance.js +198 -0
- package/dist/node/visualizations/widgets.js +595 -0
- package/dist/query/index.d.ts +1 -1
- package/dist/query-engine/index.d.ts +1 -1
- package/dist/ui/AnalyticsDashboard.js +915 -194
- package/dist/ui/AnalyticsDashboard.widgets.d.ts +5 -0
- package/dist/ui/AnalyticsDashboard.widgets.js +95 -0
- package/dist/ui/AnalyticsQueriesTable.d.ts +4 -0
- package/dist/ui/AnalyticsQueriesTable.js +189 -0
- package/dist/ui/AnalyticsQueriesTable.smoke.test.d.ts +1 -0
- package/dist/ui/hooks/index.d.ts +1 -1
- package/dist/ui/hooks/index.js +594 -3
- package/dist/ui/hooks/useAnalyticsData.js +594 -3
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +1053 -440
- package/dist/ui/renderers/analytics.markdown.d.ts +0 -9
- package/dist/ui/renderers/analytics.markdown.js +620 -138
- package/dist/ui/renderers/index.js +620 -138
- package/dist/visualizations/catalog.d.ts +9 -0
- package/dist/visualizations/catalog.js +458 -0
- package/dist/visualizations/index.d.ts +4 -0
- package/dist/visualizations/index.js +612 -0
- package/dist/visualizations/specs.breakdown.d.ts +4 -0
- package/dist/visualizations/specs.breakdown.js +141 -0
- package/dist/visualizations/specs.performance.d.ts +5 -0
- package/dist/visualizations/specs.performance.js +199 -0
- package/dist/visualizations/widgets.d.ts +24 -0
- package/dist/visualizations/widgets.js +596 -0
- package/dist/visualizations/widgets.test.d.ts +1 -0
- package/package.json +111 -11
package/dist/node/ui/index.js
CHANGED
|
@@ -1,276 +1,875 @@
|
|
|
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." }
|
|
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." }
|
|
85
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 { DataTable } from "@contractspec/lib.design-system";
|
|
686
|
+
import { useContractTable } from "@contractspec/lib.presentation-runtime-react";
|
|
687
|
+
import { Badge } from "@contractspec/lib.ui-kit-web/ui/badge";
|
|
688
|
+
import { HStack, VStack } from "@contractspec/lib.ui-kit-web/ui/stack";
|
|
689
|
+
import { Text } from "@contractspec/lib.ui-kit-web/ui/text";
|
|
690
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
691
|
+
"use client";
|
|
692
|
+
var QUERY_TYPE_COLORS = {
|
|
693
|
+
SQL: "default",
|
|
694
|
+
METRIC: "secondary",
|
|
695
|
+
AGGREGATION: "secondary",
|
|
696
|
+
CUSTOM: "outline"
|
|
270
697
|
};
|
|
698
|
+
function formatJson(value) {
|
|
699
|
+
return JSON.stringify(value, null, 2);
|
|
700
|
+
}
|
|
701
|
+
function AnalyticsQueriesTable({ queries }) {
|
|
702
|
+
const controller = useContractTable({
|
|
703
|
+
data: queries,
|
|
704
|
+
columns: [
|
|
705
|
+
{
|
|
706
|
+
id: "query",
|
|
707
|
+
header: "Query",
|
|
708
|
+
label: "Query",
|
|
709
|
+
accessor: (query) => query.name,
|
|
710
|
+
cell: ({ item }) => /* @__PURE__ */ jsxDEV2(VStack, {
|
|
711
|
+
gap: "xs",
|
|
712
|
+
children: [
|
|
713
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
714
|
+
className: "font-medium text-sm",
|
|
715
|
+
children: item.name
|
|
716
|
+
}, undefined, false, undefined, this),
|
|
717
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
718
|
+
className: "text-muted-foreground text-xs",
|
|
719
|
+
children: [
|
|
720
|
+
"Updated ",
|
|
721
|
+
item.updatedAt.toLocaleDateString()
|
|
722
|
+
]
|
|
723
|
+
}, undefined, true, undefined, this)
|
|
724
|
+
]
|
|
725
|
+
}, undefined, true, undefined, this),
|
|
726
|
+
size: 240,
|
|
727
|
+
minSize: 180,
|
|
728
|
+
canSort: true,
|
|
729
|
+
canPin: true,
|
|
730
|
+
canResize: true
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
id: "description",
|
|
734
|
+
header: "Description",
|
|
735
|
+
label: "Description",
|
|
736
|
+
accessor: (query) => query.description ?? "",
|
|
737
|
+
cell: ({ value }) => /* @__PURE__ */ jsxDEV2(Text, {
|
|
738
|
+
className: "line-clamp-2 text-muted-foreground text-sm",
|
|
739
|
+
children: String(value || "No description")
|
|
740
|
+
}, undefined, false, undefined, this),
|
|
741
|
+
size: 300,
|
|
742
|
+
minSize: 220,
|
|
743
|
+
canSort: false,
|
|
744
|
+
canHide: true,
|
|
745
|
+
canResize: true
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
id: "type",
|
|
749
|
+
header: "Type",
|
|
750
|
+
label: "Type",
|
|
751
|
+
accessorKey: "type",
|
|
752
|
+
cell: ({ value }) => /* @__PURE__ */ jsxDEV2(Badge, {
|
|
753
|
+
variant: QUERY_TYPE_COLORS[String(value)],
|
|
754
|
+
children: String(value)
|
|
755
|
+
}, undefined, false, undefined, this),
|
|
756
|
+
size: 150,
|
|
757
|
+
canSort: true,
|
|
758
|
+
canHide: true,
|
|
759
|
+
canResize: true
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
id: "cacheTtlSeconds",
|
|
763
|
+
header: "Cache TTL",
|
|
764
|
+
label: "Cache TTL",
|
|
765
|
+
accessorKey: "cacheTtlSeconds",
|
|
766
|
+
cell: ({ value }) => `${String(value)}s`,
|
|
767
|
+
align: "right",
|
|
768
|
+
size: 140,
|
|
769
|
+
canSort: true,
|
|
770
|
+
canResize: true
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
id: "isShared",
|
|
774
|
+
header: "Shared",
|
|
775
|
+
label: "Shared",
|
|
776
|
+
accessorKey: "isShared",
|
|
777
|
+
cell: ({ value }) => /* @__PURE__ */ jsxDEV2(Badge, {
|
|
778
|
+
variant: value ? "default" : "outline",
|
|
779
|
+
children: value ? "Shared" : "Private"
|
|
780
|
+
}, undefined, false, undefined, this),
|
|
781
|
+
size: 140,
|
|
782
|
+
canSort: true,
|
|
783
|
+
canHide: true,
|
|
784
|
+
canResize: true
|
|
785
|
+
}
|
|
786
|
+
],
|
|
787
|
+
initialState: {
|
|
788
|
+
pagination: { pageIndex: 0, pageSize: 3 },
|
|
789
|
+
columnVisibility: { description: false },
|
|
790
|
+
columnPinning: { left: ["query"], right: [] }
|
|
791
|
+
},
|
|
792
|
+
renderExpandedContent: (query) => /* @__PURE__ */ jsxDEV2(VStack, {
|
|
793
|
+
gap: "sm",
|
|
794
|
+
className: "py-2",
|
|
795
|
+
children: [
|
|
796
|
+
/* @__PURE__ */ jsxDEV2(VStack, {
|
|
797
|
+
gap: "xs",
|
|
798
|
+
children: [
|
|
799
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
800
|
+
className: "font-medium text-sm",
|
|
801
|
+
children: "Description"
|
|
802
|
+
}, undefined, false, undefined, this),
|
|
803
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
804
|
+
className: "text-muted-foreground text-sm",
|
|
805
|
+
children: query.description ?? "No description"
|
|
806
|
+
}, undefined, false, undefined, this)
|
|
807
|
+
]
|
|
808
|
+
}, undefined, true, undefined, this),
|
|
809
|
+
query.sql ? /* @__PURE__ */ jsxDEV2(VStack, {
|
|
810
|
+
gap: "xs",
|
|
811
|
+
children: [
|
|
812
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
813
|
+
className: "font-medium text-sm",
|
|
814
|
+
children: "SQL"
|
|
815
|
+
}, undefined, false, undefined, this),
|
|
816
|
+
/* @__PURE__ */ jsxDEV2("pre", {
|
|
817
|
+
className: "overflow-auto rounded-md bg-muted/40 p-3 text-xs",
|
|
818
|
+
children: query.sql
|
|
819
|
+
}, undefined, false, undefined, this)
|
|
820
|
+
]
|
|
821
|
+
}, undefined, true, undefined, this) : null,
|
|
822
|
+
/* @__PURE__ */ jsxDEV2(VStack, {
|
|
823
|
+
gap: "xs",
|
|
824
|
+
children: [
|
|
825
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
826
|
+
className: "font-medium text-sm",
|
|
827
|
+
children: "Definition"
|
|
828
|
+
}, undefined, false, undefined, this),
|
|
829
|
+
/* @__PURE__ */ jsxDEV2("pre", {
|
|
830
|
+
className: "overflow-auto rounded-md bg-muted/40 p-3 text-xs",
|
|
831
|
+
children: formatJson(query.definition)
|
|
832
|
+
}, undefined, false, undefined, this)
|
|
833
|
+
]
|
|
834
|
+
}, undefined, true, undefined, this)
|
|
835
|
+
]
|
|
836
|
+
}, undefined, true, undefined, this),
|
|
837
|
+
getCanExpand: () => true
|
|
838
|
+
});
|
|
839
|
+
return /* @__PURE__ */ jsxDEV2(DataTable, {
|
|
840
|
+
controller,
|
|
841
|
+
title: "Saved Queries",
|
|
842
|
+
description: "Client-mode table using the shared ContractSpec controller and renderer.",
|
|
843
|
+
toolbar: /* @__PURE__ */ jsxDEV2(HStack, {
|
|
844
|
+
gap: "sm",
|
|
845
|
+
className: "flex-wrap",
|
|
846
|
+
children: [
|
|
847
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
848
|
+
className: "text-muted-foreground text-sm",
|
|
849
|
+
children: [
|
|
850
|
+
queries.length,
|
|
851
|
+
" queries"
|
|
852
|
+
]
|
|
853
|
+
}, undefined, true, undefined, this),
|
|
854
|
+
/* @__PURE__ */ jsxDEV2(Text, {
|
|
855
|
+
className: "text-muted-foreground text-sm",
|
|
856
|
+
children: [
|
|
857
|
+
queries.filter((query) => query.isShared).length,
|
|
858
|
+
" shared"
|
|
859
|
+
]
|
|
860
|
+
}, undefined, true, undefined, this)
|
|
861
|
+
]
|
|
862
|
+
}, undefined, true, undefined, this),
|
|
863
|
+
emptyState: /* @__PURE__ */ jsxDEV2("div", {
|
|
864
|
+
className: "rounded-md border border-dashed p-8 text-center text-muted-foreground text-sm",
|
|
865
|
+
children: "No queries saved"
|
|
866
|
+
}, undefined, false, undefined, this)
|
|
867
|
+
}, undefined, false, undefined, this);
|
|
868
|
+
}
|
|
869
|
+
|
|
271
870
|
// src/ui/hooks/useAnalyticsData.ts
|
|
272
|
-
import { useCallback, useEffect, useState } from "react";
|
|
273
871
|
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
872
|
+
import { useCallback, useEffect, useState } from "react";
|
|
274
873
|
"use client";
|
|
275
874
|
function useAnalyticsData(projectId = "local-project") {
|
|
276
875
|
const { handlers } = useTemplateRuntime();
|
|
@@ -296,7 +895,7 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
296
895
|
if (first) {
|
|
297
896
|
setSelectedDashboard(first);
|
|
298
897
|
const dashboardWidgets = await analytics.getWidgets(first.id);
|
|
299
|
-
setWidgets(dashboardWidgets);
|
|
898
|
+
setWidgets(dashboardWidgets.length > 0 ? dashboardWidgets : createExampleWidgets(first.id));
|
|
300
899
|
}
|
|
301
900
|
}
|
|
302
901
|
} catch (err) {
|
|
@@ -311,7 +910,7 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
311
910
|
const selectDashboard = useCallback(async (dashboard) => {
|
|
312
911
|
setSelectedDashboard(dashboard);
|
|
313
912
|
const dashboardWidgets = await analytics.getWidgets(dashboard.id);
|
|
314
|
-
setWidgets(dashboardWidgets);
|
|
913
|
+
setWidgets(dashboardWidgets.length > 0 ? dashboardWidgets : createExampleWidgets(dashboard.id));
|
|
315
914
|
}, [analytics]);
|
|
316
915
|
const stats = {
|
|
317
916
|
totalDashboards: dashboards.length,
|
|
@@ -333,7 +932,6 @@ function useAnalyticsData(projectId = "local-project") {
|
|
|
333
932
|
}
|
|
334
933
|
|
|
335
934
|
// src/ui/AnalyticsDashboard.tsx
|
|
336
|
-
import { useState as useState2 } from "react";
|
|
337
935
|
import {
|
|
338
936
|
Button,
|
|
339
937
|
ErrorState,
|
|
@@ -341,33 +939,14 @@ import {
|
|
|
341
939
|
StatCard,
|
|
342
940
|
StatCardGroup
|
|
343
941
|
} from "@contractspec/lib.design-system";
|
|
344
|
-
import {
|
|
942
|
+
import { useMemo, useState as useState2 } from "react";
|
|
943
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
345
944
|
"use client";
|
|
346
945
|
var STATUS_COLORS = {
|
|
347
946
|
PUBLISHED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
|
|
348
947
|
DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
|
|
349
948
|
ARCHIVED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"
|
|
350
949
|
};
|
|
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
950
|
function AnalyticsDashboard() {
|
|
372
951
|
const [activeTab, setActiveTab] = useState2("dashboards");
|
|
373
952
|
const {
|
|
@@ -385,33 +964,34 @@ function AnalyticsDashboard() {
|
|
|
385
964
|
{ id: "dashboards", label: "Dashboards", icon: "\uD83D\uDCCA" },
|
|
386
965
|
{ id: "queries", label: "Queries", icon: "\uD83D\uDD0D" }
|
|
387
966
|
];
|
|
967
|
+
const resolvedWidgets = useMemo(() => widgets.map((widget2) => resolveAnalyticsWidget(widget2)).filter((widget2) => Boolean(widget2)), [widgets]);
|
|
388
968
|
if (loading) {
|
|
389
|
-
return /* @__PURE__ */
|
|
969
|
+
return /* @__PURE__ */ jsxDEV3(LoaderBlock, {
|
|
390
970
|
label: "Loading Analytics..."
|
|
391
971
|
}, undefined, false, undefined, this);
|
|
392
972
|
}
|
|
393
973
|
if (error) {
|
|
394
|
-
return /* @__PURE__ */
|
|
974
|
+
return /* @__PURE__ */ jsxDEV3(ErrorState, {
|
|
395
975
|
title: "Failed to load Analytics",
|
|
396
976
|
description: error.message,
|
|
397
977
|
onRetry: refetch,
|
|
398
978
|
retryLabel: "Retry"
|
|
399
979
|
}, undefined, false, undefined, this);
|
|
400
980
|
}
|
|
401
|
-
return /* @__PURE__ */
|
|
981
|
+
return /* @__PURE__ */ jsxDEV3("div", {
|
|
402
982
|
className: "space-y-6",
|
|
403
983
|
children: [
|
|
404
|
-
/* @__PURE__ */
|
|
984
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
405
985
|
className: "flex items-center justify-between",
|
|
406
986
|
children: [
|
|
407
|
-
/* @__PURE__ */
|
|
408
|
-
className: "text-2xl
|
|
987
|
+
/* @__PURE__ */ jsxDEV3("h2", {
|
|
988
|
+
className: "font-bold text-2xl",
|
|
409
989
|
children: "Analytics Dashboard"
|
|
410
990
|
}, undefined, false, undefined, this),
|
|
411
|
-
/* @__PURE__ */
|
|
991
|
+
/* @__PURE__ */ jsxDEV3(Button, {
|
|
412
992
|
onClick: () => alert("Create dashboard modal"),
|
|
413
993
|
children: [
|
|
414
|
-
/* @__PURE__ */
|
|
994
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
415
995
|
className: "mr-2",
|
|
416
996
|
children: "+"
|
|
417
997
|
}, undefined, false, undefined, this),
|
|
@@ -420,55 +1000,55 @@ function AnalyticsDashboard() {
|
|
|
420
1000
|
}, undefined, true, undefined, this)
|
|
421
1001
|
]
|
|
422
1002
|
}, undefined, true, undefined, this),
|
|
423
|
-
/* @__PURE__ */
|
|
1003
|
+
/* @__PURE__ */ jsxDEV3(StatCardGroup, {
|
|
424
1004
|
children: [
|
|
425
|
-
/* @__PURE__ */
|
|
1005
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
426
1006
|
label: "Dashboards",
|
|
427
1007
|
value: stats.totalDashboards,
|
|
428
1008
|
hint: `${stats.publishedDashboards} published`
|
|
429
1009
|
}, undefined, false, undefined, this),
|
|
430
|
-
/* @__PURE__ */
|
|
1010
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
431
1011
|
label: "Queries",
|
|
432
1012
|
value: stats.totalQueries,
|
|
433
1013
|
hint: `${stats.sharedQueries} shared`
|
|
434
1014
|
}, undefined, false, undefined, this),
|
|
435
|
-
/* @__PURE__ */
|
|
1015
|
+
/* @__PURE__ */ jsxDEV3(StatCard, {
|
|
436
1016
|
label: "Widgets",
|
|
437
1017
|
value: widgets.length,
|
|
438
1018
|
hint: "on current dashboard"
|
|
439
1019
|
}, undefined, false, undefined, this)
|
|
440
1020
|
]
|
|
441
1021
|
}, undefined, true, undefined, this),
|
|
442
|
-
/* @__PURE__ */
|
|
443
|
-
className: "
|
|
1022
|
+
/* @__PURE__ */ jsxDEV3("nav", {
|
|
1023
|
+
className: "flex gap-1 rounded-lg bg-muted p-1",
|
|
444
1024
|
role: "tablist",
|
|
445
|
-
children: tabs.map((tab) => /* @__PURE__ */
|
|
1025
|
+
children: tabs.map((tab) => /* @__PURE__ */ jsxDEV3(Button, {
|
|
446
1026
|
type: "button",
|
|
447
1027
|
role: "tab",
|
|
448
1028
|
"aria-selected": activeTab === tab.id,
|
|
449
1029
|
onClick: () => setActiveTab(tab.id),
|
|
450
|
-
className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 text-sm
|
|
1030
|
+
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
1031
|
children: [
|
|
452
|
-
/* @__PURE__ */
|
|
1032
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
453
1033
|
children: tab.icon
|
|
454
1034
|
}, undefined, false, undefined, this),
|
|
455
1035
|
tab.label
|
|
456
1036
|
]
|
|
457
1037
|
}, tab.id, true, undefined, this))
|
|
458
1038
|
}, undefined, false, undefined, this),
|
|
459
|
-
/* @__PURE__ */
|
|
1039
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
460
1040
|
className: "min-h-[400px]",
|
|
461
1041
|
role: "tabpanel",
|
|
462
1042
|
children: [
|
|
463
|
-
activeTab === "dashboards" && /* @__PURE__ */
|
|
1043
|
+
activeTab === "dashboards" && /* @__PURE__ */ jsxDEV3("div", {
|
|
464
1044
|
className: "space-y-6",
|
|
465
1045
|
children: [
|
|
466
|
-
/* @__PURE__ */
|
|
1046
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
467
1047
|
className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
468
1048
|
children: [
|
|
469
|
-
dashboards.map((dashboard) => /* @__PURE__ */
|
|
1049
|
+
dashboards.map((dashboard) => /* @__PURE__ */ jsxDEV3("div", {
|
|
470
1050
|
onClick: () => selectDashboard(dashboard),
|
|
471
|
-
className: `
|
|
1051
|
+
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
1052
|
role: "button",
|
|
473
1053
|
tabIndex: 0,
|
|
474
1054
|
onKeyDown: (e) => {
|
|
@@ -476,33 +1056,33 @@ function AnalyticsDashboard() {
|
|
|
476
1056
|
selectDashboard(dashboard);
|
|
477
1057
|
},
|
|
478
1058
|
children: [
|
|
479
|
-
/* @__PURE__ */
|
|
1059
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
480
1060
|
className: "mb-2 flex items-center justify-between",
|
|
481
1061
|
children: [
|
|
482
|
-
/* @__PURE__ */
|
|
1062
|
+
/* @__PURE__ */ jsxDEV3("h3", {
|
|
483
1063
|
className: "font-medium",
|
|
484
1064
|
children: dashboard.name
|
|
485
1065
|
}, undefined, false, undefined, this),
|
|
486
|
-
/* @__PURE__ */
|
|
487
|
-
className: `inline-flex rounded-full px-2 py-0.5 text-xs
|
|
1066
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
1067
|
+
className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${STATUS_COLORS[dashboard.status] ?? ""}`,
|
|
488
1068
|
children: dashboard.status
|
|
489
1069
|
}, undefined, false, undefined, this)
|
|
490
1070
|
]
|
|
491
1071
|
}, undefined, true, undefined, this),
|
|
492
|
-
/* @__PURE__ */
|
|
493
|
-
className: "text-muted-foreground
|
|
1072
|
+
/* @__PURE__ */ jsxDEV3("p", {
|
|
1073
|
+
className: "mb-3 text-muted-foreground text-sm",
|
|
494
1074
|
children: dashboard.description
|
|
495
1075
|
}, undefined, false, undefined, this),
|
|
496
|
-
/* @__PURE__ */
|
|
497
|
-
className: "
|
|
1076
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
1077
|
+
className: "flex items-center justify-between text-muted-foreground text-xs",
|
|
498
1078
|
children: [
|
|
499
|
-
/* @__PURE__ */
|
|
1079
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
500
1080
|
children: [
|
|
501
1081
|
"/",
|
|
502
1082
|
dashboard.slug
|
|
503
1083
|
]
|
|
504
1084
|
}, undefined, true, undefined, this),
|
|
505
|
-
dashboard.isPublic && /* @__PURE__ */
|
|
1085
|
+
dashboard.isPublic && /* @__PURE__ */ jsxDEV3("span", {
|
|
506
1086
|
className: "text-green-600 dark:text-green-400",
|
|
507
1087
|
children: "\uD83C\uDF10 Public"
|
|
508
1088
|
}, undefined, false, undefined, this)
|
|
@@ -510,149 +1090,20 @@ function AnalyticsDashboard() {
|
|
|
510
1090
|
}, undefined, true, undefined, this)
|
|
511
1091
|
]
|
|
512
1092
|
}, dashboard.id, true, undefined, this)),
|
|
513
|
-
dashboards.length === 0 && /* @__PURE__ */
|
|
514
|
-
className: "
|
|
1093
|
+
dashboards.length === 0 && /* @__PURE__ */ jsxDEV3("div", {
|
|
1094
|
+
className: "col-span-full flex h-64 items-center justify-center text-muted-foreground",
|
|
515
1095
|
children: "No dashboards created yet"
|
|
516
1096
|
}, undefined, false, undefined, this)
|
|
517
1097
|
]
|
|
518
1098
|
}, 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)
|
|
1099
|
+
selectedDashboard ? /* @__PURE__ */ jsxDEV3(AnalyticsWidgetBoard, {
|
|
1100
|
+
dashboardName: selectedDashboard.name,
|
|
1101
|
+
widgets: resolvedWidgets
|
|
1102
|
+
}, undefined, false, undefined, this) : null
|
|
570
1103
|
]
|
|
571
1104
|
}, 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)
|
|
1105
|
+
activeTab === "queries" && /* @__PURE__ */ jsxDEV3(AnalyticsQueriesTable, {
|
|
1106
|
+
queries
|
|
656
1107
|
}, undefined, false, undefined, this)
|
|
657
1108
|
]
|
|
658
1109
|
}, undefined, true, undefined, this)
|
|
@@ -662,6 +1113,168 @@ function AnalyticsDashboard() {
|
|
|
662
1113
|
|
|
663
1114
|
// src/ui/hooks/index.ts
|
|
664
1115
|
"use client";
|
|
1116
|
+
|
|
1117
|
+
// src/ui/renderers/analytics.markdown.ts
|
|
1118
|
+
var mockDashboards = [
|
|
1119
|
+
{
|
|
1120
|
+
id: "dash-1",
|
|
1121
|
+
name: "Sales Overview",
|
|
1122
|
+
slug: "sales-overview",
|
|
1123
|
+
status: "PUBLISHED",
|
|
1124
|
+
widgetCount: 11,
|
|
1125
|
+
viewCount: 1250,
|
|
1126
|
+
lastViewedAt: "2026-03-18T12:00:00Z"
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
id: "dash-2",
|
|
1130
|
+
name: "User Engagement",
|
|
1131
|
+
slug: "user-engagement",
|
|
1132
|
+
status: "PUBLISHED",
|
|
1133
|
+
widgetCount: 8,
|
|
1134
|
+
viewCount: 890,
|
|
1135
|
+
lastViewedAt: "2026-03-18T10:00:00Z"
|
|
1136
|
+
}
|
|
1137
|
+
];
|
|
1138
|
+
var mockQueries = [
|
|
1139
|
+
{
|
|
1140
|
+
id: "q-1",
|
|
1141
|
+
name: "Monthly Revenue",
|
|
1142
|
+
type: "AGGREGATION",
|
|
1143
|
+
isShared: true,
|
|
1144
|
+
executionCount: 1500
|
|
1145
|
+
},
|
|
1146
|
+
{
|
|
1147
|
+
id: "q-2",
|
|
1148
|
+
name: "User Growth",
|
|
1149
|
+
type: "METRIC",
|
|
1150
|
+
isShared: true,
|
|
1151
|
+
executionCount: 890
|
|
1152
|
+
},
|
|
1153
|
+
{
|
|
1154
|
+
id: "q-3",
|
|
1155
|
+
name: "Product Sales",
|
|
1156
|
+
type: "SQL",
|
|
1157
|
+
isShared: false,
|
|
1158
|
+
executionCount: 340
|
|
1159
|
+
},
|
|
1160
|
+
{
|
|
1161
|
+
id: "q-4",
|
|
1162
|
+
name: "Conversion Funnel",
|
|
1163
|
+
type: "AGGREGATION",
|
|
1164
|
+
isShared: true,
|
|
1165
|
+
executionCount: 450
|
|
1166
|
+
}
|
|
1167
|
+
];
|
|
1168
|
+
function dashboardWidgets(dashboardId) {
|
|
1169
|
+
return createExampleWidgets(dashboardId).map((widget2) => resolveAnalyticsWidget(widget2)).filter((widget2) => Boolean(widget2));
|
|
1170
|
+
}
|
|
1171
|
+
var analyticsDashboardMarkdownRenderer = {
|
|
1172
|
+
target: "markdown",
|
|
1173
|
+
render: async (desc) => {
|
|
1174
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "AnalyticsDashboard") {
|
|
1175
|
+
throw new Error("analyticsDashboardMarkdownRenderer: not AnalyticsDashboard");
|
|
1176
|
+
}
|
|
1177
|
+
const dashboard = mockDashboards[0];
|
|
1178
|
+
if (!dashboard) {
|
|
1179
|
+
return {
|
|
1180
|
+
mimeType: "text/markdown",
|
|
1181
|
+
body: `# No Dashboards
|
|
1182
|
+
|
|
1183
|
+
No dashboards available.`
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
const widgets = dashboardWidgets(dashboard.id);
|
|
1187
|
+
const metricWidgets = widgets.filter((widget2) => widget2.bindings[0]?.spec.visualization.kind === "metric");
|
|
1188
|
+
const lines = [
|
|
1189
|
+
`# ${dashboard.name}`,
|
|
1190
|
+
"",
|
|
1191
|
+
"> Contract-backed analytics dashboard overview.",
|
|
1192
|
+
"",
|
|
1193
|
+
"## Key Metrics",
|
|
1194
|
+
""
|
|
1195
|
+
];
|
|
1196
|
+
for (const widget2 of metricWidgets) {
|
|
1197
|
+
const binding2 = widget2.bindings[0];
|
|
1198
|
+
if (!binding2)
|
|
1199
|
+
continue;
|
|
1200
|
+
lines.push(`- **${widget2.name}** via \`${binding2.spec.meta.key}\``);
|
|
1201
|
+
}
|
|
1202
|
+
lines.push("");
|
|
1203
|
+
lines.push("## Visual Blocks");
|
|
1204
|
+
lines.push("");
|
|
1205
|
+
for (const widget2 of widgets) {
|
|
1206
|
+
const kinds = widget2.bindings.map((binding2) => binding2.spec.visualization.kind).join(", ");
|
|
1207
|
+
lines.push(`- **${widget2.name}** (${widget2.layout}) → ${kinds}`);
|
|
1208
|
+
}
|
|
1209
|
+
lines.push("");
|
|
1210
|
+
lines.push("## Dashboard Stats");
|
|
1211
|
+
lines.push("");
|
|
1212
|
+
lines.push("| Metric | Value |");
|
|
1213
|
+
lines.push("|--------|-------|");
|
|
1214
|
+
lines.push(`| Total Dashboards | ${mockDashboards.length} |`);
|
|
1215
|
+
lines.push(`| Published | ${mockDashboards.filter((item) => item.status === "PUBLISHED").length} |`);
|
|
1216
|
+
lines.push(`| Shared Queries | ${mockQueries.filter((query) => query.isShared).length} |`);
|
|
1217
|
+
return {
|
|
1218
|
+
mimeType: "text/markdown",
|
|
1219
|
+
body: lines.join(`
|
|
1220
|
+
`)
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
var dashboardListMarkdownRenderer = {
|
|
1225
|
+
target: "markdown",
|
|
1226
|
+
render: async (desc) => {
|
|
1227
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "DashboardList") {
|
|
1228
|
+
throw new Error("dashboardListMarkdownRenderer: not DashboardList");
|
|
1229
|
+
}
|
|
1230
|
+
const lines = [
|
|
1231
|
+
"# Dashboards",
|
|
1232
|
+
"",
|
|
1233
|
+
"> Browse and manage analytics dashboards",
|
|
1234
|
+
"",
|
|
1235
|
+
"| Dashboard | Widgets | Views | Status | Last Viewed |",
|
|
1236
|
+
"|-----------|---------|-------|--------|-------------|"
|
|
1237
|
+
];
|
|
1238
|
+
for (const dashboard of mockDashboards) {
|
|
1239
|
+
const lastViewed = dashboard.lastViewedAt ? new Date(dashboard.lastViewedAt).toLocaleDateString() : "Never";
|
|
1240
|
+
const statusIcon = dashboard.status === "PUBLISHED" ? "\uD83D\uDFE2" : "⚫";
|
|
1241
|
+
lines.push(`| [${dashboard.name}](/dashboards/${dashboard.slug}) | ${dashboard.widgetCount} | ${dashboard.viewCount.toLocaleString()} | ${statusIcon} ${dashboard.status} | ${lastViewed} |`);
|
|
1242
|
+
}
|
|
1243
|
+
return {
|
|
1244
|
+
mimeType: "text/markdown",
|
|
1245
|
+
body: lines.join(`
|
|
1246
|
+
`)
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
};
|
|
1250
|
+
var queryBuilderMarkdownRenderer = {
|
|
1251
|
+
target: "markdown",
|
|
1252
|
+
render: async (desc) => {
|
|
1253
|
+
if (desc.source.type !== "component" || desc.source.componentKey !== "QueryBuilder") {
|
|
1254
|
+
throw new Error("queryBuilderMarkdownRenderer: not QueryBuilder");
|
|
1255
|
+
}
|
|
1256
|
+
const lines = [
|
|
1257
|
+
"# Query Builder",
|
|
1258
|
+
"",
|
|
1259
|
+
"> Create and manage reusable data queries.",
|
|
1260
|
+
"",
|
|
1261
|
+
"| Query | Type | Shared | Executions |",
|
|
1262
|
+
"|-------|------|--------|------------|"
|
|
1263
|
+
];
|
|
1264
|
+
for (const query of mockQueries) {
|
|
1265
|
+
lines.push(`| ${query.name} | ${query.type} | ${query.isShared ? "\uD83C\uDF10" : "\uD83D\uDD12"} | ${query.executionCount.toLocaleString()} |`);
|
|
1266
|
+
}
|
|
1267
|
+
lines.push("");
|
|
1268
|
+
lines.push("## Visualization Contracts");
|
|
1269
|
+
lines.push("");
|
|
1270
|
+
lines.push("Widgets reference `VisualizationSpec` contracts instead of rendering ad-hoc widget types.");
|
|
1271
|
+
return {
|
|
1272
|
+
mimeType: "text/markdown",
|
|
1273
|
+
body: lines.join(`
|
|
1274
|
+
`)
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
665
1278
|
export {
|
|
666
1279
|
useAnalyticsData,
|
|
667
1280
|
queryBuilderMarkdownRenderer,
|