@marktiderman/genesis-ui-native 2.8.1 → 3.0.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 +22 -7
- package/dist/data/index.js +30 -11
- package/dist/data/index.js.map +1 -1
- package/package.json +2 -2
- package/src/data/resource-view/NativeResourceFormSheet.tsx +17 -5
- package/src/data/resource-view/NativeResourceView.tsx +11 -9
- package/src/data/resource-view/__tests__/native-resource-view.test.tsx +66 -12
- package/src/data/resource-view/display.tsx +35 -9
- package/src/data/resource-view/mapping.ts +8 -1
- package/src/data/resource-view/messages.ts +6 -0
package/dist/data/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode, ComponentType } from 'react';
|
|
3
|
-
import { ResourceFormFieldDef, BaseRecord, DataRow, ResourceContract } from '@marktiderman/genesis-core';
|
|
3
|
+
import { ResourceFormFieldDef, BaseRecord, DataRow, FieldReference, ResourceContract } from '@marktiderman/genesis-core';
|
|
4
4
|
import { Control, UseFormReturn } from 'react-hook-form';
|
|
5
5
|
import { UseResourceOptions } from '@marktiderman/genesis-core/hooks';
|
|
6
6
|
import { d as InboxSwipeAction, c as InboxPageSlotMap, g as ScreenHeaderProps } from '../inbox-page-DZUR-PJ1.js';
|
|
@@ -132,6 +132,11 @@ interface NativeResourceViewMessages {
|
|
|
132
132
|
common: {
|
|
133
133
|
/** Shown for an empty value. */
|
|
134
134
|
empty: string;
|
|
135
|
+
/**
|
|
136
|
+
* A link whose row this viewer can't see, or that's gone (never its raw id). Optional, so a
|
|
137
|
+
* catalogue written before it still fits; the English is used when it's missing.
|
|
138
|
+
*/
|
|
139
|
+
hiddenLink?: string;
|
|
135
140
|
yes: string;
|
|
136
141
|
no: string;
|
|
137
142
|
cancel: string;
|
|
@@ -274,6 +279,10 @@ interface NativeFormField {
|
|
|
274
279
|
value: string;
|
|
275
280
|
label: string;
|
|
276
281
|
}[];
|
|
282
|
+
/** For a link: what it points at and the linked row's naming field, so it shows the row's words. */
|
|
283
|
+
references?: FieldReference;
|
|
284
|
+
labelField?: string;
|
|
285
|
+
missingLabel?: string;
|
|
277
286
|
/** The heading it sits under; null for the form's first, untitled group. */
|
|
278
287
|
section: string | null;
|
|
279
288
|
sectionTitle: string | null;
|
|
@@ -422,10 +431,11 @@ interface NativeResourceViewProps<T extends Row$1 = Row$1> extends NativeResourc
|
|
|
422
431
|
/** Hide the search box. Shown by default when the view has something to search. */
|
|
423
432
|
searchable?: boolean;
|
|
424
433
|
/**
|
|
425
|
-
* The
|
|
426
|
-
*
|
|
434
|
+
* The IANA zone of whatever this screen is scoped to (a location, a league, a team), for columns
|
|
435
|
+
* with `timeZone: "scope"`. Default: ViewerScope's `scopeTimeZone`, else the viewer's clock.
|
|
436
|
+
* Timestamps on other columns read on the viewer's clock (ViewerScope's zone, else the device's).
|
|
427
437
|
*/
|
|
428
|
-
|
|
438
|
+
scopeTimeZone?: string;
|
|
429
439
|
testID?: string;
|
|
430
440
|
}
|
|
431
441
|
/**
|
|
@@ -456,10 +466,11 @@ interface NativeResourceFormSheetProps {
|
|
|
456
466
|
}
|
|
457
467
|
declare function NativeResourceFormSheet({ open, mode, title, fields, initial, loading, recordKey, onCancel, onSave, testID, }: NativeResourceFormSheetProps): react.JSX.Element;
|
|
458
468
|
|
|
459
|
-
/** The clocks a timestamp can be read on: the viewer's and the
|
|
469
|
+
/** The clocks a timestamp can be read on: the viewer's and the scope's (IANA names). */
|
|
460
470
|
interface DisplayTimeZones {
|
|
461
471
|
viewer: string;
|
|
462
|
-
|
|
472
|
+
/** The zone of whatever the screen is scoped to (a location, a league, a team): `timeZone: "scope"`. */
|
|
473
|
+
scope: string;
|
|
463
474
|
}
|
|
464
475
|
/** What a renderer gets besides the value (as on the web, with native's messages and clocks). */
|
|
465
476
|
interface DisplayContext {
|
|
@@ -480,7 +491,11 @@ declare function dateToDay(date: Date): string;
|
|
|
480
491
|
* clock (core's `wallClock`), so an 8pm edit in New York isn't tomorrow's (its UTC day).
|
|
481
492
|
*/
|
|
482
493
|
declare function formatDay(value: unknown, zone?: string): string;
|
|
483
|
-
/**
|
|
494
|
+
/**
|
|
495
|
+
* A column's clock: "viewer" (the default) and "scope" from `zones`, else a valid IANA name.
|
|
496
|
+
* Anything else throws (`defineView` refuses it first): drawing it on the viewer's clock instead
|
|
497
|
+
* would show the wrong times with nothing to say so.
|
|
498
|
+
*/
|
|
484
499
|
declare function resolveZone(zone: string | undefined, zones: DisplayTimeZones): string;
|
|
485
500
|
/** A timestamp as the clock on the wall in `zone` shows it (core's `wallClock`), not the device's. */
|
|
486
501
|
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 { 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';
|
|
@@ -804,6 +804,7 @@ function NativeResourcePage({
|
|
|
804
804
|
var defaultNativeResourceViewMessages = {
|
|
805
805
|
common: {
|
|
806
806
|
empty: "\u2014",
|
|
807
|
+
hiddenLink: "Not available",
|
|
807
808
|
yes: "Yes",
|
|
808
809
|
no: "No",
|
|
809
810
|
cancel: "Cancel",
|
|
@@ -881,8 +882,11 @@ function formatDay(value, zone = personTimeZone()) {
|
|
|
881
882
|
}
|
|
882
883
|
function resolveZone(zone, zones) {
|
|
883
884
|
if (!zone || zone === "viewer") return zones.viewer;
|
|
884
|
-
if (zone === "
|
|
885
|
-
|
|
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
|
+
);
|
|
886
890
|
}
|
|
887
891
|
var WALL = new Intl.DateTimeFormat(void 0, { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" });
|
|
888
892
|
function formatInstant(value, zone) {
|
|
@@ -945,6 +949,13 @@ function LinkText({ url, label }) {
|
|
|
945
949
|
);
|
|
946
950
|
}
|
|
947
951
|
var text = (hint) => (value, { messages, column, zones }) => /* @__PURE__ */ jsx(NativeText, { preset: "body", children: displayText(hint, value, messages, resolveZone(column.timeZone, zones)) });
|
|
952
|
+
function RelationText({ value, context }) {
|
|
953
|
+
const { column, messages } = context;
|
|
954
|
+
const reference = column.field?.references;
|
|
955
|
+
const label = useRelationLabel(reference, value, column.labelField ? { labelField: column.labelField } : {});
|
|
956
|
+
const shown = !reference ? String(value) : label === void 0 ? messages.common.empty : label ?? column.missingLabel ?? messages.common.hiddenLink ?? defaultNativeResourceViewMessages.common.hiddenLink;
|
|
957
|
+
return /* @__PURE__ */ jsx(NativeText, { preset: "body", children: shown });
|
|
958
|
+
}
|
|
948
959
|
var nativeDisplayRenderers = {
|
|
949
960
|
text: text("text"),
|
|
950
961
|
longText: (value) => /* @__PURE__ */ jsx(NativeText, { preset: "body", numberOfLines: 3, children: String(value) }),
|
|
@@ -955,8 +966,8 @@ var nativeDisplayRenderers = {
|
|
|
955
966
|
badge: (value, { column }) => /* @__PURE__ */ jsx(NativeBadge, { variant: badgeVariant(column.tones?.[String(value)]), children: valueText(column.labels, value) }),
|
|
956
967
|
date: text("date"),
|
|
957
968
|
datetime: text("datetime"),
|
|
958
|
-
// The linked row's
|
|
959
|
-
relation:
|
|
969
|
+
// The linked row's words, batched across the list (one query per linked resource), else its id.
|
|
970
|
+
relation: (value, context) => /* @__PURE__ */ jsx(RelationText, { value, context }),
|
|
960
971
|
url: (value, { messages }) => {
|
|
961
972
|
const url = openableUrl(value);
|
|
962
973
|
return url && /^https?:/i.test(url) ? /* @__PURE__ */ jsx(LinkText, { url, label: displayText("url", value, messages) }) : /* @__PURE__ */ jsx(NativeText, { preset: "body", children: String(value) });
|
|
@@ -978,7 +989,7 @@ var TimeZonesContext = createContext(null);
|
|
|
978
989
|
var DisplayTimeZonesProvider = TimeZonesContext.Provider;
|
|
979
990
|
function useDisplayTimeZones() {
|
|
980
991
|
const zones = useContext(TimeZonesContext);
|
|
981
|
-
return useMemo(() => zones ?? { viewer: personTimeZone(),
|
|
992
|
+
return useMemo(() => zones ?? { viewer: personTimeZone(), scope: personTimeZone() }, [zones]);
|
|
982
993
|
}
|
|
983
994
|
function DisplayRenderersProvider({
|
|
984
995
|
renderers,
|
|
@@ -1114,6 +1125,9 @@ function formFieldsFor(view, mode) {
|
|
|
1114
1125
|
readOnly,
|
|
1115
1126
|
...f.max !== void 0 ? { max: f.max } : {},
|
|
1116
1127
|
...options ? { options } : {},
|
|
1128
|
+
...f.field.references ? { references: f.field.references } : {},
|
|
1129
|
+
...f.labelField ? { labelField: f.labelField } : {},
|
|
1130
|
+
...f.missingLabel ? { missingLabel: f.missingLabel } : {},
|
|
1117
1131
|
section: f.section,
|
|
1118
1132
|
sectionTitle: f.sectionTitle,
|
|
1119
1133
|
...f.visible ? { visible: f.visible } : {}
|
|
@@ -1285,10 +1299,15 @@ function FormField({
|
|
|
1285
1299
|
const messages = useNativeResourceViewMessages();
|
|
1286
1300
|
const zones = useDisplayTimeZones();
|
|
1287
1301
|
const error = f.formState.errors[field.key]?.message;
|
|
1302
|
+
const linkLabel = useRelationLabel(field.references, f.getValues(field.key), {
|
|
1303
|
+
...field.labelField ? { labelField: field.labelField } : {},
|
|
1304
|
+
enabled: field.readOnly && field.display === "relation"
|
|
1305
|
+
});
|
|
1288
1306
|
if (field.readOnly) {
|
|
1289
1307
|
const value = f.getValues(field.key);
|
|
1290
1308
|
const choice = field.options?.find((o) => o.value === String(value));
|
|
1291
|
-
const
|
|
1309
|
+
const linked = field.references && field.display === "relation" && !isEmptyValue(value);
|
|
1310
|
+
const shown = choice ? choice.label : linked ? linkLabel === void 0 ? messages.common.empty : linkLabel ?? field.missingLabel ?? messages.common.hiddenLink ?? defaultNativeResourceViewMessages.common.hiddenLink : displayText(field.display, value, messages, resolveZone(void 0, zones));
|
|
1292
1311
|
return /* @__PURE__ */ jsxs(View, { testID: id, style: { gap: 4 }, accessibilityLabel: `${field.label}, ${shown}`, children: [
|
|
1293
1312
|
/* @__PURE__ */ jsx(NativeLabel, { children: field.label }),
|
|
1294
1313
|
/* @__PURE__ */ jsx(NativeText, { testID: `${id}-value`, preset: "body", className: "text-muted-foreground", children: shown })
|
|
@@ -1538,11 +1557,11 @@ var recordKey = (view, row) => {
|
|
|
1538
1557
|
function NativeResourceView(props) {
|
|
1539
1558
|
const scope = useOptionalViewerScope();
|
|
1540
1559
|
const viewer = scope?.timeZone;
|
|
1541
|
-
const
|
|
1560
|
+
const scopeZone = props.scopeTimeZone ?? scope?.scopeTimeZone;
|
|
1542
1561
|
const zones = useMemo(() => {
|
|
1543
1562
|
const own = personTimeZone({ timeZone: viewer });
|
|
1544
|
-
return { viewer: own,
|
|
1545
|
-
}, [viewer,
|
|
1563
|
+
return { viewer: own, scope: scopeClock(scopeZone, own) };
|
|
1564
|
+
}, [viewer, scopeZone]);
|
|
1546
1565
|
return /* @__PURE__ */ jsx(DisplayTimeZonesProvider, { value: zones, children: /* @__PURE__ */ jsx(Screen, { ...props }) });
|
|
1547
1566
|
}
|
|
1548
1567
|
var PICTURE_SIZE = 40;
|
|
@@ -1645,7 +1664,7 @@ function Screen(props) {
|
|
|
1645
1664
|
header,
|
|
1646
1665
|
emptyState,
|
|
1647
1666
|
searchable,
|
|
1648
|
-
|
|
1667
|
+
scopeTimeZone: _zone,
|
|
1649
1668
|
testID = "native-resource-view",
|
|
1650
1669
|
...options
|
|
1651
1670
|
} = props;
|