@altertable/data-app-examples 0.75.0 → 0.77.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.
@@ -8,15 +8,19 @@ import {
8
8
  createDataHooks,
9
9
  DataApp,
10
10
  DataSection,
11
- VisualizationWidget,
12
- DataValue,
13
- TableWidget,
14
- Ranking,
11
+ MetricWidget,
15
12
  Stack,
16
- TextContent,
13
+ TableWidget,
14
+ VisualizationWidget,
17
15
  } from '@altertable/data-app-react';
16
+ import { BarChart, ComposedChart } from '@altertable/data-app-react/ui';
18
17
  import { createDataClient } from '@altertable/data-app/client';
19
- import { parseCount } from '@altertable/data-app/contract';
18
+ import {
19
+ dateTimeRangeFilter,
20
+ displayChoice,
21
+ parseCount,
22
+ } from '@altertable/data-app/contract';
23
+ // One query per widget: each section loads its own result when it nears the viewport.
20
24
  const dataApp = defineDataApp({
21
25
  title: 'Sample finding',
22
26
  description:
@@ -24,152 +28,311 @@ const dataApp = defineDataApp({
24
28
  scope: { organization: 'demo', environment: 'sample' },
25
29
  appearance: { theme: 'system' },
26
30
  queries: {
27
- sampleCountsByGroup: {
31
+ sampleTotal: {
32
+ projections: { sample_count: { type: 'number' } },
33
+ statement: `
34
+ SELECT COALESCE(SUM(sample_count), 0) AS sample_count
35
+ FROM starter_demo.daily_samples
36
+ WHERE sample_date >= $period.from AND sample_date < $period.to`,
37
+ params: { period: { type: 'dateTimeRange' } },
38
+ },
39
+ samplesOverTime: {
28
40
  projections: {
29
- group_name: { type: 'string' },
41
+ period_start: { type: 'string' },
30
42
  sample_count: { type: 'number' },
31
43
  },
32
44
  statement: `
33
- SELECT group_name, SUM(sample_count) AS sample_count
34
- FROM starter_demo.sample_counts
35
- WHERE $groupName = '' OR group_name = $groupName
36
- GROUP BY group_name ORDER BY sample_count DESC LIMIT $limit`,
45
+ SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
46
+ SUM(sample_count) AS sample_count
47
+ FROM starter_demo.daily_samples
48
+ WHERE sample_date >= $period.from AND sample_date < $period.to
49
+ GROUP BY ALL ORDER BY period_start LIMIT 200`,
37
50
  params: {
38
- groupName: { type: 'string', defaultValue: '' },
39
- limit: { type: 'number', defaultValue: 10 },
51
+ period: { type: 'dateTimeRange' },
52
+ grain: { type: 'string', defaultValue: 'day' },
53
+ },
54
+ },
55
+ samplesByMember: {
56
+ projections: {
57
+ member: { type: 'string' },
58
+ sample_count: { type: 'number' },
59
+ },
60
+ statement: `
61
+ SELECT CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
62
+ SUM(sample_count) AS sample_count
63
+ FROM starter_demo.daily_samples
64
+ WHERE sample_date >= $period.from AND sample_date < $period.to
65
+ GROUP BY ALL ORDER BY sample_count DESC LIMIT 50`,
66
+ params: {
67
+ period: { type: 'dateTimeRange' },
68
+ breakdown: { type: 'string', defaultValue: 'segment' },
69
+ },
70
+ },
71
+ sampleRows: {
72
+ projections: {
73
+ period_start: { type: 'string' },
74
+ member: { type: 'string' },
75
+ sample_count: { type: 'number' },
76
+ },
77
+ statement: `
78
+ SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
79
+ CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
80
+ SUM(sample_count) AS sample_count
81
+ FROM starter_demo.daily_samples
82
+ WHERE sample_date >= $period.from AND sample_date < $period.to
83
+ GROUP BY ALL ORDER BY period_start, member LIMIT 500`,
84
+ params: {
85
+ period: { type: 'dateTimeRange' },
86
+ grain: { type: 'string', defaultValue: 'day' },
87
+ breakdown: { type: 'string', defaultValue: 'segment' },
40
88
  },
41
89
  },
42
90
  },
43
91
  });
92
+ // Declare each filter once; each operation lists the filters it reads.
93
+ const findingPeriod = {
94
+ from: new Date('2026-03-09T00:00:00Z'),
95
+ to: new Date('2026-03-16T00:00:00Z'),
96
+ };
97
+ const period = dateTimeRangeFilter({
98
+ key: 'period',
99
+ defaultValue: findingPeriod,
100
+ minDate: '2026-01-05',
101
+ maxDate: '2026-03-29',
102
+ maxRangeDays: 28,
103
+ comparison: 'off',
104
+ presets: [{ label: 'Finding period', range: findingPeriod }],
105
+ });
106
+ const grain = displayChoice({
107
+ key: 'grain',
108
+ label: 'Grain',
109
+ defaultValue: 'day',
110
+ options: [
111
+ { id: 'day', label: 'Day' },
112
+ { id: 'week', label: 'Week' },
113
+ ],
114
+ presentation: { control: 'widget' },
115
+ });
116
+ const breakdown = displayChoice({
117
+ key: 'breakdown',
118
+ label: 'Breakdown',
119
+ defaultValue: 'segment',
120
+ options: [
121
+ { id: 'segment', label: 'Segment' },
122
+ { id: 'group', label: 'Group' },
123
+ ],
124
+ presentation: { control: 'widget' },
125
+ });
126
+ const policy = { maxQueryRows: 500, maxDurationMs: 15000 };
44
127
  const operations = {
45
- sampleCountsByGroup: dataApp.defineOperation({
46
- input: () => ({}),
47
- checks: [{}],
48
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
49
- async run({ query }) {
50
- const result = await query('sampleCountsByGroup', {});
128
+ sampleTotal: dataApp.defineOperation({
129
+ filters: { period },
130
+ policy,
131
+ async run({ query }, { period }) {
132
+ const current = await query('sampleTotal', { period: period.range });
133
+ const previous = period.comparison
134
+ ? await query('sampleTotal', { period: period.comparison })
135
+ : null;
136
+ return {
137
+ current: parseCount(current.rows[0]!.sample_count),
138
+ previous: previous && parseCount(previous.rows[0]!.sample_count),
139
+ };
140
+ },
141
+ }),
142
+ samplesOverTime: dataApp.defineOperation({
143
+ filters: { period, grain },
144
+ policy,
145
+ async run({ query }, { period, grain }) {
146
+ // With the comparison on, the trend starts at the previous period.
147
+ const range = {
148
+ from: period.comparison?.from ?? period.range.from,
149
+ to: period.range.to,
150
+ };
151
+ const result = await query('samplesOverTime', { period: range, grain });
152
+ return result.rows.map(row => ({
153
+ periodStart: row.period_start,
154
+ sampleCount: parseCount(row.sample_count),
155
+ }));
156
+ },
157
+ }),
158
+ samplesByMember: dataApp.defineOperation({
159
+ filters: { period, breakdown },
160
+ policy,
161
+ async run({ query }, { period, breakdown }) {
162
+ const result = await query('samplesByMember', {
163
+ period: period.range,
164
+ breakdown,
165
+ });
166
+ return result.rows.map(row => ({
167
+ member: row.member,
168
+ sampleCount: parseCount(row.sample_count),
169
+ }));
170
+ },
171
+ }),
172
+ sampleRows: dataApp.defineOperation({
173
+ filters: { period, grain, breakdown },
174
+ policy,
175
+ async run({ query }, { period, grain, breakdown }) {
176
+ const result = await query('sampleRows', {
177
+ period: period.range,
178
+ grain,
179
+ breakdown,
180
+ });
51
181
  return result.rows.map(row => ({
52
- groupName: row.group_name,
182
+ periodStart: row.period_start,
183
+ member: row.member,
53
184
  sampleCount: parseCount(row.sample_count),
54
185
  }));
55
186
  },
56
187
  }),
57
188
  };
58
- const queryNames = operations.sampleCountsByGroup.queryNames;
189
+ const queryNames = {
190
+ ...operations.sampleTotal.queryNames,
191
+ ...operations.samplesOverTime.queryNames,
192
+ ...operations.samplesByMember.queryNames,
193
+ ...operations.sampleRows.queryNames,
194
+ };
59
195
  const sampleDataContext = createDataContext(queryNames)({
60
196
  description:
61
- 'Fictional sample volumes grouped from starter_demo.sample_counts. Replace this evidence with the actual Finding queries.',
197
+ 'Fictional daily samples from starter_demo.daily_samples. Replace this evidence with the actual Finding queries.',
62
198
  glossary: {
63
199
  sampleCount: {
64
200
  term: 'Sample count',
65
- definition: 'A fixture value: Alpha is 2,200,000 and Beta is 600,000.',
66
- queryNames: [queryNames.sampleCountsByGroup],
201
+ definition: 'Fixture samples recorded per day, group, and segment.',
202
+ queryNames: Object.values(queryNames),
67
203
  },
68
204
  },
69
205
  });
70
- const { defineDataView } = createDataHooks(createDataClient({ operations }));
71
- const sampleCountsView = defineDataView({
206
+ const { defineView } = createDataHooks(createDataClient({ operations }));
207
+ const count = { kind: 'count' } as const;
208
+ const emptyFallback = {
209
+ title: 'No samples in this period',
210
+ description: 'No observations are available for this period.',
211
+ };
212
+ const totalView = defineView({
72
213
  dataContext: sampleDataContext,
73
- operation: 'sampleCountsByGroup',
74
- describeInput: () => 'fixture groups',
75
- isEmpty: sampleCounts => sampleCounts.length === 0,
76
- emptyFallback: {
77
- title: 'No matching groups',
78
- description: 'No observations are available for this query.',
214
+ operation: 'sampleTotal',
215
+ });
216
+ const totalSamples = totalView.metric(
217
+ {
218
+ id: 'total-samples',
219
+ label: 'Samples',
220
+ glossaryId: 'sampleCount',
221
+ format: count,
79
222
  },
223
+ total => ({
224
+ current: total.current,
225
+ ...(total.previous !== null && { previous: total.previous }),
226
+ })
227
+ );
228
+ const trendView = defineView({
229
+ dataContext: sampleDataContext,
230
+ operation: 'samplesOverTime',
231
+ isEmpty: rows => rows.length === 0,
232
+ emptyFallback,
80
233
  });
81
- const sampleCounts = sampleCountsView.dataset({
82
- name: 'Sample counts',
234
+ const trend = trendView.dataset({
235
+ name: 'Samples over time',
83
236
  select: rows => rows,
84
- rowKey: row => row.groupName,
237
+ rowKey: row => row.periodStart,
85
238
  columns: {
86
- groupName: { label: 'Group', value: row => row.groupName },
87
- sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
88
- },
89
- evidence: {
90
- id: 'counts-by-group',
91
- glossaryIds: ['sampleCount'],
239
+ periodStart: { label: 'Period start', value: row => row.periodStart },
240
+ sampleCount: { value: row => row.sampleCount, format: count },
92
241
  },
242
+ evidence: { id: 'samples-over-time', glossaryIds: ['sampleCount'] },
93
243
  });
94
- const totalSamples = sampleCountsView.metric(
95
- {
96
- id: 'total-samples',
97
- label: 'Total samples',
98
- glossaryId: 'sampleCount',
99
- format: { kind: 'count' },
244
+ const memberView = defineView({
245
+ dataContext: sampleDataContext,
246
+ operation: 'samplesByMember',
247
+ isEmpty: rows => rows.length === 0,
248
+ emptyFallback,
249
+ });
250
+ const byMember = memberView.dataset({
251
+ name: 'Samples by member',
252
+ select: rows => rows,
253
+ rowKey: row => row.member,
254
+ columns: {
255
+ member: { label: 'Member', value: row => row.member },
256
+ sampleCount: { value: row => row.sampleCount, format: count },
100
257
  },
101
- rows => ({ current: rows.reduce((sum, row) => sum + row.sampleCount, 0) })
102
- );
103
- const alphaSamples = sampleCountsView.metric(
104
- {
105
- id: 'alpha-samples',
106
- label: 'Alpha samples',
107
- glossaryId: 'sampleCount',
108
- format: { kind: 'count' },
258
+ evidence: { id: 'samples-by-member', glossaryIds: ['sampleCount'] },
259
+ });
260
+ const rowsView = defineView({
261
+ dataContext: sampleDataContext,
262
+ operation: 'sampleRows',
263
+ isEmpty: rows => rows.length === 0,
264
+ emptyFallback,
265
+ });
266
+ const sampleRows = rowsView.dataset({
267
+ name: 'Samples',
268
+ select: rows => rows,
269
+ rowKey: row => `${row.periodStart}:${row.member}`,
270
+ columns: {
271
+ periodStart: { label: 'Period start', value: row => row.periodStart },
272
+ member: { label: 'Member', value: row => row.member },
273
+ sampleCount: { value: row => row.sampleCount, format: count },
109
274
  },
110
- rows => {
111
- const alpha = rows.find(row => row.groupName === 'Alpha');
112
- if (!alpha)
113
- throw new Error('The sample Finding requires evidence for Alpha.');
114
- return { current: alpha.sampleCount };
115
- }
116
- );
117
- // This fictional Finding demonstrates prose, inline evidence, and a Markdown-table equivalent.
118
- // Preserve each real Finding's own headings and argument instead of reusing these sections.
119
- const sampleContent = sampleCountsView.content(result => (
120
- <Stack>
121
- <TextContent>
122
- <h2>Contribution by group</h2>
123
- <p>
124
- <strong>Alpha</strong> contributed{' '}
125
- <DataValue metric={alphaSamples} source={result} /> of the{' '}
126
- <DataValue metric={totalSamples} source={result} /> recorded samples.
127
- The group comparison below supports that concentration; it does not
128
- explain its cause.
129
- </p>
130
- </TextContent>
131
- <VisualizationWidget
132
- dataset={sampleCounts}
133
- source={result}
134
- title="Sample count"
135
- >
136
- {rows => (
137
- <Ranking
138
- aria-label="Samples by group"
139
- items={rows.map(row => ({
140
- id: row.groupName,
141
- label: row.groupName,
142
- value: row.sampleCount,
143
- }))}
144
- />
145
- )}
146
- </VisualizationWidget>
147
- <TextContent>
148
- <h2>Supporting evidence</h2>
149
- <p>
150
- The source rows are grouped by <code>group_name</code> and summed using{' '}
151
- <code>sample_count</code>. The table retains the exact values behind the
152
- comparison.
153
- </p>
154
- <ul>
155
- <li>Compare the groups within the same sample population.</li>
156
- <li>
157
- <em>Volume alone does not establish performance or causality.</em>
158
- </li>
159
- </ul>
160
- </TextContent>
161
- <TableWidget
162
- dataset={sampleCounts}
163
- source={result}
164
- title="Counts by group"
165
- pagination={false}
166
- />
167
- </Stack>
275
+ evidence: { id: 'samples', glossaryIds: ['sampleCount'] },
276
+ });
277
+ // The Finding's text is shown above the app; keep content to charts and captions.
278
+ const totalContent = totalView.content(result => (
279
+ <MetricWidget metric={totalSamples} source={result} />
280
+ ));
281
+ const trendContent = trendView.content(result => (
282
+ <VisualizationWidget
283
+ dataset={trend}
284
+ source={result}
285
+ title="Samples over time"
286
+ description="Includes the previous period when comparison is on."
287
+ breakdown={trendView.breakdown('grain')}
288
+ >
289
+ {rows => (
290
+ <ComposedChart
291
+ ariaLabel="Samples over time"
292
+ data={rows}
293
+ valueFormat={count}
294
+ >
295
+ <ComposedChart.XAxis dataKey="periodStart" />
296
+ <ComposedChart.YAxis />
297
+ <ComposedChart.Line dataKey="sampleCount" name="Samples" />
298
+ <ComposedChart.Tooltip />
299
+ </ComposedChart>
300
+ )}
301
+ </VisualizationWidget>
302
+ ));
303
+ const memberContent = memberView.content(result => (
304
+ <VisualizationWidget
305
+ dataset={byMember}
306
+ source={result}
307
+ title="Samples by member"
308
+ breakdown={memberView.breakdown('breakdown')}
309
+ >
310
+ {rows => (
311
+ <BarChart
312
+ ariaLabel="Samples by member"
313
+ unit="samples"
314
+ items={rows.map(row => ({
315
+ ...row,
316
+ id: row.member,
317
+ label: row.member,
318
+ value: row.sampleCount,
319
+ }))}
320
+ />
321
+ )}
322
+ </VisualizationWidget>
323
+ ));
324
+ const rowsContent = rowsView.content(result => (
325
+ <TableWidget dataset={sampleRows} source={result} title="Samples" />
168
326
  ));
169
327
  function App() {
170
328
  return (
171
- <DataApp view={sampleCountsView} showToolbar={false}>
172
- <DataSection content={sampleContent} />
329
+ <DataApp view={totalView} showToolbar={false}>
330
+ <Stack>
331
+ <DataSection content={totalContent} />
332
+ <DataSection content={trendContent} />
333
+ <DataSection content={memberContent} />
334
+ <DataSection content={rowsContent} />
335
+ </Stack>
173
336
  </DataApp>
174
337
  );
175
338
  }
@@ -2,16 +2,16 @@
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.75.0/docs/app-authoring.md). <!-- x-release-please-version -->
5
+ [version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.77.0/docs/app-authoring.md). <!-- x-release-please-version -->
6
6
 
7
- | Task | App-owned files |
8
- | ------------------------------------------ | -------------------------------------------------------- |
9
- | Define queries and inputs | `app.ts`, `src/operations.ts`, optional shared contracts |
10
- | Compose app content and supported features | `src/App.tsx` |
11
- | Bind definitions and source evidence | `src/data-context.ts` |
12
- | Change identity and appearance | `app.ts` |
13
- | Inject styles and mount React | `src/main.tsx` |
14
- | Configure local serving | `src/server.ts` |
7
+ | Task | App-owned files |
8
+ | ------------------------------------------ | ------------------------------------------------------ |
9
+ | Define queries, filters, and operations | `app.ts`, `src/operations.ts`, shared `src/filters.ts` |
10
+ | Compose app content and supported features | `src/App.tsx` |
11
+ | Bind definitions and source evidence | `src/data-context.ts` |
12
+ | Change identity and appearance | `app.ts` |
13
+ | Inject styles and mount React | `src/main.tsx` |
14
+ | Configure local serving | `src/server.ts` |
15
15
 
16
16
  See [README.md](README.md) for setup and checks.
17
17
 
@@ -1,7 +1,7 @@
1
1
  # Local data app starter
2
2
 
3
3
  Use `node_modules/@altertable/data-app/docs/app-authoring.md` for this SDK version.
4
- Otherwise, read the [version-matched authoring recipe](https://github.com/altertable-ai/data-app/blob/v0.75.0/docs/app-authoring.md). <!-- x-release-please-version -->
4
+ Otherwise, read the [version-matched authoring recipe](https://github.com/altertable-ai/data-app/blob/v0.77.0/docs/app-authoring.md). <!-- x-release-please-version -->
5
5
  See [AGENTS.md](AGENTS.md) for app-owned files.
6
6
 
7
7
  ## Run the app
@@ -17,9 +17,9 @@
17
17
  "lint:fix": "oxlint --type-aware --fix src"
18
18
  },
19
19
  "dependencies": {
20
- "@altertable/data-app": "0.75.0",
21
- "@altertable/data-app-bun": "0.75.0",
22
- "@altertable/data-app-react": "0.75.0",
20
+ "@altertable/data-app": "0.77.0",
21
+ "@altertable/data-app-bun": "0.77.0",
22
+ "@altertable/data-app-react": "0.77.0",
23
23
  "react": "19.3.1",
24
24
  "react-dom": "19.3.1"
25
25
  },
@@ -2,16 +2,16 @@
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.75.0/docs/app-authoring.md). <!-- x-release-please-version -->
5
+ [version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.77.0/docs/app-authoring.md). <!-- x-release-please-version -->
6
6
 
7
- | Task | App-owned files |
8
- | ------------------------------------------ | -------------------------------------------------------- |
9
- | Define queries and inputs | `app.ts`, `src/operations.ts`, optional shared contracts |
10
- | Compose app content and supported features | `src/App.tsx` |
11
- | Bind definitions and source evidence | `src/data-context.ts` |
12
- | Change identity and appearance | `app.ts` |
13
- | Inject styles and mount React | `src/main.tsx` |
14
- | Configure local serving | `src/server.ts` |
7
+ | Task | App-owned files |
8
+ | ------------------------------------------ | ------------------------------------------------------ |
9
+ | Define queries, filters, and operations | `app.ts`, `src/operations.ts`, shared `src/filters.ts` |
10
+ | Compose app content and supported features | `src/App.tsx` |
11
+ | Bind definitions and source evidence | `src/data-context.ts` |
12
+ | Change identity and appearance | `app.ts` |
13
+ | Inject styles and mount React | `src/main.tsx` |
14
+ | Configure local serving | `src/server.ts` |
15
15
 
16
16
  See [README.md](README.md) for setup and checks.
17
17
 
@@ -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.75.0/docs/app-authoring.md). <!-- x-release-please-version -->
4
+ Otherwise, read the [version-matched authoring recipe](https://github.com/altertable-ai/data-app/blob/v0.77.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.75.0/docs/local-data-apps.md#preview-the-use-case-starters). <!-- x-release-please-version -->
8
+ [local preview guide](https://github.com/altertable-ai/data-app/blob/v0.77.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
 
@@ -1,4 +1,5 @@
1
1
  import { defineDataApp } from '@altertable/data-app';
2
+
2
3
  export const dataApp = defineDataApp({
3
4
  title: 'Sample finding',
4
5
  description:
@@ -6,19 +7,63 @@ export const dataApp = defineDataApp({
6
7
  scope: { organization: 'demo', environment: 'sample' },
7
8
  appearance: { theme: 'system' },
8
9
  queries: {
9
- sampleCountsByGroup: {
10
+ sampleTotal: {
11
+ projections: { sample_count: { type: 'number' } },
12
+ statement: `
13
+ SELECT COALESCE(SUM(sample_count), 0) AS sample_count
14
+ FROM starter_demo.daily_samples
15
+ WHERE sample_date >= $period.from AND sample_date < $period.to`,
16
+ params: { period: { type: 'dateTimeRange' } },
17
+ },
18
+ samplesOverTime: {
19
+ projections: {
20
+ period_start: { type: 'string' },
21
+ sample_count: { type: 'number' },
22
+ },
23
+ statement: `
24
+ SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
25
+ SUM(sample_count) AS sample_count
26
+ FROM starter_demo.daily_samples
27
+ WHERE sample_date >= $period.from AND sample_date < $period.to
28
+ GROUP BY ALL ORDER BY period_start LIMIT 200`,
29
+ params: {
30
+ period: { type: 'dateTimeRange' },
31
+ grain: { type: 'string', defaultValue: 'day' },
32
+ },
33
+ },
34
+ samplesByMember: {
35
+ projections: {
36
+ member: { type: 'string' },
37
+ sample_count: { type: 'number' },
38
+ },
39
+ statement: `
40
+ SELECT CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
41
+ SUM(sample_count) AS sample_count
42
+ FROM starter_demo.daily_samples
43
+ WHERE sample_date >= $period.from AND sample_date < $period.to
44
+ GROUP BY ALL ORDER BY sample_count DESC LIMIT 50`,
45
+ params: {
46
+ period: { type: 'dateTimeRange' },
47
+ breakdown: { type: 'string', defaultValue: 'segment' },
48
+ },
49
+ },
50
+ sampleRows: {
10
51
  projections: {
11
- group_name: { type: 'string' },
52
+ period_start: { type: 'string' },
53
+ member: { type: 'string' },
12
54
  sample_count: { type: 'number' },
13
55
  },
14
56
  statement: `
15
- SELECT group_name, SUM(sample_count) AS sample_count
16
- FROM starter_demo.sample_counts
17
- WHERE $groupName = '' OR group_name = $groupName
18
- GROUP BY group_name ORDER BY sample_count DESC LIMIT $limit`,
57
+ SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
58
+ CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
59
+ SUM(sample_count) AS sample_count
60
+ FROM starter_demo.daily_samples
61
+ WHERE sample_date >= $period.from AND sample_date < $period.to
62
+ GROUP BY ALL ORDER BY period_start, member LIMIT 500`,
19
63
  params: {
20
- groupName: { type: 'string', defaultValue: '' },
21
- limit: { type: 'number', defaultValue: 10 },
64
+ period: { type: 'dateTimeRange' },
65
+ grain: { type: 'string', defaultValue: 'day' },
66
+ breakdown: { type: 'string', defaultValue: 'segment' },
22
67
  },
23
68
  },
24
69
  },
@@ -17,9 +17,9 @@
17
17
  "lint:fix": "oxlint --type-aware --fix src"
18
18
  },
19
19
  "dependencies": {
20
- "@altertable/data-app": "0.75.0",
21
- "@altertable/data-app-bun": "0.75.0",
22
- "@altertable/data-app-react": "0.75.0",
20
+ "@altertable/data-app": "0.77.0",
21
+ "@altertable/data-app-bun": "0.77.0",
22
+ "@altertable/data-app-react": "0.77.0",
23
23
  "react": "19.3.1",
24
24
  "react-dom": "19.3.1"
25
25
  },