@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
@@ -29,18 +29,8 @@ export function useOperations<D extends object = {}>({
29
29
  {
30
30
  id: "operations",
31
31
  groupByBoundary: true,
32
- Header: () => (
33
- <div className={"text-center"}>{i18n("Operations")}</div>
34
- ),
35
- Cell: (props: any) => (
36
- <CellOperations
37
- {...props}
38
- operations={operations}
39
- onClick={onClick}
40
- ctx={ctx}
41
- i18n={i18n}
42
- />
43
- )
32
+ Header: () => <div className={"text-center"}>{i18n("Operations")}</div>,
33
+ Cell: (props: any) => <CellOperations {...props} operations={operations} onClick={onClick} ctx={ctx} i18n={i18n} />
44
34
  }
45
35
  ];
46
36
  });
@@ -0,0 +1,86 @@
1
+ import * as React from "react";
2
+ import {fireEvent, render, screen} from "@testing-library/react";
3
+ import {Sandbox} from "./tabs.component.stories";
4
+ import {Tabs} from "./tabs.component";
5
+
6
+ describe("tabs", () => {
7
+ it("should display the tabs component and children", () => {
8
+ const items = [
9
+ {
10
+ action: "back",
11
+ exact: true,
12
+ icon: "chevron-left",
13
+ back: true
14
+ },
15
+ {
16
+ action: "edit",
17
+ exact: true,
18
+ icon: "edit",
19
+ label: "Edit"
20
+ }
21
+ ];
22
+
23
+ render(<Sandbox {...Sandbox.args} items={items}/>);
24
+
25
+ const tabsComponent = screen.getByTestId("tabs-comp");
26
+
27
+ const buttonsTabWrapper = screen.getAllByTitle("button-wrapper");
28
+ const chevronLeftButtonTabWrapper = buttonsTabWrapper[0];
29
+ const editButtonTabWrapper = buttonsTabWrapper[1];
30
+
31
+ const buttonsTab = screen.getAllByTitle("button-tab");
32
+ const chevronLeftButtonTab = buttonsTab[0];
33
+ const editButtonTab = buttonsTab[1];
34
+
35
+ const fontAwsomeChevronLeftIcon = "fa fa-chevron-left";
36
+ const fontAwsomeEditIcon = "fa fa-edit";
37
+
38
+ expect(tabsComponent).toBeInTheDocument();
39
+
40
+ expect(chevronLeftButtonTabWrapper).toContainElement(chevronLeftButtonTab);
41
+ expect(chevronLeftButtonTabWrapper).toContainHTML("-back");
42
+ expect(chevronLeftButtonTab).toBeInTheDocument();
43
+ expect(chevronLeftButtonTab).toContainHTML(fontAwsomeChevronLeftIcon);
44
+ expect(chevronLeftButtonTab).toHaveTextContent("");
45
+
46
+ expect(editButtonTabWrapper).toContainElement(editButtonTab);
47
+ expect(editButtonTabWrapper).not.toContainHTML("-back");
48
+ expect(editButtonTab).toBeInTheDocument();
49
+ expect(editButtonTab).toContainHTML(fontAwsomeEditIcon);
50
+ expect(editButtonTab).toHaveTextContent("Edit");
51
+ });
52
+
53
+ it("should call dispatcher when clicking on a button tab", () => {
54
+ const items = [
55
+ {
56
+ action: "back",
57
+ exact: true,
58
+ icon: "chevron-left",
59
+ back: true
60
+ },
61
+ {
62
+ action: "edit",
63
+ exact: true,
64
+ icon: "edit",
65
+ label: "Edit"
66
+ }
67
+ ];
68
+ const onClick = jest.fn();
69
+
70
+ render(<Tabs items={items} onClick={onClick}/>);
71
+
72
+ const buttonsTab = screen.getAllByTitle("button-tab");
73
+ const chevronLeftButtonTab = buttonsTab[0];
74
+ const editButtonTab = buttonsTab[1];
75
+
76
+ fireEvent.click(chevronLeftButtonTab);
77
+
78
+ expect(onClick).toHaveBeenCalledTimes(1);
79
+ expect(onClick).toHaveBeenCalledWith(items[0]);
80
+
81
+ fireEvent.click(editButtonTab);
82
+
83
+ expect(onClick).toHaveBeenCalledTimes(2);
84
+ expect(onClick).toHaveBeenCalledWith(items[1]);
85
+ });
86
+ });
@@ -93,9 +93,7 @@ function AddButton({ onCreate }: any) {
93
93
  }
94
94
 
95
95
  function HeaderChildren() {
96
- return (
97
- <div className={"px-3 bg-gray-100 border-b-1 border-gray-light"}>test</div>
98
- );
96
+ return <div className={"px-3 bg-gray-100 border-b-1 border-gray-light"}>test</div>;
99
97
  }
100
98
 
101
99
  export const WithCloseable = (args: any) => {
@@ -104,12 +102,7 @@ export const WithCloseable = (args: any) => {
104
102
 
105
103
  return (
106
104
  <div className={"border-gray-300 border-1 shadow"}>
107
- <Tabs
108
- {...tabs}
109
- i18n={(f) => f}
110
- AddButton={AddButton}
111
- HeaderChildren={HeaderChildren}
112
- >
105
+ <Tabs {...tabs} i18n={(f) => f} AddButton={AddButton} HeaderChildren={HeaderChildren}>
113
106
  <div className={"p-5"}>{tabs?.current?.action}</div>
114
107
  </Tabs>
115
108
  </div>
@@ -2,51 +2,19 @@ import classnames from "classnames";
2
2
  import React, { PropsWithChildren } from "react";
3
3
  import { iconClass } from "../../utils/iconClass";
4
4
 
5
- export function ButtonTab({
6
- icon,
7
- back,
8
- onClick,
9
- isActive,
10
- reverse,
11
- children,
12
- className,
13
- after
14
- }: PropsWithChildren<any>) {
5
+ export function ButtonTab({ icon, back, onClick, isActive, reverse, children, className, after }: PropsWithChildren<any>) {
15
6
  return (
16
- <div
17
- className={classnames(
18
- "tw-tabs__button-wrapper",
19
- isActive ? "-active" : "",
20
- back ? "-back" : "",
21
- className
22
- )}
23
- >
7
+ <div title={'button-wrapper'} className={classnames("tw-tabs__button-wrapper", isActive ? "-active" : "", back ? "-back" : "", className)}>
24
8
  <button
25
- className={classnames(
26
- "tw-tabs__button",
27
- reverse ? "-reverse" : "",
28
- isActive ? "-active" : "",
29
- back ? "-back" : ""
30
- )}
9
+ title={'button-tab'}
10
+ className={classnames("tw-tabs__button", reverse ? "-reverse" : "", isActive ? "-active" : "", back ? "-back" : "")}
31
11
  onClick={onClick}
32
12
  >
33
- {icon && (
34
- <i
35
- className={classnames(
36
- iconClass(undefined, icon),
37
- "tw-tabs__button-icon"
38
- )}
39
- />
40
- )}
13
+ {icon && <i className={classnames(iconClass(undefined, icon), "tw-tabs__button-icon")} />}
41
14
  <span className={"tw-tabs__button-label"}>{children}</span>
42
15
  {after}
43
16
  </button>
44
- <div
45
- className={classnames(
46
- "tw-tabs__button-border",
47
- isActive ? "-active" : ""
48
- )}
49
- />
17
+ <div className={classnames("tw-tabs__button-border", isActive ? "-active" : "")} />
50
18
  </div>
51
19
  );
52
20
  }
@@ -83,7 +51,7 @@ export function Tabs({
83
51
  ...additionalProps
84
52
  }: PropsWithChildren<TabsProps>) {
85
53
  return (
86
- <div className={`tw-tabs ${className}`} style={style}>
54
+ <div data-testid={'tabs-comp'} className={`tw-tabs ${className}`} style={style}>
87
55
  <div>
88
56
  <nav className='tw-tabs__header'>
89
57
  <div className='tw-tabs__header-wrapper'>
@@ -110,11 +78,9 @@ export function Tabs({
110
78
  {AddButton && <AddButton {...additionalProps} current={current} />}
111
79
  </div>
112
80
  </nav>
113
- {HeaderChildren && (
114
- <HeaderChildren {...additionalProps} current={current} />
115
- )}
81
+ {HeaderChildren && <HeaderChildren {...additionalProps} current={current} />}
116
82
  </div>
117
- <div className={"tw-tabs__body"}>{children}</div>
83
+ <div title={"tab-body"} className={"tw-tabs__body"}>{children}</div>
118
84
  </div>
119
85
  );
120
86
  }
@@ -2,10 +2,7 @@ import React from "react";
2
2
  import { OperationButtonProps } from "../components/table/components/defaultOperationButton.component";
3
3
 
4
4
  export type PermissionsResolver<Data = any> = (data: Data, ctx: any) => void;
5
- export type OnClickOperation<Data = any> = (
6
- data: Data,
7
- operation: Operation
8
- ) => void;
5
+ export type OnClickOperation<Data = any> = (data: Data, operation: Operation) => void;
9
6
 
10
7
  export interface Operation<Data = any> {
11
8
  /**
@@ -45,9 +45,7 @@ import {
45
45
  } from "react-table";
46
46
 
47
47
  declare module "react-table" {
48
- export interface UseFlexLayoutInstanceProps<
49
- D extends Record<string, unknown>
50
- > {
48
+ export interface UseFlexLayoutInstanceProps<D extends Record<string, unknown>> {
51
49
  totalColumnsMinWidth: number;
52
50
  }
53
51
 
@@ -66,17 +64,13 @@ declare module "react-table" {
66
64
  UseRowSelectOptions<D>,
67
65
  UseSortByOptions<D> {}
68
66
 
69
- export interface Hooks<
70
- D extends Record<string, unknown> = Record<string, unknown>
71
- >
67
+ export interface Hooks<D extends Record<string, unknown> = Record<string, unknown>>
72
68
  extends UseExpandedHooks<D>,
73
69
  UseGroupByHooks<D>,
74
70
  UseRowSelectHooks<D>,
75
71
  UseSortByHooks<D> {}
76
72
 
77
- export interface TableInstance<
78
- D extends Record<string, unknown> = Record<string, unknown>
79
- >
73
+ export interface TableInstance<D extends Record<string, unknown> = Record<string, unknown>>
80
74
  extends UseColumnOrderInstanceProps<D>,
81
75
  UseExpandedInstanceProps<D>,
82
76
  UseFiltersInstanceProps<D>,
@@ -88,9 +82,7 @@ declare module "react-table" {
88
82
  UsePaginationInstanceProps<D>,
89
83
  UseSortByInstanceProps<D> {}
90
84
 
91
- export interface TableState<
92
- D extends Record<string, unknown> = Record<string, unknown>
93
- >
85
+ export interface TableState<D extends Record<string, unknown> = Record<string, unknown>>
94
86
  extends UseColumnOrderState<D>,
95
87
  UseExpandedState<D>,
96
88
  UseFiltersState<D>,
@@ -103,9 +95,7 @@ declare module "react-table" {
103
95
  rowCount: number;
104
96
  }
105
97
 
106
- export interface ColumnInterface<
107
- D extends Record<string, unknown> = Record<string, unknown>
108
- >
98
+ export interface ColumnInterface<D extends Record<string, unknown> = Record<string, unknown>>
109
99
  extends UseFiltersColumnOptions<D>,
110
100
  UseGroupByColumnOptions<D>,
111
101
  UseResizeColumnsColumnOptions<D>,
@@ -113,25 +103,16 @@ declare module "react-table" {
113
103
  align?: string;
114
104
  }
115
105
 
116
- export interface ColumnInstance<
117
- D extends Record<string, unknown> = Record<string, unknown>
118
- >
106
+ export interface ColumnInstance<D extends Record<string, unknown> = Record<string, unknown>>
119
107
  extends UseFiltersColumnProps<D>,
120
108
  UseGroupByColumnProps<D>,
121
109
  UseResizeColumnsColumnProps<D>,
122
110
  UseFlexLayoutColumnProps<D>,
123
111
  UseSortByColumnProps<D> {}
124
112
 
125
- export type Cell<
126
- D extends Record<string, unknown> = Record<string, unknown>
127
- > = UseGroupByCellProps<D>;
113
+ export type Cell<D extends Record<string, unknown> = Record<string, unknown>> = UseGroupByCellProps<D>;
128
114
 
129
- export interface Row<D extends object = {}>
130
- extends UseExpandedRowProps<D>,
131
- UseGroupByRowProps<D>,
132
- UseRowSelectRowProps<D> {}
115
+ export interface Row<D extends object = {}> extends UseExpandedRowProps<D>, UseGroupByRowProps<D>, UseRowSelectRowProps<D> {}
133
116
  }
134
117
 
135
- export type TableMouseEventHandler = (
136
- instance: TableInstance<T>
137
- ) => MouseEventHandler;
118
+ export type TableMouseEventHandler = (instance: TableInstance<T>) => MouseEventHandler;
@@ -18,45 +18,43 @@ function getFormio(formId: string, id: string) {
18
18
  return new Formio(url);
19
19
  }
20
20
 
21
- export const getAction = (
22
- formId: string,
23
- actionId: string,
24
- done = noop
25
- ) => async (dispatch: any) => {
26
- dispatch(clearActionError(ACTION));
27
- dispatch(requestAction(ACTION));
21
+ export const getAction =
22
+ (formId: string, actionId: string, done = noop) =>
23
+ async (dispatch: any) => {
24
+ dispatch(clearActionError(ACTION));
25
+ dispatch(requestAction(ACTION));
28
26
 
29
- const formio = getFormio(formId, actionId);
27
+ const formio = getFormio(formId, actionId);
30
28
 
31
- try {
32
- const action = await formio.loadAction();
29
+ try {
30
+ const action = await formio.loadAction();
33
31
 
34
- dispatch(getActionInfo(formId, action.name));
35
- dispatch(receiveAction(ACTION, { action }));
36
- done(null, action);
37
- } catch (error) {
38
- dispatch(failAction(ACTION, { error }));
39
- done(error);
40
- }
41
- };
32
+ dispatch(getActionInfo(formId, action.name));
33
+ dispatch(receiveAction(ACTION, { action }));
34
+ done(null, action);
35
+ } catch (error) {
36
+ dispatch(failAction(ACTION, { error }));
37
+ done(error);
38
+ }
39
+ };
42
40
 
43
- export const saveAction = (formId: string, action: any, done = noop) => async (
44
- dispatch: any
45
- ) => {
46
- dispatch(clearActionError(ACTION));
47
- dispatch(sendAction(ACTION, { action }));
41
+ export const saveAction =
42
+ (formId: string, action: any, done = noop) =>
43
+ async (dispatch: any) => {
44
+ dispatch(clearActionError(ACTION));
45
+ dispatch(sendAction(ACTION, { action }));
48
46
 
49
- const formio = getFormio(formId, get(action, "data._id", ""));
47
+ const formio = getFormio(formId, get(action, "data._id", ""));
50
48
 
51
- try {
52
- const result = await formio.saveAction(action);
53
- dispatch(receiveAction(ACTION, { action: result }));
54
- done(null, result);
55
- } catch (error) {
56
- dispatch(failAction(ACTION, { error }));
57
- done(error);
58
- }
59
- };
49
+ try {
50
+ const result = await formio.saveAction(action);
51
+ dispatch(receiveAction(ACTION, { action: result }));
52
+ done(null, result);
53
+ } catch (error) {
54
+ dispatch(failAction(ACTION, { error }));
55
+ done(error);
56
+ }
57
+ };
60
58
 
61
59
  export const deleteAction = (formId: string, actionId: string, done = noop) => {
62
60
  return async (dispatch: any) => {
@@ -1,11 +1,4 @@
1
- import {
2
- clearActionError,
3
- failAction,
4
- receiveAction,
5
- requestAction,
6
- resetAction,
7
- sendAction
8
- } from "./action.actions";
1
+ import { clearActionError, failAction, receiveAction, requestAction, resetAction, sendAction } from "./action.actions";
9
2
  import { ACTION } from "./action.constant";
10
3
  import { actionReducer } from "./action.reducers";
11
4
 
@@ -1,14 +1,7 @@
1
1
  import { createReducer, InitialStateCreator } from "@tsed/redux-utils";
2
2
  import { ActionSchema } from "../../interfaces";
3
3
 
4
- import {
5
- clearActionError,
6
- failAction,
7
- receiveAction,
8
- requestAction,
9
- resetAction,
10
- sendAction
11
- } from "./action.actions";
4
+ import { clearActionError, failAction, receiveAction, requestAction, resetAction, sendAction } from "./action.actions";
12
5
  import { ACTION } from "./action.constant";
13
6
 
14
7
  export interface ActionState {
@@ -3,5 +3,4 @@ import { selectRoot } from "../root";
3
3
  import { ACTION } from "./action.constant";
4
4
  import { ActionState } from "./action.reducers";
5
5
 
6
- export const selectAction = (state: Record<string, any>): ActionSchema =>
7
- selectRoot<ActionState>(ACTION, state).data;
6
+ export const selectAction = (state: Record<string, any>): ActionSchema => selectRoot<ActionState>(ACTION, state).data;
@@ -1,9 +1,5 @@
1
1
  import { Formio } from "formiojs";
2
- import {
3
- getActionInfo,
4
- receiveActionInfo,
5
- requestActionInfo
6
- } from "./action-info.actions";
2
+ import { getActionInfo, receiveActionInfo, requestActionInfo } from "./action-info.actions";
7
3
 
8
4
  jest.mock("formiojs/Formio");
9
5
 
@@ -9,26 +9,23 @@ export const requestActionInfo = createAction();
9
9
  export const receiveActionInfo = createAction();
10
10
  export const failActionInfo = createAction();
11
11
 
12
- export const getActionInfo = (
13
- formId: string,
14
- actionType: string,
15
- done = noop
16
- ) => async (dispatch: any) => {
17
- dispatch(requestActionInfo(ACTION_INFO));
12
+ export const getActionInfo =
13
+ (formId: string, actionType: string, done = noop) =>
14
+ async (dispatch: any) => {
15
+ dispatch(requestActionInfo(ACTION_INFO));
18
16
 
19
- const url = getFormUrl(formId);
20
- const formio = new Formio(url);
17
+ const url = getFormUrl(formId);
18
+ const formio = new Formio(url);
21
19
 
22
- try {
23
- const actionInfo = await formio.actionInfo(actionType);
20
+ try {
21
+ const actionInfo = await formio.actionInfo(actionType);
24
22
 
25
- actionInfo.settingsForm.action =
26
- Formio.getProjectUrl() + actionInfo.settingsForm.action;
23
+ actionInfo.settingsForm.action = Formio.getProjectUrl() + actionInfo.settingsForm.action;
27
24
 
28
- dispatch(receiveActionInfo(ACTION_INFO, { actionInfo }));
29
- done(null, actionInfo);
30
- } catch (error) {
31
- dispatch(failActionInfo(ACTION_INFO, { error }));
32
- done(error);
33
- }
34
- };
25
+ dispatch(receiveActionInfo(ACTION_INFO, { actionInfo }));
26
+ done(null, actionInfo);
27
+ } catch (error) {
28
+ dispatch(failActionInfo(ACTION_INFO, { error }));
29
+ done(error);
30
+ }
31
+ };
@@ -1,9 +1,4 @@
1
- import {
2
- failActionInfo,
3
- receiveActionInfo,
4
- requestActionInfo,
5
- resetActionInfo
6
- } from "./action-info.actions";
1
+ import { failActionInfo, receiveActionInfo, requestActionInfo, resetActionInfo } from "./action-info.actions";
7
2
  import { ACTION_INFO } from "./action-info.constant";
8
3
  import { actionInfoReducer } from "./action-info.reducers";
9
4
 
@@ -1,11 +1,6 @@
1
1
  import { InitialStateCreator, createReducer } from "@tsed/redux-utils";
2
2
  import { ActionSchema } from "../../interfaces";
3
- import {
4
- failActionInfo,
5
- receiveActionInfo,
6
- requestActionInfo,
7
- resetActionInfo
8
- } from "./action-info.actions";
3
+ import { failActionInfo, receiveActionInfo, requestActionInfo, resetActionInfo } from "./action-info.actions";
9
4
  import { ACTION_INFO } from "./action-info.constant";
10
5
 
11
6
  export interface ActionInfoState {
@@ -3,7 +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 = (
7
- state: Record<string, any>
8
- ): Partial<ActionSchema> =>
9
- selectRoot<ActionInfoState>(ACTION_INFO, state).data;
6
+ export const selectActionInfo = (state: Record<string, any>): Partial<ActionSchema> => selectRoot<ActionInfoState>(ACTION_INFO, state).data;
@@ -1,10 +1,5 @@
1
1
  import { Formio } from "formiojs";
2
- import {
3
- getActions,
4
- receiveActions,
5
- requestActions,
6
- resetActions
7
- } from "./actions.actions";
2
+ import { getActions, receiveActions, requestActions, resetActions } from "./actions.actions";
8
3
 
9
4
  jest.mock("formiojs");
10
5
 
@@ -12,25 +12,22 @@ export const receiveActions = createAction<{
12
12
  }>();
13
13
  export const failActions = createAction<{ error: Error }>();
14
14
 
15
- export const getActions = (id: string, done = noop) => async (
16
- dispatch: any
17
- ) => {
18
- dispatch(resetActions(ACTIONS));
19
- dispatch(requestActions(ACTIONS));
15
+ export const getActions =
16
+ (id: string, done = noop) =>
17
+ async (dispatch: any) => {
18
+ dispatch(resetActions(ACTIONS));
19
+ dispatch(requestActions(ACTIONS));
20
20
 
21
- const url = getFormUrl(id);
22
- const formio = new Formio(url);
21
+ const url = getFormUrl(id);
22
+ const formio = new Formio(url);
23
23
 
24
- try {
25
- const [actions, availableActions] = await Promise.all([
26
- formio.loadActions({ params: {} }),
27
- formio.availableActions()
28
- ]);
24
+ try {
25
+ const [actions, availableActions] = await Promise.all([formio.loadActions({ params: {} }), formio.availableActions()]);
29
26
 
30
- dispatch(receiveActions(ACTIONS, { actions, availableActions }));
31
- done(null, actions, availableActions);
32
- } catch (error) {
33
- dispatch(failActions(ACTIONS, { error }));
34
- done(error);
35
- }
36
- };
27
+ dispatch(receiveActions(ACTIONS, { actions, availableActions }));
28
+ done(null, actions, availableActions);
29
+ } catch (error) {
30
+ dispatch(failActions(ACTIONS, { error }));
31
+ done(error);
32
+ }
33
+ };
@@ -1,9 +1,4 @@
1
- import {
2
- failActions,
3
- receiveActions,
4
- requestActions,
5
- resetActions
6
- } from "./actions.actions";
1
+ import { failActions, receiveActions, requestActions, resetActions } from "./actions.actions";
7
2
  import { ACTIONS } from "./actions.constant";
8
3
  import { actionsReducer } from "./actions.reducers";
9
4
 
@@ -1,11 +1,6 @@
1
1
  import { createReducer, InitialStateCreator } from "@tsed/redux-utils";
2
2
  import { ActionInfoSchema, ActionSchema } from "../../interfaces";
3
- import {
4
- failActions,
5
- receiveActions,
6
- requestActions,
7
- resetActions
8
- } from "./actions.actions";
3
+ import { failActions, receiveActions, requestActions, resetActions } from "./actions.actions";
9
4
  import { ACTIONS } from "./actions.constant";
10
5
 
11
6
  export interface ActionsState {
@@ -2,8 +2,6 @@ import { selectRoot } from "../root";
2
2
  import { ACTIONS } from "./actions.constant";
3
3
  import { ActionsState } from "./actions.reducers";
4
4
 
5
- export const selectActions = (state: Record<string, any>) =>
6
- selectRoot<ActionsState>(ACTIONS, state).data;
5
+ export const selectActions = (state: Record<string, any>) => selectRoot<ActionsState>(ACTIONS, state).data;
7
6
 
8
- export const selectAvailableActions = (state: Record<string, any>) =>
9
- selectRoot<ActionsState>(ACTIONS, state).availableActions;
7
+ export const selectAvailableActions = (state: Record<string, any>) => selectRoot<ActionsState>(ACTIONS, state).availableActions;
@@ -44,10 +44,7 @@ function createInitialState(): AuthState {
44
44
  };
45
45
  }
46
46
 
47
- function mapProjectRolesToUserRoles(
48
- projectRoles: Record<string, any>,
49
- userRoles: any[]
50
- ) {
47
+ function mapProjectRolesToUserRoles(projectRoles: Record<string, any>, userRoles: any[]) {
51
48
  return Object.entries(projectRoles).reduce(
52
49
  (result, [name, role]) => ({
53
50
  ...result,
@@ -1,8 +1,4 @@
1
- import {
2
- selectIsAuthenticated,
3
- selectRoles,
4
- selectUser
5
- } from "./auth.selectors";
1
+ import { selectIsAuthenticated, selectRoles, selectUser } from "./auth.selectors";
6
2
 
7
3
  describe("auth Selectors", () => {
8
4
  describe("selectIsAuthenticated()", () => {
@@ -6,11 +6,8 @@ import { AuthState } from "./auth.reducers";
6
6
 
7
7
  export const selectAuth = (state: any) => selectRoot<AuthState>(AUTH, state);
8
8
 
9
- export const selectUser = <User = any>(state: any): null | Submission<User> =>
10
- get(selectAuth(state), "user");
9
+ export const selectUser = <User = any>(state: any): null | Submission<User> => get(selectAuth(state), "user");
11
10
 
12
- export const selectRoles = (state: any): Record<string, RoleSchema> =>
13
- get(selectAuth(state), "roles");
11
+ export const selectRoles = (state: any): Record<string, RoleSchema> => get(selectAuth(state), "roles");
14
12
 
15
- export const selectIsAuthenticated = (state: any): boolean =>
16
- get(selectAuth(state), "authenticated");
13
+ export const selectIsAuthenticated = (state: any): boolean => get(selectAuth(state), "authenticated");