@marktiderman/genesis-ui-native 2.7.0 → 2.7.1
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.js +7 -6
- package/dist/data/index.js.map +1 -1
- package/package.json +2 -2
- package/src/data/resource-view/NativeResourceFormSheet.tsx +4 -1
- package/src/data/resource-view/__tests__/native-resource-view.test.tsx +14 -0
- package/src/data/resource-view/display.tsx +2 -2
- package/src/data/resource-view/mapping.ts +4 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktiderman/genesis-ui-native",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"@expo/ui": ">=58.0.0",
|
|
70
70
|
"@gorhom/bottom-sheet": ">=5.0.0",
|
|
71
71
|
"@hookform/resolvers": "^3.0.0 || ^4.0.0 || ^5.0.0",
|
|
72
|
-
"@marktiderman/genesis-core": "^1.
|
|
72
|
+
"@marktiderman/genesis-core": "^1.15.0",
|
|
73
73
|
"@marktiderman/genesis-design-system": "^1.5.0",
|
|
74
74
|
"@react-native-community/datetimepicker": ">=8.0.0",
|
|
75
75
|
"@shopify/flash-list": ">=2.0.0",
|
|
@@ -196,7 +196,10 @@ function FormField({
|
|
|
196
196
|
const error = f.formState.errors[field.key]?.message as string | undefined;
|
|
197
197
|
if (field.readOnly) {
|
|
198
198
|
// A link shows its raw id until batched relation labels arrive.
|
|
199
|
-
const
|
|
199
|
+
const value: unknown = f.getValues(field.key);
|
|
200
|
+
// A choice shows in the view's words (its `labels`).
|
|
201
|
+
const choice = field.options?.find((o) => o.value === String(value));
|
|
202
|
+
const shown = choice ? choice.label : displayText(field.display, value, messages, resolveZone(undefined, zones));
|
|
200
203
|
return (
|
|
201
204
|
<View testID={id} style={{ gap: 4 }} accessibilityLabel={`${field.label}, ${shown}`}>
|
|
202
205
|
<NativeLabel>{field.label}</NativeLabel>
|
|
@@ -229,6 +229,20 @@ describe("sections", () => {
|
|
|
229
229
|
]);
|
|
230
230
|
});
|
|
231
231
|
|
|
232
|
+
it("titles sections and form choices in the view's words", () => {
|
|
233
|
+
const labelled = defineView(brands, {
|
|
234
|
+
fields: { status: { labels: { active: "Published", draft: "In progress" } } },
|
|
235
|
+
form: ["name", "status"],
|
|
236
|
+
groupBy: "status",
|
|
237
|
+
});
|
|
238
|
+
expect(sectionsFor(labelled, ROWS, messages).map((s) => s.title)).toEqual(["Published", "Archived"]);
|
|
239
|
+
expect(formFieldsFor(labelled, "create").find((f) => f.key === "status")!.options).toEqual([
|
|
240
|
+
{ value: "active", label: "Published" },
|
|
241
|
+
{ value: "archived", label: "Archived" },
|
|
242
|
+
{ value: "draft", label: "In progress" },
|
|
243
|
+
]);
|
|
244
|
+
});
|
|
245
|
+
|
|
232
246
|
it("is one untitled section without groupBy, and none for no rows", () => {
|
|
233
247
|
expect(sectionsFor(summaryView, ROWS, messages).map((s) => s.title)).toEqual([""]);
|
|
234
248
|
expect(sectionsFor(summaryView, [], messages)).toEqual([]);
|
|
@@ -11,7 +11,7 @@ import { titleCase } from "@marktiderman/genesis-core";
|
|
|
11
11
|
import { isTimeZone, personTimeZone, wallClock } from "@marktiderman/genesis-core/dates";
|
|
12
12
|
import { useViewer } from "@marktiderman/genesis-core/hooks";
|
|
13
13
|
import { isSafeUrl } from "@marktiderman/genesis-core/urls";
|
|
14
|
-
import type
|
|
14
|
+
import { valueText, type DisplayHint, type ResolvedColumn, type ViewTone } from "@marktiderman/genesis-core/resource-view";
|
|
15
15
|
import { NativeBadge } from "../../components/badge";
|
|
16
16
|
import { NativeImage } from "../../components/image";
|
|
17
17
|
import { NativeText } from "../../components/text";
|
|
@@ -172,7 +172,7 @@ export const nativeDisplayRenderers: DisplayRenderers = {
|
|
|
172
172
|
percent: text("percent"),
|
|
173
173
|
boolean: text("boolean"),
|
|
174
174
|
badge: (value, { column }) => (
|
|
175
|
-
<NativeBadge variant={badgeVariant(column.tones?.[String(value)])}>{
|
|
175
|
+
<NativeBadge variant={badgeVariant(column.tones?.[String(value)])}>{valueText(column.labels, value)}</NativeBadge>
|
|
176
176
|
),
|
|
177
177
|
date: text("date"),
|
|
178
178
|
datetime: text("datetime"),
|
|
@@ -85,7 +85,9 @@ export function sectionsFor<T extends Row>(
|
|
|
85
85
|
if (!group) {
|
|
86
86
|
const title = isEmptyValue(value)
|
|
87
87
|
? fill(messages.list.noGroup, { label: view.label(field).toLowerCase() })
|
|
88
|
-
:
|
|
88
|
+
: display === "badge"
|
|
89
|
+
? view.valueLabel(field, value)
|
|
90
|
+
: displayText(display, value, messages);
|
|
89
91
|
group = { key, title, data: [] };
|
|
90
92
|
groups.set(key, group);
|
|
91
93
|
}
|
|
@@ -244,7 +246,7 @@ export function formFieldsFor<T extends Row>(view: AnyResourceView<T>, mode: "cr
|
|
|
244
246
|
.filter((f) => f.display !== "json" && !f.field.array)
|
|
245
247
|
.filter((f) => mode === "edit" || writable.has(f.field.name))
|
|
246
248
|
.map((f) => {
|
|
247
|
-
const options = f.
|
|
249
|
+
const options = f.options?.map((o) => ({ value: o.value, label: o.label }));
|
|
248
250
|
const readOnly = !writable.has(f.field.name);
|
|
249
251
|
return {
|
|
250
252
|
key: f.field.name,
|
|
@@ -262,9 +264,6 @@ export function formFieldsFor<T extends Row>(view: AnyResourceView<T>, mode: "cr
|
|
|
262
264
|
});
|
|
263
265
|
}
|
|
264
266
|
|
|
265
|
-
// Only `badge` is formatted here, which reads no messages.
|
|
266
|
-
const EMPTY_WORDS = { common: { empty: "", yes: "", no: "" } } as NativeResourceViewMessages;
|
|
267
|
-
|
|
268
267
|
/** Fields shown for these values: a field whose `visible` says no is hidden, and isn't saved. */
|
|
269
268
|
export function shownFields(fields: readonly NativeFormField[], values: Readonly<Record<string, unknown>>): NativeFormField[] {
|
|
270
269
|
return fields.filter((f) => !f.visible || f.visible(values));
|