@terreno/ui 0.31.0 → 56.0.0-beta.2
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/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 -0
- 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/DateTimeField.js +5 -21
- package/dist/DateTimeField.js.map +1 -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 +5 -4
- package/dist/Page.js +0 -2
- package/dist/Page.js.map +1 -1
- 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/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 -2
- package/dist/index.js +5 -2
- 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 +44 -37
- package/src/ActionSheet.test.tsx +123 -136
- package/src/Box.test.tsx +68 -30
- package/src/Box.tsx +46 -7
- package/src/Common.ts +21 -3
- package/src/ConflictSheet.test.tsx +461 -0
- package/src/ConflictSheet.tsx +399 -0
- package/src/ConsentFormScreen.test.tsx +22 -0
- package/src/DateTimeField.test.tsx +14 -0
- package/src/DateTimeField.tsx +5 -19
- package/src/Hyperlink.tsx +1 -1
- package/src/Page.tsx +2 -3
- 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/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/WebDropdownMenu.test.tsx +128 -0
- 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__/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 +19 -0
- package/src/conflictFieldDiff.test.ts +26 -0
- package/src/conflictFieldDiff.ts +78 -0
- package/src/index.tsx +5 -2
- 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/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/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
|
+
};
|
|
@@ -351,6 +351,28 @@ describe("ConsentFormScreen", () => {
|
|
|
351
351
|
expect(queryByTestId("consent-footer-checkboxes-hint")).toBeNull();
|
|
352
352
|
});
|
|
353
353
|
|
|
354
|
+
it("toggles scrolling with the signature touch handlers on iOS", () => {
|
|
355
|
+
const form: ConsentFormPublic = {
|
|
356
|
+
...baseForm,
|
|
357
|
+
captureSignature: true,
|
|
358
|
+
};
|
|
359
|
+
const {getByTestId} = renderWithTheme(
|
|
360
|
+
<ConsentFormScreen form={form} locale="en" onAgree={() => {}} />
|
|
361
|
+
);
|
|
362
|
+
const signature = getByTestId("consent-form-signature");
|
|
363
|
+
const scroll = getByTestId("consent-form-scroll-view");
|
|
364
|
+
|
|
365
|
+
act(() => {
|
|
366
|
+
fireEvent(signature, "touchStart");
|
|
367
|
+
});
|
|
368
|
+
expect(scroll.props.scrollEnabled).toBe(false);
|
|
369
|
+
|
|
370
|
+
act(() => {
|
|
371
|
+
fireEvent(signature, "touchEnd");
|
|
372
|
+
});
|
|
373
|
+
expect(scroll.props.scrollEnabled).toBe(true);
|
|
374
|
+
});
|
|
375
|
+
|
|
354
376
|
it("exercises SignatureField onChange, onStart, and onEnd callbacks", () => {
|
|
355
377
|
const form: ConsentFormPublic = {
|
|
356
378
|
...baseForm,
|
|
@@ -1368,4 +1368,18 @@ describe("DateTimeField", () => {
|
|
|
1368
1368
|
expect(hourInput).toBeTruthy();
|
|
1369
1369
|
});
|
|
1370
1370
|
});
|
|
1371
|
+
|
|
1372
|
+
describe("timezone abbreviation", () => {
|
|
1373
|
+
it("falls back to the current time when there is no value and no complete segments", () => {
|
|
1374
|
+
setMobile();
|
|
1375
|
+
const {getByText} = renderWithTheme(
|
|
1376
|
+
<DateTimeField onChange={mockOnChange} timezone="America/New_York" type="time" value="" />
|
|
1377
|
+
);
|
|
1378
|
+
|
|
1379
|
+
const expectedAbbr = DateTime.now().setZone("America/New_York").offsetNameShort ?? "";
|
|
1380
|
+
assert.isNotEmpty(expectedAbbr);
|
|
1381
|
+
// With no value the placeholder is built from the current time in the given timezone.
|
|
1382
|
+
assert.isTrue(Boolean(getByText(`12:00 PM ${expectedAbbr}`)));
|
|
1383
|
+
});
|
|
1384
|
+
});
|
|
1371
1385
|
});
|
package/src/DateTimeField.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import {DateTime} from "luxon";
|
|
|
3
3
|
import React, {type FC, useCallback, useEffect, useMemo, useRef, useState} from "react";
|
|
4
4
|
import {Pressable, TextInput, View} from "react-native";
|
|
5
5
|
|
|
6
|
+
import type {ActionSheet} from "./ActionSheet";
|
|
6
7
|
import {Box} from "./Box";
|
|
7
8
|
import type {DateTimeFieldProps} from "./Common";
|
|
8
9
|
import {DateTimeActionSheet} from "./DateTimeActionSheet";
|
|
@@ -424,9 +425,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
424
425
|
}): React.ReactElement => {
|
|
425
426
|
const {theme} = useTheme();
|
|
426
427
|
const fieldTestIDs = resolveFieldTestIDsFromProps({testID, testIDs});
|
|
427
|
-
|
|
428
|
-
// biome-ignore lint/suspicious/noExplicitAny: ActionSheet class is defined in ActionSheet.tsx which imports from Common.ts indirectly; using its type here would create a circular dependency
|
|
429
|
-
const dateActionSheetRef: React.RefObject<any> = React.createRef();
|
|
428
|
+
const dateActionSheetRef: React.RefObject<ActionSheet | null> = React.createRef();
|
|
430
429
|
const [amPm, setAmPm] = useState<"am" | "pm">("am");
|
|
431
430
|
const [showDate, setShowDate] = useState(false);
|
|
432
431
|
const [month, setMonth] = useState("");
|
|
@@ -532,6 +531,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
532
531
|
}
|
|
533
532
|
}
|
|
534
533
|
|
|
534
|
+
// Minutes are not validated here: handleFieldChange validates them before this is reached.
|
|
535
535
|
if (type === "time" || type === "datetime") {
|
|
536
536
|
if (fieldIndex === (type === "time" ? 0 : 3)) {
|
|
537
537
|
// Hour
|
|
@@ -539,12 +539,6 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
539
539
|
if (Number.isNaN(hourNum) || hourNum < 1 || hourNum > 12) {
|
|
540
540
|
return "Hour must be between 1 and 12";
|
|
541
541
|
}
|
|
542
|
-
} else if (fieldIndex === (type === "time" ? 1 : 4)) {
|
|
543
|
-
// Minute
|
|
544
|
-
const minuteNum = parseInt(fieldValue, 10);
|
|
545
|
-
if (Number.isNaN(minuteNum) || minuteNum < 0 || minuteNum > 59) {
|
|
546
|
-
return "Minute must be between 0 and 59";
|
|
547
|
-
}
|
|
548
542
|
}
|
|
549
543
|
}
|
|
550
544
|
|
|
@@ -691,11 +685,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
691
685
|
setFieldErrors((prev) => ({...prev, [index]: "Minute must be between 0 and 59"}));
|
|
692
686
|
}
|
|
693
687
|
|
|
694
|
-
//
|
|
695
|
-
const configs = getFieldConfigs();
|
|
696
|
-
if (finalValue.length === config.maxLength && index < configs.length - 1) {
|
|
697
|
-
inputRefs.current[index + 1]?.focus();
|
|
698
|
-
}
|
|
688
|
+
// The minute segment is always last, so there is nothing to advance focus to.
|
|
699
689
|
return;
|
|
700
690
|
}
|
|
701
691
|
|
|
@@ -811,11 +801,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
|
|
|
811
801
|
.set({millisecond: 0, second: 0})
|
|
812
802
|
.toISO()
|
|
813
803
|
: parsedDate.set({millisecond: 0, second: 0}).toUTC().toISO();
|
|
814
|
-
|
|
815
|
-
console.warn("Invalid date passed to DateTimeField", parsedDate);
|
|
816
|
-
return;
|
|
817
|
-
}
|
|
818
|
-
onChange(normalized);
|
|
804
|
+
onChange(normalized ?? "");
|
|
819
805
|
setShowDate(false);
|
|
820
806
|
},
|
|
821
807
|
[onChange, type]
|
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(
|
package/src/Page.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import {router} from "expo-router";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import {SafeAreaView} from "react-native-safe-area-context";
|
|
4
4
|
|
|
5
|
+
import type {ActionSheet} from "./ActionSheet";
|
|
5
6
|
import {Box} from "./Box";
|
|
6
7
|
import {Button} from "./Button";
|
|
7
8
|
import type {PageProps} from "./Common";
|
|
@@ -12,9 +13,7 @@ import {Spinner} from "./Spinner";
|
|
|
12
13
|
import {Text} from "./Text";
|
|
13
14
|
|
|
14
15
|
export class Page extends React.Component<PageProps, {}> {
|
|
15
|
-
|
|
16
|
-
// biome-ignore lint/suspicious/noExplicitAny: ActionSheet class is defined in ActionSheet.tsx which imports from Common.ts indirectly; using its type here would create a circular dependency
|
|
17
|
-
actionSheetRef: React.RefObject<any> = React.createRef();
|
|
16
|
+
actionSheetRef: React.RefObject<ActionSheet | null> = React.createRef();
|
|
18
17
|
|
|
19
18
|
renderHeader() {
|
|
20
19
|
if (!this.props.title && !this.props.backButton) {
|
|
@@ -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
|
|