@tsed/react-formio 1.13.2 → 1.13.5

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 (135) hide show
  1. package/.eslintignore +13 -0
  2. package/.eslintrc.js +7 -0
  3. package/coverage.json +6 -0
  4. package/dist/components/form/form.stories.d.ts +25 -0
  5. package/dist/components/form/useForm.hook.d.ts +7 -3
  6. package/dist/components/form-control/formControl.component.d.ts +2 -2
  7. package/dist/components/form-control/formControl.component.spec.d.ts +1 -0
  8. package/dist/components/form-control/formControl.stories.d.ts +57 -0
  9. package/dist/components/index.d.ts +4 -2
  10. package/dist/components/table/components/defaultCellHeader.component.d.ts +1 -1
  11. package/dist/components/table/index.d.ts +1 -1
  12. package/dist/index.d.ts +3 -3
  13. package/dist/index.js +7929 -7904
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.modern.js +7366 -7339
  16. package/dist/index.modern.js.map +1 -1
  17. package/dist/stores/actions/index.d.ts +1 -1
  18. package/dist/stores/auth/index.d.ts +4 -4
  19. package/dist/stores/index.d.ts +2 -2
  20. package/jest.config.js +6 -1
  21. package/package.json +7 -4
  22. package/src/components/actions-table/actionsTable.component.spec.tsx +11 -11
  23. package/src/components/actions-table/actionsTable.component.tsx +8 -9
  24. package/src/components/actions-table/actionsTable.stories.tsx +1 -0
  25. package/src/components/alert/alert.component.spec.tsx +21 -19
  26. package/src/components/alert/alert.stories.tsx +1 -0
  27. package/src/components/card/card.component.spec.tsx +5 -4
  28. package/src/components/card/card.stories.tsx +1 -0
  29. package/src/components/form/form.component.spec.tsx +7 -6
  30. package/src/components/form/form.component.tsx +2 -1
  31. package/src/components/form/form.stories.tsx +118 -76
  32. package/src/components/form/useForm.hook.ts +47 -22
  33. package/src/components/form-access/formAccess.component.tsx +2 -1
  34. package/src/components/form-access/formAccess.schema.ts +1 -0
  35. package/src/components/form-access/formAccess.stories.tsx +1 -0
  36. package/src/components/form-access/formAccess.utils.ts +9 -8
  37. package/src/components/form-action/formAction.component.tsx +4 -3
  38. package/src/components/form-action/formAction.stories.tsx +225 -227
  39. package/src/components/form-builder/formBuilder.component.tsx +1 -0
  40. package/src/components/form-builder/formBuilder.stories.tsx +1 -0
  41. package/src/components/form-control/formControl.component.spec.tsx +76 -0
  42. package/src/components/form-control/formControl.component.tsx +15 -7
  43. package/src/components/form-control/formControl.stories.tsx +65 -0
  44. package/src/components/form-edit/formCtas.component.tsx +25 -26
  45. package/src/components/form-edit/formEdit.component.tsx +1 -0
  46. package/src/components/form-edit/formEdit.reducer.ts +1 -0
  47. package/src/components/form-edit/formEdit.stories.tsx +1 -0
  48. package/src/components/form-edit/formParameters.component.tsx +1 -0
  49. package/src/components/form-edit/useFormEdit.hook.ts +1 -0
  50. package/src/components/form-settings/formSettings.component.spec.tsx +7 -6
  51. package/src/components/form-settings/formSettings.component.tsx +12 -14
  52. package/src/components/form-settings/formSettings.stories.tsx +1 -0
  53. package/src/components/form-settings/formSettings.utils.ts +1 -0
  54. package/src/components/forms-table/components/formCell.component.tsx +1 -0
  55. package/src/components/forms-table/formsTable.component.tsx +23 -25
  56. package/src/components/forms-table/formsTable.stories.tsx +1 -0
  57. package/src/components/index.ts +4 -2
  58. package/src/components/input-tags/inputTags.component.tsx +5 -4
  59. package/src/components/input-tags/inputTags.stories.tsx +1 -0
  60. package/src/components/input-text/inputText.component.spec.tsx +12 -11
  61. package/src/components/input-text/inputText.component.tsx +1 -0
  62. package/src/components/input-text/inputText.stories.tsx +1 -0
  63. package/src/components/loader/loader.component.spec.tsx +6 -5
  64. package/src/components/loader/loader.component.tsx +1 -0
  65. package/src/components/loader/loader.stories.tsx +1 -0
  66. package/src/components/modal/modal.component.spec.tsx +36 -33
  67. package/src/components/modal/modal.component.tsx +1 -1
  68. package/src/components/modal/modal.stories.tsx +1 -0
  69. package/src/components/modal/removeModal.component.tsx +1 -0
  70. package/src/components/pagination/pagination.component.spec.tsx +24 -21
  71. package/src/components/pagination/pagination.component.tsx +1 -0
  72. package/src/components/pagination/pagination.stories.tsx +1 -0
  73. package/src/components/react-component/reactComponent.component.tsx +3 -2
  74. package/src/components/select/select.component.spec.tsx +17 -18
  75. package/src/components/select/select.component.tsx +1 -0
  76. package/src/components/select/select.stories.tsx +1 -0
  77. package/src/components/submissions-table/submissionsTable.component.tsx +6 -5
  78. package/src/components/submissions-table/submissionsTable.stories.tsx +1 -0
  79. package/src/components/table/components/defaultArrowSort.component.tsx +1 -0
  80. package/src/components/table/components/defaultCellHeader.component.tsx +1 -1
  81. package/src/components/table/components/defaultCellOperations.component.tsx +1 -0
  82. package/src/components/table/components/defaultOperationButton.component.tsx +1 -0
  83. package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +5 -3
  84. package/src/components/table/filters/defaultColumnFilter.component.tsx +1 -0
  85. package/src/components/table/filters/selectColumnFilter.component.spec.tsx +9 -7
  86. package/src/components/table/filters/selectColumnFilter.component.tsx +1 -0
  87. package/src/components/table/index.ts +1 -1
  88. package/src/components/table/table.component.tsx +45 -58
  89. package/src/components/table/table.stories.tsx +2 -1
  90. package/src/components/table/utils/mapFormToColumns.tsx +2 -1
  91. package/src/components/table/utils/useOperations.hook.tsx +1 -0
  92. package/src/components/tabs/tabs.component.spec.tsx +6 -5
  93. package/src/components/tabs/tabs.component.stories.tsx +1 -0
  94. package/src/components/tabs/tabs.component.tsx +10 -4
  95. package/src/index.ts +3 -5
  96. package/src/interfaces/Operation.ts +1 -0
  97. package/src/stores/action/action.actions.spec.ts +1 -0
  98. package/src/stores/action/action.actions.ts +1 -0
  99. package/src/stores/action/action.reducers.ts +1 -1
  100. package/src/stores/action-info/action-info.actions.spec.ts +1 -0
  101. package/src/stores/action-info/action-info.actions.ts +2 -1
  102. package/src/stores/action-info/action-info.reducers.ts +2 -1
  103. package/src/stores/action-info/action-info.selectors.ts +2 -1
  104. package/src/stores/actions/actions.actions.spec.ts +1 -0
  105. package/src/stores/actions/actions.actions.ts +1 -0
  106. package/src/stores/actions/actions.reducers.ts +1 -0
  107. package/src/stores/actions/index.ts +1 -1
  108. package/src/stores/auth/auth.actions.ts +1 -0
  109. package/src/stores/auth/auth.reducers.ts +1 -0
  110. package/src/stores/auth/auth.selectors.ts +1 -0
  111. package/src/stores/auth/auth.utils.tsx +2 -1
  112. package/src/stores/auth/getAccess.action.spec.ts +1 -0
  113. package/src/stores/auth/getAccess.action.ts +1 -0
  114. package/src/stores/auth/getProjectAccess.action.ts +1 -0
  115. package/src/stores/auth/index.ts +4 -4
  116. package/src/stores/auth/initAuth.action.spec.ts +1 -0
  117. package/src/stores/auth/initAuth.action.ts +1 -0
  118. package/src/stores/auth/logout.action.spec.ts +2 -1
  119. package/src/stores/auth/logout.action.ts +1 -0
  120. package/src/stores/auth/setUser.action.spec.ts +1 -0
  121. package/src/stores/auth/setUser.action.ts +1 -0
  122. package/src/stores/form/form.actions.spec.ts +1 -0
  123. package/src/stores/form/form.actions.ts +1 -0
  124. package/src/stores/form/form.reducers.ts +1 -0
  125. package/src/stores/forms/forms.actions.spec.ts +1 -0
  126. package/src/stores/forms/forms.actions.ts +1 -0
  127. package/src/stores/forms/forms.reducers.ts +1 -0
  128. package/src/stores/index.ts +3 -2
  129. package/src/stores/root/root.selectors.ts +1 -1
  130. package/src/stores/submission/submission.actions.spec.ts +1 -0
  131. package/src/stores/submission/submission.actions.ts +1 -0
  132. package/src/stores/submission/submission.reducers.ts +1 -0
  133. package/src/stores/submissions/submissions.actions.spec.ts +1 -0
  134. package/src/stores/submissions/submissions.actions.ts +1 -0
  135. package/src/stores/submissions/submissions.reducers.ts +1 -0
@@ -0,0 +1,76 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import React from "react";
3
+
4
+ import { iconClass } from "../../utils/iconClass";
5
+ import { Sandbox, WithDescription, WithPrefix, WithSuffix } from "./formControl.stories";
6
+
7
+ describe("form-control", () => {
8
+ it("should display form control component", () => {
9
+ render(<Sandbox {...Sandbox.args} name='test' />);
10
+
11
+ const formGroup = screen.getByTestId("form-group-test") as HTMLFormElement;
12
+
13
+ expect(formGroup).toBeInTheDocument();
14
+ });
15
+
16
+ it("should NOT display form-control component without a name attribute defined", () => {
17
+ const name = "";
18
+ render(<Sandbox {...Sandbox.args} name={name} />);
19
+
20
+ const formGroup = screen.queryByTestId(`form-group-${name}`) as HTMLFormElement;
21
+
22
+ expect(formGroup).not.toBeInTheDocument();
23
+ });
24
+
25
+ it("should display form-control component with className 'field-required' when the props 'required' is set to true", () => {
26
+ render(<Sandbox {...Sandbox.args} required={true} name='test' />);
27
+
28
+ const formGroup = screen.getByTestId("form-group-test") as HTMLFormElement;
29
+ const formControlLabel = screen.getByTestId(`form-control-label`) as HTMLLabelElement;
30
+
31
+ expect(formGroup).toBeInTheDocument();
32
+ expect(formControlLabel).toBeInTheDocument();
33
+ expect(formControlLabel).toHaveClass("col-form-label field-required");
34
+ });
35
+
36
+ it("should display prefix", () => {
37
+ const fontAwsomeCalendarIcon = "fa fa-calendar";
38
+ const prefix = (<i className={iconClass(undefined, "calendar")} />) as JSX.Element;
39
+ render(<WithPrefix {...Sandbox.args} name='testPrefix' prefix={prefix} />);
40
+
41
+ const formGroup = screen.getByTestId("form-group-testPrefix") as HTMLFormElement;
42
+ const formControlPrefix = screen.getByTestId("form-control-prefix") as HTMLSpanElement;
43
+
44
+ expect(formGroup).toBeInTheDocument();
45
+ expect(formControlPrefix).toBeInTheDocument();
46
+ expect(formControlPrefix).not.toBeEmptyDOMElement();
47
+ expect(formControlPrefix).toContainHTML(fontAwsomeCalendarIcon);
48
+ });
49
+
50
+ it("should display suffix", () => {
51
+ const fontAwsomeCalendarIcon = "fa fa-calendar";
52
+ const suffix = (<i className={iconClass(undefined, "calendar")} />) as JSX.Element;
53
+ render(<WithSuffix {...Sandbox.args} name='testSuffix' suffix={suffix} />);
54
+
55
+ const formGroup = screen.getByTestId("form-group-testSuffix") as HTMLFormElement;
56
+ const formControlSuffix = screen.getByTestId("form-control-suffix") as HTMLSpanElement;
57
+
58
+ expect(formGroup).toBeInTheDocument();
59
+ expect(formControlSuffix).toBeInTheDocument();
60
+ expect(formControlSuffix).not.toBeEmptyDOMElement();
61
+ expect(formControlSuffix).toContainHTML(fontAwsomeCalendarIcon);
62
+ });
63
+
64
+ it("should display description", () => {
65
+ const description = "test description";
66
+ render(<WithDescription {...Sandbox.args} name='testDescription' description={description} />);
67
+
68
+ const formGroup = screen.getByTestId("form-group-testDescription") as HTMLFormElement;
69
+ const formControlDescription = screen.getByTestId("form-control-description") as HTMLDivElement;
70
+
71
+ expect(formGroup).toBeInTheDocument();
72
+ expect(formControlDescription).toBeInTheDocument();
73
+ expect(formControlDescription).not.toBeEmptyDOMElement();
74
+ expect(screen.getByText(description)).toBeInTheDocument();
75
+ });
76
+ });
@@ -8,8 +8,8 @@ export interface FormControlProps {
8
8
  label?: string;
9
9
  className?: string;
10
10
  description?: string | React.ComponentType | any;
11
- prefix?: React.ComponentType | any;
12
- suffix?: React.ComponentType | any;
11
+ prefix?: JSX.Element | React.ComponentType | any;
12
+ suffix?: JSX.Element | React.ComponentType | any;
13
13
  shadow?: boolean;
14
14
  }
15
15
 
@@ -24,26 +24,34 @@ export function FormControl({
24
24
  className
25
25
  }: React.PropsWithChildren<FormControlProps>) {
26
26
  return (
27
- <div id={`form-group-${name || ""}`} className={classnames("form-group", className)}>
27
+ <div data-testid={name && `form-group-${name}`} id={`form-group-${name || ""}`} className={classnames("form-group", className)}>
28
28
  {label && (
29
- <label htmlFor={name} className={`col-form-label ${required ? " field-required" : ""}`}>
29
+ <label htmlFor={name} data-testid='form-control-label' className={`col-form-label ${required ? " field-required" : ""}`}>
30
30
  {label}
31
31
  </label>
32
32
  )}
33
33
  <div className={"input-group"}>
34
34
  {prefix && (
35
35
  <div className='input-group-prepend'>
36
- <span className='input-group-text'>{prefix}</span>
36
+ <span className='input-group-text' data-testid='form-control-prefix'>
37
+ {prefix}
38
+ </span>
37
39
  </div>
38
40
  )}
39
41
  {children}
40
42
  {suffix && (
41
43
  <div className='input-group-append'>
42
- <span className='input-group-text'>{suffix}</span>
44
+ <span className='input-group-text' data-testid='form-control-suffix'>
45
+ {suffix}
46
+ </span>
43
47
  </div>
44
48
  )}
45
49
  </div>
46
- {description && <div className='form-text text-muted'>{description}</div>}
50
+ {description && (
51
+ <div data-testid='form-control-description' className='form-text text-muted'>
52
+ {description}
53
+ </div>
54
+ )}
47
55
  </div>
48
56
  );
49
57
  }
@@ -0,0 +1,65 @@
1
+ import React from "react";
2
+
3
+ import { iconClass } from "../../utils/iconClass";
4
+ import { FormControl } from "./formControl.component";
5
+
6
+ export default {
7
+ title: "ReactFormio/FormControl",
8
+ component: FormControl,
9
+ argTypes: {
10
+ label: {
11
+ control: {
12
+ type: "text"
13
+ }
14
+ },
15
+ name: {
16
+ control: {
17
+ type: "text"
18
+ }
19
+ },
20
+ children: {
21
+ control: {
22
+ type: HTMLElement || HTMLCollection
23
+ }
24
+ }
25
+ },
26
+ parameters: {}
27
+ };
28
+
29
+ export const Sandbox = (args: any) => {
30
+ return <FormControl {...args} />;
31
+ };
32
+
33
+ Sandbox.args = {
34
+ label: "Label",
35
+ children: <input type='text' className='form-control' placeholder='placeholder' />
36
+ };
37
+
38
+ export const WithPrefix = (args: any) => {
39
+ return <FormControl {...args} />;
40
+ };
41
+
42
+ WithPrefix.args = {
43
+ label: "Label",
44
+ children: <input type='text' className='form-control' placeholder='placeholder' />,
45
+ prefix: <i className={iconClass(undefined, "calendar")} />
46
+ };
47
+
48
+ export const WithSuffix = (args: any) => {
49
+ return <FormControl {...args} />;
50
+ };
51
+
52
+ WithSuffix.args = {
53
+ label: "Label",
54
+ children: <input type='text' className='form-control' placeholder='placeholder' />,
55
+ suffix: <i className={iconClass(undefined, "calendar")} />
56
+ };
57
+
58
+ export const WithDescription = (args: any) => {
59
+ return <FormControl {...args} />;
60
+ };
61
+
62
+ WithDescription.args = {
63
+ label: "Label",
64
+ children: <input type='text' className='form-control' placeholder='placeholder' />
65
+ };
@@ -1,8 +1,9 @@
1
1
  import PropTypes from "prop-types";
2
- import React, {ReactElement} from "react";
3
- import {useTooltip} from "../../hooks/useTooltip";
4
- import {FormOptions} from "../../interfaces";
5
- import {iconClass} from "../../utils/iconClass";
2
+ import React, { ReactElement } from "react";
3
+
4
+ import { useTooltip } from "../../hooks/useTooltip";
5
+ import { FormOptions } from "../../interfaces";
6
+ import { iconClass } from "../../utils/iconClass";
6
7
 
7
8
  export interface FormEditCTAsProps extends Record<string, unknown> {
8
9
  saveText?: string;
@@ -18,18 +19,18 @@ export interface FormEditCTAsProps extends Record<string, unknown> {
18
19
  }
19
20
 
20
21
  export function FormEditCTAs({
21
- saveText = "Save",
22
- disabled,
23
- options = {},
24
- onCopy,
25
- hasUndo,
26
- hasRedo,
27
- onUndo,
28
- onRedo,
29
- onReset,
30
- onSubmit
31
- }: FormEditCTAsProps): ReactElement {
32
- const {i18n: t = (t: string): string => t} = options;
22
+ saveText = "Save",
23
+ disabled,
24
+ options = {},
25
+ onCopy,
26
+ hasUndo,
27
+ hasRedo,
28
+ onUndo,
29
+ onRedo,
30
+ onReset,
31
+ onSubmit
32
+ }: FormEditCTAsProps): ReactElement {
33
+ const { i18n: t = (t: string): string => t } = options;
33
34
 
34
35
  const copyTooltipRef: any = useTooltip({
35
36
  trigger: "hover",
@@ -63,31 +64,29 @@ export function FormEditCTAs({
63
64
  disabled={disabled}
64
65
  onClick={() => !disabled && onSubmit && onSubmit()}
65
66
  >
66
- <i className={`mr-1 ${iconClass(options.iconset, "save")}`}/>
67
+ <i className={`mr-1 ${iconClass(options.iconset, "save")}`} />
67
68
  {saveText}
68
69
  </button>
69
70
 
70
71
  <div>
71
- <button className={`btn btn-light btn-undo ${hasUndo ? "" : "disabled"}`} onClick={() => onUndo && onUndo()}
72
- ref={undoTooltipRef}>
73
- <i className={iconClass(options.iconset, "undo")}/>
72
+ <button className={`btn btn-light btn-undo ${hasUndo ? "" : "disabled"}`} onClick={() => onUndo && onUndo()} ref={undoTooltipRef}>
73
+ <i className={iconClass(options.iconset, "undo")} />
74
74
  </button>
75
75
 
76
- <button className={`btn btn-light btn-redo ${hasRedo ? "" : "disabled"}`} onClick={() => onRedo && onRedo()}
77
- ref={redoTooltipRef}>
78
- <i className={iconClass(options.iconset, "redo")}/>
76
+ <button className={`btn btn-light btn-redo ${hasRedo ? "" : "disabled"}`} onClick={() => onRedo && onRedo()} ref={redoTooltipRef}>
77
+ <i className={iconClass(options.iconset, "redo")} />
79
78
  </button>
80
79
  </div>
81
80
 
82
81
  <div>
83
82
  {onCopy && (
84
- <button className="btn btn-light" onClick={() => onCopy()} ref={copyTooltipRef!}>
85
- <i className={iconClass(options.iconset, "copy")}/>
83
+ <button className='btn btn-light' onClick={() => onCopy()} ref={copyTooltipRef!}>
84
+ <i className={iconClass(options.iconset, "copy")} />
86
85
  </button>
87
86
  )}
88
87
 
89
88
  <button className={`btn btn-light btn-reset`} onClick={() => onReset && onReset()} ref={resetTooltipRef!}>
90
- <i className={iconClass(options.iconset, "reset")}/>
89
+ <i className={iconClass(options.iconset, "reset")} />
91
90
  </button>
92
91
  </div>
93
92
  </div>
@@ -1,5 +1,6 @@
1
1
  import PropTypes from "prop-types";
2
2
  import React from "react";
3
+
3
4
  import { FormOptions } from "../../interfaces/FormOptions";
4
5
  import { FormBuilder } from "../form-builder/formBuilder.component";
5
6
  import { FormEditCTAs } from "./formCtas.component";
@@ -1,6 +1,7 @@
1
1
  import camelCase from "lodash/camelCase";
2
2
  import cloneDeep from "lodash/cloneDeep";
3
3
  import isEqual from "lodash/isEqual";
4
+
4
5
  import { FormSchema } from "../../interfaces";
5
6
 
6
7
  export const hasChanged = (form: Partial<FormSchema>, value: Partial<FormSchema>): boolean => !isEqual(form, value);
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+
2
3
  import { FormEdit } from "../../index";
3
4
  import { defaultDisplayChoices } from "./formParameters.component";
4
5
 
@@ -1,5 +1,6 @@
1
1
  import PropTypes from "prop-types";
2
2
  import React, { ReactElement } from "react";
3
+
3
4
  import { FormSchema } from "../../interfaces/FormSchema";
4
5
  import { InputTags } from "../input-tags/inputTags.component";
5
6
  import { InputText } from "../input-text/inputText.component";
@@ -1,4 +1,5 @@
1
1
  import { useEffect, useReducer } from "react";
2
+
2
3
  import { FormSchema } from "../../interfaces/FormSchema";
3
4
  import { createInitialState, hasChanged, reducer } from "./formEdit.reducer";
4
5
 
@@ -1,7 +1,8 @@
1
- import { fireEvent, render } from "@testing-library/react";
1
+ import { fireEvent, render, screen } from "@testing-library/react";
2
2
  import React from "react";
3
- import { Sandbox } from "./formSettings.stories";
3
+
4
4
  import { FormSettings } from "./formSettings.component";
5
+ import { Sandbox } from "./formSettings.stories";
5
6
 
6
7
  describe("FormSettings", () => {
7
8
  it("should render form settings", async () => {
@@ -10,7 +11,7 @@ describe("FormSettings", () => {
10
11
  // @ts-ignore
11
12
  Sandbox.args.form.action = "https://test";
12
13
 
13
- const { getByTestId } = render(
14
+ render(
14
15
  <Sandbox
15
16
  {...Sandbox.args}
16
17
  onSubmit={onSubmit}
@@ -20,7 +21,7 @@ describe("FormSettings", () => {
20
21
  />
21
22
  );
22
23
 
23
- const btn = getByTestId("submit");
24
+ const btn = screen.getByTestId("submit");
24
25
 
25
26
  await fireEvent.click(btn);
26
27
 
@@ -47,7 +48,7 @@ describe("FormSettings", () => {
47
48
  });
48
49
  });
49
50
  it("should render form settings with i18n options", async () => {
50
- const { getByTestId } = render(
51
+ render(
51
52
  <FormSettings
52
53
  {...Sandbox.args}
53
54
  options={{
@@ -56,7 +57,7 @@ describe("FormSettings", () => {
56
57
  />
57
58
  );
58
59
 
59
- const btn = getByTestId("submit");
60
+ const btn = screen.getByTestId("submit");
60
61
 
61
62
  await fireEvent.click(btn);
62
63
 
@@ -1,11 +1,12 @@
1
- import React, { useCallback, useEffect, useState } from "react";
2
- import { FormOptions, FormSchema } from "../../interfaces";
3
- import { getFormSettingsSchema } from "./formSettings.schema";
4
- import { Form } from "../form/form.component";
5
- import { FormSettingsSchema, formSettingsToSubmission, submissionToFormSettings } from "./formSettings.utils";
6
1
  import isEqual from "lodash/isEqual";
7
2
  import noop from "lodash/noop";
3
+ import React, { useEffect, useState } from "react";
4
+
5
+ import { FormOptions, FormSchema } from "../../interfaces";
6
+ import { Form } from "../form/form.component";
8
7
  import { ChangedSubmission } from "../form/useForm.hook";
8
+ import { getFormSettingsSchema } from "./formSettings.schema";
9
+ import { FormSettingsSchema, formSettingsToSubmission, submissionToFormSettings } from "./formSettings.utils";
9
10
 
10
11
  export interface FormSettingsProps {
11
12
  form: Partial<FormSchema>;
@@ -18,15 +19,12 @@ function useFormSettings({ form: formDefinition, onSubmit = noop, options }: For
18
19
  const [isValid, setIsValid] = useState(true);
19
20
  const [submission, setSubmission] = useState(() => formSettingsToSubmission(formDefinition));
20
21
 
21
- const onChange = useCallback(
22
- ({ data, isValid }: ChangedSubmission<FormSettingsSchema>) => {
23
- if (isValid) {
24
- setSubmission({ data });
25
- }
26
- setIsValid(isValid);
27
- },
28
- [submission]
29
- );
22
+ const onChange = ({ data, isValid }: ChangedSubmission<FormSettingsSchema>) => {
23
+ if (isValid) {
24
+ setSubmission({ data });
25
+ }
26
+ setIsValid(isValid);
27
+ };
30
28
 
31
29
  useEffect(() => {
32
30
  const input = formSettingsToSubmission(formDefinition);
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+
2
3
  import { FormSettings } from "./formSettings.component";
3
4
 
4
5
  export default {
@@ -1,4 +1,5 @@
1
1
  import cloneDeep from "lodash/cloneDeep";
2
+
2
3
  import { FormSchema, Submission } from "../../interfaces";
3
4
 
4
5
  export type FormSettingsSchema = {
@@ -2,6 +2,7 @@ import classnames from "classnames";
2
2
  import moment from "moment";
3
3
  import React from "react";
4
4
  import { CellProps } from "react-table";
5
+
5
6
  import { FormSchema } from "../../../interfaces";
6
7
  import { iconClass } from "../../../utils/iconClass";
7
8
  import { stopPropagationWrapper } from "../../../utils/stopPropagationWrapper";
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+
2
3
  import { FormSchema } from "../../interfaces";
3
4
  import { DefaultColumnFilter } from "../table/filters/defaultColumnFilter.component";
4
5
  import { SelectColumnFilter } from "../table/filters/selectColumnFilter.component";
@@ -13,31 +14,28 @@ export type FormsTableProps = Omit<TableProps<FormSchema>, "columns"> & {
13
14
  export function FormsTable({ Cell, ...props }: FormsTableProps) {
14
15
  const { i18n = (f: string) => f, tags } = props;
15
16
  const FormCell = Cell || (DefaultFormCell as any);
16
- const columns = React.useMemo(
17
- () => [
18
- {
19
- Header: i18n("Title"),
20
- accessor: "title",
21
- id: "title",
22
- Cell: (props: any) => <FormCell {...props} icon={props.icon} i18n={i18n} />,
23
- Filter: DefaultColumnFilter,
24
- colspan: 2
25
- },
26
- {
27
- Header: i18n("Tags"),
28
- accessor: "tags",
29
- id: "tags",
30
- hidden: true,
31
- Filter: (props: any) =>
32
- tags && tags.length ? (
33
- <SelectColumnFilter {...props} column={{ ...props.columns, choices: tags }} />
34
- ) : (
35
- <DefaultColumnFilter {...props} />
36
- )
37
- }
38
- ],
39
- [Cell]
40
- );
17
+ const columns = [
18
+ {
19
+ Header: i18n("Title"),
20
+ accessor: "title",
21
+ id: "title",
22
+ Cell: (props: any) => <FormCell {...props} icon={props.icon} i18n={i18n} />,
23
+ Filter: DefaultColumnFilter,
24
+ colspan: 2
25
+ },
26
+ {
27
+ Header: i18n("Tags"),
28
+ accessor: "tags",
29
+ id: "tags",
30
+ hidden: true,
31
+ Filter: (props: any) =>
32
+ tags && tags.length ? (
33
+ <SelectColumnFilter {...props} column={{ ...props.columns, choices: tags }} />
34
+ ) : (
35
+ <DefaultColumnFilter {...props} />
36
+ )
37
+ }
38
+ ];
41
39
 
42
40
  return <Table {...props} columns={columns} />;
43
41
  }
@@ -1,5 +1,6 @@
1
1
  import { ICONS } from "@tsed/tailwind-formio/lib/templates/tailwind/iconClass";
2
2
  import React from "react";
3
+
3
4
  import { FormsTable } from "./formsTable.component";
4
5
 
5
6
  export default {
@@ -2,17 +2,20 @@ export * from "./actions-table/actionsTable.component";
2
2
  export * from "./alert/alert.component";
3
3
  export * from "./card/card.component";
4
4
  export * from "./form/form.component";
5
+ export * from "./form/useForm.hook";
5
6
  export * from "./form-access/formAccess.component";
6
7
  export * from "./form-action/formAction.component";
7
8
  export * from "./form-builder/formBuilder.component";
8
9
  export * from "./form-control/formControl.component";
9
- export * from "./form-edit/formEdit.component";
10
10
  export * from "./form-edit/formCtas.component";
11
+ export * from "./form-edit/formEdit.component";
11
12
  export * from "./form-edit/formParameters.component";
13
+ export * from "./form-edit/useFormEdit.hook";
12
14
  export * from "./form-settings/formSettings.component";
13
15
  export * from "./forms-table/formsTable.component";
14
16
  export * from "./input-tags/inputTags.component";
15
17
  export * from "./input-text/inputText.component";
18
+ export * from "./loader/loader.component";
16
19
  export * from "./modal/modal.component";
17
20
  export * from "./modal/removeModal.component";
18
21
  export * from "./pagination/pagination.component";
@@ -21,4 +24,3 @@ export * from "./select/select.component";
21
24
  export * from "./submissions-table/submissionsTable.component";
22
25
  export * from "./table";
23
26
  export * from "./tabs/tabs.component";
24
- export * from "./loader/loader.component";
@@ -30,10 +30,11 @@ export function InputTags({ name, value = [], label, onChange, required, descrip
30
30
  });
31
31
 
32
32
  instance.passedElement.element.addEventListener("removeItem", (event: any) => {
33
- onChange && onChange(
34
- name,
35
- value.filter((v: string) => v !== event.detail.value)
36
- );
33
+ onChange &&
34
+ onChange(
35
+ name,
36
+ value.filter((v: string) => v !== event.detail.value)
37
+ );
37
38
  });
38
39
 
39
40
  return () => {
@@ -1,4 +1,5 @@
1
1
  import React, { useState } from "react";
2
+
2
3
  import { iconClass } from "../../utils/iconClass";
3
4
  import { InputTags } from "./inputTags.component";
4
5
 
@@ -1,18 +1,19 @@
1
+ import { fireEvent, render, screen } from "@testing-library/react";
1
2
  import React from "react";
2
- import { fireEvent, render } from "@testing-library/react";
3
+
3
4
  import { Sandbox } from "./inputText.stories";
4
5
 
5
6
  describe("input-text", () => {
6
7
  it("should display the input-text component", () => {
7
- const { getByTestId } = render(<Sandbox {...Sandbox.args} name={"test"} />);
8
- const input = getByTestId("input_test") as HTMLInputElement;
8
+ render(<Sandbox {...Sandbox.args} name={"test"} />);
9
+ const input = screen.getByTestId("input_test") as HTMLInputElement;
9
10
 
10
11
  expect(input).toBeInTheDocument();
11
12
  });
12
13
 
13
14
  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;
15
+ render(<Sandbox {...Sandbox.args} name={"test"} size='small' />);
16
+ const input = screen.getByTestId("input_test") as HTMLInputElement;
16
17
 
17
18
  expect(input).toBeInTheDocument();
18
19
  expect(input).toHaveClass("form-control-small");
@@ -21,8 +22,8 @@ describe("input-text", () => {
21
22
  it("should display the input-text with placeholder", () => {
22
23
  const placeholderTest = "placeholder test";
23
24
 
24
- const { getByTestId } = render(<Sandbox {...Sandbox.args} name={"test"} placeholder={placeholderTest} />);
25
- const input = getByTestId("input_test") as HTMLInputElement;
25
+ render(<Sandbox {...Sandbox.args} name={"test"} placeholder={placeholderTest} />);
26
+ const input = screen.getByTestId("input_test") as HTMLInputElement;
26
27
 
27
28
  expect(input).toBeInTheDocument();
28
29
  expect(input).toHaveAttribute("placeholder", placeholderTest);
@@ -31,8 +32,8 @@ describe("input-text", () => {
31
32
  it("should change the value of the input-text", () => {
32
33
  const placeholderTest = "placeholder test";
33
34
 
34
- const { getByTestId } = render(<Sandbox {...Sandbox.args} name={"test"} placeholder={placeholderTest} />);
35
- const input = getByTestId("input_test") as HTMLInputElement;
35
+ render(<Sandbox {...Sandbox.args} name={"test"} placeholder={placeholderTest} />);
36
+ const input = screen.getByTestId("input_test") as HTMLInputElement;
36
37
 
37
38
  expect(input).toBeInTheDocument();
38
39
  fireEvent.change(input, { target: { value: "newValue" } });
@@ -43,8 +44,8 @@ describe("input-text", () => {
43
44
  it("should NOT change the value of the input-text if the value is NOT of type number", () => {
44
45
  const placeholderTest = "placeholder test";
45
46
 
46
- const { getByTestId } = render(<Sandbox {...Sandbox.args} type='number' name={"test"} placeholder={placeholderTest} />);
47
- const input = getByTestId("input_test") as HTMLInputElement;
47
+ render(<Sandbox {...Sandbox.args} type='number' name={"test"} placeholder={placeholderTest} />);
48
+ const input = screen.getByTestId("input_test") as HTMLInputElement;
48
49
 
49
50
  expect(input).toBeInTheDocument();
50
51
  fireEvent.change(input, { target: { value: "newValue" } });
@@ -1,6 +1,7 @@
1
1
  import classnames from "classnames";
2
2
  import PropTypes from "prop-types";
3
3
  import React, { useEffect, useMemo, useState } from "react";
4
+
4
5
  import { callLast } from "../../utils/callLast";
5
6
  import { getEventValue } from "../../utils/getEventValue";
6
7
  import { FormControl, FormControlProps } from "../form-control/formControl.component";
@@ -1,4 +1,5 @@
1
1
  import React, { useState } from "react";
2
+
2
3
  import { iconClass } from "../../utils/iconClass";
3
4
  import { InputText } from "./inputText.component";
4
5
 
@@ -1,20 +1,21 @@
1
- import { render } from "@testing-library/react";
1
+ import { render, screen } from "@testing-library/react";
2
2
  import React from "react";
3
+
3
4
  import { Sandbox } from "./loader.stories";
4
5
  describe("Loader", () => {
5
6
  it("should render a component (when isActive = true)", () => {
6
- const { getByTestId } = render(<Sandbox isActive={true} />);
7
+ render(<Sandbox isActive={true} />);
7
8
 
8
- const icon = getByTestId("icon_radio-circle");
9
+ const icon = screen.getByTestId("icon_radio-circle");
9
10
 
10
11
  expect(icon).toBeTruthy();
11
12
  expect(icon).toBeInTheDocument();
12
13
  });
13
14
 
14
15
  it("should render a component (when isActive = false)", () => {
15
- const { queryByTestId } = render(<Sandbox isActive={false} />);
16
+ render(<Sandbox isActive={false} />);
16
17
 
17
- const icon = queryByTestId("icon_radio-circle");
18
+ const icon = screen.queryByTestId("icon_radio-circle");
18
19
 
19
20
  expect(icon).toBeFalsy();
20
21
  expect(icon).not.toBeInTheDocument();