@altertable/data-app-examples 0.77.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.
Files changed (37) hide show
  1. package/dist/index.js +2 -2
  2. package/dist/index.js.map +1 -1
  3. package/dist/types/index.d.ts +2 -2
  4. package/package.json +1 -1
  5. package/templates/starter-data-app/index.tsx +76 -138
  6. package/templates/starter-finding-data-app/index.tsx +379 -117
  7. package/templates/starter-local-data-app/AGENTS.md +9 -9
  8. package/templates/starter-local-data-app/README.md +11 -5
  9. package/templates/starter-local-data-app/app.ts +25 -21
  10. package/templates/starter-local-data-app/package.json +5 -5
  11. package/templates/starter-local-data-app/src/App.tsx +54 -4
  12. package/templates/starter-local-data-app/src/data-context.ts +8 -13
  13. package/templates/starter-local-data-app/src/filters.ts +14 -0
  14. package/templates/starter-local-data-app/src/main.tsx +3 -3
  15. package/templates/starter-local-data-app/src/operations.ts +14 -5
  16. package/templates/starter-local-data-app/src/server.ts +1 -2
  17. package/templates/starter-local-finding-data-app/AGENTS.md +1 -1
  18. package/templates/starter-local-finding-data-app/README.md +3 -4
  19. package/templates/starter-local-finding-data-app/app.ts +29 -11
  20. package/templates/starter-local-finding-data-app/package.json +5 -5
  21. package/templates/starter-local-finding-data-app/src/App.tsx +237 -56
  22. package/templates/starter-local-finding-data-app/src/data-context.ts +14 -11
  23. package/templates/starter-local-finding-data-app/src/filters.ts +29 -11
  24. package/templates/starter-local-finding-data-app/src/main.tsx +3 -3
  25. package/templates/starter-local-finding-data-app/src/operations.ts +80 -34
  26. package/templates/starter-local-finding-data-app/src/server.ts +4 -2
  27. package/templates/starter-local-metric-data-app/AGENTS.md +1 -1
  28. package/templates/starter-local-metric-data-app/README.md +3 -4
  29. package/templates/starter-local-metric-data-app/app.ts +9 -6
  30. package/templates/starter-local-metric-data-app/package.json +5 -5
  31. package/templates/starter-local-metric-data-app/src/App.tsx +25 -30
  32. package/templates/starter-local-metric-data-app/src/data-context.ts +9 -9
  33. package/templates/starter-local-metric-data-app/src/filters.ts +2 -3
  34. package/templates/starter-local-metric-data-app/src/main.tsx +3 -3
  35. package/templates/starter-local-metric-data-app/src/operations.ts +6 -14
  36. package/templates/starter-local-metric-data-app/src/server.ts +4 -2
  37. package/templates/starter-metric-data-app/index.tsx +49 -63
@@ -2,100 +2,188 @@ import {
2
2
  createDataHooks,
3
3
  DataApp,
4
4
  DataSection,
5
- MetricWidget,
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 { BarChart, ComposedChart } from '@altertable/data-app-react/ui';
11
- import { createDataClient } from '@altertable/data-app/client';
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 { operationFilters } from '#app/filters.ts';
15
- import type { operations } from '#app/operations.ts';
16
- const { defineView } = createDataHooks(
17
- createDataClient<typeof operations>({ filters: operationFilters })
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 totalView = defineView({
47
+ const totalsView = defineView({
25
48
  dataContext: sampleDataContext,
26
- operation: 'sampleTotal',
49
+ operation: 'sampleTotals',
50
+ emptyFallback,
27
51
  });
28
- const totalSamples = totalView.metric(
29
- {
30
- id: 'total-samples',
31
- label: 'Samples',
32
- glossaryId: 'sampleCount',
33
- format: count,
52
+ const totals = totalsView.dataset({
53
+ name: 'Period totals',
54
+ rowKey: () => 'total',
55
+ columns: {
56
+ currentCount: {
57
+ label: 'Selected period',
58
+ format: count,
59
+ },
60
+ previousCount: {
61
+ label: 'Previous period',
62
+ format: count,
63
+ },
34
64
  },
35
- total => ({
36
- current: total.current,
37
- ...(total.previous !== null && { previous: total.previous }),
38
- })
39
- );
65
+ evidence: { id: 'period-totals', glossaryIds: ['sampleCount'] },
66
+ });
40
67
  const trendView = defineView({
41
68
  dataContext: sampleDataContext,
42
69
  operation: 'samplesOverTime',
43
- isEmpty: rows => rows.length === 0,
44
70
  emptyFallback,
45
71
  });
46
72
  const trend = trendView.dataset({
47
73
  name: 'Samples over time',
48
- select: rows => rows,
49
74
  rowKey: row => row.periodStart,
50
75
  columns: {
51
- periodStart: { label: 'Period start', value: row => row.periodStart },
52
- sampleCount: { value: row => row.sampleCount, format: count },
76
+ periodStart: { label: 'Period start' },
77
+ sampleCount: { format: count },
53
78
  },
54
79
  evidence: { id: 'samples-over-time', glossaryIds: ['sampleCount'] },
55
80
  });
56
81
  const memberView = defineView({
57
82
  dataContext: sampleDataContext,
58
83
  operation: 'samplesByMember',
59
- isEmpty: rows => rows.length === 0,
60
84
  emptyFallback,
61
85
  });
62
86
  const byMember = memberView.dataset({
63
- name: 'Samples by member',
64
- select: rows => rows,
87
+ name: 'Member comparison',
88
+ rowKey: row => row.member,
89
+ columns: {
90
+ member: { label: 'Member' },
91
+ currentCount: {
92
+ label: 'Selected period',
93
+ format: count,
94
+ },
95
+ previousCount: {
96
+ label: 'Previous period',
97
+ format: count,
98
+ },
99
+ change: {
100
+ label: 'Change',
101
+ format: row => formatNumber(row.change, { signDisplay: 'exceptZero' }),
102
+ },
103
+ changeRate: {
104
+ label: 'Change %',
105
+ format: row => formatPercent(row.changeRate),
106
+ },
107
+ },
108
+ evidence: {
109
+ id: 'samples-by-member',
110
+ glossaryIds: ['sampleCount', 'sampleChange'],
111
+ },
112
+ });
113
+ const selectedMembers = memberView.dataset({
114
+ name: 'Selected-period samples',
65
115
  rowKey: row => row.member,
66
116
  columns: {
67
- member: { label: 'Member', value: row => row.member },
68
- sampleCount: { value: row => row.sampleCount, format: count },
117
+ member: { label: 'Member' },
118
+ currentCount: {
119
+ label: 'Samples',
120
+ format: count,
121
+ },
69
122
  },
70
- evidence: { id: 'samples-by-member', glossaryIds: ['sampleCount'] },
123
+ evidence: { id: 'selected-members', glossaryIds: ['sampleCount'] },
71
124
  });
72
125
  const rowsView = defineView({
73
126
  dataContext: sampleDataContext,
74
127
  operation: 'sampleRows',
75
- isEmpty: rows => rows.length === 0,
76
128
  emptyFallback,
77
129
  });
78
130
  const sampleRows = rowsView.dataset({
79
131
  name: 'Samples',
80
- select: rows => rows,
81
132
  rowKey: row => `${row.periodStart}:${row.member}`,
82
133
  columns: {
83
- periodStart: { label: 'Period start', value: row => row.periodStart },
84
- member: { label: 'Member', value: row => row.member },
85
- sampleCount: { value: row => row.sampleCount, format: count },
134
+ periodStart: { label: 'Period start' },
135
+ member: { label: 'Member' },
136
+ sampleCount: { format: count },
86
137
  },
87
138
  evidence: { id: 'samples', glossaryIds: ['sampleCount'] },
88
139
  });
89
- // The Finding's text is shown above the app; keep content to charts and captions.
90
- const totalContent = totalView.content(result => (
91
- <MetricWidget metric={totalSamples} source={result} />
140
+ // Compare current and previous periods from the same displayed result.
141
+ const totalsContent = totalsView.content(result => (
142
+ <VisualizationWidget
143
+ dataset={totals}
144
+ source={result}
145
+ title={
146
+ result.loading || result.input.period.comparison
147
+ ? 'Period comparison'
148
+ : 'Selected period'
149
+ }
150
+ >
151
+ {rows =>
152
+ result.loading ? null : result.input.period.comparison ? (
153
+ <Comparison
154
+ label="Samples"
155
+ current={{
156
+ value: rows[0]!.currentCount,
157
+ formattedValue: formatCount(rows[0]!.currentCount),
158
+ periodLabel: periodLabel(result.input.period.range),
159
+ }}
160
+ previous={{
161
+ value: rows[0]!.previousCount,
162
+ formattedValue: formatCount(rows[0]!.previousCount, {
163
+ missing: 'Not available',
164
+ }),
165
+ periodLabel: periodLabel(result.input.period.comparison),
166
+ }}
167
+ />
168
+ ) : (
169
+ <Ranking
170
+ items={[
171
+ {
172
+ id: 'selected',
173
+ label: periodLabel(result.input.period.range),
174
+ value: rows[0]!.currentCount,
175
+ },
176
+ ]}
177
+ />
178
+ )
179
+ }
180
+ </VisualizationWidget>
92
181
  ));
93
182
  const trendContent = trendView.content(result => (
94
183
  <VisualizationWidget
95
184
  dataset={trend}
96
185
  source={result}
97
186
  title="Samples over time"
98
- description="Includes the previous period when comparison is on."
99
187
  breakdown={trendView.breakdown('grain')}
100
188
  >
101
189
  {rows => (
@@ -116,34 +204,127 @@ const memberContent = memberView.content(result => (
116
204
  <VisualizationWidget
117
205
  dataset={byMember}
118
206
  source={result}
119
- title="Samples by member"
207
+ title={
208
+ result.loading || result.input.period.comparison
209
+ ? 'Where volume changed'
210
+ : 'Samples by member'
211
+ }
120
212
  breakdown={memberView.breakdown('breakdown')}
121
213
  >
122
214
  {rows => (
123
- <BarChart
215
+ <ComposedChart
124
216
  ariaLabel="Samples by member"
125
- unit="samples"
126
- items={rows.map(row => ({
127
- ...row,
128
- id: row.member,
129
- label: row.member,
130
- value: row.sampleCount,
131
- }))}
132
- />
217
+ data={rows}
218
+ valueFormat={count}
219
+ >
220
+ <ComposedChart.XAxis dataKey="member" />
221
+ <ComposedChart.YAxis />
222
+ {!result.loading && result.input.period.comparison && (
223
+ <ComposedChart.Bar
224
+ dataKey="previousCount"
225
+ name="Previous period"
226
+ fill="var(--atbl-muted)"
227
+ fillOpacity={0.45}
228
+ />
229
+ )}
230
+ <ComposedChart.Bar dataKey="currentCount" name="Selected period" />
231
+ <ComposedChart.Tooltip />
232
+ <ComposedChart.Legend />
233
+ </ComposedChart>
133
234
  )}
134
235
  </VisualizationWidget>
135
236
  ));
237
+ const memberTableContent = memberView.content(result => (
238
+ <TableWidget
239
+ dataset={
240
+ result.loading || result.input.period.comparison
241
+ ? byMember
242
+ : selectedMembers
243
+ }
244
+ source={result}
245
+ title={
246
+ result.loading || result.input.period.comparison
247
+ ? 'Change by member'
248
+ : 'Samples by member'
249
+ }
250
+ />
251
+ ));
136
252
  const rowsContent = rowsView.content(result => (
137
- <TableWidget dataset={sampleRows} source={result} title="Samples" />
253
+ <TableWidget dataset={sampleRows} source={result} title="Sample details" />
138
254
  ));
255
+ // Show this notice when scope or display choices differ from the original finding.
256
+ // Back to finding restores both scope filters and display choices to their defaults.
257
+ function FindingScope() {
258
+ const filters = useAppFilters({
259
+ period: periodFilter,
260
+ groupName,
261
+ grain,
262
+ breakdown,
263
+ });
264
+ const scopeChanged =
265
+ !periodFilter.same(filters.values.period, periodFilter.defaultValue) ||
266
+ !groupName.same(filters.values.groupName, groupName.defaultValue);
267
+ const displayChanged =
268
+ !grain.same(filters.values.grain, grain.defaultValue) ||
269
+ !breakdown.same(filters.values.breakdown, breakdown.defaultValue);
270
+ if (!scopeChanged && !displayChanged) return null;
271
+ return (
272
+ <Notice
273
+ title={
274
+ scopeChanged
275
+ ? 'Exploring a different scope'
276
+ : 'Viewing a different breakdown'
277
+ }
278
+ description={
279
+ <>
280
+ Original finding · {findingPeriodLabel} {periodFilter.policy.timeZone}{' '}
281
+ vs previous period ·{' '}
282
+ {groupName.describe?.(groupName.defaultValue) ??
283
+ groupName.defaultValue}
284
+ </>
285
+ }
286
+ action={
287
+ <Button size="compact" onClick={() => filters.resetAll()}>
288
+ Back to finding
289
+ </Button>
290
+ }
291
+ />
292
+ );
293
+ }
294
+ const views = ['overview', 'data'] as const;
139
295
  export function App() {
296
+ const [view, setView] = useViewTab(views, 'overview');
140
297
  return (
141
- <DataApp view={totalView} showToolbar={false}>
298
+ <DataApp view={trendView} showToolbar={false}>
142
299
  <Stack>
143
- <DataSection content={totalContent} />
144
- <DataSection content={trendContent} />
145
- <DataSection content={memberContent} />
146
- <DataSection content={rowsContent} />
300
+ <FindingScope />
301
+ <Tabs selectedKey={view} onSelectionChange={setView}>
302
+ <TabList aria-label="Finding views">
303
+ <Tab id="overview">Overview</Tab>
304
+ <Tab id="data">Data</Tab>
305
+ </TabList>
306
+ <TabPanels>
307
+ <TabPanel id="overview">
308
+ <Stack>
309
+ <Grid columns={3}>
310
+ <GridItem span={2}>
311
+ <DataSection content={trendContent} />
312
+ </GridItem>
313
+ <GridItem>
314
+ <DataSection content={totalsContent} />
315
+ </GridItem>
316
+ </Grid>
317
+ <DataSection content={memberContent} />
318
+ </Stack>
319
+ </TabPanel>
320
+ <TabPanel id="data">
321
+ <Stack>
322
+ <DataSection content={memberTableContent} />
323
+ <DataSection content={rowsContent} />
324
+ </Stack>
325
+ </TabPanel>
326
+ </TabPanels>
327
+ </Tabs>
147
328
  </Stack>
148
329
  </DataApp>
149
330
  );
@@ -1,19 +1,22 @@
1
1
  import { createDataContext } from '@altertable/data-app-react';
2
- // The browser imports operations by type only, so name their queries here.
3
- const queryNames = {
4
- sampleTotal: 'sampleTotal',
5
- samplesOverTime: 'samplesOverTime',
6
- samplesByMember: 'samplesByMember',
7
- sampleRows: 'sampleRows',
8
- } as const;
9
- export const sampleDataContext = createDataContext(queryNames)({
2
+
3
+ import { dataApp } from '#config';
4
+
5
+ export const sampleDataContext = createDataContext(dataApp.queryNames)({
10
6
  description:
11
- 'Fictional daily samples from starter_demo.daily_samples. Replace this evidence with the actual Finding queries.',
7
+ 'Fictional daily sample counts by group and segment. Comparisons use equal-length periods in UTC.',
12
8
  glossary: {
9
+ sampleChange: {
10
+ term: 'Sample change',
11
+ definition:
12
+ 'Selected-period samples minus the previous equal-length period in the same scope. Missing observations remain unavailable; they are not measured zeroes.',
13
+ queryNames: ['samplesByMember'],
14
+ },
13
15
  sampleCount: {
14
16
  term: 'Sample count',
15
- definition: 'Fixture samples recorded per day, group, and segment.',
16
- queryNames: Object.values(queryNames),
17
+ definition:
18
+ 'Number of samples recorded for each day, group, and segment.',
19
+ queryNames: Object.values(dataApp.queryNames),
17
20
  },
18
21
  },
19
22
  });
@@ -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
- // Declare each filter once in this browser-safe module: operations read them on
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
- const period = dateTimeRangeFilter({
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 grain = displayChoice({
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
- sampleTotal: { period },
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 { injectDataAppStyles, mountDataApp } from '@altertable/data-app-react';
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
- injectDataAppStyles();
7
-
7
+ installLocalQueryLakehouse();
8
8
  mountDataApp({ app: dataApp, component: App });
@@ -1,34 +1,45 @@
1
- import { parseCount } from '@altertable/data-app/contract';
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
- // One query per widget: each section loads its own result when it nears the viewport.
8
+
6
9
  const policy = { maxQueryRows: 500, maxDurationMs: 15000 };
7
- export const operations = {
8
- sampleTotal: dataApp.defineOperation({
9
- filters: operationFilters.sampleTotal,
10
+ export const operations = dataApp.defineOperations({
11
+ sampleTotals: dataApp.defineOperation({
12
+ filters: operationFilters.sampleTotals,
10
13
  policy,
11
- async run({ query }, { period }) {
12
- const current = await query('sampleTotal', { period: period.range });
13
- const previous = period.comparison
14
- ? await query('sampleTotal', { period: period.comparison })
15
- : null;
16
- return {
17
- current: parseCount(current.rows[0]!.sample_count),
18
- previous: previous && parseCount(previous.rows[0]!.sample_count),
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
- // With the comparison on, the trend starts at the previous period.
27
- const range = {
28
- from: period.comparison?.from ?? period.range.from,
29
- to: period.range.to,
30
- };
31
- const result = await query('samplesOverTime', { period: range, grain });
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 result = await query('samplesByMember', {
43
- period: period.range,
44
- breakdown,
45
- });
46
- return result.rows.map(row => ({
47
- member: row.member,
48
- sampleCount: parseCount(row.sample_count),
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
- period: period.range,
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({ page, operations, title: dataApp.title });
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.77.0/docs/app-authoring.md). <!-- x-release-please-version -->
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
  | ------------------------------------------ | ----------------------------------------------- |