@marktiderman/genesis-ui-native 3.0.0 → 3.2.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.
@@ -1,7 +1,7 @@
1
1
  // @feat:native-components
2
2
  /**
3
- * NativeResourceWorkspace: one record's screen from a genesis-core workspace, natively.
4
- * - the title and the header menu come from getNativeResourceWorkspaceStackOptions;
3
+ * NativeRecordView: one record's screen from a genesis-core page, natively.
4
+ * - the title and the header menu come from getNativeRecordViewStackOptions;
5
5
  * - up to four sections are a segmented control, more are pushed rows;
6
6
  * - a list section is an embedded NativeResourceView filtered by the row;
7
7
  * - a settings section saves only its changed listed keys; a zero-row save is a refusal, inline;
@@ -13,8 +13,8 @@ import { useState, type ReactNode } from "react";
13
13
  import { ActionSheetIOS, Alert, Platform } from "react-native";
14
14
  import { beforeEach, describe, expect, it, vi } from "vitest";
15
15
  import { defineResource, GenesisProvider, ViewerScope, type DataProvider, type ListParams, type Viewer } from "@marktiderman/genesis-core";
16
- import { defineView, defineWorkspace } from "@marktiderman/genesis-core/resource-view";
17
- import { getNativeResourceWorkspaceStackOptions, NativeResourceWorkspace, NativeResourceWorkspaceMenu, parseSettingNumber } from "..";
16
+ import { defineView, defineRecordView } from "@marktiderman/genesis-core/resource-view";
17
+ import { getNativeRecordViewStackOptions, NativeRecordView, NativeRecordViewMenu, parseSettingNumber } from "..";
18
18
 
19
19
  type Brand = { id: string; name: string; website: string | null; public: boolean; is_default: boolean };
20
20
  type Product = { id: string; brand_id: string; title: string };
@@ -56,7 +56,7 @@ const sections = [
56
56
  { id: "settings", label: "Settings", settings: ["website", "public"] as const },
57
57
  { id: "activity", label: "Activity" },
58
58
  ];
59
- const workspace = defineWorkspace(brandsView, {
59
+ const page = defineRecordView(brandsView, {
60
60
  sections,
61
61
  readiness: (b) => [
62
62
  { title: "Has a website", ok: !!b.website, reason: "Add the website.", tone: "danger" },
@@ -95,20 +95,20 @@ beforeEach(() => {
95
95
  (ActionSheetIOS.showActionSheetWithOptions as unknown as { mockClear: () => void }).mockClear();
96
96
  });
97
97
 
98
- describe("NativeResourceWorkspace", () => {
98
+ describe("NativeRecordView", () => {
99
99
  it("puts the title in the navigation bar and the actions in the header menu", () => {
100
- const options = getNativeResourceWorkspaceStackOptions({ workspace, row: brand });
100
+ const options = getNativeRecordViewStackOptions({ view: page, row: brand });
101
101
  expect(options.title).toBe("Northwind");
102
102
  expect(typeof options.headerRight).toBe("function");
103
- const none = defineWorkspace(brandsView, { header: { actions: [] }, sections: [{ id: "a", label: "A" }] });
104
- expect(getNativeResourceWorkspaceStackOptions({ workspace: none, row: brand }).headerRight).toBeUndefined();
103
+ const none = defineRecordView(brandsView, { header: { actions: [] }, sections: [{ id: "a", label: "A" }] });
104
+ expect(getNativeRecordViewStackOptions({ view: none, row: brand }).headerRight).toBeUndefined();
105
105
  });
106
106
 
107
107
  it("iOS: the menu is an action sheet; a refused action explains, a confirm asks, then the provider runs it", async () => {
108
108
  const alert = vi.spyOn(Alert, "alert").mockImplementation(() => {});
109
109
  const sheet = vi.spyOn(ActionSheetIOS, "showActionSheetWithOptions").mockImplementation(() => {});
110
110
  const p = provider();
111
- render(<NativeResourceWorkspaceMenu workspace={workspace} row={brand} />, { wrapper: wrap(p) });
111
+ render(<NativeRecordViewMenu view={page} row={brand} />, { wrapper: wrap(p) });
112
112
  fireEvent.click(screen.getByTestId("native-resource-workspace-menu"));
113
113
  const [options, pick] = sheet.mock.calls[0]!;
114
114
  expect(options.options).toEqual(["Archive (The default brand stays.)", "Publish", "Purge", "Cancel"]);
@@ -121,7 +121,7 @@ describe("NativeResourceWorkspace", () => {
121
121
 
122
122
  alert.mockClear();
123
123
  const onAction = vi.fn();
124
- render(<NativeResourceWorkspaceMenu workspace={workspace} row={{ ...brand, is_default: false }} onAction={onAction} testID="menu2" />, {
124
+ render(<NativeRecordViewMenu view={page} row={{ ...brand, is_default: false }} onAction={onAction} testID="menu2" />, {
125
125
  wrapper: wrap(provider()),
126
126
  });
127
127
  fireEvent.click(screen.getByTestId("menu2"));
@@ -140,7 +140,7 @@ describe("NativeResourceWorkspace", () => {
140
140
  const alert = vi.spyOn(Alert, "alert").mockImplementation(() => {});
141
141
  try {
142
142
  const p = provider();
143
- render(<NativeResourceWorkspaceMenu workspace={workspace} row={{ ...brand, is_default: false }} />, { wrapper: wrap(p) });
143
+ render(<NativeRecordViewMenu view={page} row={{ ...brand, is_default: false }} />, { wrapper: wrap(p) });
144
144
  fireEvent.click(screen.getByTestId("native-resource-workspace-menu"));
145
145
  expect(alert).not.toHaveBeenCalled();
146
146
  expect((await screen.findByTestId("native-resource-workspace-menu-purge")).textContent).toContain("Purge");
@@ -155,7 +155,7 @@ describe("NativeResourceWorkspace", () => {
155
155
  let finish!: () => void;
156
156
  const runAction = vi.fn(() => new Promise<{ data: null }>((resolve) => (finish = () => resolve({ data: null }))));
157
157
  const sheet = vi.spyOn(ActionSheetIOS, "showActionSheetWithOptions").mockImplementation(() => {});
158
- render(<NativeResourceWorkspaceMenu workspace={workspace} row={brand} />, { wrapper: wrap(provider({ runAction: runAction as never })) });
158
+ render(<NativeRecordViewMenu view={page} row={brand} />, { wrapper: wrap(provider({ runAction: runAction as never })) });
159
159
  fireEvent.click(screen.getByTestId("native-resource-workspace-menu"));
160
160
  const pick = sheet.mock.calls[0]![1];
161
161
  pick(1);
@@ -168,9 +168,9 @@ describe("NativeResourceWorkspace", () => {
168
168
 
169
169
  it("names accessibility actions with a prefix, so 'activate' can't take over the button", async () => {
170
170
  const view = defineView(brands, { actions: [{ name: "activate", label: "Activate" }] });
171
- const ws = defineWorkspace(view, { sections: [{ id: "a", label: "A" }] });
171
+ const ws = defineRecordView(view, { sections: [{ id: "a", label: "A" }] });
172
172
  const p = provider();
173
- render(<NativeResourceWorkspaceMenu workspace={ws} row={brand} />, { wrapper: wrap(p) });
173
+ render(<NativeRecordViewMenu view={ws} row={brand} />, { wrapper: wrap(p) });
174
174
  const button = screen.getByTestId("native-resource-workspace-menu");
175
175
  expect(button.getAttribute("data-a11y-actions")).toBe("action:activate");
176
176
  // The platform's own "activate" does nothing here; the prefixed one runs the action.
@@ -181,16 +181,16 @@ describe("NativeResourceWorkspace", () => {
181
181
  });
182
182
 
183
183
  it("hides actions when nothing can run them, or the screen turns them off", () => {
184
- render(<NativeResourceWorkspaceMenu workspace={workspace} row={brand} testID="none" />, { wrapper: wrap(provider({ runAction: undefined })) });
184
+ render(<NativeRecordViewMenu view={page} row={brand} testID="none" />, { wrapper: wrap(provider({ runAction: undefined })) });
185
185
  expect(screen.queryByTestId("none")).toBeNull();
186
186
  const sheet = vi.spyOn(ActionSheetIOS, "showActionSheetWithOptions").mockImplementation(() => {});
187
- render(<NativeResourceWorkspaceMenu workspace={workspace} row={brand} can={(name) => name !== "publish"} />, { wrapper: wrap(provider()) });
187
+ render(<NativeRecordViewMenu view={page} row={brand} can={(name) => name !== "publish"} />, { wrapper: wrap(provider()) });
188
188
  fireEvent.click(screen.getByTestId("native-resource-workspace-menu"));
189
189
  expect(sheet.mock.calls.at(-1)![0].options).not.toContain("Publish");
190
190
  });
191
191
 
192
192
  it("shows up to four sections as a segmented control, and the readiness checks", () => {
193
- render(<NativeResourceWorkspace workspace={workspace} row={brand} section="activity" slots={{ activity: <></> }} switcher={<></>} />, {
193
+ render(<NativeRecordView view={page} row={brand} section="activity" slots={{ activity: <></> }} switcher={<></>} />, {
194
194
  wrapper: wrap(provider()),
195
195
  });
196
196
  const control = screen.getByTestId("native-resource-workspace-sections");
@@ -202,7 +202,7 @@ describe("NativeResourceWorkspace", () => {
202
202
  });
203
203
 
204
204
  it("shows the summary chip alone once every check is met", () => {
205
- render(<NativeResourceWorkspace workspace={workspace} row={{ ...brand, website: "https://x.example" }} section="activity" messages={{ ready: "Ready to go" }} />, {
205
+ render(<NativeRecordView view={page} row={{ ...brand, website: "https://x.example" }} section="activity" messages={{ ready: "Ready to go" }} />, {
206
206
  wrapper: wrap(provider()),
207
207
  });
208
208
  expect(screen.getByTestId("native-resource-workspace-readiness").textContent).toBe("Ready to go");
@@ -210,11 +210,11 @@ describe("NativeResourceWorkspace", () => {
210
210
  });
211
211
 
212
212
  it("pushes sections when there are more than four", () => {
213
- const wide = defineWorkspace(brandsView, {
213
+ const wide = defineRecordView(brandsView, {
214
214
  sections: ["a", "b", "c", "d", "e"].map((id) => ({ id, label: id.toUpperCase() })),
215
215
  });
216
216
  const onOpenSection = vi.fn();
217
- render(<NativeResourceWorkspace workspace={wide} row={brand} onOpenSection={onOpenSection} />, { wrapper: wrap(provider()) });
217
+ render(<NativeRecordView view={wide} row={brand} onOpenSection={onOpenSection} />, { wrapper: wrap(provider()) });
218
218
  expect(screen.queryByTestId("native-resource-workspace-sections-option-a")).toBeNull();
219
219
  fireEvent.click(screen.getByTestId("native-resource-workspace-section-e"));
220
220
  expect(onOpenSection).toHaveBeenCalledWith("e");
@@ -222,7 +222,7 @@ describe("NativeResourceWorkspace", () => {
222
222
 
223
223
  it("draws a list section as an embedded NativeResourceView filtered by the row", async () => {
224
224
  const p = provider();
225
- render(<NativeResourceWorkspace workspace={workspace} row={brand} />, { wrapper: wrap(p) });
225
+ render(<NativeRecordView view={page} row={brand} />, { wrapper: wrap(p) });
226
226
  expect(await screen.findByText("Kettle")).toBeTruthy();
227
227
  const params = (p.getList as ReturnType<typeof vi.fn>).mock.calls[0]![1] as ListParams;
228
228
  expect(params.filters).toContainEqual({ field: "brand_id", operator: "eq", value: "b1" });
@@ -231,7 +231,7 @@ describe("NativeResourceWorkspace", () => {
231
231
  it("switches sections and saves only the changed listed keys", async () => {
232
232
  const p = provider();
233
233
  const onSaved = vi.fn();
234
- render(<NativeResourceWorkspace workspace={workspace} row={brand} onSaved={onSaved} />, { wrapper: wrap(p) });
234
+ render(<NativeRecordView view={page} row={brand} onSaved={onSaved} />, { wrapper: wrap(p) });
235
235
  fireEvent.click(screen.getByTestId("native-resource-workspace-sections-option-settings"));
236
236
  const input = screen.getByTestId("native-resource-workspace-settings-website-input");
237
237
  fireEvent.change(input, { target: { value: "https://northwind.example" } });
@@ -242,15 +242,15 @@ describe("NativeResourceWorkspace", () => {
242
242
 
243
243
  it("shows a zero-row save as a refusal, inline", async () => {
244
244
  const p = provider({ update: vi.fn(async () => ({ data: null })) as unknown as DataProvider["update"] });
245
- render(<NativeResourceWorkspace workspace={workspace} row={brand} section="settings" />, { wrapper: wrap(p) });
245
+ render(<NativeRecordView view={page} row={brand} section="settings" />, { wrapper: wrap(p) });
246
246
  fireEvent.change(screen.getByTestId("native-resource-workspace-settings-website-input"), { target: { value: "https://x.example" } });
247
247
  fireEvent.click(screen.getByTestId("native-resource-workspace-settings-save"));
248
248
  expect((await screen.findByTestId("native-resource-workspace-settings-refusal")).textContent).toContain("This brand was not changed.");
249
249
  });
250
250
  });
251
251
 
252
- describe("NativeResourceWorkspace review fixes", () => {
253
- const locking = defineWorkspace(
252
+ describe("NativeRecordView review fixes", () => {
253
+ const locking = defineRecordView(
254
254
  defineView(brands, {
255
255
  fields: { website: { visible: (v) => v["public"] === true } },
256
256
  can: { update: (b) => (b.is_default ? "Locked." : true) },
@@ -259,14 +259,14 @@ describe("NativeResourceWorkspace review fixes", () => {
259
259
  );
260
260
 
261
261
  it("shows settings read-only with the reason when the view refuses update", () => {
262
- render(<NativeResourceWorkspace workspace={locking} row={brand} />, { wrapper: wrap(provider()) });
262
+ render(<NativeRecordView view={locking} row={brand} />, { wrapper: wrap(provider()) });
263
263
  expect(screen.getByTestId("native-resource-workspace-settings-locked").textContent).toContain("Locked.");
264
264
  expect(screen.queryByTestId("native-resource-workspace-settings-save")).toBeNull();
265
265
  });
266
266
 
267
267
  it("leaves a field hidden by `visible` out of the save", async () => {
268
268
  const p = provider();
269
- render(<NativeResourceWorkspace workspace={locking} row={{ ...brand, is_default: false, public: true }} />, { wrapper: wrap(p) });
269
+ render(<NativeRecordView view={locking} row={{ ...brand, is_default: false, public: true }} />, { wrapper: wrap(p) });
270
270
  fireEvent.change(screen.getByTestId("native-resource-workspace-settings-website-input"), { target: { value: "https://x.example" } });
271
271
  fireEvent.change(screen.getByTestId("native-resource-workspace-settings-name-input"), { target: { value: "Southwind" } });
272
272
  fireEvent.click(screen.getByTestId("native-resource-workspace-settings-public-input"));
@@ -276,8 +276,8 @@ describe("NativeResourceWorkspace review fixes", () => {
276
276
  });
277
277
 
278
278
  it("opens a section in place with a way back when there are more than four and no onOpenSection", () => {
279
- const wide = defineWorkspace(brandsView, { sections: ["a", "b", "c", "d", "e"].map((id) => ({ id, label: id.toUpperCase() })) });
280
- render(<NativeResourceWorkspace workspace={wide} row={brand} slots={{ e: <p>Section E</p> }} />, { wrapper: wrap(provider()) });
279
+ const wide = defineRecordView(brandsView, { sections: ["a", "b", "c", "d", "e"].map((id) => ({ id, label: id.toUpperCase() })) });
280
+ render(<NativeRecordView view={wide} row={brand} slots={{ e: <p>Section E</p> }} />, { wrapper: wrap(provider()) });
281
281
  fireEvent.click(screen.getByTestId("native-resource-workspace-section-e"));
282
282
  expect(screen.getByText("Section E")).toBeTruthy();
283
283
  fireEvent.click(screen.getByTestId("native-resource-workspace-all-sections"));
@@ -294,9 +294,9 @@ describe("NativeResourceWorkspace review fixes", () => {
294
294
  });
295
295
  });
296
296
 
297
- describe("NativeResourceWorkspace when only the viewer's roles change", () => {
297
+ describe("NativeRecordView when only the viewer's roles change", () => {
298
298
  const isEditor = (v?: Viewer) => ((v?.roles as { teamRoles?: readonly string[] } | undefined)?.teamRoles ?? []).includes("editor");
299
- const guarded = defineWorkspace(
299
+ const guarded = defineRecordView(
300
300
  defineView(brands, {
301
301
  can: { update: (_b, v) => (isEditor(v) ? true : "Only editors change brands.") },
302
302
  actions: [{ name: "publish", label: "Publish", can: (_b, v) => (isEditor(v) ? true : "Only editors publish.") }],
@@ -318,8 +318,8 @@ describe("NativeResourceWorkspace when only the viewer's roles change", () => {
318
318
  <Base>
319
319
  <ViewerScope viewer="ann" roles={roles as never}>
320
320
  <Mounts />
321
- <NativeResourceWorkspaceMenu workspace={guarded} row={brand} />
322
- <NativeResourceWorkspace workspace={guarded} row={brand} />
321
+ <NativeRecordViewMenu view={guarded} row={brand} />
322
+ <NativeRecordView view={guarded} row={brand} />
323
323
  </ViewerScope>
324
324
  </Base>
325
325
  );
@@ -529,6 +529,51 @@ describe("form sheet", () => {
529
529
  });
530
530
  });
531
531
 
532
+ it("treats an empty input as the web form does, from the contract's facts", () => {
533
+ type Known = { id: string; name: string; code: string; made_by: string; notes: string | null; due_on: string | null };
534
+ const known = defineResource<Known>()({
535
+ name: "known",
536
+ key: "id",
537
+ labelField: "name",
538
+ fields: [
539
+ { name: "id", type: "string", hasDefault: true },
540
+ { name: "name", type: "string", nullable: false },
541
+ { name: "code", type: "string", nullable: false, optional: true },
542
+ { name: "made_by", type: "string", nullable: false, hasDefault: true },
543
+ { name: "notes", type: "string", nullable: true },
544
+ { name: "due_on", type: "datetime", dbType: "date", nullable: true },
545
+ ],
546
+ });
547
+ const knownView = defineView(known, { form: ["name", "code", "made_by", "notes", "due_on"] });
548
+ const blank = { name: "a", code: "", made_by: "", notes: "", due_on: "" };
549
+ const create = formFieldsFor(knownView, "create");
550
+ expect(create.find((f) => f.key === "notes")).toMatchObject({ nullable: true });
551
+ expect(create.find((f) => f.key === "made_by")).toMatchObject({ nullable: false, hasDefault: true });
552
+ // A create leaves blanks out (defaults apply); a not-null text without a default keeps "".
553
+ expect(writableValues(knownView, "create", create, blank)).toEqual({ name: "a", code: "" });
554
+ expect(writableValues(knownView, "edit", formFieldsFor(knownView, "edit"), blank)).toEqual({
555
+ name: "a", code: "", made_by: "", notes: null, due_on: null,
556
+ });
557
+ });
558
+
559
+ it("sends a list filter as `in`, and a create never takes it", async () => {
560
+ const p = provider();
561
+ const getList = vi.spyOn(p, "getList");
562
+ const { result } = renderHook(() => useNativeResourceView(plainView, { filter: { status: ["active", "archived"], practice_id: "p1" } }), {
563
+ wrapper: wrap(p),
564
+ });
565
+ await waitFor(() => expect(getList).toHaveBeenCalled());
566
+ expect(getList.mock.calls.at(-1)![1].filters).toEqual(
567
+ expect.arrayContaining([
568
+ { field: "status", operator: "in", value: ["active", "archived"] },
569
+ { field: "practice_id", operator: "eq", value: "p1" },
570
+ ]),
571
+ );
572
+ expect(result.current.formFields("create").some((f) => f.key === "practice_id")).toBe(false);
573
+ expect(result.current.formFields("create").some((f) => f.key === "status")).toBe(true);
574
+ expect(screenValues({ status: ["a"], practice_id: "p1" })).toEqual({ practice_id: "p1" });
575
+ });
576
+
532
577
  it("shows an empty date as a button to add one, and a set date can be cleared", async () => {
533
578
  render(<NativeResourceView view={plainView} />, { wrapper: wrap(provider()) });
534
579
  fireEvent.click(await screen.findByTestId("native-resource-view-create"));
@@ -50,13 +50,20 @@ export {
50
50
  } from "./mapping";
51
51
  export { defaultNativeResourceViewMessages, type NativeResourceViewMessages } from "./messages";
52
52
  export {
53
+ NativeRecordView,
54
+ NativeRecordViewMenu,
55
+ getNativeRecordViewStackOptions,
56
+ defaultNativeRecordViewMessages,
57
+ SEGMENTED_SECTIONS_MAX,
58
+ parseSettingNumber,
59
+ type NativeRecordViewProps,
60
+ type NativeRecordViewHeaderProps,
61
+ type NativeRecordViewMessages,
53
62
  NativeResourceWorkspace,
54
63
  NativeResourceWorkspaceMenu,
55
64
  getNativeResourceWorkspaceStackOptions,
56
65
  defaultNativeResourceWorkspaceMessages,
57
- SEGMENTED_SECTIONS_MAX,
58
- parseSettingNumber,
59
66
  type NativeResourceWorkspaceProps,
60
67
  type NativeResourceWorkspaceHeaderProps,
61
68
  type NativeResourceWorkspaceMessages,
62
- } from "./NativeResourceWorkspace";
69
+ } from "./NativeRecordView";
@@ -196,6 +196,10 @@ export interface NativeFormField {
196
196
  required: boolean;
197
197
  /** Shown as text, never as an input, and never sent. */
198
198
  readOnly: boolean;
199
+ /** From the contract: the column takes null. Unset when the contract doesn't say. */
200
+ nullable?: boolean;
201
+ /** From the contract: the column has a default (or is generated). */
202
+ hasDefault?: boolean;
199
203
  max?: number;
200
204
  options?: { value: string; label: string }[];
201
205
  /** For a link: what it points at and the linked row's naming field, so it shows the row's words. */
@@ -259,6 +263,8 @@ export function formFieldsFor<T extends Row>(view: AnyResourceView<T>, mode: "cr
259
263
  display: f.display,
260
264
  required: !readOnly && f.required,
261
265
  readOnly,
266
+ ...(typeof f.field.nullable === "boolean" ? { nullable: f.field.nullable } : {}),
267
+ ...(f.field.hasDefault || f.field.generated ? { hasDefault: true } : {}),
262
268
  ...(f.max !== undefined ? { max: f.max } : {}),
263
269
  ...(options ? { options } : {}),
264
270
  ...(f.field.references ? { references: f.field.references } : {}),
@@ -295,11 +301,22 @@ export function writableValues<T extends Row>(
295
301
  if (field.readOnly || !writable.has(field.key)) continue;
296
302
  if (dirty && !dirty.has(field.key)) continue;
297
303
  const value = values[field.key];
298
- out[field.key] = (value === "" || value === undefined) && !field.required ? null : value;
304
+ if ((value !== "" && value !== undefined) || field.required) {
305
+ out[field.key] = value;
306
+ continue;
307
+ }
308
+ // Empty, as the web form treats it: a text column the contract says can't be null keeps ""
309
+ // (on a create, only without a default); otherwise a create leaves it out, so the column's
310
+ // default applies, and an edit clears it. Without the contract's word, null, as before.
311
+ if (field.nullable === undefined) out[field.key] = null;
312
+ else if (TEXT_KINDS.has(field.kind) && !field.nullable && !(mode === "create" && field.hasDefault)) out[field.key] = "";
313
+ else if (mode === "edit") out[field.key] = null;
299
314
  }
300
315
  return out;
301
316
  }
302
317
 
318
+ const TEXT_KINDS: ReadonlySet<NativeFormFieldKind> = new Set(["text", "email", "url", "textarea"]);
319
+
303
320
  /** Field errors for a save: required fields with no value, and text over `max`. */
304
321
  export function validateValues(
305
322
  fields: readonly NativeFormField[],
@@ -28,7 +28,7 @@ import {
28
28
  import { fill } from "./messages";
29
29
 
30
30
  type Row = Record<string, unknown>;
31
- type Filter = Readonly<Record<string, string | number | boolean | null>>;
31
+ type Filter = Readonly<Record<string, string | number | boolean | null | readonly (string | number)[]>>;
32
32
 
33
33
  /** How long typing waits before the search goes to the server. */
34
34
  export const SEARCH_DEBOUNCE_MS = 300;
@@ -37,7 +37,8 @@ export interface NativeResourceViewOptions<T extends Row = Row> {
37
37
  /** A tab the view defines: its server filter. */
38
38
  preset?: string;
39
39
  /**
40
- * Equality filters sent to the server (`{ client_id: id }`); `null` means "is empty". A create
40
+ * Filters sent to the server (`{ client_id: id }`); `null` means "is empty" and a list means
41
+ * "any of" (`{ status: ["open", "blocked"] }`, sent as `in`; a create never takes a list). A create
41
42
  * also saves every non-null value here (a tab's filter too), even for read-only fields such as
42
43
  * a required link: they come from the screen, never from an input. An edit never sends them.
43
44
  */
@@ -107,8 +108,12 @@ export interface UseNativeResourceViewReturn<T extends Row = Row> {
107
108
  }
108
109
 
109
110
  function filterParams(filter: Filter | undefined): FilterParam[] {
110
- return Object.entries(filter ?? {}).map(([field, value]) =>
111
- value === null ? { field, operator: "is_null" as const } : { field, operator: "eq" as const, value },
111
+ return Object.entries(filter ?? {}).map(([field, value]): FilterParam =>
112
+ value === null
113
+ ? { field, operator: "is_null" }
114
+ : Array.isArray(value)
115
+ ? { field, operator: "in", value: [...(value as readonly (string | number)[])] }
116
+ : { field, operator: "eq", value: value as string | number | boolean },
112
117
  );
113
118
  }
114
119
 
@@ -116,7 +121,9 @@ function filterParams(filter: Filter | undefined): FilterParam[] {
116
121
  export function screenValues(...filters: (Filter | undefined)[]): Record<string, string | number | boolean> {
117
122
  const out: Record<string, string | number | boolean> = {};
118
123
  for (const filter of filters) {
119
- for (const [field, value] of Object.entries(filter ?? {})) if (value !== null) out[field] = value;
124
+ for (const [field, value] of Object.entries(filter ?? {})) {
125
+ if (value !== null && !Array.isArray(value)) out[field] = value as string | number | boolean;
126
+ }
120
127
  }
121
128
  return out;
122
129
  }
@@ -156,7 +163,12 @@ export function useNativeResourceView<T extends Row = Row>(
156
163
 
157
164
  // ── Reads: cursor pages, server filters, server search ──────────────────
158
165
  const tabFilter = tab?.filter as Filter | undefined;
159
- const defaultFilters = useMemo(() => [...filterParams(tabFilter), ...filterParams(filter)], [tabFilter, filter]);
166
+ // By value: an inline `filter={{ status: ["open", "done"] }}` is one list, not a new one per render.
167
+ const filterKey = JSON.stringify(filter ?? {});
168
+ const defaultFilters = useMemo(
169
+ () => [...filterParams(tabFilter), ...filterParams(JSON.parse(filterKey) as Filter)],
170
+ [tabFilter, filterKey],
171
+ );
160
172
  // By value, so an inline `filter={{ client_id }}` doesn't rebuild the form every render.
161
173
  const createKey = JSON.stringify(screenValues(tabFilter, filter));
162
174
  const createDefaults = useMemo(() => JSON.parse(createKey) as Record<string, string | number | boolean>, [createKey]);