@altertable/data-app-examples 0.77.0 → 0.78.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.
Files changed (34) hide show
  1. package/package.json +1 -1
  2. package/templates/starter-data-app/index.tsx +681 -134
  3. package/templates/starter-finding-data-app/index.tsx +382 -98
  4. package/templates/starter-local-data-app/AGENTS.md +9 -9
  5. package/templates/starter-local-data-app/README.md +14 -5
  6. package/templates/starter-local-data-app/app.ts +256 -21
  7. package/templates/starter-local-data-app/package.json +5 -5
  8. package/templates/starter-local-data-app/src/App.tsx +276 -5
  9. package/templates/starter-local-data-app/src/data-context.ts +28 -14
  10. package/templates/starter-local-data-app/src/filters.ts +35 -0
  11. package/templates/starter-local-data-app/src/main.tsx +3 -3
  12. package/templates/starter-local-data-app/src/operations.ts +129 -4
  13. package/templates/starter-local-data-app/src/server.ts +1 -2
  14. package/templates/starter-local-finding-data-app/AGENTS.md +1 -1
  15. package/templates/starter-local-finding-data-app/README.md +3 -4
  16. package/templates/starter-local-finding-data-app/app.ts +29 -11
  17. package/templates/starter-local-finding-data-app/package.json +5 -5
  18. package/templates/starter-local-finding-data-app/src/App.tsx +241 -44
  19. package/templates/starter-local-finding-data-app/src/data-context.ts +17 -8
  20. package/templates/starter-local-finding-data-app/src/filters.ts +29 -11
  21. package/templates/starter-local-finding-data-app/src/main.tsx +3 -3
  22. package/templates/starter-local-finding-data-app/src/operations.ts +80 -34
  23. package/templates/starter-local-finding-data-app/src/server.ts +4 -2
  24. package/templates/starter-local-metric-data-app/AGENTS.md +1 -1
  25. package/templates/starter-local-metric-data-app/README.md +3 -4
  26. package/templates/starter-local-metric-data-app/app.ts +5 -2
  27. package/templates/starter-local-metric-data-app/package.json +5 -5
  28. package/templates/starter-local-metric-data-app/src/App.tsx +21 -22
  29. package/templates/starter-local-metric-data-app/src/data-context.ts +9 -5
  30. package/templates/starter-local-metric-data-app/src/filters.ts +1 -3
  31. package/templates/starter-local-metric-data-app/src/main.tsx +3 -3
  32. package/templates/starter-local-metric-data-app/src/operations.ts +3 -3
  33. package/templates/starter-local-metric-data-app/src/server.ts +4 -2
  34. package/templates/starter-metric-data-app/index.tsx +34 -34
@@ -1,7 +1,7 @@
1
1
  # Local data app starter
2
2
 
3
3
  Use `node_modules/@altertable/data-app/docs/app-authoring.md` for this SDK version.
4
- Otherwise, read the [version-matched authoring recipe](https://github.com/altertable-ai/data-app/blob/v0.77.0/docs/app-authoring.md). <!-- x-release-please-version -->
4
+ Otherwise, read the [version-matched authoring recipe](https://github.com/altertable-ai/data-app/blob/v0.78.0/docs/app-authoring.md). <!-- x-release-please-version -->
5
5
  See [AGENTS.md](AGENTS.md) for app-owned files.
6
6
 
7
7
  ## Run the app
@@ -21,17 +21,26 @@ Open <http://127.0.0.1:25837>. Alternatively, configure
21
21
  `ALTERTABLE_DATA_PROXY_URL` and `ALTERTABLE_DATA_PROXY_TOKEN` for an existing
22
22
  CLI proxy. Missing credentials stop startup.
23
23
 
24
+ ## Explore the example
25
+
26
+ Choose a billing month and customer to explore the fictional cost dashboard.
27
+ Compare weekly allocations, switch the cost breakdown between services and
28
+ customers, and inspect the service mix for each customer. Select a service to see
29
+ its contributing customer allocations. Widget inspection exposes the registered
30
+ query, selected parameters, and cost definitions. All views use the same scope;
31
+ weekly batches, customer allocations, and services reconcile to the total.
32
+ Logging demonstrates a recorded zero.
33
+
24
34
  ## Build the app
25
35
 
26
- Replace the connectivity check with bounded operations, views, and the content
27
- specified by the app brief. Change identity, appearance, and queries in `app.ts`.
36
+ Use inspected source data to answer the app brief. Replace the sample queries
37
+ and views, and set identity and appearance in `app.ts`.
28
38
 
29
39
  ```fish
30
40
  bun run check
31
41
  ```
32
42
 
33
- `bun run check` includes the build, which writes browser assets to `dist/`. Hosting them requires an authorized
34
- `/api/data` backend; the local adapter does not authenticate hosted viewers.
43
+ `bun run check` includes the build, which writes browser assets to `dist/`. Hosted apps require an authorized query bridge; the local adapter does not authenticate hosted viewers.
35
44
 
36
45
  ## License
37
46
 
@@ -1,28 +1,263 @@
1
1
  import { defineDataApp } from '@altertable/data-app';
2
2
 
3
3
  export const dataApp = defineDataApp({
4
- title: 'Getting started',
5
- description: 'Check your lakehouse connection, then build an exploration.',
6
- scope: {
7
- organization: 'Your organization',
8
- environment: 'your environment',
9
- },
10
- appearance: {
11
- theme: 'light',
12
- baseColor: 'neutral',
13
- density: 'comfortable',
14
- cornerRadius: 'medium',
15
- elevation: 'subtle',
16
- typography: {
17
- body: 'system',
18
- heading: 'system',
19
- },
20
- },
4
+ // Replace the demo title, description, and scope labels with the app's identity.
5
+ title: 'Infrastructure costs',
6
+ description: 'USD · Fictional weekly allocations',
7
+ scope: { organization: 'demo', environment: 'sample' },
8
+ appearance: { theme: 'system' },
21
9
  queries: {
22
- connection: {
23
- projections: { connection_check: { type: 'number' } },
24
- statement: 'SELECT 1 AS connection_check',
25
- params: {},
10
+ costBreakdown: {
11
+ projections: {
12
+ member_name: { type: 'string' },
13
+ cost_cents: { type: 'number' },
14
+ },
15
+ statement: `
16
+ WITH infrastructure_costs(month, service_name, customer_name, week_1, week_2, week_3, week_4) AS (
17
+ -- Fictional allocation batches in integer cents.
18
+ -- Replace this CTE with verified billing data.
19
+ VALUES
20
+ ('2026-09', 'Compute', 'Atlas', 84000, 126000, 84000, 126000),
21
+ ('2026-09', 'Compute', 'Beacon', 42000, 63000, 42000, 63000),
22
+ ('2026-09', 'Compute', 'Cedar', 18000, 27000, 18000, 27000),
23
+ ('2026-09', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
24
+ ('2026-09', 'Storage', 'Beacon', 84000, 56000, 84000, 56000),
25
+ ('2026-09', 'Storage', 'Cedar', 36000, 24000, 36000, 24000),
26
+ ('2026-09', 'Networking', 'Atlas', 3000, 6000, 9000, 12000),
27
+ ('2026-09', 'Networking', 'Beacon', 6000, 12000, 18000, 24000),
28
+ ('2026-09', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
29
+ ('2026-09', 'Logging', 'Atlas', 0, 0, 0, 0),
30
+ ('2026-09', 'Logging', 'Beacon', 0, 0, 0, 0),
31
+ ('2026-09', 'Logging', 'Cedar', 0, 0, 0, 0),
32
+ ('2026-08', 'Compute', 'Atlas', 76000, 114000, 76000, 114000),
33
+ ('2026-08', 'Compute', 'Beacon', 40000, 60000, 40000, 60000),
34
+ ('2026-08', 'Compute', 'Cedar', 16000, 24000, 16000, 24000),
35
+ ('2026-08', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
36
+ ('2026-08', 'Storage', 'Beacon', 75000, 50000, 75000, 50000),
37
+ ('2026-08', 'Storage', 'Cedar', 33000, 22000, 33000, 22000),
38
+ ('2026-08', 'Networking', 'Atlas', 2000, 4000, 6000, 8000),
39
+ ('2026-08', 'Networking', 'Beacon', 5000, 10000, 15000, 20000),
40
+ ('2026-08', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
41
+ ('2026-08', 'Logging', 'Atlas', 0, 0, 0, 0),
42
+ ('2026-08', 'Logging', 'Beacon', 0, 0, 0, 0),
43
+ ('2026-08', 'Logging', 'Cedar', 0, 0, 0, 0)
44
+ ),
45
+ selected_costs AS (
46
+ SELECT service_name, customer_name,
47
+ week_1 + week_2 + week_3 + week_4 AS cost_cents
48
+ FROM infrastructure_costs
49
+ WHERE month = $month AND ($customerName = '' OR customer_name = $customerName)
50
+ )
51
+ SELECT CASE WHEN $breakdown = 'service' THEN service_name ELSE customer_name END AS member_name,
52
+ CAST(SUM(cost_cents) AS BIGINT) AS cost_cents
53
+ FROM selected_costs GROUP BY member_name
54
+ ORDER BY cost_cents DESC, member_name LIMIT $limit`,
55
+ params: {
56
+ month: { type: 'string', defaultValue: '2026-09' },
57
+ customerName: { type: 'string', defaultValue: '' },
58
+ breakdown: { type: 'string', defaultValue: 'service' },
59
+ limit: { type: 'number', defaultValue: 10 },
60
+ },
61
+ },
62
+ totalCost: {
63
+ projections: {
64
+ cost_cents: { type: 'number' },
65
+ customer_count: { type: 'number' },
66
+ },
67
+ statement: `
68
+ WITH infrastructure_costs(month, service_name, customer_name, week_1, week_2, week_3, week_4) AS (
69
+ -- Fictional allocation batches in integer cents.
70
+ -- Replace this CTE with verified billing data.
71
+ VALUES
72
+ ('2026-09', 'Compute', 'Atlas', 84000, 126000, 84000, 126000),
73
+ ('2026-09', 'Compute', 'Beacon', 42000, 63000, 42000, 63000),
74
+ ('2026-09', 'Compute', 'Cedar', 18000, 27000, 18000, 27000),
75
+ ('2026-09', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
76
+ ('2026-09', 'Storage', 'Beacon', 84000, 56000, 84000, 56000),
77
+ ('2026-09', 'Storage', 'Cedar', 36000, 24000, 36000, 24000),
78
+ ('2026-09', 'Networking', 'Atlas', 3000, 6000, 9000, 12000),
79
+ ('2026-09', 'Networking', 'Beacon', 6000, 12000, 18000, 24000),
80
+ ('2026-09', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
81
+ ('2026-09', 'Logging', 'Atlas', 0, 0, 0, 0),
82
+ ('2026-09', 'Logging', 'Beacon', 0, 0, 0, 0),
83
+ ('2026-09', 'Logging', 'Cedar', 0, 0, 0, 0),
84
+ ('2026-08', 'Compute', 'Atlas', 76000, 114000, 76000, 114000),
85
+ ('2026-08', 'Compute', 'Beacon', 40000, 60000, 40000, 60000),
86
+ ('2026-08', 'Compute', 'Cedar', 16000, 24000, 16000, 24000),
87
+ ('2026-08', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
88
+ ('2026-08', 'Storage', 'Beacon', 75000, 50000, 75000, 50000),
89
+ ('2026-08', 'Storage', 'Cedar', 33000, 22000, 33000, 22000),
90
+ ('2026-08', 'Networking', 'Atlas', 2000, 4000, 6000, 8000),
91
+ ('2026-08', 'Networking', 'Beacon', 5000, 10000, 15000, 20000),
92
+ ('2026-08', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
93
+ ('2026-08', 'Logging', 'Atlas', 0, 0, 0, 0),
94
+ ('2026-08', 'Logging', 'Beacon', 0, 0, 0, 0),
95
+ ('2026-08', 'Logging', 'Cedar', 0, 0, 0, 0)
96
+ ),
97
+ selected_costs AS (
98
+ SELECT service_name, customer_name,
99
+ week_1 + week_2 + week_3 + week_4 AS cost_cents
100
+ FROM infrastructure_costs
101
+ WHERE month = $month AND ($customerName = '' OR customer_name = $customerName)
102
+ )
103
+ SELECT CAST(SUM(cost_cents) AS BIGINT) AS cost_cents,
104
+ COUNT(DISTINCT customer_name) AS customer_count
105
+ FROM selected_costs HAVING COUNT(*) > 0`,
106
+ params: {
107
+ month: { type: 'string', defaultValue: '2026-09' },
108
+ customerName: { type: 'string', defaultValue: '' },
109
+ },
110
+ },
111
+ costsByCustomer: {
112
+ projections: {
113
+ customer_name: { type: 'string' },
114
+ cost_cents: { type: 'number' },
115
+ },
116
+ statement: `
117
+ WITH infrastructure_costs(month, service_name, customer_name, week_1, week_2, week_3, week_4) AS (
118
+ -- Fictional allocation batches in integer cents.
119
+ -- Replace this CTE with verified billing data.
120
+ VALUES
121
+ ('2026-09', 'Compute', 'Atlas', 84000, 126000, 84000, 126000),
122
+ ('2026-09', 'Compute', 'Beacon', 42000, 63000, 42000, 63000),
123
+ ('2026-09', 'Compute', 'Cedar', 18000, 27000, 18000, 27000),
124
+ ('2026-09', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
125
+ ('2026-09', 'Storage', 'Beacon', 84000, 56000, 84000, 56000),
126
+ ('2026-09', 'Storage', 'Cedar', 36000, 24000, 36000, 24000),
127
+ ('2026-09', 'Networking', 'Atlas', 3000, 6000, 9000, 12000),
128
+ ('2026-09', 'Networking', 'Beacon', 6000, 12000, 18000, 24000),
129
+ ('2026-09', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
130
+ ('2026-09', 'Logging', 'Atlas', 0, 0, 0, 0),
131
+ ('2026-09', 'Logging', 'Beacon', 0, 0, 0, 0),
132
+ ('2026-09', 'Logging', 'Cedar', 0, 0, 0, 0),
133
+ ('2026-08', 'Compute', 'Atlas', 76000, 114000, 76000, 114000),
134
+ ('2026-08', 'Compute', 'Beacon', 40000, 60000, 40000, 60000),
135
+ ('2026-08', 'Compute', 'Cedar', 16000, 24000, 16000, 24000),
136
+ ('2026-08', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
137
+ ('2026-08', 'Storage', 'Beacon', 75000, 50000, 75000, 50000),
138
+ ('2026-08', 'Storage', 'Cedar', 33000, 22000, 33000, 22000),
139
+ ('2026-08', 'Networking', 'Atlas', 2000, 4000, 6000, 8000),
140
+ ('2026-08', 'Networking', 'Beacon', 5000, 10000, 15000, 20000),
141
+ ('2026-08', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
142
+ ('2026-08', 'Logging', 'Atlas', 0, 0, 0, 0),
143
+ ('2026-08', 'Logging', 'Beacon', 0, 0, 0, 0),
144
+ ('2026-08', 'Logging', 'Cedar', 0, 0, 0, 0)
145
+ ),
146
+ selected_costs AS (
147
+ SELECT service_name, customer_name,
148
+ week_1 + week_2 + week_3 + week_4 AS cost_cents
149
+ FROM infrastructure_costs
150
+ WHERE month = $month AND ($customerName = '' OR customer_name = $customerName)
151
+ )
152
+ SELECT customer_name, CAST(SUM(cost_cents) AS BIGINT) AS cost_cents
153
+ FROM selected_costs WHERE service_name = $serviceName
154
+ GROUP BY customer_name ORDER BY cost_cents DESC, customer_name LIMIT $limit`,
155
+ params: {
156
+ month: { type: 'string', defaultValue: '2026-09' },
157
+ customerName: { type: 'string', defaultValue: '' },
158
+ serviceName: { type: 'string' },
159
+ limit: { type: 'number', defaultValue: 10 },
160
+ },
161
+ },
162
+ costTrend: {
163
+ projections: {
164
+ period_start: { type: 'string' },
165
+ cost_cents: { type: 'number' },
166
+ },
167
+ statement: `
168
+ WITH infrastructure_costs(month, service_name, customer_name, week_1, week_2, week_3, week_4) AS (
169
+ -- Fictional allocation batches in integer cents.
170
+ -- Replace this CTE with verified billing data.
171
+ VALUES
172
+ ('2026-09', 'Compute', 'Atlas', 84000, 126000, 84000, 126000),
173
+ ('2026-09', 'Compute', 'Beacon', 42000, 63000, 42000, 63000),
174
+ ('2026-09', 'Compute', 'Cedar', 18000, 27000, 18000, 27000),
175
+ ('2026-09', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
176
+ ('2026-09', 'Storage', 'Beacon', 84000, 56000, 84000, 56000),
177
+ ('2026-09', 'Storage', 'Cedar', 36000, 24000, 36000, 24000),
178
+ ('2026-09', 'Networking', 'Atlas', 3000, 6000, 9000, 12000),
179
+ ('2026-09', 'Networking', 'Beacon', 6000, 12000, 18000, 24000),
180
+ ('2026-09', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
181
+ ('2026-09', 'Logging', 'Atlas', 0, 0, 0, 0),
182
+ ('2026-09', 'Logging', 'Beacon', 0, 0, 0, 0),
183
+ ('2026-09', 'Logging', 'Cedar', 0, 0, 0, 0),
184
+ ('2026-08', 'Compute', 'Atlas', 76000, 114000, 76000, 114000),
185
+ ('2026-08', 'Compute', 'Beacon', 40000, 60000, 40000, 60000),
186
+ ('2026-08', 'Compute', 'Cedar', 16000, 24000, 16000, 24000),
187
+ ('2026-08', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
188
+ ('2026-08', 'Storage', 'Beacon', 75000, 50000, 75000, 50000),
189
+ ('2026-08', 'Storage', 'Cedar', 33000, 22000, 33000, 22000),
190
+ ('2026-08', 'Networking', 'Atlas', 2000, 4000, 6000, 8000),
191
+ ('2026-08', 'Networking', 'Beacon', 5000, 10000, 15000, 20000),
192
+ ('2026-08', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
193
+ ('2026-08', 'Logging', 'Atlas', 0, 0, 0, 0),
194
+ ('2026-08', 'Logging', 'Beacon', 0, 0, 0, 0),
195
+ ('2026-08', 'Logging', 'Cedar', 0, 0, 0, 0)
196
+ ),
197
+ -- The four fictional batch dates match the week_1 through week_4 columns.
198
+ weeks(day) AS (VALUES ('01'), ('08'), ('15'), ('22'))
199
+ SELECT $month || '-' || day AS period_start,
200
+ CAST(SUM(CASE day WHEN '01' THEN week_1 WHEN '08' THEN week_2
201
+ WHEN '15' THEN week_3 ELSE week_4 END) AS BIGINT) AS cost_cents
202
+ FROM infrastructure_costs CROSS JOIN weeks
203
+ WHERE month = $month AND ($customerName = '' OR customer_name = $customerName)
204
+ GROUP BY day ORDER BY day LIMIT $limit`,
205
+ params: {
206
+ month: { type: 'string', defaultValue: '2026-09' },
207
+ customerName: { type: 'string', defaultValue: '' },
208
+ limit: { type: 'number', defaultValue: 10 },
209
+ },
210
+ },
211
+ customerServiceMix: {
212
+ projections: {
213
+ customer_name: { type: 'string' },
214
+ service_name: { type: 'string' },
215
+ cost_cents: { type: 'number' },
216
+ },
217
+ statement: `
218
+ WITH infrastructure_costs(month, service_name, customer_name, week_1, week_2, week_3, week_4) AS (
219
+ -- Fictional allocation batches in integer cents.
220
+ -- Replace this CTE with verified billing data.
221
+ VALUES
222
+ ('2026-09', 'Compute', 'Atlas', 84000, 126000, 84000, 126000),
223
+ ('2026-09', 'Compute', 'Beacon', 42000, 63000, 42000, 63000),
224
+ ('2026-09', 'Compute', 'Cedar', 18000, 27000, 18000, 27000),
225
+ ('2026-09', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
226
+ ('2026-09', 'Storage', 'Beacon', 84000, 56000, 84000, 56000),
227
+ ('2026-09', 'Storage', 'Cedar', 36000, 24000, 36000, 24000),
228
+ ('2026-09', 'Networking', 'Atlas', 3000, 6000, 9000, 12000),
229
+ ('2026-09', 'Networking', 'Beacon', 6000, 12000, 18000, 24000),
230
+ ('2026-09', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
231
+ ('2026-09', 'Logging', 'Atlas', 0, 0, 0, 0),
232
+ ('2026-09', 'Logging', 'Beacon', 0, 0, 0, 0),
233
+ ('2026-09', 'Logging', 'Cedar', 0, 0, 0, 0),
234
+ ('2026-08', 'Compute', 'Atlas', 76000, 114000, 76000, 114000),
235
+ ('2026-08', 'Compute', 'Beacon', 40000, 60000, 40000, 60000),
236
+ ('2026-08', 'Compute', 'Cedar', 16000, 24000, 16000, 24000),
237
+ ('2026-08', 'Storage', 'Atlas', 24000, 16000, 24000, 16000),
238
+ ('2026-08', 'Storage', 'Beacon', 75000, 50000, 75000, 50000),
239
+ ('2026-08', 'Storage', 'Cedar', 33000, 22000, 33000, 22000),
240
+ ('2026-08', 'Networking', 'Atlas', 2000, 4000, 6000, 8000),
241
+ ('2026-08', 'Networking', 'Beacon', 5000, 10000, 15000, 20000),
242
+ ('2026-08', 'Networking', 'Cedar', 3000, 6000, 9000, 12000),
243
+ ('2026-08', 'Logging', 'Atlas', 0, 0, 0, 0),
244
+ ('2026-08', 'Logging', 'Beacon', 0, 0, 0, 0),
245
+ ('2026-08', 'Logging', 'Cedar', 0, 0, 0, 0)
246
+ ),
247
+ selected_costs AS (
248
+ SELECT service_name, customer_name,
249
+ week_1 + week_2 + week_3 + week_4 AS cost_cents
250
+ FROM infrastructure_costs
251
+ WHERE month = $month AND ($customerName = '' OR customer_name = $customerName)
252
+ )
253
+ SELECT customer_name, service_name, CAST(SUM(cost_cents) AS BIGINT) AS cost_cents
254
+ FROM selected_costs GROUP BY customer_name, service_name
255
+ ORDER BY customer_name, service_name LIMIT $limit`,
256
+ params: {
257
+ month: { type: 'string', defaultValue: '2026-09' },
258
+ customerName: { type: 'string', defaultValue: '' },
259
+ limit: { type: 'number', defaultValue: 20 },
260
+ },
26
261
  },
27
262
  },
28
263
  });
@@ -8,18 +8,18 @@
8
8
  },
9
9
  "scripts": {
10
10
  "typecheck": "tsc --noEmit",
11
- "lint": "oxlint --type-aware src",
11
+ "lint": "oxlint --type-aware src app.ts",
12
12
  "format": "oxfmt src app.ts",
13
13
  "format:check": "oxfmt --check src app.ts",
14
14
  "dev": "bun --hot src/server.ts",
15
15
  "build": "bun run typecheck && bun build src/index.html --outdir=dist --production",
16
16
  "check": "bun run lint && bun run format:check && bun run build",
17
- "lint:fix": "oxlint --type-aware --fix src"
17
+ "lint:fix": "oxlint --type-aware --fix src app.ts"
18
18
  },
19
19
  "dependencies": {
20
- "@altertable/data-app": "0.77.0",
21
- "@altertable/data-app-bun": "0.77.0",
22
- "@altertable/data-app-react": "0.77.0",
20
+ "@altertable/data-app": "0.78.0",
21
+ "@altertable/data-app-bun": "0.78.0",
22
+ "@altertable/data-app-react": "0.78.0",
23
23
  "react": "19.3.1",
24
24
  "react-dom": "19.3.1"
25
25
  },
@@ -1,9 +1,280 @@
1
- import { GettingStarted } from '@altertable/data-app-react/ui';
1
+ import {
2
+ createDataHooks,
3
+ DataApp,
4
+ DataSection,
5
+ Grid,
6
+ MetricWidget,
7
+ TableWidget,
8
+ VisualizationWidget,
9
+ Stack,
10
+ } from '@altertable/data-app-react';
11
+ import { BarChart, ComposedChart } from '@altertable/data-app-react/ui';
12
+ import { formatDateRange } from '@altertable/data-app/format';
2
13
 
3
- import { dataContext } from '#app/data-context.ts';
14
+ import { costDataContext } from '#app/data-context.ts';
15
+ import { month } from '#app/filters.ts';
16
+ import { operations } from '#app/operations.ts';
4
17
 
5
- /** Connectivity-only screen. Investigate the requested question, then replace this with a view
6
- * that leads with a supported finding and explores the useful angles behind it. */
18
+ // Fictional charges use USD. Match this format to the real billing currency.
19
+ const costFormat = { kind: 'currency', currency: 'USD' } as const;
20
+ const { defineView, defineDetailView } = createDataHooks(
21
+ operations.createDataClient()
22
+ );
23
+ const emptyFallback = {
24
+ title: 'No allocations',
25
+ description: 'Choose another month or customer.',
26
+ };
27
+ const servicesView = defineView({
28
+ dataContext: costDataContext,
29
+ operation: 'costBreakdown',
30
+ isEmpty: rows => rows.length === 0,
31
+ emptyFallback,
32
+ });
33
+ const serviceCosts = servicesView.dataset({
34
+ name: 'Cost breakdown',
35
+ select: rows => rows,
36
+ rowKey: row => row.memberName,
37
+ columns: {
38
+ memberName: { label: 'Member', value: row => row.memberName },
39
+ cost: { label: 'Cost', value: row => row.cost, format: costFormat },
40
+ },
41
+ evidence: { id: 'cost-breakdown', glossaryIds: ['allocatedCost'] },
42
+ });
43
+ const totalView = defineView({
44
+ dataContext: costDataContext,
45
+ operation: 'totalCost',
46
+ isEmpty: total => total === null,
47
+ emptyFallback: { title: 'No total available' },
48
+ });
49
+ const totalCost = totalView.metric(
50
+ {
51
+ id: 'total-cost',
52
+ glossaryId: 'allocatedCost',
53
+ label: 'Total cost',
54
+ format: costFormat,
55
+ },
56
+ total => {
57
+ if (total === null)
58
+ throw new Error('No allocated total for this selection.');
59
+ return { current: total.cost };
60
+ }
61
+ );
62
+ const customerCount = totalView.metric(
63
+ {
64
+ id: 'customer-count',
65
+ glossaryId: 'customerCount',
66
+ label: 'Customers',
67
+ format: { kind: 'count' },
68
+ },
69
+ total => {
70
+ if (total === null)
71
+ throw new Error('No customer count for this selection.');
72
+ return { current: total.customerCount };
73
+ }
74
+ );
75
+ const averageCost = totalView.metric(
76
+ {
77
+ id: 'average-cost',
78
+ glossaryId: 'averageCustomerCost',
79
+ label: 'Average per customer',
80
+ format: costFormat,
81
+ },
82
+ total => {
83
+ if (total === null) throw new Error('No average cost for this selection.');
84
+ return { current: total.averageCost };
85
+ }
86
+ );
87
+ const totalContent = totalView.content(result => (
88
+ <Grid columns={3}>
89
+ <MetricWidget metric={totalCost} source={result} />
90
+ <MetricWidget metric={customerCount} source={result} />
91
+ <MetricWidget metric={averageCost} source={result} />
92
+ </Grid>
93
+ ));
94
+ const customersView = defineDetailView({
95
+ id: 'service-customers',
96
+ title: 'Customer costs',
97
+ operation: 'costsByCustomer',
98
+ dataContext: costDataContext,
99
+ parseInput: operations.costsByCustomer.input,
100
+ describeInput: input =>
101
+ `${input.serviceName} · ${month.describe?.(input.month)} · USD`,
102
+ isEmpty: rows => rows.length === 0,
103
+ emptyFallback: {
104
+ title: 'No customer allocations',
105
+ description:
106
+ 'No allocations are recorded for this service in the selected month and customer scope.',
107
+ },
108
+ });
109
+ const customerCosts = customersView.dataset({
110
+ name: 'Customer allocations',
111
+ select: rows => rows,
112
+ rowKey: row => row.customerName,
113
+ columns: {
114
+ customerName: { label: 'Customer', value: row => row.customerName },
115
+ cost: { label: 'Cost', value: row => row.cost, format: costFormat },
116
+ },
117
+ evidence: { id: 'costs-by-customer', glossaryIds: ['allocatedCost'] },
118
+ });
119
+ const customersDetail = customersView.content(result => (
120
+ <TableWidget
121
+ dataset={customerCosts}
122
+ source={result}
123
+ title="Cost by customer"
124
+ pagination={false}
125
+ />
126
+ ));
127
+ const serviceActions = serviceCosts.actions(
128
+ action => ({
129
+ customers: action.detail({
130
+ label: 'View customers',
131
+ target: customersView,
132
+ when: row => row.dimension === 'service',
133
+ input: row => ({ serviceName: row.memberName }),
134
+ }),
135
+ }),
136
+ { primary: 'customers' }
137
+ );
138
+ const breakdownContent = servicesView.content(result => {
139
+ const byService = result.loading || result.input.breakdown === 'service';
140
+ return (
141
+ <VisualizationWidget
142
+ dataset={serviceCosts}
143
+ source={result}
144
+ title={byService ? 'Cost by service' : 'Cost by customer'}
145
+ actions={serviceActions}
146
+ breakdown={servicesView.breakdown('breakdown')}
147
+ >
148
+ {(rows, actions) => (
149
+ <BarChart
150
+ ariaLabel={byService ? 'Costs by service' : 'Costs by customer'}
151
+ unit="USD"
152
+ showYAxis
153
+ scrollToEnd={false}
154
+ valueFormat={costFormat}
155
+ items={rows.map(row => ({
156
+ ...row,
157
+ id: row.memberName,
158
+ label: row.memberName,
159
+ value: row.cost,
160
+ }))}
161
+ itemActions={actions}
162
+ />
163
+ )}
164
+ </VisualizationWidget>
165
+ );
166
+ });
167
+ const trendView = defineView({
168
+ dataContext: costDataContext,
169
+ operation: 'costTrend',
170
+ isEmpty: rows => rows.length === 0,
171
+ emptyFallback,
172
+ });
173
+ const weeklyCosts = trendView.dataset({
174
+ name: 'Weekly allocations',
175
+ select: rows => rows,
176
+ rowKey: row => row.periodStart,
177
+ columns: {
178
+ periodStart: { label: 'Allocation date', value: row => row.periodStart },
179
+ cost: { label: 'Cost', value: row => row.cost, format: costFormat },
180
+ },
181
+ evidence: { id: 'cost-trend', glossaryIds: ['allocatedCost'] },
182
+ });
183
+ const trendContent = trendView.content(result => (
184
+ <VisualizationWidget
185
+ dataset={weeklyCosts}
186
+ source={result}
187
+ title="Weekly allocated cost"
188
+ >
189
+ {rows => (
190
+ <ComposedChart
191
+ data={rows}
192
+ ariaLabel="Costs over time"
193
+ valueFormat={costFormat}
194
+ >
195
+ <ComposedChart.XAxis
196
+ dataKey="periodStart"
197
+ tickFormatter={value =>
198
+ formatDateRange({ start: String(value), end: String(value) })
199
+ }
200
+ />
201
+ <ComposedChart.YAxis domain={[0, 'auto']} />
202
+ <ComposedChart.Tooltip />
203
+ <ComposedChart.Line dataKey="cost" name="Allocated cost" />
204
+ </ComposedChart>
205
+ )}
206
+ </VisualizationWidget>
207
+ ));
208
+ const mixView = defineView({
209
+ dataContext: costDataContext,
210
+ operation: 'customerServiceMix',
211
+ isEmpty: rows => rows.length === 0,
212
+ emptyFallback,
213
+ });
214
+ const customerMix = mixView.dataset({
215
+ name: 'Customer service mix',
216
+ select: rows => rows,
217
+ rowKey: row => row.customerName,
218
+ columns: {
219
+ customerName: { label: 'Customer', value: row => row.customerName },
220
+ Compute: { value: row => row.Compute, format: costFormat },
221
+ Storage: { value: row => row.Storage, format: costFormat },
222
+ Networking: { value: row => row.Networking, format: costFormat },
223
+ Logging: { value: row => row.Logging, format: costFormat },
224
+ },
225
+ evidence: { id: 'customer-service-mix', glossaryIds: ['allocatedCost'] },
226
+ });
227
+ const mixContent = mixView.content(result => (
228
+ <VisualizationWidget
229
+ dataset={customerMix}
230
+ source={result}
231
+ title="Service mix by customer"
232
+ >
233
+ {rows => (
234
+ <ComposedChart
235
+ data={rows}
236
+ ariaLabel="Service mix by customer"
237
+ valueFormat={costFormat}
238
+ >
239
+ <ComposedChart.XAxis dataKey="customerName" />
240
+ <ComposedChart.YAxis domain={[0, 'auto']} />
241
+ <ComposedChart.Tooltip />
242
+ <ComposedChart.Legend />
243
+ {/* These service keys must match the columns returned by customerServiceMix. */}
244
+ <ComposedChart.Bar dataKey="Compute" name="Compute" stackId="cost" />
245
+ <ComposedChart.Bar
246
+ dataKey="Storage"
247
+ name="Storage"
248
+ stackId="cost"
249
+ fill="var(--atbl-chart-2)"
250
+ />
251
+ <ComposedChart.Bar
252
+ dataKey="Networking"
253
+ name="Networking"
254
+ stackId="cost"
255
+ fill="var(--atbl-chart-3)"
256
+ />
257
+ <ComposedChart.Bar
258
+ dataKey="Logging"
259
+ name="Logging"
260
+ stackId="cost"
261
+ fill="var(--atbl-chart-4)"
262
+ />
263
+ </ComposedChart>
264
+ )}
265
+ </VisualizationWidget>
266
+ ));
7
267
  export function App() {
8
- return <GettingStarted dataContext={dataContext} />;
268
+ return (
269
+ <DataApp view={servicesView} details={[customersDetail]}>
270
+ <Stack>
271
+ <DataSection content={totalContent} label="Cost summary" />
272
+ <Grid columns={2}>
273
+ <DataSection content={trendContent} label="Cost trend" />
274
+ <DataSection content={breakdownContent} label="Cost overview" />
275
+ </Grid>
276
+ <DataSection content={mixContent} label="Customer composition" />
277
+ </Stack>
278
+ </DataApp>
279
+ );
9
280
  }