@altertable/data-app-examples 0.76.0 → 0.77.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 +60 -57
- package/templates/starter-finding-data-app/index.tsx +224 -166
- package/templates/starter-local-data-app/AGENTS.md +9 -9
- package/templates/starter-local-data-app/README.md +1 -1
- package/templates/starter-local-data-app/package.json +3 -3
- package/templates/starter-local-finding-data-app/AGENTS.md +9 -9
- package/templates/starter-local-finding-data-app/README.md +2 -2
- package/templates/starter-local-finding-data-app/app.ts +44 -33
- package/templates/starter-local-finding-data-app/package.json +3 -3
- package/templates/starter-local-finding-data-app/src/App.tsx +98 -113
- package/templates/starter-local-finding-data-app/src/data-context.ts +8 -2
- package/templates/starter-local-finding-data-app/src/filters.ts +48 -0
- package/templates/starter-local-finding-data-app/src/operations.ts +52 -34
- package/templates/starter-local-metric-data-app/AGENTS.md +9 -9
- package/templates/starter-local-metric-data-app/README.md +2 -2
- package/templates/starter-local-metric-data-app/package.json +3 -3
- package/templates/starter-local-metric-data-app/src/App.tsx +66 -67
- package/templates/starter-local-metric-data-app/src/filters.ts +20 -0
- package/templates/starter-local-metric-data-app/src/operations.ts +32 -39
- package/templates/starter-metric-data-app/index.tsx +110 -107
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { defineDataApp } from '@altertable/data-app';
|
|
2
|
-
import {
|
|
3
|
-
dateTimeRangeVariable,
|
|
4
|
-
defineDateRangeContract,
|
|
5
|
-
} from '@altertable/data-app/contract';
|
|
6
2
|
|
|
7
3
|
export const dataApp = defineDataApp({
|
|
8
4
|
title: 'Sample finding',
|
|
@@ -11,49 +7,64 @@ export const dataApp = defineDataApp({
|
|
|
11
7
|
scope: { organization: 'demo', environment: 'sample' },
|
|
12
8
|
appearance: { theme: 'system' },
|
|
13
9
|
queries: {
|
|
14
|
-
|
|
10
|
+
sampleTotal: {
|
|
11
|
+
projections: { sample_count: { type: 'number' } },
|
|
12
|
+
statement: `
|
|
13
|
+
SELECT COALESCE(SUM(sample_count), 0) AS sample_count
|
|
14
|
+
FROM starter_demo.daily_samples
|
|
15
|
+
WHERE sample_date >= $period.from AND sample_date < $period.to`,
|
|
16
|
+
params: { period: { type: 'dateTimeRange' } },
|
|
17
|
+
},
|
|
18
|
+
samplesOverTime: {
|
|
19
|
+
projections: {
|
|
20
|
+
period_start: { type: 'string' },
|
|
21
|
+
sample_count: { type: 'number' },
|
|
22
|
+
},
|
|
23
|
+
statement: `
|
|
24
|
+
SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
|
|
25
|
+
SUM(sample_count) AS sample_count
|
|
26
|
+
FROM starter_demo.daily_samples
|
|
27
|
+
WHERE sample_date >= $period.from AND sample_date < $period.to
|
|
28
|
+
GROUP BY ALL ORDER BY period_start LIMIT 200`,
|
|
29
|
+
params: {
|
|
30
|
+
period: { type: 'dateTimeRange' },
|
|
31
|
+
grain: { type: 'string', defaultValue: 'day' },
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
samplesByMember: {
|
|
35
|
+
projections: {
|
|
36
|
+
member: { type: 'string' },
|
|
37
|
+
sample_count: { type: 'number' },
|
|
38
|
+
},
|
|
39
|
+
statement: `
|
|
40
|
+
SELECT CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
|
|
41
|
+
SUM(sample_count) AS sample_count
|
|
42
|
+
FROM starter_demo.daily_samples
|
|
43
|
+
WHERE sample_date >= $period.from AND sample_date < $period.to
|
|
44
|
+
GROUP BY ALL ORDER BY sample_count DESC LIMIT 50`,
|
|
45
|
+
params: {
|
|
46
|
+
period: { type: 'dateTimeRange' },
|
|
47
|
+
breakdown: { type: 'string', defaultValue: 'segment' },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
sampleRows: {
|
|
15
51
|
projections: {
|
|
16
52
|
period_start: { type: 'string' },
|
|
17
53
|
member: { type: 'string' },
|
|
18
|
-
selected: { type: 'boolean' },
|
|
19
54
|
sample_count: { type: 'number' },
|
|
20
55
|
},
|
|
21
56
|
statement: `
|
|
22
57
|
SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
|
|
23
58
|
CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
|
|
24
|
-
sample_date >= CAST($selected_start AS TIMESTAMP) AS selected,
|
|
25
59
|
SUM(sample_count) AS sample_count
|
|
26
60
|
FROM starter_demo.daily_samples
|
|
27
|
-
WHERE sample_date >=
|
|
28
|
-
GROUP BY ALL ORDER BY period_start, member LIMIT
|
|
61
|
+
WHERE sample_date >= $period.from AND sample_date < $period.to
|
|
62
|
+
GROUP BY ALL ORDER BY period_start, member LIMIT 500`,
|
|
29
63
|
params: {
|
|
30
|
-
|
|
31
|
-
end: { type: 'string', defaultValue: '2026-03-16T00:00:00Z' },
|
|
32
|
-
selected_start: {
|
|
33
|
-
type: 'string',
|
|
34
|
-
defaultValue: '2026-03-09T00:00:00Z',
|
|
35
|
-
},
|
|
64
|
+
period: { type: 'dateTimeRange' },
|
|
36
65
|
grain: { type: 'string', defaultValue: 'day' },
|
|
37
66
|
breakdown: { type: 'string', defaultValue: 'segment' },
|
|
38
|
-
limit: { type: 'number', defaultValue: 500 },
|
|
39
67
|
},
|
|
40
68
|
},
|
|
41
69
|
},
|
|
42
70
|
});
|
|
43
|
-
export const calendar = defineDateRangeContract({
|
|
44
|
-
minDate: '2026-01-05',
|
|
45
|
-
maxDate: '2026-03-29',
|
|
46
|
-
maxRangeDays: 28,
|
|
47
|
-
timeZone: 'UTC',
|
|
48
|
-
});
|
|
49
|
-
export const findingPeriod = {
|
|
50
|
-
from: new Date('2026-03-09T00:00:00Z'),
|
|
51
|
-
to: new Date('2026-03-16T00:00:00Z'),
|
|
52
|
-
};
|
|
53
|
-
export const period = dateTimeRangeVariable({
|
|
54
|
-
key: 'period',
|
|
55
|
-
contract: calendar,
|
|
56
|
-
allowComparison: true,
|
|
57
|
-
defaultValue: findingPeriod,
|
|
58
|
-
presets: [{ label: 'Finding period', range: findingPeriod }],
|
|
59
|
-
});
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"lint:fix": "oxlint --type-aware --fix src"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@altertable/data-app": "0.
|
|
21
|
-
"@altertable/data-app-bun": "0.
|
|
22
|
-
"@altertable/data-app-react": "0.
|
|
20
|
+
"@altertable/data-app": "0.77.0",
|
|
21
|
+
"@altertable/data-app-bun": "0.77.0",
|
|
22
|
+
"@altertable/data-app-react": "0.77.0",
|
|
23
23
|
"react": "19.3.1",
|
|
24
24
|
"react-dom": "19.3.1"
|
|
25
25
|
},
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
choiceVariable,
|
|
3
2
|
createDataHooks,
|
|
4
3
|
DataApp,
|
|
5
4
|
DataSection,
|
|
@@ -12,97 +11,73 @@ import { BarChart, ComposedChart } from '@altertable/data-app-react/ui';
|
|
|
12
11
|
import { createDataClient } from '@altertable/data-app/client';
|
|
13
12
|
|
|
14
13
|
import { sampleDataContext } from '#app/data-context.ts';
|
|
14
|
+
import { operationFilters } from '#app/filters.ts';
|
|
15
15
|
import type { operations } from '#app/operations.ts';
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
16
|
+
const { defineView } = createDataHooks(
|
|
17
|
+
createDataClient<typeof operations>({ filters: operationFilters })
|
|
18
|
+
);
|
|
19
|
+
const count = { kind: 'count' } as const;
|
|
20
|
+
const emptyFallback = {
|
|
21
|
+
title: 'No samples in this period',
|
|
22
|
+
description: 'No observations are available for this period.',
|
|
23
|
+
};
|
|
24
|
+
const totalView = defineView({
|
|
20
25
|
dataContext: sampleDataContext,
|
|
21
|
-
operation: '
|
|
22
|
-
time: period,
|
|
23
|
-
variables: {
|
|
24
|
-
grain: choiceVariable({
|
|
25
|
-
key: 'grain',
|
|
26
|
-
label: 'Grain',
|
|
27
|
-
defaultValue: 'day',
|
|
28
|
-
options: [
|
|
29
|
-
{ id: 'day', label: 'Day' },
|
|
30
|
-
{ id: 'week', label: 'Week' },
|
|
31
|
-
],
|
|
32
|
-
presentation: { group: 'display', control: 'widget' },
|
|
33
|
-
}),
|
|
34
|
-
breakdown: choiceVariable({
|
|
35
|
-
key: 'breakdown',
|
|
36
|
-
label: 'Breakdown',
|
|
37
|
-
defaultValue: 'segment',
|
|
38
|
-
options: [
|
|
39
|
-
{ id: 'segment', label: 'Segment' },
|
|
40
|
-
{ id: 'group', label: 'Group' },
|
|
41
|
-
],
|
|
42
|
-
presentation: { group: 'display', control: 'widget' },
|
|
43
|
-
}),
|
|
44
|
-
},
|
|
45
|
-
isEmpty: rows => rows.length === 0,
|
|
46
|
-
emptyFallback: {
|
|
47
|
-
title: 'No samples in this period',
|
|
48
|
-
description: 'No observations are available for this period.',
|
|
49
|
-
},
|
|
26
|
+
operation: 'sampleTotal',
|
|
50
27
|
});
|
|
51
|
-
|
|
52
|
-
function total(rows: readonly SampleRow[]) {
|
|
53
|
-
return rows.reduce((sum, row) => sum + row.sampleCount, 0);
|
|
54
|
-
}
|
|
55
|
-
function totalsBy<Row extends SampleRow>(
|
|
56
|
-
rows: readonly Row[],
|
|
57
|
-
key: (row: Row) => string
|
|
58
|
-
) {
|
|
59
|
-
const totals = new Map<string, number>();
|
|
60
|
-
for (const row of rows)
|
|
61
|
-
totals.set(key(row), (totals.get(key(row)) ?? 0) + row.sampleCount);
|
|
62
|
-
return [...totals].map(([id, sampleCount]) => ({ id, sampleCount }));
|
|
63
|
-
}
|
|
64
|
-
const count = { kind: 'count' } as const;
|
|
65
|
-
const totalSamples = samplesView.metric(
|
|
28
|
+
const totalSamples = totalView.metric(
|
|
66
29
|
{
|
|
67
30
|
id: 'total-samples',
|
|
68
31
|
label: 'Samples',
|
|
69
32
|
glossaryId: 'sampleCount',
|
|
70
33
|
format: count,
|
|
71
34
|
},
|
|
72
|
-
|
|
73
|
-
current: total
|
|
74
|
-
...(
|
|
75
|
-
previous: total(rows.filter(row => !row.selected)),
|
|
76
|
-
}),
|
|
35
|
+
total => ({
|
|
36
|
+
current: total.current,
|
|
37
|
+
...(total.previous !== null && { previous: total.previous }),
|
|
77
38
|
})
|
|
78
39
|
);
|
|
79
|
-
const
|
|
40
|
+
const trendView = defineView({
|
|
41
|
+
dataContext: sampleDataContext,
|
|
42
|
+
operation: 'samplesOverTime',
|
|
43
|
+
isEmpty: rows => rows.length === 0,
|
|
44
|
+
emptyFallback,
|
|
45
|
+
});
|
|
46
|
+
const trend = trendView.dataset({
|
|
80
47
|
name: 'Samples over time',
|
|
81
|
-
select: rows =>
|
|
82
|
-
rowKey: row => row.
|
|
48
|
+
select: rows => rows,
|
|
49
|
+
rowKey: row => row.periodStart,
|
|
83
50
|
columns: {
|
|
84
|
-
|
|
51
|
+
periodStart: { label: 'Period start', value: row => row.periodStart },
|
|
85
52
|
sampleCount: { value: row => row.sampleCount, format: count },
|
|
86
53
|
},
|
|
87
54
|
evidence: { id: 'samples-over-time', glossaryIds: ['sampleCount'] },
|
|
88
55
|
});
|
|
89
|
-
const
|
|
56
|
+
const memberView = defineView({
|
|
57
|
+
dataContext: sampleDataContext,
|
|
58
|
+
operation: 'samplesByMember',
|
|
59
|
+
isEmpty: rows => rows.length === 0,
|
|
60
|
+
emptyFallback,
|
|
61
|
+
});
|
|
62
|
+
const byMember = memberView.dataset({
|
|
90
63
|
name: 'Samples by member',
|
|
91
|
-
select: rows =>
|
|
92
|
-
|
|
93
|
-
rows.filter(row => row.selected),
|
|
94
|
-
row => row.member
|
|
95
|
-
),
|
|
96
|
-
rowKey: row => row.id,
|
|
64
|
+
select: rows => rows,
|
|
65
|
+
rowKey: row => row.member,
|
|
97
66
|
columns: {
|
|
98
|
-
|
|
67
|
+
member: { label: 'Member', value: row => row.member },
|
|
99
68
|
sampleCount: { value: row => row.sampleCount, format: count },
|
|
100
69
|
},
|
|
101
70
|
evidence: { id: 'samples-by-member', glossaryIds: ['sampleCount'] },
|
|
102
71
|
});
|
|
103
|
-
const
|
|
72
|
+
const rowsView = defineView({
|
|
73
|
+
dataContext: sampleDataContext,
|
|
74
|
+
operation: 'sampleRows',
|
|
75
|
+
isEmpty: rows => rows.length === 0,
|
|
76
|
+
emptyFallback,
|
|
77
|
+
});
|
|
78
|
+
const sampleRows = rowsView.dataset({
|
|
104
79
|
name: 'Samples',
|
|
105
|
-
select: rows => rows
|
|
80
|
+
select: rows => rows,
|
|
106
81
|
rowKey: row => `${row.periodStart}:${row.member}`,
|
|
107
82
|
columns: {
|
|
108
83
|
periodStart: { label: 'Period start', value: row => row.periodStart },
|
|
@@ -112,54 +87,64 @@ const sampleRows = samplesView.dataset({
|
|
|
112
87
|
evidence: { id: 'samples', glossaryIds: ['sampleCount'] },
|
|
113
88
|
});
|
|
114
89
|
// The Finding's text is shown above the app; keep content to charts and captions.
|
|
115
|
-
const
|
|
116
|
-
<
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
90
|
+
const totalContent = totalView.content(result => (
|
|
91
|
+
<MetricWidget metric={totalSamples} source={result} />
|
|
92
|
+
));
|
|
93
|
+
const trendContent = trendView.content(result => (
|
|
94
|
+
<VisualizationWidget
|
|
95
|
+
dataset={trend}
|
|
96
|
+
source={result}
|
|
97
|
+
title="Samples over time"
|
|
98
|
+
description="Includes the previous period when comparison is on."
|
|
99
|
+
breakdown={trendView.breakdown('grain')}
|
|
100
|
+
>
|
|
101
|
+
{rows => (
|
|
102
|
+
<ComposedChart
|
|
103
|
+
ariaLabel="Samples over time"
|
|
104
|
+
data={rows}
|
|
105
|
+
valueFormat={count}
|
|
106
|
+
>
|
|
107
|
+
<ComposedChart.XAxis dataKey="periodStart" />
|
|
108
|
+
<ComposedChart.YAxis />
|
|
109
|
+
<ComposedChart.Line dataKey="sampleCount" name="Samples" />
|
|
110
|
+
<ComposedChart.Tooltip />
|
|
111
|
+
</ComposedChart>
|
|
112
|
+
)}
|
|
113
|
+
</VisualizationWidget>
|
|
114
|
+
));
|
|
115
|
+
const memberContent = memberView.content(result => (
|
|
116
|
+
<VisualizationWidget
|
|
117
|
+
dataset={byMember}
|
|
118
|
+
source={result}
|
|
119
|
+
title="Samples by member"
|
|
120
|
+
breakdown={memberView.breakdown('breakdown')}
|
|
121
|
+
>
|
|
122
|
+
{rows => (
|
|
123
|
+
<BarChart
|
|
124
|
+
ariaLabel="Samples by member"
|
|
125
|
+
unit="samples"
|
|
126
|
+
items={rows.map(row => ({
|
|
127
|
+
...row,
|
|
128
|
+
id: row.member,
|
|
129
|
+
label: row.member,
|
|
130
|
+
value: row.sampleCount,
|
|
131
|
+
}))}
|
|
132
|
+
/>
|
|
133
|
+
)}
|
|
134
|
+
</VisualizationWidget>
|
|
135
|
+
));
|
|
136
|
+
const rowsContent = rowsView.content(result => (
|
|
137
|
+
<TableWidget dataset={sampleRows} source={result} title="Samples" />
|
|
158
138
|
));
|
|
159
139
|
export function App() {
|
|
160
140
|
return (
|
|
161
|
-
<DataApp view={
|
|
162
|
-
<
|
|
141
|
+
<DataApp view={totalView} showToolbar={false}>
|
|
142
|
+
<Stack>
|
|
143
|
+
<DataSection content={totalContent} />
|
|
144
|
+
<DataSection content={trendContent} />
|
|
145
|
+
<DataSection content={memberContent} />
|
|
146
|
+
<DataSection content={rowsContent} />
|
|
147
|
+
</Stack>
|
|
163
148
|
</DataApp>
|
|
164
149
|
);
|
|
165
150
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { createDataContext } from '@altertable/data-app-react';
|
|
2
|
-
|
|
2
|
+
// The browser imports operations by type only, so name their queries here.
|
|
3
|
+
const queryNames = {
|
|
4
|
+
sampleTotal: 'sampleTotal',
|
|
5
|
+
samplesOverTime: 'samplesOverTime',
|
|
6
|
+
samplesByMember: 'samplesByMember',
|
|
7
|
+
sampleRows: 'sampleRows',
|
|
8
|
+
} as const;
|
|
3
9
|
export const sampleDataContext = createDataContext(queryNames)({
|
|
4
10
|
description:
|
|
5
11
|
'Fictional daily samples from starter_demo.daily_samples. Replace this evidence with the actual Finding queries.',
|
|
@@ -7,7 +13,7 @@ export const sampleDataContext = createDataContext(queryNames)({
|
|
|
7
13
|
sampleCount: {
|
|
8
14
|
term: 'Sample count',
|
|
9
15
|
definition: 'Fixture samples recorded per day, group, and segment.',
|
|
10
|
-
queryNames:
|
|
16
|
+
queryNames: Object.values(queryNames),
|
|
11
17
|
},
|
|
12
18
|
},
|
|
13
19
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dateTimeRangeFilter,
|
|
3
|
+
displayChoice,
|
|
4
|
+
} from '@altertable/data-app/contract';
|
|
5
|
+
|
|
6
|
+
// Declare each filter once in this browser-safe module: operations read them on
|
|
7
|
+
// the server, and the browser client renders their controls.
|
|
8
|
+
const findingPeriod = {
|
|
9
|
+
from: new Date('2026-03-09T00:00:00Z'),
|
|
10
|
+
to: new Date('2026-03-16T00:00:00Z'),
|
|
11
|
+
};
|
|
12
|
+
const period = dateTimeRangeFilter({
|
|
13
|
+
key: 'period',
|
|
14
|
+
defaultValue: findingPeriod,
|
|
15
|
+
minDate: '2026-01-05',
|
|
16
|
+
maxDate: '2026-03-29',
|
|
17
|
+
maxRangeDays: 28,
|
|
18
|
+
comparison: 'off',
|
|
19
|
+
presets: [{ label: 'Finding period', range: findingPeriod }],
|
|
20
|
+
});
|
|
21
|
+
const grain = displayChoice({
|
|
22
|
+
key: 'grain',
|
|
23
|
+
label: 'Grain',
|
|
24
|
+
defaultValue: 'day',
|
|
25
|
+
options: [
|
|
26
|
+
{ id: 'day', label: 'Day' },
|
|
27
|
+
{ id: 'week', label: 'Week' },
|
|
28
|
+
],
|
|
29
|
+
presentation: { control: 'widget' },
|
|
30
|
+
});
|
|
31
|
+
const breakdown = displayChoice({
|
|
32
|
+
key: 'breakdown',
|
|
33
|
+
label: 'Breakdown',
|
|
34
|
+
defaultValue: 'segment',
|
|
35
|
+
options: [
|
|
36
|
+
{ id: 'segment', label: 'Segment' },
|
|
37
|
+
{ id: 'group', label: 'Group' },
|
|
38
|
+
],
|
|
39
|
+
presentation: { control: 'widget' },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/** The filters each operation reads. */
|
|
43
|
+
export const operationFilters = {
|
|
44
|
+
sampleTotal: { period },
|
|
45
|
+
samplesOverTime: { period, grain },
|
|
46
|
+
samplesByMember: { period, breakdown },
|
|
47
|
+
sampleRows: { period, grain, breakdown },
|
|
48
|
+
};
|
|
@@ -1,41 +1,60 @@
|
|
|
1
1
|
import { parseCount } from '@altertable/data-app/contract';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { operationFilters } from '#app/filters.ts';
|
|
4
|
+
import { dataApp } from '#config';
|
|
5
|
+
// One query per widget: each section loads its own result when it nears the viewport.
|
|
6
|
+
const policy = { maxQueryRows: 500, maxDurationMs: 15000 };
|
|
4
7
|
export const operations = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
sampleTotal: dataApp.defineOperation({
|
|
9
|
+
filters: operationFilters.sampleTotal,
|
|
10
|
+
policy,
|
|
11
|
+
async run({ query }, { period }) {
|
|
12
|
+
const current = await query('sampleTotal', { period: period.range });
|
|
13
|
+
const previous = period.comparison
|
|
14
|
+
? await query('sampleTotal', { period: period.comparison })
|
|
15
|
+
: null;
|
|
16
|
+
return {
|
|
17
|
+
current: parseCount(current.rows[0]!.sample_count),
|
|
18
|
+
previous: previous && parseCount(previous.rows[0]!.sample_count),
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
samplesOverTime: dataApp.defineOperation({
|
|
23
|
+
filters: operationFilters.samplesOverTime,
|
|
24
|
+
policy,
|
|
25
|
+
async run({ query }, { period, grain }) {
|
|
26
|
+
// With the comparison on, the trend starts at the previous period.
|
|
27
|
+
const range = {
|
|
28
|
+
from: period.comparison?.from ?? period.range.from,
|
|
29
|
+
to: period.range.to,
|
|
30
|
+
};
|
|
31
|
+
const result = await query('samplesOverTime', { period: range, grain });
|
|
32
|
+
return result.rows.map(row => ({
|
|
33
|
+
periodStart: row.period_start,
|
|
34
|
+
sampleCount: parseCount(row.sample_count),
|
|
35
|
+
}));
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
samplesByMember: dataApp.defineOperation({
|
|
39
|
+
filters: operationFilters.samplesByMember,
|
|
40
|
+
policy,
|
|
41
|
+
async run({ query }, { period, breakdown }) {
|
|
42
|
+
const result = await query('samplesByMember', {
|
|
43
|
+
period: period.range,
|
|
10
44
|
breakdown,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return { period: period.parseInput(selection), grain, breakdown };
|
|
45
|
+
});
|
|
46
|
+
return result.rows.map(row => ({
|
|
47
|
+
member: row.member,
|
|
48
|
+
sampleCount: parseCount(row.sample_count),
|
|
49
|
+
}));
|
|
17
50
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
breakdown: 'segment',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
period: period.input(period.defaultValue),
|
|
29
|
-
grain: 'week',
|
|
30
|
-
breakdown: 'group',
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
policy: { maxQueryRows: 500, maxDurationMs: 15000 },
|
|
34
|
-
async run({ query }, { period: { range, comparison }, grain, breakdown }) {
|
|
35
|
-
const result = await query('samples', {
|
|
36
|
-
start: (comparison?.from ?? range.from).toISOString(),
|
|
37
|
-
end: range.to.toISOString(),
|
|
38
|
-
selected_start: range.from.toISOString(),
|
|
51
|
+
}),
|
|
52
|
+
sampleRows: dataApp.defineOperation({
|
|
53
|
+
filters: operationFilters.sampleRows,
|
|
54
|
+
policy,
|
|
55
|
+
async run({ query }, { period, grain, breakdown }) {
|
|
56
|
+
const result = await query('sampleRows', {
|
|
57
|
+
period: period.range,
|
|
39
58
|
grain,
|
|
40
59
|
breakdown,
|
|
41
60
|
});
|
|
@@ -43,7 +62,6 @@ export const operations = {
|
|
|
43
62
|
periodStart: row.period_start,
|
|
44
63
|
member: row.member,
|
|
45
64
|
sampleCount: parseCount(row.sample_count),
|
|
46
|
-
selected: row.selected,
|
|
47
65
|
}));
|
|
48
66
|
},
|
|
49
67
|
}),
|
|
@@ -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.
|
|
5
|
+
[version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.77.0/docs/app-authoring.md). <!-- x-release-please-version -->
|
|
6
6
|
|
|
7
|
-
| Task | App-owned files
|
|
8
|
-
| ------------------------------------------ |
|
|
9
|
-
| Define queries and
|
|
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
|
|
|
@@ -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.
|
|
4
|
+
Otherwise, read the [version-matched authoring recipe](https://github.com/altertable-ai/data-app/blob/v0.77.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.
|
|
8
|
+
[local preview guide](https://github.com/altertable-ai/data-app/blob/v0.77.0/docs/local-data-apps.md#preview-the-use-case-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
|
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"lint:fix": "oxlint --type-aware --fix src"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@altertable/data-app": "0.
|
|
21
|
-
"@altertable/data-app-bun": "0.
|
|
22
|
-
"@altertable/data-app-react": "0.
|
|
20
|
+
"@altertable/data-app": "0.77.0",
|
|
21
|
+
"@altertable/data-app-bun": "0.77.0",
|
|
22
|
+
"@altertable/data-app-react": "0.77.0",
|
|
23
23
|
"react": "19.3.1",
|
|
24
24
|
"react-dom": "19.3.1"
|
|
25
25
|
},
|