@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.
@@ -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
  });
@@ -73,7 +73,7 @@ export const TableHeaderCell = ({
73
73
  style={{
74
74
  alignItems: "center",
75
75
  backgroundColor: theme.surface.primary,
76
- borderRadius: theme.radius.rounded as any,
76
+ borderRadius: theme.radius.rounded,
77
77
  height: 16,
78
78
  justifyContent: "center",
79
79
  width: 16,
@@ -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: any, baseUrl?: string) => {
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: any) => ({
81
+ endpoints: (build) => ({
47
82
  getPendingConsents: build.query({
48
- async onQueryStarted(_arg: unknown, {queryFulfilled}: {queryFulfilled: Promise<unknown>}) {
83
+ async onQueryStarted(_arg: unknown, {queryFulfilled}) {
49
84
  console.info("[useConsentForms] Fetching pending consent forms");
50
85
  try {
51
- const result = (await queryFulfilled) as {data?: ConsentFormPublic[]};
86
+ const result = await queryFulfilled;
52
87
  console.info("[useConsentForms] Pending consent forms fetched", {
53
88
  count: result?.data?.length ?? 0,
54
89
  });
@@ -20,11 +20,35 @@ export interface ConsentHistoryEntry {
20
20
  userAgent?: string;
21
21
  }
22
22
 
23
- export const useConsentHistory = (api: any, baseUrl?: string) => {
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: any) => ({
51
+ endpoints: (build) => ({
28
52
  getMyConsents: build.query({
29
53
  providesTags: ["MyConsents"],
30
54
  query: () => `${base}/consents/my`,
@@ -6,12 +6,48 @@ export interface SubmitConsentBody {
6
6
  signature?: string;
7
7
  }
8
8
 
9
- export const useSubmitConsent = (api: any, baseUrl?: string) => {
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: any) => ({
50
+ endpoints: (build) => ({
15
51
  submitConsentResponse: build.mutation({
16
52
  invalidatesTags: ["PendingConsents"],
17
53
  query: (body: SubmitConsentBody) => ({