@tsed/react-formio 1.12.0 → 1.13.2

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 (85) hide show
  1. package/dist/components/actions-table/actionsTable.component.d.ts +0 -1
  2. package/dist/components/actions-table/actionsTable.stories.d.ts +0 -1
  3. package/dist/components/alert/alert.component.d.ts +1 -2
  4. package/dist/components/alert/alert.stories.d.ts +0 -1
  5. package/dist/components/card/card.stories.d.ts +0 -1
  6. package/dist/components/form/form.component.d.ts +3 -2
  7. package/dist/components/form/form.component.spec.d.ts +1 -0
  8. package/dist/components/form/form.stories.d.ts +3689 -79
  9. package/dist/components/form/useForm.hook.d.ts +1 -1
  10. package/dist/components/form-access/formAccess.stories.d.ts +1 -2
  11. package/dist/components/form-action/formAction.stories.d.ts +0 -1
  12. package/dist/components/form-builder/formBuilder.stories.d.ts +518 -153
  13. package/dist/components/form-edit/formEdit.component.d.ts +0 -1
  14. package/dist/components/form-edit/formEdit.stories.d.ts +18 -19
  15. package/dist/components/form-settings/formSettings.component.d.ts +0 -1
  16. package/dist/components/form-settings/formSettings.stories.d.ts +1 -2
  17. package/dist/components/forms-table/components/formCell.component.d.ts +0 -1
  18. package/dist/components/forms-table/formsTable.component.d.ts +0 -1
  19. package/dist/components/forms-table/formsTable.stories.d.ts +0 -1
  20. package/dist/components/input-tags/inputTags.component.d.ts +0 -1
  21. package/dist/components/input-tags/inputTags.stories.d.ts +2 -3
  22. package/dist/components/input-text/inputText.component.d.ts +0 -1
  23. package/dist/components/input-text/inputText.stories.d.ts +0 -1
  24. package/dist/components/loader/loader.component.d.ts +1 -1
  25. package/dist/components/loader/loader.stories.d.ts +0 -1
  26. package/dist/components/modal/modal.component.d.ts +1 -1
  27. package/dist/components/modal/modal.stories.d.ts +0 -1
  28. package/dist/components/pagination/pagination.component.d.ts +0 -1
  29. package/dist/components/pagination/pagination.stories.d.ts +0 -1
  30. package/dist/components/react-component/reactComponent.component.d.ts +3 -3
  31. package/dist/components/select/select.stories.d.ts +2 -3
  32. package/dist/components/submissions-table/submissionsTable.component.d.ts +0 -1
  33. package/dist/components/submissions-table/submissionsTable.stories.d.ts +13 -14
  34. package/dist/components/table/components/defaultArrowSort.component.d.ts +0 -1
  35. package/dist/components/table/components/defaultCell.component.d.ts +0 -1
  36. package/dist/components/table/components/defaultCellHeader.component.d.ts +0 -1
  37. package/dist/components/table/components/defaultCellOperations.component.d.ts +0 -1
  38. package/dist/components/table/components/defaultOperationButton.component.d.ts +0 -1
  39. package/dist/components/table/filters/defaultColumnFilter.component.d.ts +0 -1
  40. package/dist/components/table/filters/selectColumnFilter.component.d.ts +0 -1
  41. package/dist/components/table/filters/sliderColumnFilter.component.d.ts +0 -1
  42. package/dist/components/table/table.stories.d.ts +4 -5
  43. package/dist/components/tabs/tabs.component.stories.d.ts +0 -1
  44. package/dist/hooks/useTooltip.d.ts +1 -1
  45. package/dist/index.js +342 -274
  46. package/dist/index.js.map +1 -1
  47. package/dist/index.modern.js +313 -268
  48. package/dist/index.modern.js.map +1 -1
  49. package/dist/stores/auth/auth.selectors.d.ts +1 -1
  50. package/jest.config.js +1 -1
  51. package/package.json +5 -5
  52. package/readme.md +51 -18
  53. package/src/components/__fixtures__/form.fixture.json +23 -0
  54. package/src/components/form/form.component.spec.tsx +56 -0
  55. package/src/components/form/form.component.tsx +5 -3
  56. package/src/components/form/form.stories.tsx +182 -11
  57. package/src/components/form/useForm.hook.ts +54 -29
  58. package/src/components/form-access/formAccess.component.tsx +1 -1
  59. package/src/components/form-access/formAccess.utils.ts +13 -13
  60. package/src/components/form-action/formAction.component.tsx +1 -1
  61. package/src/components/form-builder/formBuilder.component.tsx +1 -1
  62. package/src/components/form-edit/formCtas.component.tsx +32 -30
  63. package/src/components/form-edit/formEdit.component.tsx +1 -1
  64. package/src/components/form-settings/formSettings.utils.ts +3 -3
  65. package/src/components/input-tags/inputTags.component.tsx +3 -3
  66. package/src/components/input-text/inputText.component.spec.tsx +1 -1
  67. package/src/components/input-text/inputText.component.tsx +3 -3
  68. package/src/components/modal/modal.component.tsx +2 -2
  69. package/src/components/react-component/reactComponent.component.tsx +9 -6
  70. package/src/components/select/select.component.tsx +2 -2
  71. package/src/components/submissions-table/submissionsTable.component.tsx +6 -6
  72. package/src/components/table/table.component.tsx +58 -44
  73. package/src/components/table/utils/mapFormToColumns.tsx +1 -1
  74. package/src/components/tabs/tabs.component.tsx +1 -1
  75. package/src/hooks/useTooltip.ts +1 -1
  76. package/src/stores/action-info/action-info.selectors.ts +1 -1
  77. package/src/stores/auth/auth.utils.tsx +2 -2
  78. package/src/stores/auth/getAccess.action.ts +2 -2
  79. package/src/stores/auth/logout.action.spec.ts +1 -0
  80. package/src/stores/form/form.selectors.ts +1 -1
  81. package/src/stores/root/root.selectors.ts +2 -2
  82. package/tsconfig.json +10 -27
  83. package/tsconfig.node.json +8 -0
  84. package/craco.config.js +0 -11
  85. package/tsconfig.test.json +0 -6
@@ -1,10 +1,10 @@
1
- import { ExtendedComponentSchema } from "formiojs";
1
+ import {ExtendedComponentSchema} from "formiojs";
2
2
  import cloneDeep from "lodash/cloneDeep";
3
3
  import isEqual from "lodash/isEqual";
4
4
  import noop from "lodash/noop";
5
- import { FormSchema, Submission } from "../../interfaces";
6
- import { RoleSchema } from "../../interfaces/RoleSchema";
7
- import { getAccessPermissionForm, getSubmissionPermissionForm } from "./formAccess.schema";
5
+ import {FormSchema, Submission} from "../../interfaces";
6
+ import {RoleSchema} from "../../interfaces/RoleSchema";
7
+ import {getAccessPermissionForm, getSubmissionPermissionForm} from "./formAccess.schema";
8
8
 
9
9
  export interface Choice {
10
10
  label: string;
@@ -31,19 +31,19 @@ export type SubmissionAccess = {
31
31
  function rolesToChoices(roles: RoleSchema[]): Choice[] {
32
32
  return Object.values(roles).map((role) => {
33
33
  return {
34
- label: role.title,
35
- value: role._id
34
+ label: role.title || "",
35
+ value: role._id || ""
36
36
  };
37
37
  });
38
38
  }
39
39
 
40
- function accessToHash(keys: string[], access: Access[] = []): AccessRoles {
40
+ function accessToHash(keys: (string | undefined)[] | undefined, access: Access[] = []): AccessRoles {
41
41
  const hash = Object.values(access).reduce((o: any, role: any) => {
42
42
  o[role.type] = role.roles;
43
43
  return o;
44
44
  }, {});
45
45
 
46
- return keys.reduce((data, key) => {
46
+ return ((keys || []).filter(Boolean) as any[]).reduce((data, key: string) => {
47
47
  return {
48
48
  ...data,
49
49
  [key]: hash[key] || []
@@ -69,8 +69,8 @@ function hashToAccess(data: AccessRoles) {
69
69
 
70
70
  export function getFormAccess(roles: RoleSchema[]): FormAccessSchema {
71
71
  const choices = rolesToChoices(roles);
72
- const access = getAccessPermissionForm({ choices });
73
- const submissionAccess = getSubmissionPermissionForm({ choices });
72
+ const access = getAccessPermissionForm({choices});
73
+ const submissionAccess = getSubmissionPermissionForm({choices});
74
74
 
75
75
  return {
76
76
  access,
@@ -79,7 +79,7 @@ export function getFormAccess(roles: RoleSchema[]): FormAccessSchema {
79
79
  }
80
80
 
81
81
  export function dataAccessToSubmissions(form: Partial<FormSchema>, formAccess: FormAccessSchema): SubmissionAccess {
82
- const getKeys = (components: ExtendedComponentSchema[]) => components.map(({ key }) => key);
82
+ const getKeys = (components: ExtendedComponentSchema[]) => components.map(({key}) => key);
83
83
 
84
84
  return {
85
85
  access: {
@@ -100,14 +100,14 @@ export function submissionsToDataAccess(form: Partial<FormSchema>, submissions:
100
100
  }
101
101
 
102
102
  export function shouldUpdate(type: string, submission: Submission<AccessRoles>, submissions: SubmissionAccess) {
103
- return !isEqual(submission.data, submissions[type].data);
103
+ return !isEqual(submission.data, (submissions as any)[type].data);
104
104
  }
105
105
 
106
106
  export function updateSubmissions(type: string, submission: Submission<AccessRoles>, submissions: SubmissionAccess, cb: Function = noop) {
107
107
  if (shouldUpdate(type, submission, submissions)) {
108
108
  submissions = {
109
109
  ...submissions,
110
- [type]: { data: submission.data }
110
+ [type]: {data: submission.data}
111
111
  };
112
112
  cb(submissions);
113
113
  }
@@ -39,7 +39,7 @@ export interface FormActionProps {
39
39
 
40
40
  export function FormAction({ actionInfo, children, onSubmit, options, ...props }: PropsWithChildren<FormActionProps>): ReactElement {
41
41
  const { form, submission } = useMemo(() => {
42
- const submission = mapData(props.submission || {}, actionInfo.defaults);
42
+ const submission = mapData(props.submission || {}, actionInfo.defaults!);
43
43
  const form = mapSettingsForm(actionInfo.settingsForm);
44
44
 
45
45
  return { form, submission: { data: submission } };
@@ -175,7 +175,7 @@ export class FormBuilder extends React.Component<FormBuilderProps, any> {
175
175
 
176
176
  whenComponentsChange(components: ComponentSchema[]) {
177
177
  this.setState({ components }, () => {
178
- this.props?.onChange(components);
178
+ this.props?.onChange && this.props.onChange(components);
179
179
  });
180
180
  }
181
181
 
@@ -1,8 +1,8 @@
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
+ import {useTooltip} from "../../hooks/useTooltip";
4
+ import {FormOptions} from "../../interfaces";
5
+ import {iconClass} from "../../utils/iconClass";
6
6
 
7
7
  export interface FormEditCTAsProps extends Record<string, unknown> {
8
8
  saveText?: string;
@@ -18,38 +18,38 @@ export interface FormEditCTAsProps extends Record<string, unknown> {
18
18
  }
19
19
 
20
20
  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;
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;
33
33
 
34
- const copyTooltipRef = useTooltip({
34
+ const copyTooltipRef: any = useTooltip({
35
35
  trigger: "hover",
36
36
  placement: "top",
37
37
  title: t("Copy")
38
38
  });
39
39
 
40
- const undoTooltipRef = useTooltip({
40
+ const undoTooltipRef: any = useTooltip({
41
41
  trigger: "hover",
42
42
  placement: "top",
43
43
  title: t("Undo last change")
44
44
  });
45
45
 
46
- const redoTooltipRef = useTooltip({
46
+ const redoTooltipRef: any = useTooltip({
47
47
  trigger: "hover",
48
48
  placement: "top",
49
49
  title: t("Redo last change")
50
50
  });
51
51
 
52
- const resetTooltipRef = useTooltip({
52
+ const resetTooltipRef: any = useTooltip({
53
53
  trigger: "hover",
54
54
  placement: "top",
55
55
  title: t("Reset all changes")
@@ -61,31 +61,33 @@ export function FormEditCTAs({
61
61
  <button
62
62
  className={`btn btn-primary btn-save flex ${disabled ? "disabled" : ""}`}
63
63
  disabled={disabled}
64
- onClick={() => !disabled && onSubmit()}
64
+ onClick={() => !disabled && onSubmit && onSubmit()}
65
65
  >
66
- <i className={`mr-1 ${iconClass(options.iconset, "save")}`} />
66
+ <i className={`mr-1 ${iconClass(options.iconset, "save")}`}/>
67
67
  {saveText}
68
68
  </button>
69
69
 
70
70
  <div>
71
- <button className={`btn btn-light btn-undo ${hasUndo ? "" : "disabled"}`} onClick={() => onUndo()} ref={undoTooltipRef}>
72
- <i className={iconClass(options.iconset, "undo")} />
71
+ <button className={`btn btn-light btn-undo ${hasUndo ? "" : "disabled"}`} onClick={() => onUndo && onUndo()}
72
+ ref={undoTooltipRef}>
73
+ <i className={iconClass(options.iconset, "undo")}/>
73
74
  </button>
74
75
 
75
- <button className={`btn btn-light btn-redo ${hasRedo ? "" : "disabled"}`} onClick={() => onRedo()} ref={redoTooltipRef}>
76
- <i className={iconClass(options.iconset, "redo")} />
76
+ <button className={`btn btn-light btn-redo ${hasRedo ? "" : "disabled"}`} onClick={() => onRedo && onRedo()}
77
+ ref={redoTooltipRef}>
78
+ <i className={iconClass(options.iconset, "redo")}/>
77
79
  </button>
78
80
  </div>
79
81
 
80
82
  <div>
81
83
  {onCopy && (
82
- <button className='btn btn-light' onClick={() => onCopy()} ref={copyTooltipRef}>
83
- <i className={iconClass(options.iconset, "copy")} />
84
+ <button className="btn btn-light" onClick={() => onCopy()} ref={copyTooltipRef!}>
85
+ <i className={iconClass(options.iconset, "copy")}/>
84
86
  </button>
85
87
  )}
86
88
 
87
- <button className={`btn btn-light btn-reset`} onClick={() => onReset()} ref={resetTooltipRef}>
88
- <i className={iconClass(options.iconset, "reset")} />
89
+ <button className={`btn btn-light btn-reset`} onClick={() => onReset && onReset()} ref={resetTooltipRef!}>
90
+ <i className={iconClass(options.iconset, "reset")}/>
89
91
  </button>
90
92
  </div>
91
93
  </div>
@@ -37,7 +37,7 @@ export function FormEdit(props: FormEditProps) {
37
37
 
38
38
  <FormBuilder
39
39
  key={`form-builder-${form._id}`}
40
- components={form.components}
40
+ components={form.components!}
41
41
  display={form.display}
42
42
  options={options}
43
43
  builder={builder}
@@ -10,9 +10,9 @@ export type FormSettingsSchema = {
10
10
  export function formSettingsToSubmission(form: Partial<FormSchema>): Submission<FormSettingsSchema> {
11
11
  return {
12
12
  data: {
13
- action: form.action,
14
- tags: form.tags,
15
- properties: form.properties
13
+ action: form.action!,
14
+ tags: form.tags!,
15
+ properties: form.properties!
16
16
  }
17
17
  };
18
18
  }
@@ -14,7 +14,7 @@ export interface InputTagsProps<T = any> extends Omit<FormControlProps, "descrip
14
14
  }
15
15
 
16
16
  export function InputTags({ name, value = [], label, onChange, required, description, prefix, suffix, ...props }: InputTagsProps) {
17
- const ref = useRef();
17
+ const ref: any = useRef();
18
18
 
19
19
  useEffect(() => {
20
20
  const instance = new Choices(ref.current, {
@@ -26,11 +26,11 @@ export function InputTags({ name, value = [], label, onChange, required, descrip
26
26
  instance.setValue([].concat(value, []));
27
27
 
28
28
  instance.passedElement.element.addEventListener("addItem", (event: any) => {
29
- onChange(name, uniq(value.concat(event.detail.value)));
29
+ onChange && onChange(name, uniq(value.concat(event.detail.value)));
30
30
  });
31
31
 
32
32
  instance.passedElement.element.addEventListener("removeItem", (event: any) => {
33
- onChange(
33
+ onChange && onChange(
34
34
  name,
35
35
  value.filter((v: string) => v !== event.detail.value)
36
36
  );
@@ -25,7 +25,7 @@ describe("input-text", () => {
25
25
  const input = getByTestId("input_test") as HTMLInputElement;
26
26
 
27
27
  expect(input).toBeInTheDocument();
28
- expect(input).toHaveDisplayValue(placeholderTest);
28
+ expect(input).toHaveAttribute("placeholder", placeholderTest);
29
29
  });
30
30
 
31
31
  it("should change the value of the input-text", () => {
@@ -35,7 +35,7 @@ export function InputText<T = any>({
35
35
  }: InputTextProps<T>) {
36
36
  const [localValue, setValue] = useState(value);
37
37
 
38
- const change = useMemo(() => callLast(onChange, 300), [onChange]);
38
+ const change = useMemo(() => onChange && callLast(onChange, 300), [onChange]);
39
39
 
40
40
  useEffect(() => {
41
41
  setValue(value);
@@ -58,13 +58,13 @@ export function InputText<T = any>({
58
58
  className={classnames("form-control", size && `form-control-${size}`)}
59
59
  id={name}
60
60
  required={required}
61
- value={(localValue || placeholder || "") as any}
61
+ value={(localValue || "") as any}
62
62
  placeholder={placeholder}
63
63
  onChange={(event) => {
64
64
  const value = getEventValue(event);
65
65
  setValue(value);
66
66
 
67
- return change(name, value);
67
+ return change && change(name, value);
68
68
  }}
69
69
  />
70
70
  </FormControl>
@@ -37,8 +37,8 @@ export function Modal({
37
37
  className = "",
38
38
  ...props
39
39
  }: PropsWithChildren<ModalProps>) {
40
- const titleRef = useRef<HTMLDivElement>();
41
- const footerRef = useRef<HTMLDivElement>();
40
+ const titleRef: any = useRef<HTMLDivElement>();
41
+ const footerRef: any = useRef<HTMLDivElement>();
42
42
  const [maxHeight, setMaxHeight] = useState<string>();
43
43
 
44
44
  const onClickClose = () => {
@@ -4,8 +4,8 @@ import { Submission } from "../../interfaces/Submission";
4
4
 
5
5
  export class ReactComponent<Data = any> extends Components.components.field {
6
6
  public reactInstance: any;
7
- public shouldSetValue: boolean;
8
- private dataForSetting: Data;
7
+ public shouldSetValue?: boolean;
8
+ private dataForSetting?: Data;
9
9
 
10
10
  /**
11
11
  * This is the first phase of component building where the component is instantiated.
@@ -20,7 +20,7 @@ export class ReactComponent<Data = any> extends Components.components.field {
20
20
  }
21
21
 
22
22
  get $reactNode() {
23
- return this.refs[`react-${this.id}`];
23
+ return (this.refs as any)[`react-${this.id}`];
24
24
  }
25
25
 
26
26
  /**
@@ -67,7 +67,9 @@ export class ReactComponent<Data = any> extends Components.components.field {
67
67
  [`react-${this.id}`]: "single"
68
68
  });
69
69
 
70
+ // @ts-ignore
70
71
  if (this.refs[`react-${this.id}`]) {
72
+ // @ts-ignore
71
73
  this.reactInstance = this.attachReact(this.refs[`react-${this.id}`]);
72
74
 
73
75
  if (this.shouldSetValue) {
@@ -82,7 +84,9 @@ export class ReactComponent<Data = any> extends Components.components.field {
82
84
  * or it is being removed from the form.
83
85
  */
84
86
  detach() {
87
+ // @ts-ignore
85
88
  if (this.refs[`react-${this.id}`]) {
89
+ // @ts-ignore
86
90
  this.detachReact(this.refs[`react-${this.id}`]);
87
91
  }
88
92
  super.detach();
@@ -122,8 +126,7 @@ export class ReactComponent<Data = any> extends Components.components.field {
122
126
  * @param value
123
127
  * @param flags
124
128
  */
125
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
126
- setValue(value: any, flags?: any): boolean {
129
+ setValue(value: any, flags?: any) {
127
130
  if (this.reactInstance) {
128
131
  this.reactInstance.setState({
129
132
  value: value
@@ -134,7 +137,7 @@ export class ReactComponent<Data = any> extends Components.components.field {
134
137
  this.dataForSetting = value;
135
138
  }
136
139
 
137
- return undefined;
140
+ return false
138
141
  }
139
142
 
140
143
  /**
@@ -33,7 +33,7 @@ export function Select<T = any>({
33
33
  layout,
34
34
  ...props
35
35
  }: SelectProps<T>): ReactElement {
36
- const ref = useRef();
36
+ const ref = useRef<any>();
37
37
 
38
38
  useEffect(() => {
39
39
  let instance: any;
@@ -75,7 +75,7 @@ export function Select<T = any>({
75
75
  value={value || ("" as any)}
76
76
  placeholder={placeholder}
77
77
  onChange={(event) => {
78
- onChange(name, getEventValue(event));
78
+ onChange && onChange(name, getEventValue(event));
79
79
  }}
80
80
  >
81
81
  {choices.map(({ label, value }) => {
@@ -1,14 +1,14 @@
1
1
  import React from "react";
2
- import { FormSchema, Submission } from "../../interfaces";
3
- import { Table, TableProps } from "../table/table.component";
4
- import { mapFormToColumns } from "../table/utils/mapFormToColumns";
2
+ import {FormSchema, Submission} from "../../interfaces";
3
+ import {Table, TableProps} from "../table/table.component";
4
+ import {mapFormToColumns} from "../table/utils/mapFormToColumns";
5
5
 
6
6
  export type SubmissionsTableProps = Omit<TableProps<Submission>, "columns"> & {
7
7
  form?: FormSchema;
8
8
  };
9
9
 
10
- export function SubmissionsTable({ form, ...props }: SubmissionsTableProps) {
11
- const columns: any[] = React.useMemo(() => form && mapFormToColumns(form), [form]);
10
+ export function SubmissionsTable({form, ...props}: SubmissionsTableProps) {
11
+ const columns: any[] | undefined = form && mapFormToColumns(form);
12
12
 
13
- return <Table {...props} columns={columns} />;
13
+ return <Table {...props} columns={columns!}/>;
14
14
  }
@@ -1,13 +1,23 @@
1
1
  import classnames from "classnames";
2
2
  import noop from "lodash/noop";
3
- import React, { PropsWithChildren } from "react";
4
- import { CellProps, FilterProps, Renderer, TableOptions, useFilters, useGroupBy, usePagination, useSortBy, useTable } from "react-table";
5
- import { OnClickOperation, Operation, QueryOptions } from "../../interfaces";
6
- import { Pagination as DefaultPagination } from "../pagination/pagination.component";
7
- import { DefaultArrowSort } from "./components/defaultArrowSort.component";
8
- import { DefaultCellHeader, DefaultCellHeaderProps } from "./components/defaultCellHeader.component";
9
- import { DefaultColumnFilter } from "./filters/defaultColumnFilter.component";
10
- import { useOperations } from "./utils/useOperations.hook";
3
+ import React, {PropsWithChildren} from "react";
4
+ import {
5
+ CellProps,
6
+ FilterProps,
7
+ Renderer,
8
+ TableOptions,
9
+ useFilters,
10
+ useGroupBy,
11
+ usePagination,
12
+ useSortBy,
13
+ useTable
14
+ } from "react-table";
15
+ import {OnClickOperation, Operation, QueryOptions} from "../../interfaces";
16
+ import {Pagination as DefaultPagination} from "../pagination/pagination.component";
17
+ import {DefaultArrowSort} from "./components/defaultArrowSort.component";
18
+ import {DefaultCellHeader, DefaultCellHeaderProps} from "./components/defaultCellHeader.component";
19
+ import {DefaultColumnFilter} from "./filters/defaultColumnFilter.component";
20
+ import {useOperations} from "./utils/useOperations.hook";
11
21
 
12
22
  export interface TableProps<Data extends object = any> extends TableOptions<Data>, Partial<QueryOptions> {
13
23
  className?: string;
@@ -92,7 +102,7 @@ function DefaultLoader() {
92
102
  }
93
103
 
94
104
  function DefaultEmptyData() {
95
- return <div className='text-center p-2 pb-4 font-bold'>No data found</div>;
105
+ return <div className="text-center p-2 pb-4 font-bold">No data found</div>;
96
106
  }
97
107
 
98
108
  const hooks = [useFilters, useGroupBy, useSortBy, usePagination];
@@ -161,12 +171,12 @@ export function Table<Data extends object = any>(props: PropsWithChildren<TableP
161
171
  setFilterId
162
172
  } as any,
163
173
  ...hooks,
164
- useOperations({ operations, CellOperations, onClick: _onClick, ctx, i18n })
174
+ useOperations({operations, CellOperations, onClick: _onClick, ctx, i18n})
165
175
  );
166
176
 
167
177
  const {
168
178
  setPageSize,
169
- state: { pageIndex, pageSize, sortBy, filters }
179
+ state: {pageIndex, pageSize, sortBy, filters}
170
180
  } = tableInstance;
171
181
 
172
182
  React.useEffect(() => {
@@ -188,45 +198,49 @@ export function Table<Data extends object = any>(props: PropsWithChildren<TableP
188
198
  /* style={{ marginBottom: disablePagination ? "-1px" : "0px" }} */
189
199
  >
190
200
  <thead>
191
- {tableInstance.headerGroups.map((headerGroup, i) => (
192
- <tr key={`tableInstance.headerGroups${i}`} {...headerGroup.getHeaderGroupProps()}>
193
- {headerGroup.headers.map((column) => (
194
- <th
195
- key={`tableInstance.headers.column.${column.id}`}
196
- /* className='text-left py-2 align-top' */
197
- {...column.getHeaderProps()}
198
- >
199
- <CellHeader column={column} />
200
- </th>
201
- ))}
202
- </tr>
203
- ))}
201
+ {tableInstance.headerGroups.map((headerGroup, i) => (
202
+ <tr {...headerGroup.getHeaderGroupProps()} key={`tableInstance.headerGroups${i}`}>
203
+ {headerGroup.headers.map((column) => (
204
+ <th
205
+ /* className='text-left py-2 align-top' */
206
+ {...column.getHeaderProps()}
207
+ key={`tableInstance.headers.column.${column.id}`}
208
+ >
209
+ <CellHeader column={column}/>
210
+ </th>
211
+ ))}
212
+ </tr>
213
+ ))}
204
214
  </thead>
205
215
  {!isLoading ? (
206
216
  <tbody {...tableInstance.getTableBodyProps()}>
207
- {tableInstance.page.map((row) => {
208
- tableInstance.prepareRow(row);
209
- return (
210
- <tr key={`tableInstance.page.${row.id}`} onClick={() => _onClick(row.original, "row")} {...row.getRowProps()}>
211
- {row.cells.map((cell, i) => {
212
- const { hidden, colspan } = cell.column as any;
213
- if (hidden) {
214
- return null;
215
- }
216
- return (
217
- <td key={`tableInstance.page.cells.${cell.value || "value"}.${i}`} colSpan={colspan} {...cell.getCellProps()}>
218
- {cell.render("Cell")}
219
- </td>
220
- );
221
- })}
222
- </tr>
223
- );
224
- })}
217
+ {tableInstance.page.map((row) => {
218
+ tableInstance.prepareRow(row);
219
+ return (
220
+ <tr onClick={() => _onClick(row.original, "row")} {...row.getRowProps()}
221
+ key={`tableInstance.page.${row.id}`}>
222
+ {row.cells.map((cell, i) => {
223
+ const {hidden, colspan} = cell.column as any;
224
+ if (hidden) {
225
+ return null;
226
+ }
227
+ return (
228
+ <td
229
+ colSpan={colspan}
230
+ {...cell.getCellProps()}
231
+ key={`tableInstance.page.cells.${cell.value || "value"}.${i}`}>
232
+ {cell.render("Cell")}
233
+ </td>
234
+ );
235
+ })}
236
+ </tr>
237
+ );
238
+ })}
225
239
  </tbody>
226
240
  ) : null}
227
241
  </table>
228
- {isLoading ? <Loader /> : null}
229
- {!data.length ? <EmptyData /> : null}
242
+ {isLoading ? <Loader/> : null}
243
+ {!data.length ? <EmptyData/> : null}
230
244
  {!isLoading && data.length && !disablePagination ? (
231
245
  <div className={"overflow-hidden"}>
232
246
  <Pagination
@@ -11,7 +11,7 @@ export function mapFormToColumns(form: FormSchema): Column[] {
11
11
 
12
12
  FormioUtils.eachComponent(form.components, (component: ExtendedComponentSchema) => {
13
13
  if (component.tableView && component.key) {
14
- const cmp: any = Components.create(component, null, null, true);
14
+ const cmp: any = Components.create(component, {}, null, true);
15
15
 
16
16
  const column: Column = {
17
17
  Header: component.label || component.title || component.key,
@@ -71,7 +71,7 @@ export function Tabs({
71
71
  {...additionalProps}
72
72
  {...item}
73
73
  >
74
- {i18n(item.label)}
74
+ {i18n(item.label || "")}
75
75
  </Button>
76
76
  );
77
77
  })}
@@ -2,7 +2,7 @@ import { useEffect, useRef } from "react";
2
2
  import Tooltip, { Options } from "tooltip.js";
3
3
 
4
4
  export function useTooltip(options: Options) {
5
- const ref = useRef();
5
+ const ref = useRef<any>();
6
6
 
7
7
  useEffect(() => {
8
8
  ref.current && new Tooltip(ref.current as any, options);
@@ -3,4 +3,4 @@ import { selectRoot } from "../root";
3
3
  import { ACTION_INFO } from "./action-info.constant";
4
4
  import { ActionInfoState } from "./action-info.reducers";
5
5
 
6
- export const selectActionInfo = (state: Record<string, any>): Partial<ActionSchema> => selectRoot<ActionInfoState>(ACTION_INFO, state).data;
6
+ export const selectActionInfo = (state: Record<string, any>): Partial<ActionSchema> => selectRoot<ActionInfoState>(ACTION_INFO, state).data!;
@@ -7,7 +7,7 @@ export function hasRole(auth: AuthState, role: string): boolean {
7
7
  }
8
8
 
9
9
  export function hasRoles(auth: AuthState, roles: string[]): boolean {
10
- roles = [].concat(roles);
10
+ roles = ([] as string[]).concat(roles);
11
11
 
12
12
  return !!roles.find((role) => hasRole(auth, role));
13
13
  }
@@ -29,7 +29,7 @@ export function checkRoleFormAccess(auth: AuthState, form?: Partial<FormSchema>,
29
29
  return true;
30
30
  }
31
31
 
32
- return !!(roles.includes("owner") && get(form, "owner") === get(auth, "user._id"));
32
+ return (roles.includes("owner") && get(form, "owner") === get(auth, "user._id"));
33
33
  }
34
34
 
35
35
  return true;
@@ -8,7 +8,7 @@ function transformSubmissionAccess(forms: Record<string, FormSchema>) {
8
8
  return Object.values(forms).reduce(
9
9
  (result, form) => ({
10
10
  ...result,
11
- [form.name]: form.submissionAccess.reduce(
11
+ [form.name as string]: form.submissionAccess.reduce(
12
12
  (formSubmissionAccess: any, access: any) => ({
13
13
  ...formSubmissionAccess,
14
14
  [access.type]: access.roles
@@ -24,7 +24,7 @@ function transformFormAccess(forms: Record<string, FormSchema>) {
24
24
  return Object.values(forms).reduce(
25
25
  (result, form) => ({
26
26
  ...result,
27
- [form.name]: form.access.reduce(
27
+ [form.name as string]: form.access.reduce(
28
28
  (formAccess: any, access: any) => ({
29
29
  ...formAccess,
30
30
  [access.type]: access.roles
@@ -4,6 +4,7 @@ import { AUTH } from "./auth.constant";
4
4
  import { logout } from "./logout.action";
5
5
 
6
6
  jest.mock("./auth.actions");
7
+ jest.mock('formiojs')
7
8
 
8
9
  describe("logout()", () => {
9
10
  beforeEach(() => {
@@ -2,4 +2,4 @@ import { FormSchema } from "../../interfaces";
2
2
  import { selectRoot } from "../root";
3
3
  import { FormState } from "./form.reducers";
4
4
 
5
- export const selectForm = (name: string, state: any): Partial<FormSchema> => selectRoot<FormState>(name, state).data;
5
+ export const selectForm = (name: string, state: any): Partial<FormSchema> => selectRoot<FormState>(name, state).data!;
@@ -10,9 +10,9 @@ export function selectRoot<State = Record<string, any>>(name: string, state?: Re
10
10
  return (state: Record<string, any>) => selectRoot(name, state);
11
11
  }
12
12
 
13
- export const selectError = (name: string, state: Record<string, any>): null | Error => get(selectRoot(name, state), "error");
13
+ export const selectError = (name: string, state: Record<string, any>): null | Error => get(selectRoot(name, state)!, "error");
14
14
 
15
- export const selectIsActive = (name: string, state: Record<string, any>): boolean => get(selectRoot(name, state), "isActive");
15
+ export const selectIsActive = (name: string, state: Record<string, any>): boolean => get(selectRoot(name, state)!, "isActive");
16
16
 
17
17
  export function oneOfIsActive(...names: string[]) {
18
18
  return (state: any) => {