@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
|
@@ -2,41 +2,72 @@ import {
|
|
|
2
2
|
createDataHooks,
|
|
3
3
|
DataApp,
|
|
4
4
|
DataSection,
|
|
5
|
-
|
|
5
|
+
Button,
|
|
6
|
+
Grid,
|
|
7
|
+
GridItem,
|
|
8
|
+
Notice,
|
|
6
9
|
Stack,
|
|
7
10
|
TableWidget,
|
|
8
11
|
VisualizationWidget,
|
|
12
|
+
Ranking,
|
|
13
|
+
Comparison,
|
|
9
14
|
} from '@altertable/data-app-react';
|
|
10
|
-
import {
|
|
11
|
-
|
|
15
|
+
import {
|
|
16
|
+
Tabs,
|
|
17
|
+
TabList,
|
|
18
|
+
Tab,
|
|
19
|
+
TabPanels,
|
|
20
|
+
TabPanel,
|
|
21
|
+
useViewTab,
|
|
22
|
+
ComposedChart,
|
|
23
|
+
useAppFilters,
|
|
24
|
+
} from '@altertable/data-app-react/ui';
|
|
25
|
+
import {
|
|
26
|
+
formatCount,
|
|
27
|
+
formatNumber,
|
|
28
|
+
formatPercent,
|
|
29
|
+
} from '@altertable/data-app/format';
|
|
12
30
|
|
|
13
31
|
import { sampleDataContext } from '#app/data-context.ts';
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
import {
|
|
33
|
+
findingPeriodLabel,
|
|
34
|
+
periodLabel,
|
|
35
|
+
periodFilter,
|
|
36
|
+
groupName,
|
|
37
|
+
grain,
|
|
38
|
+
breakdown,
|
|
39
|
+
} from '#app/filters.ts';
|
|
40
|
+
import { operations } from '#app/operations.ts';
|
|
41
|
+
const { defineView } = createDataHooks(operations.createDataClient());
|
|
19
42
|
const count = { kind: 'count' } as const;
|
|
20
43
|
const emptyFallback = {
|
|
21
44
|
title: 'No samples in this period',
|
|
22
45
|
description: 'No observations are available for this period.',
|
|
23
46
|
};
|
|
24
|
-
const
|
|
47
|
+
const totalsView = defineView({
|
|
25
48
|
dataContext: sampleDataContext,
|
|
26
|
-
operation: '
|
|
49
|
+
operation: 'sampleTotals',
|
|
50
|
+
isEmpty: rows => rows.length === 0,
|
|
51
|
+
emptyFallback,
|
|
27
52
|
});
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
53
|
+
const totals = totalsView.dataset({
|
|
54
|
+
name: 'Period totals',
|
|
55
|
+
select: rows => rows,
|
|
56
|
+
rowKey: () => 'total',
|
|
57
|
+
columns: {
|
|
58
|
+
currentCount: {
|
|
59
|
+
label: 'Selected period',
|
|
60
|
+
value: row => row.currentCount,
|
|
61
|
+
format: count,
|
|
62
|
+
},
|
|
63
|
+
previousCount: {
|
|
64
|
+
label: 'Previous period',
|
|
65
|
+
value: row => row.previousCount,
|
|
66
|
+
format: count,
|
|
67
|
+
},
|
|
34
68
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
...(total.previous !== null && { previous: total.previous }),
|
|
38
|
-
})
|
|
39
|
-
);
|
|
69
|
+
evidence: { id: 'period-totals', glossaryIds: ['sampleCount'] },
|
|
70
|
+
});
|
|
40
71
|
const trendView = defineView({
|
|
41
72
|
dataContext: sampleDataContext,
|
|
42
73
|
operation: 'samplesOverTime',
|
|
@@ -60,14 +91,50 @@ const memberView = defineView({
|
|
|
60
91
|
emptyFallback,
|
|
61
92
|
});
|
|
62
93
|
const byMember = memberView.dataset({
|
|
63
|
-
name: '
|
|
94
|
+
name: 'Member comparison',
|
|
64
95
|
select: rows => rows,
|
|
65
96
|
rowKey: row => row.member,
|
|
66
97
|
columns: {
|
|
67
98
|
member: { label: 'Member', value: row => row.member },
|
|
68
|
-
|
|
99
|
+
currentCount: {
|
|
100
|
+
label: 'Selected period',
|
|
101
|
+
value: row => row.currentCount,
|
|
102
|
+
format: count,
|
|
103
|
+
},
|
|
104
|
+
previousCount: {
|
|
105
|
+
label: 'Previous period',
|
|
106
|
+
value: row => row.previousCount,
|
|
107
|
+
format: count,
|
|
108
|
+
},
|
|
109
|
+
change: {
|
|
110
|
+
label: 'Change',
|
|
111
|
+
value: row => row.change,
|
|
112
|
+
format: row => formatNumber(row.change, { signDisplay: 'exceptZero' }),
|
|
113
|
+
},
|
|
114
|
+
changeRate: {
|
|
115
|
+
label: 'Change %',
|
|
116
|
+
value: row => row.changeRate,
|
|
117
|
+
format: row => formatPercent(row.changeRate),
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
evidence: {
|
|
121
|
+
id: 'samples-by-member',
|
|
122
|
+
glossaryIds: ['sampleCount', 'sampleChange'],
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
const selectedMembers = memberView.dataset({
|
|
126
|
+
name: 'Selected-period samples',
|
|
127
|
+
select: rows => rows,
|
|
128
|
+
rowKey: row => row.member,
|
|
129
|
+
columns: {
|
|
130
|
+
member: { label: 'Member', value: row => row.member },
|
|
131
|
+
currentCount: {
|
|
132
|
+
label: 'Samples',
|
|
133
|
+
value: row => row.currentCount,
|
|
134
|
+
format: count,
|
|
135
|
+
},
|
|
69
136
|
},
|
|
70
|
-
evidence: { id: '
|
|
137
|
+
evidence: { id: 'selected-members', glossaryIds: ['sampleCount'] },
|
|
71
138
|
});
|
|
72
139
|
const rowsView = defineView({
|
|
73
140
|
dataContext: sampleDataContext,
|
|
@@ -86,16 +153,53 @@ const sampleRows = rowsView.dataset({
|
|
|
86
153
|
},
|
|
87
154
|
evidence: { id: 'samples', glossaryIds: ['sampleCount'] },
|
|
88
155
|
});
|
|
89
|
-
//
|
|
90
|
-
const
|
|
91
|
-
<
|
|
156
|
+
// Compare current and previous periods from the same displayed result.
|
|
157
|
+
const totalsContent = totalsView.content(result => (
|
|
158
|
+
<VisualizationWidget
|
|
159
|
+
dataset={totals}
|
|
160
|
+
source={result}
|
|
161
|
+
title={
|
|
162
|
+
result.loading || result.input.period.comparison
|
|
163
|
+
? 'Period comparison'
|
|
164
|
+
: 'Selected period'
|
|
165
|
+
}
|
|
166
|
+
>
|
|
167
|
+
{rows =>
|
|
168
|
+
result.loading ? null : result.input.period.comparison ? (
|
|
169
|
+
<Comparison
|
|
170
|
+
label="Samples"
|
|
171
|
+
current={{
|
|
172
|
+
value: rows[0]!.currentCount,
|
|
173
|
+
formattedValue: formatCount(rows[0]!.currentCount),
|
|
174
|
+
periodLabel: periodLabel(result.input.period.range),
|
|
175
|
+
}}
|
|
176
|
+
previous={{
|
|
177
|
+
value: rows[0]!.previousCount,
|
|
178
|
+
formattedValue: formatCount(rows[0]!.previousCount, {
|
|
179
|
+
missing: 'Not available',
|
|
180
|
+
}),
|
|
181
|
+
periodLabel: periodLabel(result.input.period.comparison),
|
|
182
|
+
}}
|
|
183
|
+
/>
|
|
184
|
+
) : (
|
|
185
|
+
<Ranking
|
|
186
|
+
items={[
|
|
187
|
+
{
|
|
188
|
+
id: 'selected',
|
|
189
|
+
label: periodLabel(result.input.period.range),
|
|
190
|
+
value: rows[0]!.currentCount,
|
|
191
|
+
},
|
|
192
|
+
]}
|
|
193
|
+
/>
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
</VisualizationWidget>
|
|
92
197
|
));
|
|
93
198
|
const trendContent = trendView.content(result => (
|
|
94
199
|
<VisualizationWidget
|
|
95
200
|
dataset={trend}
|
|
96
201
|
source={result}
|
|
97
202
|
title="Samples over time"
|
|
98
|
-
description="Includes the previous period when comparison is on."
|
|
99
203
|
breakdown={trendView.breakdown('grain')}
|
|
100
204
|
>
|
|
101
205
|
{rows => (
|
|
@@ -116,34 +220,127 @@ const memberContent = memberView.content(result => (
|
|
|
116
220
|
<VisualizationWidget
|
|
117
221
|
dataset={byMember}
|
|
118
222
|
source={result}
|
|
119
|
-
title=
|
|
223
|
+
title={
|
|
224
|
+
result.loading || result.input.period.comparison
|
|
225
|
+
? 'Where volume changed'
|
|
226
|
+
: 'Samples by member'
|
|
227
|
+
}
|
|
120
228
|
breakdown={memberView.breakdown('breakdown')}
|
|
121
229
|
>
|
|
122
230
|
{rows => (
|
|
123
|
-
<
|
|
231
|
+
<ComposedChart
|
|
124
232
|
ariaLabel="Samples by member"
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
233
|
+
data={rows}
|
|
234
|
+
valueFormat={count}
|
|
235
|
+
>
|
|
236
|
+
<ComposedChart.XAxis dataKey="member" />
|
|
237
|
+
<ComposedChart.YAxis />
|
|
238
|
+
{!result.loading && result.input.period.comparison && (
|
|
239
|
+
<ComposedChart.Bar
|
|
240
|
+
dataKey="previousCount"
|
|
241
|
+
name="Previous period"
|
|
242
|
+
fill="var(--atbl-muted)"
|
|
243
|
+
fillOpacity={0.45}
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
<ComposedChart.Bar dataKey="currentCount" name="Selected period" />
|
|
247
|
+
<ComposedChart.Tooltip />
|
|
248
|
+
<ComposedChart.Legend />
|
|
249
|
+
</ComposedChart>
|
|
133
250
|
)}
|
|
134
251
|
</VisualizationWidget>
|
|
135
252
|
));
|
|
253
|
+
const memberTableContent = memberView.content(result => (
|
|
254
|
+
<TableWidget
|
|
255
|
+
dataset={
|
|
256
|
+
result.loading || result.input.period.comparison
|
|
257
|
+
? byMember
|
|
258
|
+
: selectedMembers
|
|
259
|
+
}
|
|
260
|
+
source={result}
|
|
261
|
+
title={
|
|
262
|
+
result.loading || result.input.period.comparison
|
|
263
|
+
? 'Change by member'
|
|
264
|
+
: 'Samples by member'
|
|
265
|
+
}
|
|
266
|
+
/>
|
|
267
|
+
));
|
|
136
268
|
const rowsContent = rowsView.content(result => (
|
|
137
|
-
<TableWidget dataset={sampleRows} source={result} title="
|
|
269
|
+
<TableWidget dataset={sampleRows} source={result} title="Sample details" />
|
|
138
270
|
));
|
|
271
|
+
// Show this notice when scope or display choices differ from the original finding.
|
|
272
|
+
// Back to finding restores both scope filters and display choices to their defaults.
|
|
273
|
+
function FindingScope() {
|
|
274
|
+
const filters = useAppFilters({
|
|
275
|
+
period: periodFilter,
|
|
276
|
+
groupName,
|
|
277
|
+
grain,
|
|
278
|
+
breakdown,
|
|
279
|
+
});
|
|
280
|
+
const scopeChanged =
|
|
281
|
+
!periodFilter.same(filters.values.period, periodFilter.defaultValue) ||
|
|
282
|
+
!groupName.same(filters.values.groupName, groupName.defaultValue);
|
|
283
|
+
const displayChanged =
|
|
284
|
+
!grain.same(filters.values.grain, grain.defaultValue) ||
|
|
285
|
+
!breakdown.same(filters.values.breakdown, breakdown.defaultValue);
|
|
286
|
+
if (!scopeChanged && !displayChanged) return null;
|
|
287
|
+
return (
|
|
288
|
+
<Notice
|
|
289
|
+
title={
|
|
290
|
+
scopeChanged
|
|
291
|
+
? 'Exploring a different scope'
|
|
292
|
+
: 'Viewing a different breakdown'
|
|
293
|
+
}
|
|
294
|
+
description={
|
|
295
|
+
<>
|
|
296
|
+
Original finding · {findingPeriodLabel} {periodFilter.policy.timeZone}{' '}
|
|
297
|
+
vs previous period ·{' '}
|
|
298
|
+
{groupName.describe?.(groupName.defaultValue) ??
|
|
299
|
+
groupName.defaultValue}
|
|
300
|
+
</>
|
|
301
|
+
}
|
|
302
|
+
action={
|
|
303
|
+
<Button size="compact" onClick={() => filters.resetAll()}>
|
|
304
|
+
Back to finding
|
|
305
|
+
</Button>
|
|
306
|
+
}
|
|
307
|
+
/>
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
const views = ['overview', 'data'] as const;
|
|
139
311
|
export function App() {
|
|
312
|
+
const [view, setView] = useViewTab(views, 'overview');
|
|
140
313
|
return (
|
|
141
|
-
<DataApp view={
|
|
314
|
+
<DataApp view={trendView} showToolbar={false}>
|
|
142
315
|
<Stack>
|
|
143
|
-
<
|
|
144
|
-
<
|
|
145
|
-
|
|
146
|
-
|
|
316
|
+
<FindingScope />
|
|
317
|
+
<Tabs selectedKey={view} onSelectionChange={setView}>
|
|
318
|
+
<TabList aria-label="Finding views">
|
|
319
|
+
<Tab id="overview">Overview</Tab>
|
|
320
|
+
<Tab id="data">Data</Tab>
|
|
321
|
+
</TabList>
|
|
322
|
+
<TabPanels>
|
|
323
|
+
<TabPanel id="overview">
|
|
324
|
+
<Stack>
|
|
325
|
+
<Grid columns={3}>
|
|
326
|
+
<GridItem span={2}>
|
|
327
|
+
<DataSection content={trendContent} />
|
|
328
|
+
</GridItem>
|
|
329
|
+
<GridItem>
|
|
330
|
+
<DataSection content={totalsContent} />
|
|
331
|
+
</GridItem>
|
|
332
|
+
</Grid>
|
|
333
|
+
<DataSection content={memberContent} />
|
|
334
|
+
</Stack>
|
|
335
|
+
</TabPanel>
|
|
336
|
+
<TabPanel id="data">
|
|
337
|
+
<Stack>
|
|
338
|
+
<DataSection content={memberTableContent} />
|
|
339
|
+
<DataSection content={rowsContent} />
|
|
340
|
+
</Stack>
|
|
341
|
+
</TabPanel>
|
|
342
|
+
</TabPanels>
|
|
343
|
+
</Tabs>
|
|
147
344
|
</Stack>
|
|
148
345
|
</DataApp>
|
|
149
346
|
);
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import { createDataContext } from '@altertable/data-app-react';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { operations } from '#app/operations.ts';
|
|
4
|
+
|
|
3
5
|
const queryNames = {
|
|
4
|
-
|
|
5
|
-
samplesOverTime
|
|
6
|
-
samplesByMember
|
|
7
|
-
sampleRows
|
|
8
|
-
}
|
|
6
|
+
...operations.sampleTotals.queryNames,
|
|
7
|
+
...operations.samplesOverTime.queryNames,
|
|
8
|
+
...operations.samplesByMember.queryNames,
|
|
9
|
+
...operations.sampleRows.queryNames,
|
|
10
|
+
};
|
|
9
11
|
export const sampleDataContext = createDataContext(queryNames)({
|
|
10
12
|
description:
|
|
11
|
-
'Fictional daily
|
|
13
|
+
'Fictional daily sample counts by group and segment. Comparisons use equal-length periods in UTC.',
|
|
12
14
|
glossary: {
|
|
15
|
+
sampleChange: {
|
|
16
|
+
term: 'Sample change',
|
|
17
|
+
definition:
|
|
18
|
+
'Selected-period samples minus the previous equal-length period in the same scope. Missing observations remain unavailable; they are not measured zeroes.',
|
|
19
|
+
queryNames: ['samplesByMember'],
|
|
20
|
+
},
|
|
13
21
|
sampleCount: {
|
|
14
22
|
term: 'Sample count',
|
|
15
|
-
definition:
|
|
23
|
+
definition:
|
|
24
|
+
'Number of samples recorded for each day, group, and segment.',
|
|
16
25
|
queryNames: Object.values(queryNames),
|
|
17
26
|
},
|
|
18
27
|
},
|
|
@@ -1,24 +1,43 @@
|
|
|
1
1
|
import {
|
|
2
|
+
choiceFilter,
|
|
2
3
|
dateTimeRangeFilter,
|
|
3
4
|
displayChoice,
|
|
4
5
|
} from '@altertable/data-app/contract';
|
|
6
|
+
import { formatDateRange } from '@altertable/data-app/format';
|
|
5
7
|
|
|
6
|
-
//
|
|
7
|
-
// the server, and the browser client renders their controls.
|
|
8
|
+
// Replace this fictional finding period with the period supported by its evidence.
|
|
8
9
|
const findingPeriod = {
|
|
9
10
|
from: new Date('2026-03-09T00:00:00Z'),
|
|
10
11
|
to: new Date('2026-03-16T00:00:00Z'),
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
+
export function periodLabel(range: { from: Date; to: Date }) {
|
|
14
|
+
return formatDateRange({
|
|
15
|
+
start: range.from.toISOString().slice(0, 10),
|
|
16
|
+
end: new Date(range.to.getTime() - 1).toISOString().slice(0, 10),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export const findingPeriodLabel = periodLabel(findingPeriod);
|
|
20
|
+
export const periodFilter = dateTimeRangeFilter({
|
|
13
21
|
key: 'period',
|
|
14
22
|
defaultValue: findingPeriod,
|
|
23
|
+
comparison: 'on',
|
|
24
|
+
// These bounds match the seeded demo history. Use the real source coverage.
|
|
15
25
|
minDate: '2026-01-05',
|
|
16
26
|
maxDate: '2026-03-29',
|
|
17
27
|
maxRangeDays: 28,
|
|
18
|
-
comparison: 'off',
|
|
19
28
|
presets: [{ label: 'Finding period', range: findingPeriod }],
|
|
20
29
|
});
|
|
21
|
-
const
|
|
30
|
+
export const groupName = choiceFilter({
|
|
31
|
+
key: 'group',
|
|
32
|
+
label: 'Group',
|
|
33
|
+
defaultValue: 'Alpha',
|
|
34
|
+
options: [
|
|
35
|
+
{ id: 'all', label: 'All groups' },
|
|
36
|
+
{ id: 'Alpha', label: 'Alpha' },
|
|
37
|
+
{ id: 'Beta', label: 'Beta' },
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
export const grain = displayChoice({
|
|
22
41
|
key: 'grain',
|
|
23
42
|
label: 'Grain',
|
|
24
43
|
defaultValue: 'day',
|
|
@@ -28,7 +47,7 @@ const grain = displayChoice({
|
|
|
28
47
|
],
|
|
29
48
|
presentation: { control: 'widget' },
|
|
30
49
|
});
|
|
31
|
-
const breakdown = displayChoice({
|
|
50
|
+
export const breakdown = displayChoice({
|
|
32
51
|
key: 'breakdown',
|
|
33
52
|
label: 'Breakdown',
|
|
34
53
|
defaultValue: 'segment',
|
|
@@ -39,10 +58,9 @@ const breakdown = displayChoice({
|
|
|
39
58
|
presentation: { control: 'widget' },
|
|
40
59
|
});
|
|
41
60
|
|
|
42
|
-
/** The filters each operation reads. */
|
|
43
61
|
export const operationFilters = {
|
|
44
|
-
|
|
45
|
-
samplesOverTime: { period, grain },
|
|
46
|
-
samplesByMember: { period, breakdown },
|
|
47
|
-
sampleRows: { period, grain, breakdown },
|
|
62
|
+
sampleTotals: { period: periodFilter, groupName },
|
|
63
|
+
samplesOverTime: { period: periodFilter, groupName, grain },
|
|
64
|
+
samplesByMember: { period: periodFilter, groupName, breakdown },
|
|
65
|
+
sampleRows: { period: periodFilter, groupName, grain, breakdown },
|
|
48
66
|
};
|
|
@@ -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,34 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
parseCount,
|
|
3
|
+
queryDateTimeRangeParams,
|
|
4
|
+
} from '@altertable/data-app/contract';
|
|
2
5
|
|
|
3
|
-
import { operationFilters } from '#app/filters.ts';
|
|
6
|
+
import { operationFilters, periodFilter } from '#app/filters.ts';
|
|
4
7
|
import { dataApp } from '#config';
|
|
5
|
-
|
|
8
|
+
|
|
6
9
|
const policy = { maxQueryRows: 500, maxDurationMs: 15000 };
|
|
7
|
-
export const operations = {
|
|
8
|
-
|
|
9
|
-
filters: operationFilters.
|
|
10
|
+
export const operations = dataApp.defineOperations({
|
|
11
|
+
sampleTotals: dataApp.defineOperation({
|
|
12
|
+
filters: operationFilters.sampleTotals,
|
|
10
13
|
policy,
|
|
11
|
-
async run({ query }, { period }) {
|
|
12
|
-
const
|
|
13
|
-
const previous =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
async run({ query }, { period, groupName }) {
|
|
15
|
+
const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
|
|
16
|
+
const [current, previous] = await Promise.all([
|
|
17
|
+
query('sampleTotals', { ...bounds.current, groupName }),
|
|
18
|
+
bounds.comparison
|
|
19
|
+
? query('sampleTotals', { ...bounds.comparison, groupName })
|
|
20
|
+
: null,
|
|
21
|
+
]);
|
|
22
|
+
const row = current.rows[0];
|
|
23
|
+
if (!row) return [];
|
|
24
|
+
const baseline = previous?.rows[0];
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
currentCount: parseCount(row.sample_count),
|
|
28
|
+
previousCount: baseline ? parseCount(baseline.sample_count) : null,
|
|
29
|
+
},
|
|
30
|
+
];
|
|
20
31
|
},
|
|
21
32
|
}),
|
|
22
33
|
samplesOverTime: dataApp.defineOperation({
|
|
23
34
|
filters: operationFilters.samplesOverTime,
|
|
24
35
|
policy,
|
|
25
|
-
async run({ query }, { period, grain }) {
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
async run({ query }, { period, groupName, grain }) {
|
|
37
|
+
const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
|
|
38
|
+
const result = await query('samplesOverTime', {
|
|
39
|
+
...bounds.combined,
|
|
40
|
+
groupName,
|
|
41
|
+
grain,
|
|
42
|
+
});
|
|
32
43
|
return result.rows.map(row => ({
|
|
33
44
|
periodStart: row.period_start,
|
|
34
45
|
sampleCount: parseCount(row.sample_count),
|
|
@@ -38,23 +49,58 @@ export const operations = {
|
|
|
38
49
|
samplesByMember: dataApp.defineOperation({
|
|
39
50
|
filters: operationFilters.samplesByMember,
|
|
40
51
|
policy,
|
|
41
|
-
async run({ query }, { period, breakdown }) {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
breakdown,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
async run({ query }, { period, groupName, breakdown }) {
|
|
53
|
+
const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
|
|
54
|
+
const [current, previous] = await Promise.all([
|
|
55
|
+
query('samplesByMember', { ...bounds.current, groupName, breakdown }),
|
|
56
|
+
bounds.comparison
|
|
57
|
+
? query('samplesByMember', {
|
|
58
|
+
...bounds.comparison,
|
|
59
|
+
groupName,
|
|
60
|
+
breakdown,
|
|
61
|
+
})
|
|
62
|
+
: null,
|
|
63
|
+
]);
|
|
64
|
+
const currentCounts = new Map(
|
|
65
|
+
current.rows.map(row => [row.member, parseCount(row.sample_count)])
|
|
66
|
+
);
|
|
67
|
+
const previousCounts = new Map(
|
|
68
|
+
previous?.rows.map(row => [row.member, parseCount(row.sample_count)])
|
|
69
|
+
);
|
|
70
|
+
const members = new Set([
|
|
71
|
+
...currentCounts.keys(),
|
|
72
|
+
...previousCounts.keys(),
|
|
73
|
+
]);
|
|
74
|
+
return [...members]
|
|
75
|
+
.map(member => {
|
|
76
|
+
const currentCount = currentCounts.get(member) ?? null;
|
|
77
|
+
const previousCount = previousCounts.get(member) ?? null;
|
|
78
|
+
const change =
|
|
79
|
+
currentCount !== null && previousCount !== null
|
|
80
|
+
? currentCount - previousCount
|
|
81
|
+
: null;
|
|
82
|
+
return {
|
|
83
|
+
member,
|
|
84
|
+
currentCount,
|
|
85
|
+
previousCount,
|
|
86
|
+
change,
|
|
87
|
+
changeRate:
|
|
88
|
+
change !== null && previousCount !== null && previousCount > 0
|
|
89
|
+
? change / previousCount
|
|
90
|
+
: null,
|
|
91
|
+
};
|
|
92
|
+
})
|
|
93
|
+
.sort((a, b) => Math.abs(b.change ?? 0) - Math.abs(a.change ?? 0));
|
|
50
94
|
},
|
|
51
95
|
}),
|
|
52
96
|
sampleRows: dataApp.defineOperation({
|
|
53
97
|
filters: operationFilters.sampleRows,
|
|
54
98
|
policy,
|
|
55
|
-
async run({ query }, { period, grain, breakdown }) {
|
|
99
|
+
async run({ query }, { period, groupName, grain, breakdown }) {
|
|
100
|
+
const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
|
|
56
101
|
const result = await query('sampleRows', {
|
|
57
|
-
|
|
102
|
+
...bounds.combined,
|
|
103
|
+
groupName,
|
|
58
104
|
grain,
|
|
59
105
|
breakdown,
|
|
60
106
|
});
|
|
@@ -65,4 +111,4 @@ export const operations = {
|
|
|
65
111
|
}));
|
|
66
112
|
},
|
|
67
113
|
}),
|
|
68
|
-
};
|
|
114
|
+
});
|
|
@@ -1,7 +1,9 @@
|
|
|
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({
|
|
6
|
+
serveLocalApp({
|
|
7
|
+
page,
|
|
8
|
+
app: dataApp,
|
|
9
|
+
});
|
|
@@ -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 metric 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
|
|