@marktiderman/genesis-ui-native 3.1.0 → 3.2.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.d.ts +42 -21
- package/dist/data/index.js +46 -33
- package/dist/data/index.js.map +1 -1
- package/package.json +23 -9
- package/src/__tests__/fake-modules.tsx +10 -3
- package/src/data/resource-view/{NativeResourceWorkspace.tsx → NativeRecordView.tsx} +91 -56
- package/src/data/resource-view/__tests__/{native-resource-workspace.test.tsx → native-record-view.test.tsx} +34 -34
- package/src/data/resource-view/index.ts +10 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @feat:native-components
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* - the title and the header menu come from
|
|
3
|
+
* NativeRecordView: one record's screen from a genesis-core page, natively.
|
|
4
|
+
* - the title and the header menu come from getNativeRecordViewStackOptions;
|
|
5
5
|
* - up to four sections are a segmented control, more are pushed rows;
|
|
6
6
|
* - a list section is an embedded NativeResourceView filtered by the row;
|
|
7
7
|
* - a settings section saves only its changed listed keys; a zero-row save is a refusal, inline;
|
|
@@ -13,8 +13,8 @@ import { useState, type ReactNode } from "react";
|
|
|
13
13
|
import { ActionSheetIOS, Alert, Platform } from "react-native";
|
|
14
14
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
15
15
|
import { defineResource, GenesisProvider, ViewerScope, type DataProvider, type ListParams, type Viewer } from "@marktiderman/genesis-core";
|
|
16
|
-
import { defineView,
|
|
17
|
-
import {
|
|
16
|
+
import { defineView, defineRecordView } from "@marktiderman/genesis-core/resource-view";
|
|
17
|
+
import { getNativeRecordViewStackOptions, NativeRecordView, NativeRecordViewMenu, parseSettingNumber } from "..";
|
|
18
18
|
|
|
19
19
|
type Brand = { id: string; name: string; website: string | null; public: boolean; is_default: boolean };
|
|
20
20
|
type Product = { id: string; brand_id: string; title: string };
|
|
@@ -56,7 +56,7 @@ const sections = [
|
|
|
56
56
|
{ id: "settings", label: "Settings", settings: ["website", "public"] as const },
|
|
57
57
|
{ id: "activity", label: "Activity" },
|
|
58
58
|
];
|
|
59
|
-
const
|
|
59
|
+
const page = defineRecordView(brandsView, {
|
|
60
60
|
sections,
|
|
61
61
|
readiness: (b) => [
|
|
62
62
|
{ title: "Has a website", ok: !!b.website, reason: "Add the website.", tone: "danger" },
|
|
@@ -95,20 +95,20 @@ beforeEach(() => {
|
|
|
95
95
|
(ActionSheetIOS.showActionSheetWithOptions as unknown as { mockClear: () => void }).mockClear();
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
describe("
|
|
98
|
+
describe("NativeRecordView", () => {
|
|
99
99
|
it("puts the title in the navigation bar and the actions in the header menu", () => {
|
|
100
|
-
const options =
|
|
100
|
+
const options = getNativeRecordViewStackOptions({ view: page, row: brand });
|
|
101
101
|
expect(options.title).toBe("Northwind");
|
|
102
102
|
expect(typeof options.headerRight).toBe("function");
|
|
103
|
-
const none =
|
|
104
|
-
expect(
|
|
103
|
+
const none = defineRecordView(brandsView, { header: { actions: [] }, sections: [{ id: "a", label: "A" }] });
|
|
104
|
+
expect(getNativeRecordViewStackOptions({ view: none, row: brand }).headerRight).toBeUndefined();
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
it("iOS: the menu is an action sheet; a refused action explains, a confirm asks, then the provider runs it", async () => {
|
|
108
108
|
const alert = vi.spyOn(Alert, "alert").mockImplementation(() => {});
|
|
109
109
|
const sheet = vi.spyOn(ActionSheetIOS, "showActionSheetWithOptions").mockImplementation(() => {});
|
|
110
110
|
const p = provider();
|
|
111
|
-
render(<
|
|
111
|
+
render(<NativeRecordViewMenu view={page} row={brand} />, { wrapper: wrap(p) });
|
|
112
112
|
fireEvent.click(screen.getByTestId("native-resource-workspace-menu"));
|
|
113
113
|
const [options, pick] = sheet.mock.calls[0]!;
|
|
114
114
|
expect(options.options).toEqual(["Archive (The default brand stays.)", "Publish", "Purge", "Cancel"]);
|
|
@@ -121,7 +121,7 @@ describe("NativeResourceWorkspace", () => {
|
|
|
121
121
|
|
|
122
122
|
alert.mockClear();
|
|
123
123
|
const onAction = vi.fn();
|
|
124
|
-
render(<
|
|
124
|
+
render(<NativeRecordViewMenu view={page} row={{ ...brand, is_default: false }} onAction={onAction} testID="menu2" />, {
|
|
125
125
|
wrapper: wrap(provider()),
|
|
126
126
|
});
|
|
127
127
|
fireEvent.click(screen.getByTestId("menu2"));
|
|
@@ -140,7 +140,7 @@ describe("NativeResourceWorkspace", () => {
|
|
|
140
140
|
const alert = vi.spyOn(Alert, "alert").mockImplementation(() => {});
|
|
141
141
|
try {
|
|
142
142
|
const p = provider();
|
|
143
|
-
render(<
|
|
143
|
+
render(<NativeRecordViewMenu view={page} row={{ ...brand, is_default: false }} />, { wrapper: wrap(p) });
|
|
144
144
|
fireEvent.click(screen.getByTestId("native-resource-workspace-menu"));
|
|
145
145
|
expect(alert).not.toHaveBeenCalled();
|
|
146
146
|
expect((await screen.findByTestId("native-resource-workspace-menu-purge")).textContent).toContain("Purge");
|
|
@@ -155,7 +155,7 @@ describe("NativeResourceWorkspace", () => {
|
|
|
155
155
|
let finish!: () => void;
|
|
156
156
|
const runAction = vi.fn(() => new Promise<{ data: null }>((resolve) => (finish = () => resolve({ data: null }))));
|
|
157
157
|
const sheet = vi.spyOn(ActionSheetIOS, "showActionSheetWithOptions").mockImplementation(() => {});
|
|
158
|
-
render(<
|
|
158
|
+
render(<NativeRecordViewMenu view={page} row={brand} />, { wrapper: wrap(provider({ runAction: runAction as never })) });
|
|
159
159
|
fireEvent.click(screen.getByTestId("native-resource-workspace-menu"));
|
|
160
160
|
const pick = sheet.mock.calls[0]![1];
|
|
161
161
|
pick(1);
|
|
@@ -168,9 +168,9 @@ describe("NativeResourceWorkspace", () => {
|
|
|
168
168
|
|
|
169
169
|
it("names accessibility actions with a prefix, so 'activate' can't take over the button", async () => {
|
|
170
170
|
const view = defineView(brands, { actions: [{ name: "activate", label: "Activate" }] });
|
|
171
|
-
const ws =
|
|
171
|
+
const ws = defineRecordView(view, { sections: [{ id: "a", label: "A" }] });
|
|
172
172
|
const p = provider();
|
|
173
|
-
render(<
|
|
173
|
+
render(<NativeRecordViewMenu view={ws} row={brand} />, { wrapper: wrap(p) });
|
|
174
174
|
const button = screen.getByTestId("native-resource-workspace-menu");
|
|
175
175
|
expect(button.getAttribute("data-a11y-actions")).toBe("action:activate");
|
|
176
176
|
// The platform's own "activate" does nothing here; the prefixed one runs the action.
|
|
@@ -181,16 +181,16 @@ describe("NativeResourceWorkspace", () => {
|
|
|
181
181
|
});
|
|
182
182
|
|
|
183
183
|
it("hides actions when nothing can run them, or the screen turns them off", () => {
|
|
184
|
-
render(<
|
|
184
|
+
render(<NativeRecordViewMenu view={page} row={brand} testID="none" />, { wrapper: wrap(provider({ runAction: undefined })) });
|
|
185
185
|
expect(screen.queryByTestId("none")).toBeNull();
|
|
186
186
|
const sheet = vi.spyOn(ActionSheetIOS, "showActionSheetWithOptions").mockImplementation(() => {});
|
|
187
|
-
render(<
|
|
187
|
+
render(<NativeRecordViewMenu view={page} row={brand} can={(name) => name !== "publish"} />, { wrapper: wrap(provider()) });
|
|
188
188
|
fireEvent.click(screen.getByTestId("native-resource-workspace-menu"));
|
|
189
189
|
expect(sheet.mock.calls.at(-1)![0].options).not.toContain("Publish");
|
|
190
190
|
});
|
|
191
191
|
|
|
192
192
|
it("shows up to four sections as a segmented control, and the readiness checks", () => {
|
|
193
|
-
render(<
|
|
193
|
+
render(<NativeRecordView view={page} row={brand} section="activity" slots={{ activity: <></> }} switcher={<></>} />, {
|
|
194
194
|
wrapper: wrap(provider()),
|
|
195
195
|
});
|
|
196
196
|
const control = screen.getByTestId("native-resource-workspace-sections");
|
|
@@ -202,7 +202,7 @@ describe("NativeResourceWorkspace", () => {
|
|
|
202
202
|
});
|
|
203
203
|
|
|
204
204
|
it("shows the summary chip alone once every check is met", () => {
|
|
205
|
-
render(<
|
|
205
|
+
render(<NativeRecordView view={page} row={{ ...brand, website: "https://x.example" }} section="activity" messages={{ ready: "Ready to go" }} />, {
|
|
206
206
|
wrapper: wrap(provider()),
|
|
207
207
|
});
|
|
208
208
|
expect(screen.getByTestId("native-resource-workspace-readiness").textContent).toBe("Ready to go");
|
|
@@ -210,11 +210,11 @@ describe("NativeResourceWorkspace", () => {
|
|
|
210
210
|
});
|
|
211
211
|
|
|
212
212
|
it("pushes sections when there are more than four", () => {
|
|
213
|
-
const wide =
|
|
213
|
+
const wide = defineRecordView(brandsView, {
|
|
214
214
|
sections: ["a", "b", "c", "d", "e"].map((id) => ({ id, label: id.toUpperCase() })),
|
|
215
215
|
});
|
|
216
216
|
const onOpenSection = vi.fn();
|
|
217
|
-
render(<
|
|
217
|
+
render(<NativeRecordView view={wide} row={brand} onOpenSection={onOpenSection} />, { wrapper: wrap(provider()) });
|
|
218
218
|
expect(screen.queryByTestId("native-resource-workspace-sections-option-a")).toBeNull();
|
|
219
219
|
fireEvent.click(screen.getByTestId("native-resource-workspace-section-e"));
|
|
220
220
|
expect(onOpenSection).toHaveBeenCalledWith("e");
|
|
@@ -222,7 +222,7 @@ describe("NativeResourceWorkspace", () => {
|
|
|
222
222
|
|
|
223
223
|
it("draws a list section as an embedded NativeResourceView filtered by the row", async () => {
|
|
224
224
|
const p = provider();
|
|
225
|
-
render(<
|
|
225
|
+
render(<NativeRecordView view={page} row={brand} />, { wrapper: wrap(p) });
|
|
226
226
|
expect(await screen.findByText("Kettle")).toBeTruthy();
|
|
227
227
|
const params = (p.getList as ReturnType<typeof vi.fn>).mock.calls[0]![1] as ListParams;
|
|
228
228
|
expect(params.filters).toContainEqual({ field: "brand_id", operator: "eq", value: "b1" });
|
|
@@ -231,7 +231,7 @@ describe("NativeResourceWorkspace", () => {
|
|
|
231
231
|
it("switches sections and saves only the changed listed keys", async () => {
|
|
232
232
|
const p = provider();
|
|
233
233
|
const onSaved = vi.fn();
|
|
234
|
-
render(<
|
|
234
|
+
render(<NativeRecordView view={page} row={brand} onSaved={onSaved} />, { wrapper: wrap(p) });
|
|
235
235
|
fireEvent.click(screen.getByTestId("native-resource-workspace-sections-option-settings"));
|
|
236
236
|
const input = screen.getByTestId("native-resource-workspace-settings-website-input");
|
|
237
237
|
fireEvent.change(input, { target: { value: "https://northwind.example" } });
|
|
@@ -242,15 +242,15 @@ describe("NativeResourceWorkspace", () => {
|
|
|
242
242
|
|
|
243
243
|
it("shows a zero-row save as a refusal, inline", async () => {
|
|
244
244
|
const p = provider({ update: vi.fn(async () => ({ data: null })) as unknown as DataProvider["update"] });
|
|
245
|
-
render(<
|
|
245
|
+
render(<NativeRecordView view={page} row={brand} section="settings" />, { wrapper: wrap(p) });
|
|
246
246
|
fireEvent.change(screen.getByTestId("native-resource-workspace-settings-website-input"), { target: { value: "https://x.example" } });
|
|
247
247
|
fireEvent.click(screen.getByTestId("native-resource-workspace-settings-save"));
|
|
248
248
|
expect((await screen.findByTestId("native-resource-workspace-settings-refusal")).textContent).toContain("This brand was not changed.");
|
|
249
249
|
});
|
|
250
250
|
});
|
|
251
251
|
|
|
252
|
-
describe("
|
|
253
|
-
const locking =
|
|
252
|
+
describe("NativeRecordView review fixes", () => {
|
|
253
|
+
const locking = defineRecordView(
|
|
254
254
|
defineView(brands, {
|
|
255
255
|
fields: { website: { visible: (v) => v["public"] === true } },
|
|
256
256
|
can: { update: (b) => (b.is_default ? "Locked." : true) },
|
|
@@ -259,14 +259,14 @@ describe("NativeResourceWorkspace review fixes", () => {
|
|
|
259
259
|
);
|
|
260
260
|
|
|
261
261
|
it("shows settings read-only with the reason when the view refuses update", () => {
|
|
262
|
-
render(<
|
|
262
|
+
render(<NativeRecordView view={locking} row={brand} />, { wrapper: wrap(provider()) });
|
|
263
263
|
expect(screen.getByTestId("native-resource-workspace-settings-locked").textContent).toContain("Locked.");
|
|
264
264
|
expect(screen.queryByTestId("native-resource-workspace-settings-save")).toBeNull();
|
|
265
265
|
});
|
|
266
266
|
|
|
267
267
|
it("leaves a field hidden by `visible` out of the save", async () => {
|
|
268
268
|
const p = provider();
|
|
269
|
-
render(<
|
|
269
|
+
render(<NativeRecordView view={locking} row={{ ...brand, is_default: false, public: true }} />, { wrapper: wrap(p) });
|
|
270
270
|
fireEvent.change(screen.getByTestId("native-resource-workspace-settings-website-input"), { target: { value: "https://x.example" } });
|
|
271
271
|
fireEvent.change(screen.getByTestId("native-resource-workspace-settings-name-input"), { target: { value: "Southwind" } });
|
|
272
272
|
fireEvent.click(screen.getByTestId("native-resource-workspace-settings-public-input"));
|
|
@@ -276,8 +276,8 @@ describe("NativeResourceWorkspace review fixes", () => {
|
|
|
276
276
|
});
|
|
277
277
|
|
|
278
278
|
it("opens a section in place with a way back when there are more than four and no onOpenSection", () => {
|
|
279
|
-
const wide =
|
|
280
|
-
render(<
|
|
279
|
+
const wide = defineRecordView(brandsView, { sections: ["a", "b", "c", "d", "e"].map((id) => ({ id, label: id.toUpperCase() })) });
|
|
280
|
+
render(<NativeRecordView view={wide} row={brand} slots={{ e: <p>Section E</p> }} />, { wrapper: wrap(provider()) });
|
|
281
281
|
fireEvent.click(screen.getByTestId("native-resource-workspace-section-e"));
|
|
282
282
|
expect(screen.getByText("Section E")).toBeTruthy();
|
|
283
283
|
fireEvent.click(screen.getByTestId("native-resource-workspace-all-sections"));
|
|
@@ -294,9 +294,9 @@ describe("NativeResourceWorkspace review fixes", () => {
|
|
|
294
294
|
});
|
|
295
295
|
});
|
|
296
296
|
|
|
297
|
-
describe("
|
|
297
|
+
describe("NativeRecordView when only the viewer's roles change", () => {
|
|
298
298
|
const isEditor = (v?: Viewer) => ((v?.roles as { teamRoles?: readonly string[] } | undefined)?.teamRoles ?? []).includes("editor");
|
|
299
|
-
const guarded =
|
|
299
|
+
const guarded = defineRecordView(
|
|
300
300
|
defineView(brands, {
|
|
301
301
|
can: { update: (_b, v) => (isEditor(v) ? true : "Only editors change brands.") },
|
|
302
302
|
actions: [{ name: "publish", label: "Publish", can: (_b, v) => (isEditor(v) ? true : "Only editors publish.") }],
|
|
@@ -318,8 +318,8 @@ describe("NativeResourceWorkspace when only the viewer's roles change", () => {
|
|
|
318
318
|
<Base>
|
|
319
319
|
<ViewerScope viewer="ann" roles={roles as never}>
|
|
320
320
|
<Mounts />
|
|
321
|
-
<
|
|
322
|
-
<
|
|
321
|
+
<NativeRecordViewMenu view={guarded} row={brand} />
|
|
322
|
+
<NativeRecordView view={guarded} row={brand} />
|
|
323
323
|
</ViewerScope>
|
|
324
324
|
</Base>
|
|
325
325
|
);
|
|
@@ -50,13 +50,20 @@ export {
|
|
|
50
50
|
} from "./mapping";
|
|
51
51
|
export { defaultNativeResourceViewMessages, type NativeResourceViewMessages } from "./messages";
|
|
52
52
|
export {
|
|
53
|
+
NativeRecordView,
|
|
54
|
+
NativeRecordViewMenu,
|
|
55
|
+
getNativeRecordViewStackOptions,
|
|
56
|
+
defaultNativeRecordViewMessages,
|
|
57
|
+
SEGMENTED_SECTIONS_MAX,
|
|
58
|
+
parseSettingNumber,
|
|
59
|
+
type NativeRecordViewProps,
|
|
60
|
+
type NativeRecordViewHeaderProps,
|
|
61
|
+
type NativeRecordViewMessages,
|
|
53
62
|
NativeResourceWorkspace,
|
|
54
63
|
NativeResourceWorkspaceMenu,
|
|
55
64
|
getNativeResourceWorkspaceStackOptions,
|
|
56
65
|
defaultNativeResourceWorkspaceMessages,
|
|
57
|
-
SEGMENTED_SECTIONS_MAX,
|
|
58
|
-
parseSettingNumber,
|
|
59
66
|
type NativeResourceWorkspaceProps,
|
|
60
67
|
type NativeResourceWorkspaceHeaderProps,
|
|
61
68
|
type NativeResourceWorkspaceMessages,
|
|
62
|
-
} from "./
|
|
69
|
+
} from "./NativeRecordView";
|