@marktiderman/genesis-ui-native 2.9.0 → 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 +12 -6
- package/dist/data/index.js +11 -8
- package/dist/data/index.js.map +1 -1
- package/package.json +2 -2
- package/src/data/resource-view/NativeResourceView.tsx +11 -9
- package/src/data/resource-view/__tests__/native-resource-view.test.tsx +28 -10
- package/src/data/resource-view/display.tsx +16 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktiderman/genesis-ui-native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
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": "^
|
|
72
|
+
"@marktiderman/genesis-core": "^2.0.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",
|
|
@@ -17,8 +17,8 @@ import { memo, useCallback, useMemo, useRef, useState, type ComponentType, type
|
|
|
17
17
|
import { Alert, Platform, Pressable, SectionList, View } from "react-native";
|
|
18
18
|
import { SafeAreaView } from "react-native-safe-area-context";
|
|
19
19
|
import { encodeRecordKey, type BaseRecord, type DataRow } from "@marktiderman/genesis-core";
|
|
20
|
-
import {
|
|
21
|
-
import { useOne, useOptionalViewerScope } from "@marktiderman/genesis-core/hooks";
|
|
20
|
+
import { personTimeZone } from "@marktiderman/genesis-core/dates";
|
|
21
|
+
import { scopeClock, useOne, useOptionalViewerScope } from "@marktiderman/genesis-core/hooks";
|
|
22
22
|
import type { RowPicture } from "@marktiderman/genesis-core/resource-view";
|
|
23
23
|
import { NativeAvatar } from "../../components/avatar";
|
|
24
24
|
import { NativeBadge } from "../../components/badge";
|
|
@@ -78,10 +78,11 @@ export interface NativeResourceViewProps<T extends Row = Row> extends NativeReso
|
|
|
78
78
|
/** Hide the search box. Shown by default when the view has something to search. */
|
|
79
79
|
searchable?: boolean;
|
|
80
80
|
/**
|
|
81
|
-
* The
|
|
82
|
-
*
|
|
81
|
+
* The IANA zone of whatever this screen is scoped to (a location, a league, a team), for columns
|
|
82
|
+
* with `timeZone: "scope"`. Default: ViewerScope's `scopeTimeZone`, else the viewer's clock.
|
|
83
|
+
* Timestamps on other columns read on the viewer's clock (ViewerScope's zone, else the device's).
|
|
83
84
|
*/
|
|
84
|
-
|
|
85
|
+
scopeTimeZone?: string;
|
|
85
86
|
testID?: string;
|
|
86
87
|
}
|
|
87
88
|
|
|
@@ -110,11 +111,12 @@ const recordKey = (view: AnyResourceView<Row>, row: Row) => {
|
|
|
110
111
|
export function NativeResourceView<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
111
112
|
const scope = useOptionalViewerScope();
|
|
112
113
|
const viewer = scope?.timeZone;
|
|
113
|
-
const
|
|
114
|
+
const scopeZone = props.scopeTimeZone ?? scope?.scopeTimeZone;
|
|
114
115
|
const zones = useMemo<DisplayTimeZones>(() => {
|
|
115
116
|
const own = personTimeZone({ timeZone: viewer });
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
// An unknown zone is loud (core's scopeClock), never a quiet fall back to the viewer's clock.
|
|
118
|
+
return { viewer: own, scope: scopeClock(scopeZone, own) };
|
|
119
|
+
}, [viewer, scopeZone]);
|
|
118
120
|
return (
|
|
119
121
|
<DisplayTimeZonesProvider value={zones}>
|
|
120
122
|
<Screen {...props} />
|
|
@@ -256,7 +258,7 @@ function Screen<T extends Row = Row>(props: NativeResourceViewProps<T>) {
|
|
|
256
258
|
header,
|
|
257
259
|
emptyState,
|
|
258
260
|
searchable,
|
|
259
|
-
|
|
261
|
+
scopeTimeZone: _zone,
|
|
260
262
|
testID = "native-resource-view",
|
|
261
263
|
...options
|
|
262
264
|
} = props;
|
|
@@ -695,16 +695,32 @@ describe("peek", () => {
|
|
|
695
695
|
expect(alert).toHaveBeenLastCalledWith("Move to Bin", "The default brand stays.");
|
|
696
696
|
});
|
|
697
697
|
|
|
698
|
-
it("reads a
|
|
698
|
+
it("reads a scope-clock column on the scope's zone: the prop, else ViewerScope's", async () => {
|
|
699
699
|
const clocked = defineView(brands, {
|
|
700
|
-
fields: { updated_at: { timeZone: "
|
|
700
|
+
fields: { updated_at: { timeZone: "scope" } },
|
|
701
701
|
columns: { default: ["name", "updated_at"] },
|
|
702
702
|
});
|
|
703
|
-
|
|
703
|
+
const at = "2026-01-02T10:00:00Z";
|
|
704
|
+
expect(formatInstant(at, "Asia/Tokyo")).not.toBe(formatInstant(at, "Europe/Berlin"));
|
|
705
|
+
|
|
706
|
+
const first = render(<NativeResourceView view={clocked} scopeTimeZone="Asia/Tokyo" />, { wrapper: wrap(provider()) });
|
|
704
707
|
fireEvent.click(await screen.findByTestId("native-resource-view-row-b2"));
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
+
expect((await screen.findByTestId("native-resource-view-peek")).textContent).toContain(formatInstant(at, "Asia/Tokyo"));
|
|
709
|
+
first.unmount();
|
|
710
|
+
|
|
711
|
+
// No prop: ViewerScope's scopeTimeZone.
|
|
712
|
+
const Base = wrap(provider());
|
|
713
|
+
render(<NativeResourceView view={clocked} />, {
|
|
714
|
+
wrapper: ({ children }: { children: ReactNode }) => (
|
|
715
|
+
<Base>
|
|
716
|
+
<ViewerScope viewer="ann" timeZone="America/Los_Angeles" scopeTimeZone="Europe/Berlin">
|
|
717
|
+
{children}
|
|
718
|
+
</ViewerScope>
|
|
719
|
+
</Base>
|
|
720
|
+
),
|
|
721
|
+
});
|
|
722
|
+
fireEvent.click(await screen.findByTestId("native-resource-view-row-b2"));
|
|
723
|
+
expect((await screen.findByTestId("native-resource-view-peek")).textContent).toContain(formatInstant(at, "Europe/Berlin"));
|
|
708
724
|
});
|
|
709
725
|
|
|
710
726
|
it("shows view.columns() drawn like the cells: a when-false value and a sensitive field never appear", async () => {
|
|
@@ -742,13 +758,15 @@ describe("calendar days", () => {
|
|
|
742
758
|
});
|
|
743
759
|
|
|
744
760
|
describe("clocks", () => {
|
|
745
|
-
it("resolves viewer and
|
|
746
|
-
const zones = { viewer: "America/Los_Angeles",
|
|
761
|
+
it("resolves viewer and scope to the given zones, and refuses anything else", () => {
|
|
762
|
+
const zones = { viewer: "America/Los_Angeles", scope: "Europe/Berlin" };
|
|
747
763
|
expect(resolveZone(undefined, zones)).toBe("America/Los_Angeles");
|
|
748
764
|
expect(resolveZone("viewer", zones)).toBe("America/Los_Angeles");
|
|
749
|
-
expect(resolveZone("
|
|
765
|
+
expect(resolveZone("scope", zones)).toBe("Europe/Berlin");
|
|
750
766
|
expect(resolveZone("Asia/Tokyo", zones)).toBe("Asia/Tokyo");
|
|
751
|
-
|
|
767
|
+
// Never a quiet fall back to the viewer's clock: the removed name and an unknown zone throw.
|
|
768
|
+
expect(() => resolveZone("practice", zones)).toThrow(/"practice" was renamed "scope"/);
|
|
769
|
+
expect(() => resolveZone("Not/AZone", zones)).toThrow(RangeError);
|
|
752
770
|
});
|
|
753
771
|
});
|
|
754
772
|
|
|
@@ -17,10 +17,11 @@ import { NativeImage } from "../../components/image";
|
|
|
17
17
|
import { NativeText } from "../../components/text";
|
|
18
18
|
import { defaultNativeResourceViewMessages, type NativeResourceViewMessages } from "./messages";
|
|
19
19
|
|
|
20
|
-
/** The clocks a timestamp can be read on: the viewer's and the
|
|
20
|
+
/** The clocks a timestamp can be read on: the viewer's and the scope's (IANA names). */
|
|
21
21
|
export interface DisplayTimeZones {
|
|
22
22
|
viewer: string;
|
|
23
|
-
|
|
23
|
+
/** The zone of whatever the screen is scoped to (a location, a league, a team): `timeZone: "scope"`. */
|
|
24
|
+
scope: string;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/** What a renderer gets besides the value (as on the web, with native's messages and clocks). */
|
|
@@ -76,11 +77,20 @@ export function formatDay(value: unknown, zone: string = personTimeZone()): stri
|
|
|
76
77
|
return DAY.format(new Date(wall.year, wall.month - 1, wall.day));
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* A column's clock: "viewer" (the default) and "scope" from `zones`, else a valid IANA name.
|
|
82
|
+
* Anything else throws (`defineView` refuses it first): drawing it on the viewer's clock instead
|
|
83
|
+
* would show the wrong times with nothing to say so.
|
|
84
|
+
*/
|
|
80
85
|
export function resolveZone(zone: string | undefined, zones: DisplayTimeZones): string {
|
|
81
86
|
if (!zone || zone === "viewer") return zones.viewer;
|
|
82
|
-
if (zone === "
|
|
83
|
-
|
|
87
|
+
if (zone === "scope") return zones.scope;
|
|
88
|
+
if (isTimeZone(zone)) return zone;
|
|
89
|
+
throw new RangeError(
|
|
90
|
+
zone === "practice"
|
|
91
|
+
? `[genesis-ui-native] timeZone "practice" was renamed "scope" in genesis-core 2; run \`genesis codemod genesis-core-2-scope-names\``
|
|
92
|
+
: `[genesis-ui-native] timeZone "${zone}" isn't "viewer", "scope" or a time zone this runtime knows`,
|
|
93
|
+
);
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
// The wall clock's parts are drawn as UTC, so one formatter serves every zone.
|
|
@@ -242,7 +252,7 @@ export const DisplayTimeZonesProvider = TimeZonesContext.Provider;
|
|
|
242
252
|
/** The clocks for timestamps: the nearest provider's, else the device's for both. */
|
|
243
253
|
export function useDisplayTimeZones(): DisplayTimeZones {
|
|
244
254
|
const zones = useContext(TimeZonesContext);
|
|
245
|
-
return useMemo(() => zones ?? { viewer: personTimeZone(),
|
|
255
|
+
return useMemo(() => zones ?? { viewer: personTimeZone(), scope: personTimeZone() }, [zones]);
|
|
246
256
|
}
|
|
247
257
|
|
|
248
258
|
/** Replace some of the renderers for everything below (nested providers build on each other). */
|