@terreno/ui 57.16.1 → 57.17.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/Button.d.ts.map +1 -1
- package/dist/Button.js +2 -7
- package/dist/Button.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/Button.test.tsx +13 -2
- package/src/Button.tsx +2 -9
- package/src/DataTable.tsx +11 -7
- package/src/GPTChat.test.tsx +18 -0
- package/src/GPTChat.tsx +71 -54
- package/src/WhatsNewBanner.test.tsx +186 -0
- package/src/WhatsNewBanner.tsx +191 -0
- package/src/__snapshots__/Button.test.tsx.snap +14 -14
- package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +2 -2
- package/src/__snapshots__/DropdownPanel.test.tsx.snap +2 -2
- package/src/__snapshots__/ErrorPage.test.tsx.snap +1 -1
- package/src/__snapshots__/HeightActionSheet.test.tsx.snap +2 -2
- package/src/__snapshots__/HeightField.test.tsx.snap +5 -5
- package/src/__snapshots__/InfoModalIcon.test.tsx.snap +1 -1
- package/src/__snapshots__/Modal.test.tsx.snap +2 -2
- package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +2 -2
- package/src/bunSetup.ts +31 -0
- package/src/index.tsx +1 -0
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +2 -2
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +2 -2
package/src/GPTChat.test.tsx
CHANGED
|
@@ -124,6 +124,24 @@ describe("GPTChat", () => {
|
|
|
124
124
|
assert.isOk(getByText("New Chat"));
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
+
it("shows the history sidebar by default", () => {
|
|
128
|
+
const {getByTestId} = renderChat();
|
|
129
|
+
|
|
130
|
+
assert.isOk(getByTestId("gpt-history-sidebar"));
|
|
131
|
+
assert.isOk(getByTestId("gpt-new-chat-button"));
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("leaves out the history sidebar when showHistory is false", () => {
|
|
135
|
+
const {getByTestId, queryByTestId, queryByText} = renderChat({showHistory: false});
|
|
136
|
+
|
|
137
|
+
assert.isNull(queryByTestId("gpt-history-sidebar"));
|
|
138
|
+
assert.isNull(queryByTestId("gpt-new-chat-button"));
|
|
139
|
+
assert.isNull(queryByText("Chats"));
|
|
140
|
+
assert.isNull(queryByText("First chat"));
|
|
141
|
+
assert.isOk(getByTestId("gpt-messages"));
|
|
142
|
+
assert.isOk(getByTestId("gpt-chat"));
|
|
143
|
+
});
|
|
144
|
+
|
|
127
145
|
it("selects, creates, and deletes histories", async () => {
|
|
128
146
|
const onSelectHistory = mock((_id: string) => {});
|
|
129
147
|
const onCreateHistory = mock(() => {});
|
package/src/GPTChat.tsx
CHANGED
|
@@ -182,6 +182,12 @@ export interface GPTChatProps {
|
|
|
182
182
|
/** Turns a `file:` image id into a URL while `uiBlocks` is on. */
|
|
183
183
|
resolveImage?: BlocksViewProps["resolveImage"];
|
|
184
184
|
selectedModel?: string;
|
|
185
|
+
/**
|
|
186
|
+
* Renders the history sidebar (model selector, toolbar, new chat, and the history list).
|
|
187
|
+
* Defaults to true. Pass false on narrow layouts so the chat panel takes the full width; the
|
|
188
|
+
* host then owns history navigation and those sidebar controls.
|
|
189
|
+
*/
|
|
190
|
+
showHistory?: boolean;
|
|
185
191
|
/**
|
|
186
192
|
* Optional consumer-owned character for an empty chat. Terreno does not ship a
|
|
187
193
|
* default mascot — pass an image, icon, Lottie view, or any React node. Hidden
|
|
@@ -1429,6 +1435,7 @@ export const GPTChat = ({
|
|
|
1429
1435
|
resolveDataset,
|
|
1430
1436
|
resolveImage,
|
|
1431
1437
|
selectedModel,
|
|
1438
|
+
showHistory = true,
|
|
1432
1439
|
mascot,
|
|
1433
1440
|
suggestedPrompts,
|
|
1434
1441
|
systemMemory,
|
|
@@ -1693,68 +1700,78 @@ export const GPTChat = ({
|
|
|
1693
1700
|
return (
|
|
1694
1701
|
<Box direction="row" flex="grow" testID={testID}>
|
|
1695
1702
|
{/* Sidebar */}
|
|
1696
|
-
|
|
1697
|
-
<
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1703
|
+
{showHistory && (
|
|
1704
|
+
<Box
|
|
1705
|
+
border="default"
|
|
1706
|
+
color="base"
|
|
1707
|
+
minWidth={250}
|
|
1708
|
+
overflow="scrollY"
|
|
1709
|
+
padding={3}
|
|
1710
|
+
testID="gpt-history-sidebar"
|
|
1711
|
+
width="30%"
|
|
1712
|
+
>
|
|
1713
|
+
<SidebarModelSelector
|
|
1714
|
+
availableModels={availableModels}
|
|
1715
|
+
onModelChange={onModelChange}
|
|
1716
|
+
selectedModel={selectedModel}
|
|
1717
|
+
/>
|
|
1702
1718
|
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
+
<Box alignItems="center" direction="row" justifyContent="between" marginBottom={3}>
|
|
1720
|
+
<Heading size="sm">Chats</Heading>
|
|
1721
|
+
<Box direction="row" gap={1}>
|
|
1722
|
+
<SidebarToolbarButtons
|
|
1723
|
+
handleOpenApiKeyModal={handleOpenApiKeyModal}
|
|
1724
|
+
mcpServers={mcpServers}
|
|
1725
|
+
onGeminiApiKeyChange={onGeminiApiKeyChange}
|
|
1726
|
+
onMemoryEdit={onMemoryEdit}
|
|
1727
|
+
systemMemory={systemMemory}
|
|
1728
|
+
/>
|
|
1729
|
+
<IconButton
|
|
1730
|
+
accessibilityLabel="New chat"
|
|
1731
|
+
iconName="plus"
|
|
1732
|
+
onClick={onCreateHistory}
|
|
1733
|
+
testID="gpt-new-chat-button"
|
|
1734
|
+
/>
|
|
1735
|
+
</Box>
|
|
1719
1736
|
</Box>
|
|
1720
|
-
</Box>
|
|
1721
1737
|
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
editingHistoryId={editingHistoryId}
|
|
1739
|
-
editingTitle={editingTitle}
|
|
1740
|
-
handleFinishRename={handleFinishRename}
|
|
1741
|
-
history={history}
|
|
1742
|
-
setEditingTitle={setEditingTitle}
|
|
1743
|
-
/>
|
|
1744
|
-
<Box marginLeft={1}>
|
|
1745
|
-
<HistoryItemActions
|
|
1738
|
+
{histories.map((history) => (
|
|
1739
|
+
<Box
|
|
1740
|
+
accessibilityHint="Opens this chat history"
|
|
1741
|
+
accessibilityLabel={`Select chat: ${history.title ?? "New Chat"}`}
|
|
1742
|
+
alignItems="center"
|
|
1743
|
+
color={history.id === currentHistoryId ? "primary" : undefined}
|
|
1744
|
+
direction="row"
|
|
1745
|
+
justifyContent="between"
|
|
1746
|
+
key={history.id}
|
|
1747
|
+
marginBottom={1}
|
|
1748
|
+
onClick={() => onSelectHistory(history.id)}
|
|
1749
|
+
padding={2}
|
|
1750
|
+
rounding="md"
|
|
1751
|
+
>
|
|
1752
|
+
<HistoryItemTitle
|
|
1753
|
+
currentHistoryId={currentHistoryId}
|
|
1746
1754
|
editingHistoryId={editingHistoryId}
|
|
1755
|
+
editingTitle={editingTitle}
|
|
1747
1756
|
handleFinishRename={handleFinishRename}
|
|
1748
|
-
handleStartRename={handleStartRename}
|
|
1749
1757
|
history={history}
|
|
1750
|
-
|
|
1751
|
-
onDeleteHistory={onDeleteHistory}
|
|
1752
|
-
onUpdateTitle={onUpdateTitle}
|
|
1758
|
+
setEditingTitle={setEditingTitle}
|
|
1753
1759
|
/>
|
|
1760
|
+
<Box marginLeft={1}>
|
|
1761
|
+
<HistoryItemActions
|
|
1762
|
+
editingHistoryId={editingHistoryId}
|
|
1763
|
+
handleFinishRename={handleFinishRename}
|
|
1764
|
+
handleStartRename={handleStartRename}
|
|
1765
|
+
history={history}
|
|
1766
|
+
isSelected={history.id === currentHistoryId}
|
|
1767
|
+
onDeleteHistory={onDeleteHistory}
|
|
1768
|
+
onUpdateTitle={onUpdateTitle}
|
|
1769
|
+
/>
|
|
1770
|
+
</Box>
|
|
1754
1771
|
</Box>
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1772
|
+
))}
|
|
1773
|
+
</Box>
|
|
1774
|
+
)}
|
|
1758
1775
|
|
|
1759
1776
|
{/* Chat Panel */}
|
|
1760
1777
|
<Box direction="column" flex="grow" padding={4}>
|
|
@@ -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
|
+
};
|
|
@@ -17,7 +17,7 @@ exports[`Button renders correctly with default props 1`] = `
|
|
|
17
17
|
],
|
|
18
18
|
"props": {
|
|
19
19
|
"style": {
|
|
20
|
-
"color": "#
|
|
20
|
+
"color": "#FFFFFF",
|
|
21
21
|
"fontSize": 16,
|
|
22
22
|
"fontWeight": "700",
|
|
23
23
|
},
|
|
@@ -89,7 +89,7 @@ exports[`Button renders primary variant 1`] = `
|
|
|
89
89
|
],
|
|
90
90
|
"props": {
|
|
91
91
|
"style": {
|
|
92
|
-
"color": "#
|
|
92
|
+
"color": "#FFFFFF",
|
|
93
93
|
"fontSize": 16,
|
|
94
94
|
"fontWeight": "700",
|
|
95
95
|
},
|
|
@@ -449,7 +449,7 @@ exports[`Button renders disabled state 1`] = `
|
|
|
449
449
|
],
|
|
450
450
|
"props": {
|
|
451
451
|
"style": {
|
|
452
|
-
"color": "#
|
|
452
|
+
"color": "#FFFFFF",
|
|
453
453
|
"fontSize": 16,
|
|
454
454
|
"fontWeight": "700",
|
|
455
455
|
},
|
|
@@ -521,7 +521,7 @@ exports[`Button applies disabled styles when disabled 1`] = `
|
|
|
521
521
|
],
|
|
522
522
|
"props": {
|
|
523
523
|
"style": {
|
|
524
|
-
"color": "#
|
|
524
|
+
"color": "#FFFFFF",
|
|
525
525
|
"fontSize": 16,
|
|
526
526
|
"fontWeight": "700",
|
|
527
527
|
},
|
|
@@ -593,7 +593,7 @@ exports[`Button renders loading state 1`] = `
|
|
|
593
593
|
],
|
|
594
594
|
"props": {
|
|
595
595
|
"style": {
|
|
596
|
-
"color": "#
|
|
596
|
+
"color": "#FFFFFF",
|
|
597
597
|
"fontSize": 16,
|
|
598
598
|
"fontWeight": "700",
|
|
599
599
|
},
|
|
@@ -616,7 +616,7 @@ exports[`Button renders loading state 1`] = `
|
|
|
616
616
|
"$$typeof": Symbol(react.test.json),
|
|
617
617
|
"children": null,
|
|
618
618
|
"props": {
|
|
619
|
-
"color": "#
|
|
619
|
+
"color": "#FFFFFF",
|
|
620
620
|
"size": "small",
|
|
621
621
|
},
|
|
622
622
|
"type": "ActivityIndicator",
|
|
@@ -688,7 +688,7 @@ exports[`Button renders fullWidth button 1`] = `
|
|
|
688
688
|
],
|
|
689
689
|
"props": {
|
|
690
690
|
"style": {
|
|
691
|
-
"color": "#
|
|
691
|
+
"color": "#FFFFFF",
|
|
692
692
|
"fontSize": 16,
|
|
693
693
|
"fontWeight": "700",
|
|
694
694
|
},
|
|
@@ -773,7 +773,7 @@ exports[`Button renders with icon on left 1`] = `
|
|
|
773
773
|
],
|
|
774
774
|
"props": {
|
|
775
775
|
"style": {
|
|
776
|
-
"color": "#
|
|
776
|
+
"color": "#FFFFFF",
|
|
777
777
|
"fontSize": 16,
|
|
778
778
|
"fontWeight": "700",
|
|
779
779
|
},
|
|
@@ -858,7 +858,7 @@ exports[`Button renders with icon on right 1`] = `
|
|
|
858
858
|
],
|
|
859
859
|
"props": {
|
|
860
860
|
"style": {
|
|
861
|
-
"color": "#
|
|
861
|
+
"color": "#FFFFFF",
|
|
862
862
|
"fontSize": 16,
|
|
863
863
|
"fontWeight": "700",
|
|
864
864
|
},
|
|
@@ -930,7 +930,7 @@ exports[`Button renders with confirmation modal props 1`] = `
|
|
|
930
930
|
],
|
|
931
931
|
"props": {
|
|
932
932
|
"style": {
|
|
933
|
-
"color": "#
|
|
933
|
+
"color": "#FFFFFF",
|
|
934
934
|
"fontSize": 16,
|
|
935
935
|
"fontWeight": "700",
|
|
936
936
|
},
|
|
@@ -1002,7 +1002,7 @@ exports[`Button renders with tooltip on desktop (wrapped in Tooltip) 1`] = `
|
|
|
1002
1002
|
],
|
|
1003
1003
|
"props": {
|
|
1004
1004
|
"style": {
|
|
1005
|
-
"color": "#
|
|
1005
|
+
"color": "#FFFFFF",
|
|
1006
1006
|
"fontSize": 16,
|
|
1007
1007
|
"fontWeight": "700",
|
|
1008
1008
|
},
|
|
@@ -1074,7 +1074,7 @@ exports[`Button renders with custom confirmationText and modalSubTitle 1`] = `
|
|
|
1074
1074
|
],
|
|
1075
1075
|
"props": {
|
|
1076
1076
|
"style": {
|
|
1077
|
-
"color": "#
|
|
1077
|
+
"color": "#FFFFFF",
|
|
1078
1078
|
"fontSize": 16,
|
|
1079
1079
|
"fontWeight": "700",
|
|
1080
1080
|
},
|
|
@@ -1146,7 +1146,7 @@ exports[`Button shows loading indicator when loading prop is true 1`] = `
|
|
|
1146
1146
|
],
|
|
1147
1147
|
"props": {
|
|
1148
1148
|
"style": {
|
|
1149
|
-
"color": "#
|
|
1149
|
+
"color": "#FFFFFF",
|
|
1150
1150
|
"fontSize": 16,
|
|
1151
1151
|
"fontWeight": "700",
|
|
1152
1152
|
},
|
|
@@ -1169,7 +1169,7 @@ exports[`Button shows loading indicator when loading prop is true 1`] = `
|
|
|
1169
1169
|
"$$typeof": Symbol(react.test.json),
|
|
1170
1170
|
"children": null,
|
|
1171
1171
|
"props": {
|
|
1172
|
-
"color": "#
|
|
1172
|
+
"color": "#FFFFFF",
|
|
1173
1173
|
"size": "small",
|
|
1174
1174
|
},
|
|
1175
1175
|
"type": "ActivityIndicator",
|