@altertable/data-app 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/REFERENCE.md +365 -257
- package/dist/chunks/{contract-DsyRYgN_.js → contract-BQsFReRp.js} +323 -169
- package/dist/chunks/contract-BQsFReRp.js.map +1 -0
- package/dist/chunks/{contract-kNFYPHRK.js → contract-VhY9V9wd.js} +184 -91
- package/dist/chunks/contract-VhY9V9wd.js.map +1 -0
- package/dist/chunks/{date-time-range-value-TE8KCsfV.js → date-time-range-value-CnlTr1U1.js} +8 -8
- package/dist/chunks/date-time-range-value-CnlTr1U1.js.map +1 -0
- package/dist/chunks/{diagnostics-DhCqGklq.js → diagnostics-Dyj-rUsY.js} +2 -2
- package/dist/chunks/{diagnostics-DhCqGklq.js.map → diagnostics-Dyj-rUsY.js.map} +1 -1
- package/dist/chunks/{operation-7tiT4cpJ.js → operation-BVRM-A5Y.js} +3 -3
- package/dist/chunks/{operation-7tiT4cpJ.js.map → operation-BVRM-A5Y.js.map} +1 -1
- package/dist/client/index.js +65 -50
- package/dist/client/index.js.map +1 -1
- package/dist/core/config.js +1 -1
- package/dist/core/config.js.map +1 -1
- package/dist/core/contract.js +4 -4
- package/dist/core/format.js +1 -1
- package/dist/internal.js +6 -124
- package/dist/internal.js.map +1 -1
- package/dist/server/index.js +3 -3
- package/dist/types/chunks/contract.d.ts +358 -309
- package/dist/types/chunks/contract2.d.ts +16 -2
- package/dist/types/chunks/index.d.ts +32 -5
- package/dist/types/client/index.d.ts +3 -3
- package/dist/types/core/config.d.ts +7 -3
- package/dist/types/core/contract.d.ts +3 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internal.d.ts +5 -5
- package/dist/types/server/index.d.ts +1 -1
- package/docs/app-authoring.md +15 -10
- package/docs/client.md +12 -7
- package/docs/contract.md +33 -51
- package/docs/data-context.md +9 -5
- package/docs/filters.md +295 -0
- package/docs/hosted-apps.md +4 -3
- package/docs/layout.md +24 -18
- package/docs/stories-and-export.md +19 -10
- package/docs/ui.md +6 -5
- package/docs/views.md +62 -26
- package/docs/widgets.md +38 -14
- package/package.json +1 -1
- package/dist/chunks/contract-DsyRYgN_.js.map +0 -1
- package/dist/chunks/contract-kNFYPHRK.js.map +0 -1
- package/dist/chunks/date-time-range-value-TE8KCsfV.js.map +0 -1
- package/docs/variables.md +0 -280
package/docs/variables.md
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
# Variables and filters
|
|
2
|
-
|
|
3
|
-
Declare controls once in the view's `variables`; `<DataApp view={view}>` renders
|
|
4
|
-
them and owns URL state. Use flat operation inputs matching variable names and
|
|
5
|
-
resolved types. Derive SQL parameters inside the operation.
|
|
6
|
-
|
|
7
|
-
## Declare controls once
|
|
8
|
-
|
|
9
|
-
The starter's operation accepts `{ groupName: string }`, so it needs no `input`
|
|
10
|
-
mapper or explicit `bindings`:
|
|
11
|
-
|
|
12
|
-
```ts
|
|
13
|
-
// ... client and sampleDataContext
|
|
14
|
-
const { defineDataView } = createDataHooks(client);
|
|
15
|
-
|
|
16
|
-
const sampleCountsView = defineDataView({
|
|
17
|
-
dataContext: sampleDataContext,
|
|
18
|
-
operation: 'sampleCountsByGroup',
|
|
19
|
-
variables: {
|
|
20
|
-
groupName: searchVariable({
|
|
21
|
-
key: 'group',
|
|
22
|
-
label: 'Group',
|
|
23
|
-
defaultValue: '',
|
|
24
|
-
}),
|
|
25
|
-
},
|
|
26
|
-
describeInput: ({ groupName }) =>
|
|
27
|
-
groupName ? `group ${groupName}` : 'all groups',
|
|
28
|
-
isEmpty: rows => rows.length === 0,
|
|
29
|
-
emptyFallback: { title: 'No matching groups' },
|
|
30
|
-
});
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Keep search local only when it filters already loaded rows. Add dataset
|
|
34
|
-
`suggestions` when record names make useful query completions; suggestions cover
|
|
35
|
-
supplied rows only.
|
|
36
|
-
|
|
37
|
-
## Independent filters and chart breakdowns
|
|
38
|
-
|
|
39
|
-
For source-backed categorical members, use `dataApp.defineDimension()`:
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
// ... dataApp with its registered groups query
|
|
43
|
-
const group = dataApp.defineDimension({
|
|
44
|
-
key: 'group',
|
|
45
|
-
label: 'Group',
|
|
46
|
-
valueType: 'string',
|
|
47
|
-
selectionMode: 'multiple',
|
|
48
|
-
source: { query: 'groups' },
|
|
49
|
-
});
|
|
50
|
-
const parseInput = variableInput(parseEmptyInput, { group });
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
Import `variableInput()` and `parseEmptyInput()` from `/contract`. Use `parseInput`
|
|
54
|
-
on the operation and declare the same `group` in the view's `variables`. Use an
|
|
55
|
-
app-owned base parser instead of `parseEmptyInput()` for other input fields.
|
|
56
|
-
|
|
57
|
-
Declare the source query in `defineDataApp()` with a nullable `member` parameter
|
|
58
|
-
matching `valueType`. Its nonnullable projections are `value` (same type),
|
|
59
|
-
`label` (string), and optional `count` (number). Null requests options; a selected
|
|
60
|
-
member requests exact lookup. Other parameters need defaults or trusted values:
|
|
61
|
-
|
|
62
|
-
```sql
|
|
63
|
-
SELECT DISTINCT group_name AS value, group_name AS label
|
|
64
|
-
FROM sample_counts
|
|
65
|
-
WHERE ($member IS NULL OR group_name = $member)
|
|
66
|
-
ORDER BY label
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
Here `sample_counts` is the inspected table replacing the starter's fixture.
|
|
70
|
-
Validate these variables in every consuming operation, including details. Map
|
|
71
|
-
parsed predicates to declared query parameters; never interpolate filter values
|
|
72
|
-
into SQL. Each dimension is independent: changing one preserves other selections,
|
|
73
|
-
even when their combination returns no rows. No selection means all members.
|
|
74
|
-
|
|
75
|
-
### Chart breakdowns
|
|
76
|
-
|
|
77
|
-
Use `choiceVariable()` for a display choice, separately from population filters:
|
|
78
|
-
|
|
79
|
-
```ts
|
|
80
|
-
const countsBy = choiceVariable({
|
|
81
|
-
key: 'counts-by',
|
|
82
|
-
label: 'Counts breakdown',
|
|
83
|
-
defaultValue: 'group',
|
|
84
|
-
options: [
|
|
85
|
-
{ id: 'group', label: 'Group' },
|
|
86
|
-
{ id: 'country', label: 'Country' },
|
|
87
|
-
],
|
|
88
|
-
presentation: { group: 'display', control: 'widget' },
|
|
89
|
-
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Pass `view.breakdown('countsBy')` to `<VisualizationWidget breakdown={...}>`.
|
|
93
|
-
Declare a separate choice for each independently controlled chart.
|
|
94
|
-
Use `presentation.prominence: 'secondary'` for less frequent scope filters.
|
|
95
|
-
|
|
96
|
-
## Fixed options and query-backed facets
|
|
97
|
-
|
|
98
|
-
Use `dimensionFilter()` from `/contract` when options are known constants:
|
|
99
|
-
|
|
100
|
-
```ts
|
|
101
|
-
const group = dimensionFilter({
|
|
102
|
-
key: 'group',
|
|
103
|
-
label: 'Group',
|
|
104
|
-
valueType: 'string',
|
|
105
|
-
selectionMode: 'multiple',
|
|
106
|
-
options: [
|
|
107
|
-
{ value: 'Alpha', label: 'Alpha' },
|
|
108
|
-
{ value: 'Beta', label: 'Beta' },
|
|
109
|
-
],
|
|
110
|
-
});
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
Use `defineFacetFilter()` only when options must depend on other selections:
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
// ... client and period variable
|
|
117
|
-
const { defineFacetFilter } = createDataHooks(client);
|
|
118
|
-
|
|
119
|
-
const group = defineFacetFilter({
|
|
120
|
-
key: 'group',
|
|
121
|
-
label: 'Group',
|
|
122
|
-
valueType: 'string',
|
|
123
|
-
selectionMode: 'multiple',
|
|
124
|
-
facet: {
|
|
125
|
-
context: { period },
|
|
126
|
-
operation: 'groups',
|
|
127
|
-
input: values => ({ period: values.period }),
|
|
128
|
-
},
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
Declare `period` with `dateTimeRangeVariable()`, include it alongside `group` in the view's variables,
|
|
133
|
-
and return parsed dimension options from the `groups` operation. Validate facet
|
|
134
|
-
selections with `parseDimensionSelection(value, group)` from `/contract`.
|
|
135
|
-
|
|
136
|
-
Use `single` for a replacement choice and `multiple` for independent members.
|
|
137
|
-
Enable `allowExclusion` only when the query supports exclusion and its intended
|
|
138
|
-
missing-value behavior. Use `multiChoiceVariable()` for fixed multiselect
|
|
139
|
-
choices; empty means no choices, unlike an unrestricted dimension.
|
|
140
|
-
|
|
141
|
-
## Reporting periods
|
|
142
|
-
|
|
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:
|
|
148
|
-
|
|
149
|
-
```ts
|
|
150
|
-
// ... client, dailyCountsContext, and calendar contract
|
|
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
|
-
});
|
|
160
|
-
|
|
161
|
-
const dailyCountsView = defineTimeView({
|
|
162
|
-
dataContext: dailyCountsContext,
|
|
163
|
-
operation: 'dailyCountsByGroup',
|
|
164
|
-
time: period,
|
|
165
|
-
variables: {
|
|
166
|
-
groupName: searchVariable({
|
|
167
|
-
key: 'group',
|
|
168
|
-
label: 'Group',
|
|
169
|
-
defaultValue: '',
|
|
170
|
-
}),
|
|
171
|
-
},
|
|
172
|
-
isEmpty: rows => rows.length === 0,
|
|
173
|
-
emptyFallback: { title: 'No matching groups' },
|
|
174
|
-
});
|
|
175
|
-
```
|
|
176
|
-
|
|
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.
|
|
180
|
-
Use `defineDataView()` for fixed snapshots or analysis without a reporting period.
|
|
181
|
-
|
|
182
|
-
## Numeric and boolean predicates
|
|
183
|
-
|
|
184
|
-
Use `numberFilter()` or `booleanFilter()` from `/contract` for field predicates.
|
|
185
|
-
Declare them in `variables` and validate input with `parseNumberSelection()` or
|
|
186
|
-
`parseBooleanSelection()` using the same declarations. Both support
|
|
187
|
-
`{ kind: 'all' }`. Offer only predicates the registered query supports.
|
|
188
|
-
|
|
189
|
-
## Exclusion, clear, and reset
|
|
190
|
-
|
|
191
|
-
Clear removes scope predicates and returns dates to defaults, preserving search
|
|
192
|
-
and display choices. `resetAll()` restores all defaults. Filters apply immediately;
|
|
193
|
-
use app-owned drafts only when the task needs Apply/Cancel.
|
|
194
|
-
|
|
195
|
-
## Adapt existing input shapes
|
|
196
|
-
|
|
197
|
-
Add a mapper and bindings only when an existing operation requires nested or
|
|
198
|
-
differently named inputs. Preserve selected values unchanged in both directions:
|
|
199
|
-
|
|
200
|
-
```ts
|
|
201
|
-
// ... client; operation input is { filters: { period, groupName } }
|
|
202
|
-
const { defineTimeView } = createDataHooks(client);
|
|
203
|
-
|
|
204
|
-
const dailyCountsView = defineTimeView({
|
|
205
|
-
// ... operation, dataContext, time, variables, isEmpty, and emptyFallback
|
|
206
|
-
input: values => ({
|
|
207
|
-
filters: { period: values.period, groupName: values.groupName },
|
|
208
|
-
}),
|
|
209
|
-
bindings: {
|
|
210
|
-
period: input => input.filters.period,
|
|
211
|
-
groupName: input => input.filters.groupName,
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
Custom control ownership is needed only when generated controls cannot express
|
|
217
|
-
the requirement; use `/ui` for that case. Do not reuse reserved inspection,
|
|
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`.
|