@tsed/react-formio 1.11.2 → 1.12.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.
Files changed (141) hide show
  1. package/.env +2 -1
  2. package/craco.config.js +11 -1
  3. package/dist/components/alert/alert.component.spec.d.ts +1 -0
  4. package/dist/components/alert/alert.stories.d.ts +15 -0
  5. package/dist/components/form-action/formAction.stories.d.ts +90 -414
  6. package/dist/components/input-text/inputText.component.d.ts +1 -1
  7. package/dist/components/input-text/inputText.component.spec.d.ts +1 -0
  8. package/dist/components/select/select.component.spec.d.ts +1 -0
  9. package/dist/components/tabs/tabs.component.spec.d.ts +1 -0
  10. package/dist/index.js +60 -30
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.modern.js +59 -31
  13. package/dist/index.modern.js.map +1 -1
  14. package/jest.config.js +1 -1
  15. package/package.json +5 -9
  16. package/readme.md +74 -79
  17. package/src/components/__fixtures__/form-schema.json +10 -42
  18. package/src/components/__fixtures__/form.fixture.json +1 -1
  19. package/src/components/actions-table/actionsTable.component.spec.tsx +4 -13
  20. package/src/components/actions-table/actionsTable.component.tsx +3 -11
  21. package/src/components/alert/alert.component.spec.tsx +97 -0
  22. package/src/components/alert/alert.component.tsx +2 -8
  23. package/src/components/alert/alert.stories.tsx +17 -0
  24. package/src/components/card/card.component.tsx +1 -5
  25. package/src/components/form/form.component.tsx +1 -7
  26. package/src/components/form/useForm.hook.ts +4 -13
  27. package/src/components/form-access/formAccess.component.tsx +19 -82
  28. package/src/components/form-access/formAccess.schema.ts +7 -23
  29. package/src/components/form-access/formAccess.stories.tsx +2 -9
  30. package/src/components/form-access/formAccess.utils.spec.ts +4 -22
  31. package/src/components/form-access/formAccess.utils.ts +7 -29
  32. package/src/components/form-action/formAction.component.tsx +3 -19
  33. package/src/components/form-action/formAction.stories.tsx +251 -672
  34. package/src/components/form-builder/formBuilder.component.tsx +4 -13
  35. package/src/components/form-builder/formBuilder.stories.tsx +12 -24
  36. package/src/components/form-control/formControl.component.tsx +2 -8
  37. package/src/components/form-edit/formCtas.component.tsx +5 -23
  38. package/src/components/form-edit/formEdit.component.tsx +2 -20
  39. package/src/components/form-edit/formEdit.reducer.ts +2 -8
  40. package/src/components/form-edit/formEdit.stories.tsx +3 -15
  41. package/src/components/form-edit/formParameters.component.tsx +3 -20
  42. package/src/components/form-edit/useFormEdit.hook.ts +2 -9
  43. package/src/components/form-settings/formSettings.component.spec.tsx +2 -9
  44. package/src/components/form-settings/formSettings.component.tsx +6 -34
  45. package/src/components/form-settings/formSettings.stories.tsx +1 -6
  46. package/src/components/form-settings/formSettings.utils.spec.ts +1 -4
  47. package/src/components/form-settings/formSettings.utils.ts +2 -7
  48. package/src/components/forms-table/components/formCell.component.tsx +2 -6
  49. package/src/components/forms-table/formsTable.component.tsx +2 -7
  50. package/src/components/input-tags/inputTags.component.tsx +10 -34
  51. package/src/components/input-tags/inputTags.stories.tsx +4 -14
  52. package/src/components/input-text/inputText.component.spec.tsx +56 -0
  53. package/src/components/input-text/inputText.component.tsx +4 -5
  54. package/src/components/input-text/inputText.stories.tsx +6 -26
  55. package/src/components/loader/loader.component.tsx +2 -11
  56. package/src/components/modal/modal.component.spec.tsx +8 -14
  57. package/src/components/modal/modal.component.tsx +6 -27
  58. package/src/components/modal/modal.stories.tsx +1 -5
  59. package/src/components/modal/removeModal.component.tsx +4 -22
  60. package/src/components/pagination/pagination.component.spec.tsx +12 -38
  61. package/src/components/pagination/pagination.component.tsx +8 -41
  62. package/src/components/pagination/pagination.stories.tsx +1 -5
  63. package/src/components/react-component/reactComponent.component.tsx +3 -11
  64. package/src/components/select/select.component.spec.tsx +86 -0
  65. package/src/components/select/select.component.tsx +11 -15
  66. package/src/components/select/select.stories.tsx +6 -26
  67. package/src/components/submissions-table/submissionsTable.component.tsx +1 -3
  68. package/src/components/submissions-table/submissionsTable.stories.tsx +1 -1
  69. package/src/components/table/components/defaultArrowSort.component.tsx +1 -10
  70. package/src/components/table/components/defaultCell.component.tsx +1 -4
  71. package/src/components/table/components/defaultCellHeader.component.tsx +4 -14
  72. package/src/components/table/components/defaultCellOperations.component.tsx +14 -25
  73. package/src/components/table/components/defaultOperationButton.component.tsx +2 -10
  74. package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +1 -1
  75. package/src/components/table/filters/selectColumnFilter.component.spec.tsx +2 -10
  76. package/src/components/table/filters/selectColumnFilter.component.tsx +2 -6
  77. package/src/components/table/table.component.tsx +13 -53
  78. package/src/components/table/table.stories.tsx +1 -1
  79. package/src/components/table/utils/getPageNumbers.ts +3 -11
  80. package/src/components/table/utils/mapFormToColumns.tsx +14 -22
  81. package/src/components/table/utils/useOperations.hook.tsx +2 -12
  82. package/src/components/tabs/tabs.component.spec.tsx +86 -0
  83. package/src/components/tabs/tabs.component.stories.tsx +2 -9
  84. package/src/components/tabs/tabs.component.tsx +9 -43
  85. package/src/interfaces/Operation.ts +1 -4
  86. package/src/react-table.d.ts +9 -28
  87. package/src/stores/action/action.actions.ts +31 -33
  88. package/src/stores/action/action.reducers.spec.ts +1 -8
  89. package/src/stores/action/action.reducers.ts +1 -8
  90. package/src/stores/action/action.selectors.ts +1 -2
  91. package/src/stores/action-info/action-info.actions.spec.ts +1 -5
  92. package/src/stores/action-info/action-info.actions.ts +16 -19
  93. package/src/stores/action-info/action-info.reducers.spec.ts +1 -6
  94. package/src/stores/action-info/action-info.reducers.ts +1 -6
  95. package/src/stores/action-info/action-info.selectors.ts +1 -4
  96. package/src/stores/actions/actions.actions.spec.ts +1 -6
  97. package/src/stores/actions/actions.actions.ts +16 -19
  98. package/src/stores/actions/actions.reducers.spec.ts +1 -6
  99. package/src/stores/actions/actions.reducers.ts +1 -6
  100. package/src/stores/actions/actions.selectors.ts +2 -4
  101. package/src/stores/auth/auth.reducers.ts +1 -4
  102. package/src/stores/auth/auth.selectors.spec.ts +1 -5
  103. package/src/stores/auth/auth.selectors.ts +3 -6
  104. package/src/stores/auth/auth.utils.tsx +2 -8
  105. package/src/stores/auth/getAccess.action.spec.ts +11 -54
  106. package/src/stores/auth/getAccess.action.ts +1 -6
  107. package/src/stores/auth/initAuth.action.ts +15 -17
  108. package/src/stores/form/form.actions.spec.ts +8 -39
  109. package/src/stores/form/form.actions.ts +55 -64
  110. package/src/stores/form/form.reducers.spec.ts +1 -7
  111. package/src/stores/form/form.reducers.ts +1 -8
  112. package/src/stores/form/form.selectors.ts +1 -2
  113. package/src/stores/forms/forms.actions.spec.ts +5 -18
  114. package/src/stores/forms/forms.actions.ts +17 -21
  115. package/src/stores/forms/forms.reducers.spec.ts +1 -6
  116. package/src/stores/forms/forms.reducers.ts +2 -13
  117. package/src/stores/forms/forms.selectors.ts +2 -4
  118. package/src/stores/index.spec.ts +6 -9
  119. package/src/stores/root/root.selectors.spec.ts +1 -6
  120. package/src/stores/root/root.selectors.ts +6 -24
  121. package/src/stores/submission/submission.actions.spec.ts +11 -33
  122. package/src/stores/submission/submission.actions.ts +57 -66
  123. package/src/stores/submission/submission.reducers.spec.ts +17 -27
  124. package/src/stores/submission/submission.reducers.ts +1 -4
  125. package/src/stores/submission/submission.selectors.ts +1 -4
  126. package/src/stores/submissions/submissions.actions.spec.ts +5 -18
  127. package/src/stores/submissions/submissions.actions.ts +17 -26
  128. package/src/stores/submissions/submissions.reducers.spec.ts +3 -12
  129. package/src/stores/submissions/submissions.reducers.ts +3 -17
  130. package/src/stores/submissions/submissions.selectors.spec.ts +1 -4
  131. package/src/stores/submissions/submissions.selectors.ts +2 -4
  132. package/src/utils/getEventValue.ts +1 -4
  133. package/src/utils/iconClass.ts +2 -10
  134. package/src/utils/mapPagination.ts +1 -6
  135. package/src/utils/mapRequestParams.ts +2 -12
  136. package/src/utils/url.test.ts +4 -12
  137. package/src/utils/url.ts +2 -7
  138. package/tsconfig.json +4 -12
  139. package/tsconfig.test.json +1 -1
  140. package/.eslintrc +0 -47
  141. package/.prettierrc +0 -10
@@ -3,13 +3,13 @@ import { iconClass } from "../../utils/iconClass";
3
3
  import { InputTags } from "./inputTags.component";
4
4
 
5
5
  const useValue = (args: any) => {
6
- const [value, useValue] = useState(args.value);
6
+ const [value, setValue] = useState(args.value);
7
7
 
8
8
  return {
9
9
  ...args,
10
10
  value,
11
11
  onChange(name: string, value: any) {
12
- useValue(value);
12
+ setValue(value);
13
13
  args.onChange(name, value);
14
14
  }
15
15
  };
@@ -72,12 +72,7 @@ Sandbox.args = {
72
72
  };
73
73
 
74
74
  export const WithPrefix = (args: any) => {
75
- return (
76
- <InputTags
77
- prefix={<i className={iconClass(undefined, "calendar")} />}
78
- {...useValue(args)}
79
- />
80
- );
75
+ return <InputTags prefix={<i className={iconClass(undefined, "calendar")} />} {...useValue(args)} />;
81
76
  };
82
77
 
83
78
  WithPrefix.args = {
@@ -89,12 +84,7 @@ WithPrefix.args = {
89
84
  };
90
85
 
91
86
  export const WithSuffix = (args: any) => {
92
- return (
93
- <InputTags
94
- suffix={<i className={iconClass(undefined, "calendar")} />}
95
- {...useValue(args)}
96
- />
97
- );
87
+ return <InputTags suffix={<i className={iconClass(undefined, "calendar")} />} {...useValue(args)} />;
98
88
  };
99
89
 
100
90
  WithSuffix.args = {
@@ -0,0 +1,56 @@
1
+ import React from "react";
2
+ import { fireEvent, render } from "@testing-library/react";
3
+ import { Sandbox } from "./inputText.stories";
4
+
5
+ describe("input-text", () => {
6
+ it("should display the input-text component", () => {
7
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} name={"test"} />);
8
+ const input = getByTestId("input_test") as HTMLInputElement;
9
+
10
+ expect(input).toBeInTheDocument();
11
+ });
12
+
13
+ it("should display the input-text component with a different size", () => {
14
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} name={"test"} size='small' />);
15
+ const input = getByTestId("input_test") as HTMLInputElement;
16
+
17
+ expect(input).toBeInTheDocument();
18
+ expect(input).toHaveClass("form-control-small");
19
+ });
20
+
21
+ it("should display the input-text with placeholder", () => {
22
+ const placeholderTest = "placeholder test";
23
+
24
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} name={"test"} placeholder={placeholderTest} />);
25
+ const input = getByTestId("input_test") as HTMLInputElement;
26
+
27
+ expect(input).toBeInTheDocument();
28
+ expect(input).toHaveDisplayValue(placeholderTest);
29
+ });
30
+
31
+ it("should change the value of the input-text", () => {
32
+ const placeholderTest = "placeholder test";
33
+
34
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} name={"test"} placeholder={placeholderTest} />);
35
+ const input = getByTestId("input_test") as HTMLInputElement;
36
+
37
+ expect(input).toBeInTheDocument();
38
+ fireEvent.change(input, { target: { value: "newValue" } });
39
+ expect(input.value).toBe("newValue");
40
+ expect(input).not.toHaveDisplayValue(placeholderTest);
41
+ expect(input).toHaveDisplayValue("newValue");
42
+ });
43
+ it("should NOT change the value of the input-text if the value is NOT of type number", () => {
44
+ const placeholderTest = "placeholder test";
45
+
46
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} type='number' name={"test"} placeholder={placeholderTest} />);
47
+ const input = getByTestId("input_test") as HTMLInputElement;
48
+
49
+ expect(input).toBeInTheDocument();
50
+ fireEvent.change(input, { target: { value: "newValue" } });
51
+ expect(input).not.toHaveDisplayValue("newValue");
52
+ fireEvent.change(input, { target: { value: 1234 } });
53
+ expect(input.value).toBe("1234");
54
+ expect(input).toHaveDisplayValue("1234");
55
+ });
56
+ });
@@ -3,10 +3,7 @@ import PropTypes from "prop-types";
3
3
  import React, { useEffect, useMemo, useState } from "react";
4
4
  import { callLast } from "../../utils/callLast";
5
5
  import { getEventValue } from "../../utils/getEventValue";
6
- import {
7
- FormControl,
8
- FormControlProps
9
- } from "../form-control/formControl.component";
6
+ import { FormControl, FormControlProps } from "../form-control/formControl.component";
10
7
 
11
8
  export interface InputTextProps<T = any> extends FormControlProps {
12
9
  type?: string;
@@ -33,6 +30,7 @@ export function InputText<T = any>({
33
30
  suffix,
34
31
  description,
35
32
  className,
33
+ placeholder,
36
34
  ...props
37
35
  }: InputTextProps<T>) {
38
36
  const [localValue, setValue] = useState(value);
@@ -60,7 +58,8 @@ export function InputText<T = any>({
60
58
  className={classnames("form-control", size && `form-control-${size}`)}
61
59
  id={name}
62
60
  required={required}
63
- value={(localValue || "") as any}
61
+ value={(localValue || placeholder || "") as any}
62
+ placeholder={placeholder}
64
63
  onChange={(event) => {
65
64
  const value = getEventValue(event);
66
65
  setValue(value);
@@ -3,13 +3,13 @@ import { iconClass } from "../../utils/iconClass";
3
3
  import { InputText } from "./inputText.component";
4
4
 
5
5
  const useValue = (args: any) => {
6
- const [value, useValue] = useState(args.value);
6
+ const [value, setValue] = useState(args.value);
7
7
 
8
8
  return {
9
9
  ...args,
10
10
  value,
11
11
  onChange(name: string, value: any) {
12
- useValue(value);
12
+ setValue(value);
13
13
  args.onChange(name, value);
14
14
  }
15
15
  };
@@ -77,12 +77,7 @@ Sandbox.args = {
77
77
  };
78
78
 
79
79
  export const WithPrefix = (args: any) => {
80
- return (
81
- <InputText
82
- prefix={<i className={iconClass(undefined, "calendar")} />}
83
- {...useValue(args)}
84
- />
85
- );
80
+ return <InputText prefix={<i className={iconClass(undefined, "calendar")} />} {...useValue(args)} />;
86
81
  };
87
82
 
88
83
  WithPrefix.args = {
@@ -93,12 +88,7 @@ WithPrefix.args = {
93
88
  };
94
89
 
95
90
  export const WithSuffix = (args: any) => {
96
- return (
97
- <InputText
98
- suffix={<i className={iconClass(undefined, "calendar")} />}
99
- {...useValue(args)}
100
- />
101
- );
91
+ return <InputText suffix={<i className={iconClass(undefined, "calendar")} />} {...useValue(args)} />;
102
92
  };
103
93
 
104
94
  WithSuffix.args = {
@@ -109,12 +99,7 @@ WithSuffix.args = {
109
99
  };
110
100
 
111
101
  export const TypeNumber = (args: any) => {
112
- return (
113
- <InputText
114
- suffix={<i className={iconClass(undefined, "dollar")} />}
115
- {...useValue(args)}
116
- />
117
- );
102
+ return <InputText suffix={<i className={iconClass(undefined, "dollar")} />} {...useValue(args)} />;
118
103
  };
119
104
 
120
105
  TypeNumber.args = {
@@ -127,12 +112,7 @@ TypeNumber.args = {
127
112
  };
128
113
 
129
114
  export const Sizing = (args: any) => {
130
- return (
131
- <InputText
132
- suffix={<i className={iconClass(undefined, "dollar")} />}
133
- {...useValue(args)}
134
- />
135
- );
115
+ return <InputText suffix={<i className={iconClass(undefined, "dollar")} />} {...useValue(args)} />;
136
116
  };
137
117
 
138
118
  Sizing.args = {
@@ -10,12 +10,7 @@ export interface LoaderProps {
10
10
  className?: string;
11
11
  }
12
12
 
13
- export function Loader({
14
- isActive,
15
- color = "blue",
16
- icon = "radio-circle",
17
- className = ""
18
- }: PropsWithChildren<LoaderProps>) {
13
+ export function Loader({ isActive, color = "blue", icon = "radio-circle", className = "" }: PropsWithChildren<LoaderProps>) {
19
14
  if (isActive) {
20
15
  return (
21
16
  <div
@@ -24,11 +19,7 @@ export function Loader({
24
19
  className
25
20
  )}
26
21
  >
27
- <span
28
- data-testid={`icon_${icon}`}
29
- color={color}
30
- className={`text-11xl ${iconClass(undefined, icon, true)}`}
31
- />
22
+ <span data-testid={`icon_${icon}`} color={color} className={`text-11xl ${iconClass(undefined, icon, true)}`} />
32
23
  </div>
33
24
  );
34
25
  }
@@ -1,5 +1,5 @@
1
1
  import "@testing-library/jest-dom/extend-expect";
2
- import { fireEvent, render, screen, waitFor } from "@testing-library/react";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
3
  import React from "react";
4
4
  import { WithFooter, WithTitle } from "./modal.stories";
5
5
 
@@ -8,9 +8,7 @@ describe("Modal", () => {
8
8
  it("should display the modal when we click on the button", async () => {
9
9
  const onClose = jest.fn();
10
10
 
11
- const { queryByTestId, getByTestId } = render(
12
- <WithTitle {...WithTitle.args} onClose={onClose} />
13
- );
11
+ const { queryByTestId, getByTestId, findByTestId } = render(<WithTitle {...WithTitle.args} onClose={onClose} />);
14
12
 
15
13
  expect(queryByTestId("modalTitle")).toBeFalsy();
16
14
  expect(queryByTestId("modalBody")).toBeFalsy();
@@ -18,7 +16,7 @@ describe("Modal", () => {
18
16
 
19
17
  fireEvent.click(screen.getByRole("button", { name: "Open modal" }));
20
18
 
21
- await waitFor(() => getByTestId("modalTitle"));
19
+ await findByTestId("modalTitle");
22
20
 
23
21
  expect(getByTestId("modalTitle")).toBeTruthy();
24
22
  expect(getByTestId("modalTitle")).toHaveTextContent("Modal title");
@@ -37,9 +35,7 @@ describe("Modal", () => {
37
35
 
38
36
  describe("WithFooter", () => {
39
37
  it("should display the modal when we click on the button", async () => {
40
- const { getByRole, queryByTestId, getByTestId } = render(
41
- <WithFooter {...WithFooter.args} />
42
- );
38
+ const { getByRole, queryByTestId, getByTestId, findByTestId } = render(<WithFooter {...WithFooter.args} />);
43
39
 
44
40
  expect(queryByTestId("modalTitle")).toBeFalsy();
45
41
  expect(queryByTestId("modalBody")).toBeFalsy();
@@ -47,13 +43,13 @@ describe("Modal", () => {
47
43
 
48
44
  fireEvent.click(getByRole("button", { name: "Open modal" }));
49
45
 
50
- await waitFor(() => getByTestId("modalTitle"));
46
+ await findByTestId("modalTitle");
51
47
 
52
48
  expect(getByTestId("modalTitle")).toBeTruthy();
53
49
  expect(getByTestId("modalTitle")).toHaveTextContent("Modal title");
54
50
  expect(getByTestId("modalBody")).toBeTruthy();
55
51
  expect(getByTestId("modalBody")).toHaveTextContent("Hello body");
56
- expect(queryByTestId("modalFooter")).toBeTruthy();
52
+ expect(getByTestId("modalFooter")).toBeTruthy();
57
53
 
58
54
  fireEvent.click(screen.getByTestId("customCloseModal"));
59
55
 
@@ -63,13 +59,11 @@ describe("Modal", () => {
63
59
  });
64
60
  it("should call the onSubmit listener", async () => {
65
61
  const onSubmit = jest.fn();
66
- const { getByRole, queryByTestId, getByTestId } = render(
67
- <WithFooter {...WithFooter.args} onSubmit={onSubmit} />
68
- );
62
+ const { getByRole, queryByTestId, findByTestId } = render(<WithFooter {...WithFooter.args} onSubmit={onSubmit} />);
69
63
 
70
64
  fireEvent.click(getByRole("button", { name: "Open modal" }));
71
65
 
72
- await waitFor(() => getByTestId("modalTitle"));
66
+ await findByTestId("modalTitle");
73
67
 
74
68
  fireEvent.click(screen.getByTestId("customSubmitModal"));
75
69
 
@@ -48,9 +48,7 @@ export function Modal({
48
48
 
49
49
  useEffect(() => {
50
50
  if (titleRef.current || footerRef.current) {
51
- const height =
52
- (titleRef?.current?.offsetHeight || 0) +
53
- (footerRef?.current?.offsetHeight || 0);
51
+ const height = (titleRef?.current?.offsetHeight || 0) + (footerRef?.current?.offsetHeight || 0);
54
52
 
55
53
  setMaxHeight(`calc(85vh - ${height}px)`);
56
54
  } else {
@@ -63,42 +61,23 @@ export function Modal({
63
61
  }
64
62
 
65
63
  return (
66
- <div
67
- role={"dialog"}
68
- className={`formio-dialog formio-dialog-theme-default ${className}`}
69
- >
64
+ <div role={"dialog"} className={`formio-dialog formio-dialog-theme-default ${className}`}>
70
65
  <div className='formio-dialog-overlay' onClick={onClickClose} />
71
66
  <div style={style} className={"formio-dialog-content"}>
72
67
  <div className={"formio-dialog-wrapper"}>
73
68
  {title ? (
74
- <div
75
- className={"formio-dialog-title"}
76
- ref={titleRef}
77
- data-testid={"modalTitle"}
78
- >
69
+ <div className={"formio-dialog-title"} ref={titleRef} data-testid={"modalTitle"}>
79
70
  {title}
80
71
  </div>
81
72
  ) : null}
82
73
 
83
- <div
84
- className='formio-dialog-body'
85
- style={{ maxHeight }}
86
- data-testid={"modalBody"}
87
- >
74
+ <div className='formio-dialog-body' style={{ maxHeight }} data-testid={"modalBody"}>
88
75
  {show && children}
89
76
  </div>
90
77
 
91
78
  {ModalFooter ? (
92
- <div
93
- className={"formio-dialog-footer"}
94
- ref={footerRef}
95
- data-testid={"modalFooter"}
96
- >
97
- <ModalFooter
98
- {...props}
99
- closeModal={closeModal}
100
- onClose={onClickClose}
101
- />
79
+ <div className={"formio-dialog-footer"} ref={footerRef} data-testid={"modalFooter"}>
80
+ <ModalFooter {...props} closeModal={closeModal} onClose={onClickClose} />
102
81
  </div>
103
82
  ) : null}
104
83
  </div>
@@ -81,11 +81,7 @@ export const WithFooter = (args: ModalProps) => {
81
81
  Save
82
82
  </button>
83
83
 
84
- <button
85
- data-testid='customCloseModal'
86
- className={"btn btn-danger mx-1"}
87
- onClick={closeModal}
88
- >
84
+ <button data-testid='customCloseModal' className={"btn btn-danger mx-1"} onClick={closeModal}>
89
85
  Close
90
86
  </button>
91
87
  </div>
@@ -5,20 +5,10 @@ import { iconClass } from "../../utils/iconClass";
5
5
  import { InputText } from "../input-text/inputText.component";
6
6
  import { Modal, ModalProps } from "./modal.component";
7
7
 
8
- function RemoveModalFooter({
9
- value,
10
- valueToCompare,
11
- onSubmit,
12
- onClose,
13
- i18n = (f: string) => f
14
- }: ModalProps) {
8
+ function RemoveModalFooter({ value, valueToCompare, onSubmit, onClose, i18n = (f: string) => f }: ModalProps) {
15
9
  return (
16
10
  <div className={"flex items-center justify-center bg-white p-2"}>
17
- <button
18
- data-testid='customCloseModal'
19
- className={"btn btn-outline-dark mx-2"}
20
- onClick={onClose}
21
- >
11
+ <button data-testid='customCloseModal' className={"btn btn-outline-dark mx-2"} onClick={onClose}>
22
12
  {i18n("Cancel")}
23
13
  </button>
24
14
  <button
@@ -45,11 +35,7 @@ export interface RemoveModalProps extends ModalProps {
45
35
  maxWidth?: string;
46
36
  }
47
37
 
48
- export function RemoveModal({
49
- maxWidth = "300px",
50
- children,
51
- ...props
52
- }: PropsWithChildren<RemoveModalProps>) {
38
+ export function RemoveModal({ maxWidth = "300px", children, ...props }: PropsWithChildren<RemoveModalProps>) {
53
39
  const { i18n = noop } = props;
54
40
  const [value, setValue] = useState();
55
41
 
@@ -70,11 +56,7 @@ export function RemoveModal({
70
56
  <strong>&quot;{props.itemType?.toLowerCase()}&quot;</strong>&nbsp;
71
57
  {i18n("name")} <strong>&quot;{props.valueToCompare}&quot;</strong>.
72
58
  </div>
73
- <InputText
74
- name='remove'
75
- value={value}
76
- onChange={(name, value) => setValue(value)}
77
- />
59
+ <InputText name='remove' value={value} onChange={(name, value) => setValue(value)} />
78
60
  </div>
79
61
  </Modal>
80
62
  );
@@ -4,9 +4,7 @@ import { Sandbox } from "./pagination.stories";
4
4
 
5
5
  describe("Pagination", () => {
6
6
  it("should render the pagination component", () => {
7
- const { container, getByTestId, queryAllByTestId } = render(
8
- <Sandbox {...Sandbox.args} />
9
- );
7
+ const { container, getByTestId, queryAllByTestId } = render(<Sandbox {...Sandbox.args} />);
10
8
  const paginationBtn = queryAllByTestId("pagination-button");
11
9
  const allBtnBlocks = paginationBtn.map((bloc) => bloc.textContent);
12
10
  const select = getByTestId("select_page");
@@ -20,13 +18,9 @@ describe("Pagination", () => {
20
18
 
21
19
  it("should call previousPage() callback", () => {
22
20
  const previousPageSpy = jest.fn();
23
- const { queryAllByTestId } = render(
24
- <Sandbox previousPage={previousPageSpy} canPreviousPage={true} />
25
- );
21
+ const { queryAllByTestId } = render(<Sandbox previousPage={previousPageSpy} canPreviousPage={true} />);
26
22
  const paginationBtn = queryAllByTestId("pagination-button");
27
- const btnPreviousPage = paginationBtn.find(
28
- (btn) => btn.textContent === "Previous"
29
- );
23
+ const btnPreviousPage = paginationBtn.find((btn) => btn.textContent === "Previous");
30
24
 
31
25
  fireEvent.click(btnPreviousPage);
32
26
 
@@ -46,19 +40,17 @@ describe("Pagination", () => {
46
40
  const gotoPageSpy = jest.fn();
47
41
  let page: number;
48
42
 
49
- const { queryAllByTestId } = render(
50
- <Sandbox {...Sandbox.args} gotoPage={gotoPageSpy} />
51
- );
43
+ const { queryAllByTestId } = render(<Sandbox {...Sandbox.args} gotoPage={gotoPageSpy} />);
52
44
  const paginationBtn = queryAllByTestId("pagination-button");
53
- const buttonsPage = paginationBtn.filter(
54
- (btn) => btn.textContent !== "Previous" && btn.textContent !== "Next"
55
- );
45
+ const buttonsPage = paginationBtn.filter((btn) => btn.textContent !== "Previous" && btn.textContent !== "Next");
56
46
 
57
47
  buttonsPage.forEach((btn) => {
58
48
  if (btn.textContent !== "...") {
59
49
  page = +btn.textContent;
60
50
  fireEvent.click(btn);
51
+ // eslint-disable-next-line jest/no-conditional-expect
61
52
  expect(gotoPageSpy).toHaveBeenCalled();
53
+ // eslint-disable-next-line jest/no-conditional-expect
62
54
  expect(gotoPageSpy).toHaveBeenCalledWith(page - 1);
63
55
  }
64
56
  });
@@ -66,13 +58,7 @@ describe("Pagination", () => {
66
58
 
67
59
  it("should have Previous button disabled and not clickable", () => {
68
60
  const previousPageSpy = jest.fn();
69
- const { getByText } = render(
70
- <Sandbox
71
- canPreviousPage={false}
72
- previousPage={previousPageSpy}
73
- {...Sandbox.args}
74
- />
75
- );
61
+ const { getByText } = render(<Sandbox canPreviousPage={false} previousPage={previousPageSpy} {...Sandbox.args} />);
76
62
  const previousButton = getByText("Previous");
77
63
 
78
64
  expect(previousButton).toHaveAttribute("disabled");
@@ -82,13 +68,7 @@ describe("Pagination", () => {
82
68
 
83
69
  it("should have Previous button NOT disabled and clickable", () => {
84
70
  const previousPageSpy = jest.fn();
85
- const { getByText } = render(
86
- <Sandbox
87
- {...Sandbox.args}
88
- canPreviousPage={true}
89
- previousPage={previousPageSpy}
90
- />
91
- );
71
+ const { getByText } = render(<Sandbox {...Sandbox.args} canPreviousPage={true} previousPage={previousPageSpy} />);
92
72
 
93
73
  const previousButton = getByText("Previous");
94
74
 
@@ -99,9 +79,7 @@ describe("Pagination", () => {
99
79
 
100
80
  it("should have Next button disabled and not clickable", () => {
101
81
  const nextPageSpy = jest.fn();
102
- const { getByText } = render(
103
- <Sandbox canNextPage={false} nextPage={nextPageSpy} {...Sandbox.args} />
104
- );
82
+ const { getByText } = render(<Sandbox canNextPage={false} nextPage={nextPageSpy} {...Sandbox.args} />);
105
83
 
106
84
  const nextButton = getByText("Next");
107
85
  expect(nextButton).toHaveAttribute("disabled");
@@ -111,9 +89,7 @@ describe("Pagination", () => {
111
89
 
112
90
  it("should have Next button NOT disabled and clickable", () => {
113
91
  const nextPageSpy = jest.fn();
114
- const { getByText } = render(
115
- <Sandbox canNextPage={true} nextPage={nextPageSpy} {...Sandbox.args} />
116
- );
92
+ const { getByText } = render(<Sandbox canNextPage={true} nextPage={nextPageSpy} {...Sandbox.args} />);
117
93
  const nextButton = getByText("Next");
118
94
  expect(nextButton).not.toHaveAttribute("disabled");
119
95
  fireEvent.click(nextButton);
@@ -123,9 +99,7 @@ describe("Pagination", () => {
123
99
  it("should correctly render select component", () => {
124
100
  const pageSizes = [10, 25, 50, 100, 200, 500];
125
101
 
126
- const { getByTestId } = render(
127
- <Sandbox {...Sandbox.args} pageSizes={pageSizes} />
128
- );
102
+ const { getByTestId } = render(<Sandbox {...Sandbox.args} pageSizes={pageSizes} />);
129
103
  const selectComp = getByTestId("select_page");
130
104
  const selectChilds = Array.prototype.map.call(selectComp, function (child) {
131
105
  return +child.textContent;
@@ -1,11 +1,7 @@
1
1
  import classnames from "classnames";
2
2
  import React, { PropsWithChildren } from "react";
3
3
  import { Select } from "../select/select.component";
4
- import {
5
- getPageNumbers,
6
- LEFT_PAGE,
7
- RIGHT_PAGE
8
- } from "../table/utils/getPageNumbers";
4
+ import { getPageNumbers, LEFT_PAGE, RIGHT_PAGE } from "../table/utils/getPageNumbers";
9
5
 
10
6
  function PaginationButton(
11
7
  props: PropsWithChildren<
@@ -17,25 +13,14 @@ function PaginationButton(
17
13
  } & Record<string, any>
18
14
  >
19
15
  ) {
20
- const {
21
- component: Component = "button",
22
- children,
23
- disabled,
24
- active,
25
- ...otherProps
26
- } = props;
16
+ const { component: Component = "button", children, disabled, active, ...otherProps } = props;
27
17
 
28
18
  return (
29
19
  <Component
30
20
  {...otherProps}
31
21
  data-testid='pagination-button'
32
22
  disabled={disabled}
33
- className={classnames(
34
- "page-link",
35
- disabled ? "disabled" : "",
36
- active ? "" : "",
37
- props.className
38
- )}
23
+ className={classnames("page-link", disabled ? "disabled" : "", active ? "" : "", props.className)}
39
24
  >
40
25
  {children}
41
26
  </Component>
@@ -83,17 +68,10 @@ export function Pagination(props: PaginationProps) {
83
68
  const choices: any[] = pageSizes.map((value) => ({ value, label: value }));
84
69
 
85
70
  return (
86
- <nav
87
- aria-label='Page navigation'
88
- className={classnames("pagination-group -mb-3", className)}
89
- >
71
+ <nav aria-label='Page navigation' className={classnames("pagination-group -mb-3", className)}>
90
72
  <ul className='pagination mb-3 mr-3'>
91
73
  <li className={classnames("page-item", !canPreviousPage && "disabled")}>
92
- <PaginationButton
93
- tabIndex={-1}
94
- disabled={!canPreviousPage}
95
- onClick={() => previousPage()}
96
- >
74
+ <PaginationButton tabIndex={-1} disabled={!canPreviousPage} onClick={() => previousPage()}>
97
75
  {i18n("Previous")}
98
76
  </PaginationButton>
99
77
  </li>
@@ -109,15 +87,8 @@ export function Pagination(props: PaginationProps) {
109
87
 
110
88
  const active = page - 1 === pageIndex;
111
89
  return (
112
- <li
113
- className={classnames("page-item", active && "active")}
114
- key={page}
115
- >
116
- <PaginationButton
117
- tabIndex={pageIndex}
118
- active={active}
119
- onClick={() => gotoPage(page - 1)}
120
- >
90
+ <li className={classnames("page-item", active && "active")} key={page}>
91
+ <PaginationButton tabIndex={pageIndex} active={active} onClick={() => gotoPage(page - 1)}>
121
92
  {page}
122
93
  </PaginationButton>
123
94
  </li>
@@ -125,11 +96,7 @@ export function Pagination(props: PaginationProps) {
125
96
  })}
126
97
 
127
98
  <li className={classnames("page-item", !canNextPage && "disabled")}>
128
- <PaginationButton
129
- tabIndex={pageNumbers.length}
130
- disabled={!canNextPage}
131
- onClick={() => nextPage()}
132
- >
99
+ <PaginationButton tabIndex={pageNumbers.length} disabled={!canNextPage} onClick={() => nextPage()}>
133
100
  {i18n("Next")}
134
101
  </PaginationButton>
135
102
  </li>
@@ -17,11 +17,7 @@ export const Sandbox = (args: any) => {
17
17
 
18
18
  return (
19
19
  <div>
20
- <Pagination
21
- {...args}
22
- pageIndex={currentPageIndex}
23
- gotoPage={setPageIndex}
24
- />
20
+ <Pagination {...args} pageIndex={currentPageIndex} gotoPage={setPageIndex} />
25
21
  </div>
26
22
  );
27
23
  };
@@ -15,11 +15,7 @@ export class ReactComponent<Data = any> extends Components.components.field {
15
15
  * @param data - The submission data where this component's data exists.
16
16
  */
17
17
  // eslint-disable-next-line no-useless-constructor
18
- constructor(
19
- component: ComponentSchema,
20
- options: any,
21
- data: Submission<Data>
22
- ) {
18
+ constructor(component: ComponentSchema, options: any, data: Submission<Data>) {
23
19
  super(component, options, data);
24
20
  }
25
21
 
@@ -150,13 +146,9 @@ export class ReactComponent<Data = any> extends Components.components.field {
150
146
  updateValue = (value?: Data, flags?: Record<string, any>) => {
151
147
  flags = flags || {};
152
148
 
153
- const newValue =
154
- value === undefined || value === null ? this.getValue() : value;
149
+ const newValue = value === undefined || value === null ? this.getValue() : value;
155
150
 
156
- const changed =
157
- newValue !== undefined
158
- ? this.hasChanged(newValue, this.dataValue)
159
- : false;
151
+ const changed = newValue !== undefined ? this.hasChanged(newValue, this.dataValue) : false;
160
152
 
161
153
  this.dataValue = Array.isArray(newValue) ? [...newValue] : newValue;
162
154