@marktiderman/genesis-ui-native 3.12.1 → 3.14.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 (35) hide show
  1. package/dist/{chunk-TUDJDIGC.js → chunk-DCCOZSGR.js} +4 -2
  2. package/dist/chunk-DCCOZSGR.js.map +1 -0
  3. package/dist/{chunk-47CDRP43.js → chunk-G5M2Q7OU.js} +77 -4
  4. package/dist/chunk-G5M2Q7OU.js.map +1 -0
  5. package/dist/{chunk-C2ARUGT7.js → chunk-SRCGQWE4.js} +3 -3
  6. package/dist/{chunk-C2ARUGT7.js.map → chunk-SRCGQWE4.js.map} +1 -1
  7. package/dist/{chunk-X5CPLUPZ.js → chunk-WTO3LIUS.js} +4 -77
  8. package/dist/chunk-WTO3LIUS.js.map +1 -0
  9. package/dist/components/index.js +2 -2
  10. package/dist/data/index.d.ts +170 -27
  11. package/dist/data/index.js +493 -24
  12. package/dist/data/index.js.map +1 -1
  13. package/dist/{inbox-page-BGqR_cBs.d.ts → inbox-page-DD1cQdF4.d.ts} +6 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +4 -4
  16. package/dist/layouts/index.d.ts +2 -2
  17. package/dist/layouts/index.js +2 -2
  18. package/package.json +3 -3
  19. package/src/data/NativeRecordPeek.tsx +12 -1
  20. package/src/data/__tests__/parity-data.test.tsx +26 -0
  21. package/src/data/resource-view/NativeRecordView.tsx +15 -2
  22. package/src/data/resource-view/NativeResourceView.tsx +153 -16
  23. package/src/data/resource-view/__tests__/native-record-view.test.tsx +24 -0
  24. package/src/data/resource-view/__tests__/native-resource-inbox.test.tsx +59 -0
  25. package/src/data/resource-view/__tests__/native-resource-lists.test.tsx +281 -0
  26. package/src/data/resource-view/index.ts +12 -1
  27. package/src/data/resource-view/list-controls.tsx +508 -0
  28. package/src/data/resource-view/mapping.ts +10 -0
  29. package/src/data/resource-view/messages.ts +70 -0
  30. package/src/data/resource-view/use-native-resource-view.ts +13 -3
  31. package/src/layouts/__tests__/inbox-page-start.test.tsx +39 -0
  32. package/src/layouts/inbox-page.tsx +7 -0
  33. package/dist/chunk-47CDRP43.js.map +0 -1
  34. package/dist/chunk-TUDJDIGC.js.map +0 -1
  35. package/dist/chunk-X5CPLUPZ.js.map +0 -1
@@ -0,0 +1,508 @@
1
+ // A list's controls, board and calendar on the phone (ADR 0017): what the web draws, from the same
2
+ // core pieces. The list state is core's `useListState`, segment counts `useSegmentCounts`, the
3
+ // board `useViewBoard` and the calendar `useViewCalendarRange` with `calendarEvents` and
4
+ // `placeEvents`. Only the drawing here is the phone's.
5
+
6
+ import { useMemo, useState, type ReactNode } from "react";
7
+ import { Pressable, ScrollView, SectionList, View } from "react-native";
8
+ import type { DataRow, FilterParam } from "@marktiderman/genesis-core";
9
+ import { dayIn, type Day } from "@marktiderman/genesis-core/dates";
10
+ import { useSegmentCounts, useViewBoard, useViewCalendarRange, type ListStateResult } from "@marktiderman/genesis-core/hooks";
11
+ import { calendarEvents, calendarWindow, displayZone, placeEvents, shiftAnchor, type PlacedEvent, type ViewFilterValue } from "@marktiderman/genesis-core/resource-view";
12
+ import { NativeBadge } from "../../components/badge";
13
+ import { NativeButton } from "../../components/button";
14
+ import { NativeChip, NativeChipGroup } from "../../components/chip-group";
15
+ import { NativeEmptyState } from "../../components/empty-state";
16
+ import { NativeInlineAlert } from "../../components/inline-alert";
17
+ import { NativeInput } from "../../components/input";
18
+ import { NativeListItem } from "../../components/list-item";
19
+ import { NativeLoadingState } from "../../components/loading-state";
20
+ import { NativeSegmentedControl } from "../../components/segmented-control";
21
+ import { NativeSheet, NativeSheetScrollView } from "../../components/sheet";
22
+ import { NativeText } from "../../components/text";
23
+ import { useThemeRoles } from "../../hooks/use-theme-roles";
24
+ import { showInboxActions } from "../../layouts/inbox-page";
25
+ import { badgeVariant, useDisplayTimeZones, useNativeResourceViewMessages } from "./display";
26
+ import type { AnyResourceView, NativeResourceScreenCan } from "./mapping";
27
+ import { defaultNativeListMessages, fill, type NativeListMessages } from "./messages";
28
+
29
+ type Row = Record<string, unknown>;
30
+
31
+ /** The list words: the app's catalogue over the English. */
32
+ export function useNativeListMessages(): NativeListMessages {
33
+ const own = useNativeResourceViewMessages().lists;
34
+ return useMemo(() => ({ ...defaultNativeListMessages, ...own, types: { ...defaultNativeListMessages.types, ...own?.types } }), [own]);
35
+ }
36
+
37
+ /** The view types the phone draws. @stability Beta */
38
+ export const NATIVE_VIEW_TYPES = ["list", "grid", "gallery", "inbox", "board", "calendar"] as const;
39
+
40
+ /**
41
+ * The types a person may switch between on the phone: the view's, as the phone draws them (a
42
+ * table is a list there), each once.
43
+ *
44
+ * @stability Beta
45
+ */
46
+ export function nativeSwitchableTypes(view: AnyResourceView<Row>): string[] {
47
+ const out: string[] = [];
48
+ for (const t of view.types()) {
49
+ const shown = t === "table" ? "list" : t;
50
+ if ((NATIVE_VIEW_TYPES as readonly string[]).includes(shown) && !out.includes(shown)) out.push(shown);
51
+ }
52
+ return out;
53
+ }
54
+
55
+ /** The view's types as a segmented control: the phone's view-type switcher. @stability Beta */
56
+ export function NativeViewTypeSwitcher({ state, types, testID = "native-view-types" }: { state: ListStateResult; types: readonly string[]; testID?: string }) {
57
+ const words = useNativeListMessages();
58
+ if (types.length < 2) return null;
59
+ return (
60
+ <NativeSegmentedControl
61
+ testID={testID}
62
+ options={types.map((t) => ({ value: t, label: words.types[t] ?? t }))}
63
+ value={state.type ?? types[0]!}
64
+ onChange={(t) => state.setType(t)}
65
+ />
66
+ );
67
+ }
68
+
69
+ /** The view's segments as a row of chips, each with its count when it asks for one. @stability Beta */
70
+ export function NativeViewSegments({
71
+ view,
72
+ state,
73
+ baseFilters = [],
74
+ enabled = true,
75
+ testID = "native-view-segments",
76
+ }: {
77
+ view: AnyResourceView<Row>;
78
+ state: ListStateResult;
79
+ /** The list's other filters (the screen's), which counts include. */
80
+ baseFilters?: readonly FilterParam[];
81
+ /** False while the screen waits: no count is read. */
82
+ enabled?: boolean;
83
+ testID?: string;
84
+ }) {
85
+ const words = useNativeListMessages();
86
+ const segments = view.segments();
87
+ const counts = useSegmentCounts(view, useMemo(() => [...baseFilters, ...state.valueFilters], [baseFilters, state.valueFilters]), { enabled });
88
+ if (!segments.length) return null;
89
+ return (
90
+ <ScrollView horizontal showsHorizontalScrollIndicator={false} accessibilityLabel={words.segments}>
91
+ <NativeChipGroup mode="single" value={state.segment ?? ""} onChange={(id) => state.setSegment(String(id))} testID={testID} className="flex-nowrap">
92
+ {segments.map((s) => (
93
+ <NativeChip key={s.id} value={s.id} testID={`${testID}-${s.id}`}>
94
+ {counts[s.id] !== undefined ? `${s.label} ${counts[s.id]!.toLocaleString()}` : s.label}
95
+ </NativeChip>
96
+ ))}
97
+ </NativeChipGroup>
98
+ </ScrollView>
99
+ );
100
+ }
101
+
102
+ /** The view's declared filters: a Filters button (with how many are set) and a sheet to set them. @stability Beta */
103
+ export function NativeViewFilterControls({ view, state, testID = "native-view-filters" }: { view: AnyResourceView<Row>; state: ListStateResult; testID?: string }) {
104
+ const words = useNativeListMessages();
105
+ const filters = view.filters();
106
+ const [open, setOpen] = useState(false);
107
+ const set = Object.values(state.values).length;
108
+ if (!filters.length) return null;
109
+ return (
110
+ <>
111
+ <View style={{ flexDirection: "row", gap: 8 }}>
112
+ <NativeButton size="sm" variant="outline" testID={testID} onPress={() => setOpen(true)}>
113
+ {set ? fill(words.filtersSet, { count: set }) : words.filters}
114
+ </NativeButton>
115
+ {state.active ? (
116
+ <NativeButton size="sm" variant="ghost" testID={`${testID}-clear`} onPress={state.clear}>
117
+ {words.clear}
118
+ </NativeButton>
119
+ ) : null}
120
+ </View>
121
+ <NativeSheet open={open} onOpenChange={setOpen} testID={`${testID}-sheet`}>
122
+ <NativeSheetScrollView>
123
+ <View style={{ gap: 16, padding: 16 }}>
124
+ {filters.map((f) => {
125
+ const value = state.values[f.field];
126
+ const put = (next: ViewFilterValue | undefined) => state.setValue(f.field, next);
127
+ return (
128
+ <View key={f.field} style={{ gap: 6 }} testID={`${testID}-${f.field}`}>
129
+ <NativeText preset="label">{f.label}</NativeText>
130
+ {f.kind === "choice" ? (
131
+ <NativeChipGroup mode="multiple" value={Array.isArray(value) ? [...value] : []} onChange={(v) => put(Array.isArray(v) ? v : [v])}>
132
+ {f.options.map((o) => (
133
+ <NativeChip key={o.value} value={o.value} testID={`${testID}-${f.field}-${o.value}`}>
134
+ {o.label}
135
+ </NativeChip>
136
+ ))}
137
+ </NativeChipGroup>
138
+ ) : f.kind === "range" ? (
139
+ <View style={{ flexDirection: "row", gap: 8 }}>
140
+ {(["gte", "lte"] as const).map((end) => {
141
+ const range = value && typeof value === "object" && !Array.isArray(value) ? (value as { gte?: string; lte?: string }) : {};
142
+ return (
143
+ <NativeInput
144
+ key={end}
145
+ className="flex-1"
146
+ label={end === "gte" ? words.from : words.to}
147
+ testID={`${testID}-${f.field}-${end}`}
148
+ value={range[end] ?? ""}
149
+ keyboardType={f.input === "number" ? "numeric" : "default"}
150
+ placeholder={f.input === "date" ? "YYYY-MM-DD" : f.input === "datetime" ? "YYYY-MM-DDTHH:MM" : undefined}
151
+ onChangeText={(text) => put({ ...range, [end]: text })}
152
+ />
153
+ );
154
+ })}
155
+ </View>
156
+ ) : (
157
+ <NativeInput testID={`${testID}-${f.field}-text`} value={typeof value === "string" ? value : ""} onChangeText={(text) => put(text)} />
158
+ )}
159
+ </View>
160
+ );
161
+ })}
162
+ <View style={{ flexDirection: "row", gap: 8 }}>
163
+ <NativeButton variant="outline" onPress={state.clear} testID={`${testID}-sheet-clear`}>
164
+ {words.clear}
165
+ </NativeButton>
166
+ <NativeButton onPress={() => setOpen(false)} testID={`${testID}-sheet-done`}>
167
+ {words.done}
168
+ </NativeButton>
169
+ </View>
170
+ </View>
171
+ </NativeSheetScrollView>
172
+ </NativeSheet>
173
+ </>
174
+ );
175
+ }
176
+
177
+ /** The segments, the declared filters and the type switcher above a list (NativeResourceView's). */
178
+ export function NativeListControls({
179
+ view,
180
+ state,
181
+ baseFilters,
182
+ types,
183
+ testID,
184
+ enabled = true,
185
+ }: {
186
+ view: AnyResourceView<Row>;
187
+ state: ListStateResult;
188
+ baseFilters: readonly FilterParam[];
189
+ types: readonly string[];
190
+ testID: string;
191
+ /** False while the screen waits: the segments' counts aren't read. */
192
+ enabled?: boolean;
193
+ }) {
194
+ if (!view.segments().length && !view.filters().length && types.length < 2) return null;
195
+ return (
196
+ <View style={{ gap: 8 }} testID={`${testID}-controls`}>
197
+ <NativeViewTypeSwitcher state={state} types={types} testID={`${testID}-types`} />
198
+ <NativeViewSegments view={view} state={state} baseFilters={baseFilters} enabled={enabled} testID={`${testID}-segment`} />
199
+ <NativeViewFilterControls view={view} state={state} testID={`${testID}-filters`} />
200
+ </View>
201
+ );
202
+ }
203
+
204
+ /** A column's width on the phone's board, in points. */
205
+ const COLUMN_WIDTH = 280;
206
+
207
+ /**
208
+ * The view as a board on the phone: its columns side by side, scrolled across; a card opens on a
209
+ * press, and a long press offers its moves ("Move to …"), each through the view's guards and the
210
+ * resource's own update (core's useViewBoard, as the web's board).
211
+ */
212
+ export function NativeResourceBoard({
213
+ view,
214
+ filters,
215
+ can,
216
+ onOpen,
217
+ header,
218
+ testID,
219
+ enabled = true,
220
+ }: {
221
+ view: AnyResourceView<Row>;
222
+ filters: readonly FilterParam[];
223
+ can?: NativeResourceScreenCan<Row> | undefined;
224
+ onOpen: (row: Row) => void;
225
+ header?: ReactNode;
226
+ testID: string;
227
+ /** False while the screen waits: nothing is fetched. */
228
+ enabled?: boolean;
229
+ }) {
230
+ const words = useNativeListMessages();
231
+ const colors = useThemeRoles();
232
+ const board = useViewBoard<Row>(view as never, {
233
+ filters,
234
+ enabled,
235
+ // The screen's rule, in the board's words: a card moves only when the screen allows `update`.
236
+ ...(can
237
+ ? {
238
+ can: (action: "create" | "edit" | "delete", row?: Row) => {
239
+ const verdict = can(action === "edit" ? "update" : action, row);
240
+ return verdict !== false && typeof verdict !== "string";
241
+ },
242
+ }
243
+ : {}),
244
+ words: {
245
+ notAllowed: words.notAllowed,
246
+ noValue: words.noValue,
247
+ stillSaving: (name) => fill(words.stillSaving, { name }),
248
+ notChanged: (noun) => fill(words.notChanged, { noun }),
249
+ moveFailed: (name) => fill(words.moveFailed, { name }),
250
+ },
251
+ });
252
+ const cancel = useNativeResourceViewMessages().common.cancel;
253
+ const showMoves = (row: Row) => {
254
+ const verdict = board.movable ? board.canMove(row) : words.notAllowed;
255
+ const from = String(row[board.field] ?? "");
256
+ showInboxActions(
257
+ board.titleOf(row),
258
+ board.columns
259
+ .filter((c) => c.value !== from)
260
+ .map((c) => ({
261
+ id: c.value,
262
+ label: fill(words.moveTo, { column: c.label }),
263
+ onPress: () => {
264
+ if (verdict !== true) {
265
+ showInboxActions(verdict, [], cancel);
266
+ return;
267
+ }
268
+ void board.move(row, c.value).catch(() => undefined);
269
+ },
270
+ })),
271
+ cancel,
272
+ );
273
+ };
274
+ return (
275
+ <View style={{ flex: 1 }} testID={`${testID}-board`}>
276
+ {header}
277
+ {board.refusal ? <NativeInlineAlert variant="destructive" description={board.refusal} onDismiss={board.clearRefusal} testID={`${testID}-board-refusal`} /> : null}
278
+ <ScrollView horizontal contentContainerStyle={{ gap: 12, paddingHorizontal: 16, paddingBottom: 16 }}>
279
+ {board.columns.map((column) => (
280
+ <View key={column.value} testID={`${testID}-board-column-${column.value}`} style={{ width: COLUMN_WIDTH, gap: 8 }}>
281
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 8, paddingTop: 8 }}>
282
+ <NativeText preset="label" accessibilityRole="header">
283
+ {column.label}
284
+ </NativeText>
285
+ <NativeBadge variant={badgeVariant(column.tone)}>{String(column.total ?? column.items.length)}</NativeBadge>
286
+ </View>
287
+ <ScrollView style={{ maxHeight: "100%" }} contentContainerStyle={{ gap: 8 }}>
288
+ {column.items.map((row) => {
289
+ const key = board.keyOf(row);
290
+ const summary = view.summary(row as Row & DataRow);
291
+ return (
292
+ <Pressable
293
+ key={key}
294
+ testID={`${testID}-board-card-${key}`}
295
+ accessibilityRole="button"
296
+ accessibilityLabel={summary.title}
297
+ accessibilityActions={[{ name: "move", label: words.moveTo.replace(" {column}", "") }]}
298
+ onAccessibilityAction={() => showMoves(row)}
299
+ onPress={() => onOpen(row)}
300
+ onLongPress={() => showMoves(row)}
301
+ style={{ backgroundColor: colors.surface as string, borderRadius: 12, opacity: board.saving.has(key) ? 0.5 : 1 }}
302
+ >
303
+ <NativeListItem title={summary.title} subtitle={summary.subtitle} className="bg-transparent" />
304
+ </Pressable>
305
+ );
306
+ })}
307
+ {column.loading ? <NativeLoadingState fullScreen={false} size="small" /> : null}
308
+ {column.hasMore ? (
309
+ <NativeButton size="sm" variant="ghost" onPress={() => board.loadMore(column.value)} testID={`${testID}-board-more-${column.value}`}>
310
+ {words.loadMore}
311
+ </NativeButton>
312
+ ) : null}
313
+ </ScrollView>
314
+ </View>
315
+ ))}
316
+ </ScrollView>
317
+ </View>
318
+ );
319
+ }
320
+
321
+ /**
322
+ * The view as a calendar on the phone: an agenda (the window's days with their events) or a
323
+ * month (a grid of days with dots; a tap shows that day's events below). Rows come through core's
324
+ * useViewCalendarRange and calendarEvents, and land by placeEvents, as on the web.
325
+ */
326
+ export function NativeResourceCalendar({
327
+ view,
328
+ filters,
329
+ onOpen,
330
+ header,
331
+ testID,
332
+ enabled = true,
333
+ }: {
334
+ view: AnyResourceView<Row>;
335
+ filters: readonly FilterParam[];
336
+ onOpen: (row: Row) => void;
337
+ header?: ReactNode;
338
+ testID: string;
339
+ /** False while the screen waits: nothing is fetched. */
340
+ enabled?: boolean;
341
+ }) {
342
+ const words = useNativeListMessages();
343
+ const listWords = useNativeResourceViewMessages().list;
344
+ const colors = useThemeRoles();
345
+ const block = view.definition.calendar;
346
+ if (!block?.field) throw new Error(`NativeResourceView(${view.resource}): type="calendar" needs the view's calendar block (calendar.field)`);
347
+ const [layout, setLayout] = useState<"agenda" | "month">(block.phoneLayout === "month" || block.layout === "month" ? "month" : "agenda");
348
+ const weekStartsOn = block.weekStartsOn ?? 1;
349
+ // The clocks the cells use (the screen's `scopeTimeZone` over ViewerScope's): one clock for the
350
+ // calendar's window, its placement and its times, and the field's cells.
351
+ const zones = useDisplayTimeZones();
352
+ const zone = displayZone(view.definition.fields?.[block.field as never]?.timeZone, zones.viewer, zones.scope);
353
+ const [anchor, setAnchor] = useState<Day>(() => dayIn(zone));
354
+ const [picked, setPicked] = useState<Day>(() => dayIn(zone));
355
+ const range = calendarWindow(layout === "month" ? "month" : "agenda", anchor, { weeks: 2, weekStartsOn });
356
+ const data = useViewCalendarRange<Row>(view as never, range, { filters, timeZone: zone, enabled });
357
+ const events = useMemo(
358
+ () => calendarEvents<Row>(view as never, data.rows, { field: block.field, endField: block.endField, durationField: block.durationField, durationUnit: block.durationUnit, allDayField: block.allDayField, laneBy: block.laneBy, timeZone: zone }),
359
+ [view, data.rows, block, zone],
360
+ );
361
+ const byDay = useMemo(() => placeEvents(events, range, zone), [events, range.start, range.end, zone]); // eslint-disable-line react-hooks/exhaustive-deps -- the window by value
362
+ const step = (n: number) => setAnchor((a) => shiftAnchor(layout === "month" ? "month" : "agenda", a, n, 2));
363
+ const time = (at: Day | Date) => (typeof at === "string" ? words.allDay : at.toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit", timeZone: zone }));
364
+ const eventRow = (placed: PlacedEvent<Row>) => (
365
+ <Pressable
366
+ key={`${placed.day}:${placed.event.key}`}
367
+ testID={`${testID}-calendar-event-${placed.event.key}`}
368
+ accessibilityRole="button"
369
+ onPress={() => placed.event.row && onOpen(placed.event.row)}
370
+ style={{ backgroundColor: colors.surface as string, borderRadius: 10, marginHorizontal: 16 }}
371
+ >
372
+ <NativeListItem title={placed.event.title} subtitle={placed.allDay ? words.allDay : time(placed.event.start)} className="bg-transparent" />
373
+ </Pressable>
374
+ );
375
+ const toolbar = (
376
+ <View style={{ gap: 8, paddingHorizontal: 16 }}>
377
+ <NativeSegmentedControl
378
+ testID={`${testID}-calendar-layout`}
379
+ options={[
380
+ { value: "agenda", label: words.agenda },
381
+ { value: "month", label: words.month },
382
+ ]}
383
+ value={layout}
384
+ onChange={(l) => setLayout(l as "agenda" | "month")}
385
+ />
386
+ <View style={{ flexDirection: "row", gap: 8, alignItems: "center" }}>
387
+ <NativeButton size="sm" variant="outline" accessibilityLabel={words.previous} onPress={() => step(-1)} testID={`${testID}-calendar-previous`}>
388
+ ‹
389
+ </NativeButton>
390
+ <NativeButton
391
+ size="sm"
392
+ variant="outline"
393
+ onPress={() => {
394
+ setAnchor(dayIn(zone));
395
+ setPicked(dayIn(zone));
396
+ }}
397
+ testID={`${testID}-calendar-today`}
398
+ >
399
+ {words.today}
400
+ </NativeButton>
401
+ <NativeButton size="sm" variant="outline" accessibilityLabel={words.next} onPress={() => step(1)} testID={`${testID}-calendar-next`}>
402
+ ›
403
+ </NativeButton>
404
+ <NativeText preset="label" className="ml-2">
405
+ {anchor.slice(0, 7)}
406
+ </NativeText>
407
+ </View>
408
+ {data.total > data.rows.length ? <NativeText preset="caption">{fill(words.more, { count: data.total - data.rows.length })}</NativeText> : null}
409
+ </View>
410
+ );
411
+
412
+ // A failed read is said, with a retry: never an empty calendar.
413
+ const failed = data.error ? (
414
+ <NativeEmptyState
415
+ testID={`${testID}-calendar-error`}
416
+ variant="error"
417
+ title={fill(listWords.loadFailed, { nounPlural: view.nounPlural })}
418
+ primaryAction={
419
+ <NativeButton variant="outline" size="sm" onPress={() => data.refetch()} testID={`${testID}-calendar-retry`}>
420
+ {listWords.retry}
421
+ </NativeButton>
422
+ }
423
+ />
424
+ ) : null;
425
+ if (failed) {
426
+ return (
427
+ <ScrollView testID={`${testID}-calendar-failed`} contentContainerStyle={{ gap: 12, paddingBottom: 32 }}>
428
+ {header}
429
+ {toolbar}
430
+ {failed}
431
+ </ScrollView>
432
+ );
433
+ }
434
+
435
+ if (layout === "agenda") {
436
+ const sections = [...byDay.entries()].filter(([, list]) => list.length).map(([day, list]) => ({ key: day, title: day, data: list }));
437
+ return (
438
+ <SectionList<PlacedEvent<Row>, { key: string; title: string; data: PlacedEvent<Row>[] }>
439
+ testID={`${testID}-calendar-agenda`}
440
+ sections={sections}
441
+ keyExtractor={(p) => `${p.day}:${p.event.key}`}
442
+ renderItem={({ item }) => eventRow(item)}
443
+ renderSectionHeader={({ section }) => (
444
+ <NativeText preset="label" className="px-4 pt-4 pb-1" accessibilityRole="header">
445
+ {section.title}
446
+ </NativeText>
447
+ )}
448
+ ItemSeparatorComponent={() => <View style={{ height: 8 }} />}
449
+ ListHeaderComponent={
450
+ <>
451
+ {header}
452
+ {toolbar}
453
+ </>
454
+ }
455
+ ListEmptyComponent={data.loading ? <NativeLoadingState fullScreen={false} /> : <NativeText className="px-4 pt-4 text-muted-foreground">{words.noEvents}</NativeText>}
456
+ stickySectionHeadersEnabled={false}
457
+ />
458
+ );
459
+ }
460
+ // Month: weeks of seven days, each with a dot per event (up to three).
461
+ const days = [...byDay.keys()];
462
+ const weeks: Day[][] = [];
463
+ for (let i = 0; i < days.length; i += 7) weeks.push(days.slice(i, i + 7));
464
+ const month = anchor.slice(0, 7);
465
+ const today = dayIn(zone);
466
+ const ofPicked = byDay.get(picked) ?? [];
467
+ return (
468
+ <ScrollView testID={`${testID}-calendar-month`} contentContainerStyle={{ gap: 12, paddingBottom: 32 }}>
469
+ {header}
470
+ {toolbar}
471
+ <View style={{ paddingHorizontal: 16 }}>
472
+ {weeks.map((week) => (
473
+ <View key={week[0]} style={{ flexDirection: "row" }}>
474
+ {week.map((day) => {
475
+ const list = byDay.get(day) ?? [];
476
+ const selected = day === picked;
477
+ return (
478
+ <Pressable
479
+ key={day}
480
+ testID={`${testID}-calendar-day-${day}`}
481
+ accessibilityRole="button"
482
+ accessibilityState={{ selected }}
483
+ accessibilityLabel={`${day}${list.length ? `, ${list.length}` : ""}`}
484
+ onPress={() => setPicked(day)}
485
+ style={{ flex: 1, alignItems: "center", paddingVertical: 6, borderRadius: 8, backgroundColor: selected ? (colors.surface as string) : undefined }}
486
+ >
487
+ <NativeText preset="body-sm" className={day.slice(0, 7) !== month ? "text-muted-foreground" : day === today ? "font-semibold" : undefined}>
488
+ {String(Number(day.slice(8)))}
489
+ </NativeText>
490
+ <View style={{ flexDirection: "row", gap: 2, height: 6 }}>
491
+ {list.slice(0, 3).map((p) => (
492
+ <View key={p.event.key} style={{ width: 4, height: 4, borderRadius: 2, backgroundColor: colors.tint }} />
493
+ ))}
494
+ </View>
495
+ </Pressable>
496
+ );
497
+ })}
498
+ </View>
499
+ ))}
500
+ </View>
501
+ <NativeText preset="label" className="px-4" accessibilityRole="header">
502
+ {picked}
503
+ </NativeText>
504
+ {ofPicked.length ? <View style={{ gap: 8 }}>{ofPicked.map((p) => eventRow(p))}</View> : <NativeText className="px-4 text-muted-foreground">{words.noEvents}</NativeText>}
505
+ {data.loading ? <NativeLoadingState fullScreen={false} size="small" /> : null}
506
+ </ScrollView>
507
+ );
508
+ }
@@ -140,6 +140,11 @@ export interface SwipeActionOptions<T> {
140
140
  onDelete: (row: T) => void;
141
141
  /** A refused action was pressed: say why. */
142
142
  onRefused: (label: string, reason: string) => void;
143
+ /**
144
+ * Runs one of the view's own actions (ADR 0017 §2) on the row. With it, the view's actions sit
145
+ * between Edit and Delete, each refused one with its reason (`view.canAction`).
146
+ */
147
+ onAction?: ((name: string, row: T) => void) | undefined;
143
148
  }
144
149
 
145
150
  /**
@@ -166,6 +171,11 @@ export function swipeActionsFor<T extends Row>(
166
171
  });
167
172
  };
168
173
  if (editable) add("edit", messages.common.edit, "edit", allowed(view, "update", row, screen, viewer), () => onEdit(row));
174
+ if (options.onAction) {
175
+ for (const action of view.actions()) {
176
+ add(action.name, action.label, "bolt", view.canAction(action.name, row as T & DataRow, viewer), () => options.onAction!(action.name, row), !!action.destructive);
177
+ }
178
+ }
169
179
  add(
170
180
  "delete",
171
181
  softDelete ? messages.bin.action : messages.delete.action,
@@ -86,8 +86,78 @@ export interface NativeResourceViewMessages {
86
86
  deleteFailed: string;
87
87
  dismiss: string;
88
88
  };
89
+ /**
90
+ * A list's segments, declared filters, view types, board and calendar (ADR 0017). Optional, so
91
+ * a catalogue written before it still fits; the English is used for what's missing.
92
+ */
93
+ lists?: Partial<NativeListMessages>;
94
+ }
95
+
96
+ /** The words of a list's controls, board and calendar on the phone. @stability Beta */
97
+ export interface NativeListMessages {
98
+ segments: string;
99
+ filters: string;
100
+ /** `{count}`: declared filters set. */
101
+ filtersSet: string;
102
+ clear: string;
103
+ done: string;
104
+ from: string;
105
+ to: string;
106
+ /** The view types, by name. */
107
+ types: Readonly<Record<string, string>>;
108
+ /** The switcher's accessible name. */
109
+ type: string;
110
+ /** Board: the column of rows with no value. */
111
+ noValue: string;
112
+ /** A card the screen won't let this viewer move. */
113
+ notAllowed: string;
114
+ /** `{name}`: a card whose last move is still saving. */
115
+ stillSaving: string;
116
+ /** `{noun}`: a move that matched no row. */
117
+ notChanged: string;
118
+ /** `{name}`: a move that failed with no words of its own. */
119
+ moveFailed: string;
120
+ /** `{column}`: a card's move, in its menu. */
121
+ moveTo: string;
122
+ loadMore: string;
123
+ today: string;
124
+ previous: string;
125
+ next: string;
126
+ agenda: string;
127
+ month: string;
128
+ noEvents: string;
129
+ allDay: string;
130
+ /** `{count}`: rows the calendar's limit left out. */
131
+ more: string;
89
132
  }
90
133
 
134
+ export const defaultNativeListMessages: NativeListMessages = {
135
+ segments: "Segments",
136
+ filters: "Filters",
137
+ filtersSet: "Filters ({count})",
138
+ clear: "Clear",
139
+ done: "Done",
140
+ from: "From",
141
+ to: "To",
142
+ types: { list: "List", table: "List", grid: "Grid", gallery: "Gallery", inbox: "Inbox", board: "Board", calendar: "Calendar" },
143
+ type: "View",
144
+ noValue: "No value",
145
+ notAllowed: "You can't move this card.",
146
+ stillSaving: "{name} is still moving. Try again in a moment.",
147
+ notChanged: "This {noun} was not changed.",
148
+ moveFailed: "Couldn’t move {name}.",
149
+ moveTo: "Move to {column}",
150
+ loadMore: "Load more",
151
+ today: "Today",
152
+ previous: "Previous",
153
+ next: "Next",
154
+ agenda: "Agenda",
155
+ month: "Month",
156
+ noEvents: "Nothing on this day",
157
+ allDay: "All day",
158
+ more: "{count} more not shown",
159
+ };
160
+
91
161
  export const defaultNativeResourceViewMessages: NativeResourceViewMessages = {
92
162
  common: {
93
163
  empty: "—",
@@ -67,6 +67,10 @@ export interface NativeResourceViewOptions<T extends Row = Row> {
67
67
  can?: NativeResourceScreenCan<T>;
68
68
  /** Refetch loaded pages when the provider reports a change. */
69
69
  live?: boolean;
70
+ /** The list state's filters (core `useListState`: a segment and the declared filters), on top of the screen's. */
71
+ listFilters?: readonly FilterParam[];
72
+ /** False while another type (a board, a calendar) draws the rows: the list reads nothing. Default true. */
73
+ enabled?: boolean;
70
74
  }
71
75
 
72
76
  export type SaveResult = { ok: true } | { ok: false; message?: string; fields: Record<string, string> };
@@ -104,7 +108,7 @@ export interface UseNativeResourceViewReturn<T extends Row = Row> {
104
108
  dismissRefusal: () => void;
105
109
  item: (row: T) => NativeResourceRowItem;
106
110
  /** The row's swipe actions. Edit and delete call `onEdit` / `onDelete` you pass here. */
107
- actions: (row: T, handlers: { onEdit: (row: T) => void; onDelete: (row: T) => void; onRefused: (label: string, reason: string) => void }) => NativeResourceSwipeAction[];
111
+ actions: (row: T, handlers: { onEdit: (row: T) => void; onDelete: (row: T) => void; onRefused: (label: string, reason: string) => void; onAction?: ((name: string, row: T) => void) | undefined }) => NativeResourceSwipeAction[];
108
112
  /** Whether a new row may be created: true, or the guard's reason. False when the screen turns it off or there's no form. */
109
113
  canCreate: Allowed | false;
110
114
  /** The form sheet's fields. */
@@ -119,6 +123,8 @@ export interface UseNativeResourceViewReturn<T extends Row = Row> {
119
123
  remove: (row: T) => void;
120
124
  /** The provider bins deleted rows (they can be restored). */
121
125
  softDelete: boolean;
126
+ /** The screen's and the tab's filters, before the list state's: what segment counts start from. */
127
+ baseFilters: FilterParam[];
122
128
  }
123
129
 
124
130
  function filterParams(filter: Filter | undefined): FilterParam[] {
@@ -176,7 +182,7 @@ export function useNativeResourceView<T extends Row = Row>(
176
182
  view: AnyResourceView<T>,
177
183
  options: NativeResourceViewOptions<T> = {},
178
184
  ): UseNativeResourceViewReturn<T> {
179
- const { preset, filter, perPage, maxPages = DEFAULT_MAX_PAGES, searchFields: searchOption, can, live } = options;
185
+ const { preset, filter, perPage, maxPages = DEFAULT_MAX_PAGES, searchFields: searchOption, can, live, listFilters, enabled = true } = options;
180
186
  const messages = useNativeResourceViewMessages();
181
187
  const tab = preset ? view.definition.presets?.[preset] : undefined;
182
188
  if (preset && !tab) throw new Error(`NativeResourceView(${view.resource}): no preset "${preset}"`);
@@ -200,13 +206,16 @@ export function useNativeResourceView<T extends Row = Row>(
200
206
  () => searchOption ?? (view.labelField ? [view.labelField] : undefined),
201
207
  [searchOption, view.labelField],
202
208
  );
209
+ const listStateKey = JSON.stringify(listFilters ?? []);
210
+ const readFilters = useMemo(() => [...defaultFilters, ...(JSON.parse(listStateKey) as FilterParam[])], [defaultFilters, listStateKey]);
203
211
  const pages = useInfiniteResource<T & BaseRecord>(view.resource, {
204
- defaultFilters,
212
+ defaultFilters: readFilters,
205
213
  ...(sorts.length ? { defaultSorts: sorts } : {}),
206
214
  ...(perPage ? { perPage } : {}),
207
215
  maxPages,
208
216
  ...(searchFields ? { searchFields } : {}),
209
217
  keepPreviousData: true,
218
+ enabled,
210
219
  ...(live ? { live } : {}),
211
220
  });
212
221
 
@@ -372,6 +381,7 @@ export function useNativeResourceView<T extends Row = Row>(
372
381
  save,
373
382
  remove,
374
383
  softDelete,
384
+ baseFilters: defaultFilters,
375
385
  };
376
386
  }
377
387