@tsed/react-formio 1.10.9 → 1.10.13

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 (38) hide show
  1. package/.eslintrc +7 -2
  2. package/dist/components/form/form.component.d.ts +2 -44
  3. package/dist/components/form/useForm.hook.d.ts +56 -1
  4. package/dist/components/form-action/formAction.component.d.ts +1 -1
  5. package/dist/components/form-edit/formEdit.component.d.ts +4 -15
  6. package/dist/components/form-edit/useFormEdit.hook.d.ts +29 -0
  7. package/dist/index.js +47 -13323
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.modern.js +35 -13143
  10. package/dist/index.modern.js.map +1 -1
  11. package/package.json +13 -12
  12. package/readme.md +81 -55
  13. package/src/components/actions-table/actionsTable.component.spec.tsx +15 -17
  14. package/src/components/actions-table/actionsTable.component.tsx +1 -0
  15. package/src/components/card/card.component.spec.tsx +2 -2
  16. package/src/components/card/card.component.tsx +2 -4
  17. package/src/components/form/form.component.tsx +3 -47
  18. package/src/components/form/useForm.hook.ts +62 -8
  19. package/src/components/form-access/formAccess.component.tsx +2 -1
  20. package/src/components/form-action/formAction.component.tsx +1 -1
  21. package/src/components/form-builder/formBuilder.component.tsx +2 -0
  22. package/src/components/form-edit/formEdit.component.tsx +5 -11
  23. package/src/components/form-edit/{useForm.hook.ts → useFormEdit.hook.ts} +8 -14
  24. package/src/components/form-settings/formSettings.component.tsx +3 -1
  25. package/src/components/forms-table/components/formCell.component.tsx +2 -2
  26. package/src/components/input-text/inputText.component.tsx +1 -1
  27. package/src/components/loader/loader.component.spec.tsx +2 -2
  28. package/src/components/loader/loader.component.tsx +1 -1
  29. package/src/components/modal/modal.component.spec.tsx +3 -3
  30. package/src/components/modal/modal.component.tsx +6 -1
  31. package/src/components/modal/modal.stories.tsx +5 -21
  32. package/src/components/react-component/reactComponent.component.tsx +1 -0
  33. package/src/components/select/select.component.tsx +1 -1
  34. package/src/components/table/components/defaultOperationButton.component.tsx +2 -2
  35. package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +2 -2
  36. package/src/components/table/table.component.tsx +16 -5
  37. package/src/components/tabs/tabs.component.stories.tsx +1 -1
  38. package/dist/components/form-edit/useForm.hook.d.ts +0 -16
@@ -1,7 +1,7 @@
1
1
  import React, { useCallback, useEffect, useState } from "react";
2
2
  import { FormOptions, FormSchema } from "../../interfaces";
3
3
  import { getFormSettingsSchema } from "./formSettings.schema";
4
- import { ChangedSubmission, Form } from "../form/form.component";
4
+ import { Form } from "../form/form.component";
5
5
  import {
6
6
  FormSettingsSchema,
7
7
  formSettingsToSubmission,
@@ -9,6 +9,7 @@ import {
9
9
  } from "./formSettings.utils";
10
10
  import isEqual from "lodash/isEqual";
11
11
  import noop from "lodash/noop";
12
+ import { ChangedSubmission } from "../form/useForm.hook";
12
13
 
13
14
  export interface FormSettingsProps {
14
15
  form: Partial<FormSchema>;
@@ -84,6 +85,7 @@ export function FormSettings(props: FormSettingsProps) {
84
85
  disabled={!isValid}
85
86
  className={"mt-5 btn btn-primary"}
86
87
  onClick={onSubmit}
88
+ type={"submit"}
87
89
  >
88
90
  {i18n("Save settings")}
89
91
  </button>
@@ -32,7 +32,7 @@ export function FormsCell(
32
32
  </span>
33
33
 
34
34
  {(form.tags || []).map((tag, index) => (
35
- <span
35
+ <button
36
36
  key={index}
37
37
  className='badge badge-hover bg-secondary mr-1'
38
38
  onClick={stopPropagationWrapper(() => {
@@ -42,7 +42,7 @@ export function FormsCell(
42
42
  >
43
43
  <i className={classnames(iconClass(undefined, "tags"), "mr-1")} />
44
44
  {tag}
45
- </span>
45
+ </button>
46
46
  ))}
47
47
  </li>
48
48
  </ul>
@@ -56,7 +56,7 @@ export function InputText<T = any>({
56
56
  <input
57
57
  type={type || "text"}
58
58
  {...props}
59
- data-testid={"input"}
59
+ data-testid={`input_${name}`}
60
60
  className={classnames("form-control", size && `form-control-${size}`)}
61
61
  id={name}
62
62
  required={required}
@@ -6,7 +6,7 @@ describe("Loader", () => {
6
6
  it("should render a component (with isActive = true)", () => {
7
7
  const { getByTestId } = render(<Loader isActive={true} />);
8
8
 
9
- const icon = getByTestId("icon");
9
+ const icon = getByTestId("icon_radio-circle");
10
10
 
11
11
  expect(icon).toBeTruthy();
12
12
  });
@@ -14,7 +14,7 @@ describe("Loader", () => {
14
14
  it("should render a component (with isActive = false)", () => {
15
15
  const { queryByTestId } = render(<Loader isActive={false} />);
16
16
 
17
- const icon = queryByTestId("icon");
17
+ const icon = queryByTestId("icon_radio-circle");
18
18
 
19
19
  expect(icon).toBeFalsy();
20
20
  });
@@ -25,7 +25,7 @@ export function Loader({
25
25
  )}
26
26
  >
27
27
  <span
28
- data-testid={"icon"}
28
+ data-testid={`icon_${icon}`}
29
29
  color={color}
30
30
  className={`text-11xl ${iconClass(undefined, icon, true)}`}
31
31
  />
@@ -16,7 +16,7 @@ describe("Modal", () => {
16
16
  expect(queryByTestId("modalBody")).toBeFalsy();
17
17
  expect(queryByTestId("modalFooter")).toBeFalsy();
18
18
 
19
- fireEvent.click(screen.getByRole("openModal"));
19
+ fireEvent.click(screen.getByRole("button", { name: "Open modal" }));
20
20
 
21
21
  await waitFor(() => getByTestId("modalTitle"));
22
22
 
@@ -45,7 +45,7 @@ describe("Modal", () => {
45
45
  expect(queryByTestId("modalBody")).toBeFalsy();
46
46
  expect(queryByTestId("modalFooter")).toBeFalsy();
47
47
 
48
- fireEvent.click(getByRole("openModal"));
48
+ fireEvent.click(getByRole("button", { name: "Open modal" }));
49
49
 
50
50
  await waitFor(() => getByTestId("modalTitle"));
51
51
 
@@ -67,7 +67,7 @@ describe("Modal", () => {
67
67
  <WithFooter {...WithFooter.args} onSubmit={onSubmit} />
68
68
  );
69
69
 
70
- fireEvent.click(getByRole("openModal"));
70
+ fireEvent.click(getByRole("button", { name: "Open modal" }));
71
71
 
72
72
  await waitFor(() => getByTestId("modalTitle"));
73
73
 
@@ -1,3 +1,5 @@
1
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
2
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
1
3
  import React, { PropsWithChildren, useEffect, useRef, useState } from "react";
2
4
  import noop from "lodash";
3
5
 
@@ -61,7 +63,10 @@ export function Modal({
61
63
  }
62
64
 
63
65
  return (
64
- <div className={`formio-dialog formio-dialog-theme-default ${className}`}>
66
+ <div
67
+ role={"dialog"}
68
+ className={`formio-dialog formio-dialog-theme-default ${className}`}
69
+ >
65
70
  <div className='formio-dialog-overlay' onClick={onClickClose} />
66
71
  <div style={style} className={"formio-dialog-content"}>
67
72
  <div className={"formio-dialog-wrapper"}>
@@ -26,11 +26,7 @@ export const Sandbox = (args: ModalProps) => {
26
26
  return (
27
27
  <div>
28
28
  <div>
29
- <button
30
- role={"openModal"}
31
- className={"btn btn-primary"}
32
- onClick={modal.openModal}
33
- >
29
+ <button className={"btn btn-primary"} onClick={modal.openModal}>
34
30
  Open modal
35
31
  </button>
36
32
  </div>
@@ -51,11 +47,7 @@ export const WithTitle = (args: ModalProps) => {
51
47
  return (
52
48
  <div>
53
49
  <div>
54
- <button
55
- role={"openModal"}
56
- className={"btn btn-primary"}
57
- onClick={modal.openModal}
58
- >
50
+ <button className={"btn btn-primary"} onClick={modal.openModal}>
59
51
  Open modal
60
52
  </button>
61
53
  </div>
@@ -103,11 +95,7 @@ export const WithFooter = (args: ModalProps) => {
103
95
  return (
104
96
  <div>
105
97
  <div>
106
- <button
107
- className={"btn btn-primary"}
108
- role={"openModal"}
109
- onClick={modal.openModal}
110
- >
98
+ <button className={"btn btn-primary"} onClick={modal.openModal}>
111
99
  Open modal
112
100
  </button>
113
101
  </div>
@@ -185,12 +173,8 @@ export const WithRemoveModal = (args: RemoveModalProps) => {
185
173
  return (
186
174
  <div>
187
175
  <div>
188
- <button
189
- className={"btn btn-primary"}
190
- role={"openModal"}
191
- onClick={modal.openModal}
192
- >
193
- Open
176
+ <button className={"btn btn-primary"} onClick={modal.openModal}>
177
+ Open modal
194
178
  </button>
195
179
  </div>
196
180
  <RemoveModal
@@ -106,6 +106,7 @@ export class ReactComponent<Data = any> extends Components.components.field {
106
106
  */
107
107
  // eslint-disable-next-line @typescript-eslint/no-empty-function
108
108
  attachReact(element?: any) {
109
+ // eslint-disable-next-line react/no-render-return-value
109
110
  return ReactDOM.render(this.renderReact(), element);
110
111
  }
111
112
 
@@ -71,7 +71,7 @@ export function Select<T = any>({
71
71
  <select
72
72
  ref={ref}
73
73
  {...props}
74
- data-testid={"select"}
74
+ data-testid={`select_${name}`}
75
75
  className={classnames("form-control", size && `form-control-${size}`)}
76
76
  name={name}
77
77
  id={name}
@@ -30,7 +30,7 @@ export function DefaultOperationButton(props: OperationButtonProps) {
30
30
  } = props;
31
31
 
32
32
  return (
33
- <span
33
+ <button
34
34
  className={classnames(
35
35
  className,
36
36
  ["btn", buttonOutline && "outline", buttonType]
@@ -48,6 +48,6 @@ export function DefaultOperationButton(props: OperationButtonProps) {
48
48
  {title && (
49
49
  <span className={icon && title ? "ml-1" : ""}>{i18n(title)}</span>
50
50
  )}
51
- </span>
51
+ </button>
52
52
  );
53
53
  }
@@ -12,13 +12,13 @@ describe("DefaultColumnFilter", () => {
12
12
  column: { id: "id", filterValue: "", setFilter: jest.fn() }
13
13
  };
14
14
 
15
- const { getByTestId } = render(
15
+ const { getByRole } = render(
16
16
  // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
17
17
  // @ts-ignore
18
18
  <DefaultColumnFilter {...props} />
19
19
  );
20
20
 
21
- const input = getByTestId("input");
21
+ const input = getByRole("textbox");
22
22
 
23
23
  await act(async () => {
24
24
  fireEvent.change(input, { target: { value: "value-test" } });
@@ -215,10 +215,14 @@ export function Table<Data extends object = any>(
215
215
  /* style={{ marginBottom: disablePagination ? "-1px" : "0px" }} */
216
216
  >
217
217
  <thead>
218
- {tableInstance.headerGroups.map((headerGroup) => (
219
- <tr {...headerGroup.getHeaderGroupProps()}>
218
+ {tableInstance.headerGroups.map((headerGroup, i) => (
219
+ <tr
220
+ key={`tableInstance.headerGroups${i}`}
221
+ {...headerGroup.getHeaderGroupProps()}
222
+ >
220
223
  {headerGroup.headers.map((column) => (
221
224
  <th
225
+ key={`tableInstance.headers.column.${column.id}`}
222
226
  /* className='text-left py-2 align-top' */
223
227
  {...column.getHeaderProps()}
224
228
  >
@@ -230,20 +234,27 @@ export function Table<Data extends object = any>(
230
234
  </thead>
231
235
  {!isLoading ? (
232
236
  <tbody {...tableInstance.getTableBodyProps()}>
233
- {tableInstance.page.map((row, i) => {
237
+ {tableInstance.page.map((row) => {
234
238
  tableInstance.prepareRow(row);
235
239
  return (
236
240
  <tr
241
+ key={`tableInstance.page.${row.id}`}
237
242
  onClick={() => _onClick(row.original, "row")}
238
243
  {...row.getRowProps()}
239
244
  >
240
- {row.cells.map((cell) => {
245
+ {row.cells.map((cell, i) => {
241
246
  const { hidden, colspan } = cell.column as any;
242
247
  if (hidden) {
243
248
  return null;
244
249
  }
245
250
  return (
246
- <td colSpan={colspan} {...cell.getCellProps()}>
251
+ <td
252
+ key={`tableInstance.page.cells.${
253
+ cell.value || "value"
254
+ }.${i}`}
255
+ colSpan={colspan}
256
+ {...cell.getCellProps()}
257
+ >
247
258
  {cell.render("Cell")}
248
259
  </td>
249
260
  );
@@ -87,7 +87,7 @@ Sandbox.args = {
87
87
  function AddButton({ onCreate }: any) {
88
88
  return (
89
89
  <div>
90
- <div onClick={onCreate}>+</div>
90
+ <button onClick={onCreate}>+</button>
91
91
  </div>
92
92
  );
93
93
  }
@@ -1,16 +0,0 @@
1
- import { FormSchema } from "../../interfaces/FormSchema";
2
- export interface UseFormHookProps {
3
- form: Partial<FormSchema>;
4
- redo: Function;
5
- undo: Function;
6
- reset: Function;
7
- hasChanged: boolean;
8
- isValid: boolean;
9
- hasUndo: boolean;
10
- hasRedo: boolean;
11
- onSubmit: () => void;
12
- onCopy: () => void;
13
- formChange: (newForm: Partial<FormSchema>) => void;
14
- setChange: (path: string, value: any) => void;
15
- }
16
- export declare function useForm(props: any): UseFormHookProps;