@tsed/react-formio 1.13.1 → 1.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-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/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 +0 -1
- 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/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.js +297 -276
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +294 -272
- package/dist/index.modern.js.map +1 -1
- package/dist/stores/auth/auth.selectors.d.ts +1 -1
- package/jest.config.js +1 -1
- package/package.json +5 -5
- package/src/components/__fixtures__/form.fixture.json +23 -0
- package/src/components/form/form.component.spec.tsx +56 -0
- package/src/components/form/form.component.tsx +2 -2
- package/src/components/form/form.stories.tsx +141 -34
- package/src/components/form/useForm.hook.ts +39 -38
- package/src/components/form-access/formAccess.component.tsx +1 -1
- package/src/components/form-access/formAccess.utils.ts +13 -13
- package/src/components/form-action/formAction.component.tsx +1 -1
- package/src/components/form-builder/formBuilder.component.tsx +1 -1
- package/src/components/form-edit/formCtas.component.tsx +32 -30
- package/src/components/form-edit/formEdit.component.tsx +1 -1
- package/src/components/form-settings/formSettings.utils.ts +3 -3
- package/src/components/input-tags/inputTags.component.tsx +3 -3
- package/src/components/input-text/inputText.component.tsx +2 -2
- package/src/components/modal/modal.component.tsx +2 -2
- package/src/components/react-component/reactComponent.component.tsx +9 -6
- package/src/components/select/select.component.tsx +2 -2
- package/src/components/submissions-table/submissionsTable.component.tsx +6 -6
- package/src/components/table/table.component.tsx +58 -44
- package/src/components/table/utils/mapFormToColumns.tsx +1 -1
- package/src/components/tabs/tabs.component.tsx +1 -1
- package/src/hooks/useTooltip.ts +1 -1
- package/src/stores/action-info/action-info.selectors.ts +1 -1
- package/src/stores/auth/auth.utils.tsx +2 -2
- package/src/stores/auth/getAccess.action.ts +2 -2
- package/src/stores/auth/logout.action.spec.ts +1 -0
- package/src/stores/form/form.selectors.ts +1 -1
- package/src/stores/root/root.selectors.ts +2 -2
- package/tsconfig.json +10 -27
- package/tsconfig.node.json +8 -0
- package/craco.config.js +0 -11
- package/tsconfig.test.json +0 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RoleSchema, Submission } from "../../interfaces";
|
|
2
2
|
import { AuthState } from "./auth.reducers";
|
|
3
3
|
export declare const selectAuth: (state: any) => AuthState<any>;
|
|
4
|
-
export declare const selectUser: <User = any>(state: any) => Submission<User
|
|
4
|
+
export declare const selectUser: <User = any>(state: any) => Submission<User> | null;
|
|
5
5
|
export declare const selectRoles: (state: any) => Record<string, RoleSchema>;
|
|
6
6
|
export declare const selectIsAuthenticated: (state: any) => boolean;
|
package/jest.config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require("@tsed/config/jest.config")
|
|
1
|
+
module.exports = require("@tsed/config/jest/jest.web.config.js");
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/react-formio",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.2",
|
|
4
4
|
"description": "Provide a react formio wrapper. Written in TypeScript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.modern.js",
|
|
7
7
|
"source": "src/index.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "cross-env
|
|
9
|
+
"test": "cross-env NODE_ENV=test jest --coverage",
|
|
10
10
|
"build": "microbundle --no-compress --format modern,cjs --jsx React.createElement",
|
|
11
11
|
"watch": "microbundle watch --no-compress --format modern,cjs --jsx React.createElement"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@tsed/redux-utils": "1.13.
|
|
14
|
+
"@tsed/redux-utils": "1.13.2",
|
|
15
15
|
"eventemitter2": "^6.4.3",
|
|
16
16
|
"prop-types": "^15.7.2"
|
|
17
17
|
},
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"tooltip.js": ">=1.3.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@tsed/tailwind": "1.13.
|
|
30
|
-
"@tsed/tailwind-formio": "1.13.
|
|
29
|
+
"@tsed/tailwind": "1.13.2",
|
|
30
|
+
"@tsed/tailwind-formio": "1.13.2"
|
|
31
31
|
},
|
|
32
32
|
"repository": "https://github.com/TypedProject/tsed-formio",
|
|
33
33
|
"bugs": {
|
|
@@ -1966,6 +1966,29 @@
|
|
|
1966
1966
|
"id": "em22wkd",
|
|
1967
1967
|
"defaultValue": null
|
|
1968
1968
|
},
|
|
1969
|
+
{
|
|
1970
|
+
"label": "Edit Grid",
|
|
1971
|
+
"tableView": false,
|
|
1972
|
+
"rowDrafts": false,
|
|
1973
|
+
"key": "editGrid",
|
|
1974
|
+
"type": "editgrid",
|
|
1975
|
+
"displayAsTable": false,
|
|
1976
|
+
"input": true,
|
|
1977
|
+
"components": [
|
|
1978
|
+
{
|
|
1979
|
+
"label": "Currency",
|
|
1980
|
+
"mask": false,
|
|
1981
|
+
"spellcheck": true,
|
|
1982
|
+
"tableView": true,
|
|
1983
|
+
"currency": "USD",
|
|
1984
|
+
"inputFormat": "plain",
|
|
1985
|
+
"key": "currency",
|
|
1986
|
+
"type": "currency",
|
|
1987
|
+
"input": true,
|
|
1988
|
+
"delimiter": true
|
|
1989
|
+
}
|
|
1990
|
+
]
|
|
1991
|
+
},
|
|
1969
1992
|
{
|
|
1970
1993
|
"type": "button",
|
|
1971
1994
|
"label": "Submit",
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {render} from "@testing-library/react";
|
|
2
|
+
import {screen} from "@testing-library/dom";
|
|
3
|
+
import {Form} from "./form.component";
|
|
4
|
+
|
|
5
|
+
async function createFixture(props: any = {}) {
|
|
6
|
+
const onSubmit = jest.fn();
|
|
7
|
+
const form = {
|
|
8
|
+
type: "form",
|
|
9
|
+
display: "form",
|
|
10
|
+
tags: [],
|
|
11
|
+
components: [
|
|
12
|
+
{
|
|
13
|
+
label: "First name",
|
|
14
|
+
"placeholder": "Fill first name",
|
|
15
|
+
widget: {
|
|
16
|
+
type: "input"
|
|
17
|
+
},
|
|
18
|
+
errorLabel: "",
|
|
19
|
+
key: "firstName",
|
|
20
|
+
inputType: "text",
|
|
21
|
+
type: "textfield",
|
|
22
|
+
id: "eqb1o4r",
|
|
23
|
+
defaultValue: ""
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
label: "Submit form",
|
|
27
|
+
showValidations: false,
|
|
28
|
+
tableView: false,
|
|
29
|
+
key: "submit",
|
|
30
|
+
type: "button",
|
|
31
|
+
input: true
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
render(<Form {...props} form={form} onSubmit={onSubmit}/>);
|
|
37
|
+
|
|
38
|
+
return {onSubmit};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe("Form", () => {
|
|
42
|
+
it("should render the Form", async () => {
|
|
43
|
+
await createFixture({
|
|
44
|
+
data: [],
|
|
45
|
+
model: "MyForm",
|
|
46
|
+
groups: ["creation"],
|
|
47
|
+
params: {
|
|
48
|
+
env: "prod"
|
|
49
|
+
},
|
|
50
|
+
isActive: false
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(screen.getByTestId("formioContainer")).toBeInTheDocument();
|
|
54
|
+
expect(screen.getByText("First name")).toBeInTheDocument();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -14,10 +14,10 @@ export interface FormProps<Data = any> extends UseFormHookProps<Data> {
|
|
|
14
14
|
className?: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function Form(props: Partial<FormProps
|
|
17
|
+
export function Form<Data = any>(props: Partial<FormProps<Data>>) {
|
|
18
18
|
const { element } = useForm(props);
|
|
19
19
|
|
|
20
|
-
return <div data-testid={
|
|
20
|
+
return <div data-testid={`formioContainer${props.name || ""}`} ref={element} className={props.className} />;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
Form.propTypes = {
|
|
@@ -11,21 +11,112 @@ export default {
|
|
|
11
11
|
control: {
|
|
12
12
|
type: "object"
|
|
13
13
|
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
},
|
|
15
|
+
onPrevPage: {action: "onPrevPage"},
|
|
16
|
+
onNextPage: {action: "onNextPage"},
|
|
17
|
+
onCancel: {action: "onCancel"},
|
|
18
|
+
onChange: {action: "onChange"},
|
|
19
|
+
onCustomEvent: {action: "onCustomEvent"},
|
|
20
|
+
onComponentChange: {action: "onComponentChange"},
|
|
21
|
+
onSubmit: {action: "onSubmit"},
|
|
22
|
+
onAsyncSubmit: {action: "onAsyncSubmit"},
|
|
23
|
+
onSubmitDone: {action: "onSubmitDone"},
|
|
24
|
+
onFormLoad: {action: "onFormLoad"},
|
|
25
|
+
onError: {action: "onError"},
|
|
26
|
+
onRender: {action: "onRender"},
|
|
27
|
+
onAttach: {action: "onAttach"},
|
|
28
|
+
onBuild: {action: "onBuild"},
|
|
29
|
+
onFocus: {action: "onFocus"},
|
|
30
|
+
onBlur: {action: "onBlur"},
|
|
31
|
+
onInitialized: {action: "onInitialized"},
|
|
32
|
+
onFormReady: {action: "onFormReady"}
|
|
33
|
+
}
|
|
17
34
|
};
|
|
18
35
|
|
|
36
|
+
function filter(args: any[]) {
|
|
37
|
+
return args
|
|
38
|
+
.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
|
-
delete args.onRender;
|
|
21
|
-
delete args.onComponentChange;
|
|
22
116
|
return (
|
|
23
117
|
<Form
|
|
24
|
-
{...args}
|
|
118
|
+
{...wrap(args)}
|
|
25
119
|
form={args.form}
|
|
26
|
-
onFormReady={(formio) => {
|
|
27
|
-
console.log("ready", formio);
|
|
28
|
-
}}
|
|
29
120
|
options={{template: "tailwind", iconset: "bx"}}
|
|
30
121
|
/>
|
|
31
122
|
);
|
|
@@ -36,34 +127,27 @@ Sandbox.args = {
|
|
|
36
127
|
};
|
|
37
128
|
|
|
38
129
|
export const TriggerError = (args: any) => {
|
|
39
|
-
|
|
40
|
-
|
|
130
|
+
const onAsyncSubmit = (submission: Submission) => {
|
|
131
|
+
return new Promise((resolve, reject) => {
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
reject(new Error("server error"));
|
|
134
|
+
}, 500);
|
|
135
|
+
}).catch((error) => {
|
|
136
|
+
error.errors = {
|
|
137
|
+
"message": "My custom message about this field",
|
|
138
|
+
"type": "custom",
|
|
139
|
+
"path": ["firstName"],
|
|
140
|
+
"level": "error"
|
|
141
|
+
};
|
|
142
|
+
throw error;
|
|
143
|
+
});
|
|
144
|
+
};
|
|
41
145
|
|
|
42
146
|
return (
|
|
43
|
-
<Form
|
|
44
|
-
{...args}
|
|
147
|
+
<Form<any>
|
|
148
|
+
{...wrap(args)}
|
|
45
149
|
form={args.form}
|
|
46
|
-
onAsyncSubmit={
|
|
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
|
-
}}
|
|
150
|
+
onAsyncSubmit={onAsyncSubmit}
|
|
67
151
|
/>
|
|
68
152
|
);
|
|
69
153
|
};
|
|
@@ -97,3 +181,26 @@ TriggerError.args = {
|
|
|
97
181
|
]
|
|
98
182
|
}
|
|
99
183
|
};
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
export const ReadOnly = (args: any) => {
|
|
187
|
+
return (
|
|
188
|
+
<Form
|
|
189
|
+
{...wrap(args)}
|
|
190
|
+
options={{template: "tailwind", iconset: "bx", readOnly: args.readOnly}}
|
|
191
|
+
form={args.form}
|
|
192
|
+
submission={{
|
|
193
|
+
data: {
|
|
194
|
+
editGrid: [
|
|
195
|
+
{currency: "EUR"}
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
}}
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
ReadOnly.args = {
|
|
204
|
+
readonly: true,
|
|
205
|
+
form
|
|
206
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {ExtendedComponentSchema, Form} from "formiojs";
|
|
2
|
+
import {get} from "lodash";
|
|
3
3
|
import cloneDeep from "lodash/cloneDeep";
|
|
4
4
|
import isEqual from "lodash/isEqual";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import {useEffect, useRef} from "react";
|
|
6
|
+
import {callLast} from "../../utils/callLast";
|
|
7
|
+
import {FormOptions, FormSchema, Submission} from "../../interfaces";
|
|
8
8
|
|
|
9
9
|
export interface ChangedSubmission<T = any> extends Submission<T> {
|
|
10
10
|
changed: any;
|
|
@@ -34,6 +34,8 @@ export interface UseFormHookProps<Data = any> extends Record<string, any> {
|
|
|
34
34
|
* Data submission
|
|
35
35
|
*/
|
|
36
36
|
submission?: Submission<Data>;
|
|
37
|
+
|
|
38
|
+
/// events
|
|
37
39
|
onPrevPage?: (obj: FormPageChangeProps<Data>) => void;
|
|
38
40
|
onNextPage?: (obj: FormPageChangeProps<Data>) => void;
|
|
39
41
|
onCancel?: Function;
|
|
@@ -41,7 +43,7 @@ export interface UseFormHookProps<Data = any> extends Record<string, any> {
|
|
|
41
43
|
onCustomEvent?: (obj: { type: string; event: string; component: ExtendedComponentSchema; data: any }) => void;
|
|
42
44
|
onComponentChange?: (component: ExtendedComponentSchema) => void;
|
|
43
45
|
onSubmit?: (submission: Submission<Data>) => void;
|
|
44
|
-
onAsyncSubmit?: (submission: Submission<Data>) => Promise<
|
|
46
|
+
onAsyncSubmit?: (submission: Submission<Data>) => Promise<any>;
|
|
45
47
|
onSubmitDone?: (submission: Submission<Data>) => void;
|
|
46
48
|
onFormLoad?: Function;
|
|
47
49
|
onError?: (errors: any) => void;
|
|
@@ -52,20 +54,43 @@ export interface UseFormHookProps<Data = any> extends Record<string, any> {
|
|
|
52
54
|
onBlur?: Function;
|
|
53
55
|
onInitialized?: Function;
|
|
54
56
|
onFormReady?: (formio: Form) => void;
|
|
55
|
-
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function useDebounce(event: string, callback: any, events: Map<string, any>) {
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
callback && events.set(event, callLast(callback, 100));
|
|
62
|
+
}, [callback, event, events]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function useEvents(funcs: any) {
|
|
66
|
+
const events = useRef<Map<string, any>>(new Map());
|
|
67
|
+
|
|
68
|
+
const hasEvent = (event: string) => {
|
|
69
|
+
return funcs.hasOwnProperty(event) && typeof funcs[event] === "function"
|
|
70
|
+
}
|
|
71
|
+
const emit = (event: string, ...args: any[]) => {
|
|
72
|
+
if (hasEvent(event)) {
|
|
73
|
+
const fn = events.current.has(event) ? events.current.get(event) : funcs[event]
|
|
74
|
+
return fn(...args);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
useDebounce("onChange", funcs.onChange, events.current);
|
|
79
|
+
|
|
80
|
+
return {events, emit, hasEvent};
|
|
56
81
|
}
|
|
57
82
|
|
|
58
83
|
export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
59
|
-
const {
|
|
84
|
+
const {src, form, options = {}, submission, url, ...funcs} = props;
|
|
60
85
|
const element = useRef<any>();
|
|
61
86
|
const isLoaded = useRef<boolean>();
|
|
62
87
|
const instance = useRef<Form>();
|
|
63
|
-
const
|
|
88
|
+
const {emit, hasEvent} = useEvents(funcs);
|
|
64
89
|
|
|
65
90
|
async function customValidation(submission: Submission, callback: (err: Error | null) => void) {
|
|
66
|
-
if (
|
|
91
|
+
if (hasEvent("onAsyncSubmit")) {
|
|
67
92
|
try {
|
|
68
|
-
await
|
|
93
|
+
await emit("onAsyncSubmit", submission, instance.current);
|
|
69
94
|
} catch (err) {
|
|
70
95
|
callback(err?.errors || err);
|
|
71
96
|
}
|
|
@@ -93,27 +118,15 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
93
118
|
}
|
|
94
119
|
|
|
95
120
|
if (event.startsWith("formio.")) {
|
|
96
|
-
const
|
|
121
|
+
const eventName = `on${event.charAt(7).toUpperCase()}${event.slice(8)}`;
|
|
97
122
|
|
|
98
|
-
if (
|
|
123
|
+
if (eventName === "onChange") {
|
|
99
124
|
if (isEqual(get(submission, "data"), args[0].data)) {
|
|
100
125
|
return;
|
|
101
126
|
}
|
|
102
127
|
}
|
|
103
128
|
|
|
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
|
-
}
|
|
129
|
+
emit(eventName, ...args, instance.current)
|
|
117
130
|
}
|
|
118
131
|
});
|
|
119
132
|
|
|
@@ -172,18 +185,6 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
172
185
|
};
|
|
173
186
|
}, []);
|
|
174
187
|
|
|
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
188
|
return {
|
|
188
189
|
element
|
|
189
190
|
};
|
|
@@ -51,7 +51,7 @@ function useFormAccess({ form: formDefinition, roles, onSubmit, options }: FormA
|
|
|
51
51
|
submissions,
|
|
52
52
|
onChange,
|
|
53
53
|
onSubmit: () => {
|
|
54
|
-
onSubmit(submissionsToDataAccess(formDefinition, submissions));
|
|
54
|
+
onSubmit && onSubmit(submissionsToDataAccess(formDefinition, submissions));
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {ExtendedComponentSchema} from "formiojs";
|
|
2
2
|
import cloneDeep from "lodash/cloneDeep";
|
|
3
3
|
import isEqual from "lodash/isEqual";
|
|
4
4
|
import noop from "lodash/noop";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import {FormSchema, Submission} from "../../interfaces";
|
|
6
|
+
import {RoleSchema} from "../../interfaces/RoleSchema";
|
|
7
|
+
import {getAccessPermissionForm, getSubmissionPermissionForm} from "./formAccess.schema";
|
|
8
8
|
|
|
9
9
|
export interface Choice {
|
|
10
10
|
label: string;
|
|
@@ -31,19 +31,19 @@ export type SubmissionAccess = {
|
|
|
31
31
|
function rolesToChoices(roles: RoleSchema[]): Choice[] {
|
|
32
32
|
return Object.values(roles).map((role) => {
|
|
33
33
|
return {
|
|
34
|
-
label: role.title,
|
|
35
|
-
value: role._id
|
|
34
|
+
label: role.title || "",
|
|
35
|
+
value: role._id || ""
|
|
36
36
|
};
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function accessToHash(keys: string[], access: Access[] = []): AccessRoles {
|
|
40
|
+
function accessToHash(keys: (string | undefined)[] | undefined, access: Access[] = []): AccessRoles {
|
|
41
41
|
const hash = Object.values(access).reduce((o: any, role: any) => {
|
|
42
42
|
o[role.type] = role.roles;
|
|
43
43
|
return o;
|
|
44
44
|
}, {});
|
|
45
45
|
|
|
46
|
-
return keys.reduce((data, key) => {
|
|
46
|
+
return ((keys || []).filter(Boolean) as any[]).reduce((data, key: string) => {
|
|
47
47
|
return {
|
|
48
48
|
...data,
|
|
49
49
|
[key]: hash[key] || []
|
|
@@ -69,8 +69,8 @@ function hashToAccess(data: AccessRoles) {
|
|
|
69
69
|
|
|
70
70
|
export function getFormAccess(roles: RoleSchema[]): FormAccessSchema {
|
|
71
71
|
const choices = rolesToChoices(roles);
|
|
72
|
-
const access = getAccessPermissionForm({
|
|
73
|
-
const submissionAccess = getSubmissionPermissionForm({
|
|
72
|
+
const access = getAccessPermissionForm({choices});
|
|
73
|
+
const submissionAccess = getSubmissionPermissionForm({choices});
|
|
74
74
|
|
|
75
75
|
return {
|
|
76
76
|
access,
|
|
@@ -79,7 +79,7 @@ export function getFormAccess(roles: RoleSchema[]): FormAccessSchema {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export function dataAccessToSubmissions(form: Partial<FormSchema>, formAccess: FormAccessSchema): SubmissionAccess {
|
|
82
|
-
const getKeys = (components: ExtendedComponentSchema[]) => components.map(({
|
|
82
|
+
const getKeys = (components: ExtendedComponentSchema[]) => components.map(({key}) => key);
|
|
83
83
|
|
|
84
84
|
return {
|
|
85
85
|
access: {
|
|
@@ -100,14 +100,14 @@ export function submissionsToDataAccess(form: Partial<FormSchema>, submissions:
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
export function shouldUpdate(type: string, submission: Submission<AccessRoles>, submissions: SubmissionAccess) {
|
|
103
|
-
return !isEqual(submission.data, submissions[type].data);
|
|
103
|
+
return !isEqual(submission.data, (submissions as any)[type].data);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
export function updateSubmissions(type: string, submission: Submission<AccessRoles>, submissions: SubmissionAccess, cb: Function = noop) {
|
|
107
107
|
if (shouldUpdate(type, submission, submissions)) {
|
|
108
108
|
submissions = {
|
|
109
109
|
...submissions,
|
|
110
|
-
[type]: {
|
|
110
|
+
[type]: {data: submission.data}
|
|
111
111
|
};
|
|
112
112
|
cb(submissions);
|
|
113
113
|
}
|
|
@@ -39,7 +39,7 @@ export interface FormActionProps {
|
|
|
39
39
|
|
|
40
40
|
export function FormAction({ actionInfo, children, onSubmit, options, ...props }: PropsWithChildren<FormActionProps>): ReactElement {
|
|
41
41
|
const { form, submission } = useMemo(() => {
|
|
42
|
-
const submission = mapData(props.submission || {}, actionInfo.defaults);
|
|
42
|
+
const submission = mapData(props.submission || {}, actionInfo.defaults!);
|
|
43
43
|
const form = mapSettingsForm(actionInfo.settingsForm);
|
|
44
44
|
|
|
45
45
|
return { form, submission: { data: submission } };
|
|
@@ -175,7 +175,7 @@ export class FormBuilder extends React.Component<FormBuilderProps, any> {
|
|
|
175
175
|
|
|
176
176
|
whenComponentsChange(components: ComponentSchema[]) {
|
|
177
177
|
this.setState({ components }, () => {
|
|
178
|
-
this.props?.onChange(components);
|
|
178
|
+
this.props?.onChange && this.props.onChange(components);
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
|