@altertable/data-app 0.71.0 → 0.73.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.
Files changed (130) hide show
  1. package/AGENTS.md +5 -61
  2. package/CONTRIBUTING.md +93 -173
  3. package/README.md +3 -3
  4. package/REFERENCE.md +30 -341
  5. package/dist/chunks/contract-BeLPJwlO.js +558 -0
  6. package/dist/chunks/contract-BeLPJwlO.js.map +1 -0
  7. package/dist/chunks/contract-Di8SP74I.js +462 -0
  8. package/dist/chunks/contract-Di8SP74I.js.map +1 -0
  9. package/dist/chunks/format-BdFlv_xa.js +148 -0
  10. package/dist/chunks/format-BdFlv_xa.js.map +1 -0
  11. package/dist/chunks/iframe-C3uCZEXh.js +809 -0
  12. package/dist/chunks/iframe-C3uCZEXh.js.map +1 -0
  13. package/dist/chunks/operation-CBxhjNhK.js +131 -0
  14. package/dist/chunks/operation-CBxhjNhK.js.map +1 -0
  15. package/dist/chunks/request-body-H1qPmmTN.js +50 -0
  16. package/dist/chunks/request-body-H1qPmmTN.js.map +1 -0
  17. package/dist/client/index.js +253 -285
  18. package/dist/client/index.js.map +1 -13
  19. package/dist/core/appearance.js +171 -162
  20. package/dist/core/appearance.js.map +1 -10
  21. package/dist/core/config.js +49 -11
  22. package/dist/core/config.js.map +1 -9
  23. package/dist/core/contract.js +3 -73
  24. package/dist/core/format.js +1 -26
  25. package/dist/index.js +1 -12
  26. package/dist/internal.js +352 -397
  27. package/dist/internal.js.map +1 -15
  28. package/dist/server/index.js +85 -97
  29. package/dist/server/index.js.map +1 -10
  30. package/dist/types/chunks/appearance.d.ts +45 -0
  31. package/dist/types/chunks/contract.d.ts +720 -0
  32. package/dist/types/chunks/index.d.ts +189 -0
  33. package/dist/types/client/index.d.ts +3 -13
  34. package/dist/types/core/appearance.d.ts +2 -42
  35. package/dist/types/core/config.d.ts +44 -48
  36. package/dist/types/core/contract.d.ts +2 -114
  37. package/dist/types/core/format.d.ts +44 -17
  38. package/dist/types/index.d.ts +3 -3
  39. package/dist/types/internal.d.ts +312 -22
  40. package/dist/types/server/index.d.ts +15 -4
  41. package/docs/app-authoring.md +72 -112
  42. package/docs/client.md +29 -63
  43. package/docs/composition.md +44 -75
  44. package/docs/contract.md +60 -100
  45. package/docs/data-context.md +35 -61
  46. package/docs/embed.md +83 -55
  47. package/docs/formatting-and-appearance.md +17 -38
  48. package/docs/hosted-apps.md +12 -15
  49. package/docs/layout.md +30 -47
  50. package/docs/local-data-apps.md +7 -7
  51. package/docs/react-embed.md +20 -26
  52. package/docs/react.md +10 -27
  53. package/docs/server-bun.md +3 -28
  54. package/docs/server.md +6 -12
  55. package/docs/stories-and-export.md +38 -40
  56. package/docs/styling.md +14 -22
  57. package/docs/ui-quality.md +5 -5
  58. package/docs/ui.md +68 -70
  59. package/docs/variables.md +142 -254
  60. package/docs/views.md +85 -116
  61. package/docs/widgets.md +100 -153
  62. package/docs/worker.md +15 -27
  63. package/package.json +3 -3
  64. package/dist/chunks/index-5a27erdg.js +0 -54
  65. package/dist/chunks/index-5a27erdg.js.map +0 -10
  66. package/dist/chunks/index-9yxr7nmm.js +0 -742
  67. package/dist/chunks/index-9yxr7nmm.js.map +0 -17
  68. package/dist/chunks/index-j5q5n3ra.js +0 -151
  69. package/dist/chunks/index-j5q5n3ra.js.map +0 -10
  70. package/dist/chunks/index-q75zm3a7.js +0 -153
  71. package/dist/chunks/index-q75zm3a7.js.map +0 -11
  72. package/dist/chunks/index-vhaec7m5.js +0 -30
  73. package/dist/chunks/index-vhaec7m5.js.map +0 -10
  74. package/dist/chunks/index-zp78caex.js +0 -1047
  75. package/dist/chunks/index-zp78caex.js.map +0 -19
  76. package/dist/core/contract.js.map +0 -9
  77. package/dist/core/format.js.map +0 -9
  78. package/dist/index.js.map +0 -9
  79. package/dist/types/client/annotations.d.ts +0 -27
  80. package/dist/types/client/data-client.d.ts +0 -43
  81. package/dist/types/client/download.d.ts +0 -5
  82. package/dist/types/client/iframe.d.ts +0 -59
  83. package/dist/types/client/location.d.ts +0 -13
  84. package/dist/types/client/logger.d.ts +0 -14
  85. package/dist/types/client/messages.d.ts +0 -7
  86. package/dist/types/client/navigation.d.ts +0 -15
  87. package/dist/types/client/transport.d.ts +0 -15
  88. package/dist/types/core/annotations.d.ts +0 -99
  89. package/dist/types/core/bridge-endpoint.d.ts +0 -21
  90. package/dist/types/core/bridge.d.ts +0 -172
  91. package/dist/types/core/data-view.d.ts +0 -46
  92. package/dist/types/core/date-format.d.ts +0 -24
  93. package/dist/types/core/date-range.d.ts +0 -20
  94. package/dist/types/core/dimension-source.d.ts +0 -64
  95. package/dist/types/core/dimension.d.ts +0 -71
  96. package/dist/types/core/facets.d.ts +0 -13
  97. package/dist/types/core/filters.d.ts +0 -45
  98. package/dist/types/core/invariant.d.ts +0 -2
  99. package/dist/types/core/keys.d.ts +0 -2
  100. package/dist/types/core/logger.d.ts +0 -12
  101. package/dist/types/core/messages.d.ts +0 -62
  102. package/dist/types/core/navigation.d.ts +0 -11
  103. package/dist/types/core/operation-types.d.ts +0 -80
  104. package/dist/types/core/operation.d.ts +0 -20
  105. package/dist/types/core/presentation.d.ts +0 -9
  106. package/dist/types/core/queries.d.ts +0 -84
  107. package/dist/types/core/reading.d.ts +0 -17
  108. package/dist/types/core/uuid.d.ts +0 -2
  109. package/dist/types/core/variables.d.ts +0 -133
  110. package/dist/types/server/handler.d.ts +0 -13
  111. package/dist/types/server/request-body.d.ts +0 -4
  112. package/examples/starter-data-app/index.tsx +0 -193
  113. package/examples/starter-local-data-app/.bun-version +0 -1
  114. package/examples/starter-local-data-app/.node-version +0 -1
  115. package/examples/starter-local-data-app/.oxfmtrc.json +0 -4
  116. package/examples/starter-local-data-app/.oxlintrc.json +0 -33
  117. package/examples/starter-local-data-app/AGENTS.md +0 -22
  118. package/examples/starter-local-data-app/README.md +0 -56
  119. package/examples/starter-local-data-app/app.ts +0 -28
  120. package/examples/starter-local-data-app/bunfig.toml +0 -2
  121. package/examples/starter-local-data-app/package.json +0 -35
  122. package/examples/starter-local-data-app/src/App.tsx +0 -8
  123. package/examples/starter-local-data-app/src/assets.d.ts +0 -1
  124. package/examples/starter-local-data-app/src/data-context.ts +0 -21
  125. package/examples/starter-local-data-app/src/favicon.svg +0 -13
  126. package/examples/starter-local-data-app/src/index.html +0 -14
  127. package/examples/starter-local-data-app/src/main.tsx +0 -7
  128. package/examples/starter-local-data-app/src/operations.ts +0 -6
  129. package/examples/starter-local-data-app/src/server.ts +0 -6
  130. package/examples/starter-local-data-app/tsconfig.json +0 -21
package/docs/variables.md CHANGED
@@ -1,320 +1,208 @@
1
1
  # Variables and filters
2
2
 
3
- ## Time views and field filters
4
-
5
- `createDataHooks(client).defineTimeView()` owns the `period` variable, calendar
6
- controls, and displayed-period label. Declare `time: { contract, defaultValue }`,
7
- an operation, `isEmpty` (a predicate), and `emptyFallback` (a title and optional
8
- description for an empty result). With no additional variables, its default
9
- input is the calendar request. With additional variables, it is `{ period, ...variables }`.
10
- Supply an `input` mapper for a different operation shape and `bindings` to extract
11
- nested period or field-filter inputs. Mappings must preserve the selected values.
12
- Bindings are required when the operation input cannot supply a compatible
13
- top-level filter field or the calendar request. Keep parsed selections in the
14
- operation input and derive SQL parameters inside the operation.
15
-
16
- `dimensionFilter()` from `/contract` uses fixed `options`. Use `defineFacetFilter()`
17
- for options derived from declared variable context, or `app.defineDimension()`
18
- for independent source options and exact member lookup. `<DimensionPicker>` offers missing values separately and keeps selected values
19
- available when options refresh or fail; unknown counts remain undisclosed.
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.
20
6
 
21
7
  ## Declare controls once
22
8
 
23
- Use `searchVariable()`, `choiceVariable()`, and `dateRangeVariable()` in a view's
24
- `variables`. `<DataApp view={view}>` generates search, filters, and display options
25
- and keeps their values in the URL.
26
- Set `showSearch={false}` or `showFilters={false}` on `<DataApp>` to hide the
27
- corresponding region while preserving its values; `showFilters` includes display options.
9
+ The starter's operation accepts `{ groupName: string }`, so it needs no `input`
10
+ mapper or explicit `bindings`:
28
11
 
29
- Keep local search out of the operation input when it only filters loaded rows.
30
-
31
- ### Search suggestions
32
-
33
- Declaring dataset `suggestions` enables autocomplete automatically. Use it when
34
- record titles are useful query completions; omit it for aggregate datasets or when
35
- completion would not help. No additional enabling prop is needed.
36
-
37
- The app-owned `customers` operation accepts `{ q: string }` and returns `{ rows }`.
38
- With your typed `client` and registered `dataContext`, connect the query to its
39
- records and widgets:
12
+ ```ts
13
+ // ... client and sampleDataContext
14
+ const { defineDataView } = createDataHooks(client);
40
15
 
41
- ```tsx
42
- const view = createDataHooks(client).defineDataView({
43
- dataContext,
44
- operation: 'customers',
16
+ const sampleCountsView = defineDataView({
17
+ dataContext: sampleDataContext,
18
+ operation: 'sampleCountsByGroup',
45
19
  variables: {
46
- search: searchVariable({ key: 'q', label: 'Search customers' }),
20
+ groupName: searchVariable({
21
+ key: 'group',
22
+ label: 'Group',
23
+ defaultValue: '',
24
+ }),
47
25
  },
48
- input: ({ search }) => ({ q: search }),
49
- describeInput: ({ q }) => (q ? `Customers matching ${q}` : 'All customers'),
50
- isEmpty: () => false,
51
- emptyFallback: { title: 'No customers' },
26
+ describeInput: ({ groupName }) =>
27
+ groupName ? `group ${groupName}` : 'all groups',
28
+ isEmpty: rows => rows.length === 0,
29
+ emptyFallback: { title: 'No matching groups' },
52
30
  });
53
- const customers = view.dataset({
54
- name: 'Customers',
55
- select: data => data.rows,
56
- rowKey: row => row.id,
57
- columns: { name: { value: row => row.name } },
58
- evidence: { id: 'customers', queryNames: ['customers'] },
59
- suggestions: {
60
- title: row => row.name,
61
- description: row => row.country,
62
- },
63
- });
64
- const content = view.content(source => (
65
- <TableWidget dataset={customers} source={source} />
66
- ));
67
-
68
- <DataApp view={view} datasets={[customers]} story={story}>
69
- <DataSection content={content} />
70
- </DataApp>;
71
31
  ```
72
32
 
73
- The first `searchVariable()` in declaration order is the primary search: it owns
74
- autocomplete and combines supplied datasets that declare suggestions. Typing
75
- updates the page and suggestions from the same displayed result. Capped or
76
- paginated sources offer suggestions only for supplied rows. Title matches rank
77
- ahead of description matches; the five suggestion slots are shared across datasets. Selection completes the query with
78
- the title; `suggestions.onSelect: row => openCustomer(row.id)` overrides completion
79
- with an app action. `showSearchSuggestions` defaults to true; set it to false to
80
- suppress autocomplete for a particular app.
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.
81
36
 
82
- ### Organize controls by intent
83
-
84
- Declare controls in priority order for the user's task. Keep useful scope filters
85
- visible and set `presentation.prominence: 'secondary'` for less frequent ones in
86
- the Filters sheet. Active filter summaries reopen the same Filters sheet.
87
- Choose useful defaults rather than exposing every field; declare each label once.
37
+ ## Independent filters and chart breakdowns
88
38
 
89
- Set `presentation.group: 'display'` for ordering or presentation choices. These
90
- appear separately from scope filters. Search remains separate from both.
39
+ For source-backed categorical members, use `dataApp.defineDimension()`:
91
40
 
92
41
  ```ts
93
- const active = booleanFilter({
94
- key: 'active',
95
- label: 'Active account',
96
- presentation: { prominence: 'secondary' },
97
- });
98
- const sort = choiceVariable({
99
- key: 'sort',
100
- label: 'Sort by',
101
- options: [{ id: 'name', label: 'Customer name' }],
102
- defaultValue: 'name',
103
- presentation: { group: 'display' },
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' },
104
49
  });
50
+ const parseInput = variableInput(parseEmptyInput, { group });
105
51
  ```
106
52
 
107
- The [date range contract](contract.md#shared-date-ranges) owns source coverage,
108
- maximum range, time zone, and comparison rules. `defineTimeView()` is the compact
109
- path for a view whose primary input is a period. Use `defineDataView()` for fixed
110
- snapshots or other input shapes.
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.
111
56
 
112
- ```ts
113
- const activity = defineTimeView({
114
- dataContext,
115
- operation: 'activity',
116
- time: { contract: calendar, defaultValue: { kind: 'preset', id: 'last-7' } },
117
- variables: { region: searchVariable({ key: 'region' }) },
118
- input: values => ({
119
- filters: { period: values.period, region: values.region },
120
- }),
121
- bindings: {
122
- period: input => input.filters.period,
123
- region: input => input.filters.region,
124
- },
125
- isEmpty: data => data.rows.length === 0,
126
- emptyFallback: { title: 'No activity' },
127
- });
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
128
67
  ```
129
68
 
130
- The operation, calendar, and row shape are app-owned. Bindings must extract
131
- selected values unchanged.
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
132
76
 
133
- ## URL state and custom controls
77
+ Use `choiceVariable()` for a display choice, separately from population filters:
134
78
 
135
- Relative date presets remain relative. Explicit dates use `start`, `end`, and
136
- `compare` for the `period` variable; other date variables derive these keys from
137
- their own key. Invalid URL values fall back to validated defaults. Do not use
138
- reserved inspection, presentation, or navigation keys for app variables.
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
+ ```
139
91
 
140
- Choose push history for meaningful selections and replace history for typing.
141
- Back/Forward restores the same values and controls. Use generated controls for
142
- standard data apps. Direct pickers and standalone URL state belong to
143
- [direct UI composition](ui.md).
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.
144
95
 
145
96
  ## Fixed options and query-backed facets
146
97
 
147
- Declare fixed choices with `dimensionFilter()` from `/contract`:
98
+ Use `dimensionFilter()` from `/contract` when options are known constants:
148
99
 
149
100
  ```ts
150
- const region = dimensionFilter({
151
- key: 'region',
152
- label: 'Region',
101
+ const group = dimensionFilter({
102
+ key: 'group',
103
+ label: 'Group',
153
104
  valueType: 'string',
154
105
  selectionMode: 'multiple',
155
- options: [{ value: 'Europe', label: 'Europe' }],
106
+ options: [
107
+ { value: 'Alpha', label: 'Alpha' },
108
+ { value: 'Beta', label: 'Beta' },
109
+ ],
156
110
  });
157
111
  ```
158
112
 
159
- For query-backed choices use the hooks factory's `defineFacetFilter()`. The
160
- facet operation returns parsed dimension options. Its input mapper uses current
161
- resolved variables, including other filters:
113
+ Use `defineFacetFilter()` only when options must depend on other selections:
162
114
 
163
115
  ```ts
116
+ // ... client and period variable
164
117
  const { defineFacetFilter } = createDataHooks(client);
165
- const period = dateRangeVariable({
166
- key: 'period',
167
- contract: calendar,
168
- defaultValue: { kind: 'preset', id: 'last-7' },
169
- });
170
- const region = defineFacetFilter({
171
- key: 'region',
172
- label: 'Region',
118
+
119
+ const group = defineFacetFilter({
120
+ key: 'group',
121
+ label: 'Group',
173
122
  valueType: 'string',
174
123
  selectionMode: 'multiple',
175
124
  facet: {
176
125
  context: { period },
177
- operation: 'regions',
126
+ operation: 'groups',
178
127
  input: values => ({ period: values.period }),
179
128
  },
180
129
  });
181
130
  ```
182
131
 
183
- Declare mapper dependencies in `facet.context` (`{}` for none), and include them
184
- alongside the facet in the view's `variables`. Mapper inputs and option values are
185
- inferred from the variables and operation; options must match `valueType`.
186
- For the operation's input parser, use `parseDimensionSelection(value, region)` from `/contract`.
187
- A dimension without an explicit selection represents all members.
188
- Map parsed selections to the query's declared parameters; do not construct SQL
189
- from filter values. Choose selection modes supported by the registered query.
132
+ Declare `period` with `dateRangeVariable()`, 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`.
190
135
 
191
- Choose `selectionMode: 'single'` when one value replaces another and
192
- `selectionMode: 'multiple'` for independent values. `All` is an explicit choice for a single-value
193
- filter and the meaning of an empty selection for a multiple-value filter.
194
- Single-value filters always have a selection limit of one.
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.
195
140
 
196
- ## Fixed choices
141
+ ## Reporting periods
197
142
 
198
- `choiceVariable()` requires labeled `options` and a valid `defaultValue`.
199
- `multiChoiceVariable()` stores unique option IDs with an optional selection limit.
200
- Fixed-choice declarations need at least one option. Inline options or `as const`
201
- preserve their IDs so TypeScript checks defaults against them. An empty selected
202
- collection means no choices; categorical filters use `dimensionFilter()` when
203
- an empty selection should mean all records.
143
+ Use `defineTimeView()` when the analysis is period-driven. Obtain it from the
144
+ existing hooks factory and share a `defineDateRangeContract()` with the parser.
145
+ After adapting the operation to accept `{ period, groupName }`, the view can stay
146
+ flat:
204
147
 
205
148
  ```ts
206
- const variables = {
207
- search: searchVariable({ key: 'q', label: 'Search' }),
208
- metric: choiceVariable({
209
- key: 'metric',
210
- label: 'Metric',
211
- defaultValue: 'orders',
212
- options: [
213
- { id: 'orders', label: 'Orders' },
214
- { id: 'revenue', label: 'Revenue' },
215
- ],
216
- }),
217
- };
218
- ```
219
-
220
- ## Numeric and boolean predicates
149
+ // ... client, dailyCountsContext, and calendar contract
150
+ const { defineTimeView } = createDataHooks(client);
221
151
 
222
- Import `numberFilter()` and `booleanFilter()` from `/contract` and put their
223
- results in the view's `variables`. Both have an explicit `{ kind: 'all' }`
224
- unrestricted state. Numeric filters support inclusive, open-ended ranges and
225
- comparisons: `eq`, `ne`, `gt`, `gte`, `lt`, and `lte`. Boolean filters distinguish
226
- Any from `{ kind: 'is', value: true }` and `{ kind: 'is', value: false }`.
227
-
228
- ```ts
229
- const amount = numberFilter({ key: 'amount', label: 'Amount', min: 0 });
230
- const active = booleanFilter({ key: 'active', label: 'Active' });
152
+ const dailyCountsView = defineTimeView({
153
+ dataContext: dailyCountsContext,
154
+ operation: 'dailyCountsByGroup',
155
+ time: { contract: calendar, defaultValue: { kind: 'preset', id: 'last-7' } },
156
+ variables: {
157
+ groupName: searchVariable({
158
+ key: 'group',
159
+ label: 'Group',
160
+ defaultValue: '',
161
+ }),
162
+ },
163
+ isEmpty: rows => rows.length === 0,
164
+ emptyFallback: { title: 'No matching groups' },
165
+ });
231
166
  ```
232
167
 
233
- Use `parseNumberSelection()` and `parseBooleanSelection()` in the operation's
234
- input parser with the same filter declarations. Numeric predicates generate `<NumberFilterPicker>` panels. Draft edits reach
235
- operation input only after Apply; Cancel and dismissal preserve the applied
236
- value. Invalid ranges disable Apply.
237
- Input mappings and bindings must preserve these predicates unchanged, as with
238
- categorical filters. Map parsed operators and values to declared query parameters;
239
- offer only operators supported by the registered query.
240
-
241
- ## Exclusion, clear, and reset
242
-
243
- Set `allowExclusion: true` on `dimensionFilter()` to support
244
- `{ kind: 'exclude', members }`. `<DimensionPicker>` then exposes Include/Exclude
245
- alongside selected members. Enable exclusion only when the registered query supports
246
- it, including the intended behavior for missing values.
168
+ The operation's parser validates `period` with `calendar.parseRequest()`.
169
+ Without additional variables, the default input is the calendar request itself.
170
+ Use `defineDataView()` for fixed snapshots or analysis without a reporting period.
247
171
 
248
- Clear removes predicate filters while preserving search and display settings.
249
- Clear search separately in its field.
250
- `resetAll()` restores all
251
- configured variable defaults, including fixed choices and periods. Nonempty
252
- default filters can therefore be active immediately after Reset.
172
+ ## Numeric and boolean predicates
253
173
 
254
- Direct `useAppVariables()` callers can use `clearAll()` and `resetAll()`. `<FilterActions>` also supports app-owned draft state
255
- with paired Apply/Cancel handlers; derive queries and visible controls from applied
256
- values while a draft is being edited.
174
+ Use `numberFilter()` or `booleanFilter()` from `/contract` for field predicates.
175
+ Declare them in `variables` and validate input with `parseNumberSelection()` or
176
+ `parseBooleanSelection()` using the same declarations. Both support
177
+ `{ kind: 'all' }`. Offer only predicates the registered query supports.
257
178
 
258
- Filters apply immediately; use app-owned drafts only when the task needs Apply/Cancel.
179
+ ## Exclusion, clear, and reset
259
180
 
260
- ## Independent filters and chart breakdowns
181
+ Clear removes scope predicates and returns dates to defaults, preserving search
182
+ and display choices. `resetAll()` restores all defaults. Filters apply immediately;
183
+ use app-owned drafts only when the task needs Apply/Cancel.
261
184
 
262
- Each dimension owns its selection. Readers can select Germany without selecting
263
- a region; changing or clearing Region preserves Country and Customer. Filters
264
- combine in the operation's query. Incompatible selections can return an empty
265
- result; keep the selections visible so readers can correct them.
185
+ ## Adapt existing input shapes
266
186
 
267
- Use `dimensionFilter()` for static options or `app.defineDimension()` for query-backed
268
- options. `variableInput()` from `/contract` validates named variables alongside an
269
- app-owned base parser. Use it on every operation consuming these filters, including
270
- details. Declare the same variables on the view and preserve them in operation input.
187
+ Add a mapper and bindings only when an existing operation requires nested or
188
+ differently named inputs. Preserve selected values unchanged in both directions:
271
189
 
272
190
  ```ts
273
- const country = app.defineDimension({
274
- key: 'country',
275
- label: 'Country',
276
- valueType: 'string',
277
- selectionMode: 'single',
278
- presentation: { prominence: 'secondary' },
279
- source: { query: 'countries' },
280
- });
281
- const revenueBy = choiceVariable({
282
- key: 'revenue-by',
283
- label: 'Revenue breakdown',
284
- defaultValue: 'region',
285
- options: [
286
- { id: 'region', label: 'Region' },
287
- { id: 'country', label: 'Country' },
288
- ],
289
- presentation: { group: 'display', control: 'widget' },
290
- });
291
- const parseInput = variableInput(parsePeriodInput, { country, revenueBy });
292
- ```
191
+ // ... client; operation input is { filters: { period, groupName } }
192
+ const { defineTimeView } = createDataHooks(client);
293
193
 
294
- A breakdown is an ordinary display choice, independent of population filters.
295
- `<VisualizationWidget breakdown={view.breakdown('revenueBy')}>` renders that
296
- choice in its header. `presentation.control: 'widget'` omits it from the toolbar.
297
- Scope filters still appear in the Filters sheet, active summaries, and Clear filters.
298
- Primary controls stay in the toolbar. Active non-primary filters appear beside them
299
- as editable controls. Once the toolbar scrolls above the viewport,
300
- a floating summary shows every active filter and opens the Filters sheet.
301
- Declare each chart's choice separately when readers should control them independently.
302
-
303
- Each source query declares a nullable `member` parameter matching `valueType` and
304
- nonnullable projections for `value` (the same type), `label` (string), and optional
305
- `count` (number). `member = null` requests at most 200 options; a selected value requests
306
- an exact lookup. Other query parameters need defaults or trusted server values.
307
- Keep SQL and parameter declarations literal in `defineDataApp()`.
308
-
309
- ```sql
310
- SELECT code AS value, name AS label
311
- FROM countries
312
- WHERE ($member IS NULL OR code = $member)
313
- ORDER BY name
194
+ const dailyCountsView = defineTimeView({
195
+ // ... operation, dataContext, time, variables, isEmpty, and emptyFallback
196
+ input: values => ({
197
+ filters: { period: values.period, groupName: values.groupName },
198
+ }),
199
+ bindings: {
200
+ period: input => input.filters.period,
201
+ groupName: input => input.filters.groupName,
202
+ },
203
+ });
314
204
  ```
315
205
 
316
- Exact selected-member lookups run before business queries, sharing authorization,
317
- cancellation, execution limits, and query evidence. Labels resolve separately from
318
- the options page, including when it fails. Picker search searches supplied options;
319
- it does not fetch additional members. Clear filters preserves search and display
320
- choices and returns dates to their configured defaults.
206
+ Custom control ownership is needed only when generated controls cannot express
207
+ the requirement; use `/ui` for that case. Do not reuse reserved inspection,
208
+ presentation, or navigation URL keys.