@altertable/data-app-examples 0.78.0 → 0.80.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 (28) 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 +70 -676
  6. package/templates/starter-finding-data-app/index.tsx +9 -31
  7. package/templates/starter-local-data-app/AGENTS.md +1 -1
  8. package/templates/starter-local-data-app/README.md +5 -8
  9. package/templates/starter-local-data-app/app.ts +15 -246
  10. package/templates/starter-local-data-app/package.json +3 -3
  11. package/templates/starter-local-data-app/src/App.tsx +32 -253
  12. package/templates/starter-local-data-app/src/data-context.ts +8 -27
  13. package/templates/starter-local-data-app/src/filters.ts +9 -30
  14. package/templates/starter-local-data-app/src/operations.ts +9 -125
  15. package/templates/starter-local-finding-data-app/AGENTS.md +1 -1
  16. package/templates/starter-local-finding-data-app/README.md +2 -2
  17. package/templates/starter-local-finding-data-app/package.json +3 -3
  18. package/templates/starter-local-finding-data-app/src/App.tsx +7 -23
  19. package/templates/starter-local-finding-data-app/src/data-context.ts +3 -9
  20. package/templates/starter-local-metric-data-app/AGENTS.md +1 -1
  21. package/templates/starter-local-metric-data-app/README.md +2 -2
  22. package/templates/starter-local-metric-data-app/app.ts +4 -4
  23. package/templates/starter-local-metric-data-app/package.json +3 -3
  24. package/templates/starter-local-metric-data-app/src/App.tsx +4 -8
  25. package/templates/starter-local-metric-data-app/src/data-context.ts +4 -8
  26. package/templates/starter-local-metric-data-app/src/filters.ts +1 -0
  27. package/templates/starter-local-metric-data-app/src/operations.ts +4 -12
  28. package/templates/starter-metric-data-app/index.tsx +18 -32
@@ -47,22 +47,18 @@ const emptyFallback = {
47
47
  const totalsView = defineView({
48
48
  dataContext: sampleDataContext,
49
49
  operation: 'sampleTotals',
50
- isEmpty: rows => rows.length === 0,
51
50
  emptyFallback,
52
51
  });
53
52
  const totals = totalsView.dataset({
54
53
  name: 'Period totals',
55
- select: rows => rows,
56
54
  rowKey: () => 'total',
57
55
  columns: {
58
56
  currentCount: {
59
57
  label: 'Selected period',
60
- value: row => row.currentCount,
61
58
  format: count,
62
59
  },
63
60
  previousCount: {
64
61
  label: 'Previous period',
65
- value: row => row.previousCount,
66
62
  format: count,
67
63
  },
68
64
  },
@@ -71,49 +67,41 @@ const totals = totalsView.dataset({
71
67
  const trendView = defineView({
72
68
  dataContext: sampleDataContext,
73
69
  operation: 'samplesOverTime',
74
- isEmpty: rows => rows.length === 0,
75
70
  emptyFallback,
76
71
  });
77
72
  const trend = trendView.dataset({
78
73
  name: 'Samples over time',
79
- select: rows => rows,
80
74
  rowKey: row => row.periodStart,
81
75
  columns: {
82
- periodStart: { label: 'Period start', value: row => row.periodStart },
83
- sampleCount: { value: row => row.sampleCount, format: count },
76
+ periodStart: { label: 'Period start' },
77
+ sampleCount: { format: count },
84
78
  },
85
79
  evidence: { id: 'samples-over-time', glossaryIds: ['sampleCount'] },
86
80
  });
87
81
  const memberView = defineView({
88
82
  dataContext: sampleDataContext,
89
83
  operation: 'samplesByMember',
90
- isEmpty: rows => rows.length === 0,
91
84
  emptyFallback,
92
85
  });
93
86
  const byMember = memberView.dataset({
94
87
  name: 'Member comparison',
95
- select: rows => rows,
96
88
  rowKey: row => row.member,
97
89
  columns: {
98
- member: { label: 'Member', value: row => row.member },
90
+ member: { label: 'Member' },
99
91
  currentCount: {
100
92
  label: 'Selected period',
101
- value: row => row.currentCount,
102
93
  format: count,
103
94
  },
104
95
  previousCount: {
105
96
  label: 'Previous period',
106
- value: row => row.previousCount,
107
97
  format: count,
108
98
  },
109
99
  change: {
110
100
  label: 'Change',
111
- value: row => row.change,
112
101
  format: row => formatNumber(row.change, { signDisplay: 'exceptZero' }),
113
102
  },
114
103
  changeRate: {
115
104
  label: 'Change %',
116
- value: row => row.changeRate,
117
105
  format: row => formatPercent(row.changeRate),
118
106
  },
119
107
  },
@@ -124,13 +112,11 @@ const byMember = memberView.dataset({
124
112
  });
125
113
  const selectedMembers = memberView.dataset({
126
114
  name: 'Selected-period samples',
127
- select: rows => rows,
128
115
  rowKey: row => row.member,
129
116
  columns: {
130
- member: { label: 'Member', value: row => row.member },
117
+ member: { label: 'Member' },
131
118
  currentCount: {
132
119
  label: 'Samples',
133
- value: row => row.currentCount,
134
120
  format: count,
135
121
  },
136
122
  },
@@ -139,17 +125,15 @@ const selectedMembers = memberView.dataset({
139
125
  const rowsView = defineView({
140
126
  dataContext: sampleDataContext,
141
127
  operation: 'sampleRows',
142
- isEmpty: rows => rows.length === 0,
143
128
  emptyFallback,
144
129
  });
145
130
  const sampleRows = rowsView.dataset({
146
131
  name: 'Samples',
147
- select: rows => rows,
148
132
  rowKey: row => `${row.periodStart}:${row.member}`,
149
133
  columns: {
150
- periodStart: { label: 'Period start', value: row => row.periodStart },
151
- member: { label: 'Member', value: row => row.member },
152
- sampleCount: { value: row => row.sampleCount, format: count },
134
+ periodStart: { label: 'Period start' },
135
+ member: { label: 'Member' },
136
+ sampleCount: { format: count },
153
137
  },
154
138
  evidence: { id: 'samples', glossaryIds: ['sampleCount'] },
155
139
  });
@@ -1,14 +1,8 @@
1
1
  import { createDataContext } from '@altertable/data-app-react';
2
2
 
3
- import { operations } from '#app/operations.ts';
3
+ import { dataApp } from '#config';
4
4
 
5
- const queryNames = {
6
- ...operations.sampleTotals.queryNames,
7
- ...operations.samplesOverTime.queryNames,
8
- ...operations.samplesByMember.queryNames,
9
- ...operations.sampleRows.queryNames,
10
- };
11
- export const sampleDataContext = createDataContext(queryNames)({
5
+ export const sampleDataContext = createDataContext(dataApp.queryNames)({
12
6
  description:
13
7
  'Fictional daily sample counts by group and segment. Comparisons use equal-length periods in UTC.',
14
8
  glossary: {
@@ -22,7 +16,7 @@ export const sampleDataContext = createDataContext(queryNames)({
22
16
  term: 'Sample count',
23
17
  definition:
24
18
  'Number of samples recorded for each day, group, and segment.',
25
- queryNames: Object.values(queryNames),
19
+ queryNames: Object.values(dataApp.queryNames),
26
20
  },
27
21
  },
28
22
  });
@@ -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.78.0/docs/app-authoring.md). <!-- x-release-please-version -->
5
+ [version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.80.0/docs/app-authoring.md). <!-- x-release-please-version -->
6
6
 
7
7
  | Task | App-owned files |
8
8
  | ------------------------------------------ | ----------------------------------------------- |
@@ -1,11 +1,11 @@
1
1
  # Local metric data app starter
2
2
 
3
3
  Use `node_modules/@altertable/data-app/docs/app-authoring.md` for this SDK version.
4
- Otherwise, read the [version-matched authoring recipe](https://github.com/altertable-ai/data-app/blob/v0.78.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.80.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.78.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.80.0/docs/local-data-apps.md#preview-the-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
 
@@ -16,10 +16,10 @@ export const dataApp = defineDataApp({
16
16
  statement: `
17
17
  SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
18
18
  starter_sample_counts DIMENSIONS samples.segment_name METRICS samples.sample_count
19
- WHERE $groupName = '' OR samples.group_name = $groupName
19
+ WHERE $groupName = 'all' OR samples.group_name = $groupName
20
20
  ) ORDER BY sample_count DESC, segment_name LIMIT $limit`,
21
21
  params: {
22
- groupName: { type: 'string', defaultValue: '' },
22
+ groupName: { type: 'string', defaultValue: 'all' },
23
23
  limit: { type: 'number', defaultValue: 10 },
24
24
  },
25
25
  },
@@ -31,10 +31,10 @@ SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
31
31
  statement: `
32
32
  SELECT group_name, sample_count FROM SEMANTIC_VIEW(
33
33
  starter_sample_counts DIMENSIONS samples.group_name METRICS samples.sample_count
34
- WHERE $groupName = '' OR samples.group_name = $groupName
34
+ WHERE $groupName = 'all' OR samples.group_name = $groupName
35
35
  ) ORDER BY group_name LIMIT $limit`,
36
36
  params: {
37
- groupName: { type: 'string', defaultValue: '' },
37
+ groupName: { type: 'string', defaultValue: 'all' },
38
38
  limit: { type: 'number', defaultValue: 10 },
39
39
  },
40
40
  },
@@ -17,9 +17,9 @@
17
17
  "lint:fix": "oxlint --type-aware --fix src app.ts"
18
18
  },
19
19
  "dependencies": {
20
- "@altertable/data-app": "0.78.0",
21
- "@altertable/data-app-bun": "0.78.0",
22
- "@altertable/data-app-react": "0.78.0",
20
+ "@altertable/data-app": "0.80.0",
21
+ "@altertable/data-app-bun": "0.80.0",
22
+ "@altertable/data-app-react": "0.80.0",
23
23
  "react": "19.3.1",
24
24
  "react-dom": "19.3.1"
25
25
  },
@@ -16,7 +16,6 @@ const { defineView } = createDataHooks(operations.createDataClient());
16
16
  const sampleCountsView = defineView({
17
17
  dataContext: sampleDataContext,
18
18
  operation: 'sampleCountsByGroup',
19
- isEmpty: rows => rows.length === 0,
20
19
  emptyFallback: {
21
20
  title: 'No matching groups',
22
21
  description: 'No observations are available for this query.',
@@ -24,11 +23,10 @@ const sampleCountsView = defineView({
24
23
  });
25
24
  const sampleCounts = sampleCountsView.dataset({
26
25
  name: 'Sample counts',
27
- select: rows => rows,
28
26
  rowKey: row => row.groupName,
29
27
  columns: {
30
- groupName: { label: 'Group', value: row => row.groupName },
31
- sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
28
+ groupName: { label: 'Group' },
29
+ sampleCount: { format: { kind: 'count' } },
32
30
  },
33
31
  evidence: {
34
32
  id: 'counts-by-group',
@@ -38,7 +36,6 @@ const sampleCounts = sampleCountsView.dataset({
38
36
  const segmentCountsView = defineView({
39
37
  dataContext: sampleDataContext,
40
38
  operation: 'sampleCountsBySegment',
41
- isEmpty: rows => rows.length === 0,
42
39
  emptyFallback: {
43
40
  title: 'No matching segments',
44
41
  description: 'No observations are available for this query.',
@@ -46,11 +43,10 @@ const segmentCountsView = defineView({
46
43
  });
47
44
  const segmentCounts = segmentCountsView.dataset({
48
45
  name: 'Counts by segment',
49
- select: rows => rows,
50
46
  rowKey: row => row.segmentName,
51
47
  columns: {
52
- segmentName: { label: 'Segment', value: row => row.segmentName },
53
- sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
48
+ segmentName: { label: 'Segment' },
49
+ sampleCount: { format: { kind: 'count' } },
54
50
  },
55
51
  evidence: { id: 'counts-by-segment', glossaryIds: ['sampleCount'] },
56
52
  });
@@ -1,12 +1,8 @@
1
1
  import { createDataContext } from '@altertable/data-app-react';
2
2
 
3
- import { operations } from '#app/operations.ts';
3
+ import { dataApp } from '#config';
4
4
 
5
- const queryNames = {
6
- ...operations.sampleCountsByGroup.queryNames,
7
- ...operations.sampleCountsBySegment.queryNames,
8
- };
9
- export const sampleDataContext = createDataContext(queryNames)({
5
+ export const sampleDataContext = createDataContext(dataApp.queryNames)({
10
6
  description:
11
7
  'The starter_sample_counts semantic view measures fictional sample volume by group and segment. The source has no time dimension.',
12
8
  glossary: {
@@ -15,8 +11,8 @@ export const sampleDataContext = createDataContext(queryNames)({
15
11
  definition:
16
12
  'Sum of recorded sample counts in the selected group scope. Additive across groups and segments.',
17
13
  queryNames: [
18
- queryNames.sampleCountsByGroup,
19
- queryNames.sampleCountsBySegment,
14
+ dataApp.queryNames.sampleCountsByGroup,
15
+ dataApp.queryNames.sampleCountsBySegment,
20
16
  ],
21
17
  },
22
18
  },
@@ -1,6 +1,7 @@
1
1
  import { choiceFilter } from '@altertable/data-app/contract';
2
2
 
3
3
  // Reuse this group filter in both operations so one selection updates both charts.
4
+ // The queries treat 'all' as every group.
4
5
  const groupName = choiceFilter({
5
6
  key: 'group',
6
7
  label: 'Group',
@@ -3,18 +3,12 @@ import { parseCount } from '@altertable/data-app/contract';
3
3
  import { operationFilters } from '#app/filters.ts';
4
4
  import { dataApp } from '#config';
5
5
 
6
- // The sample SQL uses '' for all groups; the filter control uses 'all'.
7
- function queryGroup(groupName: string) {
8
- return groupName === 'all' ? '' : groupName;
9
- }
10
6
  export const operations = dataApp.defineOperations({
11
7
  sampleCountsByGroup: dataApp.defineOperation({
12
8
  filters: operationFilters.sampleCountsByGroup,
13
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
9
+ policy: { maxQueryRows: 10 },
14
10
  async run({ query }, { groupName }) {
15
- const queryResult = await query('sampleCountsByGroup', {
16
- groupName: queryGroup(groupName),
17
- });
11
+ const queryResult = await query('sampleCountsByGroup', { groupName });
18
12
  return queryResult.rows.map(
19
13
  (row): { groupName: 'Alpha' | 'Beta'; sampleCount: number } => {
20
14
  if (row.group_name !== 'Alpha' && row.group_name !== 'Beta')
@@ -29,11 +23,9 @@ export const operations = dataApp.defineOperations({
29
23
  }),
30
24
  sampleCountsBySegment: dataApp.defineOperation({
31
25
  filters: operationFilters.sampleCountsBySegment,
32
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
26
+ policy: { maxQueryRows: 10 },
33
27
  async run({ query }, { groupName }) {
34
- const queryResult = await query('sampleCountsBySegment', {
35
- groupName: queryGroup(groupName),
36
- });
28
+ const queryResult = await query('sampleCountsBySegment', { groupName });
37
29
  return queryResult.rows.map(row => ({
38
30
  segmentName: row.segment_name,
39
31
  sampleCount: parseCount(row.sample_count),
@@ -1,6 +1,6 @@
1
1
  import { defineDataApp } from '@altertable/data-app';
2
- import { createDataContext, mountDataApp } from '@altertable/data-app-react';
3
2
  import {
3
+ createDataContext,
4
4
  createDataHooks,
5
5
  DataApp,
6
6
  DataSection,
@@ -8,6 +8,7 @@ import {
8
8
  Ranking,
9
9
  Grid,
10
10
  GridItem,
11
+ mountDataApp,
11
12
  } from '@altertable/data-app-react';
12
13
  import { BarChart } from '@altertable/data-app-react/ui';
13
14
  import { choiceFilter, parseCount } from '@altertable/data-app/contract';
@@ -29,10 +30,10 @@ export const dataApp = defineDataApp({
29
30
  statement: `
30
31
  SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
31
32
  starter_sample_counts DIMENSIONS samples.segment_name METRICS samples.sample_count
32
- WHERE $groupName = '' OR samples.group_name = $groupName
33
+ WHERE $groupName = 'all' OR samples.group_name = $groupName
33
34
  ) ORDER BY sample_count DESC, segment_name LIMIT $limit`,
34
35
  params: {
35
- groupName: { type: 'string', defaultValue: '' },
36
+ groupName: { type: 'string', defaultValue: 'all' },
36
37
  limit: { type: 'number', defaultValue: 10 },
37
38
  },
38
39
  },
@@ -44,16 +45,17 @@ SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
44
45
  statement: `
45
46
  SELECT group_name, sample_count FROM SEMANTIC_VIEW(
46
47
  starter_sample_counts DIMENSIONS samples.group_name METRICS samples.sample_count
47
- WHERE $groupName = '' OR samples.group_name = $groupName
48
+ WHERE $groupName = 'all' OR samples.group_name = $groupName
48
49
  ) ORDER BY group_name LIMIT $limit`,
49
50
  params: {
50
- groupName: { type: 'string', defaultValue: '' },
51
+ groupName: { type: 'string', defaultValue: 'all' },
51
52
  limit: { type: 'number', defaultValue: 10 },
52
53
  },
53
54
  },
54
55
  },
55
56
  });
56
57
  // Reuse this group filter in both operations so one selection updates both charts.
58
+ // The queries treat 'all' as every group.
57
59
  const groupName = choiceFilter({
58
60
  key: 'group',
59
61
  label: 'Group',
@@ -64,18 +66,12 @@ const groupName = choiceFilter({
64
66
  { id: 'Beta', label: 'Beta' },
65
67
  ],
66
68
  });
67
- // The sample SQL uses '' for all groups; the filter control uses 'all'.
68
- function queryGroup(groupName: string) {
69
- return groupName === 'all' ? '' : groupName;
70
- }
71
69
  export const operations = dataApp.defineOperations({
72
70
  sampleCountsByGroup: dataApp.defineOperation({
73
71
  filters: { groupName },
74
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
72
+ policy: { maxQueryRows: 10 },
75
73
  async run({ query }, { groupName }) {
76
- const queryResult = await query('sampleCountsByGroup', {
77
- groupName: queryGroup(groupName),
78
- });
74
+ const queryResult = await query('sampleCountsByGroup', { groupName });
79
75
  return queryResult.rows.map(
80
76
  (row): { groupName: 'Alpha' | 'Beta'; sampleCount: number } => {
81
77
  if (row.group_name !== 'Alpha' && row.group_name !== 'Beta')
@@ -90,11 +86,9 @@ export const operations = dataApp.defineOperations({
90
86
  }),
91
87
  sampleCountsBySegment: dataApp.defineOperation({
92
88
  filters: { groupName },
93
- policy: { maxQueryRows: 10, maxDurationMs: 15000 },
89
+ policy: { maxQueryRows: 10 },
94
90
  async run({ query }, { groupName }) {
95
- const queryResult = await query('sampleCountsBySegment', {
96
- groupName: queryGroup(groupName),
97
- });
91
+ const queryResult = await query('sampleCountsBySegment', { groupName });
98
92
  return queryResult.rows.map(row => ({
99
93
  segmentName: row.segment_name,
100
94
  sampleCount: parseCount(row.sample_count),
@@ -102,11 +96,7 @@ export const operations = dataApp.defineOperations({
102
96
  },
103
97
  }),
104
98
  });
105
- const queryNames = {
106
- ...operations.sampleCountsByGroup.queryNames,
107
- ...operations.sampleCountsBySegment.queryNames,
108
- };
109
- const sampleDataContext = createDataContext(queryNames)({
99
+ const sampleDataContext = createDataContext(dataApp.queryNames)({
110
100
  description:
111
101
  'The starter_sample_counts semantic view measures fictional sample volume by group and segment. The source has no time dimension.',
112
102
  glossary: {
@@ -115,8 +105,8 @@ const sampleDataContext = createDataContext(queryNames)({
115
105
  definition:
116
106
  'Sum of recorded sample counts in the selected group scope. Additive across groups and segments.',
117
107
  queryNames: [
118
- queryNames.sampleCountsByGroup,
119
- queryNames.sampleCountsBySegment,
108
+ dataApp.queryNames.sampleCountsByGroup,
109
+ dataApp.queryNames.sampleCountsBySegment,
120
110
  ],
121
111
  },
122
112
  },
@@ -125,7 +115,6 @@ const { defineView } = createDataHooks(operations.createDataClient());
125
115
  const sampleCountsView = defineView({
126
116
  dataContext: sampleDataContext,
127
117
  operation: 'sampleCountsByGroup',
128
- isEmpty: rows => rows.length === 0,
129
118
  emptyFallback: {
130
119
  title: 'No matching groups',
131
120
  description: 'No observations are available for this query.',
@@ -133,11 +122,10 @@ const sampleCountsView = defineView({
133
122
  });
134
123
  const sampleCounts = sampleCountsView.dataset({
135
124
  name: 'Sample counts',
136
- select: rows => rows,
137
125
  rowKey: row => row.groupName,
138
126
  columns: {
139
- groupName: { label: 'Group', value: row => row.groupName },
140
- sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
127
+ groupName: { label: 'Group' },
128
+ sampleCount: { format: { kind: 'count' } },
141
129
  },
142
130
  evidence: {
143
131
  id: 'counts-by-group',
@@ -147,7 +135,6 @@ const sampleCounts = sampleCountsView.dataset({
147
135
  const segmentCountsView = defineView({
148
136
  dataContext: sampleDataContext,
149
137
  operation: 'sampleCountsBySegment',
150
- isEmpty: rows => rows.length === 0,
151
138
  emptyFallback: {
152
139
  title: 'No matching segments',
153
140
  description: 'No observations are available for this query.',
@@ -155,11 +142,10 @@ const segmentCountsView = defineView({
155
142
  });
156
143
  const segmentCounts = segmentCountsView.dataset({
157
144
  name: 'Counts by segment',
158
- select: rows => rows,
159
145
  rowKey: row => row.segmentName,
160
146
  columns: {
161
- segmentName: { label: 'Segment', value: row => row.segmentName },
162
- sampleCount: { value: row => row.sampleCount, format: { kind: 'count' } },
147
+ segmentName: { label: 'Segment' },
148
+ sampleCount: { format: { kind: 'count' } },
163
149
  },
164
150
  evidence: { id: 'counts-by-segment', glossaryIds: ['sampleCount'] },
165
151
  });