@tsed/react-formio 1.13.0 → 1.13.3
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.
- package/.eslintignore +13 -0
- package/.eslintrc.js +7 -0
- package/coverage.json +6 -0
- package/dist/components/actions-table/actionsTable.component.d.ts +0 -1
- package/dist/components/actions-table/actionsTable.stories.d.ts +0 -1
- package/dist/components/alert/alert.component.d.ts +1 -2
- package/dist/components/alert/alert.stories.d.ts +0 -1
- package/dist/components/card/card.stories.d.ts +0 -1
- package/dist/components/form/form.component.d.ts +1 -2
- package/dist/components/form/form.component.spec.d.ts +1 -0
- package/dist/components/form/form.stories.d.ts +3745 -172
- package/dist/components/form/useForm.hook.d.ts +1 -2
- package/dist/components/form-access/formAccess.stories.d.ts +1 -2
- package/dist/components/form-action/formAction.stories.d.ts +0 -1
- package/dist/components/form-builder/formBuilder.stories.d.ts +518 -153
- package/dist/components/form-control/formControl.component.d.ts +2 -2
- package/dist/components/form-control/formControl.component.spec.d.ts +1 -0
- package/dist/components/form-control/formControl.stories.d.ts +57 -0
- package/dist/components/form-edit/formEdit.component.d.ts +0 -1
- package/dist/components/form-edit/formEdit.stories.d.ts +18 -19
- package/dist/components/form-settings/formSettings.component.d.ts +0 -1
- package/dist/components/form-settings/formSettings.stories.d.ts +1 -2
- package/dist/components/forms-table/components/formCell.component.d.ts +0 -1
- package/dist/components/forms-table/formsTable.component.d.ts +0 -1
- package/dist/components/forms-table/formsTable.stories.d.ts +0 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/input-tags/inputTags.component.d.ts +0 -1
- package/dist/components/input-tags/inputTags.stories.d.ts +2 -3
- package/dist/components/input-text/inputText.component.d.ts +0 -1
- package/dist/components/input-text/inputText.stories.d.ts +0 -1
- package/dist/components/loader/loader.component.d.ts +1 -1
- package/dist/components/loader/loader.stories.d.ts +0 -1
- package/dist/components/modal/modal.component.d.ts +1 -1
- package/dist/components/modal/modal.stories.d.ts +0 -1
- package/dist/components/pagination/pagination.component.d.ts +0 -1
- package/dist/components/pagination/pagination.stories.d.ts +0 -1
- package/dist/components/react-component/reactComponent.component.d.ts +3 -3
- package/dist/components/select/select.stories.d.ts +2 -3
- package/dist/components/submissions-table/submissionsTable.component.d.ts +0 -1
- package/dist/components/submissions-table/submissionsTable.stories.d.ts +13 -14
- package/dist/components/table/components/defaultArrowSort.component.d.ts +0 -1
- package/dist/components/table/components/defaultCell.component.d.ts +0 -1
- package/dist/components/table/components/defaultCellHeader.component.d.ts +1 -2
- package/dist/components/table/components/defaultCellOperations.component.d.ts +0 -1
- package/dist/components/table/components/defaultOperationButton.component.d.ts +0 -1
- package/dist/components/table/filters/defaultColumnFilter.component.d.ts +0 -1
- package/dist/components/table/filters/selectColumnFilter.component.d.ts +0 -1
- package/dist/components/table/filters/sliderColumnFilter.component.d.ts +0 -1
- package/dist/components/table/index.d.ts +1 -1
- package/dist/components/table/table.stories.d.ts +4 -5
- package/dist/components/tabs/tabs.component.stories.d.ts +0 -1
- package/dist/hooks/useTooltip.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7936 -7913
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +7375 -7347
- package/dist/index.modern.js.map +1 -1
- package/dist/stores/actions/index.d.ts +1 -1
- package/dist/stores/auth/auth.selectors.d.ts +1 -1
- package/dist/stores/auth/index.d.ts +4 -4
- package/dist/stores/index.d.ts +2 -2
- package/jest.config.js +6 -1
- package/package.json +8 -5
- package/src/components/__fixtures__/form.fixture.json +23 -0
- package/src/components/actions-table/actionsTable.component.spec.tsx +11 -11
- package/src/components/actions-table/actionsTable.component.tsx +8 -9
- package/src/components/actions-table/actionsTable.stories.tsx +1 -0
- package/src/components/alert/alert.component.spec.tsx +21 -19
- package/src/components/alert/alert.stories.tsx +1 -0
- package/src/components/card/card.component.spec.tsx +5 -4
- package/src/components/card/card.stories.tsx +1 -0
- package/src/components/form/form.component.spec.tsx +57 -0
- package/src/components/form/form.component.tsx +4 -3
- package/src/components/form/form.stories.tsx +157 -65
- package/src/components/form/useForm.hook.ts +35 -33
- package/src/components/form-access/formAccess.component.tsx +3 -2
- package/src/components/form-access/formAccess.schema.ts +1 -0
- package/src/components/form-access/formAccess.stories.tsx +1 -0
- package/src/components/form-access/formAccess.utils.ts +6 -5
- package/src/components/form-action/formAction.component.tsx +5 -4
- package/src/components/form-action/formAction.stories.tsx +225 -227
- package/src/components/form-builder/formBuilder.component.tsx +2 -1
- package/src/components/form-builder/formBuilder.stories.tsx +1 -0
- package/src/components/form-control/formControl.component.spec.tsx +76 -0
- package/src/components/form-control/formControl.component.tsx +15 -7
- package/src/components/form-control/formControl.stories.tsx +65 -0
- package/src/components/form-edit/formCtas.component.tsx +10 -9
- package/src/components/form-edit/formEdit.component.tsx +2 -1
- package/src/components/form-edit/formEdit.reducer.ts +1 -0
- package/src/components/form-edit/formEdit.stories.tsx +1 -0
- package/src/components/form-edit/formParameters.component.tsx +1 -0
- package/src/components/form-edit/useFormEdit.hook.ts +1 -0
- package/src/components/form-settings/formSettings.component.spec.tsx +7 -6
- package/src/components/form-settings/formSettings.component.tsx +12 -14
- package/src/components/form-settings/formSettings.stories.tsx +1 -0
- package/src/components/form-settings/formSettings.utils.ts +4 -3
- package/src/components/forms-table/components/formCell.component.tsx +1 -0
- package/src/components/forms-table/formsTable.component.tsx +23 -25
- package/src/components/forms-table/formsTable.stories.tsx +1 -0
- package/src/components/index.ts +2 -2
- package/src/components/input-tags/inputTags.component.tsx +7 -6
- package/src/components/input-tags/inputTags.stories.tsx +1 -0
- package/src/components/input-text/inputText.component.spec.tsx +13 -12
- package/src/components/input-text/inputText.component.tsx +4 -3
- package/src/components/input-text/inputText.stories.tsx +1 -0
- package/src/components/loader/loader.component.spec.tsx +6 -5
- package/src/components/loader/loader.component.tsx +1 -0
- package/src/components/loader/loader.stories.tsx +1 -0
- package/src/components/modal/modal.component.spec.tsx +36 -33
- package/src/components/modal/modal.component.tsx +3 -3
- package/src/components/modal/modal.stories.tsx +1 -0
- package/src/components/modal/removeModal.component.tsx +1 -0
- package/src/components/pagination/pagination.component.spec.tsx +24 -21
- package/src/components/pagination/pagination.component.tsx +1 -0
- package/src/components/pagination/pagination.stories.tsx +1 -0
- package/src/components/react-component/reactComponent.component.tsx +11 -7
- package/src/components/select/select.component.spec.tsx +17 -18
- package/src/components/select/select.component.tsx +3 -2
- package/src/components/select/select.stories.tsx +1 -0
- package/src/components/submissions-table/submissionsTable.component.tsx +3 -2
- package/src/components/submissions-table/submissionsTable.stories.tsx +1 -0
- package/src/components/table/components/defaultArrowSort.component.tsx +1 -0
- package/src/components/table/components/defaultCellHeader.component.tsx +1 -1
- package/src/components/table/components/defaultCellOperations.component.tsx +1 -0
- package/src/components/table/components/defaultOperationButton.component.tsx +1 -0
- package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +5 -3
- package/src/components/table/filters/defaultColumnFilter.component.tsx +1 -0
- package/src/components/table/filters/selectColumnFilter.component.spec.tsx +9 -7
- package/src/components/table/filters/selectColumnFilter.component.tsx +1 -0
- package/src/components/table/index.ts +1 -1
- package/src/components/table/table.component.tsx +5 -4
- package/src/components/table/table.stories.tsx +2 -1
- package/src/components/table/utils/mapFormToColumns.tsx +3 -2
- package/src/components/table/utils/useOperations.hook.tsx +1 -0
- package/src/components/tabs/tabs.component.spec.tsx +6 -5
- package/src/components/tabs/tabs.component.stories.tsx +1 -0
- package/src/components/tabs/tabs.component.tsx +11 -5
- package/src/hooks/useTooltip.ts +1 -1
- package/src/index.ts +3 -4
- package/src/interfaces/Operation.ts +1 -0
- package/src/stores/action/action.actions.spec.ts +1 -0
- package/src/stores/action/action.actions.ts +1 -0
- package/src/stores/action/action.reducers.ts +1 -1
- package/src/stores/action-info/action-info.actions.spec.ts +1 -0
- package/src/stores/action-info/action-info.actions.ts +2 -1
- package/src/stores/action-info/action-info.reducers.ts +2 -1
- package/src/stores/action-info/action-info.selectors.ts +2 -1
- package/src/stores/actions/actions.actions.spec.ts +1 -0
- package/src/stores/actions/actions.actions.ts +1 -0
- package/src/stores/actions/actions.reducers.ts +1 -0
- package/src/stores/actions/index.ts +1 -1
- package/src/stores/auth/auth.actions.ts +1 -0
- package/src/stores/auth/auth.reducers.ts +1 -0
- package/src/stores/auth/auth.selectors.ts +1 -0
- package/src/stores/auth/auth.utils.tsx +3 -2
- package/src/stores/auth/getAccess.action.spec.ts +1 -0
- package/src/stores/auth/getAccess.action.ts +3 -2
- package/src/stores/auth/getProjectAccess.action.ts +1 -0
- package/src/stores/auth/index.ts +4 -4
- package/src/stores/auth/initAuth.action.spec.ts +1 -0
- package/src/stores/auth/initAuth.action.ts +1 -0
- package/src/stores/auth/logout.action.spec.ts +2 -0
- package/src/stores/auth/logout.action.ts +1 -0
- package/src/stores/auth/setUser.action.spec.ts +1 -0
- package/src/stores/auth/setUser.action.ts +1 -0
- package/src/stores/form/form.actions.spec.ts +1 -0
- package/src/stores/form/form.actions.ts +1 -0
- package/src/stores/form/form.reducers.ts +1 -0
- package/src/stores/form/form.selectors.ts +1 -1
- package/src/stores/forms/forms.actions.spec.ts +1 -0
- package/src/stores/forms/forms.actions.ts +1 -0
- package/src/stores/forms/forms.reducers.ts +1 -0
- package/src/stores/index.ts +3 -2
- package/src/stores/root/root.selectors.ts +3 -3
- package/src/stores/submission/submission.actions.spec.ts +1 -0
- package/src/stores/submission/submission.actions.ts +1 -0
- package/src/stores/submission/submission.reducers.ts +1 -0
- package/src/stores/submissions/submissions.actions.spec.ts +1 -0
- package/src/stores/submissions/submissions.actions.ts +1 -0
- package/src/stores/submissions/submissions.reducers.ts +1 -0
- package/tsconfig.json +10 -27
- package/tsconfig.node.json +8 -0
- package/craco.config.js +0 -11
- package/tsconfig.test.json +0 -6
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { Submission } from "../../interfaces";
|
|
3
4
|
import form from "../__fixtures__/form.fixture.json";
|
|
4
|
-
import {
|
|
5
|
+
import { Form } from "./form.component";
|
|
5
6
|
|
|
6
7
|
export default {
|
|
7
8
|
title: "ReactFormio/Form",
|
|
@@ -11,24 +12,108 @@ export default {
|
|
|
11
12
|
control: {
|
|
12
13
|
type: "object"
|
|
13
14
|
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
},
|
|
16
|
+
onPrevPage: { action: "onPrevPage" },
|
|
17
|
+
onNextPage: { action: "onNextPage" },
|
|
18
|
+
onCancel: { action: "onCancel" },
|
|
19
|
+
onChange: { action: "onChange" },
|
|
20
|
+
onCustomEvent: { action: "onCustomEvent" },
|
|
21
|
+
onComponentChange: { action: "onComponentChange" },
|
|
22
|
+
onSubmit: { action: "onSubmit" },
|
|
23
|
+
onAsyncSubmit: { action: "onAsyncSubmit" },
|
|
24
|
+
onSubmitDone: { action: "onSubmitDone" },
|
|
25
|
+
onFormLoad: { action: "onFormLoad" },
|
|
26
|
+
onError: { action: "onError" },
|
|
27
|
+
onRender: { action: "onRender" },
|
|
28
|
+
onAttach: { action: "onAttach" },
|
|
29
|
+
onBuild: { action: "onBuild" },
|
|
30
|
+
onFocus: { action: "onFocus" },
|
|
31
|
+
onBlur: { action: "onBlur" },
|
|
32
|
+
onInitialized: { action: "onInitialized" },
|
|
33
|
+
onFormReady: { action: "onFormReady" }
|
|
34
|
+
}
|
|
17
35
|
};
|
|
18
36
|
|
|
37
|
+
function filter(args: any[]) {
|
|
38
|
+
return args.map((item) => {
|
|
39
|
+
if (item && item._form) {
|
|
40
|
+
return "FormioInstance";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (item && item.component) {
|
|
44
|
+
return ["Component", item.component.type, item.component.key].filter(Boolean).join(":");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (item && item.changed) {
|
|
48
|
+
return `${item.changed.component.key}(${item.changed.value})`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return item;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function wrap(args: any) {
|
|
56
|
+
return {
|
|
57
|
+
...args,
|
|
58
|
+
onPrevPage: (...list: any[]) => {
|
|
59
|
+
return args.onPrevPage(...filter(list));
|
|
60
|
+
},
|
|
61
|
+
onNextPage: (...list: any[]) => {
|
|
62
|
+
return args.onNextPage(...filter(list));
|
|
63
|
+
},
|
|
64
|
+
onCancel: (...list: any[]) => {
|
|
65
|
+
return args.onCancel(...filter(list));
|
|
66
|
+
},
|
|
67
|
+
onChange: (...list: any[]) => {
|
|
68
|
+
return args.onChange(...filter(list));
|
|
69
|
+
},
|
|
70
|
+
onCustomEvent: (...list: any[]) => {
|
|
71
|
+
return args.onCustomEvent(...filter(list));
|
|
72
|
+
},
|
|
73
|
+
onComponentChange: (...list: any[]) => {
|
|
74
|
+
return args.onComponentChange(...filter(list));
|
|
75
|
+
},
|
|
76
|
+
onSubmit: (...list: any[]) => {
|
|
77
|
+
return args.onSubmit(...filter(list));
|
|
78
|
+
},
|
|
79
|
+
onAsyncSubmit: (...list: any[]) => {
|
|
80
|
+
return args.onAsyncSubmit(...filter(list));
|
|
81
|
+
},
|
|
82
|
+
onSubmitDone: (...list: any[]) => {
|
|
83
|
+
return args.onSubmitDone(...filter(list));
|
|
84
|
+
},
|
|
85
|
+
onFormLoad: (...list: any[]) => {
|
|
86
|
+
return args.onFormLoad(...filter(list));
|
|
87
|
+
},
|
|
88
|
+
onError: (...list: any[]) => {
|
|
89
|
+
return args.onError(...filter(list));
|
|
90
|
+
},
|
|
91
|
+
onRender: (...list: any[]) => {
|
|
92
|
+
return args.onRender(...filter(list));
|
|
93
|
+
},
|
|
94
|
+
onAttach: (...list: any[]) => {
|
|
95
|
+
return args.onAttach(...filter(list));
|
|
96
|
+
},
|
|
97
|
+
onBuild: (...list: any[]) => {
|
|
98
|
+
return args.onBuild(...filter(list));
|
|
99
|
+
},
|
|
100
|
+
onFocus: (...list: any[]) => {
|
|
101
|
+
return args.onFocus(...filter(list));
|
|
102
|
+
},
|
|
103
|
+
onBlur: (...list: any[]) => {
|
|
104
|
+
return args.onBlur(...filter(list));
|
|
105
|
+
},
|
|
106
|
+
onInitialized: (...list: any[]) => {
|
|
107
|
+
return args.onInitialized(...filter(list));
|
|
108
|
+
},
|
|
109
|
+
onFormReady: (...list: any[]) => {
|
|
110
|
+
return args.onFormReady(...filter(list));
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
19
115
|
export const Sandbox = (args: any) => {
|
|
20
|
-
|
|
21
|
-
delete args.onComponentChange;
|
|
22
|
-
return (
|
|
23
|
-
<Form
|
|
24
|
-
{...args}
|
|
25
|
-
form={args.form}
|
|
26
|
-
onFormReady={(formio) => {
|
|
27
|
-
console.log("ready", formio);
|
|
28
|
-
}}
|
|
29
|
-
options={{template: "tailwind", iconset: "bx"}}
|
|
30
|
-
/>
|
|
31
|
-
);
|
|
116
|
+
return <Form {...wrap(args)} form={args.form} options={{ template: "tailwind", iconset: "bx" }} />;
|
|
32
117
|
};
|
|
33
118
|
|
|
34
119
|
Sandbox.args = {
|
|
@@ -36,64 +121,71 @@ Sandbox.args = {
|
|
|
36
121
|
};
|
|
37
122
|
|
|
38
123
|
export const TriggerError = (args: any) => {
|
|
39
|
-
|
|
40
|
-
|
|
124
|
+
const onAsyncSubmit = (submission: Submission) => {
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
setTimeout(() => {
|
|
127
|
+
reject(new Error("server error"));
|
|
128
|
+
}, 500);
|
|
129
|
+
}).catch((error) => {
|
|
130
|
+
error.errors = {
|
|
131
|
+
message: "My custom message about this field",
|
|
132
|
+
type: "custom",
|
|
133
|
+
path: ["firstName"],
|
|
134
|
+
level: "error"
|
|
135
|
+
};
|
|
136
|
+
throw error;
|
|
137
|
+
});
|
|
138
|
+
};
|
|
41
139
|
|
|
42
|
-
return (
|
|
43
|
-
<Form
|
|
44
|
-
{...args}
|
|
45
|
-
form={args.form}
|
|
46
|
-
onAsyncSubmit={(submission: Submission) => {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
setTimeout(() => {
|
|
49
|
-
reject(new Error("server error"));
|
|
50
|
-
}, 500);
|
|
51
|
-
}).catch((error) => {
|
|
52
|
-
error.errors = {
|
|
53
|
-
"message": "My custom message about this field",
|
|
54
|
-
"type": "custom",
|
|
55
|
-
"path": ["firstName"],
|
|
56
|
-
"level": "error"
|
|
57
|
-
}
|
|
58
|
-
throw error
|
|
59
|
-
});
|
|
60
|
-
}}
|
|
61
|
-
options={{
|
|
62
|
-
hooks: {
|
|
63
|
-
template: "tailwind",
|
|
64
|
-
iconset: "bx"
|
|
65
|
-
}
|
|
66
|
-
}}
|
|
67
|
-
/>
|
|
68
|
-
);
|
|
140
|
+
return <Form<any> {...wrap(args)} form={args.form} onAsyncSubmit={onAsyncSubmit} />;
|
|
69
141
|
};
|
|
70
142
|
|
|
71
143
|
TriggerError.args = {
|
|
72
144
|
form: {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
145
|
+
type: "form",
|
|
146
|
+
display: "form",
|
|
147
|
+
tags: [],
|
|
148
|
+
components: [
|
|
77
149
|
{
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
150
|
+
label: "First name",
|
|
151
|
+
widget: {
|
|
152
|
+
type: "input"
|
|
81
153
|
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
154
|
+
errorLabel: "",
|
|
155
|
+
key: "firstName",
|
|
156
|
+
inputType: "text",
|
|
157
|
+
type: "textfield",
|
|
158
|
+
id: "eqb1o4r",
|
|
159
|
+
defaultValue: ""
|
|
88
160
|
},
|
|
89
161
|
{
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
162
|
+
label: "Submit",
|
|
163
|
+
showValidations: false,
|
|
164
|
+
tableView: false,
|
|
165
|
+
key: "submit",
|
|
166
|
+
type: "button",
|
|
167
|
+
input: true
|
|
96
168
|
}
|
|
97
169
|
]
|
|
98
170
|
}
|
|
99
171
|
};
|
|
172
|
+
|
|
173
|
+
export const ReadOnly = (args: any) => {
|
|
174
|
+
return (
|
|
175
|
+
<Form
|
|
176
|
+
{...wrap(args)}
|
|
177
|
+
options={{ template: "tailwind", iconset: "bx", readOnly: args.readOnly }}
|
|
178
|
+
form={args.form}
|
|
179
|
+
submission={{
|
|
180
|
+
data: {
|
|
181
|
+
editGrid: [{ currency: "EUR" }]
|
|
182
|
+
}
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
ReadOnly.args = {
|
|
189
|
+
readonly: true,
|
|
190
|
+
form
|
|
191
|
+
};
|
|
@@ -3,8 +3,9 @@ import { get } from "lodash";
|
|
|
3
3
|
import cloneDeep from "lodash/cloneDeep";
|
|
4
4
|
import isEqual from "lodash/isEqual";
|
|
5
5
|
import { useEffect, useRef } from "react";
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
import { FormOptions, FormSchema, Submission } from "../../interfaces";
|
|
8
|
+
import { callLast } from "../../utils/callLast";
|
|
8
9
|
|
|
9
10
|
export interface ChangedSubmission<T = any> extends Submission<T> {
|
|
10
11
|
changed: any;
|
|
@@ -34,6 +35,8 @@ export interface UseFormHookProps<Data = any> extends Record<string, any> {
|
|
|
34
35
|
* Data submission
|
|
35
36
|
*/
|
|
36
37
|
submission?: Submission<Data>;
|
|
38
|
+
|
|
39
|
+
/// events
|
|
37
40
|
onPrevPage?: (obj: FormPageChangeProps<Data>) => void;
|
|
38
41
|
onNextPage?: (obj: FormPageChangeProps<Data>) => void;
|
|
39
42
|
onCancel?: Function;
|
|
@@ -41,7 +44,7 @@ export interface UseFormHookProps<Data = any> extends Record<string, any> {
|
|
|
41
44
|
onCustomEvent?: (obj: { type: string; event: string; component: ExtendedComponentSchema; data: any }) => void;
|
|
42
45
|
onComponentChange?: (component: ExtendedComponentSchema) => void;
|
|
43
46
|
onSubmit?: (submission: Submission<Data>) => void;
|
|
44
|
-
onAsyncSubmit?: (submission: Submission<Data>) => Promise<
|
|
47
|
+
onAsyncSubmit?: (submission: Submission<Data>) => Promise<any>;
|
|
45
48
|
onSubmitDone?: (submission: Submission<Data>) => void;
|
|
46
49
|
onFormLoad?: Function;
|
|
47
50
|
onError?: (errors: any) => void;
|
|
@@ -52,7 +55,30 @@ export interface UseFormHookProps<Data = any> extends Record<string, any> {
|
|
|
52
55
|
onBlur?: Function;
|
|
53
56
|
onInitialized?: Function;
|
|
54
57
|
onFormReady?: (formio: Form) => void;
|
|
55
|
-
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function useDebounce(event: string, callback: any, events: Map<string, any>) {
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
callback && events.set(event, callLast(callback, 100));
|
|
63
|
+
}, [callback, event, events]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function useEvents(funcs: any) {
|
|
67
|
+
const events = useRef<Map<string, any>>(new Map());
|
|
68
|
+
|
|
69
|
+
const hasEvent = (event: string) => {
|
|
70
|
+
return funcs.hasOwnProperty(event) && typeof funcs[event] === "function";
|
|
71
|
+
};
|
|
72
|
+
const emit = (event: string, ...args: any[]) => {
|
|
73
|
+
if (hasEvent(event)) {
|
|
74
|
+
const fn = events.current.has(event) ? events.current.get(event) : funcs[event];
|
|
75
|
+
return fn(...args);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
useDebounce("onChange", funcs.onChange, events.current);
|
|
80
|
+
|
|
81
|
+
return { events, emit, hasEvent };
|
|
56
82
|
}
|
|
57
83
|
|
|
58
84
|
export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
@@ -60,12 +86,12 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
60
86
|
const element = useRef<any>();
|
|
61
87
|
const isLoaded = useRef<boolean>();
|
|
62
88
|
const instance = useRef<Form>();
|
|
63
|
-
const
|
|
89
|
+
const { emit, hasEvent } = useEvents(funcs);
|
|
64
90
|
|
|
65
91
|
async function customValidation(submission: Submission, callback: (err: Error | null) => void) {
|
|
66
|
-
if (
|
|
92
|
+
if (hasEvent("onAsyncSubmit")) {
|
|
67
93
|
try {
|
|
68
|
-
await
|
|
94
|
+
await emit("onAsyncSubmit", submission, instance.current);
|
|
69
95
|
} catch (err) {
|
|
70
96
|
callback(err?.errors || err);
|
|
71
97
|
}
|
|
@@ -93,27 +119,15 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
93
119
|
}
|
|
94
120
|
|
|
95
121
|
if (event.startsWith("formio.")) {
|
|
96
|
-
const
|
|
122
|
+
const eventName = `on${event.charAt(7).toUpperCase()}${event.slice(8)}`;
|
|
97
123
|
|
|
98
|
-
if (
|
|
124
|
+
if (eventName === "onChange") {
|
|
99
125
|
if (isEqual(get(submission, "data"), args[0].data)) {
|
|
100
126
|
return;
|
|
101
127
|
}
|
|
102
128
|
}
|
|
103
129
|
|
|
104
|
-
|
|
105
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
106
|
-
props.hasOwnProperty(funcName) &&
|
|
107
|
-
typeof funcs[funcName] === "function"
|
|
108
|
-
) {
|
|
109
|
-
if (!events.current.has(funcName)) {
|
|
110
|
-
const fn = callLast(funcs[funcName], 100);
|
|
111
|
-
events.current.set(funcName, fn);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
instance.current.instance.setAlert("success", "");
|
|
115
|
-
events.current.get(funcName)(...args, instance.current);
|
|
116
|
-
}
|
|
130
|
+
emit(eventName, ...args, instance.current);
|
|
117
131
|
}
|
|
118
132
|
});
|
|
119
133
|
|
|
@@ -172,18 +186,6 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
172
186
|
};
|
|
173
187
|
}, []);
|
|
174
188
|
|
|
175
|
-
useEffect(() => {
|
|
176
|
-
props.onSubmit && events.current.set("onSubmit", props.onSubmit);
|
|
177
|
-
}, [props.onSubmit, events]);
|
|
178
|
-
|
|
179
|
-
useEffect(() => {
|
|
180
|
-
props.onAsyncSubmit && events.current.set("onAsyncSubmit", props.onAsyncSubmit);
|
|
181
|
-
}, [props.onAsyncSubmit, events]);
|
|
182
|
-
|
|
183
|
-
useEffect(() => {
|
|
184
|
-
props.onSubmitDone && events.current.set("onSubmitDone", props.onSubmitDone);
|
|
185
|
-
}, [props.onSubmitDone, events]);
|
|
186
|
-
|
|
187
189
|
return {
|
|
188
190
|
element
|
|
189
191
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import PropTypes from "prop-types";
|
|
2
2
|
import React, { PropsWithChildren, ReactElement, useCallback, useEffect, useMemo, useState } from "react";
|
|
3
|
+
|
|
3
4
|
import { FormOptions, FormSchema, Submission } from "../../interfaces";
|
|
4
5
|
import { Card } from "../card/card.component";
|
|
5
6
|
import { Form } from "../form/form.component";
|
|
7
|
+
import { ChangedSubmission } from "../form/useForm.hook";
|
|
6
8
|
import {
|
|
7
9
|
AccessRoles,
|
|
8
10
|
dataAccessToSubmissions,
|
|
@@ -13,7 +15,6 @@ import {
|
|
|
13
15
|
submissionsToDataAccess,
|
|
14
16
|
updateSubmissions
|
|
15
17
|
} from "./formAccess.utils";
|
|
16
|
-
import { ChangedSubmission } from "../form/useForm.hook";
|
|
17
18
|
|
|
18
19
|
export interface FormAccessProps {
|
|
19
20
|
form: Partial<FormSchema>;
|
|
@@ -51,7 +52,7 @@ function useFormAccess({ form: formDefinition, roles, onSubmit, options }: FormA
|
|
|
51
52
|
submissions,
|
|
52
53
|
onChange,
|
|
53
54
|
onSubmit: () => {
|
|
54
|
-
onSubmit(submissionsToDataAccess(formDefinition, submissions));
|
|
55
|
+
onSubmit && onSubmit(submissionsToDataAccess(formDefinition, submissions));
|
|
55
56
|
}
|
|
56
57
|
};
|
|
57
58
|
}
|
|
@@ -2,6 +2,7 @@ import { ExtendedComponentSchema } from "formiojs";
|
|
|
2
2
|
import cloneDeep from "lodash/cloneDeep";
|
|
3
3
|
import isEqual from "lodash/isEqual";
|
|
4
4
|
import noop from "lodash/noop";
|
|
5
|
+
|
|
5
6
|
import { FormSchema, Submission } from "../../interfaces";
|
|
6
7
|
import { RoleSchema } from "../../interfaces/RoleSchema";
|
|
7
8
|
import { getAccessPermissionForm, getSubmissionPermissionForm } from "./formAccess.schema";
|
|
@@ -31,19 +32,19 @@ export type SubmissionAccess = {
|
|
|
31
32
|
function rolesToChoices(roles: RoleSchema[]): Choice[] {
|
|
32
33
|
return Object.values(roles).map((role) => {
|
|
33
34
|
return {
|
|
34
|
-
label: role.title,
|
|
35
|
-
value: role._id
|
|
35
|
+
label: role.title || "",
|
|
36
|
+
value: role._id || ""
|
|
36
37
|
};
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
function accessToHash(keys: string[], access: Access[] = []): AccessRoles {
|
|
41
|
+
function accessToHash(keys: (string | undefined)[] | undefined, access: Access[] = []): AccessRoles {
|
|
41
42
|
const hash = Object.values(access).reduce((o: any, role: any) => {
|
|
42
43
|
o[role.type] = role.roles;
|
|
43
44
|
return o;
|
|
44
45
|
}, {});
|
|
45
46
|
|
|
46
|
-
return keys.reduce((data, key) => {
|
|
47
|
+
return ((keys || []).filter(Boolean) as any[]).reduce((data, key: string) => {
|
|
47
48
|
return {
|
|
48
49
|
...data,
|
|
49
50
|
[key]: hash[key] || []
|
|
@@ -100,7 +101,7 @@ export function submissionsToDataAccess(form: Partial<FormSchema>, submissions:
|
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
export function shouldUpdate(type: string, submission: Submission<AccessRoles>, submissions: SubmissionAccess) {
|
|
103
|
-
return !isEqual(submission.data, submissions[type].data);
|
|
104
|
+
return !isEqual(submission.data, (submissions as any)[type].data);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
export function updateSubmissions(type: string, submission: Submission<AccessRoles>, submissions: SubmissionAccess, cb: Function = noop) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import FormioUtils from "formiojs/utils";
|
|
2
|
-
import React, { PropsWithChildren, ReactElement
|
|
2
|
+
import React, { PropsWithChildren, ReactElement } from "react";
|
|
3
|
+
|
|
3
4
|
import { ActionDefaultsSchema, ActionSchema, FormOptions, Submission } from "../../interfaces";
|
|
4
5
|
import { Form } from "../form/form.component";
|
|
5
6
|
|
|
@@ -38,12 +39,12 @@ export interface FormActionProps {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export function FormAction({ actionInfo, children, onSubmit, options, ...props }: PropsWithChildren<FormActionProps>): ReactElement {
|
|
41
|
-
const { form, submission } =
|
|
42
|
-
const submission = mapData(props.submission || {}, actionInfo.defaults);
|
|
42
|
+
const { form, submission } = (() => {
|
|
43
|
+
const submission = mapData(props.submission || {}, actionInfo.defaults!);
|
|
43
44
|
const form = mapSettingsForm(actionInfo.settingsForm);
|
|
44
45
|
|
|
45
46
|
return { form, submission: { data: submission } };
|
|
46
|
-
}
|
|
47
|
+
})();
|
|
47
48
|
|
|
48
49
|
return (
|
|
49
50
|
<div>
|