@terreno/ui 57.3.0 → 57.4.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/AnnouncementBanner.d.ts +12 -0
- package/dist/AnnouncementBanner.js +61 -0
- package/dist/AnnouncementBanner.js.map +1 -0
- package/dist/AnnouncementNavigator.d.ts +11 -0
- package/dist/AnnouncementNavigator.js +189 -0
- package/dist/AnnouncementNavigator.js.map +1 -0
- package/dist/AnnouncementScreen.d.ts +12 -0
- package/dist/AnnouncementScreen.js +28 -0
- package/dist/AnnouncementScreen.js.map +1 -0
- package/dist/AreaChart.d.ts +5 -0
- package/dist/AreaChart.js +69 -0
- package/dist/AreaChart.js.map +1 -0
- package/dist/BarChart.d.ts +5 -0
- package/dist/BarChart.js +89 -0
- package/dist/BarChart.js.map +1 -0
- package/dist/Button.js +17 -3
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +96 -0
- package/dist/Common.js.map +1 -1
- package/dist/DashboardGrid.d.ts +4 -0
- package/dist/DashboardGrid.js +38 -0
- package/dist/DashboardGrid.js.map +1 -0
- package/dist/DataTable.js +83 -11
- package/dist/DataTable.js.map +1 -1
- package/dist/DonutChart.d.ts +5 -0
- package/dist/DonutChart.js +84 -0
- package/dist/DonutChart.js.map +1 -0
- package/dist/Filter.js +12 -2
- package/dist/Filter.js.map +1 -1
- package/dist/GPTChat.d.ts +7 -1
- package/dist/GPTChat.js +28 -15
- package/dist/GPTChat.js.map +1 -1
- package/dist/LineChart.d.ts +5 -0
- package/dist/LineChart.js +68 -0
- package/dist/LineChart.js.map +1 -0
- package/dist/MarkdownEmbed.d.ts +6 -0
- package/dist/MarkdownEmbed.js +17 -0
- package/dist/MarkdownEmbed.js.map +1 -0
- package/dist/MarkdownView.js +38 -3
- package/dist/MarkdownView.js.map +1 -1
- package/dist/Modal.js +12 -10
- package/dist/Modal.js.map +1 -1
- package/dist/ModalSheet.d.ts +5 -1
- package/dist/ModalSheet.js +31 -13
- package/dist/ModalSheet.js.map +1 -1
- package/dist/MultiselectField.js +4 -9
- package/dist/MultiselectField.js.map +1 -1
- package/dist/NotificationBell.d.ts +16 -0
- package/dist/NotificationBell.js +15 -0
- package/dist/NotificationBell.js.map +1 -0
- package/dist/NotificationInbox.d.ts +21 -0
- package/dist/NotificationInbox.js +41 -0
- package/dist/NotificationInbox.js.map +1 -0
- package/dist/NotificationPreferences.d.ts +14 -0
- package/dist/NotificationPreferences.js +32 -0
- package/dist/NotificationPreferences.js.map +1 -0
- package/dist/TextField.js +83 -6
- package/dist/TextField.js.map +1 -1
- package/dist/announcementBuildVersion.d.ts +6 -0
- package/dist/announcementBuildVersion.js +21 -0
- package/dist/announcementBuildVersion.js.map +1 -0
- package/dist/announcementFrequency.d.ts +42 -0
- package/dist/announcementFrequency.js +163 -0
- package/dist/announcementFrequency.js.map +1 -0
- package/dist/announcementPlatform.d.ts +2 -0
- package/dist/announcementPlatform.js +11 -0
- package/dist/announcementPlatform.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +12 -0
- package/dist/charts/ChartFrame.js +13 -0
- package/dist/charts/ChartFrame.js.map +1 -0
- package/dist/charts/bars.d.ts +18 -0
- package/dist/charts/bars.js +29 -0
- package/dist/charts/bars.js.map +1 -0
- package/dist/charts/layout.d.ts +47 -0
- package/dist/charts/layout.js +56 -0
- package/dist/charts/layout.js.map +1 -0
- package/dist/charts/paths.d.ts +31 -0
- package/dist/charts/paths.js +52 -0
- package/dist/charts/paths.js.map +1 -0
- package/dist/charts/scales.d.ts +6 -0
- package/dist/charts/scales.js +43 -0
- package/dist/charts/scales.js.map +1 -0
- package/dist/charts/theme.d.ts +9 -0
- package/dist/charts/theme.js +15 -0
- package/dist/charts/theme.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +17 -0
- package/dist/charts/types/chartTypes.js +2 -0
- package/dist/charts/types/chartTypes.js.map +1 -0
- package/dist/dashboardGridLayout.d.ts +22 -0
- package/dist/dashboardGridLayout.js +33 -0
- package/dist/dashboardGridLayout.js.map +1 -0
- package/dist/dataTableFilters.d.ts +33 -0
- package/dist/dataTableFilters.js +221 -0
- package/dist/dataTableFilters.js.map +1 -0
- package/dist/dataTableListQuery.d.ts +42 -0
- package/dist/dataTableListQuery.js +161 -0
- package/dist/dataTableListQuery.js.map +1 -0
- package/dist/index.d.ts +18 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +12 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js +8 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/markdownEmbeds.d.ts +6 -0
- package/dist/markdownEmbeds.js +59 -0
- package/dist/markdownEmbeds.js.map +1 -0
- package/dist/testing/resolveTestId.js +2 -1
- package/dist/testing/resolveTestId.js.map +1 -1
- package/dist/testing/types.d.ts +3 -0
- package/dist/textFieldOscillationGuard.d.ts +25 -0
- package/dist/textFieldOscillationGuard.js +41 -0
- package/dist/textFieldOscillationGuard.js.map +1 -0
- package/dist/useAcknowledgeAnnouncement.d.ts +71 -0
- package/dist/useAcknowledgeAnnouncement.js +94 -0
- package/dist/useAcknowledgeAnnouncement.js.map +1 -0
- package/dist/useAnnouncements.d.ts +73 -0
- package/dist/useAnnouncements.js +66 -0
- package/dist/useAnnouncements.js.map +1 -0
- package/package.json +7 -18
- package/src/AnnouncementBanner.test.tsx +267 -0
- package/src/AnnouncementBanner.tsx +128 -0
- package/src/AnnouncementNavigator.test.tsx +759 -0
- package/src/AnnouncementNavigator.tsx +287 -0
- package/src/AnnouncementScreen.test.tsx +97 -0
- package/src/AnnouncementScreen.tsx +70 -0
- package/src/AreaChart.test.tsx +68 -0
- package/src/AreaChart.tsx +194 -0
- package/src/BarChart.test.tsx +96 -0
- package/src/BarChart.tsx +208 -0
- package/src/Button.test.tsx +66 -0
- package/src/Button.tsx +17 -2
- package/src/Common.ts +95 -0
- package/src/ConsentNavigator.test.tsx +55 -0
- package/src/DashboardGrid.test.tsx +75 -0
- package/src/DashboardGrid.tsx +69 -0
- package/src/DataTable.test.tsx +296 -1
- package/src/DataTable.tsx +210 -18
- package/src/DonutChart.test.tsx +121 -0
- package/src/DonutChart.tsx +160 -0
- package/src/EmojiSelector.test.tsx +51 -0
- package/src/Field.test.tsx +18 -0
- package/src/Filter.test.tsx +25 -0
- package/src/Filter.tsx +38 -7
- package/src/GPTChat.test.tsx +107 -0
- package/src/GPTChat.tsx +176 -86
- package/src/LineChart.test.tsx +166 -0
- package/src/LineChart.tsx +190 -0
- package/src/MarkdownEmbed.test.tsx +34 -0
- package/src/MarkdownEmbed.tsx +43 -0
- package/src/MarkdownView.test.tsx +59 -2
- package/src/MarkdownView.tsx +51 -3
- package/src/Modal.test.tsx +107 -14
- package/src/Modal.tsx +20 -8
- package/src/ModalSheet.test.tsx +121 -9
- package/src/ModalSheet.tsx +46 -11
- package/src/MultiselectField.test.tsx +21 -0
- package/src/MultiselectField.tsx +11 -13
- package/src/NotificationBell.test.tsx +91 -0
- package/src/NotificationBell.tsx +77 -0
- package/src/NotificationInbox.test.tsx +130 -0
- package/src/NotificationInbox.tsx +144 -0
- package/src/NotificationPreferences.test.tsx +25 -0
- package/src/NotificationPreferences.tsx +75 -0
- package/src/RootImportRegression.test.tsx +20 -0
- package/src/TextField.test.tsx +421 -0
- package/src/TextField.tsx +121 -4
- package/src/__snapshots__/Field.test.tsx.snap +22 -0
- package/src/__snapshots__/ModalSheet.test.tsx.snap +4 -1
- package/src/__snapshots__/TextArea.test.tsx.snap +5 -5
- package/src/__snapshots__/TextField.test.tsx.snap +5 -5
- package/src/announcementBuildVersion.test.ts +43 -0
- package/src/announcementBuildVersion.ts +21 -0
- package/src/announcementFrequency.test.ts +245 -0
- package/src/announcementFrequency.ts +246 -0
- package/src/announcementPlatform.test.ts +27 -0
- package/src/announcementPlatform.ts +13 -0
- package/src/charts/ChartFrame.tsx +67 -0
- package/src/charts/bars.test.ts +56 -0
- package/src/charts/bars.ts +53 -0
- package/src/charts/layout.test.ts +80 -0
- package/src/charts/layout.ts +99 -0
- package/src/charts/paths.test.ts +79 -0
- package/src/charts/paths.ts +100 -0
- package/src/charts/scales.test.ts +59 -0
- package/src/charts/scales.ts +60 -0
- package/src/charts/theme.test.ts +22 -0
- package/src/charts/theme.ts +24 -0
- package/src/charts/types/chartTypes.ts +19 -0
- package/src/dashboardGridLayout.test.ts +90 -0
- package/src/dashboardGridLayout.ts +60 -0
- package/src/dataTableFilters.test.tsx +552 -0
- package/src/dataTableFilters.tsx +441 -0
- package/src/dataTableListQuery.test.ts +220 -0
- package/src/dataTableListQuery.ts +201 -0
- package/src/index.tsx +21 -1
- package/src/lazyBoundaries/heavyOptionalExports.tsx +28 -0
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +22 -0
- package/src/markdownEmbeds.test.ts +53 -0
- package/src/markdownEmbeds.ts +62 -0
- package/src/pdfHtmlTemplate.test.ts +119 -0
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -0
- package/src/testing/resolveTestId.test.ts +3 -0
- package/src/testing/resolveTestId.ts +1 -0
- package/src/testing/types.ts +3 -0
- package/src/textFieldOscillationGuard.test.ts +63 -0
- package/src/textFieldOscillationGuard.ts +89 -0
- package/src/types/react-native-markdown-display.d.ts +6 -0
- package/src/types/react-native-swiper-flatlist.d.ts +5 -5
- package/src/useAcknowledgeAnnouncement.test.ts +223 -0
- package/src/useAcknowledgeAnnouncement.ts +166 -0
- package/src/useAnnouncements.test.ts +226 -0
- package/src/useAnnouncements.ts +150 -0
|
@@ -69,6 +69,7 @@ describe("resolveFieldTestIDs", () => {
|
|
|
69
69
|
helper: "signup.email.helper",
|
|
70
70
|
input: "signup.email",
|
|
71
71
|
label: "signup.email.label",
|
|
72
|
+
visibilityToggle: "signup.email.visibility-toggle",
|
|
72
73
|
});
|
|
73
74
|
});
|
|
74
75
|
|
|
@@ -77,12 +78,14 @@ describe("resolveFieldTestIDs", () => {
|
|
|
77
78
|
resolveFieldTestIDs("signup.email", {
|
|
78
79
|
input: "custom-input",
|
|
79
80
|
label: "custom-label",
|
|
81
|
+
visibilityToggle: "custom-toggle",
|
|
80
82
|
})
|
|
81
83
|
).toEqual({
|
|
82
84
|
error: "signup.email.error",
|
|
83
85
|
helper: "signup.email.helper",
|
|
84
86
|
input: "custom-input",
|
|
85
87
|
label: "custom-label",
|
|
88
|
+
visibilityToggle: "custom-toggle",
|
|
86
89
|
});
|
|
87
90
|
});
|
|
88
91
|
});
|
|
@@ -62,6 +62,7 @@ export const resolveFieldTestIDs = (
|
|
|
62
62
|
helper: testIDs?.helper ?? resolveTestID(baseTestID, "helper"),
|
|
63
63
|
input: testIDs?.input ?? baseTestID,
|
|
64
64
|
label: testIDs?.label ?? resolveTestID(baseTestID, "label"),
|
|
65
|
+
visibilityToggle: testIDs?.visibilityToggle ?? resolveTestID(baseTestID, "visibility-toggle"),
|
|
65
66
|
};
|
|
66
67
|
};
|
|
67
68
|
|
package/src/testing/types.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface FieldTestIDs {
|
|
|
10
10
|
input?: string;
|
|
11
11
|
error?: string;
|
|
12
12
|
helper?: string;
|
|
13
|
+
/** Show/hide control on password fields. */
|
|
14
|
+
visibilityToggle?: string;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/** Sub-element test ids for Modal. */
|
|
@@ -42,6 +44,7 @@ export interface ResolvedFieldTestIDs {
|
|
|
42
44
|
input?: string;
|
|
43
45
|
error?: string;
|
|
44
46
|
helper?: string;
|
|
47
|
+
visibilityToggle?: string;
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
export interface ResolvedModalTestIDs {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
createTextFieldOscillationState,
|
|
4
|
+
recordTextFieldOscillation,
|
|
5
|
+
shouldSuppressTextFieldOscillation,
|
|
6
|
+
TEXT_FIELD_OSCILLATION_WINDOW_MS,
|
|
7
|
+
} from "./textFieldOscillationGuard";
|
|
8
|
+
|
|
9
|
+
describe("textFieldOscillationGuard", () => {
|
|
10
|
+
it("suppresses rapid A→B→A synthetic alternation", () => {
|
|
11
|
+
const state = createTextFieldOscillationState();
|
|
12
|
+
const valueA = "reachthreshold";
|
|
13
|
+
const valueB = "reach threshold";
|
|
14
|
+
let now = 1_000;
|
|
15
|
+
|
|
16
|
+
expect(
|
|
17
|
+
shouldSuppressTextFieldOscillation({currentValue: valueA, now, state, text: valueB})
|
|
18
|
+
).toBe(false);
|
|
19
|
+
recordTextFieldOscillation({currentValue: valueA, now, state, text: valueB});
|
|
20
|
+
|
|
21
|
+
now += 10;
|
|
22
|
+
expect(
|
|
23
|
+
shouldSuppressTextFieldOscillation({currentValue: valueB, now, state, text: valueA})
|
|
24
|
+
).toBe(true);
|
|
25
|
+
|
|
26
|
+
now += 10;
|
|
27
|
+
expect(
|
|
28
|
+
shouldSuppressTextFieldOscillation({currentValue: valueB, now, state, text: valueA})
|
|
29
|
+
).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("allows ordinary backspace and retype after the oscillation window", () => {
|
|
33
|
+
const state = createTextFieldOscillationState();
|
|
34
|
+
const hello = "hello";
|
|
35
|
+
const hell = "hell";
|
|
36
|
+
let now = 2_000;
|
|
37
|
+
|
|
38
|
+
expect(shouldSuppressTextFieldOscillation({currentValue: hello, now, state, text: hell})).toBe(
|
|
39
|
+
false
|
|
40
|
+
);
|
|
41
|
+
recordTextFieldOscillation({currentValue: hello, now, state, text: hell});
|
|
42
|
+
|
|
43
|
+
now += TEXT_FIELD_OSCILLATION_WINDOW_MS + 1;
|
|
44
|
+
expect(shouldSuppressTextFieldOscillation({currentValue: hell, now, state, text: hello})).toBe(
|
|
45
|
+
false
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("allows forward typing that does not revisit a recent prior value", () => {
|
|
50
|
+
const state = createTextFieldOscillationState();
|
|
51
|
+
let now = 3_000;
|
|
52
|
+
|
|
53
|
+
expect(shouldSuppressTextFieldOscillation({currentValue: "h", now, state, text: "he"})).toBe(
|
|
54
|
+
false
|
|
55
|
+
);
|
|
56
|
+
recordTextFieldOscillation({currentValue: "h", now, state, text: "he"});
|
|
57
|
+
|
|
58
|
+
now += 5;
|
|
59
|
+
expect(shouldSuppressTextFieldOscillation({currentValue: "he", now, state, text: "hel"})).toBe(
|
|
60
|
+
false
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** RN Web controlled inputs can fire rapid synthetic A↔B onChangeText after typing stops. */
|
|
2
|
+
export const TEXT_FIELD_OSCILLATION_WINDOW_MS = 500;
|
|
3
|
+
|
|
4
|
+
export interface TextFieldOscillationState {
|
|
5
|
+
priorText: string | null;
|
|
6
|
+
priorTime: number;
|
|
7
|
+
lastText: string | null;
|
|
8
|
+
lastTime: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const createTextFieldOscillationState = (): TextFieldOscillationState => ({
|
|
12
|
+
lastText: null,
|
|
13
|
+
lastTime: 0,
|
|
14
|
+
priorText: null,
|
|
15
|
+
priorTime: 0,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const resetTextFieldOscillationState = (state: TextFieldOscillationState): void => {
|
|
19
|
+
state.priorText = null;
|
|
20
|
+
state.priorTime = 0;
|
|
21
|
+
state.lastText = null;
|
|
22
|
+
state.lastTime = 0;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const isOscillationHistoryStale = ({
|
|
26
|
+
now,
|
|
27
|
+
state,
|
|
28
|
+
windowMs,
|
|
29
|
+
}: {
|
|
30
|
+
now: number;
|
|
31
|
+
state: TextFieldOscillationState;
|
|
32
|
+
windowMs: number;
|
|
33
|
+
}): boolean => state.lastTime > 0 && now - state.lastTime > windowMs;
|
|
34
|
+
|
|
35
|
+
/** True when `text` completes a rapid prior → last → prior reversal (A→B→A). */
|
|
36
|
+
export const shouldSuppressTextFieldOscillation = ({
|
|
37
|
+
currentValue,
|
|
38
|
+
now,
|
|
39
|
+
state,
|
|
40
|
+
text,
|
|
41
|
+
windowMs = TEXT_FIELD_OSCILLATION_WINDOW_MS,
|
|
42
|
+
}: {
|
|
43
|
+
currentValue: string;
|
|
44
|
+
now: number;
|
|
45
|
+
state: TextFieldOscillationState;
|
|
46
|
+
text: string;
|
|
47
|
+
windowMs?: number;
|
|
48
|
+
}): boolean => {
|
|
49
|
+
if (isOscillationHistoryStale({now, state, windowMs})) {
|
|
50
|
+
resetTextFieldOscillationState(state);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const {priorText, priorTime, lastText, lastTime} = state;
|
|
55
|
+
if (priorText === null || lastText === null) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
text === priorText &&
|
|
61
|
+
text !== lastText &&
|
|
62
|
+
text !== currentValue &&
|
|
63
|
+
now - priorTime <= windowMs &&
|
|
64
|
+
now - lastTime <= windowMs
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const recordTextFieldOscillation = ({
|
|
69
|
+
currentValue,
|
|
70
|
+
now,
|
|
71
|
+
state,
|
|
72
|
+
text,
|
|
73
|
+
windowMs = TEXT_FIELD_OSCILLATION_WINDOW_MS,
|
|
74
|
+
}: {
|
|
75
|
+
currentValue: string;
|
|
76
|
+
now: number;
|
|
77
|
+
state: TextFieldOscillationState;
|
|
78
|
+
text: string;
|
|
79
|
+
windowMs?: number;
|
|
80
|
+
}): void => {
|
|
81
|
+
if (isOscillationHistoryStale({now, state, windowMs})) {
|
|
82
|
+
resetTextFieldOscillationState(state);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
state.priorText = currentValue;
|
|
86
|
+
state.priorTime = state.lastTime > 0 ? state.lastTime : now;
|
|
87
|
+
state.lastText = text;
|
|
88
|
+
state.lastTime = now;
|
|
89
|
+
};
|
|
@@ -40,11 +40,11 @@ declare module "react-native-swiper-flatlist" {
|
|
|
40
40
|
scrollToIndex: (params: {index: number; animated?: boolean}) => void;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
>;
|
|
43
|
+
// noExplicitAny: declaration must use any for the generic to allow consumers to specify their data type without explicit type args
|
|
44
|
+
// biome-ignore lint/suspicious/noExplicitAny: declaration must use any for the generic to allow consumers to specify their data type without explicit type args
|
|
45
|
+
type SwiperFlatListPropsWithRef = SwiperFlatListProps<any> &
|
|
46
|
+
React.RefAttributes<SwiperFlatListRefProps>;
|
|
47
|
+
export const SwiperFlatList: React.ForwardRefExoticComponent<SwiperFlatListPropsWithRef>;
|
|
48
48
|
|
|
49
49
|
export const Pagination: React.FC<{
|
|
50
50
|
paginationActiveColor?: string;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {renderHook} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
4
|
+
import {Platform} from "react-native";
|
|
5
|
+
|
|
6
|
+
import {useAcknowledgeAnnouncement} from "./useAcknowledgeAnnouncement";
|
|
7
|
+
|
|
8
|
+
type AcknowledgeApi = Parameters<typeof useAcknowledgeAnnouncement>[0];
|
|
9
|
+
|
|
10
|
+
interface MockMutationDef {
|
|
11
|
+
query: (args: {announcementId: string; platform?: string}) => {
|
|
12
|
+
body?: {action?: string; platform?: string};
|
|
13
|
+
method: string;
|
|
14
|
+
url: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface MockInjectOpts {
|
|
19
|
+
endpoints: (build: {mutation: (def: MockMutationDef) => string}) => Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe("useAcknowledgeAnnouncement", () => {
|
|
23
|
+
const buildApi = () => {
|
|
24
|
+
const acknowledgeUnwrap = mock(async () => ({acknowledged: true}));
|
|
25
|
+
const impressionUnwrap = mock(async () => ({recorded: true}));
|
|
26
|
+
const clickUnwrap = mock(async () => ({recorded: true}));
|
|
27
|
+
const acknowledgeMutation = mock(() => ({unwrap: acknowledgeUnwrap}));
|
|
28
|
+
const impressionMutation = mock(() => ({unwrap: impressionUnwrap}));
|
|
29
|
+
const clickMutation = mock(() => ({unwrap: clickUnwrap}));
|
|
30
|
+
let clickQueryDef: MockMutationDef | undefined;
|
|
31
|
+
let acknowledgeQueryDef: MockMutationDef | undefined;
|
|
32
|
+
const api = {
|
|
33
|
+
enhanceEndpoints: mock(() => ({
|
|
34
|
+
injectEndpoints: mock((opts: MockInjectOpts) => {
|
|
35
|
+
const build = {
|
|
36
|
+
mutation: mock((def: MockMutationDef) => {
|
|
37
|
+
const result = def.query({announcementId: "a1", platform: "ios"});
|
|
38
|
+
expect(result.method).toBe("POST");
|
|
39
|
+
expect(result.url).toContain("/announcements/a1/");
|
|
40
|
+
if (result.url.includes("/click")) {
|
|
41
|
+
clickQueryDef = def;
|
|
42
|
+
}
|
|
43
|
+
if (result.url.includes("/acknowledge")) {
|
|
44
|
+
acknowledgeQueryDef = def;
|
|
45
|
+
}
|
|
46
|
+
return "mutation";
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
opts.endpoints(build);
|
|
50
|
+
return {
|
|
51
|
+
useAcknowledgeAnnouncementMutation: () => [
|
|
52
|
+
acknowledgeMutation,
|
|
53
|
+
{error: undefined, isLoading: false},
|
|
54
|
+
],
|
|
55
|
+
useRecordAnnouncementClickMutation: () => [
|
|
56
|
+
clickMutation,
|
|
57
|
+
{error: undefined, isLoading: false},
|
|
58
|
+
],
|
|
59
|
+
useRecordAnnouncementImpressionMutation: () => [
|
|
60
|
+
impressionMutation,
|
|
61
|
+
{error: undefined, isLoading: false},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
}),
|
|
65
|
+
})),
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
acknowledgeMutation,
|
|
69
|
+
acknowledgeQueryDef: () => acknowledgeQueryDef,
|
|
70
|
+
api,
|
|
71
|
+
clickMutation,
|
|
72
|
+
clickQueryDef: () => clickQueryDef,
|
|
73
|
+
impressionMutation,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
it("acknowledges and records impressions", async () => {
|
|
78
|
+
const {api, acknowledgeMutation, impressionMutation} = buildApi();
|
|
79
|
+
const {result} = renderHook(() =>
|
|
80
|
+
useAcknowledgeAnnouncement(api as unknown as AcknowledgeApi, "/api")
|
|
81
|
+
);
|
|
82
|
+
await result.current.acknowledge("announcement-1");
|
|
83
|
+
await result.current.recordImpression("announcement-1");
|
|
84
|
+
expect(acknowledgeMutation).toHaveBeenCalled();
|
|
85
|
+
expect(impressionMutation).toHaveBeenCalled();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("uses the client platform for impressions", async () => {
|
|
89
|
+
const originalOS = Platform.OS;
|
|
90
|
+
Platform.OS = "ios";
|
|
91
|
+
const {api, impressionMutation} = buildApi();
|
|
92
|
+
const {result} = renderHook(() => useAcknowledgeAnnouncement(api as unknown as AcknowledgeApi));
|
|
93
|
+
await result.current.recordImpression("announcement-1");
|
|
94
|
+
expect(impressionMutation).toHaveBeenCalledWith({
|
|
95
|
+
announcementId: "announcement-1",
|
|
96
|
+
platform: "ios",
|
|
97
|
+
});
|
|
98
|
+
Platform.OS = originalOS;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("records primary-action clicks with platform and build version in the query", async () => {
|
|
102
|
+
const constantsState = {
|
|
103
|
+
expoConfig: {
|
|
104
|
+
extra: {
|
|
105
|
+
buildNumber: 42,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
mock.module("expo-constants", () => ({
|
|
110
|
+
default: constantsState,
|
|
111
|
+
}));
|
|
112
|
+
|
|
113
|
+
const originalOS = Platform.OS;
|
|
114
|
+
Platform.OS = "web";
|
|
115
|
+
|
|
116
|
+
const {api, clickMutation, clickQueryDef} = buildApi();
|
|
117
|
+
const {result} = renderHook(() =>
|
|
118
|
+
useAcknowledgeAnnouncement(api as unknown as AcknowledgeApi, "/api")
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
await result.current.recordClick("announcement-42");
|
|
122
|
+
|
|
123
|
+
assert.strictEqual(clickMutation.mock.calls.length, 1);
|
|
124
|
+
assert.deepEqual(clickMutation.mock.calls[0], [{announcementId: "announcement-42"}]);
|
|
125
|
+
|
|
126
|
+
const clickDef = clickQueryDef();
|
|
127
|
+
assert.ok(clickDef);
|
|
128
|
+
const queryResult = clickDef.query({announcementId: "announcement-42"});
|
|
129
|
+
assert.strictEqual(queryResult.method, "POST");
|
|
130
|
+
assert.strictEqual(
|
|
131
|
+
queryResult.url,
|
|
132
|
+
"/api/announcements/announcement-42/click?platform=web&version=42"
|
|
133
|
+
);
|
|
134
|
+
assert.deepEqual(queryResult.body, {action: "primaryAction", platform: "web"});
|
|
135
|
+
|
|
136
|
+
Platform.OS = originalOS;
|
|
137
|
+
mock.module("expo-constants", () => ({
|
|
138
|
+
default: {expoConfig: {extra: {buildNumber: undefined}}},
|
|
139
|
+
}));
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("omits version from click URL when build number is not finite", async () => {
|
|
143
|
+
mock.module("expo-constants", () => ({
|
|
144
|
+
default: {expoConfig: {extra: {buildNumber: undefined}}},
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
const originalOS = Platform.OS;
|
|
148
|
+
Platform.OS = "android";
|
|
149
|
+
|
|
150
|
+
const {api, clickQueryDef} = buildApi();
|
|
151
|
+
renderHook(() => useAcknowledgeAnnouncement(api as unknown as AcknowledgeApi, "/api"));
|
|
152
|
+
|
|
153
|
+
const clickDef = clickQueryDef();
|
|
154
|
+
assert.ok(clickDef);
|
|
155
|
+
const queryResult = clickDef.query({announcementId: "announcement-1"});
|
|
156
|
+
assert.strictEqual(queryResult.url, "/api/announcements/announcement-1/click?platform=android");
|
|
157
|
+
assert.deepEqual(queryResult.body, {action: "primaryAction", platform: "android"});
|
|
158
|
+
|
|
159
|
+
Platform.OS = originalOS;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("posts acknowledge with platform and build version in the query", async () => {
|
|
163
|
+
const constantsState = {
|
|
164
|
+
expoConfig: {
|
|
165
|
+
extra: {
|
|
166
|
+
buildNumber: 42,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
mock.module("expo-constants", () => ({
|
|
171
|
+
default: constantsState,
|
|
172
|
+
}));
|
|
173
|
+
|
|
174
|
+
const originalOS = Platform.OS;
|
|
175
|
+
Platform.OS = "ios";
|
|
176
|
+
|
|
177
|
+
const {api, acknowledgeMutation, acknowledgeQueryDef} = buildApi();
|
|
178
|
+
const {result} = renderHook(() =>
|
|
179
|
+
useAcknowledgeAnnouncement(api as unknown as AcknowledgeApi, "/api")
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
await result.current.acknowledge("announcement-42");
|
|
183
|
+
|
|
184
|
+
assert.strictEqual(acknowledgeMutation.mock.calls.length, 1);
|
|
185
|
+
assert.deepEqual(acknowledgeMutation.mock.calls[0], [{announcementId: "announcement-42"}]);
|
|
186
|
+
|
|
187
|
+
const acknowledgeDef = acknowledgeQueryDef();
|
|
188
|
+
assert.ok(acknowledgeDef);
|
|
189
|
+
const queryResult = acknowledgeDef.query({announcementId: "announcement-42"});
|
|
190
|
+
assert.strictEqual(queryResult.method, "POST");
|
|
191
|
+
assert.strictEqual(
|
|
192
|
+
queryResult.url,
|
|
193
|
+
"/api/announcements/announcement-42/acknowledge?platform=ios&version=42"
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
Platform.OS = originalOS;
|
|
197
|
+
mock.module("expo-constants", () => ({
|
|
198
|
+
default: {expoConfig: {extra: {buildNumber: undefined}}},
|
|
199
|
+
}));
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("omits version from acknowledge URL when build number is not finite", async () => {
|
|
203
|
+
mock.module("expo-constants", () => ({
|
|
204
|
+
default: {expoConfig: {extra: {buildNumber: undefined}}},
|
|
205
|
+
}));
|
|
206
|
+
|
|
207
|
+
const originalOS = Platform.OS;
|
|
208
|
+
Platform.OS = "web";
|
|
209
|
+
|
|
210
|
+
const {api, acknowledgeQueryDef} = buildApi();
|
|
211
|
+
renderHook(() => useAcknowledgeAnnouncement(api as unknown as AcknowledgeApi, "/api"));
|
|
212
|
+
|
|
213
|
+
const acknowledgeDef = acknowledgeQueryDef();
|
|
214
|
+
assert.ok(acknowledgeDef);
|
|
215
|
+
const queryResult = acknowledgeDef.query({announcementId: "announcement-1"});
|
|
216
|
+
assert.strictEqual(
|
|
217
|
+
queryResult.url,
|
|
218
|
+
"/api/announcements/announcement-1/acknowledge?platform=web"
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
Platform.OS = originalOS;
|
|
222
|
+
});
|
|
223
|
+
});
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import {useCallback, useRef} from "react";
|
|
2
|
+
|
|
3
|
+
import {getAnnouncementBuildVersion} from "./announcementBuildVersion";
|
|
4
|
+
import {getAnnouncementPlatform} from "./announcementPlatform";
|
|
5
|
+
|
|
6
|
+
interface AcknowledgeAnnouncementMutationResult {
|
|
7
|
+
unwrap: () => Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface AcknowledgeAnnouncementMutationHookState {
|
|
11
|
+
error: unknown;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface AcknowledgeAnnouncementMutationBuilder {
|
|
16
|
+
mutation: (options: {
|
|
17
|
+
invalidatesTags: string[];
|
|
18
|
+
query: (args: {announcementId: string; platform?: string}) => {
|
|
19
|
+
body?: {action?: string; platform?: string};
|
|
20
|
+
method: "POST";
|
|
21
|
+
url: string;
|
|
22
|
+
};
|
|
23
|
+
}) => unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface AcknowledgeAnnouncementEnhancedApi {
|
|
27
|
+
useAcknowledgeAnnouncementMutation: () => [
|
|
28
|
+
(args: {announcementId: string; platform?: string}) => AcknowledgeAnnouncementMutationResult,
|
|
29
|
+
AcknowledgeAnnouncementMutationHookState,
|
|
30
|
+
];
|
|
31
|
+
useRecordAnnouncementClickMutation: () => [
|
|
32
|
+
(args: {announcementId: string}) => AcknowledgeAnnouncementMutationResult,
|
|
33
|
+
AcknowledgeAnnouncementMutationHookState,
|
|
34
|
+
];
|
|
35
|
+
useRecordAnnouncementImpressionMutation: () => [
|
|
36
|
+
(args: {announcementId: string; platform?: string}) => AcknowledgeAnnouncementMutationResult,
|
|
37
|
+
AcknowledgeAnnouncementMutationHookState,
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface AcknowledgeAnnouncementApiWithTags {
|
|
42
|
+
injectEndpoints: (options: {
|
|
43
|
+
endpoints: (build: AcknowledgeAnnouncementMutationBuilder) => {
|
|
44
|
+
acknowledgeAnnouncement: unknown;
|
|
45
|
+
recordAnnouncementClick: unknown;
|
|
46
|
+
recordAnnouncementImpression: unknown;
|
|
47
|
+
};
|
|
48
|
+
overrideExisting: boolean;
|
|
49
|
+
}) => AcknowledgeAnnouncementEnhancedApi;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface AcknowledgeAnnouncementApi {
|
|
53
|
+
enhanceEndpoints: (options: {addTagTypes: string[]}) => AcknowledgeAnnouncementApiWithTags;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const enhancedApiCache = new WeakMap<
|
|
57
|
+
AcknowledgeAnnouncementApi,
|
|
58
|
+
Map<string, AcknowledgeAnnouncementEnhancedApi>
|
|
59
|
+
>();
|
|
60
|
+
|
|
61
|
+
const buildAnnouncementEventUrl = (
|
|
62
|
+
base: string,
|
|
63
|
+
announcementId: string,
|
|
64
|
+
action: "acknowledge" | "click"
|
|
65
|
+
): string => {
|
|
66
|
+
const platform = getAnnouncementPlatform();
|
|
67
|
+
const version = getAnnouncementBuildVersion();
|
|
68
|
+
const versionParam = version === undefined ? "" : `&version=${version}`;
|
|
69
|
+
return `${base}/announcements/${announcementId}/${action}?platform=${platform}${versionParam}`;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const getEnhancedApi = (
|
|
73
|
+
api: AcknowledgeAnnouncementApi,
|
|
74
|
+
base: string
|
|
75
|
+
): AcknowledgeAnnouncementEnhancedApi => {
|
|
76
|
+
let byBase = enhancedApiCache.get(api);
|
|
77
|
+
if (!byBase) {
|
|
78
|
+
byBase = new Map();
|
|
79
|
+
enhancedApiCache.set(api, byBase);
|
|
80
|
+
}
|
|
81
|
+
const cached = byBase.get(base);
|
|
82
|
+
if (cached) {
|
|
83
|
+
return cached;
|
|
84
|
+
}
|
|
85
|
+
const apiWithTags = api.enhanceEndpoints({addTagTypes: ["PendingAnnouncements"]});
|
|
86
|
+
const enhanced = apiWithTags.injectEndpoints({
|
|
87
|
+
endpoints: (build) => ({
|
|
88
|
+
acknowledgeAnnouncement: build.mutation({
|
|
89
|
+
invalidatesTags: ["PendingAnnouncements"],
|
|
90
|
+
query: ({announcementId}: {announcementId: string}) => ({
|
|
91
|
+
method: "POST",
|
|
92
|
+
url: buildAnnouncementEventUrl(base, announcementId, "acknowledge"),
|
|
93
|
+
}),
|
|
94
|
+
}),
|
|
95
|
+
recordAnnouncementClick: build.mutation({
|
|
96
|
+
invalidatesTags: [],
|
|
97
|
+
query: ({announcementId}: {announcementId: string}) => ({
|
|
98
|
+
body: {
|
|
99
|
+
action: "primaryAction",
|
|
100
|
+
platform: getAnnouncementPlatform(),
|
|
101
|
+
},
|
|
102
|
+
method: "POST",
|
|
103
|
+
url: buildAnnouncementEventUrl(base, announcementId, "click"),
|
|
104
|
+
}),
|
|
105
|
+
}),
|
|
106
|
+
recordAnnouncementImpression: build.mutation({
|
|
107
|
+
invalidatesTags: [],
|
|
108
|
+
query: ({announcementId, platform}: {announcementId: string; platform?: string}) => ({
|
|
109
|
+
body: platform ? {platform} : undefined,
|
|
110
|
+
method: "POST",
|
|
111
|
+
url: `${base}/announcements/${announcementId}/impression`,
|
|
112
|
+
}),
|
|
113
|
+
}),
|
|
114
|
+
}),
|
|
115
|
+
overrideExisting: false,
|
|
116
|
+
});
|
|
117
|
+
byBase.set(base, enhanced);
|
|
118
|
+
return enhanced;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const useAcknowledgeAnnouncement = (api: AcknowledgeAnnouncementApi, baseUrl?: string) => {
|
|
122
|
+
const base = baseUrl || "";
|
|
123
|
+
const enhancedApi = getEnhancedApi(api, base);
|
|
124
|
+
|
|
125
|
+
const [acknowledgeMutation, {isLoading: isAcknowledging, error: acknowledgeError}] =
|
|
126
|
+
enhancedApi.useAcknowledgeAnnouncementMutation();
|
|
127
|
+
const [clickMutation, {isLoading: isRecordingClick, error: clickError}] =
|
|
128
|
+
enhancedApi.useRecordAnnouncementClickMutation();
|
|
129
|
+
const [impressionMutation, {isLoading: isRecordingImpression, error: impressionError}] =
|
|
130
|
+
enhancedApi.useRecordAnnouncementImpressionMutation();
|
|
131
|
+
|
|
132
|
+
const acknowledgeMutationRef = useRef(acknowledgeMutation);
|
|
133
|
+
acknowledgeMutationRef.current = acknowledgeMutation;
|
|
134
|
+
const clickMutationRef = useRef(clickMutation);
|
|
135
|
+
clickMutationRef.current = clickMutation;
|
|
136
|
+
const impressionMutationRef = useRef(impressionMutation);
|
|
137
|
+
impressionMutationRef.current = impressionMutation;
|
|
138
|
+
|
|
139
|
+
const acknowledge = useCallback(async (announcementId: string): Promise<void> => {
|
|
140
|
+
await acknowledgeMutationRef.current({announcementId}).unwrap();
|
|
141
|
+
}, []);
|
|
142
|
+
|
|
143
|
+
const recordClick = useCallback(async (announcementId: string): Promise<void> => {
|
|
144
|
+
await clickMutationRef.current({announcementId}).unwrap();
|
|
145
|
+
}, []);
|
|
146
|
+
|
|
147
|
+
const recordImpression = useCallback(async (announcementId: string): Promise<void> => {
|
|
148
|
+
await impressionMutationRef
|
|
149
|
+
.current({
|
|
150
|
+
announcementId,
|
|
151
|
+
platform: getAnnouncementPlatform(),
|
|
152
|
+
})
|
|
153
|
+
.unwrap();
|
|
154
|
+
}, []);
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
acknowledge,
|
|
158
|
+
error: acknowledgeError ?? clickError ?? impressionError,
|
|
159
|
+
isAcknowledging,
|
|
160
|
+
isRecordingClick,
|
|
161
|
+
isRecordingImpression,
|
|
162
|
+
isSubmitting: isAcknowledging || isRecordingClick || isRecordingImpression,
|
|
163
|
+
recordClick,
|
|
164
|
+
recordImpression,
|
|
165
|
+
};
|
|
166
|
+
};
|