@marktiderman/genesis-ui-native 2.8.0 → 2.9.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,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;
@@ -475,7 +484,11 @@ declare function dayToDate(value: unknown): Date | null;
475
484
  /** A picked Date back to the `YYYY-MM-DD` day it shows, from its local parts (never `toISOString`). */
476
485
  declare function dateToDay(date: Date): string;
477
486
  /** A calendar day, the same day on every clock. */
478
- declare function formatDay(value: unknown): string;
487
+ /**
488
+ * A day. A calendar day (`YYYY-MM-DD`) from its parts; a timestamp as the day it is on `zone`'s
489
+ * clock (core's `wallClock`), so an 8pm edit in New York isn't tomorrow's (its UTC day).
490
+ */
491
+ declare function formatDay(value: unknown, zone?: string): string;
479
492
  /** A column's clock: "viewer" (the default) and "practice" from `zones`, else a valid IANA name. */
480
493
  declare function resolveZone(zone: string | undefined, zones: DisplayTimeZones): string;
481
494
  /** A timestamp as the clock on the wall in `zone` shows it (core's `wallClock`), not the device's. */
@@ -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, 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",
@@ -870,9 +871,14 @@ function dateToDay(date) {
870
871
  const pad = (n) => String(n).padStart(2, "0");
871
872
  return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
872
873
  }
873
- function formatDay(value) {
874
+ function formatDay(value, zone = personTimeZone()) {
874
875
  const date = dayToDate(value);
875
- return date ? DAY.format(date) : String(value);
876
+ if (date) return DAY.format(date);
877
+ const text2 = String(value);
878
+ const at = /^\d{4}-\d{2}-\d{2}[T ]/.test(text2) ? new Date(text2) : null;
879
+ if (!at || Number.isNaN(at.getTime()) || !isTimeZone(zone)) return text2;
880
+ const wall = wallClock(zone, at);
881
+ return DAY.format(new Date(wall.year, wall.month - 1, wall.day));
876
882
  }
877
883
  function resolveZone(zone, zones) {
878
884
  if (!zone || zone === "viewer") return zones.viewer;
@@ -905,7 +911,7 @@ function displayText(hint, value, messages, timeZone = personTimeZone()) {
905
911
  case "badge":
906
912
  return titleCase(String(value));
907
913
  case "date":
908
- return formatDay(value);
914
+ return formatDay(value, timeZone);
909
915
  case "datetime":
910
916
  return formatInstant(value, timeZone);
911
917
  case "url": {
@@ -940,6 +946,13 @@ function LinkText({ url, label }) {
940
946
  );
941
947
  }
942
948
  var text = (hint) => (value, { messages, column, zones }) => /* @__PURE__ */ jsx(NativeText, { preset: "body", children: displayText(hint, value, messages, resolveZone(column.timeZone, zones)) });
949
+ function RelationText({ value, context }) {
950
+ const { column, messages } = context;
951
+ const reference = column.field?.references;
952
+ const label = useRelationLabel(reference, value, column.labelField ? { labelField: column.labelField } : {});
953
+ const shown = !reference ? String(value) : label === void 0 ? messages.common.empty : label ?? column.missingLabel ?? messages.common.hiddenLink ?? defaultNativeResourceViewMessages.common.hiddenLink;
954
+ return /* @__PURE__ */ jsx(NativeText, { preset: "body", children: shown });
955
+ }
943
956
  var nativeDisplayRenderers = {
944
957
  text: text("text"),
945
958
  longText: (value) => /* @__PURE__ */ jsx(NativeText, { preset: "body", numberOfLines: 3, children: String(value) }),
@@ -950,8 +963,8 @@ var nativeDisplayRenderers = {
950
963
  badge: (value, { column }) => /* @__PURE__ */ jsx(NativeBadge, { variant: badgeVariant(column.tones?.[String(value)]), children: valueText(column.labels, value) }),
951
964
  date: text("date"),
952
965
  datetime: text("datetime"),
953
- // The linked row's id until relation labels arrive (batched per page, never per row).
954
- relation: text("relation"),
966
+ // The linked row's words, batched across the list (one query per linked resource), else its id.
967
+ relation: (value, context) => /* @__PURE__ */ jsx(RelationText, { value, context }),
955
968
  url: (value, { messages }) => {
956
969
  const url = openableUrl(value);
957
970
  return url && /^https?:/i.test(url) ? /* @__PURE__ */ jsx(LinkText, { url, label: displayText("url", value, messages) }) : /* @__PURE__ */ jsx(NativeText, { preset: "body", children: String(value) });
@@ -1109,6 +1122,9 @@ function formFieldsFor(view, mode) {
1109
1122
  readOnly,
1110
1123
  ...f.max !== void 0 ? { max: f.max } : {},
1111
1124
  ...options ? { options } : {},
1125
+ ...f.field.references ? { references: f.field.references } : {},
1126
+ ...f.labelField ? { labelField: f.labelField } : {},
1127
+ ...f.missingLabel ? { missingLabel: f.missingLabel } : {},
1112
1128
  section: f.section,
1113
1129
  sectionTitle: f.sectionTitle,
1114
1130
  ...f.visible ? { visible: f.visible } : {}
@@ -1280,10 +1296,15 @@ function FormField({
1280
1296
  const messages = useNativeResourceViewMessages();
1281
1297
  const zones = useDisplayTimeZones();
1282
1298
  const error = f.formState.errors[field.key]?.message;
1299
+ const linkLabel = useRelationLabel(field.references, f.getValues(field.key), {
1300
+ ...field.labelField ? { labelField: field.labelField } : {},
1301
+ enabled: field.readOnly && field.display === "relation"
1302
+ });
1283
1303
  if (field.readOnly) {
1284
1304
  const value = f.getValues(field.key);
1285
1305
  const choice = field.options?.find((o) => o.value === String(value));
1286
- const shown = choice ? choice.label : displayText(field.display, value, messages, resolveZone(void 0, zones));
1306
+ const linked = field.references && field.display === "relation" && !isEmptyValue(value);
1307
+ 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));
1287
1308
  return /* @__PURE__ */ jsxs(View, { testID: id, style: { gap: 4 }, accessibilityLabel: `${field.label}, ${shown}`, children: [
1288
1309
  /* @__PURE__ */ jsx(NativeLabel, { children: field.label }),
1289
1310
  /* @__PURE__ */ jsx(NativeText, { testID: `${id}-value`, preset: "body", className: "text-muted-foreground", children: shown })