@marktiderman/genesis-ui-native 2.7.0 → 2.8.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.
@@ -384,15 +384,18 @@ interface UseNativeResourceViewReturn<T extends Row$2 = Row$2> {
384
384
  declare function screenValues(...filters: (Filter | undefined)[]): Record<string, string | number | boolean>;
385
385
  /** Pages kept loaded by default (cursor paging). */
386
386
  declare const DEFAULT_MAX_PAGES = 10;
387
- /**
388
- * The server sort: the `groupBy` field first, so every page arrives in section order and a later
389
- * page never lands in the middle of an earlier section; else the view's `orderBy`. (A second sort
390
- * key within a group needs `useInfiniteResource` to take several sorts.)
391
- */
392
- declare function serverSort<T extends Row$2>(view: AnyResourceView<T>): {
387
+ type ServerSort = {
393
388
  field: string;
394
389
  order: "asc" | "desc";
395
- } | undefined;
390
+ };
391
+ /**
392
+ * The server sorts: the `groupBy` field first, so every page arrives in section order and a later
393
+ * page never lands in the middle of an earlier section, then the view's `orderBy` within each
394
+ * group. A provider without `multiSort` applies only the first.
395
+ */
396
+ declare function serverSorts<T extends Row$2>(view: AnyResourceView<T>): ServerSort[];
397
+ /** The first of {@link serverSorts}: what a provider that sorts by one field gets. */
398
+ declare function serverSort<T extends Row$2>(view: AnyResourceView<T>): ServerSort | undefined;
396
399
  declare function useNativeResourceView<T extends Row$2 = Row$2>(view: AnyResourceView<T>, options?: NativeResourceViewOptions<T>): UseNativeResourceViewReturn<T>;
397
400
 
398
401
  type Row$1 = Record<string, unknown>;
@@ -597,4 +600,4 @@ declare function NativeResourceWorkspace<T extends Row = Row>(props: NativeResou
597
600
  */
598
601
  declare function parseSettingNumber(text: string): number | null;
599
602
 
600
- export { type AnyResourceView, DEFAULT_MAX_PAGES, type DisplayContext, type DisplayRenderer, type DisplayRenderers, DisplayRenderersProvider, type DisplayTimeZones, DisplayTimeZonesProvider, type NativeCardFieldDef, NativeDataFilters, type NativeDataFiltersProps, NativeDataPageShell, type NativeDataPageShellProps, type NativeDetailField, NativeDetailPanel, type NativeDetailPanelProps, NativeEmptyState, type NativeEmptyStateProps, type NativeFormField, type NativeFormFieldKind, NativeResourceForm, NativeResourceFormFieldRenderer, type NativeResourceFormFieldRendererProps, type NativeResourceFormProps, NativeResourceFormSheet, type NativeResourceFormSheetProps, NativeResourcePage, type NativeResourcePageProps, type NativeResourceRowItem, type NativeResourceScreenCan, type NativeResourceSection, type NativeResourceSwipeAction, type NativeResourceSwipeableProps, NativeResourceView, type NativeResourceViewMessages, NativeResourceViewMessagesProvider, type NativeResourceViewOptions, type NativeResourceViewProps, NativeResourceWorkspace, type NativeResourceWorkspaceHeaderProps, NativeResourceWorkspaceMenu, type NativeResourceWorkspaceMessages, type NativeResourceWorkspaceProps, SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, type SaveResult, type UseNativeResourceViewReturn, allowed, dateToDay, dayToDate, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
603
+ export { type AnyResourceView, DEFAULT_MAX_PAGES, type DisplayContext, type DisplayRenderer, type DisplayRenderers, DisplayRenderersProvider, type DisplayTimeZones, DisplayTimeZonesProvider, type NativeCardFieldDef, NativeDataFilters, type NativeDataFiltersProps, NativeDataPageShell, type NativeDataPageShellProps, type NativeDetailField, NativeDetailPanel, type NativeDetailPanelProps, NativeEmptyState, type NativeEmptyStateProps, type NativeFormField, type NativeFormFieldKind, NativeResourceForm, NativeResourceFormFieldRenderer, type NativeResourceFormFieldRendererProps, type NativeResourceFormProps, NativeResourceFormSheet, type NativeResourceFormSheetProps, NativeResourcePage, type NativeResourcePageProps, type NativeResourceRowItem, type NativeResourceScreenCan, type NativeResourceSection, type NativeResourceSwipeAction, type NativeResourceSwipeableProps, NativeResourceView, type NativeResourceViewMessages, NativeResourceViewMessagesProvider, type NativeResourceViewOptions, type NativeResourceViewProps, NativeResourceWorkspace, type NativeResourceWorkspaceHeaderProps, NativeResourceWorkspaceMenu, type NativeResourceWorkspaceMessages, type NativeResourceWorkspaceProps, SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, type SaveResult, type UseNativeResourceViewReturn, allowed, dateToDay, dayToDate, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, serverSorts, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
@@ -15,7 +15,7 @@ import { Controller, useForm } from 'react-hook-form';
15
15
  import { 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
- import { rowPicture } from '@marktiderman/genesis-core/resource-view';
18
+ import { valueText, rowPicture } from '@marktiderman/genesis-core/resource-view';
19
19
  import { useQueryClient, useQuery } from '@tanstack/react-query';
20
20
  import { readinessChip } from '@marktiderman/genesis-core/resource';
21
21
 
@@ -947,7 +947,7 @@ var nativeDisplayRenderers = {
947
947
  currency: text("currency"),
948
948
  percent: text("percent"),
949
949
  boolean: text("boolean"),
950
- badge: (value, { column }) => /* @__PURE__ */ jsx(NativeBadge, { variant: badgeVariant(column.tones?.[String(value)]), children: titleCase(String(value)) }),
950
+ badge: (value, { column }) => /* @__PURE__ */ jsx(NativeBadge, { variant: badgeVariant(column.tones?.[String(value)]), children: valueText(column.labels, value) }),
951
951
  date: text("date"),
952
952
  datetime: text("datetime"),
953
953
  // The linked row's id until relation labels arrive (batched per page, never per row).
@@ -1029,7 +1029,7 @@ function sectionsFor(view, rows, messages) {
1029
1029
  const key = isEmptyValue(value) ? "\0" : String(value);
1030
1030
  let group = groups.get(key);
1031
1031
  if (!group) {
1032
- const title = isEmptyValue(value) ? fill(messages.list.noGroup, { label: view.label(field).toLowerCase() }) : displayText(display, value, messages);
1032
+ const title = isEmptyValue(value) ? fill(messages.list.noGroup, { label: view.label(field).toLowerCase() }) : display === "badge" ? view.valueLabel(field, value) : displayText(display, value, messages);
1033
1033
  group = { key, title, data: [] };
1034
1034
  groups.set(key, group);
1035
1035
  }
@@ -1098,7 +1098,7 @@ function kindFor(display, options) {
1098
1098
  function formFieldsFor(view, mode) {
1099
1099
  const writable = new Set(view.writable(mode));
1100
1100
  return view.form(mode).filter((f) => f.display !== "json" && !f.field.array).filter((f) => mode === "edit" || writable.has(f.field.name)).map((f) => {
1101
- const options = f.field.enumValues?.map((value) => ({ value, label: displayText("badge", value, EMPTY_WORDS) }));
1101
+ const options = f.options?.map((o) => ({ value: o.value, label: o.label }));
1102
1102
  const readOnly = !writable.has(f.field.name);
1103
1103
  return {
1104
1104
  key: f.field.name,
@@ -1115,7 +1115,6 @@ function formFieldsFor(view, mode) {
1115
1115
  };
1116
1116
  });
1117
1117
  }
1118
- var EMPTY_WORDS = { common: { empty: "", yes: "", no: "" } };
1119
1118
  function shownFields(fields, values) {
1120
1119
  return fields.filter((f) => !f.visible || f.visible(values));
1121
1120
  }
@@ -1282,7 +1281,9 @@ function FormField({
1282
1281
  const zones = useDisplayTimeZones();
1283
1282
  const error = f.formState.errors[field.key]?.message;
1284
1283
  if (field.readOnly) {
1285
- const shown = displayText(field.display, f.getValues(field.key), messages, resolveZone(void 0, zones));
1284
+ const value = f.getValues(field.key);
1285
+ 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));
1286
1287
  return /* @__PURE__ */ jsxs(View, { testID: id, style: { gap: 4 }, accessibilityLabel: `${field.label}, ${shown}`, children: [
1287
1288
  /* @__PURE__ */ jsx(NativeLabel, { children: field.label }),
1288
1289
  /* @__PURE__ */ jsx(NativeText, { testID: `${id}-value`, preset: "body", className: "text-muted-foreground", children: shown })
@@ -1374,11 +1375,16 @@ function screenValues(...filters) {
1374
1375
  return out;
1375
1376
  }
1376
1377
  var DEFAULT_MAX_PAGES = 10;
1377
- function serverSort(view) {
1378
+ function serverSorts(view) {
1378
1379
  const groupBy = view.definition.groupBy;
1379
1380
  const orderBy = view.definition.orderBy;
1380
- if (groupBy) return { field: groupBy, order: orderBy?.field === groupBy ? orderBy.direction ?? "asc" : "asc" };
1381
- return orderBy ? { field: orderBy.field, order: orderBy.direction ?? "asc" } : void 0;
1381
+ const order = orderBy ? { field: orderBy.field, order: orderBy.direction ?? "asc" } : void 0;
1382
+ if (!groupBy) return order ? [order] : [];
1383
+ if (order?.field === groupBy) return [order];
1384
+ return [{ field: groupBy, order: "asc" }, ...order ? [order] : []];
1385
+ }
1386
+ function serverSort(view) {
1387
+ return serverSorts(view)[0];
1382
1388
  }
1383
1389
  function useNativeResourceView(view, options = {}) {
1384
1390
  const { preset, filter, perPage, maxPages = DEFAULT_MAX_PAGES, searchFields: searchOption, can, live } = options;
@@ -1389,14 +1395,14 @@ function useNativeResourceView(view, options = {}) {
1389
1395
  const defaultFilters = useMemo(() => [...filterParams(tabFilter), ...filterParams(filter)], [tabFilter, filter]);
1390
1396
  const createKey = JSON.stringify(screenValues(tabFilter, filter));
1391
1397
  const createDefaults = useMemo(() => JSON.parse(createKey), [createKey]);
1392
- const sort = useMemo(() => serverSort(view), [view]);
1398
+ const sorts = useMemo(() => serverSorts(view), [view]);
1393
1399
  const searchFields = useMemo(
1394
1400
  () => searchOption ?? (view.labelField ? [view.labelField] : void 0),
1395
1401
  [searchOption, view.labelField]
1396
1402
  );
1397
1403
  const pages = useInfiniteResource(view.resource, {
1398
1404
  defaultFilters,
1399
- ...sort ? { defaultSort: sort } : {},
1405
+ ...sorts.length ? { defaultSorts: sorts } : {},
1400
1406
  ...perPage ? { perPage } : {},
1401
1407
  maxPages,
1402
1408
  ...searchFields ? { searchFields } : {},
@@ -2253,6 +2259,6 @@ function Cell({ last, children }) {
2253
2259
  ] });
2254
2260
  }
2255
2261
 
2256
- export { DEFAULT_MAX_PAGES, DisplayRenderersProvider, DisplayTimeZonesProvider, NativeDataFilters, NativeDataPageShell, NativeDetailPanel, NativeEmptyState2 as NativeEmptyState, NativeResourceForm, NativeResourceFormFieldRenderer, NativeResourceFormSheet, NativeResourcePage, NativeResourceView, NativeResourceViewMessagesProvider, NativeResourceWorkspace, NativeResourceWorkspaceMenu, SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, allowed, dateToDay, dayToDate, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
2262
+ export { DEFAULT_MAX_PAGES, DisplayRenderersProvider, DisplayTimeZonesProvider, NativeDataFilters, NativeDataPageShell, NativeDetailPanel, NativeEmptyState2 as NativeEmptyState, NativeResourceForm, NativeResourceFormFieldRenderer, NativeResourceFormSheet, NativeResourcePage, NativeResourceView, NativeResourceViewMessagesProvider, NativeResourceWorkspace, NativeResourceWorkspaceMenu, SEARCH_DEBOUNCE_MS, SEGMENTED_SECTIONS_MAX, allowed, dateToDay, dayToDate, defaultNativeResourceViewMessages, defaultNativeResourceWorkspaceMessages, displayText, formFieldsFor, formatDay, formatInstant, getNativeResourceWorkspaceStackOptions, nativeDisplayRenderers, openableUrl, parseSettingNumber, resolveZone, rowItem, screenValues, sectionsFor, serverSort, serverSorts, swipeActionsFor, useDisplayCell, useDisplayTimeZones, useNativeResourceView, useNativeResourceViewMessages, validateValues, writableValues };
2257
2263
  //# sourceMappingURL=index.js.map
2258
2264
  //# sourceMappingURL=index.js.map