@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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
import { iconClass } from "../../utils/iconClass";
|
|
5
|
+
import { Sandbox, WithDescription, WithPrefix, WithSuffix } from "./formControl.stories";
|
|
6
|
+
|
|
7
|
+
describe("form-control", () => {
|
|
8
|
+
it("should display form control component", () => {
|
|
9
|
+
render(<Sandbox {...Sandbox.args} name='test' />);
|
|
10
|
+
|
|
11
|
+
const formGroup = screen.getByTestId("form-group-test") as HTMLFormElement;
|
|
12
|
+
|
|
13
|
+
expect(formGroup).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should NOT display form-control component without a name attribute defined", () => {
|
|
17
|
+
const name = "";
|
|
18
|
+
render(<Sandbox {...Sandbox.args} name={name} />);
|
|
19
|
+
|
|
20
|
+
const formGroup = screen.queryByTestId(`form-group-${name}`) as HTMLFormElement;
|
|
21
|
+
|
|
22
|
+
expect(formGroup).not.toBeInTheDocument();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should display form-control component with className 'field-required' when the props 'required' is set to true", () => {
|
|
26
|
+
render(<Sandbox {...Sandbox.args} required={true} name='test' />);
|
|
27
|
+
|
|
28
|
+
const formGroup = screen.getByTestId("form-group-test") as HTMLFormElement;
|
|
29
|
+
const formControlLabel = screen.getByTestId(`form-control-label`) as HTMLLabelElement;
|
|
30
|
+
|
|
31
|
+
expect(formGroup).toBeInTheDocument();
|
|
32
|
+
expect(formControlLabel).toBeInTheDocument();
|
|
33
|
+
expect(formControlLabel).toHaveClass("col-form-label field-required");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should display prefix", () => {
|
|
37
|
+
const fontAwsomeCalendarIcon = "fa fa-calendar";
|
|
38
|
+
const prefix = (<i className={iconClass(undefined, "calendar")} />) as JSX.Element;
|
|
39
|
+
render(<WithPrefix {...Sandbox.args} name='testPrefix' prefix={prefix} />);
|
|
40
|
+
|
|
41
|
+
const formGroup = screen.getByTestId("form-group-testPrefix") as HTMLFormElement;
|
|
42
|
+
const formControlPrefix = screen.getByTestId("form-control-prefix") as HTMLSpanElement;
|
|
43
|
+
|
|
44
|
+
expect(formGroup).toBeInTheDocument();
|
|
45
|
+
expect(formControlPrefix).toBeInTheDocument();
|
|
46
|
+
expect(formControlPrefix).not.toBeEmptyDOMElement();
|
|
47
|
+
expect(formControlPrefix).toContainHTML(fontAwsomeCalendarIcon);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should display suffix", () => {
|
|
51
|
+
const fontAwsomeCalendarIcon = "fa fa-calendar";
|
|
52
|
+
const suffix = (<i className={iconClass(undefined, "calendar")} />) as JSX.Element;
|
|
53
|
+
render(<WithSuffix {...Sandbox.args} name='testSuffix' suffix={suffix} />);
|
|
54
|
+
|
|
55
|
+
const formGroup = screen.getByTestId("form-group-testSuffix") as HTMLFormElement;
|
|
56
|
+
const formControlSuffix = screen.getByTestId("form-control-suffix") as HTMLSpanElement;
|
|
57
|
+
|
|
58
|
+
expect(formGroup).toBeInTheDocument();
|
|
59
|
+
expect(formControlSuffix).toBeInTheDocument();
|
|
60
|
+
expect(formControlSuffix).not.toBeEmptyDOMElement();
|
|
61
|
+
expect(formControlSuffix).toContainHTML(fontAwsomeCalendarIcon);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should display description", () => {
|
|
65
|
+
const description = "test description";
|
|
66
|
+
render(<WithDescription {...Sandbox.args} name='testDescription' description={description} />);
|
|
67
|
+
|
|
68
|
+
const formGroup = screen.getByTestId("form-group-testDescription") as HTMLFormElement;
|
|
69
|
+
const formControlDescription = screen.getByTestId("form-control-description") as HTMLDivElement;
|
|
70
|
+
|
|
71
|
+
expect(formGroup).toBeInTheDocument();
|
|
72
|
+
expect(formControlDescription).toBeInTheDocument();
|
|
73
|
+
expect(formControlDescription).not.toBeEmptyDOMElement();
|
|
74
|
+
expect(screen.getByText(description)).toBeInTheDocument();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -8,8 +8,8 @@ export interface FormControlProps {
|
|
|
8
8
|
label?: string;
|
|
9
9
|
className?: string;
|
|
10
10
|
description?: string | React.ComponentType | any;
|
|
11
|
-
prefix?: React.ComponentType | any;
|
|
12
|
-
suffix?: React.ComponentType | any;
|
|
11
|
+
prefix?: JSX.Element | React.ComponentType | any;
|
|
12
|
+
suffix?: JSX.Element | React.ComponentType | any;
|
|
13
13
|
shadow?: boolean;
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -24,26 +24,34 @@ export function FormControl({
|
|
|
24
24
|
className
|
|
25
25
|
}: React.PropsWithChildren<FormControlProps>) {
|
|
26
26
|
return (
|
|
27
|
-
<div id={`form-group-${name || ""}`} className={classnames("form-group", className)}>
|
|
27
|
+
<div data-testid={name && `form-group-${name}`} id={`form-group-${name || ""}`} className={classnames("form-group", className)}>
|
|
28
28
|
{label && (
|
|
29
|
-
<label htmlFor={name} className={`col-form-label ${required ? " field-required" : ""}`}>
|
|
29
|
+
<label htmlFor={name} data-testid='form-control-label' className={`col-form-label ${required ? " field-required" : ""}`}>
|
|
30
30
|
{label}
|
|
31
31
|
</label>
|
|
32
32
|
)}
|
|
33
33
|
<div className={"input-group"}>
|
|
34
34
|
{prefix && (
|
|
35
35
|
<div className='input-group-prepend'>
|
|
36
|
-
<span className='input-group-text'
|
|
36
|
+
<span className='input-group-text' data-testid='form-control-prefix'>
|
|
37
|
+
{prefix}
|
|
38
|
+
</span>
|
|
37
39
|
</div>
|
|
38
40
|
)}
|
|
39
41
|
{children}
|
|
40
42
|
{suffix && (
|
|
41
43
|
<div className='input-group-append'>
|
|
42
|
-
<span className='input-group-text'
|
|
44
|
+
<span className='input-group-text' data-testid='form-control-suffix'>
|
|
45
|
+
{suffix}
|
|
46
|
+
</span>
|
|
43
47
|
</div>
|
|
44
48
|
)}
|
|
45
49
|
</div>
|
|
46
|
-
{description &&
|
|
50
|
+
{description && (
|
|
51
|
+
<div data-testid='form-control-description' className='form-text text-muted'>
|
|
52
|
+
{description}
|
|
53
|
+
</div>
|
|
54
|
+
)}
|
|
47
55
|
</div>
|
|
48
56
|
);
|
|
49
57
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { iconClass } from "../../utils/iconClass";
|
|
4
|
+
import { FormControl } from "./formControl.component";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: "ReactFormio/FormControl",
|
|
8
|
+
component: FormControl,
|
|
9
|
+
argTypes: {
|
|
10
|
+
label: {
|
|
11
|
+
control: {
|
|
12
|
+
type: "text"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
name: {
|
|
16
|
+
control: {
|
|
17
|
+
type: "text"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
children: {
|
|
21
|
+
control: {
|
|
22
|
+
type: HTMLElement || HTMLCollection
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
parameters: {}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const Sandbox = (args: any) => {
|
|
30
|
+
return <FormControl {...args} />;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
Sandbox.args = {
|
|
34
|
+
label: "Label",
|
|
35
|
+
children: <input type='text' className='form-control' placeholder='placeholder' />
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const WithPrefix = (args: any) => {
|
|
39
|
+
return <FormControl {...args} />;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
WithPrefix.args = {
|
|
43
|
+
label: "Label",
|
|
44
|
+
children: <input type='text' className='form-control' placeholder='placeholder' />,
|
|
45
|
+
prefix: <i className={iconClass(undefined, "calendar")} />
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const WithSuffix = (args: any) => {
|
|
49
|
+
return <FormControl {...args} />;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
WithSuffix.args = {
|
|
53
|
+
label: "Label",
|
|
54
|
+
children: <input type='text' className='form-control' placeholder='placeholder' />,
|
|
55
|
+
suffix: <i className={iconClass(undefined, "calendar")} />
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const WithDescription = (args: any) => {
|
|
59
|
+
return <FormControl {...args} />;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
WithDescription.args = {
|
|
63
|
+
label: "Label",
|
|
64
|
+
children: <input type='text' className='form-control' placeholder='placeholder' />
|
|
65
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import PropTypes from "prop-types";
|
|
2
2
|
import React, { ReactElement } from "react";
|
|
3
|
+
|
|
3
4
|
import { useTooltip } from "../../hooks/useTooltip";
|
|
4
5
|
import { FormOptions } from "../../interfaces";
|
|
5
6
|
import { iconClass } from "../../utils/iconClass";
|
|
@@ -31,25 +32,25 @@ export function FormEditCTAs({
|
|
|
31
32
|
}: FormEditCTAsProps): ReactElement {
|
|
32
33
|
const { i18n: t = (t: string): string => t } = options;
|
|
33
34
|
|
|
34
|
-
const copyTooltipRef = useTooltip({
|
|
35
|
+
const copyTooltipRef: any = useTooltip({
|
|
35
36
|
trigger: "hover",
|
|
36
37
|
placement: "top",
|
|
37
38
|
title: t("Copy")
|
|
38
39
|
});
|
|
39
40
|
|
|
40
|
-
const undoTooltipRef = useTooltip({
|
|
41
|
+
const undoTooltipRef: any = useTooltip({
|
|
41
42
|
trigger: "hover",
|
|
42
43
|
placement: "top",
|
|
43
44
|
title: t("Undo last change")
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
const redoTooltipRef = useTooltip({
|
|
47
|
+
const redoTooltipRef: any = useTooltip({
|
|
47
48
|
trigger: "hover",
|
|
48
49
|
placement: "top",
|
|
49
50
|
title: t("Redo last change")
|
|
50
51
|
});
|
|
51
52
|
|
|
52
|
-
const resetTooltipRef = useTooltip({
|
|
53
|
+
const resetTooltipRef: any = useTooltip({
|
|
53
54
|
trigger: "hover",
|
|
54
55
|
placement: "top",
|
|
55
56
|
title: t("Reset all changes")
|
|
@@ -61,30 +62,30 @@ export function FormEditCTAs({
|
|
|
61
62
|
<button
|
|
62
63
|
className={`btn btn-primary btn-save flex ${disabled ? "disabled" : ""}`}
|
|
63
64
|
disabled={disabled}
|
|
64
|
-
onClick={() => !disabled && onSubmit()}
|
|
65
|
+
onClick={() => !disabled && onSubmit && onSubmit()}
|
|
65
66
|
>
|
|
66
67
|
<i className={`mr-1 ${iconClass(options.iconset, "save")}`} />
|
|
67
68
|
{saveText}
|
|
68
69
|
</button>
|
|
69
70
|
|
|
70
71
|
<div>
|
|
71
|
-
<button className={`btn btn-light btn-undo ${hasUndo ? "" : "disabled"}`} onClick={() => onUndo()} ref={undoTooltipRef}>
|
|
72
|
+
<button className={`btn btn-light btn-undo ${hasUndo ? "" : "disabled"}`} onClick={() => onUndo && onUndo()} ref={undoTooltipRef}>
|
|
72
73
|
<i className={iconClass(options.iconset, "undo")} />
|
|
73
74
|
</button>
|
|
74
75
|
|
|
75
|
-
<button className={`btn btn-light btn-redo ${hasRedo ? "" : "disabled"}`} onClick={() => onRedo()} ref={redoTooltipRef}>
|
|
76
|
+
<button className={`btn btn-light btn-redo ${hasRedo ? "" : "disabled"}`} onClick={() => onRedo && onRedo()} ref={redoTooltipRef}>
|
|
76
77
|
<i className={iconClass(options.iconset, "redo")} />
|
|
77
78
|
</button>
|
|
78
79
|
</div>
|
|
79
80
|
|
|
80
81
|
<div>
|
|
81
82
|
{onCopy && (
|
|
82
|
-
<button className='btn btn-light' onClick={() => onCopy()} ref={copyTooltipRef}>
|
|
83
|
+
<button className='btn btn-light' onClick={() => onCopy()} ref={copyTooltipRef!}>
|
|
83
84
|
<i className={iconClass(options.iconset, "copy")} />
|
|
84
85
|
</button>
|
|
85
86
|
)}
|
|
86
87
|
|
|
87
|
-
<button className={`btn btn-light btn-reset`} onClick={() => onReset()} ref={resetTooltipRef}>
|
|
88
|
+
<button className={`btn btn-light btn-reset`} onClick={() => onReset && onReset()} ref={resetTooltipRef!}>
|
|
88
89
|
<i className={iconClass(options.iconset, "reset")} />
|
|
89
90
|
</button>
|
|
90
91
|
</div>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import PropTypes from "prop-types";
|
|
2
2
|
import React from "react";
|
|
3
|
+
|
|
3
4
|
import { FormOptions } from "../../interfaces/FormOptions";
|
|
4
5
|
import { FormBuilder } from "../form-builder/formBuilder.component";
|
|
5
6
|
import { FormEditCTAs } from "./formCtas.component";
|
|
@@ -37,7 +38,7 @@ export function FormEdit(props: FormEditProps) {
|
|
|
37
38
|
|
|
38
39
|
<FormBuilder
|
|
39
40
|
key={`form-builder-${form._id}`}
|
|
40
|
-
components={form.components}
|
|
41
|
+
components={form.components!}
|
|
41
42
|
display={form.display}
|
|
42
43
|
options={options}
|
|
43
44
|
builder={builder}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import camelCase from "lodash/camelCase";
|
|
2
2
|
import cloneDeep from "lodash/cloneDeep";
|
|
3
3
|
import isEqual from "lodash/isEqual";
|
|
4
|
+
|
|
4
5
|
import { FormSchema } from "../../interfaces";
|
|
5
6
|
|
|
6
7
|
export const hasChanged = (form: Partial<FormSchema>, value: Partial<FormSchema>): boolean => !isEqual(form, value);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import PropTypes from "prop-types";
|
|
2
2
|
import React, { ReactElement } from "react";
|
|
3
|
+
|
|
3
4
|
import { FormSchema } from "../../interfaces/FormSchema";
|
|
4
5
|
import { InputTags } from "../input-tags/inputTags.component";
|
|
5
6
|
import { InputText } from "../input-text/inputText.component";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { fireEvent, render } from "@testing-library/react";
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
import { FormSettings } from "./formSettings.component";
|
|
5
|
+
import { Sandbox } from "./formSettings.stories";
|
|
5
6
|
|
|
6
7
|
describe("FormSettings", () => {
|
|
7
8
|
it("should render form settings", async () => {
|
|
@@ -10,7 +11,7 @@ describe("FormSettings", () => {
|
|
|
10
11
|
// @ts-ignore
|
|
11
12
|
Sandbox.args.form.action = "https://test";
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
render(
|
|
14
15
|
<Sandbox
|
|
15
16
|
{...Sandbox.args}
|
|
16
17
|
onSubmit={onSubmit}
|
|
@@ -20,7 +21,7 @@ describe("FormSettings", () => {
|
|
|
20
21
|
/>
|
|
21
22
|
);
|
|
22
23
|
|
|
23
|
-
const btn = getByTestId("submit");
|
|
24
|
+
const btn = screen.getByTestId("submit");
|
|
24
25
|
|
|
25
26
|
await fireEvent.click(btn);
|
|
26
27
|
|
|
@@ -47,7 +48,7 @@ describe("FormSettings", () => {
|
|
|
47
48
|
});
|
|
48
49
|
});
|
|
49
50
|
it("should render form settings with i18n options", async () => {
|
|
50
|
-
|
|
51
|
+
render(
|
|
51
52
|
<FormSettings
|
|
52
53
|
{...Sandbox.args}
|
|
53
54
|
options={{
|
|
@@ -56,7 +57,7 @@ describe("FormSettings", () => {
|
|
|
56
57
|
/>
|
|
57
58
|
);
|
|
58
59
|
|
|
59
|
-
const btn = getByTestId("submit");
|
|
60
|
+
const btn = screen.getByTestId("submit");
|
|
60
61
|
|
|
61
62
|
await fireEvent.click(btn);
|
|
62
63
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useState } from "react";
|
|
2
|
-
import { FormOptions, FormSchema } from "../../interfaces";
|
|
3
|
-
import { getFormSettingsSchema } from "./formSettings.schema";
|
|
4
|
-
import { Form } from "../form/form.component";
|
|
5
|
-
import { FormSettingsSchema, formSettingsToSubmission, submissionToFormSettings } from "./formSettings.utils";
|
|
6
1
|
import isEqual from "lodash/isEqual";
|
|
7
2
|
import noop from "lodash/noop";
|
|
3
|
+
import React, { useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
import { FormOptions, FormSchema } from "../../interfaces";
|
|
6
|
+
import { Form } from "../form/form.component";
|
|
8
7
|
import { ChangedSubmission } from "../form/useForm.hook";
|
|
8
|
+
import { getFormSettingsSchema } from "./formSettings.schema";
|
|
9
|
+
import { FormSettingsSchema, formSettingsToSubmission, submissionToFormSettings } from "./formSettings.utils";
|
|
9
10
|
|
|
10
11
|
export interface FormSettingsProps {
|
|
11
12
|
form: Partial<FormSchema>;
|
|
@@ -18,15 +19,12 @@ function useFormSettings({ form: formDefinition, onSubmit = noop, options }: For
|
|
|
18
19
|
const [isValid, setIsValid] = useState(true);
|
|
19
20
|
const [submission, setSubmission] = useState(() => formSettingsToSubmission(formDefinition));
|
|
20
21
|
|
|
21
|
-
const onChange =
|
|
22
|
-
(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
[submission]
|
|
29
|
-
);
|
|
22
|
+
const onChange = ({ data, isValid }: ChangedSubmission<FormSettingsSchema>) => {
|
|
23
|
+
if (isValid) {
|
|
24
|
+
setSubmission({ data });
|
|
25
|
+
}
|
|
26
|
+
setIsValid(isValid);
|
|
27
|
+
};
|
|
30
28
|
|
|
31
29
|
useEffect(() => {
|
|
32
30
|
const input = formSettingsToSubmission(formDefinition);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import cloneDeep from "lodash/cloneDeep";
|
|
2
|
+
|
|
2
3
|
import { FormSchema, Submission } from "../../interfaces";
|
|
3
4
|
|
|
4
5
|
export type FormSettingsSchema = {
|
|
@@ -10,9 +11,9 @@ export type FormSettingsSchema = {
|
|
|
10
11
|
export function formSettingsToSubmission(form: Partial<FormSchema>): Submission<FormSettingsSchema> {
|
|
11
12
|
return {
|
|
12
13
|
data: {
|
|
13
|
-
action: form.action
|
|
14
|
-
tags: form.tags
|
|
15
|
-
properties: form.properties
|
|
14
|
+
action: form.action!,
|
|
15
|
+
tags: form.tags!,
|
|
16
|
+
properties: form.properties!
|
|
16
17
|
}
|
|
17
18
|
};
|
|
18
19
|
}
|
|
@@ -2,6 +2,7 @@ import classnames from "classnames";
|
|
|
2
2
|
import moment from "moment";
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { CellProps } from "react-table";
|
|
5
|
+
|
|
5
6
|
import { FormSchema } from "../../../interfaces";
|
|
6
7
|
import { iconClass } from "../../../utils/iconClass";
|
|
7
8
|
import { stopPropagationWrapper } from "../../../utils/stopPropagationWrapper";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
|
|
2
3
|
import { FormSchema } from "../../interfaces";
|
|
3
4
|
import { DefaultColumnFilter } from "../table/filters/defaultColumnFilter.component";
|
|
4
5
|
import { SelectColumnFilter } from "../table/filters/selectColumnFilter.component";
|
|
@@ -13,31 +14,28 @@ export type FormsTableProps = Omit<TableProps<FormSchema>, "columns"> & {
|
|
|
13
14
|
export function FormsTable({ Cell, ...props }: FormsTableProps) {
|
|
14
15
|
const { i18n = (f: string) => f, tags } = props;
|
|
15
16
|
const FormCell = Cell || (DefaultFormCell as any);
|
|
16
|
-
const columns =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
],
|
|
39
|
-
[Cell]
|
|
40
|
-
);
|
|
17
|
+
const columns = [
|
|
18
|
+
{
|
|
19
|
+
Header: i18n("Title"),
|
|
20
|
+
accessor: "title",
|
|
21
|
+
id: "title",
|
|
22
|
+
Cell: (props: any) => <FormCell {...props} icon={props.icon} i18n={i18n} />,
|
|
23
|
+
Filter: DefaultColumnFilter,
|
|
24
|
+
colspan: 2
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
Header: i18n("Tags"),
|
|
28
|
+
accessor: "tags",
|
|
29
|
+
id: "tags",
|
|
30
|
+
hidden: true,
|
|
31
|
+
Filter: (props: any) =>
|
|
32
|
+
tags && tags.length ? (
|
|
33
|
+
<SelectColumnFilter {...props} column={{ ...props.columns, choices: tags }} />
|
|
34
|
+
) : (
|
|
35
|
+
<DefaultColumnFilter {...props} />
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
];
|
|
41
39
|
|
|
42
40
|
return <Table {...props} columns={columns} />;
|
|
43
41
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -6,13 +6,14 @@ export * from "./form-access/formAccess.component";
|
|
|
6
6
|
export * from "./form-action/formAction.component";
|
|
7
7
|
export * from "./form-builder/formBuilder.component";
|
|
8
8
|
export * from "./form-control/formControl.component";
|
|
9
|
-
export * from "./form-edit/formEdit.component";
|
|
10
9
|
export * from "./form-edit/formCtas.component";
|
|
10
|
+
export * from "./form-edit/formEdit.component";
|
|
11
11
|
export * from "./form-edit/formParameters.component";
|
|
12
12
|
export * from "./form-settings/formSettings.component";
|
|
13
13
|
export * from "./forms-table/formsTable.component";
|
|
14
14
|
export * from "./input-tags/inputTags.component";
|
|
15
15
|
export * from "./input-text/inputText.component";
|
|
16
|
+
export * from "./loader/loader.component";
|
|
16
17
|
export * from "./modal/modal.component";
|
|
17
18
|
export * from "./modal/removeModal.component";
|
|
18
19
|
export * from "./pagination/pagination.component";
|
|
@@ -21,4 +22,3 @@ export * from "./select/select.component";
|
|
|
21
22
|
export * from "./submissions-table/submissionsTable.component";
|
|
22
23
|
export * from "./table";
|
|
23
24
|
export * from "./tabs/tabs.component";
|
|
24
|
-
export * from "./loader/loader.component";
|
|
@@ -14,7 +14,7 @@ export interface InputTagsProps<T = any> extends Omit<FormControlProps, "descrip
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function InputTags({ name, value = [], label, onChange, required, description, prefix, suffix, ...props }: InputTagsProps) {
|
|
17
|
-
const ref = useRef();
|
|
17
|
+
const ref: any = useRef();
|
|
18
18
|
|
|
19
19
|
useEffect(() => {
|
|
20
20
|
const instance = new Choices(ref.current, {
|
|
@@ -26,14 +26,15 @@ export function InputTags({ name, value = [], label, onChange, required, descrip
|
|
|
26
26
|
instance.setValue([].concat(value, []));
|
|
27
27
|
|
|
28
28
|
instance.passedElement.element.addEventListener("addItem", (event: any) => {
|
|
29
|
-
onChange(name, uniq(value.concat(event.detail.value)));
|
|
29
|
+
onChange && onChange(name, uniq(value.concat(event.detail.value)));
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
instance.passedElement.element.addEventListener("removeItem", (event: any) => {
|
|
33
|
-
onChange
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
onChange &&
|
|
34
|
+
onChange(
|
|
35
|
+
name,
|
|
36
|
+
value.filter((v: string) => v !== event.detail.value)
|
|
37
|
+
);
|
|
37
38
|
});
|
|
38
39
|
|
|
39
40
|
return () => {
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
1
2
|
import React from "react";
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
import { Sandbox } from "./inputText.stories";
|
|
4
5
|
|
|
5
6
|
describe("input-text", () => {
|
|
6
7
|
it("should display the input-text component", () => {
|
|
7
|
-
|
|
8
|
-
const input = getByTestId("input_test") as HTMLInputElement;
|
|
8
|
+
render(<Sandbox {...Sandbox.args} name={"test"} />);
|
|
9
|
+
const input = screen.getByTestId("input_test") as HTMLInputElement;
|
|
9
10
|
|
|
10
11
|
expect(input).toBeInTheDocument();
|
|
11
12
|
});
|
|
12
13
|
|
|
13
14
|
it("should display the input-text component with a different size", () => {
|
|
14
|
-
|
|
15
|
-
const input = getByTestId("input_test") as HTMLInputElement;
|
|
15
|
+
render(<Sandbox {...Sandbox.args} name={"test"} size='small' />);
|
|
16
|
+
const input = screen.getByTestId("input_test") as HTMLInputElement;
|
|
16
17
|
|
|
17
18
|
expect(input).toBeInTheDocument();
|
|
18
19
|
expect(input).toHaveClass("form-control-small");
|
|
@@ -21,18 +22,18 @@ describe("input-text", () => {
|
|
|
21
22
|
it("should display the input-text with placeholder", () => {
|
|
22
23
|
const placeholderTest = "placeholder test";
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
const input = getByTestId("input_test") as HTMLInputElement;
|
|
25
|
+
render(<Sandbox {...Sandbox.args} name={"test"} placeholder={placeholderTest} />);
|
|
26
|
+
const input = screen.getByTestId("input_test") as HTMLInputElement;
|
|
26
27
|
|
|
27
28
|
expect(input).toBeInTheDocument();
|
|
28
|
-
expect(input).
|
|
29
|
+
expect(input).toHaveAttribute("placeholder", placeholderTest);
|
|
29
30
|
});
|
|
30
31
|
|
|
31
32
|
it("should change the value of the input-text", () => {
|
|
32
33
|
const placeholderTest = "placeholder test";
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
const input = getByTestId("input_test") as HTMLInputElement;
|
|
35
|
+
render(<Sandbox {...Sandbox.args} name={"test"} placeholder={placeholderTest} />);
|
|
36
|
+
const input = screen.getByTestId("input_test") as HTMLInputElement;
|
|
36
37
|
|
|
37
38
|
expect(input).toBeInTheDocument();
|
|
38
39
|
fireEvent.change(input, { target: { value: "newValue" } });
|
|
@@ -43,8 +44,8 @@ describe("input-text", () => {
|
|
|
43
44
|
it("should NOT change the value of the input-text if the value is NOT of type number", () => {
|
|
44
45
|
const placeholderTest = "placeholder test";
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
const input = getByTestId("input_test") as HTMLInputElement;
|
|
47
|
+
render(<Sandbox {...Sandbox.args} type='number' name={"test"} placeholder={placeholderTest} />);
|
|
48
|
+
const input = screen.getByTestId("input_test") as HTMLInputElement;
|
|
48
49
|
|
|
49
50
|
expect(input).toBeInTheDocument();
|
|
50
51
|
fireEvent.change(input, { target: { value: "newValue" } });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import classnames from "classnames";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import React, { useEffect, useMemo, useState } from "react";
|
|
4
|
+
|
|
4
5
|
import { callLast } from "../../utils/callLast";
|
|
5
6
|
import { getEventValue } from "../../utils/getEventValue";
|
|
6
7
|
import { FormControl, FormControlProps } from "../form-control/formControl.component";
|
|
@@ -35,7 +36,7 @@ export function InputText<T = any>({
|
|
|
35
36
|
}: InputTextProps<T>) {
|
|
36
37
|
const [localValue, setValue] = useState(value);
|
|
37
38
|
|
|
38
|
-
const change = useMemo(() => callLast(onChange, 300), [onChange]);
|
|
39
|
+
const change = useMemo(() => onChange && callLast(onChange, 300), [onChange]);
|
|
39
40
|
|
|
40
41
|
useEffect(() => {
|
|
41
42
|
setValue(value);
|
|
@@ -58,13 +59,13 @@ export function InputText<T = any>({
|
|
|
58
59
|
className={classnames("form-control", size && `form-control-${size}`)}
|
|
59
60
|
id={name}
|
|
60
61
|
required={required}
|
|
61
|
-
value={(localValue ||
|
|
62
|
+
value={(localValue || "") as any}
|
|
62
63
|
placeholder={placeholder}
|
|
63
64
|
onChange={(event) => {
|
|
64
65
|
const value = getEventValue(event);
|
|
65
66
|
setValue(value);
|
|
66
67
|
|
|
67
|
-
return change(name, value);
|
|
68
|
+
return change && change(name, value);
|
|
68
69
|
}}
|
|
69
70
|
/>
|
|
70
71
|
</FormControl>
|