@altertable/data-app-examples 0.78.0 → 0.79.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/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
- package/templates/starter-data-app/index.tsx +71 -680
- package/templates/starter-finding-data-app/index.tsx +9 -31
- package/templates/starter-local-data-app/AGENTS.md +1 -1
- package/templates/starter-local-data-app/README.md +5 -8
- package/templates/starter-local-data-app/app.ts +15 -246
- package/templates/starter-local-data-app/package.json +3 -3
- package/templates/starter-local-data-app/src/App.tsx +32 -253
- package/templates/starter-local-data-app/src/data-context.ts +8 -27
- package/templates/starter-local-data-app/src/filters.ts +9 -30
- package/templates/starter-local-data-app/src/operations.ts +9 -125
- package/templates/starter-local-finding-data-app/AGENTS.md +1 -1
- package/templates/starter-local-finding-data-app/README.md +2 -2
- package/templates/starter-local-finding-data-app/package.json +3 -3
- package/templates/starter-local-finding-data-app/src/App.tsx +7 -23
- package/templates/starter-local-finding-data-app/src/data-context.ts +3 -9
- package/templates/starter-local-metric-data-app/AGENTS.md +1 -1
- package/templates/starter-local-metric-data-app/README.md +2 -2
- package/templates/starter-local-metric-data-app/app.ts +4 -4
- package/templates/starter-local-metric-data-app/package.json +3 -3
- package/templates/starter-local-metric-data-app/src/App.tsx +4 -8
- package/templates/starter-local-metric-data-app/src/data-context.ts +4 -8
- package/templates/starter-local-metric-data-app/src/filters.ts +1 -0
- package/templates/starter-local-metric-data-app/src/operations.ts +4 -12
- package/templates/starter-metric-data-app/index.tsx +18 -32
|
@@ -2,279 +2,58 @@ import {
|
|
|
2
2
|
createDataHooks,
|
|
3
3
|
DataApp,
|
|
4
4
|
DataSection,
|
|
5
|
-
Grid,
|
|
6
|
-
MetricWidget,
|
|
7
|
-
TableWidget,
|
|
8
5
|
VisualizationWidget,
|
|
9
|
-
Stack,
|
|
10
6
|
} from '@altertable/data-app-react';
|
|
11
|
-
import { BarChart
|
|
12
|
-
import { formatDateRange } from '@altertable/data-app/format';
|
|
7
|
+
import { BarChart } from '@altertable/data-app-react/ui';
|
|
13
8
|
|
|
14
|
-
import {
|
|
15
|
-
import { month } from '#app/filters.ts';
|
|
9
|
+
import { dataContext } from '#app/data-context.ts';
|
|
16
10
|
import { operations } from '#app/operations.ts';
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
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,
|
|
12
|
+
const { defineView } = createDataHooks(operations.createDataClient());
|
|
13
|
+
const sampleCountsView = defineView({
|
|
14
|
+
dataContext,
|
|
15
|
+
operation: 'sampleCountsByGroup',
|
|
103
16
|
emptyFallback: {
|
|
104
|
-
title: 'No
|
|
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 },
|
|
17
|
+
title: 'No matching groups',
|
|
18
|
+
description: 'Choose another group.',
|
|
180
19
|
},
|
|
181
|
-
evidence: { id: 'cost-trend', glossaryIds: ['allocatedCost'] },
|
|
182
20
|
});
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
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,
|
|
21
|
+
const sampleCounts = sampleCountsView.dataset({
|
|
22
|
+
name: 'Sample counts',
|
|
23
|
+
rowKey: row => row.groupName,
|
|
218
24
|
columns: {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
Storage: { value: row => row.Storage, format: costFormat },
|
|
222
|
-
Networking: { value: row => row.Networking, format: costFormat },
|
|
223
|
-
Logging: { value: row => row.Logging, format: costFormat },
|
|
25
|
+
groupName: { label: 'Group' },
|
|
26
|
+
sampleCount: { format: { kind: 'count' } },
|
|
224
27
|
},
|
|
225
|
-
evidence: { id: '
|
|
28
|
+
evidence: { id: 'counts-by-group', glossaryIds: ['sampleCount'] },
|
|
226
29
|
});
|
|
227
|
-
const
|
|
30
|
+
const countsContent = sampleCountsView.content(result => (
|
|
228
31
|
<VisualizationWidget
|
|
229
|
-
dataset={
|
|
32
|
+
dataset={sampleCounts}
|
|
230
33
|
source={result}
|
|
231
|
-
title="
|
|
34
|
+
title="Samples by group"
|
|
232
35
|
>
|
|
233
36
|
{rows => (
|
|
234
|
-
<
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
valueFormat={
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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>
|
|
37
|
+
<BarChart
|
|
38
|
+
ariaLabel="Sample counts by group"
|
|
39
|
+
unit="samples"
|
|
40
|
+
valueFormat={{ kind: 'count' }}
|
|
41
|
+
showYAxis
|
|
42
|
+
scrollToEnd={false}
|
|
43
|
+
items={rows.map(row => ({
|
|
44
|
+
id: row.groupName,
|
|
45
|
+
label: row.groupName,
|
|
46
|
+
value: row.sampleCount,
|
|
47
|
+
}))}
|
|
48
|
+
/>
|
|
264
49
|
)}
|
|
265
50
|
</VisualizationWidget>
|
|
266
51
|
));
|
|
52
|
+
|
|
267
53
|
export function App() {
|
|
268
54
|
return (
|
|
269
|
-
<DataApp view={
|
|
270
|
-
<
|
|
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>
|
|
55
|
+
<DataApp view={sampleCountsView} datasets={[sampleCounts]}>
|
|
56
|
+
<DataSection content={countsContent} />
|
|
278
57
|
</DataApp>
|
|
279
58
|
);
|
|
280
59
|
}
|
|
@@ -1,36 +1,17 @@
|
|
|
1
1
|
import { createDataContext } from '@altertable/data-app-react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { dataApp } from '#config';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
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)({
|
|
5
|
+
// Replace the description and definitions with verified source metadata.
|
|
6
|
+
export const dataContext = createDataContext(dataApp.queryNames)({
|
|
14
7
|
description:
|
|
15
|
-
'Fictional
|
|
8
|
+
'Fictional sample counts by group. Gamma has a recorded count of zero.',
|
|
16
9
|
glossary: {
|
|
17
|
-
|
|
18
|
-
term: '
|
|
10
|
+
sampleCount: {
|
|
11
|
+
term: 'Sample count',
|
|
19
12
|
definition:
|
|
20
|
-
'
|
|
21
|
-
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],
|
|
13
|
+
'Sum of recorded samples in the selected group scope. Additive across groups.',
|
|
14
|
+
queryNames: [dataApp.queryNames.sampleCountsByGroup],
|
|
34
15
|
},
|
|
35
16
|
},
|
|
36
17
|
});
|
|
@@ -1,35 +1,14 @@
|
|
|
1
|
-
import { choiceFilter
|
|
1
|
+
import { choiceFilter } from '@altertable/data-app/contract';
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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',
|
|
3
|
+
// The options match the fictional rows; the query treats 'all' as every group.
|
|
4
|
+
export const groupName = choiceFilter({
|
|
5
|
+
key: 'group',
|
|
6
|
+
label: 'Group',
|
|
19
7
|
defaultValue: 'all',
|
|
20
8
|
options: [
|
|
21
|
-
{ id: 'all', label: 'All
|
|
22
|
-
{ id: '
|
|
23
|
-
{ id: '
|
|
24
|
-
{ id: '
|
|
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' },
|
|
9
|
+
{ id: 'all', label: 'All groups' },
|
|
10
|
+
{ id: 'Alpha', label: 'Alpha' },
|
|
11
|
+
{ id: 'Beta', label: 'Beta' },
|
|
12
|
+
{ id: 'Gamma', label: 'Gamma' },
|
|
34
13
|
],
|
|
35
14
|
});
|
|
@@ -1,132 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { month, customer, breakdown } from '#app/filters.ts';
|
|
1
|
+
import { groupName } from '#app/filters.ts';
|
|
4
2
|
import { dataApp } from '#config';
|
|
5
3
|
|
|
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
4
|
export const operations = dataApp.defineOperations({
|
|
26
|
-
|
|
27
|
-
filters: {
|
|
28
|
-
policy: { maxQueryRows: 10
|
|
29
|
-
async run({ query },
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
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,
|
|
5
|
+
sampleCountsByGroup: dataApp.defineOperation({
|
|
6
|
+
filters: { groupName },
|
|
7
|
+
policy: { maxQueryRows: 10 },
|
|
8
|
+
async run({ query }, { groupName }) {
|
|
9
|
+
const { rows } = await query('sampleCountsByGroup', { groupName });
|
|
10
|
+
return rows.map(row => ({
|
|
11
|
+
groupName: row.group_name,
|
|
12
|
+
sampleCount: row.sample_count,
|
|
72
13
|
}));
|
|
73
14
|
},
|
|
74
15
|
}),
|
|
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
16
|
});
|
|
@@ -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.79.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.79.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.79.0/docs/local-data-apps.md#preview-the-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
|
|
|
@@ -17,9 +17,9 @@
|
|
|
17
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.79.0",
|
|
21
|
+
"@altertable/data-app-bun": "0.79.0",
|
|
22
|
+
"@altertable/data-app-react": "0.79.0",
|
|
23
23
|
"react": "19.3.1",
|
|
24
24
|
"react-dom": "19.3.1"
|
|
25
25
|
},
|