@marktiderman/genesis-ui-native 2.9.0 → 3.1.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/dist/data/index.d.ts +19 -8
- package/dist/data/index.js +30 -12
- package/dist/data/index.js.map +1 -1
- package/package.json +51 -3
- package/src/data/resource-view/NativeResourceView.tsx +11 -9
- package/src/data/resource-view/__tests__/native-resource-view.test.tsx +73 -10
- package/src/data/resource-view/display.tsx +16 -6
- package/src/data/resource-view/mapping.ts +18 -1
- package/src/data/resource-view/use-native-resource-view.ts +18 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktiderman/genesis-ui-native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"@expo/ui": ">=58.0.0",
|
|
70
70
|
"@gorhom/bottom-sheet": ">=5.0.0",
|
|
71
71
|
"@hookform/resolvers": "^3.0.0 || ^4.0.0 || ^5.0.0",
|
|
72
|
-
"@marktiderman/genesis-core": "^1.
|
|
73
|
-
"@marktiderman/genesis-design-system": "^1.5.
|
|
72
|
+
"@marktiderman/genesis-core": "^2.1.0",
|
|
73
|
+
"@marktiderman/genesis-design-system": "^1.5.1",
|
|
74
74
|
"@react-native-community/datetimepicker": ">=8.0.0",
|
|
75
75
|
"@shopify/flash-list": ">=2.0.0",
|
|
76
76
|
"@tanstack/react-query": "^5.0.0",
|
|
@@ -146,6 +146,54 @@
|
|
|
146
146
|
"typescript": "~6.0.3",
|
|
147
147
|
"vitest": "^4.1.12"
|
|
148
148
|
},
|
|
149
|
+
"genesis": {
|
|
150
|
+
"doctor": {
|
|
151
|
+
"prefer": [
|
|
152
|
+
{
|
|
153
|
+
"id": "lists-use-native-resource-view",
|
|
154
|
+
"need": "a list screen on the phone",
|
|
155
|
+
"level": "warn",
|
|
156
|
+
"platform": "native",
|
|
157
|
+
"newOnly": true,
|
|
158
|
+
"files": [
|
|
159
|
+
"**/*.tsx",
|
|
160
|
+
"**/*.jsx"
|
|
161
|
+
],
|
|
162
|
+
"forbid": {
|
|
163
|
+
"jsx": [
|
|
164
|
+
"FlatList",
|
|
165
|
+
"SectionList",
|
|
166
|
+
"NativeResourcePage"
|
|
167
|
+
]
|
|
168
|
+
},
|
|
169
|
+
"unless": {
|
|
170
|
+
"renders": [
|
|
171
|
+
"NativeResourceView",
|
|
172
|
+
"NativeResourceWorkspace"
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
"use": "the web screen's view (defineView) rendered by <NativeResourceView>",
|
|
176
|
+
"import": "@marktiderman/genesis-ui-native/data",
|
|
177
|
+
"docs": "https://github.com/marktiderman/genesis/blob/main/docs/RESOURCE-VIEW.md#native",
|
|
178
|
+
"why": "The phone list comes from the same view as the web list: one description, two surfaces, no second set of helpers."
|
|
179
|
+
}
|
|
180
|
+
],
|
|
181
|
+
"primitives": [
|
|
182
|
+
{
|
|
183
|
+
"need": "a phone screen",
|
|
184
|
+
"use": "ScreenContainer, or a …Page / …Screen layout",
|
|
185
|
+
"import": "@marktiderman/genesis-ui-native/layouts",
|
|
186
|
+
"docs": "https://github.com/marktiderman/genesis/blob/main/packages/ui-native/README.md"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
"need": "a record page on the phone",
|
|
190
|
+
"use": "NativeResourceWorkspace",
|
|
191
|
+
"import": "@marktiderman/genesis-ui-native/data",
|
|
192
|
+
"docs": "https://github.com/marktiderman/genesis/blob/main/docs/RESOURCE-VIEW.md#resourceworkspace"
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
},
|
|
149
197
|
"scripts": {
|
|
150
198
|
"build": "tsup",
|
|
151
199
|
"dev": "tsup --watch",
|
|
@@ -17,8 +17,8 @@ import { memo, useCallback, useMemo, useRef, useState, type ComponentType, type
|
|
|
17
17
|
import { Alert, Platform, Pressable, SectionList, View } from "react-native";
|
|
18
18
|
import { SafeAreaView } from "react-native-safe-area-context";
|
|
19
19
|
import { encodeRecordKey, type BaseRecord, type DataRow } from "@marktiderman/genesis-core";
|
|
20
|
-
import {
|
|
21
|
-
import { useOne, useOptionalViewerScope } from "@marktiderman/genesis-core/hooks";
|
|
20
|
+
import { personTimeZone } from "@marktiderman/genesis-core/dates";
|
|
21
|
+
import { scopeClock, useOne, useOptionalViewerScope } from "@marktiderman/genesis-core/hooks";
|
|
22
22
|
import type { RowPicture } from "@marktiderman/genesis-core/resource-view";
|
|
23
23
|
import { NativeAvatar } from "../../components/avatar";
|
|
24
24
|
import { NativeBadge } from "../../components/badge";
|
|
@@ -78,10 +78,11 @@ export interface NativeResourceViewProps<T extends Row = Row> extends NativeReso
|
|
|
78
78
|
/** Hide the search box. Shown by default when the view has something to search. */
|
|
79
79
|
searchable?: boolean;
|
|
80
80
|
/**
|
|
81
|
-
* The
|
|
82
|
-
*
|
|
81
|
+
* The IANA zone of whatever this screen is scoped to (a location, a league, a team), for columns
|
|
82
|
+
* with `timeZone: "scope"`. Default: ViewerScope's `scopeTimeZone`, else the viewer's clock.
|
|
83
|
+
* Timestamps on other columns read on the viewer's clock (ViewerScope's zone, else the device's).
|
|
83
84
|
*/
|
|
84
|
-
|
|
85
|
+
scopeTimeZone?: string;
|
|
85
86
|
testID?: string;
|
|
86
87
|
}
|
|
87
88
|
|
|
@@ -110,11 +111,12 @@ const recordKey = (view: AnyResourceView<Row>, row: Row) => {
|
|
|
110
111
|
export function NativeResourceView<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
111
112
|
const scope = useOptionalViewerScope();
|
|
112
113
|
const viewer = scope?.timeZone;
|
|
113
|
-
const
|
|
114
|
+
const scopeZone = props.scopeTimeZone ?? scope?.scopeTimeZone;
|
|
114
115
|
const zones = useMemo<DisplayTimeZones>(() => {
|
|
115
116
|
const own = personTimeZone({ timeZone: viewer });
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
// An unknown zone is loud (core's scopeClock), never a quiet fall back to the viewer's clock.
|
|
118
|
+
return { viewer: own, scope: scopeClock(scopeZone, own) };
|
|
119
|
+
}, [viewer, scopeZone]);
|
|
118
120
|
return (
|
|
119
121
|
<DisplayTimeZonesProvider value={zones}>
|
|
120
122
|
<Screen {...props} />
|
|
@@ -256,7 +258,7 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
|
256
258
|
header,
|
|
257
259
|
emptyState,
|
|
258
260
|
searchable,
|
|
259
|
-
|
|
261
|
+
scopeTimeZone: _zone,
|
|
260
262
|
testID = "native-resource-view",
|
|
261
263
|
...options
|
|
262
264
|
} = props;
|
|
@@ -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"));
|
|
@@ -695,16 +740,32 @@ describe("peek", () => {
|
|
|
695
740
|
expect(alert).toHaveBeenLastCalledWith("Move to Bin", "The default brand stays.");
|
|
696
741
|
});
|
|
697
742
|
|
|
698
|
-
it("reads a
|
|
743
|
+
it("reads a scope-clock column on the scope's zone: the prop, else ViewerScope's", async () => {
|
|
699
744
|
const clocked = defineView(brands, {
|
|
700
|
-
fields: { updated_at: { timeZone: "
|
|
745
|
+
fields: { updated_at: { timeZone: "scope" } },
|
|
701
746
|
columns: { default: ["name", "updated_at"] },
|
|
702
747
|
});
|
|
703
|
-
|
|
748
|
+
const at = "2026-01-02T10:00:00Z";
|
|
749
|
+
expect(formatInstant(at, "Asia/Tokyo")).not.toBe(formatInstant(at, "Europe/Berlin"));
|
|
750
|
+
|
|
751
|
+
const first = render(<NativeResourceView view={clocked} scopeTimeZone="Asia/Tokyo" />, { wrapper: wrap(provider()) });
|
|
752
|
+
fireEvent.click(await screen.findByTestId("native-resource-view-row-b2"));
|
|
753
|
+
expect((await screen.findByTestId("native-resource-view-peek")).textContent).toContain(formatInstant(at, "Asia/Tokyo"));
|
|
754
|
+
first.unmount();
|
|
755
|
+
|
|
756
|
+
// No prop: ViewerScope's scopeTimeZone.
|
|
757
|
+
const Base = wrap(provider());
|
|
758
|
+
render(<NativeResourceView view={clocked} />, {
|
|
759
|
+
wrapper: ({ children }: { children: ReactNode }) => (
|
|
760
|
+
<Base>
|
|
761
|
+
<ViewerScope viewer="ann" timeZone="America/Los_Angeles" scopeTimeZone="Europe/Berlin">
|
|
762
|
+
{children}
|
|
763
|
+
</ViewerScope>
|
|
764
|
+
</Base>
|
|
765
|
+
),
|
|
766
|
+
});
|
|
704
767
|
fireEvent.click(await screen.findByTestId("native-resource-view-row-b2"));
|
|
705
|
-
|
|
706
|
-
expect(peek.textContent).toContain(formatInstant("2026-01-02T10:00:00Z", "Asia/Tokyo"));
|
|
707
|
-
expect(formatInstant("2026-01-02T10:00:00Z", "Asia/Tokyo")).not.toBe(formatInstant("2026-01-02T10:00:00Z", "America/Los_Angeles"));
|
|
768
|
+
expect((await screen.findByTestId("native-resource-view-peek")).textContent).toContain(formatInstant(at, "Europe/Berlin"));
|
|
708
769
|
});
|
|
709
770
|
|
|
710
771
|
it("shows view.columns() drawn like the cells: a when-false value and a sensitive field never appear", async () => {
|
|
@@ -742,13 +803,15 @@ describe("calendar days", () => {
|
|
|
742
803
|
});
|
|
743
804
|
|
|
744
805
|
describe("clocks", () => {
|
|
745
|
-
it("resolves viewer and
|
|
746
|
-
const zones = { viewer: "America/Los_Angeles",
|
|
806
|
+
it("resolves viewer and scope to the given zones, and refuses anything else", () => {
|
|
807
|
+
const zones = { viewer: "America/Los_Angeles", scope: "Europe/Berlin" };
|
|
747
808
|
expect(resolveZone(undefined, zones)).toBe("America/Los_Angeles");
|
|
748
809
|
expect(resolveZone("viewer", zones)).toBe("America/Los_Angeles");
|
|
749
|
-
expect(resolveZone("
|
|
810
|
+
expect(resolveZone("scope", zones)).toBe("Europe/Berlin");
|
|
750
811
|
expect(resolveZone("Asia/Tokyo", zones)).toBe("Asia/Tokyo");
|
|
751
|
-
|
|
812
|
+
// Never a quiet fall back to the viewer's clock: the removed name and an unknown zone throw.
|
|
813
|
+
expect(() => resolveZone("practice", zones)).toThrow(/"practice" was renamed "scope"/);
|
|
814
|
+
expect(() => resolveZone("Not/AZone", zones)).toThrow(RangeError);
|
|
752
815
|
});
|
|
753
816
|
});
|
|
754
817
|
|
|
@@ -17,10 +17,11 @@ import { NativeImage } from "../../components/image";
|
|
|
17
17
|
import { NativeText } from "../../components/text";
|
|
18
18
|
import { defaultNativeResourceViewMessages, type NativeResourceViewMessages } from "./messages";
|
|
19
19
|
|
|
20
|
-
/** The clocks a timestamp can be read on: the viewer's and the
|
|
20
|
+
/** The clocks a timestamp can be read on: the viewer's and the scope's (IANA names). */
|
|
21
21
|
export interface DisplayTimeZones {
|
|
22
22
|
viewer: string;
|
|
23
|
-
|
|
23
|
+
/** The zone of whatever the screen is scoped to (a location, a league, a team): `timeZone: "scope"`. */
|
|
24
|
+
scope: string;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/** What a renderer gets besides the value (as on the web, with native's messages and clocks). */
|
|
@@ -76,11 +77,20 @@ export function formatDay(value: unknown, zone: string = personTimeZone()): stri
|
|
|
76
77
|
return DAY.format(new Date(wall.year, wall.month - 1, wall.day));
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* A column's clock: "viewer" (the default) and "scope" from `zones`, else a valid IANA name.
|
|
82
|
+
* Anything else throws (`defineView` refuses it first): drawing it on the viewer's clock instead
|
|
83
|
+
* would show the wrong times with nothing to say so.
|
|
84
|
+
*/
|
|
80
85
|
export function resolveZone(zone: string | undefined, zones: DisplayTimeZones): string {
|
|
81
86
|
if (!zone || zone === "viewer") return zones.viewer;
|
|
82
|
-
if (zone === "
|
|
83
|
-
|
|
87
|
+
if (zone === "scope") return zones.scope;
|
|
88
|
+
if (isTimeZone(zone)) return zone;
|
|
89
|
+
throw new RangeError(
|
|
90
|
+
zone === "practice"
|
|
91
|
+
? `[genesis-ui-native] timeZone "practice" was renamed "scope" in genesis-core 2; run \`genesis codemod genesis-core-2-scope-names\``
|
|
92
|
+
: `[genesis-ui-native] timeZone "${zone}" isn't "viewer", "scope" or a time zone this runtime knows`,
|
|
93
|
+
);
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
// The wall clock's parts are drawn as UTC, so one formatter serves every zone.
|
|
@@ -242,7 +252,7 @@ export const DisplayTimeZonesProvider = TimeZonesContext.Provider;
|
|
|
242
252
|
/** The clocks for timestamps: the nearest provider's, else the device's for both. */
|
|
243
253
|
export function useDisplayTimeZones(): DisplayTimeZones {
|
|
244
254
|
const zones = useContext(TimeZonesContext);
|
|
245
|
-
return useMemo(() => zones ?? { viewer: personTimeZone(),
|
|
255
|
+
return useMemo(() => zones ?? { viewer: personTimeZone(), scope: personTimeZone() }, [zones]);
|
|
246
256
|
}
|
|
247
257
|
|
|
248
258
|
/** Replace some of the renderers for everything below (nested providers build on each other). */
|
|
@@ -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
|
-
|
|
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
|
-
*
|
|
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
|
|
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 ?? {}))
|
|
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
|
-
|
|
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]);
|