@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
@@ -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,105 +288,171 @@ const operations = {
185
288
  }));
186
289
  },
187
290
  }),
188
- };
189
- const queryNames = {
190
- ...operations.sampleTotal.queryNames,
191
- ...operations.samplesOverTime.queryNames,
192
- ...operations.samplesByMember.queryNames,
193
- ...operations.sampleRows.queryNames,
194
- };
195
- const sampleDataContext = createDataContext(queryNames)({
291
+ });
292
+ const sampleDataContext = createDataContext(dataApp.queryNames)({
196
293
  description:
197
- 'Fictional daily samples from starter_demo.daily_samples. Replace this evidence with the actual Finding queries.',
294
+ 'Fictional daily sample counts by group and segment. Comparisons use equal-length periods in UTC.',
198
295
  glossary: {
296
+ sampleChange: {
297
+ term: 'Sample change',
298
+ definition:
299
+ 'Selected-period samples minus the previous equal-length period in the same scope. Missing observations remain unavailable; they are not measured zeroes.',
300
+ queryNames: ['samplesByMember'],
301
+ },
199
302
  sampleCount: {
200
303
  term: 'Sample count',
201
- definition: 'Fixture samples recorded per day, group, and segment.',
202
- queryNames: Object.values(queryNames),
304
+ definition:
305
+ 'Number of samples recorded for each day, group, and segment.',
306
+ queryNames: Object.values(dataApp.queryNames),
203
307
  },
204
308
  },
205
309
  });
206
- const { defineView } = createDataHooks(createDataClient({ operations }));
310
+ const { defineView } = createDataHooks(operations.createDataClient());
207
311
  const count = { kind: 'count' } as const;
208
312
  const emptyFallback = {
209
313
  title: 'No samples in this period',
210
314
  description: 'No observations are available for this period.',
211
315
  };
212
- const totalView = defineView({
316
+ const totalsView = defineView({
213
317
  dataContext: sampleDataContext,
214
- operation: 'sampleTotal',
318
+ operation: 'sampleTotals',
319
+ emptyFallback,
215
320
  });
216
- const totalSamples = totalView.metric(
217
- {
218
- id: 'total-samples',
219
- label: 'Samples',
220
- glossaryId: 'sampleCount',
221
- format: count,
321
+ const totals = totalsView.dataset({
322
+ name: 'Period totals',
323
+ rowKey: () => 'total',
324
+ columns: {
325
+ currentCount: {
326
+ label: 'Selected period',
327
+ format: count,
328
+ },
329
+ previousCount: {
330
+ label: 'Previous period',
331
+ format: count,
332
+ },
222
333
  },
223
- total => ({
224
- current: total.current,
225
- ...(total.previous !== null && { previous: total.previous }),
226
- })
227
- );
334
+ evidence: { id: 'period-totals', glossaryIds: ['sampleCount'] },
335
+ });
228
336
  const trendView = defineView({
229
337
  dataContext: sampleDataContext,
230
338
  operation: 'samplesOverTime',
231
- isEmpty: rows => rows.length === 0,
232
339
  emptyFallback,
233
340
  });
234
341
  const trend = trendView.dataset({
235
342
  name: 'Samples over time',
236
- select: rows => rows,
237
343
  rowKey: row => row.periodStart,
238
344
  columns: {
239
- periodStart: { label: 'Period start', value: row => row.periodStart },
240
- sampleCount: { value: row => row.sampleCount, format: count },
345
+ periodStart: { label: 'Period start' },
346
+ sampleCount: { format: count },
241
347
  },
242
348
  evidence: { id: 'samples-over-time', glossaryIds: ['sampleCount'] },
243
349
  });
244
350
  const memberView = defineView({
245
351
  dataContext: sampleDataContext,
246
352
  operation: 'samplesByMember',
247
- isEmpty: rows => rows.length === 0,
248
353
  emptyFallback,
249
354
  });
250
355
  const byMember = memberView.dataset({
251
- name: 'Samples by member',
252
- select: rows => rows,
356
+ name: 'Member comparison',
357
+ rowKey: row => row.member,
358
+ columns: {
359
+ member: { label: 'Member' },
360
+ currentCount: {
361
+ label: 'Selected period',
362
+ format: count,
363
+ },
364
+ previousCount: {
365
+ label: 'Previous period',
366
+ format: count,
367
+ },
368
+ change: {
369
+ label: 'Change',
370
+ format: row => formatNumber(row.change, { signDisplay: 'exceptZero' }),
371
+ },
372
+ changeRate: {
373
+ label: 'Change %',
374
+ format: row => formatPercent(row.changeRate),
375
+ },
376
+ },
377
+ evidence: {
378
+ id: 'samples-by-member',
379
+ glossaryIds: ['sampleCount', 'sampleChange'],
380
+ },
381
+ });
382
+ const selectedMembers = memberView.dataset({
383
+ name: 'Selected-period samples',
253
384
  rowKey: row => row.member,
254
385
  columns: {
255
- member: { label: 'Member', value: row => row.member },
256
- sampleCount: { value: row => row.sampleCount, format: count },
386
+ member: { label: 'Member' },
387
+ currentCount: {
388
+ label: 'Samples',
389
+ format: count,
390
+ },
257
391
  },
258
- evidence: { id: 'samples-by-member', glossaryIds: ['sampleCount'] },
392
+ evidence: { id: 'selected-members', glossaryIds: ['sampleCount'] },
259
393
  });
260
394
  const rowsView = defineView({
261
395
  dataContext: sampleDataContext,
262
396
  operation: 'sampleRows',
263
- isEmpty: rows => rows.length === 0,
264
397
  emptyFallback,
265
398
  });
266
399
  const sampleRows = rowsView.dataset({
267
400
  name: 'Samples',
268
- select: rows => rows,
269
401
  rowKey: row => `${row.periodStart}:${row.member}`,
270
402
  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 },
403
+ periodStart: { label: 'Period start' },
404
+ member: { label: 'Member' },
405
+ sampleCount: { format: count },
274
406
  },
275
407
  evidence: { id: 'samples', glossaryIds: ['sampleCount'] },
276
408
  });
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} />
409
+ // Compare current and previous periods from the same displayed result.
410
+ const totalsContent = totalsView.content(result => (
411
+ <VisualizationWidget
412
+ dataset={totals}
413
+ source={result}
414
+ title={
415
+ result.loading || result.input.period.comparison
416
+ ? 'Period comparison'
417
+ : 'Selected period'
418
+ }
419
+ >
420
+ {rows =>
421
+ result.loading ? null : result.input.period.comparison ? (
422
+ <Comparison
423
+ label="Samples"
424
+ current={{
425
+ value: rows[0]!.currentCount,
426
+ formattedValue: formatCount(rows[0]!.currentCount),
427
+ periodLabel: periodLabel(result.input.period.range),
428
+ }}
429
+ previous={{
430
+ value: rows[0]!.previousCount,
431
+ formattedValue: formatCount(rows[0]!.previousCount, {
432
+ missing: 'Not available',
433
+ }),
434
+ periodLabel: periodLabel(result.input.period.comparison),
435
+ }}
436
+ />
437
+ ) : (
438
+ <Ranking
439
+ items={[
440
+ {
441
+ id: 'selected',
442
+ label: periodLabel(result.input.period.range),
443
+ value: rows[0]!.currentCount,
444
+ },
445
+ ]}
446
+ />
447
+ )
448
+ }
449
+ </VisualizationWidget>
280
450
  ));
281
451
  const trendContent = trendView.content(result => (
282
452
  <VisualizationWidget
283
453
  dataset={trend}
284
454
  source={result}
285
455
  title="Samples over time"
286
- description="Includes the previous period when comparison is on."
287
456
  breakdown={trendView.breakdown('grain')}
288
457
  >
289
458
  {rows => (
@@ -304,37 +473,130 @@ const memberContent = memberView.content(result => (
304
473
  <VisualizationWidget
305
474
  dataset={byMember}
306
475
  source={result}
307
- title="Samples by member"
476
+ title={
477
+ result.loading || result.input.period.comparison
478
+ ? 'Where volume changed'
479
+ : 'Samples by member'
480
+ }
308
481
  breakdown={memberView.breakdown('breakdown')}
309
482
  >
310
483
  {rows => (
311
- <BarChart
484
+ <ComposedChart
312
485
  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
- />
486
+ data={rows}
487
+ valueFormat={count}
488
+ >
489
+ <ComposedChart.XAxis dataKey="member" />
490
+ <ComposedChart.YAxis />
491
+ {!result.loading && result.input.period.comparison && (
492
+ <ComposedChart.Bar
493
+ dataKey="previousCount"
494
+ name="Previous period"
495
+ fill="var(--atbl-muted)"
496
+ fillOpacity={0.45}
497
+ />
498
+ )}
499
+ <ComposedChart.Bar dataKey="currentCount" name="Selected period" />
500
+ <ComposedChart.Tooltip />
501
+ <ComposedChart.Legend />
502
+ </ComposedChart>
321
503
  )}
322
504
  </VisualizationWidget>
323
505
  ));
506
+ const memberTableContent = memberView.content(result => (
507
+ <TableWidget
508
+ dataset={
509
+ result.loading || result.input.period.comparison
510
+ ? byMember
511
+ : selectedMembers
512
+ }
513
+ source={result}
514
+ title={
515
+ result.loading || result.input.period.comparison
516
+ ? 'Change by member'
517
+ : 'Samples by member'
518
+ }
519
+ />
520
+ ));
324
521
  const rowsContent = rowsView.content(result => (
325
- <TableWidget dataset={sampleRows} source={result} title="Samples" />
522
+ <TableWidget dataset={sampleRows} source={result} title="Sample details" />
326
523
  ));
524
+ // Show this notice when scope or display choices differ from the original finding.
525
+ // Back to finding restores both scope filters and display choices to their defaults.
526
+ function FindingScope() {
527
+ const filters = useAppFilters({
528
+ period: periodFilter,
529
+ groupName,
530
+ grain,
531
+ breakdown,
532
+ });
533
+ const scopeChanged =
534
+ !periodFilter.same(filters.values.period, periodFilter.defaultValue) ||
535
+ !groupName.same(filters.values.groupName, groupName.defaultValue);
536
+ const displayChanged =
537
+ !grain.same(filters.values.grain, grain.defaultValue) ||
538
+ !breakdown.same(filters.values.breakdown, breakdown.defaultValue);
539
+ if (!scopeChanged && !displayChanged) return null;
540
+ return (
541
+ <Notice
542
+ title={
543
+ scopeChanged
544
+ ? 'Exploring a different scope'
545
+ : 'Viewing a different breakdown'
546
+ }
547
+ description={
548
+ <>
549
+ Original finding · {findingPeriodLabel} {periodFilter.policy.timeZone}{' '}
550
+ vs previous period ·{' '}
551
+ {groupName.describe?.(groupName.defaultValue) ??
552
+ groupName.defaultValue}
553
+ </>
554
+ }
555
+ action={
556
+ <Button size="compact" onClick={() => filters.resetAll()}>
557
+ Back to finding
558
+ </Button>
559
+ }
560
+ />
561
+ );
562
+ }
563
+ const views = ['overview', 'data'] as const;
327
564
  function App() {
565
+ const [view, setView] = useViewTab(views, 'overview');
328
566
  return (
329
- <DataApp view={totalView} showToolbar={false}>
567
+ <DataApp view={trendView} showToolbar={false}>
330
568
  <Stack>
331
- <DataSection content={totalContent} />
332
- <DataSection content={trendContent} />
333
- <DataSection content={memberContent} />
334
- <DataSection content={rowsContent} />
569
+ <FindingScope />
570
+ <Tabs selectedKey={view} onSelectionChange={setView}>
571
+ <TabList aria-label="Finding views">
572
+ <Tab id="overview">Overview</Tab>
573
+ <Tab id="data">Data</Tab>
574
+ </TabList>
575
+ <TabPanels>
576
+ <TabPanel id="overview">
577
+ <Stack>
578
+ <Grid columns={3}>
579
+ <GridItem span={2}>
580
+ <DataSection content={trendContent} />
581
+ </GridItem>
582
+ <GridItem>
583
+ <DataSection content={totalsContent} />
584
+ </GridItem>
585
+ </Grid>
586
+ <DataSection content={memberContent} />
587
+ </Stack>
588
+ </TabPanel>
589
+ <TabPanel id="data">
590
+ <Stack>
591
+ <DataSection content={memberTableContent} />
592
+ <DataSection content={rowsContent} />
593
+ </Stack>
594
+ </TabPanel>
595
+ </TabPanels>
596
+ </Tabs>
335
597
  </Stack>
336
598
  </DataApp>
337
599
  );
338
600
  }
339
- injectDataAppStyles();
601
+
340
602
  mountDataApp({ app: dataApp, component: App });