@altertable/data-app-examples 0.76.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.
- package/package.json +1 -1
- package/templates/starter-data-app/index.tsx +686 -136
- package/templates/starter-finding-data-app/index.tsx +530 -188
- package/templates/starter-local-data-app/AGENTS.md +9 -9
- package/templates/starter-local-data-app/README.md +14 -5
- package/templates/starter-local-data-app/app.ts +256 -21
- package/templates/starter-local-data-app/package.json +5 -5
- package/templates/starter-local-data-app/src/App.tsx +276 -5
- package/templates/starter-local-data-app/src/data-context.ts +28 -14
- package/templates/starter-local-data-app/src/filters.ts +35 -0
- package/templates/starter-local-data-app/src/main.tsx +3 -3
- package/templates/starter-local-data-app/src/operations.ts +129 -4
- package/templates/starter-local-data-app/src/server.ts +1 -2
- package/templates/starter-local-finding-data-app/AGENTS.md +9 -9
- package/templates/starter-local-finding-data-app/README.md +3 -4
- package/templates/starter-local-finding-data-app/app.ts +63 -34
- package/templates/starter-local-finding-data-app/package.json +5 -5
- package/templates/starter-local-finding-data-app/src/App.tsx +308 -126
- package/templates/starter-local-finding-data-app/src/data-context.ts +19 -4
- package/templates/starter-local-finding-data-app/src/filters.ts +66 -0
- package/templates/starter-local-finding-data-app/src/main.tsx +3 -3
- package/templates/starter-local-finding-data-app/src/operations.ts +101 -37
- package/templates/starter-local-finding-data-app/src/server.ts +4 -2
- package/templates/starter-local-metric-data-app/AGENTS.md +9 -9
- package/templates/starter-local-metric-data-app/README.md +3 -4
- package/templates/starter-local-metric-data-app/app.ts +5 -2
- package/templates/starter-local-metric-data-app/package.json +5 -5
- package/templates/starter-local-metric-data-app/src/App.tsx +69 -71
- package/templates/starter-local-metric-data-app/src/data-context.ts +9 -5
- package/templates/starter-local-metric-data-app/src/filters.ts +18 -0
- package/templates/starter-local-metric-data-app/src/main.tsx +3 -3
- package/templates/starter-local-metric-data-app/src/operations.ts +34 -41
- package/templates/starter-local-metric-data-app/src/server.ts +4 -2
- package/templates/starter-metric-data-app/index.tsx +125 -122
|
@@ -1,25 +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
|
-
|
|
13
|
-
|
|
8
|
+
Ranking,
|
|
9
|
+
Grid,
|
|
10
|
+
GridItem,
|
|
14
11
|
} from '@altertable/data-app-react';
|
|
15
12
|
import { BarChart } from '@altertable/data-app-react/ui';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
const dataApp = defineDataApp({
|
|
13
|
+
import { choiceFilter, parseCount } from '@altertable/data-app/contract';
|
|
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.
|
|
19
17
|
title: 'Sample metric',
|
|
20
|
-
description: '
|
|
18
|
+
description: 'Explore sample volume across groups and segments.',
|
|
21
19
|
scope: { organization: 'demo', environment: 'sample' },
|
|
22
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.
|
|
23
23
|
queries: {
|
|
24
24
|
sampleCountsBySegment: {
|
|
25
25
|
projections: {
|
|
@@ -30,7 +30,7 @@ const dataApp = defineDataApp({
|
|
|
30
30
|
SELECT segment_name, sample_count FROM SEMANTIC_VIEW(
|
|
31
31
|
starter_sample_counts DIMENSIONS samples.segment_name METRICS samples.sample_count
|
|
32
32
|
WHERE $groupName = '' OR samples.group_name = $groupName
|
|
33
|
-
) ORDER BY segment_name LIMIT $limit`,
|
|
33
|
+
) ORDER BY sample_count DESC, segment_name LIMIT $limit`,
|
|
34
34
|
params: {
|
|
35
35
|
groupName: { type: 'string', defaultValue: '' },
|
|
36
36
|
limit: { type: 'number', defaultValue: 10 },
|
|
@@ -53,61 +53,67 @@ SELECT group_name, sample_count FROM SEMANTIC_VIEW(
|
|
|
53
53
|
},
|
|
54
54
|
},
|
|
55
55
|
});
|
|
56
|
-
|
|
56
|
+
// Reuse this group filter in both operations so one selection updates both charts.
|
|
57
|
+
const groupName = choiceFilter({
|
|
58
|
+
key: 'group',
|
|
59
|
+
label: 'Group',
|
|
60
|
+
defaultValue: 'all',
|
|
61
|
+
options: [
|
|
62
|
+
{ id: 'all', label: 'All groups' },
|
|
63
|
+
{ id: 'Alpha', label: 'Alpha' },
|
|
64
|
+
{ id: 'Beta', label: 'Beta' },
|
|
65
|
+
],
|
|
66
|
+
});
|
|
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
|
+
export const operations = dataApp.defineOperations({
|
|
57
72
|
sampleCountsByGroup: dataApp.defineOperation({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
filters: { groupName },
|
|
74
|
+
policy: { maxQueryRows: 10, maxDurationMs: 15000 },
|
|
75
|
+
async run({ query }, { groupName }) {
|
|
76
|
+
const queryResult = await query('sampleCountsByGroup', {
|
|
77
|
+
groupName: queryGroup(groupName),
|
|
78
|
+
});
|
|
79
|
+
return queryResult.rows.map(
|
|
80
|
+
(row): { groupName: 'Alpha' | 'Beta'; sampleCount: number } => {
|
|
81
|
+
if (row.group_name !== 'Alpha' && row.group_name !== 'Beta')
|
|
82
|
+
throw new Error('Unexpected fixture group.');
|
|
83
|
+
return {
|
|
84
|
+
groupName: row.group_name,
|
|
85
|
+
sampleCount: parseCount(row.sample_count),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
);
|
|
68
89
|
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
{ groupName: 'Beta' },
|
|
73
|
-
],
|
|
90
|
+
}),
|
|
91
|
+
sampleCountsBySegment: dataApp.defineOperation({
|
|
92
|
+
filters: { groupName },
|
|
74
93
|
policy: { maxQueryRows: 10, maxDurationMs: 15000 },
|
|
75
94
|
async run({ query }, { groupName }) {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
]);
|
|
84
|
-
return {
|
|
85
|
-
groups: groups.rows.map(
|
|
86
|
-
(row): { groupName: 'Alpha' | 'Beta'; sampleCount: number } => {
|
|
87
|
-
if (row.group_name !== 'Alpha' && row.group_name !== 'Beta')
|
|
88
|
-
throw new Error('Unexpected fixture group.');
|
|
89
|
-
return {
|
|
90
|
-
groupName: row.group_name,
|
|
91
|
-
sampleCount: parseCount(row.sample_count),
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
),
|
|
95
|
-
segments: segments.rows.map(row => ({
|
|
96
|
-
segmentName: row.segment_name,
|
|
97
|
-
sampleCount: parseCount(row.sample_count),
|
|
98
|
-
})),
|
|
99
|
-
};
|
|
95
|
+
const queryResult = await query('sampleCountsBySegment', {
|
|
96
|
+
groupName: queryGroup(groupName),
|
|
97
|
+
});
|
|
98
|
+
return queryResult.rows.map(row => ({
|
|
99
|
+
segmentName: row.segment_name,
|
|
100
|
+
sampleCount: parseCount(row.sample_count),
|
|
101
|
+
}));
|
|
100
102
|
},
|
|
101
103
|
}),
|
|
104
|
+
});
|
|
105
|
+
const queryNames = {
|
|
106
|
+
...operations.sampleCountsByGroup.queryNames,
|
|
107
|
+
...operations.sampleCountsBySegment.queryNames,
|
|
102
108
|
};
|
|
103
|
-
const queryNames = operations.sampleCountsByGroup.queryNames;
|
|
104
109
|
const sampleDataContext = createDataContext(queryNames)({
|
|
105
110
|
description:
|
|
106
|
-
'The starter_sample_counts semantic view measures fictional
|
|
111
|
+
'The starter_sample_counts semantic view measures fictional sample volume by group and segment. The source has no time dimension.',
|
|
107
112
|
glossary: {
|
|
108
113
|
sampleCount: {
|
|
109
114
|
term: 'Sample count',
|
|
110
|
-
definition:
|
|
115
|
+
definition:
|
|
116
|
+
'Sum of recorded sample counts in the selected group scope. Additive across groups and segments.',
|
|
111
117
|
queryNames: [
|
|
112
118
|
queryNames.sampleCountsByGroup,
|
|
113
119
|
queryNames.sampleCountsBySegment,
|
|
@@ -115,25 +121,11 @@ const sampleDataContext = createDataContext(queryNames)({
|
|
|
115
121
|
},
|
|
116
122
|
},
|
|
117
123
|
});
|
|
118
|
-
const {
|
|
119
|
-
const sampleCountsView =
|
|
124
|
+
const { defineView } = createDataHooks(operations.createDataClient());
|
|
125
|
+
const sampleCountsView = defineView({
|
|
120
126
|
dataContext: sampleDataContext,
|
|
121
127
|
operation: 'sampleCountsByGroup',
|
|
122
|
-
|
|
123
|
-
groupName: choiceVariable({
|
|
124
|
-
key: 'group',
|
|
125
|
-
label: 'Group',
|
|
126
|
-
defaultValue: 'all',
|
|
127
|
-
options: [
|
|
128
|
-
{ id: 'all', label: 'All groups' },
|
|
129
|
-
{ id: 'Alpha', label: 'Alpha' },
|
|
130
|
-
{ id: 'Beta', label: 'Beta' },
|
|
131
|
-
],
|
|
132
|
-
}),
|
|
133
|
-
},
|
|
134
|
-
describeInput: ({ groupName }) =>
|
|
135
|
-
groupName === 'all' ? 'all groups' : groupName,
|
|
136
|
-
isEmpty: result => result.groups.length === 0,
|
|
128
|
+
isEmpty: rows => rows.length === 0,
|
|
137
129
|
emptyFallback: {
|
|
138
130
|
title: 'No matching groups',
|
|
139
131
|
description: 'No observations are available for this query.',
|
|
@@ -141,7 +133,7 @@ const sampleCountsView = defineDataView({
|
|
|
141
133
|
});
|
|
142
134
|
const sampleCounts = sampleCountsView.dataset({
|
|
143
135
|
name: 'Sample counts',
|
|
144
|
-
select:
|
|
136
|
+
select: rows => rows,
|
|
145
137
|
rowKey: row => row.groupName,
|
|
146
138
|
columns: {
|
|
147
139
|
groupName: { label: 'Group', value: row => row.groupName },
|
|
@@ -152,9 +144,18 @@ const sampleCounts = sampleCountsView.dataset({
|
|
|
152
144
|
glossaryIds: ['sampleCount'],
|
|
153
145
|
},
|
|
154
146
|
});
|
|
155
|
-
const
|
|
147
|
+
const segmentCountsView = defineView({
|
|
148
|
+
dataContext: sampleDataContext,
|
|
149
|
+
operation: 'sampleCountsBySegment',
|
|
150
|
+
isEmpty: rows => rows.length === 0,
|
|
151
|
+
emptyFallback: {
|
|
152
|
+
title: 'No matching segments',
|
|
153
|
+
description: 'No observations are available for this query.',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
const segmentCounts = segmentCountsView.dataset({
|
|
156
157
|
name: 'Counts by segment',
|
|
157
|
-
select:
|
|
158
|
+
select: rows => rows,
|
|
158
159
|
rowKey: row => row.segmentName,
|
|
159
160
|
columns: {
|
|
160
161
|
segmentName: { label: 'Segment', value: row => row.segmentName },
|
|
@@ -162,6 +163,7 @@ const segments = sampleCountsView.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,58 +174,59 @@ const groupActions = sampleCounts.actions(
|
|
|
172
174
|
}),
|
|
173
175
|
{ primary: 'drill' }
|
|
174
176
|
);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
itemActions={actions}
|
|
216
|
-
/>
|
|
217
|
-
)}
|
|
218
|
-
</VisualizationWidget>
|
|
219
|
-
</Stack>
|
|
177
|
+
const groupContent = sampleCountsView.content(result => (
|
|
178
|
+
<VisualizationWidget
|
|
179
|
+
dataset={sampleCounts}
|
|
180
|
+
source={result}
|
|
181
|
+
title="Samples by group"
|
|
182
|
+
actions={groupActions}
|
|
183
|
+
>
|
|
184
|
+
{(rows, actions) => (
|
|
185
|
+
<BarChart
|
|
186
|
+
ariaLabel="Sample counts by group"
|
|
187
|
+
unit="samples"
|
|
188
|
+
items={rows.map(row => ({
|
|
189
|
+
...row,
|
|
190
|
+
id: row.groupName,
|
|
191
|
+
label: `${row.groupName} · ${formatCount(row.sampleCount, { compact: true })}`,
|
|
192
|
+
value: row.sampleCount,
|
|
193
|
+
}))}
|
|
194
|
+
horizontalGrid={false}
|
|
195
|
+
itemActions={actions}
|
|
196
|
+
/>
|
|
197
|
+
)}
|
|
198
|
+
</VisualizationWidget>
|
|
199
|
+
));
|
|
200
|
+
const segmentContent = segmentCountsView.content(result => (
|
|
201
|
+
<VisualizationWidget
|
|
202
|
+
dataset={segmentCounts}
|
|
203
|
+
source={result}
|
|
204
|
+
title="Samples by segment"
|
|
205
|
+
>
|
|
206
|
+
{rows => (
|
|
207
|
+
<Ranking
|
|
208
|
+
aria-label="Sample counts by segment"
|
|
209
|
+
items={rows.map(row => ({
|
|
210
|
+
id: row.segmentName,
|
|
211
|
+
label: row.segmentName,
|
|
212
|
+
value: row.sampleCount,
|
|
213
|
+
}))}
|
|
214
|
+
/>
|
|
215
|
+
)}
|
|
216
|
+
</VisualizationWidget>
|
|
220
217
|
));
|
|
221
218
|
function App() {
|
|
222
219
|
return (
|
|
223
220
|
<DataApp view={sampleCountsView} showToolbar={false}>
|
|
224
|
-
<
|
|
221
|
+
<Grid columns={3}>
|
|
222
|
+
<GridItem span={2}>
|
|
223
|
+
<DataSection content={groupContent} />
|
|
224
|
+
</GridItem>
|
|
225
|
+
<GridItem>
|
|
226
|
+
<DataSection content={segmentContent} />
|
|
227
|
+
</GridItem>
|
|
228
|
+
</Grid>
|
|
225
229
|
</DataApp>
|
|
226
230
|
);
|
|
227
231
|
}
|
|
228
|
-
injectDataAppStyles();
|
|
229
232
|
mountDataApp({ app: dataApp, component: App });
|