@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.
Files changed (34) hide show
  1. package/package.json +1 -1
  2. package/templates/starter-data-app/index.tsx +681 -134
  3. package/templates/starter-finding-data-app/index.tsx +382 -98
  4. package/templates/starter-local-data-app/AGENTS.md +9 -9
  5. package/templates/starter-local-data-app/README.md +14 -5
  6. package/templates/starter-local-data-app/app.ts +256 -21
  7. package/templates/starter-local-data-app/package.json +5 -5
  8. package/templates/starter-local-data-app/src/App.tsx +276 -5
  9. package/templates/starter-local-data-app/src/data-context.ts +28 -14
  10. package/templates/starter-local-data-app/src/filters.ts +35 -0
  11. package/templates/starter-local-data-app/src/main.tsx +3 -3
  12. package/templates/starter-local-data-app/src/operations.ts +129 -4
  13. package/templates/starter-local-data-app/src/server.ts +1 -2
  14. package/templates/starter-local-finding-data-app/AGENTS.md +1 -1
  15. package/templates/starter-local-finding-data-app/README.md +3 -4
  16. package/templates/starter-local-finding-data-app/app.ts +29 -11
  17. package/templates/starter-local-finding-data-app/package.json +5 -5
  18. package/templates/starter-local-finding-data-app/src/App.tsx +241 -44
  19. package/templates/starter-local-finding-data-app/src/data-context.ts +17 -8
  20. package/templates/starter-local-finding-data-app/src/filters.ts +29 -11
  21. package/templates/starter-local-finding-data-app/src/main.tsx +3 -3
  22. package/templates/starter-local-finding-data-app/src/operations.ts +80 -34
  23. package/templates/starter-local-finding-data-app/src/server.ts +4 -2
  24. package/templates/starter-local-metric-data-app/AGENTS.md +1 -1
  25. package/templates/starter-local-metric-data-app/README.md +3 -4
  26. package/templates/starter-local-metric-data-app/app.ts +5 -2
  27. package/templates/starter-local-metric-data-app/package.json +5 -5
  28. package/templates/starter-local-metric-data-app/src/App.tsx +21 -22
  29. package/templates/starter-local-metric-data-app/src/data-context.ts +9 -5
  30. package/templates/starter-local-metric-data-app/src/filters.ts +1 -3
  31. package/templates/starter-local-metric-data-app/src/main.tsx +3 -3
  32. package/templates/starter-local-metric-data-app/src/operations.ts +3 -3
  33. package/templates/starter-local-metric-data-app/src/server.ts +4 -2
  34. package/templates/starter-metric-data-app/index.tsx +34 -34
@@ -1,40 +1,66 @@
1
1
  import { defineDataApp } from '@altertable/data-app';
2
2
  import {
3
3
  createDataContext,
4
- injectDataAppStyles,
5
- mountDataApp,
6
- } from '@altertable/data-app-react';
7
- import {
8
4
  createDataHooks,
5
+ mountDataApp,
9
6
  DataApp,
10
7
  DataSection,
11
- MetricWidget,
8
+ Button,
9
+ Grid,
10
+ GridItem,
11
+ Notice,
12
12
  Stack,
13
13
  TableWidget,
14
14
  VisualizationWidget,
15
+ Ranking,
16
+ Comparison,
15
17
  } from '@altertable/data-app-react';
16
- import { BarChart, ComposedChart } from '@altertable/data-app-react/ui';
17
- import { createDataClient } from '@altertable/data-app/client';
18
18
  import {
19
+ Tabs,
20
+ TabList,
21
+ Tab,
22
+ TabPanels,
23
+ TabPanel,
24
+ useViewTab,
25
+ ComposedChart,
26
+ useAppFilters,
27
+ } from '@altertable/data-app-react/ui';
28
+ import {
29
+ choiceFilter,
19
30
  dateTimeRangeFilter,
20
31
  displayChoice,
21
32
  parseCount,
33
+ queryDateTimeRangeParams,
22
34
  } from '@altertable/data-app/contract';
23
- // One query per widget: each section loads its own result when it nears the viewport.
24
- const dataApp = defineDataApp({
35
+ import {
36
+ formatDateRange,
37
+ formatCount,
38
+ formatNumber,
39
+ formatPercent,
40
+ } from '@altertable/data-app/format';
41
+ export const dataApp = defineDataApp({
42
+ // Replace the demo title, description, and scope labels with the app's identity.
25
43
  title: 'Sample finding',
26
44
  description:
27
- 'Fixture evidence; replace with the Finding and its supporting queries.',
45
+ 'Explore sample volume over time and across groups and segments.',
28
46
  scope: { organization: 'demo', environment: 'sample' },
29
47
  appearance: { theme: 'system' },
48
+ // starter_demo.daily_samples contains seeded fictional observations.
49
+ // Replace these queries with verified sources before publishing.
30
50
  queries: {
31
- sampleTotal: {
51
+ sampleTotals: {
32
52
  projections: { sample_count: { type: 'number' } },
33
53
  statement: `
34
- SELECT COALESCE(SUM(sample_count), 0) AS sample_count
54
+ SELECT SUM(sample_count) AS sample_count
35
55
  FROM starter_demo.daily_samples
36
- WHERE sample_date >= $period.from AND sample_date < $period.to`,
37
- params: { period: { type: 'dateTimeRange' } },
56
+ WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
57
+ AND ($groupName = 'all' OR group_name = $groupName)
58
+ HAVING COUNT(*) > 0`,
59
+ params: {
60
+ groupName: { type: 'string', defaultValue: 'Alpha' },
61
+ period_from: { type: 'string' },
62
+ period_to: { type: 'string' },
63
+ },
38
64
  },
39
65
  samplesOverTime: {
40
66
  projections: {
@@ -45,10 +71,13 @@ WHERE sample_date >= $period.from AND sample_date < $period.to`,
45
71
  SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
46
72
  SUM(sample_count) AS sample_count
47
73
  FROM starter_demo.daily_samples
48
- WHERE sample_date >= $period.from AND sample_date < $period.to
74
+ WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
75
+ AND ($groupName = 'all' OR group_name = $groupName)
49
76
  GROUP BY ALL ORDER BY period_start LIMIT 200`,
50
77
  params: {
51
- period: { type: 'dateTimeRange' },
78
+ groupName: { type: 'string', defaultValue: 'Alpha' },
79
+ period_from: { type: 'string' },
80
+ period_to: { type: 'string' },
52
81
  grain: { type: 'string', defaultValue: 'day' },
53
82
  },
54
83
  },
@@ -61,10 +90,13 @@ GROUP BY ALL ORDER BY period_start LIMIT 200`,
61
90
  SELECT CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
62
91
  SUM(sample_count) AS sample_count
63
92
  FROM starter_demo.daily_samples
64
- WHERE sample_date >= $period.from AND sample_date < $period.to
93
+ WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
94
+ AND ($groupName = 'all' OR group_name = $groupName)
65
95
  GROUP BY ALL ORDER BY sample_count DESC LIMIT 50`,
66
96
  params: {
67
- period: { type: 'dateTimeRange' },
97
+ groupName: { type: 'string', defaultValue: 'Alpha' },
98
+ period_from: { type: 'string' },
99
+ period_to: { type: 'string' },
68
100
  breakdown: { type: 'string', defaultValue: 'segment' },
69
101
  },
70
102
  },
@@ -79,30 +111,51 @@ SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
79
111
  CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
80
112
  SUM(sample_count) AS sample_count
81
113
  FROM starter_demo.daily_samples
82
- WHERE sample_date >= $period.from AND sample_date < $period.to
114
+ WHERE sample_date >= CAST($period_from AS TIMESTAMP) AND sample_date < CAST($period_to AS TIMESTAMP)
115
+ AND ($groupName = 'all' OR group_name = $groupName)
83
116
  GROUP BY ALL ORDER BY period_start, member LIMIT 500`,
84
117
  params: {
85
- period: { type: 'dateTimeRange' },
118
+ groupName: { type: 'string', defaultValue: 'Alpha' },
119
+ period_from: { type: 'string' },
120
+ period_to: { type: 'string' },
86
121
  grain: { type: 'string', defaultValue: 'day' },
87
122
  breakdown: { type: 'string', defaultValue: 'segment' },
88
123
  },
89
124
  },
90
125
  },
91
126
  });
92
- // Declare each filter once; each operation lists the filters it reads.
127
+ // Replace this fictional finding period with the period supported by its evidence.
93
128
  const findingPeriod = {
94
129
  from: new Date('2026-03-09T00:00:00Z'),
95
130
  to: new Date('2026-03-16T00:00:00Z'),
96
131
  };
97
- const period = dateTimeRangeFilter({
132
+ function periodLabel(range: { from: Date; to: Date }) {
133
+ return formatDateRange({
134
+ start: range.from.toISOString().slice(0, 10),
135
+ end: new Date(range.to.getTime() - 1).toISOString().slice(0, 10),
136
+ });
137
+ }
138
+ const findingPeriodLabel = periodLabel(findingPeriod);
139
+ const periodFilter = dateTimeRangeFilter({
98
140
  key: 'period',
99
141
  defaultValue: findingPeriod,
142
+ comparison: 'on',
143
+ // These bounds match the seeded demo history. Use the real source coverage.
100
144
  minDate: '2026-01-05',
101
145
  maxDate: '2026-03-29',
102
146
  maxRangeDays: 28,
103
- comparison: 'off',
104
147
  presets: [{ label: 'Finding period', range: findingPeriod }],
105
148
  });
149
+ const groupName = choiceFilter({
150
+ key: 'group',
151
+ label: 'Group',
152
+ defaultValue: 'Alpha',
153
+ options: [
154
+ { id: 'all', label: 'All groups' },
155
+ { id: 'Alpha', label: 'Alpha' },
156
+ { id: 'Beta', label: 'Beta' },
157
+ ],
158
+ });
106
159
  const grain = displayChoice({
107
160
  key: 'grain',
108
161
  label: 'Grain',
@@ -123,32 +176,47 @@ const breakdown = displayChoice({
123
176
  ],
124
177
  presentation: { control: 'widget' },
125
178
  });
179
+
180
+ const operationFilters = {
181
+ sampleTotals: { period: periodFilter, groupName },
182
+ samplesOverTime: { period: periodFilter, groupName, grain },
183
+ samplesByMember: { period: periodFilter, groupName, breakdown },
184
+ sampleRows: { period: periodFilter, groupName, grain, breakdown },
185
+ };
126
186
  const policy = { maxQueryRows: 500, maxDurationMs: 15000 };
127
- const operations = {
128
- sampleTotal: dataApp.defineOperation({
129
- filters: { period },
187
+ export const operations = dataApp.defineOperations({
188
+ sampleTotals: dataApp.defineOperation({
189
+ filters: operationFilters.sampleTotals,
130
190
  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
- };
191
+ async run({ query }, { period, groupName }) {
192
+ const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
193
+ const [current, previous] = await Promise.all([
194
+ query('sampleTotals', { ...bounds.current, groupName }),
195
+ bounds.comparison
196
+ ? query('sampleTotals', { ...bounds.comparison, groupName })
197
+ : null,
198
+ ]);
199
+ const row = current.rows[0];
200
+ if (!row) return [];
201
+ const baseline = previous?.rows[0];
202
+ return [
203
+ {
204
+ currentCount: parseCount(row.sample_count),
205
+ previousCount: baseline ? parseCount(baseline.sample_count) : null,
206
+ },
207
+ ];
140
208
  },
141
209
  }),
142
210
  samplesOverTime: dataApp.defineOperation({
143
- filters: { period, grain },
211
+ filters: operationFilters.samplesOverTime,
144
212
  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 });
213
+ async run({ query }, { period, groupName, grain }) {
214
+ const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
215
+ const result = await query('samplesOverTime', {
216
+ ...bounds.combined,
217
+ groupName,
218
+ grain,
219
+ });
152
220
  return result.rows.map(row => ({
153
221
  periodStart: row.period_start,
154
222
  sampleCount: parseCount(row.sample_count),
@@ -156,25 +224,60 @@ const operations = {
156
224
  },
157
225
  }),
158
226
  samplesByMember: dataApp.defineOperation({
159
- filters: { period, breakdown },
227
+ filters: operationFilters.samplesByMember,
160
228
  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
- }));
229
+ async run({ query }, { period, groupName, breakdown }) {
230
+ const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
231
+ const [current, previous] = await Promise.all([
232
+ query('samplesByMember', { ...bounds.current, groupName, breakdown }),
233
+ bounds.comparison
234
+ ? query('samplesByMember', {
235
+ ...bounds.comparison,
236
+ groupName,
237
+ breakdown,
238
+ })
239
+ : null,
240
+ ]);
241
+ const currentCounts = new Map(
242
+ current.rows.map(row => [row.member, parseCount(row.sample_count)])
243
+ );
244
+ const previousCounts = new Map(
245
+ previous?.rows.map(row => [row.member, parseCount(row.sample_count)])
246
+ );
247
+ const members = new Set([
248
+ ...currentCounts.keys(),
249
+ ...previousCounts.keys(),
250
+ ]);
251
+ return [...members]
252
+ .map(member => {
253
+ const currentCount = currentCounts.get(member) ?? null;
254
+ const previousCount = previousCounts.get(member) ?? null;
255
+ const change =
256
+ currentCount !== null && previousCount !== null
257
+ ? currentCount - previousCount
258
+ : null;
259
+ return {
260
+ member,
261
+ currentCount,
262
+ previousCount,
263
+ change,
264
+ changeRate:
265
+ change !== null && previousCount !== null && previousCount > 0
266
+ ? change / previousCount
267
+ : null,
268
+ };
269
+ })
270
+ .sort((a, b) => Math.abs(b.change ?? 0) - Math.abs(a.change ?? 0));
170
271
  },
171
272
  }),
172
273
  sampleRows: dataApp.defineOperation({
173
- filters: { period, grain, breakdown },
274
+ filters: operationFilters.sampleRows,
174
275
  policy,
175
- async run({ query }, { period, grain, breakdown }) {
276
+ async run({ query }, { period, groupName, grain, breakdown }) {
277
+ const bounds = queryDateTimeRangeParams(periodFilter, period, 'period');
176
278
  const result = await query('sampleRows', {
177
- period: period.range,
279
+ ...bounds.combined,
280
+ groupName,
178
281
  grain,
179
282
  breakdown,
180
283
  });
@@ -185,46 +288,61 @@ const operations = {
185
288
  }));
186
289
  },
187
290
  }),
188
- };
291
+ });
189
292
  const queryNames = {
190
- ...operations.sampleTotal.queryNames,
293
+ ...operations.sampleTotals.queryNames,
191
294
  ...operations.samplesOverTime.queryNames,
192
295
  ...operations.samplesByMember.queryNames,
193
296
  ...operations.sampleRows.queryNames,
194
297
  };
195
298
  const sampleDataContext = createDataContext(queryNames)({
196
299
  description:
197
- 'Fictional daily samples from starter_demo.daily_samples. Replace this evidence with the actual Finding queries.',
300
+ 'Fictional daily sample counts by group and segment. Comparisons use equal-length periods in UTC.',
198
301
  glossary: {
302
+ sampleChange: {
303
+ term: 'Sample change',
304
+ definition:
305
+ 'Selected-period samples minus the previous equal-length period in the same scope. Missing observations remain unavailable; they are not measured zeroes.',
306
+ queryNames: ['samplesByMember'],
307
+ },
199
308
  sampleCount: {
200
309
  term: 'Sample count',
201
- definition: 'Fixture samples recorded per day, group, and segment.',
310
+ definition:
311
+ 'Number of samples recorded for each day, group, and segment.',
202
312
  queryNames: Object.values(queryNames),
203
313
  },
204
314
  },
205
315
  });
206
- const { defineView } = createDataHooks(createDataClient({ operations }));
316
+ const { defineView } = createDataHooks(operations.createDataClient());
207
317
  const count = { kind: 'count' } as const;
208
318
  const emptyFallback = {
209
319
  title: 'No samples in this period',
210
320
  description: 'No observations are available for this period.',
211
321
  };
212
- const totalView = defineView({
322
+ const totalsView = defineView({
213
323
  dataContext: sampleDataContext,
214
- operation: 'sampleTotal',
324
+ operation: 'sampleTotals',
325
+ isEmpty: rows => rows.length === 0,
326
+ emptyFallback,
215
327
  });
216
- const totalSamples = totalView.metric(
217
- {
218
- id: 'total-samples',
219
- label: 'Samples',
220
- glossaryId: 'sampleCount',
221
- format: count,
328
+ const totals = totalsView.dataset({
329
+ name: 'Period totals',
330
+ select: rows => rows,
331
+ rowKey: () => 'total',
332
+ columns: {
333
+ currentCount: {
334
+ label: 'Selected period',
335
+ value: row => row.currentCount,
336
+ format: count,
337
+ },
338
+ previousCount: {
339
+ label: 'Previous period',
340
+ value: row => row.previousCount,
341
+ format: count,
342
+ },
222
343
  },
223
- total => ({
224
- current: total.current,
225
- ...(total.previous !== null && { previous: total.previous }),
226
- })
227
- );
344
+ evidence: { id: 'period-totals', glossaryIds: ['sampleCount'] },
345
+ });
228
346
  const trendView = defineView({
229
347
  dataContext: sampleDataContext,
230
348
  operation: 'samplesOverTime',
@@ -248,14 +366,50 @@ const memberView = defineView({
248
366
  emptyFallback,
249
367
  });
250
368
  const byMember = memberView.dataset({
251
- name: 'Samples by member',
369
+ name: 'Member comparison',
252
370
  select: rows => rows,
253
371
  rowKey: row => row.member,
254
372
  columns: {
255
373
  member: { label: 'Member', value: row => row.member },
256
- sampleCount: { value: row => row.sampleCount, format: count },
374
+ currentCount: {
375
+ label: 'Selected period',
376
+ value: row => row.currentCount,
377
+ format: count,
378
+ },
379
+ previousCount: {
380
+ label: 'Previous period',
381
+ value: row => row.previousCount,
382
+ format: count,
383
+ },
384
+ change: {
385
+ label: 'Change',
386
+ value: row => row.change,
387
+ format: row => formatNumber(row.change, { signDisplay: 'exceptZero' }),
388
+ },
389
+ changeRate: {
390
+ label: 'Change %',
391
+ value: row => row.changeRate,
392
+ format: row => formatPercent(row.changeRate),
393
+ },
394
+ },
395
+ evidence: {
396
+ id: 'samples-by-member',
397
+ glossaryIds: ['sampleCount', 'sampleChange'],
257
398
  },
258
- evidence: { id: 'samples-by-member', glossaryIds: ['sampleCount'] },
399
+ });
400
+ const selectedMembers = memberView.dataset({
401
+ name: 'Selected-period samples',
402
+ select: rows => rows,
403
+ rowKey: row => row.member,
404
+ columns: {
405
+ member: { label: 'Member', value: row => row.member },
406
+ currentCount: {
407
+ label: 'Samples',
408
+ value: row => row.currentCount,
409
+ format: count,
410
+ },
411
+ },
412
+ evidence: { id: 'selected-members', glossaryIds: ['sampleCount'] },
259
413
  });
260
414
  const rowsView = defineView({
261
415
  dataContext: sampleDataContext,
@@ -274,16 +428,53 @@ const sampleRows = rowsView.dataset({
274
428
  },
275
429
  evidence: { id: 'samples', glossaryIds: ['sampleCount'] },
276
430
  });
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} />
431
+ // Compare current and previous periods from the same displayed result.
432
+ const totalsContent = totalsView.content(result => (
433
+ <VisualizationWidget
434
+ dataset={totals}
435
+ source={result}
436
+ title={
437
+ result.loading || result.input.period.comparison
438
+ ? 'Period comparison'
439
+ : 'Selected period'
440
+ }
441
+ >
442
+ {rows =>
443
+ result.loading ? null : result.input.period.comparison ? (
444
+ <Comparison
445
+ label="Samples"
446
+ current={{
447
+ value: rows[0]!.currentCount,
448
+ formattedValue: formatCount(rows[0]!.currentCount),
449
+ periodLabel: periodLabel(result.input.period.range),
450
+ }}
451
+ previous={{
452
+ value: rows[0]!.previousCount,
453
+ formattedValue: formatCount(rows[0]!.previousCount, {
454
+ missing: 'Not available',
455
+ }),
456
+ periodLabel: periodLabel(result.input.period.comparison),
457
+ }}
458
+ />
459
+ ) : (
460
+ <Ranking
461
+ items={[
462
+ {
463
+ id: 'selected',
464
+ label: periodLabel(result.input.period.range),
465
+ value: rows[0]!.currentCount,
466
+ },
467
+ ]}
468
+ />
469
+ )
470
+ }
471
+ </VisualizationWidget>
280
472
  ));
281
473
  const trendContent = trendView.content(result => (
282
474
  <VisualizationWidget
283
475
  dataset={trend}
284
476
  source={result}
285
477
  title="Samples over time"
286
- description="Includes the previous period when comparison is on."
287
478
  breakdown={trendView.breakdown('grain')}
288
479
  >
289
480
  {rows => (
@@ -304,37 +495,130 @@ const memberContent = memberView.content(result => (
304
495
  <VisualizationWidget
305
496
  dataset={byMember}
306
497
  source={result}
307
- title="Samples by member"
498
+ title={
499
+ result.loading || result.input.period.comparison
500
+ ? 'Where volume changed'
501
+ : 'Samples by member'
502
+ }
308
503
  breakdown={memberView.breakdown('breakdown')}
309
504
  >
310
505
  {rows => (
311
- <BarChart
506
+ <ComposedChart
312
507
  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
- />
508
+ data={rows}
509
+ valueFormat={count}
510
+ >
511
+ <ComposedChart.XAxis dataKey="member" />
512
+ <ComposedChart.YAxis />
513
+ {!result.loading && result.input.period.comparison && (
514
+ <ComposedChart.Bar
515
+ dataKey="previousCount"
516
+ name="Previous period"
517
+ fill="var(--atbl-muted)"
518
+ fillOpacity={0.45}
519
+ />
520
+ )}
521
+ <ComposedChart.Bar dataKey="currentCount" name="Selected period" />
522
+ <ComposedChart.Tooltip />
523
+ <ComposedChart.Legend />
524
+ </ComposedChart>
321
525
  )}
322
526
  </VisualizationWidget>
323
527
  ));
528
+ const memberTableContent = memberView.content(result => (
529
+ <TableWidget
530
+ dataset={
531
+ result.loading || result.input.period.comparison
532
+ ? byMember
533
+ : selectedMembers
534
+ }
535
+ source={result}
536
+ title={
537
+ result.loading || result.input.period.comparison
538
+ ? 'Change by member'
539
+ : 'Samples by member'
540
+ }
541
+ />
542
+ ));
324
543
  const rowsContent = rowsView.content(result => (
325
- <TableWidget dataset={sampleRows} source={result} title="Samples" />
544
+ <TableWidget dataset={sampleRows} source={result} title="Sample details" />
326
545
  ));
546
+ // Show this notice when scope or display choices differ from the original finding.
547
+ // Back to finding restores both scope filters and display choices to their defaults.
548
+ function FindingScope() {
549
+ const filters = useAppFilters({
550
+ period: periodFilter,
551
+ groupName,
552
+ grain,
553
+ breakdown,
554
+ });
555
+ const scopeChanged =
556
+ !periodFilter.same(filters.values.period, periodFilter.defaultValue) ||
557
+ !groupName.same(filters.values.groupName, groupName.defaultValue);
558
+ const displayChanged =
559
+ !grain.same(filters.values.grain, grain.defaultValue) ||
560
+ !breakdown.same(filters.values.breakdown, breakdown.defaultValue);
561
+ if (!scopeChanged && !displayChanged) return null;
562
+ return (
563
+ <Notice
564
+ title={
565
+ scopeChanged
566
+ ? 'Exploring a different scope'
567
+ : 'Viewing a different breakdown'
568
+ }
569
+ description={
570
+ <>
571
+ Original finding · {findingPeriodLabel} {periodFilter.policy.timeZone}{' '}
572
+ vs previous period ·{' '}
573
+ {groupName.describe?.(groupName.defaultValue) ??
574
+ groupName.defaultValue}
575
+ </>
576
+ }
577
+ action={
578
+ <Button size="compact" onClick={() => filters.resetAll()}>
579
+ Back to finding
580
+ </Button>
581
+ }
582
+ />
583
+ );
584
+ }
585
+ const views = ['overview', 'data'] as const;
327
586
  function App() {
587
+ const [view, setView] = useViewTab(views, 'overview');
328
588
  return (
329
- <DataApp view={totalView} showToolbar={false}>
589
+ <DataApp view={trendView} showToolbar={false}>
330
590
  <Stack>
331
- <DataSection content={totalContent} />
332
- <DataSection content={trendContent} />
333
- <DataSection content={memberContent} />
334
- <DataSection content={rowsContent} />
591
+ <FindingScope />
592
+ <Tabs selectedKey={view} onSelectionChange={setView}>
593
+ <TabList aria-label="Finding views">
594
+ <Tab id="overview">Overview</Tab>
595
+ <Tab id="data">Data</Tab>
596
+ </TabList>
597
+ <TabPanels>
598
+ <TabPanel id="overview">
599
+ <Stack>
600
+ <Grid columns={3}>
601
+ <GridItem span={2}>
602
+ <DataSection content={trendContent} />
603
+ </GridItem>
604
+ <GridItem>
605
+ <DataSection content={totalsContent} />
606
+ </GridItem>
607
+ </Grid>
608
+ <DataSection content={memberContent} />
609
+ </Stack>
610
+ </TabPanel>
611
+ <TabPanel id="data">
612
+ <Stack>
613
+ <DataSection content={memberTableContent} />
614
+ <DataSection content={rowsContent} />
615
+ </Stack>
616
+ </TabPanel>
617
+ </TabPanels>
618
+ </Tabs>
335
619
  </Stack>
336
620
  </DataApp>
337
621
  );
338
622
  }
339
- injectDataAppStyles();
623
+
340
624
  mountDataApp({ app: dataApp, component: App });
@@ -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.77.0/docs/app-authoring.md). <!-- x-release-please-version -->
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
- | 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` |
7
+ | Task | App-owned files |
8
+ | ------------------------------------------ | ----------------------------------------------- |
9
+ | Define queries, filters, and operations | `app.ts`, `src/filters.ts`, `src/operations.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