@marktiderman/genesis-ui-native 2.8.1 → 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;
@@ -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",
@@ -945,6 +946,13 @@ function LinkText({ url, label }) {
945
946
  );
946
947
  }
947
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
+ }
948
956
  var nativeDisplayRenderers = {
949
957
  text: text("text"),
950
958
  longText: (value) => /* @__PURE__ */ jsx(NativeText, { preset: "body", numberOfLines: 3, children: String(value) }),
@@ -955,8 +963,8 @@ var nativeDisplayRenderers = {
955
963
  badge: (value, { column }) => /* @__PURE__ */ jsx(NativeBadge, { variant: badgeVariant(column.tones?.[String(value)]), children: valueText(column.labels, value) }),
956
964
  date: text("date"),
957
965
  datetime: text("datetime"),
958
- // The linked row's id until relation labels arrive (batched per page, never per row).
959
- 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 }),
960
968
  url: (value, { messages }) => {
961
969
  const url = openableUrl(value);
962
970
  return url && /^https?:/i.test(url) ? /* @__PURE__ */ jsx(LinkText, { url, label: displayText("url", value, messages) }) : /* @__PURE__ */ jsx(NativeText, { preset: "body", children: String(value) });
@@ -1114,6 +1122,9 @@ function formFieldsFor(view, mode) {
1114
1122
  readOnly,
1115
1123
  ...f.max !== void 0 ? { max: f.max } : {},
1116
1124
  ...options ? { options } : {},
1125
+ ...f.field.references ? { references: f.field.references } : {},
1126
+ ...f.labelField ? { labelField: f.labelField } : {},
1127
+ ...f.missingLabel ? { missingLabel: f.missingLabel } : {},
1117
1128
  section: f.section,
1118
1129
  sectionTitle: f.sectionTitle,
1119
1130
  ...f.visible ? { visible: f.visible } : {}
@@ -1285,10 +1296,15 @@ function FormField({
1285
1296
  const messages = useNativeResourceViewMessages();
1286
1297
  const zones = useDisplayTimeZones();
1287
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
+ });
1288
1303
  if (field.readOnly) {
1289
1304
  const value = f.getValues(field.key);
1290
1305
  const choice = field.options?.find((o) => o.value === String(value));
1291
- 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));
1292
1308
  return /* @__PURE__ */ jsxs(View, { testID: id, style: { gap: 4 }, accessibilityLabel: `${field.label}, ${shown}`, children: [
1293
1309
  /* @__PURE__ */ jsx(NativeLabel, { children: field.label }),
1294
1310
  /* @__PURE__ */ jsx(NativeText, { testID: `${id}-value`, preset: "body", className: "text-muted-foreground", children: shown })