@terreno/ui 0.9.2 → 0.10.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/Common.d.ts +6 -10
- package/dist/Common.js.map +1 -1
- package/dist/ConsentHistory.d.ts +2 -1
- package/dist/DataTable.js +4 -2
- package/dist/DataTable.js.map +1 -1
- package/dist/DateUtilities.js +16 -7
- package/dist/DateUtilities.js.map +1 -1
- package/dist/DraggableList.d.ts +5 -4
- package/dist/DraggableList.js.map +1 -1
- package/dist/Icon.js +0 -3
- package/dist/Icon.js.map +1 -1
- package/dist/PasswordField.d.ts +1 -1
- package/dist/PasswordField.js.map +1 -1
- package/dist/table/TableHeaderCell.js.map +1 -1
- package/dist/useConsentForms.d.ts +38 -4
- package/dist/useConsentForms.js +1 -1
- package/dist/useConsentForms.js.map +1 -1
- package/dist/useConsentHistory.d.ts +30 -4
- package/dist/useConsentHistory.js.map +1 -1
- package/dist/useSubmitConsent.d.ts +40 -4
- package/dist/useSubmitConsent.js.map +1 -1
- package/package.json +4 -1
- package/src/Common.ts +11 -9
- package/src/ConsentHistory.tsx +1 -1
- package/src/ConsentNavigator.test.tsx +4 -4
- package/src/DataTable.tsx +15 -15
- package/src/DateUtilities.test.ts +34 -16
- package/src/DateUtilities.tsx +24 -13
- package/src/DraggableList.tsx +5 -5
- package/src/ErrorBoundary.test.tsx +52 -1
- package/src/Icon.tsx +0 -3
- package/src/OpenAPIContext.test.tsx +184 -3
- package/src/PasswordField.tsx +1 -1
- package/src/table/TableBadge.test.tsx +36 -0
- package/src/table/TableHeaderCell.tsx +1 -1
- package/src/useConsentForms.ts +39 -4
- package/src/useConsentHistory.ts +26 -2
- package/src/useSubmitConsent.ts +38 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import {fireEvent} from "@testing-library/react-native";
|
|
2
3
|
import {renderWithTheme} from "../test-utils";
|
|
3
4
|
import {TableBadge} from "./TableBadge";
|
|
4
5
|
|
|
@@ -50,4 +51,39 @@ describe("TableBadge", () => {
|
|
|
50
51
|
);
|
|
51
52
|
expect(toJSON()).toMatchSnapshot();
|
|
52
53
|
});
|
|
54
|
+
|
|
55
|
+
it("renders badge when editing is enabled but options are missing", () => {
|
|
56
|
+
const {getByText, queryByTestId} = renderWithTheme(<TableBadge isEditing value="Pending" />);
|
|
57
|
+
expect(getByText("Pending")).toBeTruthy();
|
|
58
|
+
expect(queryByTestId("ios_picker")).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("updates selected value when select field changes to a non-empty option", () => {
|
|
62
|
+
const editingOptions = [
|
|
63
|
+
{label: "Option A", value: "a"},
|
|
64
|
+
{label: "Option B", value: "b"},
|
|
65
|
+
];
|
|
66
|
+
const {getByTestId} = renderWithTheme(
|
|
67
|
+
<TableBadge editingOptions={editingOptions} isEditing value="a" />
|
|
68
|
+
);
|
|
69
|
+
const picker = getByTestId("ios_picker");
|
|
70
|
+
|
|
71
|
+
expect(picker.props.selectedValue).toBe("a");
|
|
72
|
+
fireEvent(picker, "onValueChange", "b", 2);
|
|
73
|
+
expect(getByTestId("ios_picker").props.selectedValue).toBe("b");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("clears selected value when select field changes to an empty value", () => {
|
|
77
|
+
const editingOptions = [
|
|
78
|
+
{label: "Option A", value: "a"},
|
|
79
|
+
{label: "Option B", value: "b"},
|
|
80
|
+
];
|
|
81
|
+
const {getByTestId} = renderWithTheme(
|
|
82
|
+
<TableBadge editingOptions={editingOptions} isEditing value="a" />
|
|
83
|
+
);
|
|
84
|
+
const picker = getByTestId("ios_picker");
|
|
85
|
+
|
|
86
|
+
fireEvent(picker, "onValueChange", "", 0);
|
|
87
|
+
expect(getByTestId("ios_picker").props.selectedValue).toBe("");
|
|
88
|
+
});
|
|
53
89
|
});
|
package/src/useConsentForms.ts
CHANGED
|
@@ -19,6 +19,41 @@ export interface ConsentFormPublic {
|
|
|
19
19
|
|
|
20
20
|
import {getLocales} from "expo-localization";
|
|
21
21
|
|
|
22
|
+
interface ConsentFormsResponse {
|
|
23
|
+
data?: ConsentFormPublic[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface ConsentFormsQueryBuilder {
|
|
27
|
+
query: (options: {
|
|
28
|
+
onQueryStarted?: (
|
|
29
|
+
_arg: unknown,
|
|
30
|
+
helpers: {queryFulfilled: Promise<ConsentFormsResponse>}
|
|
31
|
+
) => Promise<void>;
|
|
32
|
+
providesTags: string[];
|
|
33
|
+
query: () => string;
|
|
34
|
+
}) => unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface ConsentFormsHookState {
|
|
38
|
+
data?: ConsentFormPublic[] | ConsentFormsResponse;
|
|
39
|
+
error: unknown;
|
|
40
|
+
isLoading: boolean;
|
|
41
|
+
refetch: () => void | Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface ConsentFormsApiWithTags {
|
|
45
|
+
injectEndpoints: (options: {
|
|
46
|
+
endpoints: (build: ConsentFormsQueryBuilder) => {getPendingConsents: unknown};
|
|
47
|
+
overrideExisting: boolean;
|
|
48
|
+
}) => {
|
|
49
|
+
useGetPendingConsentsQuery: () => ConsentFormsHookState;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface ConsentFormsApi {
|
|
54
|
+
enhanceEndpoints: (options: {addTagTypes: string[]}) => ConsentFormsApiWithTags;
|
|
55
|
+
}
|
|
56
|
+
|
|
22
57
|
export const detectLocale = (): string => {
|
|
23
58
|
// Web
|
|
24
59
|
if (typeof navigator !== "undefined" && navigator.language) {
|
|
@@ -38,17 +73,17 @@ export const detectLocale = (): string => {
|
|
|
38
73
|
return "en";
|
|
39
74
|
};
|
|
40
75
|
|
|
41
|
-
export const useConsentForms = (api:
|
|
76
|
+
export const useConsentForms = (api: ConsentFormsApi, baseUrl?: string) => {
|
|
42
77
|
const base = baseUrl || "";
|
|
43
78
|
const apiWithConsentTags = api.enhanceEndpoints({addTagTypes: ["PendingConsents"]});
|
|
44
79
|
|
|
45
80
|
const enhancedApi = apiWithConsentTags.injectEndpoints({
|
|
46
|
-
endpoints: (build
|
|
81
|
+
endpoints: (build) => ({
|
|
47
82
|
getPendingConsents: build.query({
|
|
48
|
-
async onQueryStarted(_arg: unknown, {queryFulfilled}
|
|
83
|
+
async onQueryStarted(_arg: unknown, {queryFulfilled}) {
|
|
49
84
|
console.info("[useConsentForms] Fetching pending consent forms");
|
|
50
85
|
try {
|
|
51
|
-
const result =
|
|
86
|
+
const result = await queryFulfilled;
|
|
52
87
|
console.info("[useConsentForms] Pending consent forms fetched", {
|
|
53
88
|
count: result?.data?.length ?? 0,
|
|
54
89
|
});
|
package/src/useConsentHistory.ts
CHANGED
|
@@ -20,11 +20,35 @@ export interface ConsentHistoryEntry {
|
|
|
20
20
|
userAgent?: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
interface ConsentHistoryResponse {
|
|
24
|
+
data?: ConsentHistoryEntry[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ConsentHistoryQueryBuilder {
|
|
28
|
+
query: (options: {providesTags: string[]; query: () => string}) => unknown;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ConsentHistoryHookState {
|
|
32
|
+
data?: ConsentHistoryEntry[] | ConsentHistoryResponse;
|
|
33
|
+
error: unknown;
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
refetch: () => void | Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface ConsentHistoryApi {
|
|
39
|
+
injectEndpoints: (options: {
|
|
40
|
+
endpoints: (build: ConsentHistoryQueryBuilder) => {getMyConsents: unknown};
|
|
41
|
+
overrideExisting: boolean;
|
|
42
|
+
}) => {
|
|
43
|
+
useGetMyConsentsQuery: () => ConsentHistoryHookState;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const useConsentHistory = (api: ConsentHistoryApi, baseUrl?: string) => {
|
|
24
48
|
const base = baseUrl || "";
|
|
25
49
|
|
|
26
50
|
const enhancedApi = api.injectEndpoints({
|
|
27
|
-
endpoints: (build
|
|
51
|
+
endpoints: (build) => ({
|
|
28
52
|
getMyConsents: build.query({
|
|
29
53
|
providesTags: ["MyConsents"],
|
|
30
54
|
query: () => `${base}/consents/my`,
|
package/src/useSubmitConsent.ts
CHANGED
|
@@ -6,12 +6,48 @@ export interface SubmitConsentBody {
|
|
|
6
6
|
signature?: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
interface SubmitConsentMutationResult {
|
|
10
|
+
unwrap: () => Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface SubmitConsentMutationHookState {
|
|
14
|
+
error: unknown;
|
|
15
|
+
isLoading: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface SubmitConsentMutationBuilder {
|
|
19
|
+
mutation: (options: {
|
|
20
|
+
invalidatesTags: string[];
|
|
21
|
+
query: (body: SubmitConsentBody) => {
|
|
22
|
+
body: SubmitConsentBody;
|
|
23
|
+
method: "POST";
|
|
24
|
+
url: string;
|
|
25
|
+
};
|
|
26
|
+
}) => unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface SubmitConsentApiWithTags {
|
|
30
|
+
injectEndpoints: (options: {
|
|
31
|
+
endpoints: (build: SubmitConsentMutationBuilder) => {submitConsentResponse: unknown};
|
|
32
|
+
overrideExisting: boolean;
|
|
33
|
+
}) => {
|
|
34
|
+
useSubmitConsentResponseMutation: () => [
|
|
35
|
+
(body: SubmitConsentBody) => SubmitConsentMutationResult,
|
|
36
|
+
SubmitConsentMutationHookState,
|
|
37
|
+
];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface SubmitConsentApi {
|
|
42
|
+
enhanceEndpoints: (options: {addTagTypes: string[]}) => SubmitConsentApiWithTags;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const useSubmitConsent = (api: SubmitConsentApi, baseUrl?: string) => {
|
|
10
46
|
const base = baseUrl || "";
|
|
11
47
|
const apiWithConsentTags = api.enhanceEndpoints({addTagTypes: ["PendingConsents"]});
|
|
12
48
|
|
|
13
49
|
const enhancedApi = apiWithConsentTags.injectEndpoints({
|
|
14
|
-
endpoints: (build
|
|
50
|
+
endpoints: (build) => ({
|
|
15
51
|
submitConsentResponse: build.mutation({
|
|
16
52
|
invalidatesTags: ["PendingConsents"],
|
|
17
53
|
query: (body: SubmitConsentBody) => ({
|