@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
@@ -25,17 +25,9 @@ const EVENTS = [
25
25
  "pasteComponent"
26
26
  ];
27
27
 
28
- const EVENTS_CHANGE = [
29
- "addComponent",
30
- "saveComponent",
31
- "updateComponent",
32
- "removeComponent"
33
- ];
28
+ const EVENTS_CHANGE = ["addComponent", "saveComponent", "updateComponent", "removeComponent"];
34
29
 
35
- async function createBuilder(
36
- el: Element,
37
- { components = [], display, options, onChange, events = {} }: any
38
- ): Promise<void> {
30
+ async function createBuilder(el: Element, { components = [], display, options, onChange, events = {} }: any): Promise<void> {
39
31
  const form = {
40
32
  display,
41
33
  components: [...components]
@@ -54,9 +46,7 @@ async function createBuilder(
54
46
  };
55
47
  };
56
48
 
57
- EVENTS.forEach((event) =>
58
- builder.on(event, callLast(handleEvent(event), 200))
59
- );
49
+ EVENTS.forEach((event) => builder.on(event, callLast(handleEvent(event), 200)));
60
50
 
61
51
  return builder;
62
52
  } catch (er) {
@@ -166,6 +156,7 @@ export class FormBuilder extends React.Component<FormBuilderProps, any> {
166
156
  this.builderRef?.destroy();
167
157
  }
168
158
 
159
+ // eslint-disable-next-line react/no-deprecated
169
160
  async componentWillReceiveProps(nextProps: FormBuilderProps) {
170
161
  if (this.builderRef) {
171
162
  if (nextProps.display !== this.state.display) {
@@ -1126,8 +1126,7 @@ Sandbox.args = {
1126
1126
  key: "address1",
1127
1127
  type: "textfield",
1128
1128
  input: true,
1129
- customConditional:
1130
- "show = _.get(instance, 'parent.manualMode', false);",
1129
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
1131
1130
  placeholder: "",
1132
1131
  prefix: "",
1133
1132
  customClass: "",
@@ -1189,8 +1188,7 @@ Sandbox.args = {
1189
1188
  key: "address2",
1190
1189
  type: "textfield",
1191
1190
  input: true,
1192
- customConditional:
1193
- "show = _.get(instance, 'parent.manualMode', false);",
1191
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
1194
1192
  placeholder: "",
1195
1193
  prefix: "",
1196
1194
  customClass: "",
@@ -1252,8 +1250,7 @@ Sandbox.args = {
1252
1250
  key: "city",
1253
1251
  type: "textfield",
1254
1252
  input: true,
1255
- customConditional:
1256
- "show = _.get(instance, 'parent.manualMode', false);",
1253
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
1257
1254
  placeholder: "",
1258
1255
  prefix: "",
1259
1256
  customClass: "",
@@ -1315,8 +1312,7 @@ Sandbox.args = {
1315
1312
  key: "state",
1316
1313
  type: "textfield",
1317
1314
  input: true,
1318
- customConditional:
1319
- "show = _.get(instance, 'parent.manualMode', false);",
1315
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
1320
1316
  placeholder: "",
1321
1317
  prefix: "",
1322
1318
  customClass: "",
@@ -1378,8 +1374,7 @@ Sandbox.args = {
1378
1374
  key: "country",
1379
1375
  type: "textfield",
1380
1376
  input: true,
1381
- customConditional:
1382
- "show = _.get(instance, 'parent.manualMode', false);",
1377
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
1383
1378
  placeholder: "",
1384
1379
  prefix: "",
1385
1380
  customClass: "",
@@ -1441,8 +1436,7 @@ Sandbox.args = {
1441
1436
  key: "zip",
1442
1437
  type: "textfield",
1443
1438
  input: true,
1444
- customConditional:
1445
- "show = _.get(instance, 'parent.manualMode', false);",
1439
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
1446
1440
  placeholder: "",
1447
1441
  prefix: "",
1448
1442
  customClass: "",
@@ -2947,8 +2941,7 @@ Wizard.args = {
2947
2941
  key: "address1",
2948
2942
  type: "textfield",
2949
2943
  input: true,
2950
- customConditional:
2951
- "show = _.get(instance, 'parent.manualMode', false);",
2944
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
2952
2945
  placeholder: "",
2953
2946
  prefix: "",
2954
2947
  customClass: "",
@@ -3010,8 +3003,7 @@ Wizard.args = {
3010
3003
  key: "address2",
3011
3004
  type: "textfield",
3012
3005
  input: true,
3013
- customConditional:
3014
- "show = _.get(instance, 'parent.manualMode', false);",
3006
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
3015
3007
  placeholder: "",
3016
3008
  prefix: "",
3017
3009
  customClass: "",
@@ -3073,8 +3065,7 @@ Wizard.args = {
3073
3065
  key: "city",
3074
3066
  type: "textfield",
3075
3067
  input: true,
3076
- customConditional:
3077
- "show = _.get(instance, 'parent.manualMode', false);",
3068
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
3078
3069
  placeholder: "",
3079
3070
  prefix: "",
3080
3071
  customClass: "",
@@ -3136,8 +3127,7 @@ Wizard.args = {
3136
3127
  key: "state",
3137
3128
  type: "textfield",
3138
3129
  input: true,
3139
- customConditional:
3140
- "show = _.get(instance, 'parent.manualMode', false);",
3130
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
3141
3131
  placeholder: "",
3142
3132
  prefix: "",
3143
3133
  customClass: "",
@@ -3199,8 +3189,7 @@ Wizard.args = {
3199
3189
  key: "country",
3200
3190
  type: "textfield",
3201
3191
  input: true,
3202
- customConditional:
3203
- "show = _.get(instance, 'parent.manualMode', false);",
3192
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
3204
3193
  placeholder: "",
3205
3194
  prefix: "",
3206
3195
  customClass: "",
@@ -3262,8 +3251,7 @@ Wizard.args = {
3262
3251
  key: "zip",
3263
3252
  type: "textfield",
3264
3253
  input: true,
3265
- customConditional:
3266
- "show = _.get(instance, 'parent.manualMode', false);",
3254
+ customConditional: "show = _.get(instance, 'parent.manualMode', false);",
3267
3255
  placeholder: "",
3268
3256
  prefix: "",
3269
3257
  customClass: "",
@@ -24,15 +24,9 @@ export function FormControl({
24
24
  className
25
25
  }: React.PropsWithChildren<FormControlProps>) {
26
26
  return (
27
- <div
28
- id={`form-group-${name || ""}`}
29
- className={classnames("form-group", className)}
30
- >
27
+ <div id={`form-group-${name || ""}`} className={classnames("form-group", className)}>
31
28
  {label && (
32
- <label
33
- htmlFor={name}
34
- className={`col-form-label ${required ? " field-required" : ""}`}
35
- >
29
+ <label htmlFor={name} className={`col-form-label ${required ? " field-required" : ""}`}>
36
30
  {label}
37
31
  </label>
38
32
  )}
@@ -59,9 +59,7 @@ export function FormEditCTAs({
59
59
  <div className={"form-edit__actions"}>
60
60
  <div>
61
61
  <button
62
- className={`btn btn-primary btn-save flex ${
63
- disabled ? "disabled" : ""
64
- }`}
62
+ className={`btn btn-primary btn-save flex ${disabled ? "disabled" : ""}`}
65
63
  disabled={disabled}
66
64
  onClick={() => !disabled && onSubmit()}
67
65
  >
@@ -70,39 +68,23 @@ export function FormEditCTAs({
70
68
  </button>
71
69
 
72
70
  <div>
73
- <button
74
- className={`btn btn-light btn-undo ${hasUndo ? "" : "disabled"}`}
75
- onClick={() => onUndo()}
76
- ref={undoTooltipRef}
77
- >
71
+ <button className={`btn btn-light btn-undo ${hasUndo ? "" : "disabled"}`} onClick={() => onUndo()} ref={undoTooltipRef}>
78
72
  <i className={iconClass(options.iconset, "undo")} />
79
73
  </button>
80
74
 
81
- <button
82
- className={`btn btn-light btn-redo ${hasRedo ? "" : "disabled"}`}
83
- onClick={() => onRedo()}
84
- ref={redoTooltipRef}
85
- >
75
+ <button className={`btn btn-light btn-redo ${hasRedo ? "" : "disabled"}`} onClick={() => onRedo()} ref={redoTooltipRef}>
86
76
  <i className={iconClass(options.iconset, "redo")} />
87
77
  </button>
88
78
  </div>
89
79
 
90
80
  <div>
91
81
  {onCopy && (
92
- <button
93
- className='btn btn-light'
94
- onClick={() => onCopy()}
95
- ref={copyTooltipRef}
96
- >
82
+ <button className='btn btn-light' onClick={() => onCopy()} ref={copyTooltipRef}>
97
83
  <i className={iconClass(options.iconset, "copy")} />
98
84
  </button>
99
85
  )}
100
86
 
101
- <button
102
- className={`btn btn-light btn-reset`}
103
- onClick={() => onReset()}
104
- ref={resetTooltipRef}
105
- >
87
+ <button className={`btn btn-light btn-reset`} onClick={() => onReset()} ref={resetTooltipRef}>
106
88
  <i className={iconClass(options.iconset, "reset")} />
107
89
  </button>
108
90
  </div>
@@ -12,31 +12,13 @@ export interface FormEditProps extends UseFormEditHookProps {
12
12
  }
13
13
 
14
14
  export function FormEdit(props: FormEditProps) {
15
- const {
16
- form,
17
- isValid,
18
- setChange,
19
- hasRedo,
20
- hasChanged,
21
- hasUndo,
22
- redo,
23
- undo,
24
- reset,
25
- onSubmit,
26
- onCopy
27
- } = useFormEdit(props);
15
+ const { form, isValid, setChange, hasRedo, hasChanged, hasUndo, redo, undo, reset, onSubmit, onCopy } = useFormEdit(props);
28
16
  const { options = {}, builder } = props;
29
17
 
30
18
  return (
31
19
  <div>
32
20
  <div className='form-edit'>
33
- <FormParameters
34
- {...props}
35
- className={""}
36
- key={`form-settings-${form._id}`}
37
- form={form}
38
- onChange={setChange}
39
- />
21
+ <FormParameters {...props} className={""} key={`form-settings-${form._id}`} form={form} onChange={setChange} />
40
22
  <FormEditCTAs
41
23
  {...props}
42
24
  className={""}
@@ -3,10 +3,7 @@ import cloneDeep from "lodash/cloneDeep";
3
3
  import isEqual from "lodash/isEqual";
4
4
  import { FormSchema } from "../../interfaces";
5
5
 
6
- export const hasChanged = (
7
- form: Partial<FormSchema>,
8
- value: Partial<FormSchema>
9
- ): boolean => !isEqual(form, value);
6
+ export const hasChanged = (form: Partial<FormSchema>, value: Partial<FormSchema>): boolean => !isEqual(form, value);
10
7
 
11
8
  export interface FormEditState {
12
9
  past: Partial<FormSchema>[];
@@ -24,10 +21,7 @@ export function createInitialState(props: any): FormEditState {
24
21
  };
25
22
  }
26
23
 
27
- export const reducer = (
28
- state: FormEditState,
29
- { type, value }: any
30
- ): FormEditState => {
24
+ export const reducer = (state: FormEditState, { type, value }: any): FormEditState => {
31
25
  const { past, current, future } = state;
32
26
 
33
27
  const update = (newValue: any): any => {
@@ -134,11 +134,7 @@ Sandbox.args = {
134
134
  display: "form",
135
135
  access: [
136
136
  {
137
- roles: [
138
- "5d0797bc872fc747da559858",
139
- "5d0797bc872fc71d05559859",
140
- "5d0797bc872fc7da3b55985a"
141
- ],
137
+ roles: ["5d0797bc872fc747da559858", "5d0797bc872fc71d05559859", "5d0797bc872fc7da3b55985a"],
142
138
  type: "read_all"
143
139
  }
144
140
  ],
@@ -249,11 +245,7 @@ WithoutTypeChoices.args = {
249
245
  display: "form",
250
246
  access: [
251
247
  {
252
- roles: [
253
- "5d0797bc872fc747da559858",
254
- "5d0797bc872fc71d05559859",
255
- "5d0797bc872fc7da3b55985a"
256
- ],
248
+ roles: ["5d0797bc872fc747da559858", "5d0797bc872fc71d05559859", "5d0797bc872fc7da3b55985a"],
257
249
  type: "read_all"
258
250
  }
259
251
  ],
@@ -360,11 +352,7 @@ WithoutTags.args = {
360
352
  display: "form",
361
353
  access: [
362
354
  {
363
- roles: [
364
- "5d0797bc872fc747da559858",
365
- "5d0797bc872fc71d05559859",
366
- "5d0797bc872fc7da3b55985a"
367
- ],
355
+ roles: ["5d0797bc872fc747da559858", "5d0797bc872fc71d05559859", "5d0797bc872fc7da3b55985a"],
368
356
  type: "read_all"
369
357
  }
370
358
  ],
@@ -71,33 +71,16 @@ export function FormParameters({
71
71
  />
72
72
  </div>
73
73
  <div className={"w-1/3"}>
74
- <Select
75
- label={"Display as"}
76
- name={"display"}
77
- value={form.display}
78
- choices={displayChoices}
79
- onChange={onChange}
80
- />
74
+ <Select label={"Display as"} name={"display"} value={form.display} choices={displayChoices} onChange={onChange} />
81
75
  </div>
82
76
  {hasTypeChoices && (
83
77
  <div className={"w-1/3"}>
84
- <Select
85
- label={"Type"}
86
- name={"type"}
87
- value={form.type}
88
- choices={typeChoices}
89
- onChange={onChange}
90
- />
78
+ <Select label={"Type"} name={"type"} value={form.type} choices={typeChoices} onChange={onChange} />
91
79
  </div>
92
80
  )}
93
81
  {enableTags && (
94
82
  <div className={"w-1/3"}>
95
- <InputTags
96
- label={"Tags"}
97
- name={"tags"}
98
- value={form.tags}
99
- onChange={onChange}
100
- />
83
+ <InputTags label={"Tags"} name={"tags"} value={form.tags} onChange={onChange} />
101
84
  </div>
102
85
  )}
103
86
  </div>
@@ -12,10 +12,7 @@ export interface UseFormEditHookProps extends Record<string, unknown> {
12
12
  }
13
13
 
14
14
  export function useFormEdit(props: UseFormEditHookProps) {
15
- const [{ current, future, past }, dispatchFormAction] = useReducer(
16
- reducer,
17
- createInitialState(props)
18
- );
15
+ const [{ current, future, past }, dispatchFormAction] = useReducer(reducer, createInitialState(props));
19
16
 
20
17
  const onSubmit = () => {
21
18
  if (props.onSubmit && typeof props.onSubmit === "function") {
@@ -29,11 +26,7 @@ export function useFormEdit(props: UseFormEditHookProps) {
29
26
  };
30
27
 
31
28
  useEffect(() => {
32
- if (
33
- props.form &&
34
- (current._id !== props.form._id ||
35
- current.modified !== props.form.modified)
36
- ) {
29
+ if (props.form && (current._id !== props.form._id || current.modified !== props.form.modified)) {
37
30
  dispatchFormAction({ type: "replaceForm", value: props.form });
38
31
  }
39
32
  }, [props.form]);
@@ -7,7 +7,6 @@ describe("FormSettings", () => {
7
7
  it("should render form settings", async () => {
8
8
  const onSubmit = jest.fn();
9
9
 
10
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
11
10
  // @ts-ignore
12
11
  Sandbox.args.form.action = "https://test";
13
12
 
@@ -30,11 +29,7 @@ describe("FormSettings", () => {
30
29
  _id: "6023f8fe4b1a2ab9a3aae096",
31
30
  access: [
32
31
  {
33
- roles: [
34
- "5d0797bc872fc747da559858",
35
- "5d0797bc872fc71d05559859",
36
- "5d0797bc872fc7da3b55985a"
37
- ],
32
+ roles: ["5d0797bc872fc747da559858", "5d0797bc872fc71d05559859", "5d0797bc872fc7da3b55985a"],
38
33
  type: "read_all"
39
34
  }
40
35
  ],
@@ -46,9 +41,7 @@ describe("FormSettings", () => {
46
41
  path: "textfield",
47
42
  properties: {},
48
43
  settings: {},
49
- submissionAccess: [
50
- { roles: ["5d0797bc872fc747da559858"], type: "read_all" }
51
- ],
44
+ submissionAccess: [{ roles: ["5d0797bc872fc747da559858"], type: "read_all" }],
52
45
  tags: [],
53
46
  type: "form"
54
47
  });
@@ -2,11 +2,7 @@ import React, { useCallback, useEffect, useState } from "react";
2
2
  import { FormOptions, FormSchema } from "../../interfaces";
3
3
  import { getFormSettingsSchema } from "./formSettings.schema";
4
4
  import { Form } from "../form/form.component";
5
- import {
6
- FormSettingsSchema,
7
- formSettingsToSubmission,
8
- submissionToFormSettings
9
- } from "./formSettings.utils";
5
+ import { FormSettingsSchema, formSettingsToSubmission, submissionToFormSettings } from "./formSettings.utils";
10
6
  import isEqual from "lodash/isEqual";
11
7
  import noop from "lodash/noop";
12
8
  import { ChangedSubmission } from "../form/useForm.hook";
@@ -17,16 +13,10 @@ export interface FormSettingsProps {
17
13
  options?: FormOptions;
18
14
  }
19
15
 
20
- function useFormSettings({
21
- form: formDefinition,
22
- onSubmit = noop,
23
- options
24
- }: FormSettingsProps) {
16
+ function useFormSettings({ form: formDefinition, onSubmit = noop, options }: FormSettingsProps) {
25
17
  const form = getFormSettingsSchema();
26
18
  const [isValid, setIsValid] = useState(true);
27
- const [submission, setSubmission] = useState(() =>
28
- formSettingsToSubmission(formDefinition)
29
- );
19
+ const [submission, setSubmission] = useState(() => formSettingsToSubmission(formDefinition));
30
20
 
31
21
  const onChange = useCallback(
32
22
  ({ data, isValid }: ChangedSubmission<FormSettingsSchema>) => {
@@ -60,33 +50,15 @@ function useFormSettings({
60
50
  }
61
51
 
62
52
  export function FormSettings(props: FormSettingsProps) {
63
- const {
64
- form,
65
- submission,
66
- options = {},
67
- onChange,
68
- onSubmit,
69
- isValid
70
- } = useFormSettings(props);
53
+ const { form, submission, options = {}, onChange, onSubmit, isValid } = useFormSettings(props);
71
54
 
72
55
  const i18n = options.i18n || ((f: string) => f);
73
56
 
74
57
  return (
75
58
  <div>
76
- <Form
77
- form={form}
78
- submission={submission}
79
- onChange={onChange}
80
- options={options}
81
- />
59
+ <Form form={form} submission={submission} onChange={onChange} options={options} />
82
60
 
83
- <button
84
- data-testid='submit'
85
- disabled={!isValid}
86
- className={"mt-5 btn btn-primary"}
87
- onClick={onSubmit}
88
- type={"submit"}
89
- >
61
+ <button data-testid='submit' disabled={!isValid} className={"mt-5 btn btn-primary"} onClick={onSubmit} type={"submit"}>
90
62
  {i18n("Save settings")}
91
63
  </button>
92
64
  </div>
@@ -27,7 +27,6 @@ export default {
27
27
  };
28
28
 
29
29
  export const Sandbox = (args: any) => {
30
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
31
30
  // @ts-ignore
32
31
  return <FormSettings {...args} />;
33
32
  };
@@ -40,11 +39,7 @@ Sandbox.args = {
40
39
  owner: "5d0797a382461b6656d2c790",
41
40
  access: [
42
41
  {
43
- roles: [
44
- "5d0797bc872fc747da559858",
45
- "5d0797bc872fc71d05559859",
46
- "5d0797bc872fc7da3b55985a"
47
- ],
42
+ roles: ["5d0797bc872fc747da559858", "5d0797bc872fc71d05559859", "5d0797bc872fc7da3b55985a"],
48
43
  type: "read_all"
49
44
  }
50
45
  ],
@@ -1,7 +1,4 @@
1
- import {
2
- formSettingsToSubmission,
3
- submissionToFormSettings
4
- } from "./formSettings.utils";
1
+ import { formSettingsToSubmission, submissionToFormSettings } from "./formSettings.utils";
5
2
 
6
3
  describe("FormSettings utils", () => {
7
4
  describe("submissionToDataSettings()", () => {
@@ -7,9 +7,7 @@ export type FormSettingsSchema = {
7
7
  properties: Record<string, any>;
8
8
  };
9
9
 
10
- export function formSettingsToSubmission(
11
- form: Partial<FormSchema>
12
- ): Submission<FormSettingsSchema> {
10
+ export function formSettingsToSubmission(form: Partial<FormSchema>): Submission<FormSettingsSchema> {
13
11
  return {
14
12
  data: {
15
13
  action: form.action,
@@ -19,10 +17,7 @@ export function formSettingsToSubmission(
19
17
  };
20
18
  }
21
19
 
22
- export function submissionToFormSettings(
23
- form: Partial<FormSchema>,
24
- submission: Submission<FormSettingsSchema>
25
- ): Partial<FormSchema> {
20
+ export function submissionToFormSettings(form: Partial<FormSchema>, submission: Submission<FormSettingsSchema>): Partial<FormSchema> {
26
21
  return {
27
22
  ...cloneDeep(form),
28
23
  tags: submission.data.tags,
@@ -6,9 +6,7 @@ import { FormSchema } from "../../../interfaces";
6
6
  import { iconClass } from "../../../utils/iconClass";
7
7
  import { stopPropagationWrapper } from "../../../utils/stopPropagationWrapper";
8
8
 
9
- export function FormsCell(
10
- props: CellProps<FormSchema> & { icon: string; i18n: (f: string) => string }
11
- ) {
9
+ export function FormsCell(props: CellProps<FormSchema> & { icon: string; i18n: (f: string) => string }) {
12
10
  const {
13
11
  icon = "server",
14
12
  row: { original: form }
@@ -25,9 +23,7 @@ export function FormsCell(
25
23
  <li className={"text-sm"}>Name: {form.name || form.machineName}</li>
26
24
  <li className='mt-5'>
27
25
  <span className='badge bg-light mr-1'>
28
- <i
29
- className={classnames(iconClass(undefined, "history"), "mr-1")}
30
- />
26
+ <i className={classnames(iconClass(undefined, "history"), "mr-1")} />
31
27
  <span>Updated {moment(form.modified).fromNow()}</span>
32
28
  </span>
33
29
 
@@ -19,9 +19,7 @@ export function FormsTable({ Cell, ...props }: FormsTableProps) {
19
19
  Header: i18n("Title"),
20
20
  accessor: "title",
21
21
  id: "title",
22
- Cell: (props: any) => (
23
- <FormCell {...props} icon={props.icon} i18n={i18n} />
24
- ),
22
+ Cell: (props: any) => <FormCell {...props} icon={props.icon} i18n={i18n} />,
25
23
  Filter: DefaultColumnFilter,
26
24
  colspan: 2
27
25
  },
@@ -32,10 +30,7 @@ export function FormsTable({ Cell, ...props }: FormsTableProps) {
32
30
  hidden: true,
33
31
  Filter: (props: any) =>
34
32
  tags && tags.length ? (
35
- <SelectColumnFilter
36
- {...props}
37
- column={{ ...props.columns, choices: tags }}
38
- />
33
+ <SelectColumnFilter {...props} column={{ ...props.columns, choices: tags }} />
39
34
  ) : (
40
35
  <DefaultColumnFilter {...props} />
41
36
  )
@@ -3,13 +3,9 @@ import uniq from "lodash/uniq";
3
3
  import PropTypes from "prop-types";
4
4
  import React, { useEffect, useRef } from "react";
5
5
 
6
- import {
7
- FormControl,
8
- FormControlProps
9
- } from "../form-control/formControl.component";
6
+ import { FormControl, FormControlProps } from "../form-control/formControl.component";
10
7
 
11
- export interface InputTagsProps<T = any>
12
- extends Omit<FormControlProps, "description" | "prefix" | "suffix"> {
8
+ export interface InputTagsProps<T = any> extends Omit<FormControlProps, "description" | "prefix" | "suffix"> {
13
9
  value?: T;
14
10
  onChange?: (name: string, value: T) => void;
15
11
  placeholder?: string;
@@ -17,17 +13,7 @@ export interface InputTagsProps<T = any>
17
13
  [key: string]: any;
18
14
  }
19
15
 
20
- export function InputTags({
21
- name,
22
- value = [],
23
- label,
24
- onChange,
25
- required,
26
- description,
27
- prefix,
28
- suffix,
29
- ...props
30
- }: InputTagsProps) {
16
+ export function InputTags({ name, value = [], label, onChange, required, description, prefix, suffix, ...props }: InputTagsProps) {
31
17
  const ref = useRef();
32
18
 
33
19
  useEffect(() => {
@@ -43,15 +29,12 @@ export function InputTags({
43
29
  onChange(name, uniq(value.concat(event.detail.value)));
44
30
  });
45
31
 
46
- instance.passedElement.element.addEventListener(
47
- "removeItem",
48
- (event: any) => {
49
- onChange(
50
- name,
51
- value.filter((v: string) => v !== event.detail.value)
52
- );
53
- }
54
- );
32
+ instance.passedElement.element.addEventListener("removeItem", (event: any) => {
33
+ onChange(
34
+ name,
35
+ value.filter((v: string) => v !== event.detail.value)
36
+ );
37
+ });
55
38
 
56
39
  return () => {
57
40
  instance.destroy();
@@ -59,14 +42,7 @@ export function InputTags({
59
42
  }, []);
60
43
 
61
44
  return (
62
- <FormControl
63
- name={name}
64
- label={label}
65
- required={required}
66
- description={description}
67
- prefix={prefix}
68
- suffix={suffix}
69
- >
45
+ <FormControl name={name} label={label} required={required} description={description} prefix={prefix} suffix={suffix}>
70
46
  <input ref={ref} type='text' {...props} id={name} required={required} />
71
47
  </FormControl>
72
48
  );