@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,9 +1,12 @@
1
1
  import { defineDataApp } from '@altertable/data-app';
2
2
  export const dataApp = defineDataApp({
3
+ // Replace the demo title, description, and scope labels with the app's identity.
3
4
  title: 'Sample metric',
4
- description: 'Fixture counts by group; replace with the requested metric.',
5
+ description: 'Explore sample volume across groups and segments.',
5
6
  scope: { organization: 'demo', environment: 'sample' },
6
7
  appearance: { theme: 'system' },
8
+ // starter_sample_counts is the seeded semantic view for fictional sample counts.
9
+ // Replace these queries with verified sources before publishing.
7
10
  queries: {
8
11
  sampleCountsBySegment: {
9
12
  projections: {
@@ -14,7 +17,7 @@ export const dataApp = defineDataApp({
14
17
  SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
15
18
  starter_sample_counts DIMENSIONS samples.segment_name METRICS samples.sample_count
16
19
  WHERE $groupName = '' OR samples.group_name = $groupName
17
- ) ORDER BY segment_name LIMIT $limit`,
20
+ ) ORDER BY sample_count DESC, segment_name LIMIT $limit`,
18
21
  params: {
19
22
  groupName: { type: 'string', defaultValue: '' },
20
23
  limit: { type: 'number', defaultValue: 10 },
@@ -8,18 +8,18 @@
8
8
  },
9
9
  "scripts": {
10
10
  "typecheck": "tsc --noEmit",
11
- "lint": "oxlint --type-aware src",
11
+ "lint": "oxlint --type-aware src app.ts",
12
12
  "format": "oxfmt src app.ts",
13
13
  "format:check": "oxfmt --check src app.ts",
14
14
  "dev": "bun --hot src/server.ts",
15
15
  "build": "bun run typecheck && bun build src/index.html --outdir=dist --production",
16
16
  "check": "bun run lint && bun run format:check && bun run build",
17
- "lint:fix": "oxlint --type-aware --fix src"
17
+ "lint:fix": "oxlint --type-aware --fix src app.ts"
18
18
  },
19
19
  "dependencies": {
20
- "@altertable/data-app": "0.77.0",
21
- "@altertable/data-app-bun": "0.77.0",
22
- "@altertable/data-app-react": "0.77.0",
20
+ "@altertable/data-app": "0.78.0",
21
+ "@altertable/data-app-bun": "0.78.0",
22
+ "@altertable/data-app-react": "0.78.0",
23
23
  "react": "19.3.1",
24
24
  "react-dom": "19.3.1"
25
25
  },
@@ -3,17 +3,16 @@ import {
3
3
  DataApp,
4
4
  DataSection,
5
5
  VisualizationWidget,
6
- Stack,
6
+ Ranking,
7
+ Grid,
8
+ GridItem,
7
9
  } from '@altertable/data-app-react';
8
10
  import { BarChart } from '@altertable/data-app-react/ui';
9
- import { createDataClient } from '@altertable/data-app/client';
11
+ import { formatCount } from '@altertable/data-app/format';
10
12
 
11
13
  import { sampleDataContext } from '#app/data-context.ts';
12
- import { operationFilters } from '#app/filters.ts';
13
- import type { operations } from '#app/operations.ts';
14
- const { defineView } = createDataHooks(
15
- createDataClient<typeof operations>({ filters: operationFilters })
16
- );
14
+ import { operations } from '#app/operations.ts';
15
+ const { defineView } = createDataHooks(operations.createDataClient());
17
16
  const sampleCountsView = defineView({
18
17
  dataContext: sampleDataContext,
19
18
  operation: 'sampleCountsByGroup',
@@ -55,6 +54,7 @@ const segmentCounts = segmentCountsView.dataset({
55
54
  },
56
55
  evidence: { id: 'counts-by-segment', glossaryIds: ['sampleCount'] },
57
56
  });
57
+ // Selecting a group applies the shared group filter to both charts.
58
58
  const groupActions = sampleCounts.actions(
59
59
  action => ({
60
60
  drill: action.filter({
@@ -65,13 +65,11 @@ const groupActions = sampleCounts.actions(
65
65
  }),
66
66
  { primary: 'drill' }
67
67
  );
68
- // Keep only the breakdowns and interactions relevant to the requested metric.
69
68
  const groupContent = sampleCountsView.content(result => (
70
69
  <VisualizationWidget
71
70
  dataset={sampleCounts}
72
71
  source={result}
73
- title="Sample count"
74
- description="Select a group to filter both charts; choose All groups to reset."
72
+ title="Samples by group"
75
73
  actions={groupActions}
76
74
  >
77
75
  {(rows, actions) => (
@@ -81,9 +79,10 @@ const groupContent = sampleCountsView.content(result => (
81
79
  items={rows.map(row => ({
82
80
  ...row,
83
81
  id: row.groupName,
84
- label: row.groupName,
82
+ label: `${row.groupName} · ${formatCount(row.sampleCount, { compact: true })}`,
85
83
  value: row.sampleCount,
86
84
  }))}
85
+ horizontalGrid={false}
87
86
  itemActions={actions}
88
87
  />
89
88
  )}
@@ -94,19 +93,15 @@ const segmentContent = segmentCountsView.content(result => (
94
93
  dataset={segmentCounts}
95
94
  source={result}
96
95
  title="Samples by segment"
97
- description="Segment breakdown for the selected group scope."
98
96
  >
99
- {(rows, actions) => (
100
- <BarChart
101
- ariaLabel="Sample counts by segment"
102
- unit="samples"
97
+ {rows => (
98
+ <Ranking
99
+ aria-label="Sample counts by segment"
103
100
  items={rows.map(row => ({
104
- ...row,
105
101
  id: row.segmentName,
106
102
  label: row.segmentName,
107
103
  value: row.sampleCount,
108
104
  }))}
109
- itemActions={actions}
110
105
  />
111
106
  )}
112
107
  </VisualizationWidget>
@@ -114,10 +109,14 @@ const segmentContent = segmentCountsView.content(result => (
114
109
  export function App() {
115
110
  return (
116
111
  <DataApp view={sampleCountsView} showToolbar={false}>
117
- <Stack>
118
- <DataSection content={groupContent} label="Sample count" />
119
- <DataSection content={segmentContent} label="Samples by segment" />
120
- </Stack>
112
+ <Grid columns={3}>
113
+ <GridItem span={2}>
114
+ <DataSection content={groupContent} />
115
+ </GridItem>
116
+ <GridItem>
117
+ <DataSection content={segmentContent} />
118
+ </GridItem>
119
+ </Grid>
121
120
  </DataApp>
122
121
  );
123
122
  }
@@ -1,15 +1,19 @@
1
1
  import { createDataContext } from '@altertable/data-app-react';
2
+
3
+ import { operations } from '#app/operations.ts';
4
+
2
5
  const queryNames = {
3
- sampleCountsByGroup: 'sampleCountsByGroup',
4
- sampleCountsBySegment: 'sampleCountsBySegment',
5
- } as const;
6
+ ...operations.sampleCountsByGroup.queryNames,
7
+ ...operations.sampleCountsBySegment.queryNames,
8
+ };
6
9
  export const sampleDataContext = createDataContext(queryNames)({
7
10
  description:
8
- 'The starter_sample_counts semantic view measures fictional samples by group and segment. Replace it with the requested semantic metric before publishing.',
11
+ 'The starter_sample_counts semantic view measures fictional sample volume by group and segment. The source has no time dimension.',
9
12
  glossary: {
10
13
  sampleCount: {
11
14
  term: 'Sample count',
12
- definition: 'A fixture value: Alpha is 2,200,000 and Beta is 600,000.',
15
+ definition:
16
+ 'Sum of recorded sample counts in the selected group scope. Additive across groups and segments.',
13
17
  queryNames: [
14
18
  queryNames.sampleCountsByGroup,
15
19
  queryNames.sampleCountsBySegment,
@@ -1,7 +1,6 @@
1
1
  import { choiceFilter } from '@altertable/data-app/contract';
2
2
 
3
- // Declare each filter once in this browser-safe module: operations read them on
4
- // the server, and the browser client renders their controls.
3
+ // Reuse this group filter in both operations so one selection updates both charts.
5
4
  const groupName = choiceFilter({
6
5
  key: 'group',
7
6
  label: 'Group',
@@ -13,7 +12,6 @@ const groupName = choiceFilter({
13
12
  ],
14
13
  });
15
14
 
16
- /** The filters each operation reads. */
17
15
  export const operationFilters = {
18
16
  sampleCountsByGroup: { groupName },
19
17
  sampleCountsBySegment: { groupName },
@@ -1,8 +1,8 @@
1
- import { injectDataAppStyles, mountDataApp } from '@altertable/data-app-react';
1
+ import { mountDataApp } from '@altertable/data-app-react';
2
+ import { installLocalQueryLakehouse } from '@altertable/data-app/client';
2
3
 
3
4
  import { App } from '#app/App.tsx';
4
5
  import { dataApp } from '#config';
5
6
 
6
- injectDataAppStyles();
7
-
7
+ installLocalQueryLakehouse();
8
8
  mountDataApp({ app: dataApp, component: App });
@@ -3,11 +3,11 @@ 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 fixture queries read an empty group name as every group. */
6
+ // The sample SQL uses '' for all groups; the filter control uses 'all'.
7
7
  function queryGroup(groupName: string) {
8
8
  return groupName === 'all' ? '' : groupName;
9
9
  }
10
- export const operations = {
10
+ export const operations = dataApp.defineOperations({
11
11
  sampleCountsByGroup: dataApp.defineOperation({
12
12
  filters: operationFilters.sampleCountsByGroup,
13
13
  policy: { maxQueryRows: 10, maxDurationMs: 15000 },
@@ -40,4 +40,4 @@ export const operations = {
40
40
  }));
41
41
  },
42
42
  }),
43
- };
43
+ });
@@ -1,7 +1,9 @@
1
1
  import { serveLocalApp } from '@altertable/data-app-bun';
2
2
 
3
3
  import page from '#app/index.html';
4
- import { operations } from '#app/operations.ts';
5
4
  import { dataApp } from '#config';
6
5
 
7
- serveLocalApp({ page, operations, title: dataApp.title });
6
+ serveLocalApp({
7
+ page,
8
+ app: dataApp,
9
+ });
@@ -1,24 +1,25 @@
1
1
  import { defineDataApp } from '@altertable/data-app';
2
- import {
3
- createDataContext,
4
- injectDataAppStyles,
5
- mountDataApp,
6
- } from '@altertable/data-app-react';
2
+ import { createDataContext, mountDataApp } from '@altertable/data-app-react';
7
3
  import {
8
4
  createDataHooks,
9
5
  DataApp,
10
6
  DataSection,
11
7
  VisualizationWidget,
12
- Stack,
8
+ Ranking,
9
+ Grid,
10
+ GridItem,
13
11
  } from '@altertable/data-app-react';
14
12
  import { BarChart } from '@altertable/data-app-react/ui';
15
- import { createDataClient } from '@altertable/data-app/client';
16
13
  import { choiceFilter, parseCount } from '@altertable/data-app/contract';
17
- const dataApp = defineDataApp({
14
+ import { formatCount } from '@altertable/data-app/format';
15
+ export const dataApp = defineDataApp({
16
+ // Replace the demo title, description, and scope labels with the app's identity.
18
17
  title: 'Sample metric',
19
- description: 'Fixture counts by group; replace with the requested metric.',
18
+ description: 'Explore sample volume across groups and segments.',
20
19
  scope: { organization: 'demo', environment: 'sample' },
21
20
  appearance: { theme: 'system' },
21
+ // starter_sample_counts is the seeded semantic view for fictional sample counts.
22
+ // Replace these queries with verified sources before publishing.
22
23
  queries: {
23
24
  sampleCountsBySegment: {
24
25
  projections: {
@@ -29,7 +30,7 @@ const dataApp = defineDataApp({
29
30
  SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
30
31
  starter_sample_counts DIMENSIONS samples.segment_name METRICS samples.sample_count
31
32
  WHERE $groupName = '' OR samples.group_name = $groupName
32
- ) ORDER BY segment_name LIMIT $limit`,
33
+ ) ORDER BY sample_count DESC, segment_name LIMIT $limit`,
33
34
  params: {
34
35
  groupName: { type: 'string', defaultValue: '' },
35
36
  limit: { type: 'number', defaultValue: 10 },
@@ -52,8 +53,7 @@ SELECT group_name, sample_count FROM SEMANTIC_VIEW(
52
53
  },
53
54
  },
54
55
  });
55
- // Declare each filter once; operations list the filters they read, and views,
56
- // controls, and scope derive from them.
56
+ // Reuse this group filter in both operations so one selection updates both charts.
57
57
  const groupName = choiceFilter({
58
58
  key: 'group',
59
59
  label: 'Group',
@@ -64,11 +64,11 @@ const groupName = choiceFilter({
64
64
  { id: 'Beta', label: 'Beta' },
65
65
  ],
66
66
  });
67
- /** The fixture queries read an empty group name as every group. */
67
+ // The sample SQL uses '' for all groups; the filter control uses 'all'.
68
68
  function queryGroup(groupName: string) {
69
69
  return groupName === 'all' ? '' : groupName;
70
70
  }
71
- const operations = {
71
+ export const operations = dataApp.defineOperations({
72
72
  sampleCountsByGroup: dataApp.defineOperation({
73
73
  filters: { groupName },
74
74
  policy: { maxQueryRows: 10, maxDurationMs: 15000 },
@@ -101,18 +101,19 @@ const operations = {
101
101
  }));
102
102
  },
103
103
  }),
104
- };
104
+ });
105
105
  const queryNames = {
106
106
  ...operations.sampleCountsByGroup.queryNames,
107
107
  ...operations.sampleCountsBySegment.queryNames,
108
108
  };
109
109
  const sampleDataContext = createDataContext(queryNames)({
110
110
  description:
111
- 'The starter_sample_counts semantic view measures fictional samples by group and segment. Replace it with the requested semantic metric before publishing.',
111
+ 'The starter_sample_counts semantic view measures fictional sample volume by group and segment. The source has no time dimension.',
112
112
  glossary: {
113
113
  sampleCount: {
114
114
  term: 'Sample count',
115
- definition: 'A fixture value: Alpha is 2,200,000 and Beta is 600,000.',
115
+ definition:
116
+ 'Sum of recorded sample counts in the selected group scope. Additive across groups and segments.',
116
117
  queryNames: [
117
118
  queryNames.sampleCountsByGroup,
118
119
  queryNames.sampleCountsBySegment,
@@ -120,7 +121,7 @@ const sampleDataContext = createDataContext(queryNames)({
120
121
  },
121
122
  },
122
123
  });
123
- const { defineView } = createDataHooks(createDataClient({ operations }));
124
+ const { defineView } = createDataHooks(operations.createDataClient());
124
125
  const sampleCountsView = defineView({
125
126
  dataContext: sampleDataContext,
126
127
  operation: 'sampleCountsByGroup',
@@ -162,6 +163,7 @@ const segmentCounts = segmentCountsView.dataset({
162
163
  },
163
164
  evidence: { id: 'counts-by-segment', glossaryIds: ['sampleCount'] },
164
165
  });
166
+ // Selecting a group applies the shared group filter to both charts.
165
167
  const groupActions = sampleCounts.actions(
166
168
  action => ({
167
169
  drill: action.filter({
@@ -172,13 +174,11 @@ const groupActions = sampleCounts.actions(
172
174
  }),
173
175
  { primary: 'drill' }
174
176
  );
175
- // Keep only the breakdowns and interactions relevant to the requested metric.
176
177
  const groupContent = sampleCountsView.content(result => (
177
178
  <VisualizationWidget
178
179
  dataset={sampleCounts}
179
180
  source={result}
180
- title="Sample count"
181
- description="Select a group to filter both charts; choose All groups to reset."
181
+ title="Samples by group"
182
182
  actions={groupActions}
183
183
  >
184
184
  {(rows, actions) => (
@@ -188,9 +188,10 @@ const groupContent = sampleCountsView.content(result => (
188
188
  items={rows.map(row => ({
189
189
  ...row,
190
190
  id: row.groupName,
191
- label: row.groupName,
191
+ label: `${row.groupName} · ${formatCount(row.sampleCount, { compact: true })}`,
192
192
  value: row.sampleCount,
193
193
  }))}
194
+ horizontalGrid={false}
194
195
  itemActions={actions}
195
196
  />
196
197
  )}
@@ -201,19 +202,15 @@ const segmentContent = segmentCountsView.content(result => (
201
202
  dataset={segmentCounts}
202
203
  source={result}
203
204
  title="Samples by segment"
204
- description="Segment breakdown for the selected group scope."
205
205
  >
206
- {(rows, actions) => (
207
- <BarChart
208
- ariaLabel="Sample counts by segment"
209
- unit="samples"
206
+ {rows => (
207
+ <Ranking
208
+ aria-label="Sample counts by segment"
210
209
  items={rows.map(row => ({
211
- ...row,
212
210
  id: row.segmentName,
213
211
  label: row.segmentName,
214
212
  value: row.sampleCount,
215
213
  }))}
216
- itemActions={actions}
217
214
  />
218
215
  )}
219
216
  </VisualizationWidget>
@@ -221,12 +218,15 @@ const segmentContent = segmentCountsView.content(result => (
221
218
  function App() {
222
219
  return (
223
220
  <DataApp view={sampleCountsView} showToolbar={false}>
224
- <Stack>
225
- <DataSection content={groupContent} label="Sample count" />
226
- <DataSection content={segmentContent} label="Samples by segment" />
227
- </Stack>
221
+ <Grid columns={3}>
222
+ <GridItem span={2}>
223
+ <DataSection content={groupContent} />
224
+ </GridItem>
225
+ <GridItem>
226
+ <DataSection content={segmentContent} />
227
+ </GridItem>
228
+ </Grid>
228
229
  </DataApp>
229
230
  );
230
231
  }
231
- injectDataAppStyles();
232
232
  mountDataApp({ app: dataApp, component: App });