@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
@@ -2,15 +2,12 @@ import { defaultFormioReducer } from "./index";
2
2
 
3
3
  describe("defaultFormioReducer", () => {
4
4
  it("should return initial state", () => {
5
- const state = Object.entries(defaultFormioReducer).reduce(
6
- (state, [key, reduce]) => {
7
- return {
8
- ...state,
9
- [key]: reduce(undefined, {} as any)
10
- };
11
- },
12
- {}
13
- );
5
+ const state = Object.entries(defaultFormioReducer).reduce((state, [key, reduce]) => {
6
+ return {
7
+ ...state,
8
+ [key]: reduce(undefined, {} as any)
9
+ };
10
+ }, {});
14
11
 
15
12
  expect(state).toEqual({
16
13
  action: {
@@ -1,9 +1,4 @@
1
- import {
2
- oneOfIsActive,
3
- selectError,
4
- selectIsActive,
5
- selectRoot
6
- } from "./root.selectors";
1
+ import { oneOfIsActive, selectError, selectIsActive, selectRoot } from "./root.selectors";
7
2
 
8
3
  describe("root Selectors", () => {
9
4
  describe("selectRoot()", () => {
@@ -1,16 +1,8 @@
1
1
  import get from "lodash/get";
2
2
 
3
- export function selectRoot<State = Record<string, any>>(
4
- name: string
5
- ): (state: Record<string, any>) => State;
6
- export function selectRoot<State = Record<string, any>>(
7
- name: string,
8
- state: Record<string, any>
9
- ): State;
10
- export function selectRoot<State = Record<string, any>>(
11
- name: string,
12
- state?: Record<string, any>
13
- ): any {
3
+ export function selectRoot<State = Record<string, any>>(name: string): (state: Record<string, any>) => State;
4
+ export function selectRoot<State = Record<string, any>>(name: string, state: Record<string, any>): State;
5
+ export function selectRoot<State = Record<string, any>>(name: string, state?: Record<string, any>): any {
14
6
  if (state) {
15
7
  return state[name];
16
8
  }
@@ -18,24 +10,14 @@ export function selectRoot<State = Record<string, any>>(
18
10
  return (state: Record<string, any>) => selectRoot(name, state);
19
11
  }
20
12
 
21
- export const selectError = (
22
- name: string,
23
- state: Record<string, any>
24
- ): null | Error => get(selectRoot(name, state), "error");
13
+ export const selectError = (name: string, state: Record<string, any>): null | Error => get(selectRoot(name, state), "error");
25
14
 
26
- export const selectIsActive = (
27
- name: string,
28
- state: Record<string, any>
29
- ): boolean => get(selectRoot(name, state), "isActive");
15
+ export const selectIsActive = (name: string, state: Record<string, any>): boolean => get(selectRoot(name, state), "isActive");
30
16
 
31
17
  export function oneOfIsActive(...names: string[]) {
32
18
  return (state: any) => {
33
19
  return !!names.find((name) => {
34
- return get(
35
- state,
36
- `${name}.isActive`,
37
- get(state, `${name}.current.isActive`)
38
- );
20
+ return get(state, `${name}.isActive`, get(state, `${name}.current.isActive`));
39
21
  });
40
22
  };
41
23
  }
@@ -20,9 +20,7 @@ describe("Submission actions", () => {
20
20
  });
21
21
  it("should return a result", async () => {
22
22
  // GIVEN
23
- (Formio as any).prototype.loadSubmission.mockReturnValue(
24
- Promise.resolve({})
25
- );
23
+ (Formio as any).prototype.loadSubmission.mockReturnValue(Promise.resolve({}));
26
24
 
27
25
  const dispatch = jest.fn();
28
26
  const name = "name";
@@ -34,9 +32,7 @@ describe("Submission actions", () => {
34
32
  });
35
33
 
36
34
  // WHEN
37
- await new Promise((resolve) =>
38
- getSubmission(name, formId, id, resolve)(dispatch, getState)
39
- );
35
+ await new Promise((resolve) => getSubmission(name, formId, id, resolve)(dispatch, getState));
40
36
 
41
37
  // THEN
42
38
  expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
@@ -61,9 +57,7 @@ describe("Submission actions", () => {
61
57
  });
62
58
  it("should do nothing when submission is already loaded", async () => {
63
59
  // GIVEN
64
- (Formio.prototype.loadSubmission as any).mockReturnValue(
65
- Promise.resolve({})
66
- );
60
+ (Formio.prototype.loadSubmission as any).mockReturnValue(Promise.resolve({}));
67
61
 
68
62
  const dispatch = jest.fn();
69
63
  const name = "name";
@@ -82,9 +76,7 @@ describe("Submission actions", () => {
82
76
  });
83
77
  it("should throw error", async () => {
84
78
  // GIVEN
85
- (Formio.prototype.loadSubmission as any).mockReturnValue(
86
- Promise.reject(new Error("message"))
87
- );
79
+ (Formio.prototype.loadSubmission as any).mockReturnValue(Promise.reject(new Error("message")));
88
80
 
89
81
  const dispatch = jest.fn();
90
82
  const name = "name";
@@ -96,9 +88,7 @@ describe("Submission actions", () => {
96
88
  });
97
89
 
98
90
  // WHEN
99
- await new Promise((resolve) =>
100
- getSubmission(name, formId, id, resolve)(dispatch, getState)
101
- );
91
+ await new Promise((resolve) => getSubmission(name, formId, id, resolve)(dispatch, getState));
102
92
 
103
93
  // THEN
104
94
  expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
@@ -120,13 +110,9 @@ describe("Submission actions", () => {
120
110
  const data = { _id: "123454" };
121
111
  const formId = "formId";
122
112
 
123
- (Formio.prototype.saveSubmission as any).mockReturnValue(
124
- Promise.resolve(data)
125
- );
113
+ (Formio.prototype.saveSubmission as any).mockReturnValue(Promise.resolve(data));
126
114
  // WHEN
127
- await new Promise((resolve) =>
128
- saveSubmission(name, formId, data, resolve)(dispatch)
129
- );
115
+ await new Promise((resolve) => saveSubmission(name, formId, data, resolve)(dispatch));
130
116
 
131
117
  // THEN
132
118
  expect(dispatch).toHaveBeenCalledWith({
@@ -164,9 +150,7 @@ describe("Submission actions", () => {
164
150
  const formId = "formId";
165
151
 
166
152
  // WHEN
167
- await new Promise((resolve) =>
168
- saveSubmission(name, formId, data, resolve)(dispatch)
169
- );
153
+ await new Promise((resolve) => saveSubmission(name, formId, data, resolve)(dispatch));
170
154
 
171
155
  // THEN
172
156
  expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
@@ -183,9 +167,7 @@ describe("Submission actions", () => {
183
167
  describe("deleteSubmission", () => {
184
168
  it("should return a result", async () => {
185
169
  // GIVEN
186
- (Formio.prototype.deleteSubmission as any).mockReturnValue(
187
- Promise.resolve({})
188
- );
170
+ (Formio.prototype.deleteSubmission as any).mockReturnValue(Promise.resolve({}));
189
171
 
190
172
  const dispatch = jest.fn();
191
173
  const name = "name";
@@ -193,9 +175,7 @@ describe("Submission actions", () => {
193
175
  const formId = "formId";
194
176
 
195
177
  // WHEN
196
- await new Promise((resolve) =>
197
- deleteSubmission(name, formId, id, resolve)(dispatch)
198
- );
178
+ await new Promise((resolve) => deleteSubmission(name, formId, id, resolve)(dispatch));
199
179
 
200
180
  // THEN
201
181
  expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
@@ -216,9 +196,7 @@ describe("Submission actions", () => {
216
196
  const formId = "formId";
217
197
 
218
198
  // WHEN
219
- await new Promise((resolve) =>
220
- deleteSubmission(name, formId, id, resolve)(dispatch)
221
- );
199
+ await new Promise((resolve) => deleteSubmission(name, formId, id, resolve)(dispatch));
222
200
 
223
201
  // THEN
224
202
  expect(Formio).toHaveBeenCalledWith("/formId/submission/123454");
@@ -11,79 +11,70 @@ export const receiveSubmission = createAction();
11
11
  export const failSubmission = createAction();
12
12
  export const resetSubmission = createAction();
13
13
 
14
- export const getSubmission = (
15
- name: string,
16
- formId: string,
17
- id: string,
18
- done = noop
19
- ) => async (dispatch: any, getState: any) => {
20
- // Check to see if the submission is already loaded.
21
- if (getState().id === id) {
22
- return;
23
- }
14
+ export const getSubmission =
15
+ (name: string, formId: string, id: string, done = noop) =>
16
+ async (dispatch: any, getState: any) => {
17
+ // Check to see if the submission is already loaded.
18
+ if (getState().id === id) {
19
+ return;
20
+ }
24
21
 
25
- const url = getSubmissionUrl(formId, id);
26
- const formio = new Formio(url);
22
+ const url = getSubmissionUrl(formId, id);
23
+ const formio = new Formio(url);
27
24
 
28
- dispatch(clearSubmissionError(name));
29
- dispatch(requestSubmission(name, { id, formId, url }));
25
+ dispatch(clearSubmissionError(name));
26
+ dispatch(requestSubmission(name, { id, formId, url }));
30
27
 
31
- try {
32
- const result = await formio.loadSubmission();
28
+ try {
29
+ const result = await formio.loadSubmission();
33
30
 
34
- dispatch(receiveSubmission(name, { submission: result, url }));
35
- done(null, result);
36
- } catch (error) {
37
- dispatch(failSubmission(name, { error }));
38
- done(error);
39
- }
40
- };
31
+ dispatch(receiveSubmission(name, { submission: result, url }));
32
+ done(null, result);
33
+ } catch (error) {
34
+ dispatch(failSubmission(name, { error }));
35
+ done(error);
36
+ }
37
+ };
41
38
 
42
- export const saveSubmission = (
43
- name: string,
44
- formId: string,
45
- data: Submission,
46
- done = noop
47
- ) => async (dispatch: any) => {
48
- dispatch(clearSubmissionError(name));
49
- dispatch(sendSubmission(name, { submission: data, formId }));
39
+ export const saveSubmission =
40
+ (name: string, formId: string, data: Submission, done = noop) =>
41
+ async (dispatch: any) => {
42
+ dispatch(clearSubmissionError(name));
43
+ dispatch(sendSubmission(name, { submission: data, formId }));
50
44
 
51
- const id = data._id;
52
- const url = getSubmissionUrl(formId, id);
53
- const formio = new Formio(url);
45
+ const id = data._id;
46
+ const url = getSubmissionUrl(formId, id);
47
+ const formio = new Formio(url);
54
48
 
55
- try {
56
- const result = await formio.saveSubmission(data);
57
- dispatch(
58
- receiveSubmission(name, {
59
- submission: result,
60
- url: getSubmissionUrl(formId, result._id)
61
- })
62
- );
63
- done(null, result);
64
- } catch (error) {
65
- dispatch(failSubmission(name, { error }));
66
- done(error);
67
- }
68
- };
49
+ try {
50
+ const result = await formio.saveSubmission(data);
51
+ dispatch(
52
+ receiveSubmission(name, {
53
+ submission: result,
54
+ url: getSubmissionUrl(formId, result._id)
55
+ })
56
+ );
57
+ done(null, result);
58
+ } catch (error) {
59
+ dispatch(failSubmission(name, { error }));
60
+ done(error);
61
+ }
62
+ };
69
63
 
70
- export const deleteSubmission = (
71
- name: string,
72
- formId: string,
73
- id: string,
74
- done = noop
75
- ) => async (dispatch: any) => {
76
- dispatch(clearSubmissionError(name));
64
+ export const deleteSubmission =
65
+ (name: string, formId: string, id: string, done = noop) =>
66
+ async (dispatch: any) => {
67
+ dispatch(clearSubmissionError(name));
77
68
 
78
- const url = getSubmissionUrl(formId, id);
79
- const formio = new Formio(url);
69
+ const url = getSubmissionUrl(formId, id);
70
+ const formio = new Formio(url);
80
71
 
81
- try {
82
- await formio.deleteSubmission();
83
- dispatch(resetSubmission(name));
84
- done(null);
85
- } catch (error) {
86
- dispatch(failSubmission(name, { error }));
87
- done(error);
88
- }
89
- };
72
+ try {
73
+ await formio.deleteSubmission();
74
+ dispatch(resetSubmission(name));
75
+ done(null);
76
+ } catch (error) {
77
+ dispatch(failSubmission(name, { error }));
78
+ done(error);
79
+ }
80
+ };
@@ -1,10 +1,4 @@
1
- import {
2
- failSubmission,
3
- receiveSubmission,
4
- requestSubmission,
5
- resetSubmission,
6
- sendSubmission
7
- } from "./submission.actions";
1
+ import { failSubmission, receiveSubmission, requestSubmission, resetSubmission, sendSubmission } from "./submission.actions";
8
2
  import { submissionReducer } from "./submission.reducers";
9
3
 
10
4
  describe("Submission reducers", () => {
@@ -33,16 +27,14 @@ describe("Submission reducers", () => {
33
27
  url: "url"
34
28
  };
35
29
 
36
- expect(reducer.$emit(requestSubmission.toString(), state, payload)).toEqual(
37
- {
38
- name: "name",
39
- formId: "formId",
40
- id: "id",
41
- isActive: true,
42
- data: {},
43
- url: "url"
44
- }
45
- );
30
+ expect(reducer.$emit(requestSubmission.toString(), state, payload)).toEqual({
31
+ name: "name",
32
+ formId: "formId",
33
+ id: "id",
34
+ isActive: true,
35
+ data: {},
36
+ url: "url"
37
+ });
46
38
  });
47
39
 
48
40
  it("should return state (sendSubmission)", () => {
@@ -77,17 +69,15 @@ describe("Submission reducers", () => {
77
69
  }
78
70
  };
79
71
 
80
- expect(reducer.$emit(receiveSubmission.toString(), state, payload)).toEqual(
81
- {
82
- name: "name",
83
- url: "url",
84
- error: null,
85
- isActive: false,
86
- data: {
87
- _id: "id"
88
- }
72
+ expect(reducer.$emit(receiveSubmission.toString(), state, payload)).toEqual({
73
+ name: "name",
74
+ url: "url",
75
+ error: null,
76
+ isActive: false,
77
+ data: {
78
+ _id: "id"
89
79
  }
90
- );
80
+ });
91
81
  });
92
82
 
93
83
  it("should return state (failSubmission)", () => {
@@ -44,10 +44,7 @@ export const submissionReducer = createReducer<SubmissionState>(
44
44
  data: {},
45
45
  isActive: true
46
46
  }),
47
- [sendSubmission.toString()]: (
48
- state: any,
49
- { formId, submission, id, url }: any
50
- ) => ({
47
+ [sendSubmission.toString()]: (state: any, { formId, submission, id, url }: any) => ({
51
48
  ...state,
52
49
  formId,
53
50
  id,
@@ -2,7 +2,4 @@ import { Submission } from "../../interfaces";
2
2
  import { selectRoot } from "../root";
3
3
  import { SubmissionState } from "./submission.reducers";
4
4
 
5
- export const selectSubmission = (
6
- name: string,
7
- state: any
8
- ): Partial<Submission> => selectRoot<SubmissionState>(name, state).data;
5
+ export const selectSubmission = (name: string, state: any): Partial<Submission> => selectRoot<SubmissionState>(name, state).data;
@@ -1,11 +1,6 @@
1
1
  import { Formio } from "formiojs";
2
2
  import { mapRequestParams } from "../../utils/mapRequestParams";
3
- import {
4
- failSubmissions,
5
- getSubmissions,
6
- receiveSubmissions,
7
- requestSubmissions
8
- } from "./submissions.actions";
3
+ import { failSubmissions, getSubmissions, receiveSubmissions, requestSubmissions } from "./submissions.actions";
9
4
 
10
5
  jest.mock("formiojs");
11
6
  jest.mock("../../utils/mapRequestParams");
@@ -17,9 +12,7 @@ describe("Submissions actions", () => {
17
12
  describe("getSubmissions", () => {
18
13
  it("should return a result", async () => {
19
14
  // GIVEN
20
- (Formio.prototype.loadSubmissions as any).mockReturnValue(
21
- Promise.resolve([{}])
22
- );
15
+ (Formio.prototype.loadSubmissions as any).mockReturnValue(Promise.resolve([{}]));
23
16
  (Formio.getProjectUrl as any).mockReturnValue("https://formio");
24
17
 
25
18
  const dispatch = jest.fn();
@@ -37,9 +30,7 @@ describe("Submissions actions", () => {
37
30
  });
38
31
 
39
32
  // WHEN
40
- await new Promise((resolve) =>
41
- getSubmissions(name, formId, parameters, resolve)(dispatch, getState)
42
- );
33
+ await new Promise((resolve) => getSubmissions(name, formId, parameters, resolve)(dispatch, getState));
43
34
 
44
35
  // THEN
45
36
  expect(Formio).toHaveBeenCalledWith("https://formio/formId/submission");
@@ -64,9 +55,7 @@ describe("Submissions actions", () => {
64
55
  });
65
56
  it("should return a error", async () => {
66
57
  // GIVEN
67
- (Formio.prototype.loadSubmissions as any).mockReturnValue(
68
- Promise.reject(new Error("message"))
69
- );
58
+ (Formio.prototype.loadSubmissions as any).mockReturnValue(Promise.reject(new Error("message")));
70
59
  (Formio.getProjectUrl as any).mockReturnValue("https://formio");
71
60
 
72
61
  const dispatch = jest.fn();
@@ -84,9 +73,7 @@ describe("Submissions actions", () => {
84
73
  });
85
74
 
86
75
  // WHEN
87
- await new Promise((resolve) =>
88
- getSubmissions(name, formId, parameters, resolve)(dispatch, getState)
89
- );
76
+ await new Promise((resolve) => getSubmissions(name, formId, parameters, resolve)(dispatch, getState));
90
77
 
91
78
  // THEN
92
79
  expect(Formio).toHaveBeenCalledWith("https://formio/formId/submission");
@@ -10,35 +10,26 @@ export const requestSubmissions = createAction();
10
10
  export const receiveSubmissions = createAction();
11
11
  export const failSubmissions = createAction();
12
12
 
13
- export const getSubmissions = (
14
- name: string,
15
- formId: string,
16
- parameters: any = {},
17
- done = noop
18
- ) => async (dispatch: any, getState: any) => {
19
- dispatch(requestSubmissions(name, { formId, parameters }));
13
+ export const getSubmissions =
14
+ (name: string, formId: string, parameters: any = {}, done = noop) =>
15
+ async (dispatch: any, getState: any) => {
16
+ dispatch(requestSubmissions(name, { formId, parameters }));
20
17
 
21
- const url = getSubmissionUrl(formId);
22
- const formio = new Formio(url);
23
- const requestParams = mapRequestParams(
24
- selectSubmissionsParameters(name, getState())
25
- );
18
+ const url = getSubmissionUrl(formId);
19
+ const formio = new Formio(url);
20
+ const requestParams = mapRequestParams(selectSubmissionsParameters(name, getState()));
26
21
 
27
- try {
28
- const submissions = await formio.loadSubmissions({ params: requestParams });
29
- dispatch(receiveSubmissions(name, { submissions }));
30
- done(null, submissions);
31
- } catch (error) {
32
- dispatch(failSubmissions(name, { error }));
33
- done(error);
34
- }
35
- };
22
+ try {
23
+ const submissions = await formio.loadSubmissions({ params: requestParams });
24
+ dispatch(receiveSubmissions(name, { submissions }));
25
+ done(null, submissions);
26
+ } catch (error) {
27
+ dispatch(failSubmissions(name, { error }));
28
+ done(error);
29
+ }
30
+ };
36
31
 
37
- export const refreshSubmissions = (
38
- name: string,
39
- formId: string,
40
- done = noop
41
- ) => {
32
+ export const refreshSubmissions = (name: string, formId: string, done = noop) => {
42
33
  return async (dispatch: any, getState: any) => {
43
34
  const parameters = selectSubmissionsParameters(name, getState());
44
35
  return getSubmissions(name, formId, parameters, done)(dispatch, getState);
@@ -1,9 +1,4 @@
1
- import {
2
- failSubmissions,
3
- receiveSubmissions,
4
- requestSubmissions,
5
- resetSubmissions
6
- } from "./submissions.actions";
1
+ import { failSubmissions, receiveSubmissions, requestSubmissions, resetSubmissions } from "./submissions.actions";
7
2
  import { submissionsReducer } from "./submissions.reducers";
8
3
 
9
4
  describe("Submissions reducers", () => {
@@ -42,9 +37,7 @@ describe("Submissions reducers", () => {
42
37
  }
43
38
  };
44
39
 
45
- expect(
46
- reducer.$emit(requestSubmissions.toString(), state, payload)
47
- ).toEqual({
40
+ expect(reducer.$emit(requestSubmissions.toString(), state, payload)).toEqual({
48
41
  error: null,
49
42
  formId: undefined,
50
43
  name: "name",
@@ -74,9 +67,7 @@ describe("Submissions reducers", () => {
74
67
  };
75
68
  payload.submissions.serverCount = 100;
76
69
 
77
- expect(
78
- reducer.$emit(receiveSubmissions.toString(), state, payload)
79
- ).toEqual({
70
+ expect(reducer.$emit(receiveSubmissions.toString(), state, payload)).toEqual({
80
71
  name: "name",
81
72
  data: [
82
73
  {
@@ -1,11 +1,6 @@
1
1
  import { createReducer } from "@tsed/redux-utils";
2
2
  import { Submission } from "../../interfaces/Submission";
3
- import {
4
- failSubmissions,
5
- receiveSubmissions,
6
- requestSubmissions,
7
- resetSubmissions
8
- } from "./submissions.actions";
3
+ import { failSubmissions, receiveSubmissions, requestSubmissions, resetSubmissions } from "./submissions.actions";
9
4
 
10
5
  export interface SubmissionsState {
11
6
  error: null | Error;
@@ -22,13 +17,7 @@ export interface SubmissionsState {
22
17
  data: Submission[];
23
18
  }
24
19
 
25
- export function createInitialState({
26
- pageIndex = 0,
27
- pageSize = 10,
28
- query = {},
29
- select = "",
30
- sortBy = []
31
- }: any = {}): SubmissionsState {
20
+ export function createInitialState({ pageIndex = 0, pageSize = 10, query = {}, select = "", sortBy = [] }: any = {}): SubmissionsState {
32
21
  return {
33
22
  error: null,
34
23
  formId: "",
@@ -45,10 +34,7 @@ export function createInitialState({
45
34
  };
46
35
  }
47
36
 
48
- export const submissionsReducer = createReducer<SubmissionsState>(
49
- {},
50
- createInitialState
51
- )
37
+ export const submissionsReducer = createReducer<SubmissionsState>({}, createInitialState)
52
38
  .on(resetSubmissions, (_: any, _2: any, reset: any) => {
53
39
  return reset();
54
40
  })
@@ -1,7 +1,4 @@
1
- import {
2
- selectSubmissions,
3
- selectSubmissionsParameters
4
- } from "./submissions.selectors";
1
+ import { selectSubmissions, selectSubmissionsParameters } from "./submissions.selectors";
5
2
 
6
3
  describe("Submissions Selectors", () => {
7
4
  describe("selectSubmissions()", () => {
@@ -1,8 +1,6 @@
1
1
  import { selectRoot } from "../root";
2
2
  import { SubmissionsState } from "./submissions.reducers";
3
3
 
4
- export const selectSubmissions = (name: string, state: any) =>
5
- selectRoot<SubmissionsState>(name, state).data;
4
+ export const selectSubmissions = (name: string, state: any) => selectRoot<SubmissionsState>(name, state).data;
6
5
 
7
- export const selectSubmissionsParameters = (name: string, state: any) =>
8
- selectRoot<SubmissionsState>(name, state).parameters;
6
+ export const selectSubmissionsParameters = (name: string, state: any) => selectRoot<SubmissionsState>(name, state).parameters;
@@ -2,10 +2,7 @@ export function getEventValue(event: any) {
2
2
  const { target } = event;
3
3
 
4
4
  if (event.target.multiple && event.target.selectedOptions) {
5
- return Array.from(
6
- event.target.selectedOptions,
7
- (option: any) => option.value
8
- );
5
+ return Array.from(event.target.selectedOptions, (option: any) => option.value);
9
6
  }
10
7
 
11
8
  return target.type === "checkbox" ? target.checked : target.value;
@@ -1,13 +1,5 @@
1
1
  import { Templates } from "formiojs";
2
2
 
3
- export function iconClass(
4
- iconset: string | undefined,
5
- name: string,
6
- spinning?: boolean
7
- ): string {
8
- return Templates.current.iconClass(
9
- iconset || Templates.current.defaultIconset,
10
- name,
11
- spinning
12
- );
3
+ export function iconClass(iconset: string | undefined, name: string, spinning?: boolean): string {
4
+ return Templates.current.iconClass(iconset || Templates.current.defaultIconset, name, spinning);
13
5
  }
@@ -1,9 +1,4 @@
1
- export function mapPagination({
2
- skip,
3
- limit,
4
- serverCount,
5
- length
6
- }: any = {}): any {
1
+ export function mapPagination({ skip, limit, serverCount, length }: any = {}): any {
7
2
  skip = skip || 0;
8
3
  limit = limit || 10;
9
4
  serverCount = serverCount || length;