@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.
- package/package.json +1 -1
- package/templates/starter-data-app/index.tsx +681 -134
- package/templates/starter-finding-data-app/index.tsx +382 -98
- package/templates/starter-local-data-app/AGENTS.md +9 -9
- package/templates/starter-local-data-app/README.md +14 -5
- package/templates/starter-local-data-app/app.ts +256 -21
- package/templates/starter-local-data-app/package.json +5 -5
- package/templates/starter-local-data-app/src/App.tsx +276 -5
- package/templates/starter-local-data-app/src/data-context.ts +28 -14
- package/templates/starter-local-data-app/src/filters.ts +35 -0
- package/templates/starter-local-data-app/src/main.tsx +3 -3
- package/templates/starter-local-data-app/src/operations.ts +129 -4
- package/templates/starter-local-data-app/src/server.ts +1 -2
- package/templates/starter-local-finding-data-app/AGENTS.md +1 -1
- package/templates/starter-local-finding-data-app/README.md +3 -4
- package/templates/starter-local-finding-data-app/app.ts +29 -11
- package/templates/starter-local-finding-data-app/package.json +5 -5
- package/templates/starter-local-finding-data-app/src/App.tsx +241 -44
- package/templates/starter-local-finding-data-app/src/data-context.ts +17 -8
- package/templates/starter-local-finding-data-app/src/filters.ts +29 -11
- package/templates/starter-local-finding-data-app/src/main.tsx +3 -3
- package/templates/starter-local-finding-data-app/src/operations.ts +80 -34
- package/templates/starter-local-finding-data-app/src/server.ts +4 -2
- package/templates/starter-local-metric-data-app/AGENTS.md +1 -1
- package/templates/starter-local-metric-data-app/README.md +3 -4
- package/templates/starter-local-metric-data-app/app.ts +5 -2
- package/templates/starter-local-metric-data-app/package.json +5 -5
- package/templates/starter-local-metric-data-app/src/App.tsx +21 -22
- package/templates/starter-local-metric-data-app/src/data-context.ts +9 -5
- package/templates/starter-local-metric-data-app/src/filters.ts +1 -3
- package/templates/starter-local-metric-data-app/src/main.tsx +3 -3
- package/templates/starter-local-metric-data-app/src/operations.ts +3 -3
- package/templates/starter-local-metric-data-app/src/server.ts +4 -2
- package/templates/starter-metric-data-app/index.tsx +34 -34
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
import { createDataContext } from '@altertable/data-app-react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { operations } from '#app/operations.ts';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const queryNames = {
|
|
6
|
+
...operations.costBreakdown.queryNames,
|
|
7
|
+
...operations.totalCost.queryNames,
|
|
8
|
+
...operations.costsByCustomer.queryNames,
|
|
9
|
+
...operations.costTrend.queryNames,
|
|
10
|
+
...operations.customerServiceMix.queryNames,
|
|
11
|
+
};
|
|
12
|
+
// Replace these example definitions and coverage with verified source metadata.
|
|
13
|
+
export const costDataContext = createDataContext(queryNames)({
|
|
13
14
|
description:
|
|
14
|
-
'
|
|
15
|
+
'Fictional weekly customer allocations for August and September 2026. Scope filters apply to every chart and its contributing records.',
|
|
15
16
|
glossary: {
|
|
16
|
-
|
|
17
|
-
term: '
|
|
18
|
-
definition:
|
|
19
|
-
|
|
17
|
+
allocatedCost: {
|
|
18
|
+
term: 'Allocated cost',
|
|
19
|
+
definition:
|
|
20
|
+
'USD charges in the selected billing month and customer scope. Four recorded allocation batches, dated the 1st, 8th, 15th and 22nd, sum to each monthly allocation. Customers sum to services; services sum to the total. Zero is a recorded charge of zero.',
|
|
21
|
+
queryNames: Object.values(queryNames),
|
|
22
|
+
},
|
|
23
|
+
customerCount: {
|
|
24
|
+
term: 'Customers',
|
|
25
|
+
definition:
|
|
26
|
+
'Distinct customers with recorded allocations in the selected scope, including recorded zero charges.',
|
|
27
|
+
queryNames: [queryNames.totalCost],
|
|
28
|
+
},
|
|
29
|
+
averageCustomerCost: {
|
|
30
|
+
term: 'Average per customer',
|
|
31
|
+
definition:
|
|
32
|
+
'Total allocated cost divided by the number of distinct customers in the same selected scope, including customers with zero charges.',
|
|
33
|
+
queryNames: [queryNames.totalCost],
|
|
20
34
|
},
|
|
21
35
|
},
|
|
22
36
|
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { choiceFilter, displayChoice } from '@altertable/data-app/contract';
|
|
2
|
+
|
|
3
|
+
// These months match the fictional SQL rows.
|
|
4
|
+
// Replace them with months covered by the billing source.
|
|
5
|
+
export const month = choiceFilter({
|
|
6
|
+
key: 'month',
|
|
7
|
+
label: 'Month',
|
|
8
|
+
defaultValue: '2026-09',
|
|
9
|
+
options: [
|
|
10
|
+
{ id: '2026-09', label: 'September 2026' },
|
|
11
|
+
{ id: '2026-08', label: 'August 2026' },
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
// These customers match the fictional SQL rows.
|
|
15
|
+
// Replace them with customers from the billing source.
|
|
16
|
+
export const customer = choiceFilter({
|
|
17
|
+
key: 'customer',
|
|
18
|
+
label: 'Customer',
|
|
19
|
+
defaultValue: 'all',
|
|
20
|
+
options: [
|
|
21
|
+
{ id: 'all', label: 'All customers' },
|
|
22
|
+
{ id: 'Atlas', label: 'Atlas' },
|
|
23
|
+
{ id: 'Beacon', label: 'Beacon' },
|
|
24
|
+
{ id: 'Cedar', label: 'Cedar' },
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
export const breakdown = displayChoice({
|
|
28
|
+
key: 'breakdown',
|
|
29
|
+
label: 'Breakdown',
|
|
30
|
+
defaultValue: 'service',
|
|
31
|
+
options: [
|
|
32
|
+
{ id: 'service', label: 'Service' },
|
|
33
|
+
{ id: 'customer', label: 'Customer' },
|
|
34
|
+
],
|
|
35
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mountDataApp } from '@altertable/data-app-react';
|
|
2
|
+
import { installLocalQueryLakehouse } from '@altertable/data-app/client';
|
|
2
3
|
|
|
3
4
|
import { App } from '#app/App.tsx';
|
|
4
5
|
import { dataApp } from '#config';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
installLocalQueryLakehouse();
|
|
8
8
|
mountDataApp({ app: dataApp, component: App });
|
|
@@ -1,7 +1,132 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseCount } from '@altertable/data-app/contract';
|
|
2
2
|
|
|
3
|
+
import { month, customer, breakdown } from '#app/filters.ts';
|
|
3
4
|
import { dataApp } from '#config';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
function parseService(value: unknown) {
|
|
7
|
+
if (
|
|
8
|
+
!value ||
|
|
9
|
+
typeof value !== 'object' ||
|
|
10
|
+
Array.isArray(value) ||
|
|
11
|
+
!('serviceName' in value) ||
|
|
12
|
+
typeof value.serviceName !== 'string' ||
|
|
13
|
+
value.serviceName.trim().length === 0 ||
|
|
14
|
+
value.serviceName.length > 100
|
|
15
|
+
)
|
|
16
|
+
throw new Error('Choose a service to inspect its customer costs.');
|
|
17
|
+
return { serviceName: value.serviceName };
|
|
18
|
+
}
|
|
19
|
+
function queryScope(input: { month: string; customer: string }) {
|
|
20
|
+
return {
|
|
21
|
+
month: input.month,
|
|
22
|
+
customerName: input.customer === 'all' ? '' : input.customer,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export const operations = dataApp.defineOperations({
|
|
26
|
+
costBreakdown: dataApp.defineOperation({
|
|
27
|
+
filters: { month, customer, breakdown },
|
|
28
|
+
policy: { maxQueryRows: 10, maxDurationMs: 15000 },
|
|
29
|
+
async run({ query }, input) {
|
|
30
|
+
const result = await query('costBreakdown', {
|
|
31
|
+
...queryScope(input),
|
|
32
|
+
breakdown: input.breakdown,
|
|
33
|
+
});
|
|
34
|
+
return result.rows.map(row => ({
|
|
35
|
+
memberName: row.member_name,
|
|
36
|
+
dimension: input.breakdown,
|
|
37
|
+
cost: parseCount(row.cost_cents) / 100,
|
|
38
|
+
}));
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
totalCost: dataApp.defineOperation({
|
|
42
|
+
filters: { month, customer },
|
|
43
|
+
policy: { maxQueryRows: 1, maxDurationMs: 15000 },
|
|
44
|
+
async run({ query }, input) {
|
|
45
|
+
const result = await query('totalCost', queryScope(input));
|
|
46
|
+
const row = result.rows[0];
|
|
47
|
+
if (!row) return null;
|
|
48
|
+
const cost = parseCount(row.cost_cents) / 100;
|
|
49
|
+
const customerCount = parseCount(row.customer_count);
|
|
50
|
+
if (customerCount === 0)
|
|
51
|
+
throw new Error('Allocations must identify at least one customer.');
|
|
52
|
+
return {
|
|
53
|
+
cost,
|
|
54
|
+
customerCount,
|
|
55
|
+
averageCost: cost / customerCount,
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
costsByCustomer: dataApp.defineOperation({
|
|
60
|
+
filters: { month, customer },
|
|
61
|
+
input: parseService,
|
|
62
|
+
checks: [{ serviceName: 'Compute' }],
|
|
63
|
+
policy: { maxQueryRows: 10, maxDurationMs: 15000 },
|
|
64
|
+
async run({ query }, input) {
|
|
65
|
+
const result = await query('costsByCustomer', {
|
|
66
|
+
...queryScope(input),
|
|
67
|
+
serviceName: input.serviceName,
|
|
68
|
+
});
|
|
69
|
+
return result.rows.map(row => ({
|
|
70
|
+
customerName: row.customer_name,
|
|
71
|
+
cost: parseCount(row.cost_cents) / 100,
|
|
72
|
+
}));
|
|
73
|
+
},
|
|
74
|
+
}),
|
|
75
|
+
costTrend: dataApp.defineOperation({
|
|
76
|
+
filters: { month, customer },
|
|
77
|
+
policy: { maxQueryRows: 10, maxDurationMs: 15000 },
|
|
78
|
+
async run({ query }, input) {
|
|
79
|
+
const result = await query('costTrend', queryScope(input));
|
|
80
|
+
return result.rows.map(row => ({
|
|
81
|
+
periodStart: row.period_start,
|
|
82
|
+
cost: parseCount(row.cost_cents) / 100,
|
|
83
|
+
}));
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
customerServiceMix: dataApp.defineOperation({
|
|
87
|
+
filters: { month, customer },
|
|
88
|
+
policy: { maxQueryRows: 20, maxDurationMs: 15000 },
|
|
89
|
+
async run({ query }, input) {
|
|
90
|
+
const result = await query('customerServiceMix', queryScope(input));
|
|
91
|
+
// These service names match the fictional SQL rows and chart series.
|
|
92
|
+
// Update the pivot and chart series together when changing the services.
|
|
93
|
+
const customers = new Map<
|
|
94
|
+
string,
|
|
95
|
+
{
|
|
96
|
+
customerName: string;
|
|
97
|
+
Compute: number;
|
|
98
|
+
Storage: number;
|
|
99
|
+
Networking: number;
|
|
100
|
+
Logging: number;
|
|
101
|
+
total: number;
|
|
102
|
+
}
|
|
103
|
+
>();
|
|
104
|
+
for (const row of result.rows) {
|
|
105
|
+
const service = row.service_name;
|
|
106
|
+
if (
|
|
107
|
+
service !== 'Compute' &&
|
|
108
|
+
service !== 'Storage' &&
|
|
109
|
+
service !== 'Networking' &&
|
|
110
|
+
service !== 'Logging'
|
|
111
|
+
)
|
|
112
|
+
throw new Error('Unexpected fixture service.');
|
|
113
|
+
const entry = customers.get(row.customer_name) ?? {
|
|
114
|
+
customerName: row.customer_name,
|
|
115
|
+
Compute: 0,
|
|
116
|
+
Storage: 0,
|
|
117
|
+
Networking: 0,
|
|
118
|
+
Logging: 0,
|
|
119
|
+
total: 0,
|
|
120
|
+
};
|
|
121
|
+
const cost = parseCount(row.cost_cents) / 100;
|
|
122
|
+
entry[service] += cost;
|
|
123
|
+
entry.total += cost;
|
|
124
|
+
customers.set(row.customer_name, entry);
|
|
125
|
+
}
|
|
126
|
+
return [...customers.values()].sort(
|
|
127
|
+
(a, b) =>
|
|
128
|
+
b.total - a.total || a.customerName.localeCompare(b.customerName)
|
|
129
|
+
);
|
|
130
|
+
},
|
|
131
|
+
}),
|
|
132
|
+
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { serveLocalApp } from '@altertable/data-app-bun';
|
|
2
2
|
|
|
3
3
|
import page from '#app/index.html';
|
|
4
|
-
import { operations } from '#app/operations.ts';
|
|
5
4
|
import { dataApp } from '#config';
|
|
6
5
|
|
|
7
|
-
serveLocalApp({ page,
|
|
6
|
+
serveLocalApp({ page, app: dataApp });
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Read `node_modules/@altertable/data-app/docs/app-authoring.md` and use this project
|
|
4
4
|
as the selected scaffold. If dependencies are unavailable, read the
|
|
5
|
-
[version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.
|
|
5
|
+
[version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.78.0/docs/app-authoring.md). <!-- x-release-please-version -->
|
|
6
6
|
|
|
7
7
|
| Task | App-owned files |
|
|
8
8
|
| ------------------------------------------ | ------------------------------------------------------ |
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Local finding 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.
|
|
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
|
The example queries require the seeded sample data described in the
|
|
8
|
-
[local preview guide](https://github.com/altertable-ai/data-app/blob/v0.
|
|
8
|
+
[local preview guide](https://github.com/altertable-ai/data-app/blob/v0.78.0/docs/local-data-apps.md#preview-the-use-case-starters). <!-- x-release-please-version -->
|
|
9
9
|
Use that mock for development, or replace the example queries with verified data
|
|
10
10
|
in your lakehouse. The starter does not install a mock or create demo tables.
|
|
11
11
|
|
|
@@ -35,8 +35,7 @@ specified by the app brief. Change identity, appearance, and queries in `app.ts`
|
|
|
35
35
|
bun run check
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
`bun run check` includes the build, which writes browser assets to `dist/`.
|
|
39
|
-
`/api/data` backend; the local adapter does not authenticate hosted viewers.
|
|
38
|
+
`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.
|
|
40
39
|
|
|
41
40
|
## License
|
|
42
41
|
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { defineDataApp } from '@altertable/data-app';
|
|
2
2
|
|
|
3
3
|
export const dataApp = defineDataApp({
|
|
4
|
+
// Replace the demo title, description, and scope labels with the app's identity.
|
|
4
5
|
title: 'Sample finding',
|
|
5
6
|
description:
|
|
6
|
-
'
|
|
7
|
+
'Explore sample volume over time and across groups and segments.',
|
|
7
8
|
scope: { organization: 'demo', environment: 'sample' },
|
|
8
9
|
appearance: { theme: 'system' },
|
|
10
|
+
// starter_demo.daily_samples contains seeded fictional observations.
|
|
11
|
+
// Replace these queries with verified sources before publishing.
|
|
9
12
|
queries: {
|
|
10
|
-
|
|
13
|
+
sampleTotals: {
|
|
11
14
|
projections: { sample_count: { type: 'number' } },
|
|
12
15
|
statement: `
|
|
13
|
-
SELECT
|
|
16
|
+
SELECT SUM(sample_count) AS sample_count
|
|
14
17
|
FROM starter_demo.daily_samples
|
|
15
|
-
WHERE sample_date >= $
|
|
16
|
-
|
|
18
|
+
WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
|
|
19
|
+
AND ($groupName = 'all' OR group_name = $groupName)
|
|
20
|
+
HAVING COUNT(*) > 0`,
|
|
21
|
+
params: {
|
|
22
|
+
groupName: { type: 'string', defaultValue: 'Alpha' },
|
|
23
|
+
period_from: { type: 'string' },
|
|
24
|
+
period_to: { type: 'string' },
|
|
25
|
+
},
|
|
17
26
|
},
|
|
18
27
|
samplesOverTime: {
|
|
19
28
|
projections: {
|
|
@@ -24,10 +33,13 @@ WHERE sample_date >= $period.from AND sample_date < $period.to`,
|
|
|
24
33
|
SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
|
|
25
34
|
SUM(sample_count) AS sample_count
|
|
26
35
|
FROM starter_demo.daily_samples
|
|
27
|
-
WHERE sample_date >= $
|
|
36
|
+
WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
|
|
37
|
+
AND ($groupName = 'all' OR group_name = $groupName)
|
|
28
38
|
GROUP BY ALL ORDER BY period_start LIMIT 200`,
|
|
29
39
|
params: {
|
|
30
|
-
|
|
40
|
+
groupName: { type: 'string', defaultValue: 'Alpha' },
|
|
41
|
+
period_from: { type: 'string' },
|
|
42
|
+
period_to: { type: 'string' },
|
|
31
43
|
grain: { type: 'string', defaultValue: 'day' },
|
|
32
44
|
},
|
|
33
45
|
},
|
|
@@ -40,10 +52,13 @@ GROUP BY ALL ORDER BY period_start LIMIT 200`,
|
|
|
40
52
|
SELECT CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
|
|
41
53
|
SUM(sample_count) AS sample_count
|
|
42
54
|
FROM starter_demo.daily_samples
|
|
43
|
-
WHERE sample_date >= $
|
|
55
|
+
WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
|
|
56
|
+
AND ($groupName = 'all' OR group_name = $groupName)
|
|
44
57
|
GROUP BY ALL ORDER BY sample_count DESC LIMIT 50`,
|
|
45
58
|
params: {
|
|
46
|
-
|
|
59
|
+
groupName: { type: 'string', defaultValue: 'Alpha' },
|
|
60
|
+
period_from: { type: 'string' },
|
|
61
|
+
period_to: { type: 'string' },
|
|
47
62
|
breakdown: { type: 'string', defaultValue: 'segment' },
|
|
48
63
|
},
|
|
49
64
|
},
|
|
@@ -58,10 +73,13 @@ SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
|
|
|
58
73
|
CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
|
|
59
74
|
SUM(sample_count) AS sample_count
|
|
60
75
|
FROM starter_demo.daily_samples
|
|
61
|
-
WHERE sample_date >= $
|
|
76
|
+
WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
|
|
77
|
+
AND ($groupName = 'all' OR group_name = $groupName)
|
|
62
78
|
GROUP BY ALL ORDER BY period_start, member LIMIT 500`,
|
|
63
79
|
params: {
|
|
64
|
-
|
|
80
|
+
groupName: { type: 'string', defaultValue: 'Alpha' },
|
|
81
|
+
period_from: { type: 'string' },
|
|
82
|
+
period_to: { type: 'string' },
|
|
65
83
|
grain: { type: 'string', defaultValue: 'day' },
|
|
66
84
|
breakdown: { type: 'string', defaultValue: 'segment' },
|
|
67
85
|
},
|
|
@@ -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.
|
|
21
|
-
"@altertable/data-app-bun": "0.
|
|
22
|
-
"@altertable/data-app-react": "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
|
},
|