@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/dist/data/index.d.ts
CHANGED
|
@@ -274,6 +274,10 @@ interface NativeFormField {
|
|
|
274
274
|
required: boolean;
|
|
275
275
|
/** Shown as text, never as an input, and never sent. */
|
|
276
276
|
readOnly: boolean;
|
|
277
|
+
/** From the contract: the column takes null. Unset when the contract doesn't say. */
|
|
278
|
+
nullable?: boolean;
|
|
279
|
+
/** From the contract: the column has a default (or is generated). */
|
|
280
|
+
hasDefault?: boolean;
|
|
277
281
|
max?: number;
|
|
278
282
|
options?: {
|
|
279
283
|
value: string;
|
|
@@ -306,14 +310,15 @@ declare function writableValues<T extends Row$3>(view: AnyResourceView<T>, mode:
|
|
|
306
310
|
declare function validateValues(fields: readonly NativeFormField[], values: Readonly<Record<string, unknown>>, messages: NativeResourceViewMessages): Record<string, string>;
|
|
307
311
|
|
|
308
312
|
type Row$2 = Record<string, unknown>;
|
|
309
|
-
type Filter = Readonly<Record<string, string | number | boolean | null>>;
|
|
313
|
+
type Filter = Readonly<Record<string, string | number | boolean | null | readonly (string | number)[]>>;
|
|
310
314
|
/** How long typing waits before the search goes to the server. */
|
|
311
315
|
declare const SEARCH_DEBOUNCE_MS = 300;
|
|
312
316
|
interface NativeResourceViewOptions<T extends Row$2 = Row$2> {
|
|
313
317
|
/** A tab the view defines: its server filter. */
|
|
314
318
|
preset?: string;
|
|
315
319
|
/**
|
|
316
|
-
*
|
|
320
|
+
* Filters sent to the server (`{ client_id: id }`); `null` means "is empty" and a list means
|
|
321
|
+
* "any of" (`{ status: ["open", "blocked"] }`, sent as `in`; a create never takes a list). A create
|
|
317
322
|
* also saves every non-null value here (a tab's filter too), even for read-only fields such as
|
|
318
323
|
* a required link: they come from the screen, never from an input. An edit never sends them.
|
|
319
324
|
*/
|
|
@@ -431,10 +436,11 @@ interface NativeResourceViewProps<T extends Row$1 = Row$1> extends NativeResourc
|
|
|
431
436
|
/** Hide the search box. Shown by default when the view has something to search. */
|
|
432
437
|
searchable?: boolean;
|
|
433
438
|
/**
|
|
434
|
-
* The
|
|
435
|
-
*
|
|
439
|
+
* The IANA zone of whatever this screen is scoped to (a location, a league, a team), for columns
|
|
440
|
+
* with `timeZone: "scope"`. Default: ViewerScope's `scopeTimeZone`, else the viewer's clock.
|
|
441
|
+
* Timestamps on other columns read on the viewer's clock (ViewerScope's zone, else the device's).
|
|
436
442
|
*/
|
|
437
|
-
|
|
443
|
+
scopeTimeZone?: string;
|
|
438
444
|
testID?: string;
|
|
439
445
|
}
|
|
440
446
|
/**
|
|
@@ -465,10 +471,11 @@ interface NativeResourceFormSheetProps {
|
|
|
465
471
|
}
|
|
466
472
|
declare function NativeResourceFormSheet({ open, mode, title, fields, initial, loading, recordKey, onCancel, onSave, testID, }: NativeResourceFormSheetProps): react.JSX.Element;
|
|
467
473
|
|
|
468
|
-
/** The clocks a timestamp can be read on: the viewer's and the
|
|
474
|
+
/** The clocks a timestamp can be read on: the viewer's and the scope's (IANA names). */
|
|
469
475
|
interface DisplayTimeZones {
|
|
470
476
|
viewer: string;
|
|
471
|
-
|
|
477
|
+
/** The zone of whatever the screen is scoped to (a location, a league, a team): `timeZone: "scope"`. */
|
|
478
|
+
scope: string;
|
|
472
479
|
}
|
|
473
480
|
/** What a renderer gets besides the value (as on the web, with native's messages and clocks). */
|
|
474
481
|
interface DisplayContext {
|
|
@@ -489,7 +496,11 @@ declare function dateToDay(date: Date): string;
|
|
|
489
496
|
* clock (core's `wallClock`), so an 8pm edit in New York isn't tomorrow's (its UTC day).
|
|
490
497
|
*/
|
|
491
498
|
declare function formatDay(value: unknown, zone?: string): string;
|
|
492
|
-
/**
|
|
499
|
+
/**
|
|
500
|
+
* A column's clock: "viewer" (the default) and "scope" from `zones`, else a valid IANA name.
|
|
501
|
+
* Anything else throws (`defineView` refuses it first): drawing it on the viewer's clock instead
|
|
502
|
+
* would show the wrong times with nothing to say so.
|
|
503
|
+
*/
|
|
493
504
|
declare function resolveZone(zone: string | undefined, zones: DisplayTimeZones): string;
|
|
494
505
|
/** A timestamp as the clock on the wall in `zone` shows it (core's `wallClock`), not the device's. */
|
|
495
506
|
declare function formatInstant(value: unknown, zone: string): string;
|
package/dist/data/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { createContext, memo, useState, useCallback, useMemo, useEffect, useCont
|
|
|
12
12
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
13
13
|
import { titleCase, useResourceForm, resourceKeys, useDataProvider, useViewer as useViewer$1, encodeRecordKey, useCapabilities as useCapabilities$1, DataWriteError } from '@marktiderman/genesis-core';
|
|
14
14
|
import { Controller, useForm } from 'react-hook-form';
|
|
15
|
-
import { useRelationLabel, useResource, useViewer, useInfiniteResource, useCapabilities, useOptionalViewerScope, useOne } from '@marktiderman/genesis-core/hooks';
|
|
15
|
+
import { useRelationLabel, useResource, useViewer, useInfiniteResource, useCapabilities, useOptionalViewerScope, scopeClock, useOne } from '@marktiderman/genesis-core/hooks';
|
|
16
16
|
import { personTimeZone, isTimeZone, wallClock } from '@marktiderman/genesis-core/dates';
|
|
17
17
|
import { isSafeUrl } from '@marktiderman/genesis-core/urls';
|
|
18
18
|
import { valueText, rowPicture } from '@marktiderman/genesis-core/resource-view';
|
|
@@ -882,8 +882,11 @@ function formatDay(value, zone = personTimeZone()) {
|
|
|
882
882
|
}
|
|
883
883
|
function resolveZone(zone, zones) {
|
|
884
884
|
if (!zone || zone === "viewer") return zones.viewer;
|
|
885
|
-
if (zone === "
|
|
886
|
-
|
|
885
|
+
if (zone === "scope") return zones.scope;
|
|
886
|
+
if (isTimeZone(zone)) return zone;
|
|
887
|
+
throw new RangeError(
|
|
888
|
+
zone === "practice" ? `[genesis-ui-native] timeZone "practice" was renamed "scope" in genesis-core 2; run \`genesis codemod genesis-core-2-scope-names\`` : `[genesis-ui-native] timeZone "${zone}" isn't "viewer", "scope" or a time zone this runtime knows`
|
|
889
|
+
);
|
|
887
890
|
}
|
|
888
891
|
var WALL = new Intl.DateTimeFormat(void 0, { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" });
|
|
889
892
|
function formatInstant(value, zone) {
|
|
@@ -986,7 +989,7 @@ var TimeZonesContext = createContext(null);
|
|
|
986
989
|
var DisplayTimeZonesProvider = TimeZonesContext.Provider;
|
|
987
990
|
function useDisplayTimeZones() {
|
|
988
991
|
const zones = useContext(TimeZonesContext);
|
|
989
|
-
return useMemo(() => zones ?? { viewer: personTimeZone(),
|
|
992
|
+
return useMemo(() => zones ?? { viewer: personTimeZone(), scope: personTimeZone() }, [zones]);
|
|
990
993
|
}
|
|
991
994
|
function DisplayRenderersProvider({
|
|
992
995
|
renderers,
|
|
@@ -1120,6 +1123,8 @@ function formFieldsFor(view, mode) {
|
|
|
1120
1123
|
display: f.display,
|
|
1121
1124
|
required: !readOnly && f.required,
|
|
1122
1125
|
readOnly,
|
|
1126
|
+
...typeof f.field.nullable === "boolean" ? { nullable: f.field.nullable } : {},
|
|
1127
|
+
...f.field.hasDefault || f.field.generated ? { hasDefault: true } : {},
|
|
1123
1128
|
...f.max !== void 0 ? { max: f.max } : {},
|
|
1124
1129
|
...options ? { options } : {},
|
|
1125
1130
|
...f.field.references ? { references: f.field.references } : {},
|
|
@@ -1141,10 +1146,17 @@ function writableValues(view, mode, fields, values, dirty) {
|
|
|
1141
1146
|
if (field.readOnly || !writable.has(field.key)) continue;
|
|
1142
1147
|
if (dirty && !dirty.has(field.key)) continue;
|
|
1143
1148
|
const value = values[field.key];
|
|
1144
|
-
|
|
1149
|
+
if (value !== "" && value !== void 0 || field.required) {
|
|
1150
|
+
out[field.key] = value;
|
|
1151
|
+
continue;
|
|
1152
|
+
}
|
|
1153
|
+
if (field.nullable === void 0) out[field.key] = null;
|
|
1154
|
+
else if (TEXT_KINDS.has(field.kind) && !field.nullable && !(mode === "create" && field.hasDefault)) out[field.key] = "";
|
|
1155
|
+
else if (mode === "edit") out[field.key] = null;
|
|
1145
1156
|
}
|
|
1146
1157
|
return out;
|
|
1147
1158
|
}
|
|
1159
|
+
var TEXT_KINDS = /* @__PURE__ */ new Set(["text", "email", "url", "textarea"]);
|
|
1148
1160
|
function validateValues(fields, values, messages) {
|
|
1149
1161
|
const errors = {};
|
|
1150
1162
|
for (const field of shownFields(fields, values)) {
|
|
@@ -1385,13 +1397,15 @@ function DateField({
|
|
|
1385
1397
|
var SEARCH_DEBOUNCE_MS = 300;
|
|
1386
1398
|
function filterParams(filter) {
|
|
1387
1399
|
return Object.entries(filter ?? {}).map(
|
|
1388
|
-
([field, value]) => value === null ? { field, operator: "is_null" } : { field, operator: "eq", value }
|
|
1400
|
+
([field, value]) => value === null ? { field, operator: "is_null" } : Array.isArray(value) ? { field, operator: "in", value: [...value] } : { field, operator: "eq", value }
|
|
1389
1401
|
);
|
|
1390
1402
|
}
|
|
1391
1403
|
function screenValues(...filters) {
|
|
1392
1404
|
const out = {};
|
|
1393
1405
|
for (const filter of filters) {
|
|
1394
|
-
for (const [field, value] of Object.entries(filter ?? {}))
|
|
1406
|
+
for (const [field, value] of Object.entries(filter ?? {})) {
|
|
1407
|
+
if (value !== null && !Array.isArray(value)) out[field] = value;
|
|
1408
|
+
}
|
|
1395
1409
|
}
|
|
1396
1410
|
return out;
|
|
1397
1411
|
}
|
|
@@ -1413,7 +1427,11 @@ function useNativeResourceView(view, options = {}) {
|
|
|
1413
1427
|
const tab = preset ? view.definition.presets?.[preset] : void 0;
|
|
1414
1428
|
if (preset && !tab) throw new Error(`NativeResourceView(${view.resource}): no preset "${preset}"`);
|
|
1415
1429
|
const tabFilter = tab?.filter;
|
|
1416
|
-
const
|
|
1430
|
+
const filterKey = JSON.stringify(filter ?? {});
|
|
1431
|
+
const defaultFilters = useMemo(
|
|
1432
|
+
() => [...filterParams(tabFilter), ...filterParams(JSON.parse(filterKey))],
|
|
1433
|
+
[tabFilter, filterKey]
|
|
1434
|
+
);
|
|
1417
1435
|
const createKey = JSON.stringify(screenValues(tabFilter, filter));
|
|
1418
1436
|
const createDefaults = useMemo(() => JSON.parse(createKey), [createKey]);
|
|
1419
1437
|
const sorts = useMemo(() => serverSorts(view), [view]);
|
|
@@ -1554,11 +1572,11 @@ var recordKey = (view, row) => {
|
|
|
1554
1572
|
function NativeResourceView(props) {
|
|
1555
1573
|
const scope = useOptionalViewerScope();
|
|
1556
1574
|
const viewer = scope?.timeZone;
|
|
1557
|
-
const
|
|
1575
|
+
const scopeZone = props.scopeTimeZone ?? scope?.scopeTimeZone;
|
|
1558
1576
|
const zones = useMemo(() => {
|
|
1559
1577
|
const own = personTimeZone({ timeZone: viewer });
|
|
1560
|
-
return { viewer: own,
|
|
1561
|
-
}, [viewer,
|
|
1578
|
+
return { viewer: own, scope: scopeClock(scopeZone, own) };
|
|
1579
|
+
}, [viewer, scopeZone]);
|
|
1562
1580
|
return /* @__PURE__ */ jsx(DisplayTimeZonesProvider, { value: zones, children: /* @__PURE__ */ jsx(Screen, { ...props }) });
|
|
1563
1581
|
}
|
|
1564
1582
|
var PICTURE_SIZE = 40;
|
|
@@ -1661,7 +1679,7 @@ function Screen(props) {
|
|
|
1661
1679
|
header,
|
|
1662
1680
|
emptyState,
|
|
1663
1681
|
searchable,
|
|
1664
|
-
|
|
1682
|
+
scopeTimeZone: _zone,
|
|
1665
1683
|
testID = "native-resource-view",
|
|
1666
1684
|
...options
|
|
1667
1685
|
} = props;
|