@tsed/react-formio 1.13.2 → 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/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/index.d.ts +2 -2
- package/dist/components/table/components/defaultCellHeader.component.d.ts +1 -1
- package/dist/components/table/index.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7904 -7902
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +5506 -5500
- package/dist/index.modern.js.map +1 -1
- package/dist/stores/actions/index.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 +7 -4
- 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 +7 -6
- package/src/components/form/form.component.tsx +2 -1
- package/src/components/form/form.stories.tsx +60 -75
- package/src/components/form/useForm.hook.ts +13 -12
- package/src/components/form-access/formAccess.component.tsx +2 -1
- 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 +9 -8
- package/src/components/form-action/formAction.component.tsx +4 -3
- package/src/components/form-action/formAction.stories.tsx +225 -227
- package/src/components/form-builder/formBuilder.component.tsx +1 -0
- 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 +25 -26
- package/src/components/form-edit/formEdit.component.tsx +1 -0
- 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 +1 -0
- 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 +5 -4
- package/src/components/input-tags/inputTags.stories.tsx +1 -0
- package/src/components/input-text/inputText.component.spec.tsx +12 -11
- package/src/components/input-text/inputText.component.tsx +1 -0
- 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 +1 -1
- 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 +3 -2
- package/src/components/select/select.component.spec.tsx +17 -18
- package/src/components/select/select.component.tsx +1 -0
- package/src/components/select/select.stories.tsx +1 -0
- package/src/components/submissions-table/submissionsTable.component.tsx +6 -5
- 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 +45 -58
- package/src/components/table/table.stories.tsx +2 -1
- package/src/components/table/utils/mapFormToColumns.tsx +2 -1
- 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 +10 -4
- 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 +2 -1
- package/src/stores/auth/getAccess.action.spec.ts +1 -0
- package/src/stores/auth/getAccess.action.ts +1 -0
- 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 -1
- 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/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 +1 -1
- 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
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from "./auth.constant";
|
|
2
|
-
export * from "./auth.utils";
|
|
3
1
|
export * from "./auth.actions";
|
|
2
|
+
export * from "./auth.constant";
|
|
4
3
|
export * from "./auth.reducers";
|
|
5
4
|
export * from "./auth.selectors";
|
|
6
|
-
export * from "./
|
|
5
|
+
export * from "./auth.utils";
|
|
7
6
|
export * from "./getAccess.action";
|
|
7
|
+
export * from "./getProjectAccess.action";
|
|
8
|
+
export * from "./initAuth.action";
|
|
8
9
|
export * from "./logout.action";
|
|
9
10
|
export * from "./setUser.action";
|
|
10
|
-
export * from "./initAuth.action";
|
package/dist/stores/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from "./auth";
|
|
2
1
|
export * from "./action";
|
|
3
2
|
export * from "./action-info";
|
|
4
3
|
export * from "./actions";
|
|
4
|
+
export * from "./auth";
|
|
5
5
|
export * from "./form";
|
|
6
6
|
export * from "./forms";
|
|
7
|
+
export * from "./root";
|
|
7
8
|
export * from "./submission";
|
|
8
9
|
export * from "./submissions";
|
|
9
|
-
export * from "./root";
|
|
10
10
|
export declare const defaultFormioReducer: Record<string, import("@tsed/redux-utils").ReduceFunction<any, any>>;
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/react-formio",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.3",
|
|
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
|
+
"lint": "eslint \"**/*.{js,jsx,ts,tsx}\"",
|
|
10
|
+
"lint:fix": "yarn lint --fix",
|
|
9
11
|
"test": "cross-env NODE_ENV=test jest --coverage",
|
|
12
|
+
"test:coverage:update": "write-coverage",
|
|
10
13
|
"build": "microbundle --no-compress --format modern,cjs --jsx React.createElement",
|
|
11
14
|
"watch": "microbundle watch --no-compress --format modern,cjs --jsx React.createElement"
|
|
12
15
|
},
|
|
13
16
|
"dependencies": {
|
|
14
|
-
"@tsed/redux-utils": "1.13.
|
|
17
|
+
"@tsed/redux-utils": "1.13.3",
|
|
15
18
|
"eventemitter2": "^6.4.3",
|
|
16
19
|
"prop-types": "^15.7.2"
|
|
17
20
|
},
|
|
@@ -26,8 +29,8 @@
|
|
|
26
29
|
"tooltip.js": ">=1.3.3"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
29
|
-
"@tsed/tailwind": "1.13.
|
|
30
|
-
"@tsed/tailwind-formio": "1.13.
|
|
32
|
+
"@tsed/tailwind": "1.13.3",
|
|
33
|
+
"@tsed/tailwind-formio": "1.13.3"
|
|
31
34
|
},
|
|
32
35
|
"repository": "https://github.com/TypedProject/tsed-formio",
|
|
33
36
|
"bugs": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { fireEvent, render } from "@testing-library/react";
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
2
|
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import React from "react";
|
|
4
4
|
|
|
5
5
|
import { Sandbox } from "./actionsTable.stories";
|
|
6
6
|
|
|
@@ -8,11 +8,11 @@ describe("ActionsTable", () => {
|
|
|
8
8
|
it("should render the table actions", async () => {
|
|
9
9
|
const onAddAction = jest.fn();
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
|
|
12
12
|
|
|
13
|
-
const btn = getByRole("button", { name: /add action/i });
|
|
14
|
-
const cells = getAllByRole("cell");
|
|
15
|
-
const options = getAllByRole("option");
|
|
13
|
+
const btn = screen.getByRole("button", { name: /add action/i });
|
|
14
|
+
const cells = screen.getAllByRole("cell");
|
|
15
|
+
const options = screen.getAllByRole("option");
|
|
16
16
|
|
|
17
17
|
expect(btn).toHaveProperty("disabled");
|
|
18
18
|
expect(btn.innerHTML).toMatch("Add action");
|
|
@@ -25,9 +25,9 @@ describe("ActionsTable", () => {
|
|
|
25
25
|
it("should not call addAction when the default item is selected", async () => {
|
|
26
26
|
const onAddAction = jest.fn();
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
|
|
29
29
|
|
|
30
|
-
const btn = getByRole("button", { name: /add action/i });
|
|
30
|
+
const btn = screen.getByRole("button", { name: /add action/i });
|
|
31
31
|
|
|
32
32
|
await fireEvent.click(btn);
|
|
33
33
|
expect(onAddAction).not.toHaveBeenCalled();
|
|
@@ -35,10 +35,10 @@ describe("ActionsTable", () => {
|
|
|
35
35
|
it("should call addAction with the selected action", async () => {
|
|
36
36
|
const onAddAction = jest.fn();
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
render(<Sandbox {...Sandbox.args} onAddAction={onAddAction} />);
|
|
39
39
|
|
|
40
|
-
const btn = getByRole("button", { name: /add action/i });
|
|
41
|
-
const select = getByRole("combobox");
|
|
40
|
+
const btn = screen.getByRole("button", { name: /add action/i });
|
|
41
|
+
const select = screen.getByRole("combobox");
|
|
42
42
|
|
|
43
43
|
await userEvent.selectOptions(select, String(Sandbox.args.availableActions[1].value));
|
|
44
44
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import classnames from "classnames";
|
|
2
2
|
import noop from "lodash/noop";
|
|
3
3
|
import React, { useState } from "react";
|
|
4
|
+
|
|
4
5
|
import { ActionSchema } from "../../interfaces";
|
|
5
6
|
import { iconClass } from "../../utils/iconClass";
|
|
6
7
|
import { Select } from "../select/select.component";
|
|
@@ -21,15 +22,13 @@ export function ActionsTable({
|
|
|
21
22
|
const { i18n = (f: string) => f } = props;
|
|
22
23
|
const [currentAction, setAction] = useState("");
|
|
23
24
|
|
|
24
|
-
const columns =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
];
|
|
32
|
-
}, []);
|
|
25
|
+
const columns = [
|
|
26
|
+
{
|
|
27
|
+
Header: i18n("Actions"),
|
|
28
|
+
accessor: "title",
|
|
29
|
+
id: "title"
|
|
30
|
+
}
|
|
31
|
+
];
|
|
33
32
|
|
|
34
33
|
return (
|
|
35
34
|
<Table {...props} disableFilters={disableFilters} disablePagination={disablePagination} columns={columns}>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
1
2
|
import React from "react";
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
import { Sandbox } from "./alert.stories";
|
|
4
5
|
|
|
5
6
|
describe("Alert component", () => {
|
|
@@ -11,9 +12,10 @@ describe("Alert component", () => {
|
|
|
11
12
|
|
|
12
13
|
it("should display an error when the error is in string format", () => {
|
|
13
14
|
const error = "error in string format";
|
|
14
|
-
const { getByRole } = render(<Sandbox {...Sandbox.args} error={error} />);
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
render(<Sandbox {...Sandbox.args} error={error} />);
|
|
17
|
+
|
|
18
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
17
19
|
|
|
18
20
|
expect(alert).toBeInTheDocument();
|
|
19
21
|
expect(alert).toHaveClass("alert alert-danger");
|
|
@@ -23,13 +25,13 @@ describe("Alert component", () => {
|
|
|
23
25
|
it("should display error(s) when the error is an array", () => {
|
|
24
26
|
const arrayOfErrors = ["first error", "second error", "third error"];
|
|
25
27
|
const joinedErrors = arrayOfErrors.map((error) => error).join("");
|
|
26
|
-
|
|
28
|
+
render(<Sandbox {...Sandbox.args} error={arrayOfErrors} />);
|
|
27
29
|
|
|
28
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
30
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
29
31
|
|
|
30
32
|
expect(alert).toBeInTheDocument();
|
|
31
33
|
expect(alert).toHaveClass("alert alert-danger");
|
|
32
|
-
expect(getByText(joinedErrors)).toBeInTheDocument();
|
|
34
|
+
expect(screen.getByText(joinedErrors)).toBeInTheDocument();
|
|
33
35
|
});
|
|
34
36
|
|
|
35
37
|
it("should display error's names paths and messages when the error is an object that has an 'errors' property that contains an array of error objects", () => {
|
|
@@ -40,9 +42,9 @@ describe("Alert component", () => {
|
|
|
40
42
|
{ name: "third error", path: "/path", message: "message" }
|
|
41
43
|
]
|
|
42
44
|
};
|
|
43
|
-
|
|
45
|
+
render(<Sandbox {...Sandbox.args} error={arrayOfErrors} />);
|
|
44
46
|
|
|
45
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
47
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
46
48
|
|
|
47
49
|
expect(alert).toBeInTheDocument();
|
|
48
50
|
expect(alert).toHaveClass("alert alert-danger");
|
|
@@ -51,33 +53,33 @@ describe("Alert component", () => {
|
|
|
51
53
|
|
|
52
54
|
it("should display an error message when the error is a standard error", () => {
|
|
53
55
|
const standardError = { message: "first error" };
|
|
54
|
-
|
|
56
|
+
render(<Sandbox {...Sandbox.args} error={standardError} />);
|
|
55
57
|
|
|
56
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
58
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
57
59
|
|
|
58
60
|
expect(alert).toBeInTheDocument();
|
|
59
61
|
expect(alert).toHaveClass("alert alert-danger");
|
|
60
|
-
expect(getByText(standardError.message)).toBeInTheDocument();
|
|
62
|
+
expect(screen.getByText(standardError.message)).toBeInTheDocument();
|
|
61
63
|
});
|
|
62
64
|
|
|
63
65
|
it("should display error(s) message(s) when the error is a joi validation error", () => {
|
|
64
66
|
const joiValidationError = { name: "ValidationError", details: [{ message: "message 1" }, { message: "message 2" }] };
|
|
65
|
-
|
|
67
|
+
render(<Sandbox {...Sandbox.args} error={joiValidationError} />);
|
|
66
68
|
|
|
67
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
69
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
68
70
|
|
|
69
71
|
expect(alert).toBeInTheDocument();
|
|
70
72
|
expect(alert).toHaveClass("alert alert-danger");
|
|
71
|
-
expect(getByText("message 1")).toBeInTheDocument();
|
|
72
|
-
expect(getByText("message 2")).toBeInTheDocument();
|
|
73
|
+
expect(screen.getByText("message 1")).toBeInTheDocument();
|
|
74
|
+
expect(screen.getByText("message 2")).toBeInTheDocument();
|
|
73
75
|
});
|
|
74
76
|
|
|
75
77
|
it("should display a custom error message that asks to reload the form when a conflict error occurs in a form", () => {
|
|
76
78
|
const error = { _id: "some id", display: "some value" };
|
|
77
79
|
const messageReturned = "Another user has saved this form already. Please reload and re-apply your changes.";
|
|
78
|
-
|
|
80
|
+
render(<Sandbox {...Sandbox.args} error={error} />);
|
|
79
81
|
|
|
80
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
82
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
81
83
|
|
|
82
84
|
expect(alert).toBeInTheDocument();
|
|
83
85
|
expect(alert).toHaveClass("alert alert-danger");
|
|
@@ -86,9 +88,9 @@ describe("Alert component", () => {
|
|
|
86
88
|
|
|
87
89
|
it("should display an error message by default when the error format does not match any of the conditions of the formatError() handler", () => {
|
|
88
90
|
const messageError: string = "An error occurred. See console logs for details.";
|
|
89
|
-
|
|
91
|
+
render(<Sandbox {...Sandbox.args} error={true} />);
|
|
90
92
|
|
|
91
|
-
const alert = getByRole("alert") as HTMLDivElement;
|
|
93
|
+
const alert = screen.getByRole("alert") as HTMLDivElement;
|
|
92
94
|
|
|
93
95
|
expect(alert).toBeInTheDocument();
|
|
94
96
|
expect(alert).toHaveClass("alert alert-danger");
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { render } from "@testing-library/react";
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
2
|
import React from "react";
|
|
3
|
+
|
|
3
4
|
import { Sandbox } from "./card.stories";
|
|
4
5
|
|
|
5
6
|
describe("Card", () => {
|
|
6
7
|
it("should render the card component", () => {
|
|
7
|
-
|
|
8
|
+
render(<Sandbox {...Sandbox.args} />);
|
|
8
9
|
|
|
9
|
-
const title = getByRole("heading");
|
|
10
|
-
const body = getByRole("article");
|
|
10
|
+
const title = screen.getByRole("heading");
|
|
11
|
+
const body = screen.getByRole("article");
|
|
11
12
|
|
|
12
13
|
expect(title).toHaveTextContent("label");
|
|
13
14
|
expect(body).toHaveTextContent("test");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { screen } from "@testing-library/react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
|
|
4
|
+
import { Form } from "./form.component";
|
|
4
5
|
|
|
5
6
|
async function createFixture(props: any = {}) {
|
|
6
7
|
const onSubmit = jest.fn();
|
|
@@ -11,7 +12,7 @@ async function createFixture(props: any = {}) {
|
|
|
11
12
|
components: [
|
|
12
13
|
{
|
|
13
14
|
label: "First name",
|
|
14
|
-
|
|
15
|
+
placeholder: "Fill first name",
|
|
15
16
|
widget: {
|
|
16
17
|
type: "input"
|
|
17
18
|
},
|
|
@@ -33,9 +34,9 @@ async function createFixture(props: any = {}) {
|
|
|
33
34
|
]
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
render(<Form {...props} form={form} onSubmit={onSubmit}/>);
|
|
37
|
+
render(<Form {...props} form={form} onSubmit={onSubmit} />);
|
|
37
38
|
|
|
38
|
-
return {onSubmit};
|
|
39
|
+
return { onSubmit };
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
describe("Form", () => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import AllComponents from "formiojs/components";
|
|
2
1
|
import { Components } from "formiojs";
|
|
2
|
+
import AllComponents from "formiojs/components";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import React from "react";
|
|
5
|
+
|
|
5
6
|
import { useForm, UseFormHookProps } from "./useForm.hook";
|
|
6
7
|
|
|
7
8
|
Components.setComponents(AllComponents);
|
|
@@ -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",
|
|
@@ -12,44 +13,43 @@ export default {
|
|
|
12
13
|
type: "object"
|
|
13
14
|
}
|
|
14
15
|
},
|
|
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"}
|
|
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" }
|
|
33
34
|
}
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
function filter(args: any[]) {
|
|
37
|
-
return args
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
38
|
+
return args.map((item) => {
|
|
39
|
+
if (item && item._form) {
|
|
40
|
+
return "FormioInstance";
|
|
41
|
+
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (item && item.component) {
|
|
44
|
+
return ["Component", item.component.type, item.component.key].filter(Boolean).join(":");
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
if (item && item.changed) {
|
|
48
|
+
return `${item.changed.component.key}(${item.changed.value})`;
|
|
49
|
+
}
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
return item;
|
|
52
|
+
});
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function wrap(args: any) {
|
|
@@ -113,13 +113,7 @@ function wrap(args: any) {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
export const Sandbox = (args: any) => {
|
|
116
|
-
return (
|
|
117
|
-
<Form
|
|
118
|
-
{...wrap(args)}
|
|
119
|
-
form={args.form}
|
|
120
|
-
options={{template: "tailwind", iconset: "bx"}}
|
|
121
|
-
/>
|
|
122
|
-
);
|
|
116
|
+
return <Form {...wrap(args)} form={args.form} options={{ template: "tailwind", iconset: "bx" }} />;
|
|
123
117
|
};
|
|
124
118
|
|
|
125
119
|
Sandbox.args = {
|
|
@@ -134,66 +128,57 @@ export const TriggerError = (args: any) => {
|
|
|
134
128
|
}, 500);
|
|
135
129
|
}).catch((error) => {
|
|
136
130
|
error.errors = {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
message: "My custom message about this field",
|
|
132
|
+
type: "custom",
|
|
133
|
+
path: ["firstName"],
|
|
134
|
+
level: "error"
|
|
141
135
|
};
|
|
142
136
|
throw error;
|
|
143
137
|
});
|
|
144
138
|
};
|
|
145
139
|
|
|
146
|
-
return (
|
|
147
|
-
<Form<any>
|
|
148
|
-
{...wrap(args)}
|
|
149
|
-
form={args.form}
|
|
150
|
-
onAsyncSubmit={onAsyncSubmit}
|
|
151
|
-
/>
|
|
152
|
-
);
|
|
140
|
+
return <Form<any> {...wrap(args)} form={args.form} onAsyncSubmit={onAsyncSubmit} />;
|
|
153
141
|
};
|
|
154
142
|
|
|
155
143
|
TriggerError.args = {
|
|
156
144
|
form: {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
145
|
+
type: "form",
|
|
146
|
+
display: "form",
|
|
147
|
+
tags: [],
|
|
148
|
+
components: [
|
|
161
149
|
{
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
150
|
+
label: "First name",
|
|
151
|
+
widget: {
|
|
152
|
+
type: "input"
|
|
165
153
|
},
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
154
|
+
errorLabel: "",
|
|
155
|
+
key: "firstName",
|
|
156
|
+
inputType: "text",
|
|
157
|
+
type: "textfield",
|
|
158
|
+
id: "eqb1o4r",
|
|
159
|
+
defaultValue: ""
|
|
172
160
|
},
|
|
173
161
|
{
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
162
|
+
label: "Submit",
|
|
163
|
+
showValidations: false,
|
|
164
|
+
tableView: false,
|
|
165
|
+
key: "submit",
|
|
166
|
+
type: "button",
|
|
167
|
+
input: true
|
|
180
168
|
}
|
|
181
169
|
]
|
|
182
170
|
}
|
|
183
171
|
};
|
|
184
172
|
|
|
185
|
-
|
|
186
173
|
export const ReadOnly = (args: any) => {
|
|
187
174
|
return (
|
|
188
175
|
<Form
|
|
189
176
|
{...wrap(args)}
|
|
190
|
-
options={{template: "tailwind", iconset: "bx", readOnly: args.readOnly}}
|
|
177
|
+
options={{ template: "tailwind", iconset: "bx", readOnly: args.readOnly }}
|
|
191
178
|
form={args.form}
|
|
192
179
|
submission={{
|
|
193
180
|
data: {
|
|
194
|
-
editGrid: [
|
|
195
|
-
{currency: "EUR"}
|
|
196
|
-
]
|
|
181
|
+
editGrid: [{ currency: "EUR" }]
|
|
197
182
|
}
|
|
198
183
|
}}
|
|
199
184
|
/>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {ExtendedComponentSchema, Form} from "formiojs";
|
|
2
|
-
import {get} from "lodash";
|
|
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 {useEffect, useRef} from "react";
|
|
6
|
-
|
|
7
|
-
import {FormOptions, FormSchema, Submission} from "../../interfaces";
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
6
|
+
|
|
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;
|
|
@@ -66,26 +67,26 @@ function useEvents(funcs: any) {
|
|
|
66
67
|
const events = useRef<Map<string, any>>(new Map());
|
|
67
68
|
|
|
68
69
|
const hasEvent = (event: string) => {
|
|
69
|
-
return funcs.hasOwnProperty(event) && typeof funcs[event] === "function"
|
|
70
|
-
}
|
|
70
|
+
return funcs.hasOwnProperty(event) && typeof funcs[event] === "function";
|
|
71
|
+
};
|
|
71
72
|
const emit = (event: string, ...args: any[]) => {
|
|
72
73
|
if (hasEvent(event)) {
|
|
73
|
-
const fn = events.current.has(event) ? events.current.get(event) : funcs[event]
|
|
74
|
+
const fn = events.current.has(event) ? events.current.get(event) : funcs[event];
|
|
74
75
|
return fn(...args);
|
|
75
76
|
}
|
|
76
77
|
};
|
|
77
78
|
|
|
78
79
|
useDebounce("onChange", funcs.onChange, events.current);
|
|
79
80
|
|
|
80
|
-
return {events, emit, hasEvent};
|
|
81
|
+
return { events, emit, hasEvent };
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
84
|
-
const {src, form, options = {}, submission, url, ...funcs} = props;
|
|
85
|
+
const { src, form, options = {}, submission, url, ...funcs } = props;
|
|
85
86
|
const element = useRef<any>();
|
|
86
87
|
const isLoaded = useRef<boolean>();
|
|
87
88
|
const instance = useRef<Form>();
|
|
88
|
-
const {emit, hasEvent} = useEvents(funcs);
|
|
89
|
+
const { emit, hasEvent } = useEvents(funcs);
|
|
89
90
|
|
|
90
91
|
async function customValidation(submission: Submission, callback: (err: Error | null) => void) {
|
|
91
92
|
if (hasEvent("onAsyncSubmit")) {
|
|
@@ -126,7 +127,7 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
emit(eventName, ...args, instance.current)
|
|
130
|
+
emit(eventName, ...args, instance.current);
|
|
130
131
|
}
|
|
131
132
|
});
|
|
132
133
|
|
|
@@ -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>;
|