@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/filters.md
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# Filters and display options
|
|
2
|
+
|
|
3
|
+
Declare each filter once as a constant and list it in `filters` on every
|
|
4
|
+
operation that reads it. Everything else derives from that list: input
|
|
5
|
+
validation, checks, the view's period and scope, and the controls `<DataApp>`
|
|
6
|
+
renders. Import filters from `@altertable/data-app/contract`.
|
|
7
|
+
|
|
8
|
+
## Declare filters on operations
|
|
9
|
+
|
|
10
|
+
The hosted starter's operations both read one group search:
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import { parseCount, searchFilter } from '@altertable/data-app/contract';
|
|
14
|
+
|
|
15
|
+
// ... dataApp, sampleDataContext, and section contents
|
|
16
|
+
const groupName = searchFilter({ key: 'group', label: 'Group' });
|
|
17
|
+
|
|
18
|
+
const operations = {
|
|
19
|
+
sampleCountsByGroup: dataApp.defineOperation({
|
|
20
|
+
filters: { groupName },
|
|
21
|
+
policy: { maxQueryRows: 10, maxDurationMs: 15000 },
|
|
22
|
+
async run({ query }, { groupName }) {
|
|
23
|
+
const result = await query('sampleCountsByGroup', { groupName });
|
|
24
|
+
return result.rows.map(row => ({
|
|
25
|
+
groupName: row.group_name,
|
|
26
|
+
sampleCount: parseCount(row.sample_count),
|
|
27
|
+
}));
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
// ... sampleTotal reads the same { groupName }
|
|
31
|
+
};
|
|
32
|
+
const { defineView } = createDataHooks(createDataClient({ operations }));
|
|
33
|
+
const sampleCountsView = defineView({
|
|
34
|
+
dataContext: sampleDataContext,
|
|
35
|
+
operation: 'sampleCountsByGroup',
|
|
36
|
+
isEmpty: rows => rows.length === 0,
|
|
37
|
+
emptyFallback: { title: 'No matching groups' },
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function App() {
|
|
41
|
+
return (
|
|
42
|
+
<DataApp view={sampleCountsView}>
|
|
43
|
+
<DataSection content={countsContent} />
|
|
44
|
+
</DataApp>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- Reuse the same constant on every operation that reads it; two filters with one
|
|
50
|
+
name, or one URL key, fail.
|
|
51
|
+
- Omit `filters` for an operation without inputs.
|
|
52
|
+
- A detail operation that also needs its own fields, such as a record ID, keeps
|
|
53
|
+
`filters` for the scope and adds `input` and `checks` for those fields only.
|
|
54
|
+
- The view's scope reads like “Mar 1–7, 2026 UTC · group Alpha” or “all data”.
|
|
55
|
+
Pass `describeInput` only for different copy.
|
|
56
|
+
- Use `searchFilter()` to query the server; use a table's `search` prop to filter
|
|
57
|
+
rows already loaded.
|
|
58
|
+
|
|
59
|
+
## Read filter values
|
|
60
|
+
|
|
61
|
+
`run(context, input)` receives one field per declared filter:
|
|
62
|
+
|
|
63
|
+
| Filter | Input value |
|
|
64
|
+
| ------------------------------------------------------ | ---------------------------------------------- |
|
|
65
|
+
| `searchFilter()` | `string`, at most `maxLength` (200 by default) |
|
|
66
|
+
| `choiceFilter()`, `displayChoice()` | Selected option ID |
|
|
67
|
+
| `multiChoiceFilter()` | Selected option IDs |
|
|
68
|
+
| `dimensionFilter()`, `facetFilter()`, source dimension | `DimensionSelection` |
|
|
69
|
+
| `numberFilter()`, `booleanFilter()` | `NumberSelection`, `BooleanSelection` |
|
|
70
|
+
| `dateTimeRangeFilter()` | `{ range, comparison }` of resolved dates |
|
|
71
|
+
|
|
72
|
+
Pass values to declared query parameters; never interpolate them into SQL. Date
|
|
73
|
+
ranges bind as [`dateTimeRange` parameters](contract.md#bind-date-ranges). A
|
|
74
|
+
dimension selection binds whole to a `{ type: 'dimension', valueType }`
|
|
75
|
+
parameter; `$country.matches(column)` keeps the selected rows, including
|
|
76
|
+
multiple members, missing values, and exclusion:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
// ... in defineDataApp({ queries })
|
|
80
|
+
revenueByCampaign: {
|
|
81
|
+
statement: `SELECT o.campaign, sum(o.amount) AS revenue
|
|
82
|
+
FROM demo.orders o JOIN demo.customers c ON c.id = o.customer_id
|
|
83
|
+
WHERE $country.matches(c.country)
|
|
84
|
+
GROUP BY o.campaign`,
|
|
85
|
+
params: { country: { type: 'dimension', valueType: 'string' } },
|
|
86
|
+
projections: { campaign: { type: 'string' }, revenue: { type: 'number' } },
|
|
87
|
+
},
|
|
88
|
+
// ... in the operation: query('revenueByCampaign', { country: input.country })
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Dimension, number, and boolean selections support `{ kind: 'all' }`. Offer only
|
|
92
|
+
predicates the registered query supports.
|
|
93
|
+
|
|
94
|
+
## Categorical dimensions
|
|
95
|
+
|
|
96
|
+
For source-backed members, use `dataApp.defineDimension()`:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
// ... dataApp with its registered groups query
|
|
100
|
+
const group = dataApp.defineDimension({
|
|
101
|
+
key: 'group',
|
|
102
|
+
label: 'Group',
|
|
103
|
+
valueType: 'string',
|
|
104
|
+
selectionMode: 'multiple',
|
|
105
|
+
source: { query: 'groups' },
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Declare the source query in `defineDataApp()` with a nullable `member` parameter
|
|
110
|
+
matching `valueType`. Its nonnullable projections are `value` (same type),
|
|
111
|
+
`label` (string), and optional `count` (number). Null requests options; a selected
|
|
112
|
+
member requests exact lookup. Other parameters need defaults or trusted values:
|
|
113
|
+
|
|
114
|
+
```sql
|
|
115
|
+
SELECT DISTINCT group_name AS value, group_name AS label
|
|
116
|
+
FROM sample_counts
|
|
117
|
+
WHERE ($member IS NULL OR group_name = $member)
|
|
118
|
+
ORDER BY label
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Operations reading `group` check selected members against this query before
|
|
122
|
+
`run()`. Use `dimensionFilter()` when options are known constants:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const group = dimensionFilter({
|
|
126
|
+
key: 'group',
|
|
127
|
+
label: 'Group',
|
|
128
|
+
valueType: 'string',
|
|
129
|
+
selectionMode: 'multiple',
|
|
130
|
+
options: [
|
|
131
|
+
{ value: 'Alpha', label: 'Alpha' },
|
|
132
|
+
{ value: 'Beta', label: 'Beta' },
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Set `defaultValue` to start from a narrower selection, such as
|
|
138
|
+
`{ kind: 'include', members: [{ kind: 'value', value: 'paid' }] }`; clearing
|
|
139
|
+
filters still returns to every member.
|
|
140
|
+
|
|
141
|
+
No selection means every member. Enable `allowExclusion` and `allowMissing` only
|
|
142
|
+
when the query handles them. Use `multiChoiceFilter()` for fixed multiselect
|
|
143
|
+
choices; empty means no choices, unlike an unrestricted dimension.
|
|
144
|
+
|
|
145
|
+
## Facet filters
|
|
146
|
+
|
|
147
|
+
Use `facetFilter()` only when options must follow other selections:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
// ... period filter
|
|
151
|
+
const group = facetFilter({
|
|
152
|
+
key: 'group',
|
|
153
|
+
label: 'Group',
|
|
154
|
+
valueType: 'string',
|
|
155
|
+
selectionMode: 'multiple',
|
|
156
|
+
options: 'groupOptions',
|
|
157
|
+
});
|
|
158
|
+
const operations = {
|
|
159
|
+
groupOptions: dataApp.defineOperation({
|
|
160
|
+
filters: { period },
|
|
161
|
+
// ... policy, and run() returning DimensionOption[] for the period
|
|
162
|
+
}),
|
|
163
|
+
groupCounts: dataApp.defineOperation({
|
|
164
|
+
filters: { period, group },
|
|
165
|
+
// ... policy and run()
|
|
166
|
+
}),
|
|
167
|
+
};
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
- `options` names a registered operation. Its filters decide what narrows the
|
|
171
|
+
options: here, changing `period` reloads them.
|
|
172
|
+
- Return `{ value, label, count? }[]` from `run()`, at most 200 values. The picker
|
|
173
|
+
shows `count` beside each option.
|
|
174
|
+
- The server checks a facet selection's shape, not its members; use a source
|
|
175
|
+
dimension when unknown members must be rejected.
|
|
176
|
+
|
|
177
|
+
## Display choices and breakdowns
|
|
178
|
+
|
|
179
|
+
Use `displayChoice()` for a choice that changes how results are shown rather
|
|
180
|
+
than which data is included. List it on the operation, which receives the
|
|
181
|
+
selected ID and groups its results accordingly:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
const countsBy = displayChoice({
|
|
185
|
+
key: 'counts-by',
|
|
186
|
+
label: 'Counts breakdown',
|
|
187
|
+
defaultValue: 'group',
|
|
188
|
+
options: [
|
|
189
|
+
{ id: 'group', label: 'Group' },
|
|
190
|
+
{ id: 'country', label: 'Country' },
|
|
191
|
+
],
|
|
192
|
+
presentation: { control: 'widget' },
|
|
193
|
+
});
|
|
194
|
+
// ... sampleCountsByGroup declares filters: { groupName, countsBy }
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Pass `view.breakdown('countsBy')` to `<VisualizationWidget breakdown>`. Without
|
|
198
|
+
`control: 'widget'`, the choice renders in the toolbar's display options. Use one
|
|
199
|
+
choice per independently controlled chart. Use
|
|
200
|
+
`presentation.prominence: 'secondary'` for less frequent filters.
|
|
201
|
+
|
|
202
|
+
## Date ranges
|
|
203
|
+
|
|
204
|
+
Use one `dateTimeRangeFilter()` per operation. It sets the view's reporting
|
|
205
|
+
period, time zone, and metric comparisons:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import {
|
|
209
|
+
dateTimeRangeFilter,
|
|
210
|
+
dateTimeRangePresets,
|
|
211
|
+
} from '@altertable/data-app/contract';
|
|
212
|
+
|
|
213
|
+
const period = dateTimeRangeFilter({
|
|
214
|
+
key: 'period',
|
|
215
|
+
defaultValue: '30d',
|
|
216
|
+
maxRangeDays: 90,
|
|
217
|
+
comparison: 'off',
|
|
218
|
+
presets: dateTimeRangePresets.analytics,
|
|
219
|
+
});
|
|
220
|
+
const dailyCounts = dataApp.defineOperation({
|
|
221
|
+
filters: { period, groupName },
|
|
222
|
+
policy: { maxQueryRows: 100, maxDurationMs: 15000 },
|
|
223
|
+
async run({ query }, { period, groupName }) {
|
|
224
|
+
const current = await query('dailyCounts', {
|
|
225
|
+
period: period.range,
|
|
226
|
+
groupName,
|
|
227
|
+
});
|
|
228
|
+
// ... query { period: period.comparison } when it is not null
|
|
229
|
+
return current.rows;
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
- `run()` receives `{ range, comparison }` with resolved dates. Ranges include
|
|
235
|
+
`from` and exclude `to`: September 24–30 queries `2026-09-24T00:00:00Z`
|
|
236
|
+
through `2026-10-01T00:00:00Z`. Bind them to a
|
|
237
|
+
[`dateTimeRange` parameter](contract.md#bind-date-ranges).
|
|
238
|
+
- A range that runs past now ends at now: today picked in the calendar queries
|
|
239
|
+
midnight through the current time.
|
|
240
|
+
- `comparison: 'off'` or `'on'` offers the previous-period toggle, starting in
|
|
241
|
+
that state. `period.comparison` is the same window one selected length
|
|
242
|
+
earlier, such as yesterday through the same time, while the toggle is on, and
|
|
243
|
+
`null` otherwise. Omit `comparison` for no toggle.
|
|
244
|
+
- `defaultValue` and preset `range` take range text such as `'24h'`, `'7d'`, or
|
|
245
|
+
`'6mo'`, or `{ from, to }`. `dateTimeRangePresets.analytics` covers days to a
|
|
246
|
+
year; `dateTimeRangePresets.monitoring` covers minutes to 24 hours.
|
|
247
|
+
- Relative ranges such as `'7d'` resolve in `timeZone`, UTC by default.
|
|
248
|
+
- `minDate`, `maxDate`, and `maxRangeDays` limit what readers can pick.
|
|
249
|
+
Coverage runs through now; set `completeDays: true` to end it yesterday when
|
|
250
|
+
the source loads whole days.
|
|
251
|
+
|
|
252
|
+
## Exclusion, clear, and reset
|
|
253
|
+
|
|
254
|
+
Clear removes filter predicates and returns dates to defaults, preserving search
|
|
255
|
+
and display choices. `resetAll()` restores all defaults. Filters apply immediately;
|
|
256
|
+
use app-owned drafts only when the task needs Apply/Cancel.
|
|
257
|
+
|
|
258
|
+
Custom control ownership is needed only when generated controls cannot express
|
|
259
|
+
the requirement; use `/ui` for that case. Do not reuse reserved inspection,
|
|
260
|
+
presentation, or navigation URL keys.
|
|
261
|
+
|
|
262
|
+
## Share filters with HTTP and local apps
|
|
263
|
+
|
|
264
|
+
HTTP and local apps keep operations on the server, so the browser imports them
|
|
265
|
+
as types only. Declare filters in a browser-safe module that both sides import:
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
// src/filters.ts
|
|
269
|
+
import { choiceFilter } from '@altertable/data-app/contract';
|
|
270
|
+
|
|
271
|
+
const groupName = choiceFilter({
|
|
272
|
+
// ... key, label, defaultValue, and options
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
export const operationFilters = {
|
|
276
|
+
sampleCountsByGroup: { groupName },
|
|
277
|
+
sampleCountsBySegment: { groupName },
|
|
278
|
+
};
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Each operation in `src/operations.ts` declares
|
|
282
|
+
`filters: operationFilters.sampleCountsByGroup`, and the browser client receives
|
|
283
|
+
the same map:
|
|
284
|
+
|
|
285
|
+
```ts
|
|
286
|
+
// src/App.tsx
|
|
287
|
+
import { operationFilters } from '#app/filters.ts';
|
|
288
|
+
import type { operations } from '#app/operations.ts';
|
|
289
|
+
|
|
290
|
+
const { defineView } = createDataHooks(
|
|
291
|
+
createDataClient<typeof operations>({ filters: operationFilters })
|
|
292
|
+
);
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
The client's types require `filters` whenever an operation declares them.
|
package/docs/hosted-apps.md
CHANGED
|
@@ -14,7 +14,7 @@ interpolation), finite signed numbers, booleans, and null. Parentheses, `as`, an
|
|
|
14
14
|
`satisfies` are allowed. Keep executable composition outside the call; omit spreads,
|
|
15
15
|
computed keys, references, and callbacks. Static apps use `queries: {}`.
|
|
16
16
|
|
|
17
|
-
Replace sample queries and
|
|
17
|
+
Replace sample queries, operations, and datasets with inspected source data. Supply `scope`
|
|
18
18
|
in `defineDataApp()`. When using bound `<DataApp>`, follow its current
|
|
19
19
|
[story and dataset requirements](stories-and-export.md).
|
|
20
20
|
|
|
@@ -23,11 +23,12 @@ the transport; no bootstrap or message routes are needed in app code.
|
|
|
23
23
|
|
|
24
24
|
## Convert a local data app
|
|
25
25
|
|
|
26
|
-
1. Combine the app's operations
|
|
26
|
+
1. Combine the app's filters, operations, data context, views, any presentation
|
|
27
27
|
and export features, app declaration, and browser entry into one `index.tsx`, following the
|
|
28
28
|
[single-file starter](app-authoring.md#use-release-matched-starters).
|
|
29
29
|
2. Replace the HTTP client with `createDataClient({ operations })`, using the
|
|
30
|
-
operation registry as a value
|
|
30
|
+
operation registry as a value; it supplies the operations' filters, so drop
|
|
31
|
+
the `filters` option. See [browser-owned operations](client.md#browser-owned-operations-for-bundle-apps)
|
|
31
32
|
for execution through the host.
|
|
32
33
|
3. Remove the Bun server, HTML, server adapters, credentials, and relative or
|
|
33
34
|
app-alias imports. Rewrite any operation that depends on server-only code
|
package/docs/layout.md
CHANGED
|
@@ -2,26 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
Use `<Stack>` for reading order, `<Grid>` for peer widgets, and `<GridItem>` for
|
|
4
4
|
spans. The shell owns page width and gutters; parents own spacing and widgets
|
|
5
|
-
own internal padding.
|
|
5
|
+
own internal padding. Lay out sections the same way as widgets; static headings
|
|
6
|
+
and prose stay outside their loading boundaries. Keep default density unless
|
|
7
|
+
customization is requested.
|
|
6
8
|
|
|
7
9
|
```tsx
|
|
8
|
-
// ... sampleCountsView,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
// ... sampleCountsView, countsContent, and totalContent
|
|
11
|
+
function App() {
|
|
12
|
+
return (
|
|
13
|
+
<DataApp view={sampleCountsView}>
|
|
14
|
+
<Stack>
|
|
15
|
+
<SectionHeading>Sample counts</SectionHeading>
|
|
16
|
+
<TextContent>
|
|
17
|
+
<p>Explore the sources behind this finding.</p>
|
|
18
|
+
</TextContent>
|
|
19
|
+
<Grid columns={3}>
|
|
20
|
+
<GridItem span={2}>
|
|
21
|
+
<DataSection content={countsContent} />
|
|
22
|
+
</GridItem>
|
|
23
|
+
<GridItem>
|
|
24
|
+
<DataSection content={totalContent} />
|
|
25
|
+
</GridItem>
|
|
26
|
+
</Grid>
|
|
27
|
+
</Stack>
|
|
28
|
+
</DataApp>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
25
31
|
```
|
|
26
32
|
|
|
27
33
|
Grids wrap to fit their container and spans collapse when needed. Set widget
|
|
@@ -16,42 +16,51 @@ explanatory prose in the app body.
|
|
|
16
16
|
|
|
17
17
|
Continue the starter's `totalSamples` binding. Return one to four findings with a
|
|
18
18
|
headline, visual, and registered dataset or
|
|
19
|
-
metric as `evidence`.
|
|
19
|
+
metric as `evidence`. The story receives `view`'s displayed snapshot, then one
|
|
20
|
+
snapshot per entry in `summaryViews`. Reuse each binding with its own view's
|
|
21
|
+
snapshot and derive scope from it:
|
|
20
22
|
|
|
21
23
|
```tsx
|
|
22
|
-
// ... sampleCountsView, sampleCounts, totalSamples, and
|
|
24
|
+
// ... sampleCountsView, sampleTotalView, sampleCounts, totalSamples, and contents
|
|
23
25
|
function App() {
|
|
24
26
|
return (
|
|
25
27
|
<DataApp
|
|
26
28
|
view={sampleCountsView}
|
|
29
|
+
summaryViews={[sampleTotalView]}
|
|
27
30
|
datasets={[sampleCounts]}
|
|
28
|
-
story={
|
|
29
|
-
const total = totalSamples.read(
|
|
31
|
+
story={(countsSnapshot, totalSnapshot) => {
|
|
32
|
+
const total = totalSamples.read(totalSnapshot);
|
|
30
33
|
return [
|
|
31
34
|
{
|
|
32
35
|
id: 'total-samples',
|
|
33
36
|
headline: `Total samples: ${formatMetric(total.value.current, totalSamples.definition.format)}`,
|
|
34
|
-
context: sampleCountsView.scope(
|
|
35
|
-
visual:
|
|
37
|
+
context: sampleCountsView.scope(countsSnapshot),
|
|
38
|
+
visual: (
|
|
39
|
+
<MetricWidget metric={totalSamples} source={totalSnapshot} />
|
|
40
|
+
),
|
|
36
41
|
evidence: totalSamples,
|
|
37
42
|
},
|
|
38
43
|
];
|
|
39
44
|
}}
|
|
40
45
|
>
|
|
41
|
-
<DataSection content={
|
|
46
|
+
<DataSection content={totalContent} />
|
|
47
|
+
<DataSection content={countsContent} />
|
|
42
48
|
</DataApp>
|
|
43
49
|
);
|
|
44
50
|
}
|
|
45
51
|
```
|
|
46
52
|
|
|
53
|
+
List a view in `summaryViews` only when the story or export reads it: summary
|
|
54
|
+
views load with the page instead of when their sections near the viewport.
|
|
55
|
+
|
|
47
56
|
Keep the starter's `formatMetric()` import for formatted headlines.
|
|
48
57
|
|
|
49
58
|
## Export displayed data as CSV
|
|
50
59
|
|
|
51
60
|
Declare [datasets](widgets.md#declare-datasets-and-metrics) once and pass
|
|
52
|
-
`datasets={[sampleCounts]}`.
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
`datasets={[sampleCounts]}`. List datasets from `view` or a summary view; each
|
|
62
|
+
exports its bound rows and columns. Preserve the displayed grain; reuse a dataset
|
|
63
|
+
for visuals sharing the same rows.
|
|
55
64
|
|
|
56
65
|
One dataset downloads as CSV; multiple datasets offer individual downloads and
|
|
57
66
|
**Export all** as ZIP. Filenames use the displayed scope. Accessors must return
|
package/docs/ui.md
CHANGED
|
@@ -10,7 +10,7 @@ frame for deliberately custom content. Use `<GettingStarted>` for
|
|
|
10
10
|
connection setup. Fetched data belongs to a declared view; avoid inventing
|
|
11
11
|
request states to populate a shell.
|
|
12
12
|
|
|
13
|
-
Custom controls own values and change handlers; use `
|
|
13
|
+
Custom controls own values and change handlers; use `useAppFilters()` for
|
|
14
14
|
custom URL state. Use `<DataTable>` for custom tables and `<Tabs>`, `<Sheet>`,
|
|
15
15
|
and `<HelpPopover>` for navigation and overlays.
|
|
16
16
|
|
|
@@ -283,8 +283,8 @@ function FilterChoices() {
|
|
|
283
283
|
|
|
284
284
|
A standalone `<Checkbox>` uses `checked` and `onChange`; group items use `value`.
|
|
285
285
|
|
|
286
|
-
Use `<FilterBar>` to arrange predicates and `<
|
|
287
|
-
|
|
286
|
+
Use `<FilterBar>` to arrange predicates and `<ControlBar>` for a row of mixed
|
|
287
|
+
search, filter, and display controls. Use `<FilterActions>` for Clear or paired Apply/Cancel actions on
|
|
288
288
|
app-owned drafts; provide the handlers for your applied state.
|
|
289
289
|
|
|
290
290
|
Use `<NumberFilterPicker>` for a numeric predicate popover or numeric fields
|
|
@@ -296,7 +296,8 @@ Use `<Button variant="inline">` for actions within text or table cells. Use butt
|
|
|
296
296
|
|
|
297
297
|
## Datetime selection
|
|
298
298
|
|
|
299
|
-
Prefer a [datetime
|
|
299
|
+
Prefer a [datetime filter](filters.md#date-ranges)
|
|
300
300
|
for generated controls and URL state. For custom screens, `<DateTimeRangePicker>`
|
|
301
301
|
accepts the same `DateTimeRange` and preset sets, with calendar and natural-language
|
|
302
|
-
entry.
|
|
302
|
+
entry. Pass `policy={period.policy}` to apply a date filter's coverage and time
|
|
303
|
+
zone. See its props in [REFERENCE.md](../REFERENCE.md).
|
package/docs/views.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Views and displayed results
|
|
2
2
|
|
|
3
|
-
Keep the starter's client and hooks.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Keep the starter's client and hooks. Define one view per operation, and one
|
|
4
|
+
operation per widget. The examples continue the hosted starter's
|
|
5
|
+
`sampleCountsByGroup` operation and `sampleDataContext`.
|
|
6
6
|
|
|
7
7
|
## Bind a view
|
|
8
8
|
|
|
@@ -11,25 +11,15 @@ import {
|
|
|
11
11
|
createDataHooks,
|
|
12
12
|
DataApp,
|
|
13
13
|
DataSection,
|
|
14
|
-
searchVariable,
|
|
15
14
|
TableWidget,
|
|
16
15
|
} from '@altertable/data-app-react';
|
|
17
16
|
|
|
18
17
|
// ... client, operations, and sampleDataContext
|
|
19
|
-
const {
|
|
18
|
+
const { defineView } = createDataHooks(client);
|
|
20
19
|
|
|
21
|
-
const sampleCountsView =
|
|
20
|
+
const sampleCountsView = defineView({
|
|
22
21
|
dataContext: sampleDataContext,
|
|
23
22
|
operation: 'sampleCountsByGroup',
|
|
24
|
-
variables: {
|
|
25
|
-
groupName: searchVariable({
|
|
26
|
-
key: 'group',
|
|
27
|
-
label: 'Group',
|
|
28
|
-
defaultValue: '',
|
|
29
|
-
}),
|
|
30
|
-
},
|
|
31
|
-
describeInput: ({ groupName }) =>
|
|
32
|
-
groupName ? `group ${groupName}` : 'all groups',
|
|
33
23
|
isEmpty: rows => rows.length === 0,
|
|
34
24
|
emptyFallback: { title: 'No matching groups' },
|
|
35
25
|
});
|
|
@@ -47,10 +37,51 @@ function App() {
|
|
|
47
37
|
}
|
|
48
38
|
```
|
|
49
39
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
The view's filters, reporting period, metric comparisons, and scope come from
|
|
41
|
+
the [filters](filters.md) its operation declares. Set `describeInput` only when
|
|
42
|
+
the derived scope needs specific copy.
|
|
43
|
+
|
|
44
|
+
## Give each widget its own view
|
|
45
|
+
|
|
46
|
+
The hosted starter gives its total and its group counts separate operations and
|
|
47
|
+
views. `<DataApp view>` loads with the page; every other `<DataSection>` loads
|
|
48
|
+
when it nears the viewport. Both operations read the same `groupName` filter,
|
|
49
|
+
and `<DataApp>` renders its control once:
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
// ... client, operations, sampleDataContext, and section contents
|
|
53
|
+
const { defineView } = createDataHooks(client);
|
|
54
|
+
|
|
55
|
+
const sampleCountsView = defineView({
|
|
56
|
+
dataContext: sampleDataContext,
|
|
57
|
+
operation: 'sampleCountsByGroup',
|
|
58
|
+
isEmpty: rows => rows.length === 0,
|
|
59
|
+
emptyFallback: { title: 'No matching groups' },
|
|
60
|
+
});
|
|
61
|
+
const sampleTotalView = defineView({
|
|
62
|
+
dataContext: sampleDataContext,
|
|
63
|
+
operation: 'sampleTotal',
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
function App() {
|
|
67
|
+
return (
|
|
68
|
+
<DataApp view={sampleCountsView}>
|
|
69
|
+
<Stack>
|
|
70
|
+
<DataSection content={totalContent} />
|
|
71
|
+
<DataSection content={countsContent} />
|
|
72
|
+
</Stack>
|
|
73
|
+
</DataApp>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Define every view rendered inside one `<DataApp>` from the same
|
|
79
|
+
`createDataHooks()` result; its client owns their filter controls.
|
|
80
|
+
|
|
81
|
+
Share one [data context](data-context.md) across the app's views. Group widgets
|
|
82
|
+
in one view only when they show the same result, such as a chart and the table
|
|
83
|
+
of its rows. A story or export that reads other views lists them in
|
|
84
|
+
[`summaryViews`](stories-and-export.md).
|
|
54
85
|
|
|
55
86
|
## Preserve displayed results
|
|
56
87
|
|
|
@@ -60,8 +91,8 @@ refresh or failure. Use `result.scope` in content and `view.scope(snapshot)` in
|
|
|
60
91
|
stories. Let views and bound widgets own request state and loading feedback.
|
|
61
92
|
Keep static introductions outside loading boundaries.
|
|
62
93
|
|
|
63
|
-
A measured zero is valid data. Set `isEmpty`
|
|
64
|
-
|
|
94
|
+
A measured zero is valid data. Set `isEmpty` and useful `emptyFallback` copy when
|
|
95
|
+
a result can be empty; omit both when it never is, such as a total.
|
|
65
96
|
|
|
66
97
|
## Detail destinations
|
|
67
98
|
|
|
@@ -70,9 +101,8 @@ The destination owns its input parser, operation, datasets, context, and content
|
|
|
70
101
|
Pass its content to `<DataApp details={[groupDetail]}>`:
|
|
71
102
|
|
|
72
103
|
```tsx
|
|
73
|
-
// ...
|
|
74
|
-
|
|
75
|
-
|
|
104
|
+
// ... operations, sampleDataContext, main view, datasets, and story
|
|
105
|
+
// ... defineDetailView from the main view's createDataHooks() result
|
|
76
106
|
const groupView = defineDetailView({
|
|
77
107
|
id: 'group',
|
|
78
108
|
title: 'Group counts',
|
|
@@ -111,8 +141,14 @@ function App() {
|
|
|
111
141
|
}
|
|
112
142
|
```
|
|
113
143
|
|
|
114
|
-
|
|
115
|
-
|
|
144
|
+
- The destination's operation lists the displayed filters it reads in
|
|
145
|
+
`filters` and parses only its own fields, such as a record ID, with `input`.
|
|
146
|
+
- An action or `metric.records()` returns those own fields and any filter it
|
|
147
|
+
narrows, such as the clicked group; the other filters carry over.
|
|
148
|
+
- Pass serializable IDs, never records or credentials. `parseInput` can reuse
|
|
149
|
+
the operation's `input`.
|
|
150
|
+
- Detail content receives `result.scope`; `describeInput` defaults to the
|
|
151
|
+
filters' description.
|
|
116
152
|
|
|
117
153
|
### Contributing metric records
|
|
118
154
|
|