@altertable/data-app 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/AGENTS.md +11 -3
- package/CONTRIBUTING.md +14 -3
- package/README.md +56 -9
- package/REFERENCE.md +194 -99
- package/dist/chunks/{contract-BeLPJwlO.js → contract-DsyRYgN_.js} +176 -108
- package/dist/chunks/contract-DsyRYgN_.js.map +1 -0
- package/dist/chunks/{contract-Di8SP74I.js → contract-kNFYPHRK.js} +255 -4
- package/dist/chunks/contract-kNFYPHRK.js.map +1 -0
- package/dist/chunks/date-time-range-value-TE8KCsfV.js +648 -0
- package/dist/chunks/date-time-range-value-TE8KCsfV.js.map +1 -0
- package/dist/chunks/{diagnostics-BTZSlNtW.js → diagnostics-DhCqGklq.js} +2 -2
- package/dist/chunks/{diagnostics-BTZSlNtW.js.map → diagnostics-DhCqGklq.js.map} +1 -1
- package/dist/chunks/{operation-CSM9UmO3.js → operation-7tiT4cpJ.js} +3 -3
- package/dist/chunks/{operation-CSM9UmO3.js.map → operation-7tiT4cpJ.js.map} +1 -1
- package/dist/client/index.js +51 -5
- package/dist/client/index.js.map +1 -1
- package/dist/core/config.js +4 -3
- package/dist/core/config.js.map +1 -1
- package/dist/core/contract.js +4 -3
- package/dist/core/format.js +149 -1
- package/dist/core/format.js.map +1 -0
- package/dist/internal.js +6 -189
- package/dist/internal.js.map +1 -1
- package/dist/server/index.js +3 -3
- package/dist/server/index.js.map +1 -1
- package/dist/types/chunks/contract.d.ts +133 -264
- package/dist/types/chunks/contract2.d.ts +207 -0
- package/dist/types/chunks/date-time-range-value.d.ts +20 -0
- package/dist/types/chunks/date-time-range.d.ts +29 -0
- package/dist/types/chunks/index.d.ts +14 -2
- package/dist/types/client/index.d.ts +3 -3
- package/dist/types/core/config.d.ts +6 -4
- package/dist/types/core/contract.d.ts +5 -2
- package/dist/types/core/format.d.ts +21 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/internal.d.ts +11 -4
- package/dist/types/server/index.d.ts +2 -2
- package/docs/app-authoring.md +46 -14
- package/docs/composition.md +4 -23
- package/docs/contract.md +42 -9
- package/docs/diagnostics.md +37 -0
- package/docs/embed.md +38 -0
- package/docs/hosted-apps.md +7 -4
- package/docs/local-data-apps.md +17 -2
- package/docs/react.md +6 -3
- package/docs/stories-and-export.md +14 -5
- package/docs/ui-quality.md +3 -2
- package/docs/ui.md +53 -2
- package/docs/variables.md +80 -8
- package/package.json +17 -5
- package/dist/chunks/contract-BeLPJwlO.js.map +0 -1
- package/dist/chunks/contract-Di8SP74I.js.map +0 -1
- package/dist/chunks/format-BdFlv_xa.js +0 -148
- package/dist/chunks/format-BdFlv_xa.js.map +0 -1
package/docs/contract.md
CHANGED
|
@@ -33,8 +33,9 @@ ORDER BY group_name LIMIT $limit`,
|
|
|
33
33
|
});
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
Replace fixture SQL with inspected data.
|
|
37
|
-
|
|
36
|
+
Replace fixture SQL with inspected data. Keep query declarations and projections
|
|
37
|
+
in sync when adapting SQL to the app's inputs. Preserve metric definitions.
|
|
38
|
+
Keep operation inputs flat; derive SQL parameters inside `run()`:
|
|
38
39
|
|
|
39
40
|
```ts
|
|
40
41
|
import { parseCount } from '@altertable/data-app/contract';
|
|
@@ -68,7 +69,9 @@ HTTP results must be JSON-serializable.
|
|
|
68
69
|
|
|
69
70
|
Host `queryParams` supplies protected parameters that callers cannot override.
|
|
70
71
|
Other values come from `query()` arguments or defaults. The host/backend enforces
|
|
71
|
-
data access and limits.
|
|
72
|
+
data access and limits. Operation policies must set `maxQueryRows` to a positive
|
|
73
|
+
integer no greater than 10,000. The shared SQL host handler also rejects requests
|
|
74
|
+
for more than 10,000 rows.
|
|
72
75
|
|
|
73
76
|
### Declare query projections
|
|
74
77
|
|
|
@@ -79,11 +82,39 @@ return SQL text and declare `string` when exact numeric precision matters.
|
|
|
79
82
|
|
|
80
83
|
Use `operations.sampleCountsByGroup.queryNames` for context and evidence.
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
### Bind datetime ranges
|
|
83
86
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
Declare a `dateTimeRange` parameter and pass a `DateTimeRange` to `query()`.
|
|
88
|
+
For a [comparison variable](variables.md#absolute-and-relative-datetime-ranges),
|
|
89
|
+
pass its `range` or `comparison` bounds. Reference those bounds in SQL:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
const dataApp = defineDataApp({
|
|
93
|
+
// ... title, description, and scope
|
|
94
|
+
queries: {
|
|
95
|
+
events: {
|
|
96
|
+
statement: `SELECT occurred_at AS "occurredAt" FROM events
|
|
97
|
+
WHERE occurred_at >= $period.from AND occurred_at < $period.to`,
|
|
98
|
+
params: { period: { type: 'dateTimeRange' } },
|
|
99
|
+
projections: { occurredAt: { type: 'string' } },
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The start is inclusive and the end exclusive. Relative values resolve at query
|
|
106
|
+
execution. Absolute values encode wall-clock fields in UTC: selecting 4 PM stores
|
|
107
|
+
16:00Z.
|
|
108
|
+
SQL bounds are timezone-free timestamps. Configure the backend session to the
|
|
109
|
+
reporting timezone and interpret timestamp-with-timezone comparisons in that
|
|
110
|
+
same zone.
|
|
111
|
+
|
|
112
|
+
## Share reporting policy
|
|
113
|
+
|
|
114
|
+
Pass an optional `defineDateRangeContract()` to `dateTimeRangeVariable()` to
|
|
115
|
+
share coverage, duration limits, and reporting timezone between the picker and
|
|
116
|
+
server parser. By default, coverage ends yesterday; set `completeDays: false`
|
|
117
|
+
to include today. Declare the policy once:
|
|
87
118
|
|
|
88
119
|
```ts
|
|
89
120
|
import { defineDateRangeContract } from '@altertable/data-app/contract';
|
|
@@ -95,5 +126,7 @@ const calendar = defineDateRangeContract({
|
|
|
95
126
|
});
|
|
96
127
|
```
|
|
97
128
|
|
|
98
|
-
Use
|
|
99
|
-
|
|
129
|
+
Use the shared contract in the [datetime variable workflow](variables.md#absolute-and-relative-datetime-ranges),
|
|
130
|
+
including optional previous-period comparison. Resolved datetime requests include
|
|
131
|
+
the start and exclude the end. Pass the variable to `defineTimeView()` and
|
|
132
|
+
validate operation input with its parser.
|
package/docs/diagnostics.md
CHANGED
|
@@ -43,3 +43,40 @@ reset the allowance. Callback resolution means acceptance, not agent execution.
|
|
|
43
43
|
Omit `onRepairRequest` when delivery or reliable state retention is unavailable;
|
|
44
44
|
the banner offers diagnostics to copy instead. Avoid sensitive values in errors.
|
|
45
45
|
Source locations use generated filenames and positions.
|
|
46
|
+
|
|
47
|
+
## Custom banners
|
|
48
|
+
|
|
49
|
+
Use `session.snapshot()` to read diagnostics, delivery status, the automatic
|
|
50
|
+
request count, and the latest request's start time. Subscribe with
|
|
51
|
+
`session.subscribe()` and request a fix with `session.requestRepair()`. These APIs
|
|
52
|
+
work without React or the default banner.
|
|
53
|
+
|
|
54
|
+
In React, pass the snapshot to your own banner:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import type { DataAppRepairSession } from '@altertable/data-app-embed';
|
|
58
|
+
import { useSyncExternalStore } from 'react';
|
|
59
|
+
|
|
60
|
+
import { RepairBanner } from './RepairBanner';
|
|
61
|
+
|
|
62
|
+
function AppRepair({ session }: { session: DataAppRepairSession }) {
|
|
63
|
+
const repair = useSyncExternalStore(
|
|
64
|
+
listener => session.subscribe(listener),
|
|
65
|
+
session.snapshot,
|
|
66
|
+
session.snapshot
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<RepairBanner
|
|
71
|
+
repair={repair}
|
|
72
|
+
onRequestRepair={() => void session.requestRepair()}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The host owns agent activity and revision loading. Request acceptance does not
|
|
79
|
+
mean the agent has started or finished. Clear the previous attempt's activity
|
|
80
|
+
when requesting another fix, and clear progress when the updated revision's
|
|
81
|
+
diagnostics settle. Custom banners choose their own presentation; the default
|
|
82
|
+
`<DataAppRepairBanner>` accepts observed host activity through `progress`.
|
package/docs/embed.md
CHANGED
|
@@ -86,6 +86,44 @@ Host Back/Forward events publish opaque host state through the bridge. The app's
|
|
|
86
86
|
optional navigation adapter interprets search/hash and synchronizes controls;
|
|
87
87
|
opaque apps keep that state in memory rather than modifying their document URL.
|
|
88
88
|
|
|
89
|
+
## External links
|
|
90
|
+
|
|
91
|
+
Register the external link route to let apps request HTTPS navigation without
|
|
92
|
+
relaxing the iframe sandbox:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import {
|
|
96
|
+
createMessageRouter,
|
|
97
|
+
openExternalLinkRoute,
|
|
98
|
+
} from '@altertable/data-app/contract';
|
|
99
|
+
import { createExternalLinkHandler } from '@altertable/data-app-embed';
|
|
100
|
+
|
|
101
|
+
const router = createMessageRouter(
|
|
102
|
+
{ 'navigation:openExternal': openExternalLinkRoute },
|
|
103
|
+
{
|
|
104
|
+
'navigation:openExternal': createExternalLinkHandler({
|
|
105
|
+
allowedOrigins: ['https://example.com'],
|
|
106
|
+
}),
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
// Pass router.dispatch as the bridge's onMessage handler.
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
To use an existing modifier-based host navigation helper, register it directly:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
const openExternalLink = createExternalLinkHandler({
|
|
116
|
+
navigate: navigateNewWindowOrTab,
|
|
117
|
+
});
|
|
118
|
+
// Register openExternalLink for navigation:openExternal in the host router.
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Here `navigateNewWindowOrTab` is the host's `(url, event)` navigation helper.
|
|
122
|
+
Use the frontend helper, not the app-side bridge client with the same name.
|
|
123
|
+
|
|
124
|
+
Choose permitted origins according to the host's data policy: URLs can carry app
|
|
125
|
+
data, and the initial origin check does not constrain redirects at the destination.
|
|
126
|
+
|
|
89
127
|
## Status and diagnostics
|
|
90
128
|
|
|
91
129
|
`onStatusChange` receives `connecting`, `connected`, `ready`, `failed`, or
|
package/docs/hosted-apps.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Author a data app
|
|
2
2
|
|
|
3
|
-
Follow the [
|
|
3
|
+
Follow the [SDK integration guide](app-authoring.md) with a version-matched hosted
|
|
4
|
+
starter selected by the authoring workflow. The shared starter
|
|
5
|
+
is `starter-data-app/index.tsx`; its sample content is replaceable. Keep the app in
|
|
4
6
|
one file with public package imports; omit server files, HTML, credentials, and
|
|
5
7
|
relative or app-alias imports.
|
|
6
8
|
|
|
@@ -13,15 +15,16 @@ interpolation), finite signed numbers, booleans, and null. Parentheses, `as`, an
|
|
|
13
15
|
computed keys, references, and callbacks. Static apps use `queries: {}`.
|
|
14
16
|
|
|
15
17
|
Replace sample queries and bindings with inspected source data. Supply `scope`
|
|
16
|
-
in `defineDataApp()
|
|
18
|
+
in `defineDataApp()`. When using bound `<DataApp>`, follow its current
|
|
19
|
+
[story and dataset requirements](stories-and-export.md).
|
|
17
20
|
|
|
18
21
|
Keep the starter's client, style injection, and mounting code. The host supplies
|
|
19
22
|
the transport; no bootstrap or message routes are needed in app code.
|
|
20
23
|
|
|
21
24
|
## Convert a local data app
|
|
22
25
|
|
|
23
|
-
1. Combine the app's operations and parsers, data context, views,
|
|
24
|
-
|
|
26
|
+
1. Combine the app's operations and parsers, data context, views, any presentation
|
|
27
|
+
and export features, app declaration, and browser entry into one `index.tsx`, following the
|
|
25
28
|
[single-file starter](app-authoring.md#use-release-matched-starters).
|
|
26
29
|
2. Replace the HTTP client with `createDataClient({ operations })`, using the
|
|
27
30
|
operation registry as a value. See [browser-owned operations](client.md#browser-owned-operations-for-bundle-apps)
|
package/docs/local-data-apps.md
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Use the local scaffold supplied by your authoring workflow. Its README covers
|
|
4
4
|
setup and its AGENTS.md identifies app-owned files.
|
|
5
|
-
Replace the connectivity screen
|
|
6
|
-
[shared
|
|
5
|
+
Replace the connectivity screen or fixture examples with the content specified by
|
|
6
|
+
the app brief, using the [shared SDK patterns](app-authoring.md). Local execution
|
|
7
|
+
does not require a particular content structure or presentation story.
|
|
7
8
|
|
|
8
9
|
| Task | Documentation |
|
|
9
10
|
| ---------------------------- | ---------------------------------------- |
|
|
@@ -12,3 +13,17 @@ Replace the connectivity screen with the exploration, CSV export, and story from
|
|
|
12
13
|
| Customize the browser client | [HTTP client](client.md#http-operations) |
|
|
13
14
|
|
|
14
15
|
You can also [convert the local app to a hosted data app](hosted-apps.md#convert-a-local-data-app).
|
|
16
|
+
|
|
17
|
+
## Preview the use-case starters
|
|
18
|
+
|
|
19
|
+
From the SDK repository, run `bun run dev:gallery` with Docker available. It starts
|
|
20
|
+
and seeds the Altertable mock with fictional sample data.
|
|
21
|
+
|
|
22
|
+
| Starter | Hosted preview | Local preview |
|
|
23
|
+
| ------- | ------------------------------------------------- | ------------------------ |
|
|
24
|
+
| Metric | <http://127.0.0.1:27418/starter-metric-data-app> | <http://127.0.0.1:27421> |
|
|
25
|
+
| Finding | <http://127.0.0.1:27418/starter-finding-data-app> | <http://127.0.0.1:27422> |
|
|
26
|
+
|
|
27
|
+
Copied starters use the normal query connection. Replace their example queries
|
|
28
|
+
with verified sources in the target lakehouse; the mock and seed belong only to
|
|
29
|
+
local development. Never create demo objects in a user's lakehouse.
|
package/docs/react.md
CHANGED
|
@@ -15,9 +15,12 @@ mountDataApp({ app: dataApp, component: App });
|
|
|
15
15
|
|
|
16
16
|
The app supplies `dataApp`, `App`, and a `#root` element.
|
|
17
17
|
|
|
18
|
-
Keep the starter's mounting and client wiring.
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
Keep the selected starter's mounting and client wiring. The
|
|
19
|
+
app brief selects the starter and content structure; the available runtime
|
|
20
|
+
starters are listed in [app authoring](app-authoring.md#use-release-matched-starters).
|
|
21
|
+
Use declared views and bound widgets for data-backed content. Use `/ui` for
|
|
22
|
+
setup/static screens or a custom component only when bound components cannot
|
|
23
|
+
express the requirement.
|
|
21
24
|
|
|
22
25
|
Hosts embedding an app use the separate `@altertable/data-app-embed` package;
|
|
23
26
|
that integration is outside ordinary app authoring.
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
# Stories and CSV export
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
The bound `<DataApp>` from `@altertable/data-app-react` accepts an optional `story`
|
|
4
|
+
callback and optional nonempty `datasets` list. Omit either prop to omit its toolbar
|
|
5
|
+
control. Supplied features use the displayed snapshot, including during refresh or
|
|
6
|
+
failure. A story callback returning `[]` leaves a disabled presentation action.
|
|
7
|
+
Set `showToolbar={false}` to omit page actions together; data loading, error states,
|
|
8
|
+
and declared filters remain available. Setup and static screens can use `<DataApp>`
|
|
9
|
+
from `/ui`.
|
|
10
|
+
|
|
11
|
+
These are component contracts. The app brief determines the
|
|
12
|
+
intended presentation and export coverage. A presentation story is distinct from
|
|
13
|
+
explanatory prose in the app body.
|
|
6
14
|
|
|
7
15
|
## Present data with stories
|
|
8
16
|
|
|
@@ -41,8 +49,9 @@ Keep the starter's `formatMetric()` import for formatted headlines.
|
|
|
41
49
|
## Export displayed data as CSV
|
|
42
50
|
|
|
43
51
|
Declare [datasets](widgets.md#declare-datasets-and-metrics) once and pass
|
|
44
|
-
`datasets={[sampleCounts]}`.
|
|
45
|
-
|
|
52
|
+
`datasets={[sampleCounts]}`. This list determines which datasets are available
|
|
53
|
+
for export, using their bound rows and columns. Preserve the displayed grain;
|
|
54
|
+
reuse a dataset for visuals sharing the same rows.
|
|
46
55
|
|
|
47
56
|
One dataset downloads as CSV; multiple datasets offer individual downloads and
|
|
48
57
|
**Export all** as ZIP. Filenames use the displayed scope. Accessors must return
|
package/docs/ui-quality.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# UI quality
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Make the main result easy to identify and compare. Make its scope, units, and
|
|
4
|
+
supporting evidence explicit, using context supplied by the host where available
|
|
5
|
+
instead of repeating it. Explain each chart's purpose and measures. Use package typography and formatters;
|
|
5
6
|
keep primary values prominent and preserve exact values in records and exports.
|
|
6
7
|
|
|
7
8
|
Compose with `<Stack>`, `<Grid>`, and `<TextContent>`; parents own spacing and
|
package/docs/ui.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Direct UI composition
|
|
2
2
|
|
|
3
3
|
Import from `@altertable/data-app-react/ui` for setup/static screens, custom
|
|
4
|
-
controls, or a deliberately custom shell.
|
|
4
|
+
controls, or a deliberately custom shell. For data-backed content, prefer declared views
|
|
5
5
|
and bound widgets from `@altertable/data-app-react`.
|
|
6
6
|
|
|
7
7
|
`<DataApp>` here renders a static screen and accepts optional direct CSV data.
|
|
@@ -23,6 +23,50 @@ For framework mounting, `<DataAppProvider app={dataApp}>` supplies app identity,
|
|
|
23
23
|
Call `injectDataAppStyles()` before mounting either entry; imports do not install
|
|
24
24
|
styles.
|
|
25
25
|
|
|
26
|
+
## Tooltips and explanations
|
|
27
|
+
|
|
28
|
+
Use `<Tooltip>` for a short, supplemental description of an already labeled
|
|
29
|
+
control. Pass one child that forwards `aria-describedby` to its focusable DOM
|
|
30
|
+
element. Keep the accessible name on the control itself. `<IconButton>` already
|
|
31
|
+
includes a tooltip; use its `tooltip` prop to customize the hint.
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { Button } from '@altertable/data-app-react';
|
|
35
|
+
import { Tooltip, TooltipProvider } from '@altertable/data-app-react/ui';
|
|
36
|
+
|
|
37
|
+
function ExportActions({ exportRows }: { exportRows: () => void }) {
|
|
38
|
+
return (
|
|
39
|
+
<TooltipProvider>
|
|
40
|
+
<Tooltip content="Download the rows in the current view">
|
|
41
|
+
<Button onClick={exportRows}>Export CSV</Button>
|
|
42
|
+
</Tooltip>
|
|
43
|
+
<Tooltip
|
|
44
|
+
content="Available after data loads"
|
|
45
|
+
tabIndex={0}
|
|
46
|
+
role="group"
|
|
47
|
+
aria-label="Export all rows unavailable"
|
|
48
|
+
>
|
|
49
|
+
<Button disabled>Export all rows</Button>
|
|
50
|
+
</Tooltip>
|
|
51
|
+
</TooltipProvider>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`<AppLayout>` already provides shared timing. A standalone `<Tooltip>` works
|
|
57
|
+
without a provider; wrap adjacent custom controls in `<TooltipProvider>` to share
|
|
58
|
+
the first-hover delay and open subsequent hints immediately. Keyboard focus opens
|
|
59
|
+
hints immediately. The pointer can move onto the hint to keep it visible; Escape
|
|
60
|
+
or pressing the control dismisses it. Existing descriptions, child handlers, and
|
|
61
|
+
refs are preserved. Native span props and `ref` target the wrapper; make that
|
|
62
|
+
wrapper focusable for disabled controls or plain text.
|
|
63
|
+
|
|
64
|
+
Keep tooltip content non-interactive. Use `<HelpPopover>` for links, actions,
|
|
65
|
+
longer explanations, or information users must be able to open on touch devices.
|
|
66
|
+
Use `content={null}` to suppress an unavailable hint. Portals escape clipping
|
|
67
|
+
containers and stay inside a surrounding native dialog automatically; use
|
|
68
|
+
`portalRoot` only when a custom overlay needs a specific destination.
|
|
69
|
+
|
|
26
70
|
## Custom activity labels
|
|
27
71
|
|
|
28
72
|
For a custom activity label, wrap `<ShimmerText>` in `<output>`:
|
|
@@ -215,7 +259,7 @@ filter declarations own URL state, validation, and operation meaning.
|
|
|
215
259
|
| `<SegmentedControl>` | Compact radio choices |
|
|
216
260
|
| `<NumberField>` | Localized numeric input; empty is `null` |
|
|
217
261
|
| `<NumberRangeField>` | Exact, inclusive minimum/maximum; omitted bounds are unrestricted |
|
|
218
|
-
| `<
|
|
262
|
+
| `<DateTimeRangePicker>` | Datetime ranges with an exclusive end |
|
|
219
263
|
| `<DimensionPicker>` | Typed categorical predicates with fixed or facet options |
|
|
220
264
|
|
|
221
265
|
```tsx
|
|
@@ -249,3 +293,10 @@ for inline forms.
|
|
|
249
293
|
Use `<Button variant="primary">` for the main committing action, such as Apply.
|
|
250
294
|
Use outline and ghost buttons for secondary actions.
|
|
251
295
|
Use `<Button variant="inline">` for actions within text or table cells. Use buttons for opening sheets and links for URL navigation.
|
|
296
|
+
|
|
297
|
+
## Datetime selection
|
|
298
|
+
|
|
299
|
+
Prefer a [datetime variable](variables.md#absolute-and-relative-datetime-ranges)
|
|
300
|
+
for generated controls and URL state. For custom screens, `<DateTimeRangePicker>`
|
|
301
|
+
accepts the same `DateTimeRange` and preset sets, with calendar and natural-language
|
|
302
|
+
entry. See its props in [REFERENCE.md](../REFERENCE.md).
|
package/docs/variables.md
CHANGED
|
@@ -129,7 +129,7 @@ const group = defineFacetFilter({
|
|
|
129
129
|
});
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
-
Declare `period` with `
|
|
132
|
+
Declare `period` with `dateTimeRangeVariable()`, include it alongside `group` in the view's variables,
|
|
133
133
|
and return parsed dimension options from the `groups` operation. Validate facet
|
|
134
134
|
selections with `parseDimensionSelection(value, group)` from `/contract`.
|
|
135
135
|
|
|
@@ -140,19 +140,28 @@ choices; empty means no choices, unlike an unrestricted dimension.
|
|
|
140
140
|
|
|
141
141
|
## Reporting periods
|
|
142
142
|
|
|
143
|
-
Use `defineTimeView()` when the analysis is period-driven.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
Use `defineTimeView()` when the analysis is period-driven. Declare a
|
|
144
|
+
`dateTimeRangeVariable()` and share its `defineDateRangeContract()` with the
|
|
145
|
+
operation parser. Datetime bounds include `from` and exclude `to`; the `period`
|
|
146
|
+
URL value stores the datetime selection. After adapting the operation to accept
|
|
147
|
+
`{ period, groupName }`, the view can stay flat:
|
|
147
148
|
|
|
148
149
|
```ts
|
|
149
150
|
// ... client, dailyCountsContext, and calendar contract
|
|
150
151
|
const { defineTimeView } = createDataHooks(client);
|
|
152
|
+
const period = dateTimeRangeVariable({
|
|
153
|
+
key: 'period',
|
|
154
|
+
contract: calendar,
|
|
155
|
+
defaultValue: {
|
|
156
|
+
from: new Date('2026-03-04T00:00:00Z'),
|
|
157
|
+
to: new Date('2026-03-11T00:00:00Z'),
|
|
158
|
+
},
|
|
159
|
+
});
|
|
151
160
|
|
|
152
161
|
const dailyCountsView = defineTimeView({
|
|
153
162
|
dataContext: dailyCountsContext,
|
|
154
163
|
operation: 'dailyCountsByGroup',
|
|
155
|
-
time:
|
|
164
|
+
time: period,
|
|
156
165
|
variables: {
|
|
157
166
|
groupName: searchVariable({
|
|
158
167
|
key: 'group',
|
|
@@ -165,8 +174,9 @@ const dailyCountsView = defineTimeView({
|
|
|
165
174
|
});
|
|
166
175
|
```
|
|
167
176
|
|
|
168
|
-
The operation's parser validates `period` with `
|
|
169
|
-
|
|
177
|
+
The operation's parser validates `period` with `period.parse()` or
|
|
178
|
+
`period.parseInput()` when comparison is enabled. Resolved comparison requests
|
|
179
|
+
have exclusive `range.to` and `comparison.to` bounds.
|
|
170
180
|
Use `defineDataView()` for fixed snapshots or analysis without a reporting period.
|
|
171
181
|
|
|
172
182
|
## Numeric and boolean predicates
|
|
@@ -206,3 +216,65 @@ const dailyCountsView = defineTimeView({
|
|
|
206
216
|
Custom control ownership is needed only when generated controls cannot express
|
|
207
217
|
the requirement; use `/ui` for that case. Do not reuse reserved inspection,
|
|
208
218
|
presentation, or navigation URL keys.
|
|
219
|
+
|
|
220
|
+
## Absolute and relative datetime ranges
|
|
221
|
+
|
|
222
|
+
Use `dateTimeRangeVariable()` for calendar days, times, rolling windows, or
|
|
223
|
+
mixed absolute and relative bounds. Share the variable between the operation parser and the view;
|
|
224
|
+
`<DataApp>` supplies the picker and URL state:
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
import {
|
|
228
|
+
dateTimeRangeVariable,
|
|
229
|
+
dateTimeRangePresets,
|
|
230
|
+
defineDateRangeContract,
|
|
231
|
+
variableInput,
|
|
232
|
+
} from '@altertable/data-app/contract';
|
|
233
|
+
import { createDataHooks } from '@altertable/data-app-react';
|
|
234
|
+
|
|
235
|
+
const calendar = defineDateRangeContract({
|
|
236
|
+
maxRangeDays: 366,
|
|
237
|
+
timeZone: 'UTC',
|
|
238
|
+
completeDays: false,
|
|
239
|
+
});
|
|
240
|
+
const period = dateTimeRangeVariable({
|
|
241
|
+
key: 'period',
|
|
242
|
+
contract: calendar,
|
|
243
|
+
allowComparison: true,
|
|
244
|
+
defaultValue: '30d',
|
|
245
|
+
presets: [
|
|
246
|
+
...dateTimeRangePresets.analytics,
|
|
247
|
+
{ label: 'Past 6 months', range: '6mo', shortcut: '6mo' },
|
|
248
|
+
],
|
|
249
|
+
});
|
|
250
|
+
const events = dataApp.defineOperation({
|
|
251
|
+
input: variableInput(() => ({}), { period }),
|
|
252
|
+
checks: [{ period: period.input(period.defaultValue) }],
|
|
253
|
+
policy: { maxQueryRows: 1000, maxDurationMs: 15000 },
|
|
254
|
+
async run({ query }, input) {
|
|
255
|
+
const current = await query('events', { period: input.period.range });
|
|
256
|
+
const previous = input.period.comparison
|
|
257
|
+
? await query('events', { period: input.period.comparison })
|
|
258
|
+
: null;
|
|
259
|
+
return { current: current.rows, previous: previous?.rows ?? null };
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
// ... client created from { events }, and eventsContext
|
|
263
|
+
const { defineTimeView } = createDataHooks(client);
|
|
264
|
+
const eventsView = defineTimeView({
|
|
265
|
+
operation: 'events',
|
|
266
|
+
dataContext: eventsContext,
|
|
267
|
+
time: period,
|
|
268
|
+
isEmpty: result => result.current.length === 0,
|
|
269
|
+
emptyFallback: { title: 'No events' },
|
|
270
|
+
});
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Use `dateTimeRangePresets.monitoring` for shorter windows. Bind the query bounds
|
|
274
|
+
to a [datetime parameter](contract.md#bind-datetime-ranges).
|
|
275
|
+
`allowComparison: true` adds the toggle and supplies current/previous ranges resolved
|
|
276
|
+
against one reference time; the view derives metric comparison labels from that
|
|
277
|
+
request. Omit `comparison` for a plain `DateTimeRange` input, and omit `contract`
|
|
278
|
+
when no shared reporting policy is needed. Relative selections stay relative
|
|
279
|
+
across reloads. Query `from` inclusively and `to` exclusively. A September 24–30
|
|
280
|
+
calendar selection uses `2026-09-24T00:00:00Z` through `2026-10-01T00:00:00Z`.
|
package/package.json
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altertable/data-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.76.0",
|
|
4
4
|
"description": "Portable definitions, contracts, formatting, browser clients, and request handlers for Altertable data apps.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"altertable",
|
|
7
|
-
"analytics",
|
|
8
7
|
"data-app",
|
|
9
|
-
"
|
|
8
|
+
"data-apps",
|
|
9
|
+
"dashboard",
|
|
10
|
+
"analytics",
|
|
11
|
+
"embedded-analytics",
|
|
12
|
+
"business-intelligence",
|
|
13
|
+
"bi",
|
|
14
|
+
"reporting",
|
|
15
|
+
"data-visualization",
|
|
16
|
+
"sql",
|
|
17
|
+
"lakehouse",
|
|
18
|
+
"ai-agents",
|
|
19
|
+
"mcp",
|
|
20
|
+
"mcp-apps",
|
|
10
21
|
"typescript"
|
|
11
22
|
],
|
|
12
|
-
"homepage": "https://
|
|
23
|
+
"homepage": "https://altertable.ai/docs/data-apps",
|
|
13
24
|
"bugs": {
|
|
14
25
|
"url": "https://github.com/altertable-ai/data-app/issues"
|
|
15
26
|
},
|
|
@@ -77,6 +88,7 @@
|
|
|
77
88
|
"typecheck": "bun ../../node_modules/typescript/bin/tsc --noEmit -p tsconfig.build.json"
|
|
78
89
|
},
|
|
79
90
|
"dependencies": {
|
|
80
|
-
"@internationalized/date": "3.12.4"
|
|
91
|
+
"@internationalized/date": "3.12.4",
|
|
92
|
+
"chrono-node": "2.10.3"
|
|
81
93
|
}
|
|
82
94
|
}
|