@terreno/ui 57.16.2 → 57.18.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/Banner.d.ts +2 -1
- package/dist/Banner.d.ts.map +1 -1
- package/dist/Banner.js +2 -2
- package/dist/Banner.js.map +1 -1
- package/dist/DataTable.d.ts.map +1 -1
- package/dist/DataTable.js +10 -7
- package/dist/DataTable.js.map +1 -1
- package/dist/GPTChat.d.ts +7 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +2 -2
- package/dist/GPTChat.js.map +1 -1
- package/dist/WhatsNewBanner.d.ts +42 -0
- package/dist/WhatsNewBanner.d.ts.map +1 -0
- package/dist/WhatsNewBanner.js +68 -0
- package/dist/WhatsNewBanner.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/Banner.tsx +3 -0
- package/src/DataTable.tsx +11 -7
- package/src/GPTChat.test.tsx +18 -0
- package/src/GPTChat.tsx +71 -54
- package/src/IconButton.test.tsx +178 -0
- package/src/WhatsNewBanner.test.tsx +186 -0
- package/src/WhatsNewBanner.tsx +191 -0
- package/src/bunSetup.ts +31 -0
- package/src/index.tsx +1 -0
package/src/IconButton.test.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {act, fireEvent, waitFor} from "@testing-library/react-native";
|
|
2
3
|
import type {ReactTestInstance} from "react-test-renderer";
|
|
3
4
|
|
|
4
5
|
import {IconButton} from "./IconButton";
|
|
@@ -267,4 +268,181 @@ describe("IconButton", () => {
|
|
|
267
268
|
).not.toThrow();
|
|
268
269
|
});
|
|
269
270
|
});
|
|
271
|
+
describe("interaction (real component)", () => {
|
|
272
|
+
// bunSetup replaces ./IconButton with a null mock; the query suffix loads the real module.
|
|
273
|
+
const loadIconButton = async (): Promise<typeof import("./IconButton").IconButton> => {
|
|
274
|
+
const actualIconButtonPath = "./IconButton.tsx?interaction";
|
|
275
|
+
const module = (await import(actualIconButtonPath)) as typeof import("./IconButton");
|
|
276
|
+
return module.IconButton;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
it("runs onClick once when pressed without confirmation", async () => {
|
|
280
|
+
const ActualIconButton = await loadIconButton();
|
|
281
|
+
const handleClick = mock(() => Promise.resolve());
|
|
282
|
+
const {getByLabelText} = renderWithTheme(
|
|
283
|
+
<ActualIconButton accessibilityLabel="Save" iconName="check" onClick={handleClick} />
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
await act(async () => {
|
|
287
|
+
fireEvent.press(getByLabelText("Save"));
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
await waitFor(() => {
|
|
291
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("asks for confirmation first and runs onClick only after Confirm", async () => {
|
|
296
|
+
const ActualIconButton = await loadIconButton();
|
|
297
|
+
const handleClick = mock(() => Promise.resolve());
|
|
298
|
+
const {getByLabelText, getByText} = renderWithTheme(
|
|
299
|
+
<ActualIconButton
|
|
300
|
+
accessibilityLabel="Delete"
|
|
301
|
+
confirmationHeading="Delete item"
|
|
302
|
+
confirmationText="This cannot be undone."
|
|
303
|
+
iconName="trash"
|
|
304
|
+
onClick={handleClick}
|
|
305
|
+
withConfirmation
|
|
306
|
+
/>
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
expect(getByLabelText("Delete").props.accessibilityHint).toBe(
|
|
310
|
+
"Opens a confirmation dialog to confirm Delete"
|
|
311
|
+
);
|
|
312
|
+
await act(async () => {
|
|
313
|
+
fireEvent.press(getByLabelText("Delete"));
|
|
314
|
+
});
|
|
315
|
+
await waitFor(() => {
|
|
316
|
+
expect(getByText("This cannot be undone.")).toBeTruthy();
|
|
317
|
+
});
|
|
318
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
319
|
+
|
|
320
|
+
await act(async () => {
|
|
321
|
+
fireEvent.press(getByText("Confirm"));
|
|
322
|
+
});
|
|
323
|
+
await waitFor(() => {
|
|
324
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("closes the confirmation without running onClick on Cancel", async () => {
|
|
329
|
+
const ActualIconButton = await loadIconButton();
|
|
330
|
+
const handleClick = mock(() => Promise.resolve());
|
|
331
|
+
const {getByLabelText, getByText} = renderWithTheme(
|
|
332
|
+
<ActualIconButton
|
|
333
|
+
accessibilityLabel="Archive"
|
|
334
|
+
iconName="box-archive"
|
|
335
|
+
onClick={handleClick}
|
|
336
|
+
withConfirmation
|
|
337
|
+
/>
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
await act(async () => {
|
|
341
|
+
fireEvent.press(getByLabelText("Archive"));
|
|
342
|
+
});
|
|
343
|
+
await waitFor(() => {
|
|
344
|
+
expect(getByText("Are you sure you want to continue?")).toBeTruthy();
|
|
345
|
+
});
|
|
346
|
+
await act(async () => {
|
|
347
|
+
fireEvent.press(getByText("Cancel"));
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
expect(handleClick).not.toHaveBeenCalled();
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("colors each variant and state from the theme", async () => {
|
|
354
|
+
const ActualIconButton = await loadIconButton();
|
|
355
|
+
let theme = {} as ReturnType<typeof useTheme>["theme"];
|
|
356
|
+
const CaptureTheme = (): null => {
|
|
357
|
+
theme = useTheme().theme;
|
|
358
|
+
return null;
|
|
359
|
+
};
|
|
360
|
+
const {getByLabelText} = renderWithTheme(
|
|
361
|
+
<>
|
|
362
|
+
<CaptureTheme />
|
|
363
|
+
<ActualIconButton accessibilityLabel="primary" iconName="check" onClick={() => {}} />
|
|
364
|
+
<ActualIconButton
|
|
365
|
+
accessibilityLabel="secondary"
|
|
366
|
+
iconName="check"
|
|
367
|
+
onClick={() => {}}
|
|
368
|
+
variant="secondary"
|
|
369
|
+
/>
|
|
370
|
+
<ActualIconButton
|
|
371
|
+
accessibilityLabel="navigation"
|
|
372
|
+
iconName="check"
|
|
373
|
+
onClick={() => {}}
|
|
374
|
+
variant="navigation"
|
|
375
|
+
/>
|
|
376
|
+
<ActualIconButton
|
|
377
|
+
accessibilityLabel="destructive"
|
|
378
|
+
iconName="check"
|
|
379
|
+
onClick={() => {}}
|
|
380
|
+
variant="destructive"
|
|
381
|
+
/>
|
|
382
|
+
<ActualIconButton
|
|
383
|
+
accessibilityLabel="ghost"
|
|
384
|
+
iconName="check"
|
|
385
|
+
onClick={() => {}}
|
|
386
|
+
variant="ghost"
|
|
387
|
+
/>
|
|
388
|
+
<ActualIconButton
|
|
389
|
+
accessibilityLabel="disabled"
|
|
390
|
+
disabled
|
|
391
|
+
iconName="check"
|
|
392
|
+
onClick={() => {}}
|
|
393
|
+
/>
|
|
394
|
+
<ActualIconButton
|
|
395
|
+
accessibilityLabel="primary active"
|
|
396
|
+
iconName="check"
|
|
397
|
+
onClick={() => {}}
|
|
398
|
+
state="active"
|
|
399
|
+
/>
|
|
400
|
+
<ActualIconButton
|
|
401
|
+
accessibilityLabel="ghost active"
|
|
402
|
+
iconName="check"
|
|
403
|
+
onClick={() => {}}
|
|
404
|
+
state="active"
|
|
405
|
+
variant="ghost"
|
|
406
|
+
/>
|
|
407
|
+
<ActualIconButton
|
|
408
|
+
accessibilityLabel="small"
|
|
409
|
+
iconName="check"
|
|
410
|
+
indicator="error"
|
|
411
|
+
indicatorText="3"
|
|
412
|
+
onClick={() => {}}
|
|
413
|
+
size="sm"
|
|
414
|
+
/>
|
|
415
|
+
</>
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
expect(getByLabelText("primary")).toHaveStyle({backgroundColor: theme.surface.primary});
|
|
419
|
+
expect(getByLabelText("secondary")).toHaveStyle({
|
|
420
|
+
backgroundColor: theme.surface.neutralLight,
|
|
421
|
+
});
|
|
422
|
+
expect(getByLabelText("navigation")).toHaveStyle({backgroundColor: theme.text.inverted});
|
|
423
|
+
expect(getByLabelText("destructive")).toHaveStyle({backgroundColor: theme.text.inverted});
|
|
424
|
+
expect(getByLabelText("ghost")).toHaveStyle({backgroundColor: "transparent"});
|
|
425
|
+
expect(getByLabelText("disabled")).toHaveStyle({backgroundColor: theme.surface.disabled});
|
|
426
|
+
expect(getByLabelText("primary active")).toHaveStyle({
|
|
427
|
+
backgroundColor: theme.primitives.primary600,
|
|
428
|
+
});
|
|
429
|
+
expect(getByLabelText("ghost active")).toHaveStyle({backgroundColor: theme.surface.primary});
|
|
430
|
+
expect(getByLabelText("small")).toHaveStyle({height: 28, width: 28});
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it("uses the tooltip text as the label when the label is empty", async () => {
|
|
434
|
+
const ActualIconButton = await loadIconButton();
|
|
435
|
+
const {getByLabelText} = renderWithTheme(
|
|
436
|
+
<ActualIconButton
|
|
437
|
+
accessibilityLabel=""
|
|
438
|
+
iconName="gear"
|
|
439
|
+
onClick={() => {}}
|
|
440
|
+
tooltipText="Settings"
|
|
441
|
+
/>
|
|
442
|
+
);
|
|
443
|
+
expect(getByLabelText("Settings").props.accessibilityHint).toBe(
|
|
444
|
+
"Press to perform Settings action"
|
|
445
|
+
);
|
|
446
|
+
});
|
|
447
|
+
});
|
|
270
448
|
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {beforeEach, describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {act, fireEvent, waitFor} from "@testing-library/react-native";
|
|
3
|
+
import {type ScaledSize, StyleSheet, useWindowDimensions} from "react-native";
|
|
4
|
+
|
|
5
|
+
import {renderWithTheme} from "./test-utils";
|
|
6
|
+
import {Unifier} from "./Unifier";
|
|
7
|
+
import {getUnseenWhatsNewReleases, WhatsNewBanner, type WhatsNewRelease} from "./WhatsNewBanner";
|
|
8
|
+
|
|
9
|
+
const RELEASES: WhatsNewRelease[] = [
|
|
10
|
+
{body: "### Fixed\n\n- Third fix.", date: "2026-10-13", version: "3.0.0"},
|
|
11
|
+
{body: "### Added\n\n- Second feature.", date: "2026-10-12", version: "2.0.0"},
|
|
12
|
+
{body: "### Added\n\n- First feature.", date: "2026-10-01", version: "1.0.0"},
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
const STORAGE_KEY = "test:whatsNew";
|
|
16
|
+
|
|
17
|
+
type MockableUseWindowDimensions = (() => ScaledSize) & {
|
|
18
|
+
mockImplementation?: (impl: () => ScaledSize) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const setWindowHeight = (height: number): void => {
|
|
22
|
+
(useWindowDimensions as MockableUseWindowDimensions).mockImplementation?.(() => ({
|
|
23
|
+
fontScale: 1,
|
|
24
|
+
height,
|
|
25
|
+
scale: 2,
|
|
26
|
+
width: 375,
|
|
27
|
+
}));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const mockStoredVersion = (version: string | null): void => {
|
|
31
|
+
Unifier.storage.getItem = mock(() => Promise.resolve(version));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
describe("getUnseenWhatsNewReleases", () => {
|
|
35
|
+
it("returns every release when nothing was seen", () => {
|
|
36
|
+
expect(getUnseenWhatsNewReleases({releases: RELEASES})).toEqual(RELEASES);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("returns only releases newer than the last seen version", () => {
|
|
40
|
+
const unseen = getUnseenWhatsNewReleases({lastSeenVersion: "2.0.0", releases: RELEASES});
|
|
41
|
+
expect(unseen.map((release) => release.version)).toEqual(["3.0.0"]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("returns nothing when the latest release was seen", () => {
|
|
45
|
+
expect(getUnseenWhatsNewReleases({lastSeenVersion: "3.0.0", releases: RELEASES})).toEqual([]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("treats an unknown last seen version as nothing seen", () => {
|
|
49
|
+
const unseen = getUnseenWhatsNewReleases({lastSeenVersion: "0.1.0", releases: RELEASES});
|
|
50
|
+
expect(unseen).toEqual(RELEASES);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("WhatsNewBanner", () => {
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
mockStoredVersion(null);
|
|
57
|
+
Unifier.storage.setItem = mock(() => Promise.resolve());
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("shows the latest version and how many earlier releases are unseen", async () => {
|
|
61
|
+
const {findByTestId} = renderWithTheme(
|
|
62
|
+
<WhatsNewBanner releases={RELEASES} storageKey={STORAGE_KEY} />
|
|
63
|
+
);
|
|
64
|
+
const text = await findByTestId("whats-new-banner-text");
|
|
65
|
+
expect(text.props.children).toBe("What's new in 3.0.0 and 2 earlier releases");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("names a single unseen release without an earlier count", async () => {
|
|
69
|
+
mockStoredVersion("2.0.0");
|
|
70
|
+
const {findByTestId} = renderWithTheme(
|
|
71
|
+
<WhatsNewBanner releases={RELEASES} storageKey={STORAGE_KEY} />
|
|
72
|
+
);
|
|
73
|
+
const text = await findByTestId("whats-new-banner-text");
|
|
74
|
+
expect(text.props.children).toBe("What's new in 3.0.0");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("renders nothing once the latest release was seen", async () => {
|
|
78
|
+
mockStoredVersion("3.0.0");
|
|
79
|
+
const {queryByTestId} = renderWithTheme(
|
|
80
|
+
<WhatsNewBanner releases={RELEASES} storageKey={STORAGE_KEY} />
|
|
81
|
+
);
|
|
82
|
+
await waitFor(() => {
|
|
83
|
+
expect(Unifier.storage.getItem).toHaveBeenCalledWith(STORAGE_KEY);
|
|
84
|
+
});
|
|
85
|
+
expect(queryByTestId("whats-new-banner")).toBeNull();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("renders nothing without releases", async () => {
|
|
89
|
+
const {queryByTestId} = renderWithTheme(
|
|
90
|
+
<WhatsNewBanner releases={[]} storageKey={STORAGE_KEY} />
|
|
91
|
+
);
|
|
92
|
+
await waitFor(() => {
|
|
93
|
+
expect(Unifier.storage.getItem).toHaveBeenCalled();
|
|
94
|
+
});
|
|
95
|
+
expect(queryByTestId("whats-new-banner")).toBeNull();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("dismissing stores the latest version and hides the banner", async () => {
|
|
99
|
+
const {findByLabelText, queryByTestId} = renderWithTheme(
|
|
100
|
+
<WhatsNewBanner releases={RELEASES} storageKey={STORAGE_KEY} />
|
|
101
|
+
);
|
|
102
|
+
const dismiss = await findByLabelText("Dismiss what's new");
|
|
103
|
+
await act(async () => {
|
|
104
|
+
fireEvent.press(dismiss);
|
|
105
|
+
});
|
|
106
|
+
expect(Unifier.storage.setItem).toHaveBeenCalledWith(STORAGE_KEY, "3.0.0");
|
|
107
|
+
await waitFor(() => {
|
|
108
|
+
expect(queryByTestId("whats-new-banner")).toBeNull();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("opening lists the unseen release notes and marks them seen", async () => {
|
|
113
|
+
mockStoredVersion("1.0.0");
|
|
114
|
+
const onOpen = mock(() => undefined);
|
|
115
|
+
const {findByTestId, queryByTestId} = renderWithTheme(
|
|
116
|
+
<WhatsNewBanner onOpen={onOpen} releases={RELEASES} storageKey={STORAGE_KEY} />
|
|
117
|
+
);
|
|
118
|
+
const openButton = await findByTestId("whats-new-banner-open-button");
|
|
119
|
+
await act(async () => {
|
|
120
|
+
fireEvent.press(openButton);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
await waitFor(() => {
|
|
124
|
+
expect(Unifier.storage.setItem).toHaveBeenCalledWith(STORAGE_KEY, "3.0.0");
|
|
125
|
+
});
|
|
126
|
+
expect(onOpen).toHaveBeenCalledTimes(1);
|
|
127
|
+
expect(await findByTestId("whats-new-banner-release-3.0.0")).toBeTruthy();
|
|
128
|
+
expect(await findByTestId("whats-new-banner-release-2.0.0")).toBeTruthy();
|
|
129
|
+
expect(queryByTestId("whats-new-banner-release-1.0.0")).toBeNull();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("leaves room for the modal title and Done button on short windows", async () => {
|
|
133
|
+
const openNotesMaxHeight = async (height: number): Promise<unknown> => {
|
|
134
|
+
setWindowHeight(height);
|
|
135
|
+
mockStoredVersion(null);
|
|
136
|
+
const {findByTestId, getByTestId, unmount} = renderWithTheme(
|
|
137
|
+
<WhatsNewBanner releases={RELEASES} storageKey={STORAGE_KEY} />
|
|
138
|
+
);
|
|
139
|
+
const openButton = await findByTestId("whats-new-banner-open-button");
|
|
140
|
+
await act(async () => {
|
|
141
|
+
fireEvent.press(openButton);
|
|
142
|
+
});
|
|
143
|
+
const maxHeight = StyleSheet.flatten(
|
|
144
|
+
getByTestId("whats-new-banner-notes").props.style
|
|
145
|
+
).maxHeight;
|
|
146
|
+
unmount();
|
|
147
|
+
return maxHeight;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
expect(await openNotesMaxHeight(1000)).toBe(600);
|
|
152
|
+
expect(await openNotesMaxHeight(400)).toBe(160);
|
|
153
|
+
expect(await openNotesMaxHeight(300)).toBe(120);
|
|
154
|
+
} finally {
|
|
155
|
+
setWindowHeight(812);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("keeps the open notes mounted when marking them seen hides the banner", async () => {
|
|
160
|
+
mockStoredVersion("1.0.0");
|
|
161
|
+
let finishSave: () => void = () => undefined;
|
|
162
|
+
Unifier.storage.setItem = mock(
|
|
163
|
+
() =>
|
|
164
|
+
new Promise<void>((resolve) => {
|
|
165
|
+
finishSave = resolve;
|
|
166
|
+
})
|
|
167
|
+
);
|
|
168
|
+
const {findByTestId, getByTestId, queryByTestId} = renderWithTheme(
|
|
169
|
+
<WhatsNewBanner releases={RELEASES} storageKey={STORAGE_KEY} />
|
|
170
|
+
);
|
|
171
|
+
const openButton = await findByTestId("whats-new-banner-open-button");
|
|
172
|
+
await act(async () => {
|
|
173
|
+
fireEvent.press(openButton);
|
|
174
|
+
});
|
|
175
|
+
const notesWhileBannerShown = getByTestId("whats-new-banner-notes");
|
|
176
|
+
|
|
177
|
+
await act(async () => {
|
|
178
|
+
finishSave();
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
await waitFor(() => {
|
|
182
|
+
expect(queryByTestId("whats-new-banner")).toBeNull();
|
|
183
|
+
});
|
|
184
|
+
expect(getByTestId("whats-new-banner-notes")).toBe(notesWhileBannerShown);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import {useCallback, useMemo, useState} from "react";
|
|
3
|
+
import {useWindowDimensions} from "react-native";
|
|
4
|
+
|
|
5
|
+
import {BannerButton} from "./Banner";
|
|
6
|
+
import {Box} from "./Box";
|
|
7
|
+
import {DismissButton} from "./DismissButton";
|
|
8
|
+
import {Heading} from "./Heading";
|
|
9
|
+
import {MarkdownView} from "./MarkdownView";
|
|
10
|
+
import {Modal} from "./Modal";
|
|
11
|
+
import {Text} from "./Text";
|
|
12
|
+
import {useStoredState} from "./useStoredState";
|
|
13
|
+
|
|
14
|
+
const DEFAULT_STORAGE_KEY = "@TerrenoUI:whatsNew:lastSeenVersion";
|
|
15
|
+
/** Share of the window height the release notes may fill before they scroll. */
|
|
16
|
+
const NOTES_MAX_HEIGHT_RATIO = 0.6;
|
|
17
|
+
/** Room the modal's padding, title, and Done button need outside the notes scroller. */
|
|
18
|
+
const MODAL_CHROME_HEIGHT = 240;
|
|
19
|
+
/** Smallest notes area, so very short windows still show a few lines. */
|
|
20
|
+
const NOTES_MIN_HEIGHT = 120;
|
|
21
|
+
|
|
22
|
+
const getNotesMaxHeight = (windowHeight: number): number =>
|
|
23
|
+
Math.round(
|
|
24
|
+
Math.max(
|
|
25
|
+
NOTES_MIN_HEIGHT,
|
|
26
|
+
Math.min(windowHeight * NOTES_MAX_HEIGHT_RATIO, windowHeight - MODAL_CHROME_HEIGHT)
|
|
27
|
+
)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export interface WhatsNewRelease {
|
|
31
|
+
/** Release version, for example "57.16.2". Identifies what the viewer has already seen. */
|
|
32
|
+
version: string;
|
|
33
|
+
/** ISO date (YYYY-MM-DD) the release shipped. */
|
|
34
|
+
date?: string;
|
|
35
|
+
/** Release notes as Markdown. */
|
|
36
|
+
body: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface WhatsNewBannerProps {
|
|
40
|
+
/** Releases ordered newest first. The first entry is the current release. */
|
|
41
|
+
releases: WhatsNewRelease[];
|
|
42
|
+
/**
|
|
43
|
+
* Storage key holding the last version the viewer saw. Change it to keep separate
|
|
44
|
+
* what's new histories (for example per product) on one device.
|
|
45
|
+
* @default "@TerrenoUI:whatsNew:lastSeenVersion"
|
|
46
|
+
*/
|
|
47
|
+
storageKey?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Modal title above the release notes.
|
|
50
|
+
* @default "What's new"
|
|
51
|
+
*/
|
|
52
|
+
title?: string;
|
|
53
|
+
/** Called when the viewer opens the release notes. */
|
|
54
|
+
onOpen?: () => void;
|
|
55
|
+
testID?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns the releases newer than `lastSeenVersion`, newest first. When the viewer has never
|
|
60
|
+
* seen a release, or the last seen version is no longer listed, every release is unseen.
|
|
61
|
+
*/
|
|
62
|
+
export const getUnseenWhatsNewReleases = ({
|
|
63
|
+
lastSeenVersion,
|
|
64
|
+
releases,
|
|
65
|
+
}: {
|
|
66
|
+
lastSeenVersion?: string;
|
|
67
|
+
releases: WhatsNewRelease[];
|
|
68
|
+
}): WhatsNewRelease[] => {
|
|
69
|
+
const lastSeenIndex = releases.findIndex((release) => release.version === lastSeenVersion);
|
|
70
|
+
if (lastSeenIndex === -1) {
|
|
71
|
+
return releases;
|
|
72
|
+
}
|
|
73
|
+
return releases.slice(0, lastSeenIndex);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Non-blocking release notes banner. Shows "What's new in 57.16.2" (the latest version) until
|
|
78
|
+
* the viewer opens or dismisses it, then stays hidden until a newer release is listed. Opening
|
|
79
|
+
* it lists the notes of every release the viewer has not seen yet.
|
|
80
|
+
*/
|
|
81
|
+
export const WhatsNewBanner: React.FC<WhatsNewBannerProps> = ({
|
|
82
|
+
releases,
|
|
83
|
+
storageKey = DEFAULT_STORAGE_KEY,
|
|
84
|
+
title = "What's new",
|
|
85
|
+
onOpen,
|
|
86
|
+
testID = "whats-new-banner",
|
|
87
|
+
}) => {
|
|
88
|
+
const [lastSeenVersion, setLastSeenVersion, isLoading] = useStoredState<string>(storageKey);
|
|
89
|
+
const [isModalVisible, setIsModalVisible] = useState(false);
|
|
90
|
+
const [modalReleases, setModalReleases] = useState<WhatsNewRelease[]>([]);
|
|
91
|
+
const {height: windowHeight} = useWindowDimensions();
|
|
92
|
+
|
|
93
|
+
const unseenReleases = useMemo(
|
|
94
|
+
() => getUnseenWhatsNewReleases({lastSeenVersion, releases}),
|
|
95
|
+
[lastSeenVersion, releases]
|
|
96
|
+
);
|
|
97
|
+
const latestRelease = releases[0];
|
|
98
|
+
|
|
99
|
+
const markLatestSeen = useCallback(async (): Promise<void> => {
|
|
100
|
+
if (!latestRelease) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
await setLastSeenVersion(latestRelease.version);
|
|
104
|
+
}, [latestRelease, setLastSeenVersion]);
|
|
105
|
+
|
|
106
|
+
const handleOpen = useCallback(async (): Promise<void> => {
|
|
107
|
+
// Snapshot the unseen list so marking it seen does not empty the open modal.
|
|
108
|
+
setModalReleases(unseenReleases);
|
|
109
|
+
setIsModalVisible(true);
|
|
110
|
+
onOpen?.();
|
|
111
|
+
await markLatestSeen();
|
|
112
|
+
}, [markLatestSeen, onOpen, unseenReleases]);
|
|
113
|
+
|
|
114
|
+
const handleCloseModal = useCallback((): void => {
|
|
115
|
+
setIsModalVisible(false);
|
|
116
|
+
}, []);
|
|
117
|
+
|
|
118
|
+
const modal = (
|
|
119
|
+
<Modal
|
|
120
|
+
onDismiss={handleCloseModal}
|
|
121
|
+
primaryButtonOnClick={handleCloseModal}
|
|
122
|
+
primaryButtonText="Done"
|
|
123
|
+
size="lg"
|
|
124
|
+
testID={`${testID}-modal`}
|
|
125
|
+
title={title}
|
|
126
|
+
visible={isModalVisible}
|
|
127
|
+
>
|
|
128
|
+
{/* Box applies maxHeight to the scroller's content too, so the cap lives on a wrapper. */}
|
|
129
|
+
<Box maxHeight={getNotesMaxHeight(windowHeight)} testID={`${testID}-notes`}>
|
|
130
|
+
<Box gap={4} scroll>
|
|
131
|
+
{modalReleases.map((release) => (
|
|
132
|
+
<Box gap={2} key={release.version} testID={`${testID}-release-${release.version}`}>
|
|
133
|
+
<Heading size="sm">
|
|
134
|
+
{release.date ? `${release.version} (${release.date})` : release.version}
|
|
135
|
+
</Heading>
|
|
136
|
+
<MarkdownView>{release.body}</MarkdownView>
|
|
137
|
+
</Box>
|
|
138
|
+
))}
|
|
139
|
+
</Box>
|
|
140
|
+
</Box>
|
|
141
|
+
</Modal>
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const isBannerVisible = !isLoading && Boolean(latestRelease) && unseenReleases.length > 0;
|
|
145
|
+
const moreCount = unseenReleases.length - 1;
|
|
146
|
+
const bannerText =
|
|
147
|
+
moreCount > 0
|
|
148
|
+
? `What's new in ${latestRelease?.version} and ${moreCount} earlier ${moreCount === 1 ? "release" : "releases"}`
|
|
149
|
+
: `What's new in ${latestRelease?.version}`;
|
|
150
|
+
|
|
151
|
+
// One return shape keeps the modal mounted in place when opening it hides the banner.
|
|
152
|
+
return (
|
|
153
|
+
<>
|
|
154
|
+
{isBannerVisible ? (
|
|
155
|
+
<Box
|
|
156
|
+
alignItems="center"
|
|
157
|
+
color="secondaryDark"
|
|
158
|
+
direction="row"
|
|
159
|
+
marginBottom={3}
|
|
160
|
+
minHeight={8}
|
|
161
|
+
padding={1}
|
|
162
|
+
rounding="md"
|
|
163
|
+
testID={testID}
|
|
164
|
+
width="100%"
|
|
165
|
+
>
|
|
166
|
+
<Box alignItems="center" direction="row" flex="grow" justifyContent="center" paddingX={2}>
|
|
167
|
+
<Text bold color="inverted" testID={`${testID}-text`}>
|
|
168
|
+
{bannerText}
|
|
169
|
+
</Text>
|
|
170
|
+
</Box>
|
|
171
|
+
<Box alignItems="center" direction="row" gap={2} paddingX={2}>
|
|
172
|
+
<BannerButton
|
|
173
|
+
buttonOnClick={handleOpen}
|
|
174
|
+
buttonText="See what's new"
|
|
175
|
+
testID={`${testID}-open-button`}
|
|
176
|
+
/>
|
|
177
|
+
<Box testID={`${testID}-dismiss`}>
|
|
178
|
+
<DismissButton
|
|
179
|
+
accessibilityHint="Hides the what's new banner until the next release"
|
|
180
|
+
accessibilityLabel="Dismiss what's new"
|
|
181
|
+
color="inverted"
|
|
182
|
+
onClick={markLatestSeen}
|
|
183
|
+
/>
|
|
184
|
+
</Box>
|
|
185
|
+
</Box>
|
|
186
|
+
</Box>
|
|
187
|
+
) : null}
|
|
188
|
+
{modal}
|
|
189
|
+
</>
|
|
190
|
+
);
|
|
191
|
+
};
|
package/src/bunSetup.ts
CHANGED
|
@@ -668,7 +668,37 @@ if (typeof globalThis.expo === "undefined") {
|
|
|
668
668
|
}
|
|
669
669
|
|
|
670
670
|
// Mock expo-router
|
|
671
|
+
const mockNavigationFonts = {
|
|
672
|
+
bold: {fontFamily: "System", fontWeight: "600"},
|
|
673
|
+
heavy: {fontFamily: "System", fontWeight: "700"},
|
|
674
|
+
medium: {fontFamily: "System", fontWeight: "500"},
|
|
675
|
+
regular: {fontFamily: "System", fontWeight: "400"},
|
|
676
|
+
};
|
|
671
677
|
mock.module("expo-router", () => ({
|
|
678
|
+
DarkTheme: {
|
|
679
|
+
colors: {
|
|
680
|
+
background: "rgb(1, 1, 1)",
|
|
681
|
+
border: "rgb(39, 39, 41)",
|
|
682
|
+
card: "rgb(18, 18, 18)",
|
|
683
|
+
notification: "rgb(255, 69, 58)",
|
|
684
|
+
primary: "rgb(10, 132, 255)",
|
|
685
|
+
text: "rgb(229, 229, 231)",
|
|
686
|
+
},
|
|
687
|
+
dark: true,
|
|
688
|
+
fonts: mockNavigationFonts,
|
|
689
|
+
},
|
|
690
|
+
DefaultTheme: {
|
|
691
|
+
colors: {
|
|
692
|
+
background: "rgb(242, 242, 242)",
|
|
693
|
+
border: "rgb(216, 216, 216)",
|
|
694
|
+
card: "rgb(255, 255, 255)",
|
|
695
|
+
notification: "rgb(255, 59, 48)",
|
|
696
|
+
primary: "rgb(0, 122, 255)",
|
|
697
|
+
text: "rgb(28, 28, 30)",
|
|
698
|
+
},
|
|
699
|
+
dark: false,
|
|
700
|
+
fonts: mockNavigationFonts,
|
|
701
|
+
},
|
|
672
702
|
Link: ({children, ...props}: MockComponentProps) => React.createElement("Link", props, children),
|
|
673
703
|
Navigator: ({children, ...props}: MockComponentProps) =>
|
|
674
704
|
React.createElement("Navigator", props, children),
|
|
@@ -684,6 +714,7 @@ mock.module("expo-router", () => ({
|
|
|
684
714
|
Stack: ({children, ...props}: MockComponentProps) =>
|
|
685
715
|
React.createElement("Stack", props, children),
|
|
686
716
|
Tabs: ({children, ...props}: MockComponentProps) => React.createElement("Tabs", props, children),
|
|
717
|
+
ThemeProvider: ({children}: MockComponentProps) => children,
|
|
687
718
|
useFocusEffect: mock(() => undefined),
|
|
688
719
|
useGlobalSearchParams: mock(() => ({})),
|
|
689
720
|
useLocalSearchParams: mock(() => ({})),
|
package/src/index.tsx
CHANGED
|
@@ -191,6 +191,7 @@ export * from "./useConsentForms";
|
|
|
191
191
|
export * from "./useStoredState";
|
|
192
192
|
export * from "./useSubmitConsent";
|
|
193
193
|
export * from "./WebAddressAutocomplete";
|
|
194
|
+
export * from "./WhatsNewBanner";
|
|
194
195
|
|
|
195
196
|
// export * from "./Layout";
|
|
196
197
|
// export * from "./Drawer";
|