@altertable/data-app-examples 0.74.0 → 0.76.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 -4
- package/dist/index.js +38 -11
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +20 -0
- package/package.json +13 -1
- package/templates/starter-finding-data-app/LICENSE +21 -0
- package/templates/starter-finding-data-app/index.tsx +282 -0
- package/templates/starter-local-data-app/AGENTS.md +9 -9
- package/templates/starter-local-data-app/README.md +4 -4
- package/templates/starter-local-data-app/package.json +3 -3
- package/templates/starter-local-finding-data-app/.bun-version +1 -0
- package/templates/starter-local-finding-data-app/.node-version +1 -0
- package/templates/starter-local-finding-data-app/.oxfmtrc.json +11 -0
- package/templates/starter-local-finding-data-app/.oxlintrc.json +33 -0
- package/templates/starter-local-finding-data-app/AGENTS.md +18 -0
- package/templates/starter-local-finding-data-app/LICENSE +21 -0
- package/templates/starter-local-finding-data-app/README.md +43 -0
- package/templates/starter-local-finding-data-app/_gitignore +3 -0
- package/templates/starter-local-finding-data-app/app.ts +59 -0
- package/templates/starter-local-finding-data-app/bunfig.toml +2 -0
- package/templates/starter-local-finding-data-app/package.json +36 -0
- package/templates/starter-local-finding-data-app/src/App.tsx +165 -0
- package/templates/starter-local-finding-data-app/src/assets.d.ts +1 -0
- package/templates/starter-local-finding-data-app/src/data-context.ts +13 -0
- package/templates/starter-local-finding-data-app/src/favicon.svg +13 -0
- package/templates/starter-local-finding-data-app/src/index.html +14 -0
- package/templates/starter-local-finding-data-app/src/main.tsx +8 -0
- package/templates/starter-local-finding-data-app/src/operations.ts +50 -0
- package/templates/starter-local-finding-data-app/src/server.ts +7 -0
- package/templates/starter-local-finding-data-app/tsconfig.json +21 -0
- package/templates/starter-local-metric-data-app/.bun-version +1 -0
- package/templates/starter-local-metric-data-app/.node-version +1 -0
- package/templates/starter-local-metric-data-app/.oxfmtrc.json +11 -0
- package/templates/starter-local-metric-data-app/.oxlintrc.json +33 -0
- package/templates/starter-local-metric-data-app/AGENTS.md +18 -0
- package/templates/starter-local-metric-data-app/LICENSE +21 -0
- package/templates/starter-local-metric-data-app/README.md +43 -0
- package/templates/starter-local-metric-data-app/_gitignore +3 -0
- package/templates/starter-local-metric-data-app/app.ts +39 -0
- package/templates/starter-local-metric-data-app/bunfig.toml +2 -0
- package/templates/starter-local-metric-data-app/package.json +36 -0
- package/templates/starter-local-metric-data-app/src/App.tsx +124 -0
- package/templates/starter-local-metric-data-app/src/assets.d.ts +1 -0
- package/templates/starter-local-metric-data-app/src/data-context.ts +19 -0
- package/templates/starter-local-metric-data-app/src/favicon.svg +13 -0
- package/templates/starter-local-metric-data-app/src/index.html +14 -0
- package/templates/starter-local-metric-data-app/src/main.tsx +8 -0
- package/templates/starter-local-metric-data-app/src/operations.ts +50 -0
- package/templates/starter-local-metric-data-app/src/server.ts +7 -0
- package/templates/starter-local-metric-data-app/tsconfig.json +21 -0
- package/templates/starter-metric-data-app/LICENSE +21 -0
- package/templates/starter-metric-data-app/index.tsx +229 -0
package/README.md
CHANGED
|
@@ -17,10 +17,14 @@ on this package.
|
|
|
17
17
|
|
|
18
18
|
## Starters
|
|
19
19
|
|
|
20
|
-
| ID
|
|
21
|
-
|
|
|
22
|
-
| `starter-data-app`
|
|
23
|
-
| `starter-local-data-app`
|
|
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) |
|
|
24
28
|
|
|
25
29
|
Pin to the same exact version as `@altertable/data-app`. Authoring guides and
|
|
26
30
|
API reference ship in that base package.
|
package/dist/index.js
CHANGED
|
@@ -4,17 +4,44 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
//#region src/index.ts
|
|
5
5
|
const templateFileRenames = /* @__PURE__ */ new Map([["_gitignore", ".gitignore"]]);
|
|
6
6
|
/** Canonical starters available to scaffolding tools. IDs are stable across releases. */
|
|
7
|
-
const dataAppExamples = [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
const dataAppExamples = [
|
|
8
|
+
{
|
|
9
|
+
id: "starter-data-app",
|
|
10
|
+
title: "Hosted data app",
|
|
11
|
+
description: "A single-file React app for hosted execution.",
|
|
12
|
+
mode: "hosted"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "starter-local-data-app",
|
|
16
|
+
title: "Local data app",
|
|
17
|
+
description: "A Bun and React project with server-side lakehouse access.",
|
|
18
|
+
mode: "local"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "starter-metric-data-app",
|
|
22
|
+
title: "Hosted metric illustration",
|
|
23
|
+
description: "A focused metric app for hosted execution.",
|
|
24
|
+
mode: "hosted"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "starter-finding-data-app",
|
|
28
|
+
title: "Hosted Finding exploration",
|
|
29
|
+
description: "An interactive companion to a Finding’s text for hosted execution.",
|
|
30
|
+
mode: "hosted"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "starter-local-metric-data-app",
|
|
34
|
+
title: "Local metric illustration",
|
|
35
|
+
description: "A focused metric app for local execution.",
|
|
36
|
+
mode: "local"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "starter-local-finding-data-app",
|
|
40
|
+
title: "Local Finding exploration",
|
|
41
|
+
description: "An interactive companion to a Finding’s text for local execution.",
|
|
42
|
+
mode: "local"
|
|
43
|
+
}
|
|
44
|
+
];
|
|
18
45
|
/** Absolute source directory. Use copyExample() to restore npm-excluded filenames. */
|
|
19
46
|
function getExampleDirectory(id) {
|
|
20
47
|
const example = dataAppExamples.find((example) => example.id === id);
|
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] 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
|
|
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
|
@@ -10,6 +10,26 @@ export declare const dataAppExamples: readonly [{
|
|
|
10
10
|
readonly title: 'Local data app';
|
|
11
11
|
readonly description: 'A Bun and React project with server-side lakehouse access.';
|
|
12
12
|
readonly mode: 'local';
|
|
13
|
+
}, {
|
|
14
|
+
readonly id: 'starter-metric-data-app';
|
|
15
|
+
readonly title: 'Hosted metric illustration';
|
|
16
|
+
readonly description: 'A focused metric app for hosted execution.';
|
|
17
|
+
readonly mode: 'hosted';
|
|
18
|
+
}, {
|
|
19
|
+
readonly id: 'starter-finding-data-app';
|
|
20
|
+
readonly title: 'Hosted Finding exploration';
|
|
21
|
+
readonly description: 'An interactive companion to a Finding’s text for hosted execution.';
|
|
22
|
+
readonly mode: 'hosted';
|
|
23
|
+
}, {
|
|
24
|
+
readonly id: 'starter-local-metric-data-app';
|
|
25
|
+
readonly title: 'Local metric illustration';
|
|
26
|
+
readonly description: 'A focused metric app for local execution.';
|
|
27
|
+
readonly mode: 'local';
|
|
28
|
+
}, {
|
|
29
|
+
readonly id: 'starter-local-finding-data-app';
|
|
30
|
+
readonly title: 'Local Finding exploration';
|
|
31
|
+
readonly description: 'An interactive companion to a Finding’s text for local execution.';
|
|
32
|
+
readonly mode: 'local';
|
|
13
33
|
}];
|
|
14
34
|
/** Stable identifier for a canonical starter. */
|
|
15
35
|
export type DataAppExampleId = (typeof dataAppExamples)[number]['id'];
|
package/package.json
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altertable/data-app-examples",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.76.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": {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Altertable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { defineDataApp } from '@altertable/data-app';
|
|
2
|
+
import {
|
|
3
|
+
createDataContext,
|
|
4
|
+
injectDataAppStyles,
|
|
5
|
+
mountDataApp,
|
|
6
|
+
} from '@altertable/data-app-react';
|
|
7
|
+
import {
|
|
8
|
+
choiceVariable,
|
|
9
|
+
createDataHooks,
|
|
10
|
+
DataApp,
|
|
11
|
+
DataSection,
|
|
12
|
+
MetricWidget,
|
|
13
|
+
Stack,
|
|
14
|
+
TableWidget,
|
|
15
|
+
VisualizationWidget,
|
|
16
|
+
} from '@altertable/data-app-react';
|
|
17
|
+
import { BarChart, ComposedChart } from '@altertable/data-app-react/ui';
|
|
18
|
+
import { createDataClient } from '@altertable/data-app/client';
|
|
19
|
+
import {
|
|
20
|
+
dateTimeRangeVariable,
|
|
21
|
+
defineDateRangeContract,
|
|
22
|
+
parseCount,
|
|
23
|
+
} from '@altertable/data-app/contract';
|
|
24
|
+
const dataApp = defineDataApp({
|
|
25
|
+
title: 'Sample finding',
|
|
26
|
+
description:
|
|
27
|
+
'Fixture evidence; replace with the Finding and its supporting queries.',
|
|
28
|
+
scope: { organization: 'demo', environment: 'sample' },
|
|
29
|
+
appearance: { theme: 'system' },
|
|
30
|
+
queries: {
|
|
31
|
+
samples: {
|
|
32
|
+
projections: {
|
|
33
|
+
period_start: { type: 'string' },
|
|
34
|
+
member: { type: 'string' },
|
|
35
|
+
selected: { type: 'boolean' },
|
|
36
|
+
sample_count: { type: 'number' },
|
|
37
|
+
},
|
|
38
|
+
statement: `
|
|
39
|
+
SELECT strftime(date_trunc($grain, sample_date), '%Y-%m-%d') AS period_start,
|
|
40
|
+
CASE WHEN $breakdown = 'group' THEN group_name ELSE segment_name END AS member,
|
|
41
|
+
sample_date >= CAST($selected_start AS TIMESTAMP) AS selected,
|
|
42
|
+
SUM(sample_count) AS sample_count
|
|
43
|
+
FROM starter_demo.daily_samples
|
|
44
|
+
WHERE sample_date >= CAST($start AS TIMESTAMP) AND sample_date < CAST($end AS TIMESTAMP)
|
|
45
|
+
GROUP BY ALL ORDER BY period_start, member LIMIT $limit`,
|
|
46
|
+
params: {
|
|
47
|
+
start: { type: 'string', defaultValue: '2026-03-09T00:00:00Z' },
|
|
48
|
+
end: { type: 'string', defaultValue: '2026-03-16T00:00:00Z' },
|
|
49
|
+
selected_start: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
defaultValue: '2026-03-09T00:00:00Z',
|
|
52
|
+
},
|
|
53
|
+
grain: { type: 'string', defaultValue: 'day' },
|
|
54
|
+
breakdown: { type: 'string', defaultValue: 'segment' },
|
|
55
|
+
limit: { type: 'number', defaultValue: 500 },
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
const calendar = defineDateRangeContract({
|
|
61
|
+
minDate: '2026-01-05',
|
|
62
|
+
maxDate: '2026-03-29',
|
|
63
|
+
maxRangeDays: 28,
|
|
64
|
+
timeZone: 'UTC',
|
|
65
|
+
});
|
|
66
|
+
const findingPeriod = {
|
|
67
|
+
from: new Date('2026-03-09T00:00:00Z'),
|
|
68
|
+
to: new Date('2026-03-16T00:00:00Z'),
|
|
69
|
+
};
|
|
70
|
+
const period = dateTimeRangeVariable({
|
|
71
|
+
key: 'period',
|
|
72
|
+
contract: calendar,
|
|
73
|
+
allowComparison: true,
|
|
74
|
+
defaultValue: findingPeriod,
|
|
75
|
+
presets: [{ label: 'Finding period', range: findingPeriod }],
|
|
76
|
+
});
|
|
77
|
+
const operations = {
|
|
78
|
+
samples: dataApp.defineOperation({
|
|
79
|
+
input: value => {
|
|
80
|
+
const {
|
|
81
|
+
period: selection,
|
|
82
|
+
grain,
|
|
83
|
+
breakdown,
|
|
84
|
+
} = (value ?? {}) as Record<string, unknown>;
|
|
85
|
+
if (grain !== 'day' && grain !== 'week')
|
|
86
|
+
throw new Error('Expected a day or week grain.');
|
|
87
|
+
if (breakdown !== 'segment' && breakdown !== 'group')
|
|
88
|
+
throw new Error('Expected a segment or group breakdown.');
|
|
89
|
+
return { period: period.parseInput(selection), grain, breakdown };
|
|
90
|
+
},
|
|
91
|
+
checks: [
|
|
92
|
+
{
|
|
93
|
+
period: period.input({ range: findingPeriod, comparison: 'previous' }),
|
|
94
|
+
grain: 'day',
|
|
95
|
+
breakdown: 'segment',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
period: period.input(period.defaultValue),
|
|
99
|
+
grain: 'week',
|
|
100
|
+
breakdown: 'group',
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
policy: { maxQueryRows: 500, maxDurationMs: 15000 },
|
|
104
|
+
async run({ query }, { period: { range, comparison }, grain, breakdown }) {
|
|
105
|
+
const result = await query('samples', {
|
|
106
|
+
start: (comparison?.from ?? range.from).toISOString(),
|
|
107
|
+
end: range.to.toISOString(),
|
|
108
|
+
selected_start: range.from.toISOString(),
|
|
109
|
+
grain,
|
|
110
|
+
breakdown,
|
|
111
|
+
});
|
|
112
|
+
return result.rows.map(row => ({
|
|
113
|
+
periodStart: row.period_start,
|
|
114
|
+
member: row.member,
|
|
115
|
+
sampleCount: parseCount(row.sample_count),
|
|
116
|
+
selected: row.selected,
|
|
117
|
+
}));
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
};
|
|
121
|
+
const queryNames = operations.samples.queryNames;
|
|
122
|
+
const sampleDataContext = createDataContext(queryNames)({
|
|
123
|
+
description:
|
|
124
|
+
'Fictional daily samples from starter_demo.daily_samples. Replace this evidence with the actual Finding queries.',
|
|
125
|
+
glossary: {
|
|
126
|
+
sampleCount: {
|
|
127
|
+
term: 'Sample count',
|
|
128
|
+
definition: 'Fixture samples recorded per day, group, and segment.',
|
|
129
|
+
queryNames: [queryNames.samples],
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
const { defineTimeView } = createDataHooks(createDataClient({ operations }));
|
|
134
|
+
const samplesView = defineTimeView({
|
|
135
|
+
dataContext: sampleDataContext,
|
|
136
|
+
operation: 'samples',
|
|
137
|
+
time: period,
|
|
138
|
+
variables: {
|
|
139
|
+
grain: choiceVariable({
|
|
140
|
+
key: 'grain',
|
|
141
|
+
label: 'Grain',
|
|
142
|
+
defaultValue: 'day',
|
|
143
|
+
options: [
|
|
144
|
+
{ id: 'day', label: 'Day' },
|
|
145
|
+
{ id: 'week', label: 'Week' },
|
|
146
|
+
],
|
|
147
|
+
presentation: { group: 'display', control: 'widget' },
|
|
148
|
+
}),
|
|
149
|
+
breakdown: choiceVariable({
|
|
150
|
+
key: 'breakdown',
|
|
151
|
+
label: 'Breakdown',
|
|
152
|
+
defaultValue: 'segment',
|
|
153
|
+
options: [
|
|
154
|
+
{ id: 'segment', label: 'Segment' },
|
|
155
|
+
{ id: 'group', label: 'Group' },
|
|
156
|
+
],
|
|
157
|
+
presentation: { group: 'display', control: 'widget' },
|
|
158
|
+
}),
|
|
159
|
+
},
|
|
160
|
+
isEmpty: rows => rows.length === 0,
|
|
161
|
+
emptyFallback: {
|
|
162
|
+
title: 'No samples in this period',
|
|
163
|
+
description: 'No observations are available for this period.',
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
type SampleRow = { sampleCount: number; selected: boolean };
|
|
167
|
+
function total(rows: readonly SampleRow[]) {
|
|
168
|
+
return rows.reduce((sum, row) => sum + row.sampleCount, 0);
|
|
169
|
+
}
|
|
170
|
+
function totalsBy<Row extends SampleRow>(
|
|
171
|
+
rows: readonly Row[],
|
|
172
|
+
key: (row: Row) => string
|
|
173
|
+
) {
|
|
174
|
+
const totals = new Map<string, number>();
|
|
175
|
+
for (const row of rows)
|
|
176
|
+
totals.set(key(row), (totals.get(key(row)) ?? 0) + row.sampleCount);
|
|
177
|
+
return [...totals].map(([id, sampleCount]) => ({ id, sampleCount }));
|
|
178
|
+
}
|
|
179
|
+
const count = { kind: 'count' } as const;
|
|
180
|
+
const totalSamples = samplesView.metric(
|
|
181
|
+
{
|
|
182
|
+
id: 'total-samples',
|
|
183
|
+
label: 'Samples',
|
|
184
|
+
glossaryId: 'sampleCount',
|
|
185
|
+
format: count,
|
|
186
|
+
},
|
|
187
|
+
(rows, input) => ({
|
|
188
|
+
current: total(rows.filter(row => row.selected)),
|
|
189
|
+
...(input.period.comparison && {
|
|
190
|
+
previous: total(rows.filter(row => !row.selected)),
|
|
191
|
+
}),
|
|
192
|
+
})
|
|
193
|
+
);
|
|
194
|
+
const trend = samplesView.dataset({
|
|
195
|
+
name: 'Samples over time',
|
|
196
|
+
select: rows => totalsBy(rows, row => row.periodStart),
|
|
197
|
+
rowKey: row => row.id,
|
|
198
|
+
columns: {
|
|
199
|
+
id: { label: 'Period start', value: row => row.id },
|
|
200
|
+
sampleCount: { value: row => row.sampleCount, format: count },
|
|
201
|
+
},
|
|
202
|
+
evidence: { id: 'samples-over-time', glossaryIds: ['sampleCount'] },
|
|
203
|
+
});
|
|
204
|
+
const breakdown = samplesView.dataset({
|
|
205
|
+
name: 'Samples by member',
|
|
206
|
+
select: rows =>
|
|
207
|
+
totalsBy(
|
|
208
|
+
rows.filter(row => row.selected),
|
|
209
|
+
row => row.member
|
|
210
|
+
),
|
|
211
|
+
rowKey: row => row.id,
|
|
212
|
+
columns: {
|
|
213
|
+
id: { label: 'Member', value: row => row.id },
|
|
214
|
+
sampleCount: { value: row => row.sampleCount, format: count },
|
|
215
|
+
},
|
|
216
|
+
evidence: { id: 'samples-by-member', glossaryIds: ['sampleCount'] },
|
|
217
|
+
});
|
|
218
|
+
const sampleRows = samplesView.dataset({
|
|
219
|
+
name: 'Samples',
|
|
220
|
+
select: rows => rows.filter(row => row.selected),
|
|
221
|
+
rowKey: row => `${row.periodStart}:${row.member}`,
|
|
222
|
+
columns: {
|
|
223
|
+
periodStart: { label: 'Period start', value: row => row.periodStart },
|
|
224
|
+
member: { label: 'Member', value: row => row.member },
|
|
225
|
+
sampleCount: { value: row => row.sampleCount, format: count },
|
|
226
|
+
},
|
|
227
|
+
evidence: { id: 'samples', glossaryIds: ['sampleCount'] },
|
|
228
|
+
});
|
|
229
|
+
// The Finding's text is shown above the app; keep content to charts and captions.
|
|
230
|
+
const sampleContent = samplesView.content(result => (
|
|
231
|
+
<Stack>
|
|
232
|
+
<MetricWidget metric={totalSamples} source={result} />
|
|
233
|
+
<VisualizationWidget
|
|
234
|
+
dataset={trend}
|
|
235
|
+
source={result}
|
|
236
|
+
title="Samples over time"
|
|
237
|
+
description="Includes the previous period when comparison is on."
|
|
238
|
+
breakdown={samplesView.breakdown('grain')}
|
|
239
|
+
>
|
|
240
|
+
{rows => (
|
|
241
|
+
<ComposedChart
|
|
242
|
+
ariaLabel="Samples over time"
|
|
243
|
+
data={rows}
|
|
244
|
+
valueFormat={count}
|
|
245
|
+
>
|
|
246
|
+
<ComposedChart.XAxis dataKey="id" />
|
|
247
|
+
<ComposedChart.YAxis />
|
|
248
|
+
<ComposedChart.Line dataKey="sampleCount" name="Samples" />
|
|
249
|
+
<ComposedChart.Tooltip />
|
|
250
|
+
</ComposedChart>
|
|
251
|
+
)}
|
|
252
|
+
</VisualizationWidget>
|
|
253
|
+
<VisualizationWidget
|
|
254
|
+
dataset={breakdown}
|
|
255
|
+
source={result}
|
|
256
|
+
title="Samples by member"
|
|
257
|
+
breakdown={samplesView.breakdown('breakdown')}
|
|
258
|
+
>
|
|
259
|
+
{rows => (
|
|
260
|
+
<BarChart
|
|
261
|
+
ariaLabel="Samples by member"
|
|
262
|
+
unit="samples"
|
|
263
|
+
items={rows.map(row => ({
|
|
264
|
+
...row,
|
|
265
|
+
label: row.id,
|
|
266
|
+
value: row.sampleCount,
|
|
267
|
+
}))}
|
|
268
|
+
/>
|
|
269
|
+
)}
|
|
270
|
+
</VisualizationWidget>
|
|
271
|
+
<TableWidget dataset={sampleRows} source={result} title="Samples" />
|
|
272
|
+
</Stack>
|
|
273
|
+
));
|
|
274
|
+
function App() {
|
|
275
|
+
return (
|
|
276
|
+
<DataApp view={samplesView} showToolbar={false}>
|
|
277
|
+
<DataSection content={sampleContent} />
|
|
278
|
+
</DataApp>
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
injectDataAppStyles();
|
|
282
|
+
mountDataApp({ app: dataApp, component: App });
|
|
@@ -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.76.0/docs/app-authoring.md). <!-- x-release-please-version -->
|
|
6
6
|
|
|
7
|
-
| Task
|
|
8
|
-
|
|
|
9
|
-
| Define queries and inputs
|
|
10
|
-
|
|
|
11
|
-
| Bind definitions and source evidence
|
|
12
|
-
| Change identity and appearance
|
|
13
|
-
| Inject styles and mount React
|
|
14
|
-
| Configure local serving
|
|
7
|
+
| Task | App-owned files |
|
|
8
|
+
| ------------------------------------------ | -------------------------------------------------------- |
|
|
9
|
+
| Define queries and inputs | `app.ts`, `src/operations.ts`, optional shared contracts |
|
|
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,7 +1,7 @@
|
|
|
1
1
|
# Local 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.76.0/docs/app-authoring.md). <!-- x-release-please-version -->
|
|
5
5
|
See [AGENTS.md](AGENTS.md) for app-owned files.
|
|
6
6
|
|
|
7
7
|
## Run the app
|
|
@@ -21,10 +21,10 @@ Open <http://127.0.0.1:25837>. Alternatively, configure
|
|
|
21
21
|
`ALTERTABLE_DATA_PROXY_URL` and `ALTERTABLE_DATA_PROXY_TOKEN` for an existing
|
|
22
22
|
CLI proxy. Missing credentials stop startup.
|
|
23
23
|
|
|
24
|
-
## Build the
|
|
24
|
+
## Build the app
|
|
25
25
|
|
|
26
|
-
Replace the connectivity check with bounded operations, views,
|
|
27
|
-
|
|
26
|
+
Replace the connectivity check with bounded operations, views, and the content
|
|
27
|
+
specified by the app brief. Change identity, appearance, and queries in `app.ts`.
|
|
28
28
|
|
|
29
29
|
```fish
|
|
30
30
|
bun run check
|
|
@@ -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.76.0",
|
|
21
|
+
"@altertable/data-app-bun": "0.76.0",
|
|
22
|
+
"@altertable/data-app-react": "0.76.0",
|
|
23
23
|
"react": "19.3.1",
|
|
24
24
|
"react-dom": "19.3.1"
|
|
25
25
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.4.4
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
24.18.0
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
|
|
3
|
+
"ignorePatterns": ["dist/**", "bun.lock"],
|
|
4
|
+
"singleQuote": true,
|
|
5
|
+
"trailingComma": "es5",
|
|
6
|
+
"arrowParens": "avoid",
|
|
7
|
+
"printWidth": 80,
|
|
8
|
+
"endOfLine": "lf",
|
|
9
|
+
"sortImports": true,
|
|
10
|
+
"sortPackageJson": false
|
|
11
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
|
3
|
+
"plugins": ["eslint", "typescript", "unicorn", "oxc", "react", "jsx-a11y"],
|
|
4
|
+
"categories": {
|
|
5
|
+
"correctness": "error"
|
|
6
|
+
},
|
|
7
|
+
"options": {
|
|
8
|
+
"typeAware": true
|
|
9
|
+
},
|
|
10
|
+
"rules": {
|
|
11
|
+
"react/unsupported-syntax": "error",
|
|
12
|
+
"eslint/no-restricted-imports": [
|
|
13
|
+
"error",
|
|
14
|
+
{
|
|
15
|
+
"patterns": [
|
|
16
|
+
{
|
|
17
|
+
"regex": "^\\.\\.?/",
|
|
18
|
+
"message": "Use #app/* or #config for app-owned files."
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"func-style": [
|
|
24
|
+
"error",
|
|
25
|
+
"declaration",
|
|
26
|
+
{
|
|
27
|
+
"overrides": {
|
|
28
|
+
"namedExports": "declaration"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Build this local data app
|
|
2
|
+
|
|
3
|
+
Read `node_modules/@altertable/data-app/docs/app-authoring.md` and use this project
|
|
4
|
+
as the selected scaffold. If dependencies are unavailable, read the
|
|
5
|
+
[version-matched recipe](https://github.com/altertable-ai/data-app/blob/v0.76.0/docs/app-authoring.md). <!-- x-release-please-version -->
|
|
6
|
+
|
|
7
|
+
| Task | App-owned files |
|
|
8
|
+
| ------------------------------------------ | -------------------------------------------------------- |
|
|
9
|
+
| Define queries and inputs | `app.ts`, `src/operations.ts`, optional shared contracts |
|
|
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
|
+
|
|
16
|
+
See [README.md](README.md) for setup and checks.
|
|
17
|
+
|
|
18
|
+
Keep reusable app-specific conventions here.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Altertable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Local finding data app starter
|
|
2
|
+
|
|
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.76.0/docs/app-authoring.md). <!-- x-release-please-version -->
|
|
5
|
+
See [AGENTS.md](AGENTS.md) for app-owned files.
|
|
6
|
+
|
|
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.76.0/docs/local-data-apps.md#preview-the-use-case-starters). <!-- x-release-please-version -->
|
|
9
|
+
Use that mock for development, or replace the example queries with verified data
|
|
10
|
+
in your lakehouse. The starter does not install a mock or create demo tables.
|
|
11
|
+
|
|
12
|
+
## Run the app
|
|
13
|
+
|
|
14
|
+
From the copied starter directory, install dependencies and set server-only
|
|
15
|
+
credentials before starting:
|
|
16
|
+
|
|
17
|
+
```fish
|
|
18
|
+
bun install
|
|
19
|
+
set -gx ALTERTABLE_LAKEHOUSE_USERNAME your-username
|
|
20
|
+
read --silent --prompt-str 'Lakehouse password: ' ALTERTABLE_LAKEHOUSE_PASSWORD
|
|
21
|
+
set -gx ALTERTABLE_LAKEHOUSE_PASSWORD $ALTERTABLE_LAKEHOUSE_PASSWORD
|
|
22
|
+
bun run dev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Open <http://127.0.0.1:25837>. Alternatively, configure
|
|
26
|
+
`ALTERTABLE_DATA_PROXY_URL` and `ALTERTABLE_DATA_PROXY_TOKEN` for an existing
|
|
27
|
+
CLI proxy. Missing credentials stop startup.
|
|
28
|
+
|
|
29
|
+
## Build the app
|
|
30
|
+
|
|
31
|
+
Replace the fixture queries and example content with the evidence and content
|
|
32
|
+
specified by the app brief. Change identity, appearance, and queries in `app.ts`.
|
|
33
|
+
|
|
34
|
+
```fish
|
|
35
|
+
bun run check
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`bun run check` includes the build, which writes browser assets to `dist/`. Hosting them requires an authorized
|
|
39
|
+
`/api/data` backend; the local adapter does not authenticate hosted viewers.
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
[MIT](LICENSE)
|