@terreno/ui 0.31.0 → 56.0.0-beta.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/LICENSE +203 -21
- package/dist/ActionSheet.d.ts +1 -1
- package/dist/Avatar.js +1 -4
- package/dist/Avatar.js.map +1 -1
- package/dist/Box.js +45 -9
- package/dist/Box.js.map +1 -1
- package/dist/Common.d.ts +21 -39
- package/dist/Common.js.map +1 -1
- package/dist/ConflictSheet.d.ts +53 -0
- package/dist/ConflictSheet.js +132 -0
- package/dist/ConflictSheet.js.map +1 -0
- package/dist/DateTimeActionSheet.d.ts +2 -1
- package/dist/DecimalRangeActionSheet.d.ts +1 -1
- package/dist/EmojiSelector.d.ts +1 -1
- package/dist/ErrorPage.d.ts +1 -1
- package/dist/HeightActionSheet.d.ts +1 -1
- package/dist/Hyperlink.d.ts +2 -1
- package/dist/Hyperlink.js +2 -1
- package/dist/Hyperlink.js.map +1 -1
- package/dist/Image.d.ts +1 -1
- package/dist/ImageBackground.d.ts +1 -1
- package/dist/MobileAddressAutoComplete.d.ts +1 -1
- package/dist/NumberPickerActionSheet.d.ts +1 -1
- package/dist/Page.d.ts +3 -3
- package/dist/PickerSelect.d.ts +1 -1
- package/dist/SidebarNavigation.js +1 -1
- package/dist/SidebarNavigation.js.map +1 -1
- package/dist/SidebarNavigation.native.js +1 -1
- package/dist/SidebarNavigation.native.js.map +1 -1
- package/dist/SplitPage.d.ts +1 -1
- package/dist/SplitPage.js +1 -4
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts +1 -1
- package/dist/SyncStatusBanner.d.ts +46 -0
- package/dist/SyncStatusBanner.js +29 -0
- package/dist/SyncStatusBanner.js.map +1 -0
- package/dist/Theme.d.ts +1 -1
- package/dist/Theme.js +0 -1
- package/dist/Theme.js.map +1 -1
- package/dist/Toast.d.ts +9 -1
- package/dist/Toast.js +20 -7
- package/dist/Toast.js.map +1 -1
- package/dist/ToastNotifications.js +23 -1
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/UnifiedAddressAutoComplete.d.ts +1 -1
- package/dist/Unifier.js +1 -1
- package/dist/Unifier.js.map +1 -1
- package/dist/conflictFieldDiff.d.ts +14 -0
- package/dist/conflictFieldDiff.js +62 -0
- package/dist/conflictFieldDiff.js.map +1 -0
- package/dist/icons/OfflineIcon.d.ts +1 -1
- package/dist/icons/OnlineIcon.d.ts +1 -1
- package/dist/icons/OutOfficeIcon.d.ts +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/pdfHtmlTemplate.d.ts +30 -0
- package/dist/pdfHtmlTemplate.js +170 -0
- package/dist/pdfHtmlTemplate.js.map +1 -0
- package/dist/table/TableTitle.js +1 -3
- package/dist/table/TableTitle.js.map +1 -1
- package/dist/useAppLaunchOrForeground.d.ts +9 -0
- package/dist/useAppLaunchOrForeground.js +27 -0
- package/dist/useAppLaunchOrForeground.js.map +1 -0
- package/package.json +45 -39
- package/src/ActionSheet.test.tsx +37 -80
- package/src/Box.test.tsx +39 -9
- package/src/Box.tsx +46 -7
- package/src/Common.ts +21 -50
- package/src/ConflictSheet.test.tsx +461 -0
- package/src/ConflictSheet.tsx +399 -0
- package/src/ConsentNavigator.test.tsx +8 -6
- package/src/DateTimeField.test.tsx +0 -36
- package/src/Hyperlink.tsx +1 -1
- package/src/PickerSelect.test.tsx +12 -23
- package/src/SidebarNavigation.native.tsx +1 -1
- package/src/SidebarNavigation.tsx +1 -1
- package/src/SyncStatusBanner.test.tsx +204 -0
- package/src/SyncStatusBanner.tsx +148 -0
- package/src/TerrenoProvider.test.tsx +3 -4
- package/src/Theme.tsx +0 -1
- package/src/Toast.test.tsx +60 -0
- package/src/Toast.tsx +46 -1
- package/src/ToastNotifications.test.tsx +82 -0
- package/src/ToastNotifications.tsx +25 -1
- package/src/Unifier.ts +1 -1
- package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +0 -3
- package/src/__snapshots__/Body.test.tsx.snap +0 -16
- package/src/__snapshots__/Box.test.tsx.snap +4 -13
- package/src/__snapshots__/Card.test.tsx.snap +0 -1
- package/src/__snapshots__/Page.test.tsx.snap +0 -84
- package/src/__snapshots__/SplitPage.test.tsx.snap +24 -120
- package/src/__snapshots__/TapToEdit.test.tsx.snap +5 -16
- package/src/__snapshots__/Toast.test.tsx.snap +4 -2
- package/src/bunSetup.ts +21 -6
- package/src/conflictFieldDiff.test.ts +26 -0
- package/src/conflictFieldDiff.ts +78 -0
- package/src/index.tsx +5 -3
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +0 -9
- package/src/pdfHtmlTemplate.ts +219 -0
- package/src/signUp/__snapshots__/OAuthButtons.test.tsx.snap +0 -1
- package/src/signUp/__snapshots__/PasswordRequirements.test.tsx.snap +2 -16
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +1 -17
- package/src/signUp/__snapshots__/Swiper.test.tsx.snap +0 -1
- package/src/table/__snapshots__/Table.test.tsx.snap +22 -87
- package/src/table/__snapshots__/TableHeader.test.tsx.snap +10 -50
- package/src/table/__snapshots__/TableHeaderCell.test.tsx.snap +10 -84
- package/src/table/__snapshots__/TableRow.test.tsx.snap +12 -77
- package/src/useAppLaunchOrForeground.test.tsx +54 -0
- package/src/useAppLaunchOrForeground.ts +30 -0
- package/dist/ConsentHistory.d.ts +0 -9
- package/dist/ConsentHistory.js +0 -70
- package/dist/ConsentHistory.js.map +0 -1
- package/dist/EditableCard.d.ts +0 -3
- package/dist/EditableCard.js +0 -23
- package/dist/EditableCard.js.map +0 -1
- package/dist/generateConsentHistoryPdf.d.ts +0 -2
- package/dist/generateConsentHistoryPdf.js +0 -185
- package/dist/generateConsentHistoryPdf.js.map +0 -1
- package/dist/useConsentHistory.d.ts +0 -63
- package/dist/useConsentHistory.js +0 -40
- package/dist/useConsentHistory.js.map +0 -1
- package/src/ConsentHistory.test.tsx +0 -224
- package/src/ConsentHistory.tsx +0 -249
- package/src/DraggableList.test.tsx +0 -377
- package/src/EditableCard.test.tsx +0 -69
- package/src/EditableCard.tsx +0 -73
- package/src/SidebarNavigation.test.tsx +0 -339
- package/src/__snapshots__/EditableCard.test.tsx.snap +0 -242
- package/src/generateConsentHistoryPdf.test.ts +0 -253
- package/src/generateConsentHistoryPdf.ts +0 -211
- package/src/useConsentHistory.test.ts +0 -106
- package/src/useConsentHistory.ts +0 -94
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import {DateTime} from "luxon";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import {useCallback, useEffect, useRef, useState} from "react";
|
|
4
|
+
import {ScrollView, useWindowDimensions} from "react-native";
|
|
5
|
+
|
|
6
|
+
import {Badge} from "./Badge";
|
|
7
|
+
import {Box} from "./Box";
|
|
8
|
+
import {Button} from "./Button";
|
|
9
|
+
import {
|
|
10
|
+
formatConflictFieldLabel,
|
|
11
|
+
formatConflictFieldValue,
|
|
12
|
+
getChangedConflictFields,
|
|
13
|
+
NO_CONFLICT_DIFF_FIELDS,
|
|
14
|
+
parseConflictPayload,
|
|
15
|
+
summarizeConflictSide,
|
|
16
|
+
} from "./conflictFieldDiff";
|
|
17
|
+
import {Modal} from "./Modal";
|
|
18
|
+
import {Text} from "./Text";
|
|
19
|
+
|
|
20
|
+
/** Resolution strategy for a sync conflict. */
|
|
21
|
+
export type SyncConflictResolutionStrategy = "useServer" | "keepMine";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Minimal shape of a sync conflict rendered by {@link ConflictSheet}. Mirrors the fields exposed by
|
|
25
|
+
* @terreno/syncdb's `SyncConflict` (local/server payloads are JSON strings) without importing the
|
|
26
|
+
* data layer, so the sheet stays a pure presentational component.
|
|
27
|
+
*/
|
|
28
|
+
export interface SyncConflictItem {
|
|
29
|
+
mutationId: string;
|
|
30
|
+
collection: string;
|
|
31
|
+
entityId: string;
|
|
32
|
+
/** Local (optimistic) payload as a JSON string. */
|
|
33
|
+
localData: string;
|
|
34
|
+
/** Server payload as a JSON string. */
|
|
35
|
+
serverData: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ConflictSheetProps {
|
|
39
|
+
visible: boolean;
|
|
40
|
+
onDismiss: () => void;
|
|
41
|
+
/** Unresolved conflicts to display. */
|
|
42
|
+
conflicts: SyncConflictItem[];
|
|
43
|
+
/** Called when the user picks a resolution for a conflict. */
|
|
44
|
+
onResolve: (args: {mutationId: string; strategy: SyncConflictResolutionStrategy}) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Modal title. Default avoids sync jargon so non-technical users understand
|
|
47
|
+
* they need to pick between two versions of the same item.
|
|
48
|
+
*/
|
|
49
|
+
title?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Plain-language explanation shown above the conflict list. Pass an empty
|
|
52
|
+
* string to hide it.
|
|
53
|
+
*/
|
|
54
|
+
description?: string;
|
|
55
|
+
testID?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const DEFAULT_TITLE = "These changes don't match";
|
|
59
|
+
|
|
60
|
+
const DEFAULT_DESCRIPTION =
|
|
61
|
+
"The same item was changed in two places at once — for example on this device and on another phone, computer, or by someone else. Choose which version to keep. The other one will be discarded.";
|
|
62
|
+
|
|
63
|
+
const LOCAL_COLUMN_TITLE = "Your change";
|
|
64
|
+
const REMOTE_COLUMN_TITLE = "Other version";
|
|
65
|
+
|
|
66
|
+
const KEEP_MINE_BUTTON = "Keep my change";
|
|
67
|
+
const USE_OTHER_BUTTON = "Use the other version";
|
|
68
|
+
const KEEP_MINE_ALL_BUTTON = "Keep all of my changes";
|
|
69
|
+
const USE_OTHER_ALL_BUTTON = "Use all other versions";
|
|
70
|
+
|
|
71
|
+
const KEEP_MINE_ALL_CONFIRM_TITLE = "Keep all of your changes?";
|
|
72
|
+
const KEEP_MINE_ALL_CONFIRM_TEXT =
|
|
73
|
+
"Your edits on this device will be kept and sent again. The other versions will be discarded.";
|
|
74
|
+
const USE_OTHER_ALL_CONFIRM_TITLE = "Use the other versions for everything?";
|
|
75
|
+
const USE_OTHER_ALL_CONFIRM_TEXT =
|
|
76
|
+
"Your edits on this device will be discarded. What's saved elsewhere will be kept instead.";
|
|
77
|
+
|
|
78
|
+
const EMPTY_STATE = "Nothing left to choose — you're all set.";
|
|
79
|
+
|
|
80
|
+
const TIME_UNAVAILABLE = "Time unavailable";
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Best-effort "when was this last touched" for a conflict side. Payload shapes
|
|
84
|
+
* vary by collection, so try the usual timestamp fields in order of specificity.
|
|
85
|
+
*/
|
|
86
|
+
const parseConflictTime = (data: Record<string, unknown>): DateTime | null => {
|
|
87
|
+
const value = data.updated ?? data.updatedAt ?? data.created ?? data.createdAt;
|
|
88
|
+
if (typeof value !== "string") {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const dateTime = DateTime.fromISO(value);
|
|
92
|
+
return dateTime.isValid ? dateTime : null;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const formatConflictTime = (dateTime: DateTime | null): string =>
|
|
96
|
+
dateTime ? dateTime.toLocaleString(DateTime.DATETIME_MED_WITH_SECONDS) : TIME_UNAVAILABLE;
|
|
97
|
+
|
|
98
|
+
/** Badge label for each side, or null where there is nothing meaningful to say. */
|
|
99
|
+
type RecencyLabel = "Newer" | "Same time" | null;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Which side is more recent, so the user can tell at a glance which version they
|
|
103
|
+
* would be discarding. Both sides need a usable timestamp for a comparison to
|
|
104
|
+
* mean anything; without that we stay silent rather than guess.
|
|
105
|
+
*/
|
|
106
|
+
const compareRecency = ({
|
|
107
|
+
local,
|
|
108
|
+
server,
|
|
109
|
+
}: {
|
|
110
|
+
local: DateTime | null;
|
|
111
|
+
server: DateTime | null;
|
|
112
|
+
}): {local: RecencyLabel; server: RecencyLabel} => {
|
|
113
|
+
if (!local || !server) {
|
|
114
|
+
return {local: null, server: null};
|
|
115
|
+
}
|
|
116
|
+
const localMillis = local.toMillis();
|
|
117
|
+
const serverMillis = server.toMillis();
|
|
118
|
+
if (localMillis === serverMillis) {
|
|
119
|
+
return {local: "Same time", server: "Same time"};
|
|
120
|
+
}
|
|
121
|
+
if (localMillis > serverMillis) {
|
|
122
|
+
return {local: "Newer", server: null};
|
|
123
|
+
}
|
|
124
|
+
return {local: null, server: "Newer"};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const RecencyBadge: React.FC<{label: RecencyLabel; testID: string}> = ({label, testID}) => {
|
|
128
|
+
if (!label) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
return (
|
|
132
|
+
<Badge
|
|
133
|
+
secondary
|
|
134
|
+
status={label === "Newer" ? "info" : "neutral"}
|
|
135
|
+
testID={testID}
|
|
136
|
+
value={label}
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
interface VersionColumnProps {
|
|
142
|
+
action: React.ReactNode;
|
|
143
|
+
changedFields: string[];
|
|
144
|
+
data: Record<string, unknown>;
|
|
145
|
+
entityId: string;
|
|
146
|
+
recency: RecencyLabel;
|
|
147
|
+
showDiff: boolean;
|
|
148
|
+
side: "local" | "server";
|
|
149
|
+
time: DateTime | null;
|
|
150
|
+
title: string;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const VersionColumn: React.FC<VersionColumnProps> = ({
|
|
154
|
+
action,
|
|
155
|
+
changedFields,
|
|
156
|
+
data,
|
|
157
|
+
entityId,
|
|
158
|
+
recency,
|
|
159
|
+
showDiff,
|
|
160
|
+
side,
|
|
161
|
+
time,
|
|
162
|
+
title,
|
|
163
|
+
}) => (
|
|
164
|
+
<Box
|
|
165
|
+
flex="grow"
|
|
166
|
+
gap={3}
|
|
167
|
+
justifyContent="between"
|
|
168
|
+
minWidth={240}
|
|
169
|
+
testID={`conflict-${side}-column-${entityId}`}
|
|
170
|
+
width={240}
|
|
171
|
+
>
|
|
172
|
+
<Box gap={2}>
|
|
173
|
+
<Box alignItems="center" direction="row" gap={1}>
|
|
174
|
+
<Text bold color="secondaryDark" size="sm">
|
|
175
|
+
{title}
|
|
176
|
+
</Text>
|
|
177
|
+
<RecencyBadge label={recency} testID={`conflict-${side}-recency-${entityId}`} />
|
|
178
|
+
</Box>
|
|
179
|
+
<Text color="secondaryLight" size="sm" testID={`conflict-${side}-time-${entityId}`}>
|
|
180
|
+
{formatConflictTime(time)}
|
|
181
|
+
</Text>
|
|
182
|
+
{showDiff ? (
|
|
183
|
+
changedFields.length === 0 ? (
|
|
184
|
+
<Text color="secondaryLight" size="sm">
|
|
185
|
+
{NO_CONFLICT_DIFF_FIELDS}
|
|
186
|
+
</Text>
|
|
187
|
+
) : (
|
|
188
|
+
changedFields.map((field) => (
|
|
189
|
+
<Box gap={1} key={field} testID={`conflict-${side}-field-${field}-${entityId}`}>
|
|
190
|
+
<Text bold color="secondaryDark" size="sm">
|
|
191
|
+
{formatConflictFieldLabel(field)}
|
|
192
|
+
</Text>
|
|
193
|
+
<Text size="sm">{formatConflictFieldValue(data[field])}</Text>
|
|
194
|
+
</Box>
|
|
195
|
+
))
|
|
196
|
+
)
|
|
197
|
+
) : (
|
|
198
|
+
<Text size="sm">{summarizeConflictSide({changedFields, data})}</Text>
|
|
199
|
+
)}
|
|
200
|
+
</Box>
|
|
201
|
+
{action}
|
|
202
|
+
</Box>
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const ConflictItem: React.FC<{
|
|
206
|
+
conflict: SyncConflictItem;
|
|
207
|
+
onResolve: (args: {mutationId: string; strategy: SyncConflictResolutionStrategy}) => void;
|
|
208
|
+
}> = ({conflict, onResolve}) => {
|
|
209
|
+
const [showDiff, setShowDiff] = useState<boolean>(false);
|
|
210
|
+
const local = parseConflictPayload(conflict.localData);
|
|
211
|
+
const server = parseConflictPayload(conflict.serverData);
|
|
212
|
+
const localTime = parseConflictTime(local);
|
|
213
|
+
const serverTime = parseConflictTime(server);
|
|
214
|
+
const recency = compareRecency({local: localTime, server: serverTime});
|
|
215
|
+
const changedFields = getChangedConflictFields({local, server});
|
|
216
|
+
|
|
217
|
+
const handleToggleDiff = useCallback((): void => {
|
|
218
|
+
setShowDiff((prev) => !prev);
|
|
219
|
+
}, []);
|
|
220
|
+
|
|
221
|
+
const handleKeepMine = useCallback((): void => {
|
|
222
|
+
onResolve({mutationId: conflict.mutationId, strategy: "keepMine"});
|
|
223
|
+
}, [conflict.mutationId, onResolve]);
|
|
224
|
+
|
|
225
|
+
const handleUseServer = useCallback((): void => {
|
|
226
|
+
onResolve({mutationId: conflict.mutationId, strategy: "useServer"});
|
|
227
|
+
}, [conflict.mutationId, onResolve]);
|
|
228
|
+
|
|
229
|
+
return (
|
|
230
|
+
<Box
|
|
231
|
+
border="default"
|
|
232
|
+
gap={3}
|
|
233
|
+
padding={3}
|
|
234
|
+
rounding="md"
|
|
235
|
+
testID={`conflict-item-${conflict.entityId}`}
|
|
236
|
+
>
|
|
237
|
+
<Box direction="row" gap={2} justifyContent="between" wrap>
|
|
238
|
+
<Box flex="grow">
|
|
239
|
+
<Text bold size="sm">
|
|
240
|
+
{conflict.collection} · {conflict.entityId}
|
|
241
|
+
</Text>
|
|
242
|
+
</Box>
|
|
243
|
+
<Button
|
|
244
|
+
onClick={handleToggleDiff}
|
|
245
|
+
size="sm"
|
|
246
|
+
testID={`conflict-diff-toggle-${conflict.entityId}`}
|
|
247
|
+
text={showDiff ? "Hide diff" : "Diff"}
|
|
248
|
+
variant="outline"
|
|
249
|
+
/>
|
|
250
|
+
</Box>
|
|
251
|
+
<Box direction="row" gap={3} wrap>
|
|
252
|
+
<VersionColumn
|
|
253
|
+
action={
|
|
254
|
+
<Button
|
|
255
|
+
fullWidth
|
|
256
|
+
onClick={handleKeepMine}
|
|
257
|
+
testID={`conflict-keep-mine-button-${conflict.mutationId}`}
|
|
258
|
+
text={KEEP_MINE_BUTTON}
|
|
259
|
+
variant="outline"
|
|
260
|
+
/>
|
|
261
|
+
}
|
|
262
|
+
changedFields={changedFields}
|
|
263
|
+
data={local}
|
|
264
|
+
entityId={conflict.entityId}
|
|
265
|
+
recency={recency.local}
|
|
266
|
+
showDiff={showDiff}
|
|
267
|
+
side="local"
|
|
268
|
+
time={localTime}
|
|
269
|
+
title={LOCAL_COLUMN_TITLE}
|
|
270
|
+
/>
|
|
271
|
+
<VersionColumn
|
|
272
|
+
action={
|
|
273
|
+
<Button
|
|
274
|
+
fullWidth
|
|
275
|
+
onClick={handleUseServer}
|
|
276
|
+
testID={`conflict-use-server-button-${conflict.mutationId}`}
|
|
277
|
+
text={USE_OTHER_BUTTON}
|
|
278
|
+
variant="primary"
|
|
279
|
+
/>
|
|
280
|
+
}
|
|
281
|
+
changedFields={changedFields}
|
|
282
|
+
data={server}
|
|
283
|
+
entityId={conflict.entityId}
|
|
284
|
+
recency={recency.server}
|
|
285
|
+
showDiff={showDiff}
|
|
286
|
+
side="server"
|
|
287
|
+
time={serverTime}
|
|
288
|
+
title={REMOTE_COLUMN_TITLE}
|
|
289
|
+
/>
|
|
290
|
+
</Box>
|
|
291
|
+
</Box>
|
|
292
|
+
);
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Presentational modal listing unresolved sync conflicts. Copy is written for
|
|
297
|
+
* non-technical users: "Your change" (this device) vs "Other version" (elsewhere
|
|
298
|
+
* or out of sync), with a short explanation of why they must pick one. Whichever
|
|
299
|
+
* side is more recent is badged. Users can resolve conflicts individually — each
|
|
300
|
+
* button lives inside the version column it keeps — or apply a choice to every
|
|
301
|
+
* conflict after confirmation. Data-layer agnostic: pass `conflicts` and an `onResolve`
|
|
302
|
+
* callback (e.g. from @terreno/syncdb's `useConflicts`).
|
|
303
|
+
*
|
|
304
|
+
* The sheet never closes itself on a button press. It calls `onDismiss` once `conflicts`
|
|
305
|
+
* becomes empty while open, so the caller's resolutions get to settle (or fail, keeping
|
|
306
|
+
* the sheet open) before the UI goes away.
|
|
307
|
+
*/
|
|
308
|
+
export const ConflictSheet: React.FC<ConflictSheetProps> = ({
|
|
309
|
+
visible,
|
|
310
|
+
onDismiss,
|
|
311
|
+
conflicts,
|
|
312
|
+
onResolve,
|
|
313
|
+
title = DEFAULT_TITLE,
|
|
314
|
+
description = DEFAULT_DESCRIPTION,
|
|
315
|
+
testID = "conflict-sheet",
|
|
316
|
+
}) => {
|
|
317
|
+
const {height: windowHeight} = useWindowDimensions();
|
|
318
|
+
// Whether this open episode ever had conflicts, so a sheet opened deliberately
|
|
319
|
+
// with none (to show the empty state) is not closed out from under the caller.
|
|
320
|
+
const hadConflictsRef = useRef<boolean>(false);
|
|
321
|
+
|
|
322
|
+
// Dismissal is driven purely by the conflict list emptying, never by a button
|
|
323
|
+
// press: `onResolve` resolutions settle asynchronously in the data layer, and the
|
|
324
|
+
// parent drops a row from `conflicts` only once its resolution actually landed.
|
|
325
|
+
// Closing at press time would hide a resolution that then failed, leaving the
|
|
326
|
+
// conflict unresolved with no visible way back to it.
|
|
327
|
+
useEffect(() => {
|
|
328
|
+
if (!visible) {
|
|
329
|
+
hadConflictsRef.current = false;
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (conflicts.length > 0) {
|
|
333
|
+
hadConflictsRef.current = true;
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (hadConflictsRef.current) {
|
|
337
|
+
onDismiss();
|
|
338
|
+
}
|
|
339
|
+
}, [conflicts.length, onDismiss, visible]);
|
|
340
|
+
|
|
341
|
+
const handleUseServerForAll = useCallback((): void => {
|
|
342
|
+
for (const conflict of conflicts) {
|
|
343
|
+
onResolve({mutationId: conflict.mutationId, strategy: "useServer"});
|
|
344
|
+
}
|
|
345
|
+
}, [conflicts, onResolve]);
|
|
346
|
+
|
|
347
|
+
const handleUseMineForAll = useCallback((): void => {
|
|
348
|
+
for (const conflict of conflicts) {
|
|
349
|
+
onResolve({mutationId: conflict.mutationId, strategy: "keepMine"});
|
|
350
|
+
}
|
|
351
|
+
}, [conflicts, onResolve]);
|
|
352
|
+
|
|
353
|
+
return (
|
|
354
|
+
<Modal onDismiss={onDismiss} size="md" title={title} visible={visible}>
|
|
355
|
+
<ScrollView
|
|
356
|
+
contentContainerStyle={{paddingBottom: 4}}
|
|
357
|
+
style={{maxHeight: Math.max(windowHeight * 0.65, 240), width: "100%"}}
|
|
358
|
+
testID="conflict-sheet-scroll"
|
|
359
|
+
>
|
|
360
|
+
<Box gap={3} testID={testID}>
|
|
361
|
+
{conflicts.length === 0 ? (
|
|
362
|
+
<Text color="secondaryLight">{EMPTY_STATE}</Text>
|
|
363
|
+
) : (
|
|
364
|
+
<>
|
|
365
|
+
{description ? (
|
|
366
|
+
<Text color="secondaryDark" size="sm" testID="conflict-sheet-description">
|
|
367
|
+
{description}
|
|
368
|
+
</Text>
|
|
369
|
+
) : null}
|
|
370
|
+
<Box direction="row" gap={2} wrap>
|
|
371
|
+
<Button
|
|
372
|
+
confirmationText={KEEP_MINE_ALL_CONFIRM_TEXT}
|
|
373
|
+
modalTitle={KEEP_MINE_ALL_CONFIRM_TITLE}
|
|
374
|
+
onClick={handleUseMineForAll}
|
|
375
|
+
testID="conflict-use-mine-all-button"
|
|
376
|
+
text={KEEP_MINE_ALL_BUTTON}
|
|
377
|
+
variant="outline"
|
|
378
|
+
withConfirmation
|
|
379
|
+
/>
|
|
380
|
+
<Button
|
|
381
|
+
confirmationText={USE_OTHER_ALL_CONFIRM_TEXT}
|
|
382
|
+
modalTitle={USE_OTHER_ALL_CONFIRM_TITLE}
|
|
383
|
+
onClick={handleUseServerForAll}
|
|
384
|
+
testID="conflict-use-server-all-button"
|
|
385
|
+
text={USE_OTHER_ALL_BUTTON}
|
|
386
|
+
variant="destructive"
|
|
387
|
+
withConfirmation
|
|
388
|
+
/>
|
|
389
|
+
</Box>
|
|
390
|
+
{conflicts.map((conflict) => (
|
|
391
|
+
<ConflictItem conflict={conflict} key={conflict.mutationId} onResolve={onResolve} />
|
|
392
|
+
))}
|
|
393
|
+
</>
|
|
394
|
+
)}
|
|
395
|
+
</Box>
|
|
396
|
+
</ScrollView>
|
|
397
|
+
</Modal>
|
|
398
|
+
);
|
|
399
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// noExplicitAny: test mock typing
|
|
2
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
1
3
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
4
|
import React from "react";
|
|
3
5
|
import {Pressable} from "react-native";
|
|
@@ -184,7 +186,7 @@ describe("ConsentNavigator", () => {
|
|
|
184
186
|
};
|
|
185
187
|
|
|
186
188
|
const {getByText} = renderWithTheme(
|
|
187
|
-
<ConsentNavigator api={api}>
|
|
189
|
+
<ConsentNavigator api={api as any}>
|
|
188
190
|
<Text>App Content</Text>
|
|
189
191
|
</ConsentNavigator>
|
|
190
192
|
);
|
|
@@ -210,7 +212,7 @@ describe("ConsentNavigator", () => {
|
|
|
210
212
|
};
|
|
211
213
|
|
|
212
214
|
const {getByText} = renderWithTheme(
|
|
213
|
-
<ConsentNavigator api={api}>
|
|
215
|
+
<ConsentNavigator api={api as any}>
|
|
214
216
|
<Text>App Content</Text>
|
|
215
217
|
</ConsentNavigator>
|
|
216
218
|
);
|
|
@@ -237,7 +239,7 @@ describe("ConsentNavigator", () => {
|
|
|
237
239
|
};
|
|
238
240
|
|
|
239
241
|
const {getByTestId, getByText} = renderWithTheme(
|
|
240
|
-
<ConsentNavigator api={api} onError={onError}>
|
|
242
|
+
<ConsentNavigator api={api as any} onError={onError}>
|
|
241
243
|
<Text>App Content</Text>
|
|
242
244
|
</ConsentNavigator>
|
|
243
245
|
);
|
|
@@ -282,7 +284,7 @@ describe("ConsentNavigator", () => {
|
|
|
282
284
|
};
|
|
283
285
|
|
|
284
286
|
const {getByTestId} = renderWithTheme(
|
|
285
|
-
<ConsentNavigator api={api}>
|
|
287
|
+
<ConsentNavigator api={api as any}>
|
|
286
288
|
<Text>App Content</Text>
|
|
287
289
|
</ConsentNavigator>
|
|
288
290
|
);
|
|
@@ -319,7 +321,7 @@ describe("ConsentNavigator", () => {
|
|
|
319
321
|
};
|
|
320
322
|
|
|
321
323
|
const {getByTestId} = renderWithTheme(
|
|
322
|
-
<ConsentNavigator api={api} onError={onError}>
|
|
324
|
+
<ConsentNavigator api={api as any} onError={onError}>
|
|
323
325
|
<Text>App Content</Text>
|
|
324
326
|
</ConsentNavigator>
|
|
325
327
|
);
|
|
@@ -359,7 +361,7 @@ describe("ConsentNavigator", () => {
|
|
|
359
361
|
};
|
|
360
362
|
|
|
361
363
|
const {getByTestId} = renderWithTheme(
|
|
362
|
-
<ConsentNavigator api={api}>
|
|
364
|
+
<ConsentNavigator api={api as any}>
|
|
363
365
|
<Text>App Content</Text>
|
|
364
366
|
</ConsentNavigator>
|
|
365
367
|
);
|
|
@@ -11,9 +11,7 @@ import {
|
|
|
11
11
|
mock,
|
|
12
12
|
} from "bun:test";
|
|
13
13
|
import {act, userEvent} from "@testing-library/react-native";
|
|
14
|
-
import {assert} from "chai";
|
|
15
14
|
import {DateTime} from "luxon";
|
|
16
|
-
import type {ReactTestInstance} from "react-test-renderer";
|
|
17
15
|
|
|
18
16
|
import {DateTimeField} from "./DateTimeField";
|
|
19
17
|
import {renderWithTheme, setupComponentTest, teardownComponentTest} from "./test-utils";
|
|
@@ -1312,40 +1310,6 @@ describe("DateTimeField", () => {
|
|
|
1312
1310
|
});
|
|
1313
1311
|
});
|
|
1314
1312
|
|
|
1315
|
-
describe("TimezonePicker onChange", () => {
|
|
1316
|
-
it("forwards the picked timezone to onTimezoneChange and emits a new value", async () => {
|
|
1317
|
-
setDesktop();
|
|
1318
|
-
const mockTzChange = mock(() => {});
|
|
1319
|
-
const {UNSAFE_root} = renderWithTheme(
|
|
1320
|
-
<DateTimeField
|
|
1321
|
-
onChange={mockOnChange}
|
|
1322
|
-
onTimezoneChange={mockTzChange}
|
|
1323
|
-
timezone="America/New_York"
|
|
1324
|
-
type="time"
|
|
1325
|
-
value="2023-05-15T15:30:00.000Z"
|
|
1326
|
-
/>
|
|
1327
|
-
);
|
|
1328
|
-
|
|
1329
|
-
// Select the rendered TimezonePicker itself rather than any ancestor that happens to
|
|
1330
|
-
// have an onTimezoneChange prop, so the component's own handler runs.
|
|
1331
|
-
const pickers = UNSAFE_root.findAll((node: ReactTestInstance) =>
|
|
1332
|
-
Boolean((node.props as {shortTimezone?: boolean}).shortTimezone)
|
|
1333
|
-
);
|
|
1334
|
-
assert.isAbove(pickers.length, 0);
|
|
1335
|
-
await act(async () => {
|
|
1336
|
-
pickers[0].props.onChange("America/Chicago");
|
|
1337
|
-
});
|
|
1338
|
-
|
|
1339
|
-
assert.isTrue(mockTzChange.mock.calls.some((call) => call[0] === "America/Chicago"));
|
|
1340
|
-
// The picked timezone is applied to the current segments and emitted.
|
|
1341
|
-
assert.isAbove(mockOnChange.mock.calls.length, 0);
|
|
1342
|
-
assert.equal(
|
|
1343
|
-
mockOnChange.mock.calls[mockOnChange.mock.calls.length - 1][0],
|
|
1344
|
-
"2023-05-15T16:30:00.000Z"
|
|
1345
|
-
);
|
|
1346
|
-
});
|
|
1347
|
-
});
|
|
1348
|
-
|
|
1349
1313
|
describe("minute validation in validateField", () => {
|
|
1350
1314
|
it("should validate minute field for datetime type via hour change triggering revalidation", async () => {
|
|
1351
1315
|
setDesktop();
|
package/src/Hyperlink.tsx
CHANGED
|
@@ -188,7 +188,7 @@ class HyperlinkComponent extends React.Component<HyperlinkProps> {
|
|
|
188
188
|
export const Hyperlink = (props: HyperlinkProps) => {
|
|
189
189
|
const handleLink = (url: string) => {
|
|
190
190
|
const urlObject = mdurl.parse(url);
|
|
191
|
-
urlObject.protocol = urlObject.protocol
|
|
191
|
+
urlObject.protocol = urlObject.protocol?.toLowerCase() ?? "";
|
|
192
192
|
const normalizedURL = mdurl.format(urlObject);
|
|
193
193
|
|
|
194
194
|
void Linking.canOpenURL(normalizedURL).then(
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// noExplicitAny: test mock typing
|
|
2
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
1
3
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
4
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
5
|
import type {ReactTestInstance} from "react-test-renderer";
|
|
@@ -5,17 +7,6 @@ import type {ReactTestInstance} from "react-test-renderer";
|
|
|
5
7
|
import {RNPickerSelect} from "./PickerSelect";
|
|
6
8
|
import {renderWithTheme} from "./test-utils";
|
|
7
9
|
|
|
8
|
-
/** Minimal element stub used to fake `document.activeElement` on web. */
|
|
9
|
-
interface MockElement {
|
|
10
|
-
blur: () => void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Globals the web rendering tests stub out. */
|
|
14
|
-
const globalScope = globalThis as unknown as {
|
|
15
|
-
document?: unknown;
|
|
16
|
-
HTMLElement?: new () => MockElement;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
10
|
// Note: @react-native-picker/picker is mocked globally in bunSetup.ts
|
|
20
11
|
|
|
21
12
|
describe("PickerSelect", () => {
|
|
@@ -175,24 +166,22 @@ describe("PickerSelect", () => {
|
|
|
175
166
|
|
|
176
167
|
describe("web rendering (Platform.OS === 'web')", () => {
|
|
177
168
|
const PlatformModule = require("react-native").Platform;
|
|
178
|
-
let savedOS:
|
|
169
|
+
let savedOS: any;
|
|
179
170
|
|
|
180
171
|
let hadDocument = false;
|
|
181
|
-
let savedDocument:
|
|
172
|
+
let savedDocument: any;
|
|
182
173
|
|
|
183
174
|
const searchEnabledWebProps = {...defaultProps, disableSearch: false};
|
|
184
175
|
|
|
185
176
|
const ensureDocument = () => {
|
|
186
177
|
hadDocument = "document" in globalThis;
|
|
187
|
-
savedDocument =
|
|
188
|
-
if (
|
|
189
|
-
|
|
190
|
-
blur = (): void => {};
|
|
191
|
-
};
|
|
178
|
+
savedDocument = (globalThis as any).document;
|
|
179
|
+
if (typeof (globalThis as any).HTMLElement === "undefined") {
|
|
180
|
+
(globalThis as any).HTMLElement = class HTMLElement {};
|
|
192
181
|
}
|
|
193
|
-
const el = new
|
|
182
|
+
const el = new (globalThis as any).HTMLElement();
|
|
194
183
|
el.blur = () => {};
|
|
195
|
-
|
|
184
|
+
(globalThis as any).document = {
|
|
196
185
|
activeElement: el,
|
|
197
186
|
addEventListener: () => {},
|
|
198
187
|
body: {
|
|
@@ -205,9 +194,9 @@ describe("PickerSelect", () => {
|
|
|
205
194
|
|
|
206
195
|
const restoreDocument = () => {
|
|
207
196
|
if (hadDocument) {
|
|
208
|
-
|
|
197
|
+
(globalThis as any).document = savedDocument;
|
|
209
198
|
} else {
|
|
210
|
-
delete
|
|
199
|
+
delete (globalThis as any).document;
|
|
211
200
|
}
|
|
212
201
|
};
|
|
213
202
|
|
|
@@ -528,7 +517,7 @@ describe("PickerSelect", () => {
|
|
|
528
517
|
|
|
529
518
|
describe("android rendering", () => {
|
|
530
519
|
const PlatformModule = require("react-native").Platform;
|
|
531
|
-
let savedOS:
|
|
520
|
+
let savedOS: any;
|
|
532
521
|
|
|
533
522
|
it("renders android headless when useNativeAndroidPickerStyle is false", () => {
|
|
534
523
|
savedOS = PlatformModule.OS;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {TabRouter} from "@react-navigation/native";
|
|
2
1
|
import {Navigator, Slot} from "expo-router";
|
|
3
2
|
// Screen is not exported from expo-router's public API (exports.d.ts only exposes ScreenProps).
|
|
4
3
|
// Stack.Screen and Tabs.Screen use this same internal path. If expo-router upgrades break this,
|
|
5
4
|
// update the import path here — this is the only place in the codebase that references it.
|
|
6
5
|
// eslint-disable-next-line import/no-internal-modules
|
|
7
6
|
import {Screen} from "expo-router/build/views/Screen";
|
|
7
|
+
import {TabRouter} from "expo-router/react-navigation";
|
|
8
8
|
import {type FC, type ReactNode, useCallback, useEffect, useMemo, useRef, useState} from "react";
|
|
9
9
|
import {
|
|
10
10
|
Animated,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {TabRouter} from "@react-navigation/native";
|
|
2
1
|
import {Navigator, Slot} from "expo-router";
|
|
3
2
|
// Screen is not exported from expo-router's public API (exports.d.ts only exposes ScreenProps).
|
|
4
3
|
// Stack.Screen and Tabs.Screen use this same internal path. If expo-router upgrades break this,
|
|
5
4
|
// update the import path here — this is the only place in the codebase that references it.
|
|
6
5
|
// eslint-disable-next-line import/no-internal-modules
|
|
7
6
|
import {Screen} from "expo-router/build/views/Screen";
|
|
7
|
+
import {TabRouter} from "expo-router/react-navigation";
|
|
8
8
|
import {type FC, type ReactNode, useCallback, useMemo, useState} from "react";
|
|
9
9
|
import {Pressable, type StyleProp, View, type ViewProps, type ViewStyle} from "react-native";
|
|
10
10
|
|