@altertable/data-app-examples 0.75.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/README.md +8 -8
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/package.json +13 -1
- package/templates/starter-data-app/index.tsx +60 -57
- package/templates/starter-finding-data-app/index.tsx +279 -116
- 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 +53 -8
- package/templates/starter-local-finding-data-app/package.json +3 -3
- package/templates/starter-local-finding-data-app/src/App.tsx +125 -97
- package/templates/starter-local-finding-data-app/src/data-context.ts +10 -4
- package/templates/starter-local-finding-data-app/src/filters.ts +48 -0
- package/templates/starter-local-finding-data-app/src/operations.ts +58 -7
- 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
package/README.md
CHANGED
|
@@ -17,14 +17,14 @@ on this package.
|
|
|
17
17
|
|
|
18
18
|
## Starters
|
|
19
19
|
|
|
20
|
-
| ID | Use
|
|
21
|
-
| -------------------------------- |
|
|
22
|
-
| `starter-data-app` | [Hosted single-file app](templates/starter-data-app/index.tsx)
|
|
23
|
-
| `starter-local-data-app` | [Local Bun and React project](templates/starter-local-data-app/README.md)
|
|
24
|
-
| `starter-metric-data-app` | [Hosted metric app](templates/starter-metric-data-app/index.tsx)
|
|
25
|
-
| `starter-finding-data-app` | [Hosted
|
|
26
|
-
| `starter-local-metric-data-app` | [Local metric app](templates/starter-local-metric-data-app/README.md)
|
|
27
|
-
| `starter-local-finding-data-app` | [Local
|
|
20
|
+
| ID | Use |
|
|
21
|
+
| -------------------------------- | ------------------------------------------------------------------------------- |
|
|
22
|
+
| `starter-data-app` | [Hosted single-file app](templates/starter-data-app/index.tsx) |
|
|
23
|
+
| `starter-local-data-app` | [Local Bun and React project](templates/starter-local-data-app/README.md) |
|
|
24
|
+
| `starter-metric-data-app` | [Hosted metric app](templates/starter-metric-data-app/index.tsx) |
|
|
25
|
+
| `starter-finding-data-app` | [Hosted Finding exploration](templates/starter-finding-data-app/index.tsx) |
|
|
26
|
+
| `starter-local-metric-data-app` | [Local metric app](templates/starter-local-metric-data-app/README.md) |
|
|
27
|
+
| `starter-local-finding-data-app` | [Local Finding exploration](templates/starter-local-finding-data-app/README.md) |
|
|
28
28
|
|
|
29
29
|
Pin to the same exact version as `@altertable/data-app`. Authoring guides and
|
|
30
30
|
API reference ship in that base package.
|
package/dist/index.js
CHANGED
|
@@ -25,8 +25,8 @@ const dataAppExamples = [
|
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
id: "starter-finding-data-app",
|
|
28
|
-
title: "Hosted Finding
|
|
29
|
-
description: "
|
|
28
|
+
title: "Hosted Finding exploration",
|
|
29
|
+
description: "An interactive companion to a Finding’s text for hosted execution.",
|
|
30
30
|
mode: "hosted"
|
|
31
31
|
},
|
|
32
32
|
{
|
|
@@ -37,8 +37,8 @@ const dataAppExamples = [
|
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
39
|
id: "starter-local-finding-data-app",
|
|
40
|
-
title: "Local Finding
|
|
41
|
-
description: "
|
|
40
|
+
title: "Local Finding exploration",
|
|
41
|
+
description: "An interactive companion to a Finding’s text for local execution.",
|
|
42
42
|
mode: "local"
|
|
43
43
|
}
|
|
44
44
|
];
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { cp, mkdir, readdir, rename, rm } from 'node:fs/promises';\nimport { join, relative, sep } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst templateFileRenames = new Map([['_gitignore', '.gitignore']]);\n\n/** Canonical starters available to scaffolding tools. IDs are stable across releases. */\nexport const dataAppExamples = [\n {\n id: 'starter-data-app',\n title: 'Hosted data app',\n description: 'A single-file React app for hosted execution.',\n mode: 'hosted',\n },\n {\n id: 'starter-local-data-app',\n title: 'Local data app',\n description: 'A Bun and React project with server-side lakehouse access.',\n mode: 'local',\n },\n {\n id: 'starter-metric-data-app',\n title: 'Hosted metric illustration',\n description: 'A focused metric app for hosted execution.',\n mode: 'hosted',\n },\n {\n id: 'starter-finding-data-app',\n title: 'Hosted Finding
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { cp, mkdir, readdir, rename, rm } from 'node:fs/promises';\nimport { join, relative, sep } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst templateFileRenames = new Map([['_gitignore', '.gitignore']]);\n\n/** Canonical starters available to scaffolding tools. IDs are stable across releases. */\nexport const dataAppExamples = [\n {\n id: 'starter-data-app',\n title: 'Hosted data app',\n description: 'A single-file React app for hosted execution.',\n mode: 'hosted',\n },\n {\n id: 'starter-local-data-app',\n title: 'Local data app',\n description: 'A Bun and React project with server-side lakehouse access.',\n mode: 'local',\n },\n {\n id: 'starter-metric-data-app',\n title: 'Hosted metric illustration',\n description: 'A focused metric app for hosted execution.',\n mode: 'hosted',\n },\n {\n id: 'starter-finding-data-app',\n title: 'Hosted Finding exploration',\n description:\n 'An interactive companion to a Finding’s text for hosted execution.',\n mode: 'hosted',\n },\n {\n id: 'starter-local-metric-data-app',\n title: 'Local metric illustration',\n description: 'A focused metric app for local execution.',\n mode: 'local',\n },\n {\n id: 'starter-local-finding-data-app',\n title: 'Local Finding exploration',\n description:\n 'An interactive companion to a Finding’s text for local execution.',\n mode: 'local',\n },\n] as const;\n\n/** Stable identifier for a canonical starter. */\nexport type DataAppExampleId = (typeof dataAppExamples)[number]['id'];\n\n/** Absolute source directory. Use copyExample() to restore npm-excluded filenames. */\nexport function getExampleDirectory(id: DataAppExampleId): string {\n const example = dataAppExamples.find(example => example.id === id);\n if (!example) throw new Error(`Unknown data app example: ${id}`);\n return fileURLToPath(new URL(`../templates/${example.id}/`, import.meta.url));\n}\n\n/** Copy a starter into a new directory; reject existing destinations. */\nexport async function copyExample(\n id: DataAppExampleId,\n destination: string\n): Promise<void> {\n const source = getExampleDirectory(id);\n await mkdir(destination);\n try {\n await cp(source, destination, {\n recursive: true,\n filter: path =>\n relative(source, path)\n .split(sep)\n .every(\n part =>\n part !== 'node_modules' &&\n part !== 'dist' &&\n !part.startsWith('.env')\n ),\n });\n for (const filename of await readdir(destination)) {\n const target = templateFileRenames.get(filename);\n if (target)\n await rename(join(destination, filename), join(destination, target));\n }\n } catch (error) {\n await rm(destination, { recursive: true, force: true });\n throw error;\n }\n}\n"],"mappings":";;;;AAIA,MAAM,sCAAsB,IAAI,IAAI,CAAC,CAAC,cAAc,YAAY,CAAC,CAAC;;AAGlE,MAAa,kBAAkB;CAC7B;EACE,IAAI;EACJ,OAAO;EACP,aAAa;EACb,MAAM;CACR;CACA;EACE,IAAI;EACJ,OAAO;EACP,aAAa;EACb,MAAM;CACR;CACA;EACE,IAAI;EACJ,OAAO;EACP,aAAa;EACb,MAAM;CACR;CACA;EACE,IAAI;EACJ,OAAO;EACP,aACE;EACF,MAAM;CACR;CACA;EACE,IAAI;EACJ,OAAO;EACP,aAAa;EACb,MAAM;CACR;CACA;EACE,IAAI;EACJ,OAAO;EACP,aACE;EACF,MAAM;CACR;AACF;;AAMA,SAAgB,oBAAoB,IAA8B;CAChE,MAAM,UAAU,gBAAgB,MAAK,YAAW,QAAQ,OAAO,EAAE;CACjE,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,6BAA6B,IAAI;CAC/D,OAAO,cAAc,IAAI,IAAI,gBAAgB,QAAQ,GAAG,IAAI,YAAY,GAAG,CAAC;AAC9E;;AAGA,eAAsB,YACpB,IACA,aACe;CACf,MAAM,SAAS,oBAAoB,EAAE;CACrC,MAAM,MAAM,WAAW;CACvB,IAAI;EACF,MAAM,GAAG,QAAQ,aAAa;GAC5B,WAAW;GACX,SAAQ,SACN,SAAS,QAAQ,IAAI,CAAC,CACnB,MAAM,GAAG,CAAC,CACV,OACC,SACE,SAAS,kBACT,SAAS,UACT,CAAC,KAAK,WAAW,MAAM,CAC3B;EACN,CAAC;EACD,KAAK,MAAM,YAAY,MAAM,QAAQ,WAAW,GAAG;GACjD,MAAM,SAAS,oBAAoB,IAAI,QAAQ;GAC/C,IAAI,QACF,MAAM,OAAO,KAAK,aAAa,QAAQ,GAAG,KAAK,aAAa,MAAM,CAAC;EACvE;CACF,SAAS,OAAO;EACd,MAAM,GAAG,aAAa;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;EACtD,MAAM;CACR;AACF"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ export declare const dataAppExamples: readonly [{
|
|
|
17
17
|
readonly mode: 'hosted';
|
|
18
18
|
}, {
|
|
19
19
|
readonly id: 'starter-finding-data-app';
|
|
20
|
-
readonly title: 'Hosted Finding
|
|
21
|
-
readonly description: '
|
|
20
|
+
readonly title: 'Hosted Finding exploration';
|
|
21
|
+
readonly description: 'An interactive companion to a Finding’s text for hosted execution.';
|
|
22
22
|
readonly mode: 'hosted';
|
|
23
23
|
}, {
|
|
24
24
|
readonly id: 'starter-local-metric-data-app';
|
|
@@ -27,8 +27,8 @@ export declare const dataAppExamples: readonly [{
|
|
|
27
27
|
readonly mode: 'local';
|
|
28
28
|
}, {
|
|
29
29
|
readonly id: 'starter-local-finding-data-app';
|
|
30
|
-
readonly title: 'Local Finding
|
|
31
|
-
readonly description: '
|
|
30
|
+
readonly title: 'Local Finding exploration';
|
|
31
|
+
readonly description: 'An interactive companion to a Finding’s text for local execution.';
|
|
32
32
|
readonly mode: 'local';
|
|
33
33
|
}];
|
|
34
34
|
/** Stable identifier for a canonical starter. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altertable/data-app-examples",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.77.0",
|
|
4
4
|
"description": "Canonical starter templates for Altertable data apps.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"altertable",
|
|
7
|
+
"data-app",
|
|
8
|
+
"data-apps",
|
|
9
|
+
"templates",
|
|
10
|
+
"starter",
|
|
11
|
+
"boilerplate",
|
|
12
|
+
"dashboard",
|
|
13
|
+
"analytics",
|
|
14
|
+
"react",
|
|
15
|
+
"typescript"
|
|
16
|
+
],
|
|
5
17
|
"license": "MIT",
|
|
6
18
|
"author": "Altertable",
|
|
7
19
|
"repository": {
|
|
@@ -6,16 +6,14 @@ import {
|
|
|
6
6
|
DataSection,
|
|
7
7
|
DataValue,
|
|
8
8
|
TableWidget,
|
|
9
|
-
Grid,
|
|
10
9
|
Stack,
|
|
11
10
|
TextContent,
|
|
12
11
|
injectDataAppStyles,
|
|
13
12
|
mountDataApp,
|
|
14
13
|
MetricWidget,
|
|
15
|
-
searchVariable,
|
|
16
14
|
} from '@altertable/data-app-react';
|
|
17
15
|
import { createDataClient } from '@altertable/data-app/client';
|
|
18
|
-
import { parseCount } from '@altertable/data-app/contract';
|
|
16
|
+
import { parseCount, searchFilter } from '@altertable/data-app/contract';
|
|
19
17
|
import { formatMetric } from '@altertable/data-app/format';
|
|
20
18
|
|
|
21
19
|
const dataApp = defineDataApp({
|
|
@@ -39,27 +37,22 @@ ORDER BY group_name LIMIT $limit`,
|
|
|
39
37
|
limit: { type: 'number', defaultValue: 10 },
|
|
40
38
|
},
|
|
41
39
|
},
|
|
40
|
+
sampleTotal: {
|
|
41
|
+
projections: { sample_count: { type: 'number' } },
|
|
42
|
+
statement: `
|
|
43
|
+
WITH sample_counts(group_name, sample_count) AS (VALUES ('Alpha', 2200000), ('Beta', 0))
|
|
44
|
+
SELECT CAST(COALESCE(SUM(sample_count), 0) AS BIGINT) AS sample_count FROM sample_counts
|
|
45
|
+
WHERE $groupName = '' OR group_name = $groupName`,
|
|
46
|
+
params: { groupName: { type: 'string', defaultValue: '' } },
|
|
47
|
+
},
|
|
42
48
|
},
|
|
43
49
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
typeof value !== 'object' ||
|
|
48
|
-
!('groupName' in value) ||
|
|
49
|
-
typeof value.groupName !== 'string' ||
|
|
50
|
-
value.groupName.length > 40
|
|
51
|
-
)
|
|
52
|
-
throw new Error('Expected a group name of at most 40 characters.');
|
|
53
|
-
return { groupName: value.groupName };
|
|
54
|
-
}
|
|
50
|
+
// Declare each filter once; operations list the filters they read, and views,
|
|
51
|
+
// controls, and scope derive from them.
|
|
52
|
+
const groupName = searchFilter({ key: 'group', label: 'Group' });
|
|
55
53
|
const operations = {
|
|
56
54
|
sampleCountsByGroup: dataApp.defineOperation({
|
|
57
|
-
|
|
58
|
-
checks: [
|
|
59
|
-
{ groupName: '' },
|
|
60
|
-
{ groupName: 'Alpha' },
|
|
61
|
-
{ groupName: 'missing' },
|
|
62
|
-
],
|
|
55
|
+
filters: { groupName },
|
|
63
56
|
policy: { maxQueryRows: 10, maxDurationMs: 15000 },
|
|
64
57
|
async run({ query }, { groupName }) {
|
|
65
58
|
const queryResult = await query('sampleCountsByGroup', { groupName });
|
|
@@ -69,8 +62,19 @@ const operations = {
|
|
|
69
62
|
}));
|
|
70
63
|
},
|
|
71
64
|
}),
|
|
65
|
+
sampleTotal: dataApp.defineOperation({
|
|
66
|
+
filters: { groupName },
|
|
67
|
+
policy: { maxQueryRows: 1, maxDurationMs: 15000 },
|
|
68
|
+
async run({ query }, { groupName }) {
|
|
69
|
+
const queryResult = await query('sampleTotal', { groupName });
|
|
70
|
+
return { sampleCount: parseCount(queryResult.rows[0]?.sample_count) };
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
const queryNames = {
|
|
75
|
+
...operations.sampleCountsByGroup.queryNames,
|
|
76
|
+
...operations.sampleTotal.queryNames,
|
|
72
77
|
};
|
|
73
|
-
const queryNames = operations.sampleCountsByGroup.queryNames;
|
|
74
78
|
const sampleDataContext = createDataContext(queryNames)({
|
|
75
79
|
description:
|
|
76
80
|
'Two SQL VALUES rows demonstrate the host query path. Replace them with inspected source data before publishing findings.',
|
|
@@ -79,23 +83,14 @@ const sampleDataContext = createDataContext(queryNames)({
|
|
|
79
83
|
term: 'Sample count',
|
|
80
84
|
definition:
|
|
81
85
|
'A fixture value: Alpha is 2,200,000 and Beta is a measured zero.',
|
|
82
|
-
queryNames: [queryNames.sampleCountsByGroup],
|
|
86
|
+
queryNames: [queryNames.sampleCountsByGroup, queryNames.sampleTotal],
|
|
83
87
|
},
|
|
84
88
|
},
|
|
85
89
|
});
|
|
86
|
-
const {
|
|
87
|
-
const sampleCountsView =
|
|
90
|
+
const { defineView } = createDataHooks(createDataClient({ operations }));
|
|
91
|
+
const sampleCountsView = defineView({
|
|
88
92
|
dataContext: sampleDataContext,
|
|
89
93
|
operation: 'sampleCountsByGroup',
|
|
90
|
-
variables: {
|
|
91
|
-
groupName: searchVariable({
|
|
92
|
-
key: 'group',
|
|
93
|
-
label: 'Group',
|
|
94
|
-
defaultValue: '',
|
|
95
|
-
}),
|
|
96
|
-
},
|
|
97
|
-
describeInput: ({ groupName }) =>
|
|
98
|
-
groupName ? `group ${groupName}` : 'all groups',
|
|
99
94
|
isEmpty: sampleCounts => sampleCounts.length === 0,
|
|
100
95
|
emptyFallback: {
|
|
101
96
|
title: 'No matching groups',
|
|
@@ -115,52 +110,59 @@ const sampleCounts = sampleCountsView.dataset({
|
|
|
115
110
|
glossaryIds: ['sampleCount'],
|
|
116
111
|
},
|
|
117
112
|
});
|
|
118
|
-
const
|
|
113
|
+
const sampleTotalView = defineView({
|
|
114
|
+
dataContext: sampleDataContext,
|
|
115
|
+
operation: 'sampleTotal',
|
|
116
|
+
});
|
|
117
|
+
const totalSamples = sampleTotalView.metric(
|
|
119
118
|
{
|
|
120
119
|
id: 'total-samples',
|
|
121
120
|
glossaryId: 'sampleCount',
|
|
122
121
|
label: 'Total samples',
|
|
123
122
|
format: { kind: 'count', compact: true },
|
|
124
123
|
},
|
|
125
|
-
|
|
124
|
+
total => ({ current: total.sampleCount })
|
|
126
125
|
);
|
|
127
|
-
const
|
|
128
|
-
<Stack
|
|
126
|
+
const totalContent = sampleTotalView.content(result => (
|
|
127
|
+
<Stack>
|
|
129
128
|
<TextContent>
|
|
130
129
|
<p>
|
|
131
130
|
Showing <DataValue scope={result.scope} />
|
|
132
131
|
</p>
|
|
133
132
|
</TextContent>
|
|
134
|
-
<
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/>
|
|
140
|
-
<TableWidget
|
|
141
|
-
dataset={sampleCounts}
|
|
142
|
-
source={result}
|
|
143
|
-
title="Counts by group"
|
|
144
|
-
description="Alpha and Beta demonstrate measured values, including zero."
|
|
145
|
-
pagination={false}
|
|
146
|
-
/>
|
|
147
|
-
</Grid>
|
|
133
|
+
<MetricWidget
|
|
134
|
+
metric={totalSamples}
|
|
135
|
+
source={result}
|
|
136
|
+
description="Sum of the fixture counts in the selected groups."
|
|
137
|
+
/>
|
|
148
138
|
</Stack>
|
|
149
139
|
));
|
|
140
|
+
const countsContent = sampleCountsView.content(result => (
|
|
141
|
+
<TableWidget
|
|
142
|
+
dataset={sampleCounts}
|
|
143
|
+
source={result}
|
|
144
|
+
title="Counts by group"
|
|
145
|
+
description="Alpha and Beta demonstrate measured values, including zero."
|
|
146
|
+
pagination={false}
|
|
147
|
+
/>
|
|
148
|
+
));
|
|
150
149
|
function App() {
|
|
151
150
|
return (
|
|
152
151
|
<DataApp
|
|
153
152
|
view={sampleCountsView}
|
|
153
|
+
summaryViews={[sampleTotalView]}
|
|
154
154
|
datasets={[sampleCounts]}
|
|
155
|
-
story={
|
|
156
|
-
const total = totalSamples.read(
|
|
157
|
-
const scope = sampleCountsView.scope(
|
|
155
|
+
story={(countsSnapshot, totalSnapshot) => {
|
|
156
|
+
const total = totalSamples.read(totalSnapshot);
|
|
157
|
+
const scope = sampleCountsView.scope(countsSnapshot);
|
|
158
158
|
return [
|
|
159
159
|
{
|
|
160
160
|
id: 'total-samples',
|
|
161
161
|
headline: `Total samples: ${formatMetric(total.value.current, totalSamples.definition.format)}`,
|
|
162
162
|
context: `Demonstration values for ${scope}.`,
|
|
163
|
-
visual:
|
|
163
|
+
visual: (
|
|
164
|
+
<MetricWidget metric={totalSamples} source={totalSnapshot} />
|
|
165
|
+
),
|
|
164
166
|
visualKind: 'metric',
|
|
165
167
|
evidence: totalSamples,
|
|
166
168
|
},
|
|
@@ -171,7 +173,7 @@ function App() {
|
|
|
171
173
|
visual: (
|
|
172
174
|
<TableWidget
|
|
173
175
|
dataset={sampleCounts}
|
|
174
|
-
source={
|
|
176
|
+
source={countsSnapshot}
|
|
175
177
|
pagination={false}
|
|
176
178
|
/>
|
|
177
179
|
),
|
|
@@ -184,7 +186,8 @@ function App() {
|
|
|
184
186
|
<TextContent>
|
|
185
187
|
<h2>Sample counts</h2>
|
|
186
188
|
</TextContent>
|
|
187
|
-
<DataSection content={
|
|
189
|
+
<DataSection content={totalContent} label="Sample total" />
|
|
190
|
+
<DataSection content={countsContent} label="Group counts" />
|
|
188
191
|
</Stack>
|
|
189
192
|
</DataApp>
|
|
190
193
|
);
|