@tsed/react-formio 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +2 -1
- package/craco.config.js +11 -1
- package/dist/components/alert/alert.component.spec.d.ts +1 -0
- package/dist/components/alert/alert.stories.d.ts +15 -0
- package/dist/components/card/card.component.d.ts +2 -1
- package/dist/components/form-action/formAction.stories.d.ts +90 -414
- package/dist/components/input-text/inputText.component.d.ts +1 -1
- package/dist/components/input-text/inputText.component.spec.d.ts +1 -0
- package/dist/components/loader/loader.component.d.ts +3 -3
- package/dist/components/loader/loader.stories.d.ts +15 -0
- package/dist/components/pagination/pagination.component.spec.d.ts +1 -0
- package/dist/components/pagination/pagination.stories.d.ts +0 -27
- package/dist/components/select/select.component.spec.d.ts +1 -0
- package/dist/components/tabs/tabs.component.spec.d.ts +1 -0
- package/dist/index.js +64 -32
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +62 -33
- package/dist/index.modern.js.map +1 -1
- package/jest.config.js +1 -1
- package/package.json +5 -9
- package/readme.md +74 -79
- package/src/components/__fixtures__/form-schema.json +10 -42
- package/src/components/__fixtures__/form.fixture.json +1 -1
- package/src/components/actions-table/actionsTable.component.spec.tsx +4 -13
- package/src/components/actions-table/actionsTable.component.tsx +3 -11
- package/src/components/alert/alert.component.spec.tsx +97 -0
- package/src/components/alert/alert.component.tsx +2 -8
- package/src/components/alert/alert.stories.tsx +17 -0
- package/src/components/card/card.component.tsx +2 -5
- package/src/components/form/form.component.tsx +1 -7
- package/src/components/form/useForm.hook.ts +4 -13
- package/src/components/form-access/formAccess.component.tsx +19 -82
- package/src/components/form-access/formAccess.schema.ts +7 -23
- package/src/components/form-access/formAccess.stories.tsx +2 -9
- package/src/components/form-access/formAccess.utils.spec.ts +4 -22
- package/src/components/form-access/formAccess.utils.ts +7 -29
- package/src/components/form-action/formAction.component.tsx +3 -19
- package/src/components/form-action/formAction.stories.tsx +251 -672
- package/src/components/form-builder/formBuilder.component.tsx +4 -13
- package/src/components/form-builder/formBuilder.stories.tsx +12 -24
- package/src/components/form-control/formControl.component.tsx +2 -8
- package/src/components/form-edit/formCtas.component.tsx +5 -23
- package/src/components/form-edit/formEdit.component.tsx +2 -20
- package/src/components/form-edit/formEdit.reducer.ts +2 -8
- package/src/components/form-edit/formEdit.stories.tsx +3 -15
- package/src/components/form-edit/formParameters.component.tsx +3 -20
- package/src/components/form-edit/useFormEdit.hook.ts +2 -9
- package/src/components/form-settings/formSettings.component.spec.tsx +2 -9
- package/src/components/form-settings/formSettings.component.tsx +6 -34
- package/src/components/form-settings/formSettings.stories.tsx +1 -6
- package/src/components/form-settings/formSettings.utils.spec.ts +1 -4
- package/src/components/form-settings/formSettings.utils.ts +2 -7
- package/src/components/forms-table/components/formCell.component.tsx +2 -6
- package/src/components/forms-table/formsTable.component.tsx +2 -7
- package/src/components/input-tags/inputTags.component.tsx +10 -34
- package/src/components/input-tags/inputTags.stories.tsx +4 -14
- package/src/components/input-text/inputText.component.spec.tsx +56 -0
- package/src/components/input-text/inputText.component.tsx +4 -5
- package/src/components/input-text/inputText.stories.tsx +6 -26
- package/src/components/loader/loader.component.spec.tsx +7 -6
- package/src/components/loader/loader.component.tsx +4 -13
- package/src/components/loader/loader.stories.tsx +17 -0
- package/src/components/modal/modal.component.spec.tsx +8 -14
- package/src/components/modal/modal.component.tsx +6 -27
- package/src/components/modal/modal.stories.tsx +1 -5
- package/src/components/modal/removeModal.component.tsx +4 -22
- package/src/components/pagination/pagination.component.spec.tsx +111 -0
- package/src/components/pagination/pagination.component.tsx +10 -42
- package/src/components/pagination/pagination.stories.tsx +9 -29
- package/src/components/react-component/reactComponent.component.tsx +3 -11
- package/src/components/select/select.component.spec.tsx +86 -0
- package/src/components/select/select.component.tsx +11 -15
- package/src/components/select/select.stories.tsx +6 -26
- package/src/components/submissions-table/submissionsTable.component.tsx +1 -3
- package/src/components/submissions-table/submissionsTable.stories.tsx +1 -1
- package/src/components/table/components/defaultArrowSort.component.tsx +1 -10
- package/src/components/table/components/defaultCell.component.tsx +1 -4
- package/src/components/table/components/defaultCellHeader.component.tsx +4 -14
- package/src/components/table/components/defaultCellOperations.component.tsx +14 -25
- package/src/components/table/components/defaultOperationButton.component.tsx +2 -10
- package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +1 -1
- package/src/components/table/filters/selectColumnFilter.component.spec.tsx +2 -10
- package/src/components/table/filters/selectColumnFilter.component.tsx +2 -6
- package/src/components/table/table.component.tsx +13 -53
- package/src/components/table/table.stories.tsx +1 -1
- package/src/components/table/utils/getPageNumbers.ts +3 -11
- package/src/components/table/utils/mapFormToColumns.tsx +14 -22
- package/src/components/table/utils/useOperations.hook.tsx +2 -12
- package/src/components/tabs/tabs.component.spec.tsx +86 -0
- package/src/components/tabs/tabs.component.stories.tsx +2 -9
- package/src/components/tabs/tabs.component.tsx +9 -43
- package/src/interfaces/Operation.ts +1 -4
- package/src/react-table.d.ts +9 -28
- package/src/stores/action/action.actions.ts +31 -33
- package/src/stores/action/action.reducers.spec.ts +1 -8
- package/src/stores/action/action.reducers.ts +1 -8
- package/src/stores/action/action.selectors.ts +1 -2
- package/src/stores/action-info/action-info.actions.spec.ts +1 -5
- package/src/stores/action-info/action-info.actions.ts +16 -19
- package/src/stores/action-info/action-info.reducers.spec.ts +1 -6
- package/src/stores/action-info/action-info.reducers.ts +1 -6
- package/src/stores/action-info/action-info.selectors.ts +1 -4
- package/src/stores/actions/actions.actions.spec.ts +1 -6
- package/src/stores/actions/actions.actions.ts +16 -19
- package/src/stores/actions/actions.reducers.spec.ts +1 -6
- package/src/stores/actions/actions.reducers.ts +1 -6
- package/src/stores/actions/actions.selectors.ts +2 -4
- package/src/stores/auth/auth.reducers.ts +1 -4
- package/src/stores/auth/auth.selectors.spec.ts +1 -5
- package/src/stores/auth/auth.selectors.ts +3 -6
- package/src/stores/auth/auth.utils.tsx +2 -8
- package/src/stores/auth/getAccess.action.spec.ts +11 -54
- package/src/stores/auth/getAccess.action.ts +1 -6
- package/src/stores/auth/initAuth.action.ts +15 -17
- package/src/stores/form/form.actions.spec.ts +8 -39
- package/src/stores/form/form.actions.ts +55 -64
- package/src/stores/form/form.reducers.spec.ts +1 -7
- package/src/stores/form/form.reducers.ts +1 -8
- package/src/stores/form/form.selectors.ts +1 -2
- package/src/stores/forms/forms.actions.spec.ts +5 -18
- package/src/stores/forms/forms.actions.ts +17 -21
- package/src/stores/forms/forms.reducers.spec.ts +1 -6
- package/src/stores/forms/forms.reducers.ts +2 -13
- package/src/stores/forms/forms.selectors.ts +2 -4
- package/src/stores/index.spec.ts +6 -9
- package/src/stores/root/root.selectors.spec.ts +1 -6
- package/src/stores/root/root.selectors.ts +6 -24
- package/src/stores/submission/submission.actions.spec.ts +11 -33
- package/src/stores/submission/submission.actions.ts +57 -66
- package/src/stores/submission/submission.reducers.spec.ts +17 -27
- package/src/stores/submission/submission.reducers.ts +1 -4
- package/src/stores/submission/submission.selectors.ts +1 -4
- package/src/stores/submissions/submissions.actions.spec.ts +5 -18
- package/src/stores/submissions/submissions.actions.ts +17 -26
- package/src/stores/submissions/submissions.reducers.spec.ts +3 -12
- package/src/stores/submissions/submissions.reducers.ts +3 -17
- package/src/stores/submissions/submissions.selectors.spec.ts +1 -4
- package/src/stores/submissions/submissions.selectors.ts +2 -4
- package/src/utils/getEventValue.ts +1 -4
- package/src/utils/iconClass.ts +2 -10
- package/src/utils/mapPagination.ts +1 -6
- package/src/utils/mapRequestParams.ts +2 -12
- package/src/utils/url.test.ts +4 -12
- package/src/utils/url.ts +2 -7
- package/tsconfig.json +4 -12
- package/tsconfig.test.json +1 -1
- package/.eslintrc +0 -47
- package/.prettierrc +0 -10
|
@@ -2,15 +2,12 @@ import classnames from "classnames";
|
|
|
2
2
|
import React, { PropsWithChildren } from "react";
|
|
3
3
|
|
|
4
4
|
export interface CardProps {
|
|
5
|
+
children: React.ReactNode;
|
|
5
6
|
label: string;
|
|
6
7
|
className?: string;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export function Card({
|
|
10
|
-
children,
|
|
11
|
-
label,
|
|
12
|
-
className
|
|
13
|
-
}: PropsWithChildren<CardProps>) {
|
|
10
|
+
export function Card({ children, label, className }: PropsWithChildren<CardProps>) {
|
|
14
11
|
return (
|
|
15
12
|
<div className={classnames("card", className)}>
|
|
16
13
|
<div className={"card-header "}>
|
|
@@ -17,13 +17,7 @@ export interface FormProps<Data = any> extends UseFormHookProps<Data> {
|
|
|
17
17
|
export function Form(props: Partial<FormProps>) {
|
|
18
18
|
const { element } = useForm(props);
|
|
19
19
|
|
|
20
|
-
return (
|
|
21
|
-
<div
|
|
22
|
-
data-testid={"formioContainer" + (props.name || "")}
|
|
23
|
-
ref={element}
|
|
24
|
-
className={props.className}
|
|
25
|
-
/>
|
|
26
|
-
);
|
|
20
|
+
return <div data-testid={"formioContainer" + (props.name || "")} ref={element} className={props.className} />;
|
|
27
21
|
}
|
|
28
22
|
|
|
29
23
|
Form.propTypes = {
|
|
@@ -38,12 +38,7 @@ export interface UseFormHookProps<Data = any> extends Record<string, any> {
|
|
|
38
38
|
onNextPage?: (obj: FormPageChangeProps<Data>) => void;
|
|
39
39
|
onCancel?: Function;
|
|
40
40
|
onChange?: (submission: ChangedSubmission) => void;
|
|
41
|
-
onCustomEvent?: (obj: {
|
|
42
|
-
type: string;
|
|
43
|
-
event: string;
|
|
44
|
-
component: ExtendedComponentSchema;
|
|
45
|
-
data: any;
|
|
46
|
-
}) => void;
|
|
41
|
+
onCustomEvent?: (obj: { type: string; event: string; component: ExtendedComponentSchema; data: any }) => void;
|
|
47
42
|
onComponentChange?: (component: ExtendedComponentSchema) => void;
|
|
48
43
|
onSubmit?: (submission: Submission<Data>) => void;
|
|
49
44
|
onSubmitDone?: (submission: Submission<Data>) => void;
|
|
@@ -68,8 +63,7 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
68
63
|
|
|
69
64
|
const createWebForm = (srcOrForm: any, options: any) => {
|
|
70
65
|
options = Object.assign({}, options);
|
|
71
|
-
srcOrForm =
|
|
72
|
-
typeof srcOrForm === "string" ? srcOrForm : cloneDeep(srcOrForm);
|
|
66
|
+
srcOrForm = typeof srcOrForm === "string" ? srcOrForm : cloneDeep(srcOrForm);
|
|
73
67
|
|
|
74
68
|
if (!instance.current) {
|
|
75
69
|
isLoaded.current = false;
|
|
@@ -81,9 +75,7 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
81
75
|
}
|
|
82
76
|
|
|
83
77
|
if (event.startsWith("formio.")) {
|
|
84
|
-
const funcName = `on${event.charAt(7).toUpperCase()}${event.slice(
|
|
85
|
-
8
|
|
86
|
-
)}`;
|
|
78
|
+
const funcName = `on${event.charAt(7).toUpperCase()}${event.slice(8)}`;
|
|
87
79
|
|
|
88
80
|
if (funcName === "onChange") {
|
|
89
81
|
if (isEqual(get(submission, "data"), args[0].data)) {
|
|
@@ -165,8 +157,7 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
165
157
|
}, [props.onSubmit, events]);
|
|
166
158
|
|
|
167
159
|
useEffect(() => {
|
|
168
|
-
props.onSubmitDone &&
|
|
169
|
-
events.current.set("onSubmitDone", props.onSubmitDone);
|
|
160
|
+
props.onSubmitDone && events.current.set("onSubmitDone", props.onSubmitDone);
|
|
170
161
|
}, [props.onSubmitDone, events]);
|
|
171
162
|
|
|
172
163
|
return {
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import PropTypes from "prop-types";
|
|
2
|
-
import React, {
|
|
3
|
-
PropsWithChildren,
|
|
4
|
-
ReactElement,
|
|
5
|
-
useCallback,
|
|
6
|
-
useEffect,
|
|
7
|
-
useMemo,
|
|
8
|
-
useState
|
|
9
|
-
} from "react";
|
|
2
|
+
import React, { PropsWithChildren, ReactElement, useCallback, useEffect, useMemo, useState } from "react";
|
|
10
3
|
import { FormOptions, FormSchema, Submission } from "../../interfaces";
|
|
11
4
|
import { Card } from "../card/card.component";
|
|
12
5
|
import { Form } from "../form/form.component";
|
|
@@ -29,18 +22,11 @@ export interface FormAccessProps {
|
|
|
29
22
|
options?: FormOptions;
|
|
30
23
|
}
|
|
31
24
|
|
|
32
|
-
function useFormAccess({
|
|
33
|
-
form: formDefinition,
|
|
34
|
-
roles,
|
|
35
|
-
onSubmit,
|
|
36
|
-
options
|
|
37
|
-
}: FormAccessProps) {
|
|
25
|
+
function useFormAccess({ form: formDefinition, roles, onSubmit, options }: FormAccessProps) {
|
|
38
26
|
// eslint-disable-next-line no-undef
|
|
39
27
|
const form = useMemo(() => getFormAccess(roles), [roles]);
|
|
40
28
|
|
|
41
|
-
const [submissions, setSubmissions] = useState(() =>
|
|
42
|
-
dataAccessToSubmissions(formDefinition, form)
|
|
43
|
-
);
|
|
29
|
+
const [submissions, setSubmissions] = useState(() => dataAccessToSubmissions(formDefinition, form));
|
|
44
30
|
|
|
45
31
|
const onChange = useCallback(
|
|
46
32
|
(type: string, submission: Submission<AccessRoles>) => {
|
|
@@ -52,10 +38,7 @@ function useFormAccess({
|
|
|
52
38
|
useEffect(() => {
|
|
53
39
|
const input = dataAccessToSubmissions(formDefinition, form);
|
|
54
40
|
if (formDefinition?._id) {
|
|
55
|
-
if (
|
|
56
|
-
shouldUpdate("access", submissions.access, input) ||
|
|
57
|
-
shouldUpdate("submissionAccess", submissions.submissionAccess, input)
|
|
58
|
-
) {
|
|
41
|
+
if (shouldUpdate("access", submissions.access, input) || shouldUpdate("submissionAccess", submissions.submissionAccess, input)) {
|
|
59
42
|
setSubmissions(input);
|
|
60
43
|
}
|
|
61
44
|
}
|
|
@@ -80,21 +63,10 @@ interface NamedFormAccessProps {
|
|
|
80
63
|
options: any;
|
|
81
64
|
onSubmit: any;
|
|
82
65
|
|
|
83
|
-
onChange(
|
|
84
|
-
name: "access" | "submissionAccess",
|
|
85
|
-
submission: Submission<AccessRoles>
|
|
86
|
-
): void;
|
|
66
|
+
onChange(name: "access" | "submissionAccess", submission: Submission<AccessRoles>): void;
|
|
87
67
|
}
|
|
88
68
|
|
|
89
|
-
function NamedFormAccess({
|
|
90
|
-
name,
|
|
91
|
-
form,
|
|
92
|
-
submissions,
|
|
93
|
-
options,
|
|
94
|
-
onChange,
|
|
95
|
-
onSubmit,
|
|
96
|
-
children
|
|
97
|
-
}: PropsWithChildren<NamedFormAccessProps>) {
|
|
69
|
+
function NamedFormAccess({ name, form, submissions, options, onChange, onSubmit, children }: PropsWithChildren<NamedFormAccessProps>) {
|
|
98
70
|
const [isValid, setIsValid] = useState(true);
|
|
99
71
|
|
|
100
72
|
return (
|
|
@@ -110,35 +82,21 @@ function NamedFormAccess({
|
|
|
110
82
|
options={options}
|
|
111
83
|
/>
|
|
112
84
|
|
|
113
|
-
<button
|
|
114
|
-
disabled={!isValid}
|
|
115
|
-
className={"mt-5 btn btn-primary"}
|
|
116
|
-
onClick={onSubmit}
|
|
117
|
-
>
|
|
85
|
+
<button disabled={!isValid} className={"mt-5 btn btn-primary"} onClick={onSubmit}>
|
|
118
86
|
Save access
|
|
119
87
|
</button>
|
|
120
88
|
|
|
121
89
|
{children}
|
|
122
90
|
|
|
123
91
|
<div className={"alert alert-warning mt-5"}>
|
|
124
|
-
Elevated permissions allow users to access and modify other user's
|
|
125
|
-
entities. Assign with caution.
|
|
92
|
+
Elevated permissions allow users to access and modify other user's entities. Assign with caution.
|
|
126
93
|
</div>
|
|
127
94
|
</>
|
|
128
95
|
);
|
|
129
96
|
}
|
|
130
97
|
|
|
131
|
-
export function FormAccess(
|
|
132
|
-
props
|
|
133
|
-
): ReactElement {
|
|
134
|
-
const {
|
|
135
|
-
type,
|
|
136
|
-
form,
|
|
137
|
-
submissions,
|
|
138
|
-
options,
|
|
139
|
-
onChange,
|
|
140
|
-
onSubmit
|
|
141
|
-
} = useFormAccess(props);
|
|
98
|
+
export function FormAccess(props: PropsWithChildren<FormAccessProps>): ReactElement {
|
|
99
|
+
const { type, form, submissions, options, onChange, onSubmit } = useFormAccess(props);
|
|
142
100
|
|
|
143
101
|
return (
|
|
144
102
|
<div>
|
|
@@ -158,22 +116,16 @@ export function FormAccess(
|
|
|
158
116
|
</Card>
|
|
159
117
|
<div className={"w-1/4 pl-4"}>
|
|
160
118
|
<Card label={"About Submission Data Permissions"}>
|
|
161
|
-
<p>
|
|
162
|
-
Submission Data Permissions allow you to control who can create,
|
|
163
|
-
view, and modify form submission data.
|
|
164
|
-
</p>
|
|
119
|
+
<p>Submission Data Permissions allow you to control who can create, view, and modify form submission data.</p>
|
|
165
120
|
|
|
166
121
|
<ul className={"mt-5 pl-7 list-disc"}>
|
|
167
122
|
<li className={"pb-2"}>
|
|
168
|
-
<strong>Own Permissions</strong> - These permissions apply if
|
|
169
|
-
|
|
170
|
-
listed as the owner of the submission in submission.owner. This
|
|
171
|
-
allows users to create and edit their own submission data
|
|
123
|
+
<strong>Own Permissions</strong> - These permissions apply if the user is the original creator of the submission data and is
|
|
124
|
+
listed as the owner of the submission in submission.owner. This allows users to create and edit their own submission data
|
|
172
125
|
without seeing other user's data.
|
|
173
126
|
</li>
|
|
174
127
|
<li>
|
|
175
|
-
<strong>All Permissions</strong> - These permissions apply to
|
|
176
|
-
all submission data regardless of who owns it.
|
|
128
|
+
<strong>All Permissions</strong> - These permissions apply to all submission data regardless of who owns it.
|
|
177
129
|
</li>
|
|
178
130
|
</ul>
|
|
179
131
|
</Card>
|
|
@@ -181,35 +133,20 @@ export function FormAccess(
|
|
|
181
133
|
</div>
|
|
182
134
|
<div className={"flex mb-5"}>
|
|
183
135
|
<Card label={`Manage ${type} definition access`} className={"flex-1"}>
|
|
184
|
-
<NamedFormAccess
|
|
185
|
-
name={"access"}
|
|
186
|
-
form={form}
|
|
187
|
-
submissions={submissions}
|
|
188
|
-
onChange={onChange}
|
|
189
|
-
onSubmit={onSubmit}
|
|
190
|
-
options={options}
|
|
191
|
-
>
|
|
136
|
+
<NamedFormAccess name={"access"} form={form} submissions={submissions} onChange={onChange} onSubmit={onSubmit} options={options}>
|
|
192
137
|
{props.children}
|
|
193
138
|
</NamedFormAccess>
|
|
194
139
|
</Card>
|
|
195
140
|
|
|
196
141
|
<div className={"w-1/4 pl-4"}>
|
|
197
142
|
<Card label={"About Form Definition Access"}>
|
|
198
|
-
<p>
|
|
199
|
-
These permissions allow you to give access to a single form's JSON
|
|
200
|
-
definition so they can render the form.
|
|
201
|
-
</p>
|
|
143
|
+
<p>These permissions allow you to give access to a single form's JSON definition so they can render the form.</p>
|
|
202
144
|
|
|
203
|
-
<p>
|
|
204
|
-
Typically you will want to allow all of your roles to be able to
|
|
205
|
-
Read the form definition.
|
|
206
|
-
</p>
|
|
145
|
+
<p>Typically you will want to allow all of your roles to be able to Read the form definition.</p>
|
|
207
146
|
|
|
208
147
|
<p>
|
|
209
|
-
Each form also has an owner at <strong>form.owner</strong> which
|
|
210
|
-
|
|
211
|
-
allowed to create their own forms. In those cases it is helpful to
|
|
212
|
-
have Owner based permissions as well.
|
|
148
|
+
Each form also has an owner at <strong>form.owner</strong> which is the user who created the form. In some applications users
|
|
149
|
+
are allowed to create their own forms. In those cases it is helpful to have Owner based permissions as well.
|
|
213
150
|
</p>
|
|
214
151
|
</Card>
|
|
215
152
|
</div>
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { ExtendedComponentSchema } from "formiojs";
|
|
2
2
|
import { FormSchema } from "../../interfaces/FormSchema";
|
|
3
3
|
|
|
4
|
-
export function getRoleComponent({
|
|
5
|
-
label,
|
|
6
|
-
key,
|
|
7
|
-
description,
|
|
8
|
-
choices,
|
|
9
|
-
data
|
|
10
|
-
}: any): ExtendedComponentSchema {
|
|
4
|
+
export function getRoleComponent({ label, key, description, choices, data }: any): ExtendedComponentSchema {
|
|
11
5
|
return {
|
|
12
6
|
label,
|
|
13
7
|
key,
|
|
@@ -36,18 +30,12 @@ export function getRoleComponent({
|
|
|
36
30
|
}
|
|
37
31
|
|
|
38
32
|
function toDescription(description: string, hr = true): string {
|
|
39
|
-
return (
|
|
40
|
-
'<span class="text-sm">' +
|
|
41
|
-
description +
|
|
42
|
-
"</span> " +
|
|
43
|
-
(hr ? '<hr class="mt-6 mb-5 border-gray-200 mx-20"/>' : "")
|
|
44
|
-
);
|
|
33
|
+
return '<span class="text-sm">' + description + "</span> " + (hr ? '<hr class="mt-6 mb-5 border-gray-200 mx-20"/>' : "");
|
|
45
34
|
}
|
|
46
35
|
|
|
47
36
|
export function getSubmissionPermissionForm({ choices }: any): FormSchema {
|
|
48
37
|
return {
|
|
49
|
-
description:
|
|
50
|
-
"<strong>Elevated permissions allow users to access and modify other user's entities. Assign with caution.</strong>",
|
|
38
|
+
description: "<strong>Elevated permissions allow users to access and modify other user's entities. Assign with caution.</strong>",
|
|
51
39
|
components: [
|
|
52
40
|
getRoleComponent({
|
|
53
41
|
key: "create_own",
|
|
@@ -120,13 +108,11 @@ export function getSubmissionPermissionForm({ choices }: any): FormSchema {
|
|
|
120
108
|
|
|
121
109
|
export function getAccessPermissionForm({ choices }: any): FormSchema {
|
|
122
110
|
return {
|
|
123
|
-
description:
|
|
124
|
-
"<strong>Elevated permissions allow users to access and modify other user's entities. Assign with caution.</strong>",
|
|
111
|
+
description: "<strong>Elevated permissions allow users to access and modify other user's entities. Assign with caution.</strong>",
|
|
125
112
|
components: [
|
|
126
113
|
getRoleComponent({
|
|
127
114
|
key: "read_own",
|
|
128
|
-
label:
|
|
129
|
-
'<h4 class="text-gray-800">Read Form Definition (Restricted to owner)</h4>',
|
|
115
|
+
label: '<h4 class="text-gray-800">Read Form Definition (Restricted to owner)</h4>',
|
|
130
116
|
description: toDescription(
|
|
131
117
|
"The Read Own permission will allow a user, with one of the given Roles, to read a form. A user can only read a form if they are defined as its owner."
|
|
132
118
|
),
|
|
@@ -142,8 +128,7 @@ export function getAccessPermissionForm({ choices }: any): FormSchema {
|
|
|
142
128
|
}),
|
|
143
129
|
getRoleComponent({
|
|
144
130
|
key: "update_own",
|
|
145
|
-
label:
|
|
146
|
-
'<h4 class="text-gray-800">Update Form Definition (Restricted to owner)</h4>',
|
|
131
|
+
label: '<h4 class="text-gray-800">Update Form Definition (Restricted to owner)</h4>',
|
|
147
132
|
description: toDescription(
|
|
148
133
|
"The Update Own permission will allow a user, with one of the given Roles, to update a form. A user can only update a form if they are defined as its owner."
|
|
149
134
|
),
|
|
@@ -159,8 +144,7 @@ export function getAccessPermissionForm({ choices }: any): FormSchema {
|
|
|
159
144
|
}),
|
|
160
145
|
getRoleComponent({
|
|
161
146
|
key: "delete_own",
|
|
162
|
-
label:
|
|
163
|
-
'<h4 class="text-gray-800">Delete Form Definition (Restricted to owner)</h4>',
|
|
147
|
+
label: '<h4 class="text-gray-800">Delete Form Definition (Restricted to owner)</h4>',
|
|
164
148
|
description: toDescription(
|
|
165
149
|
"The Delete Own permission will allow a user, with one of the given Roles, to delete a form. A user can only delete a form if they are defined as its owner."
|
|
166
150
|
),
|
|
@@ -27,11 +27,8 @@ export default {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
export const Sandbox = (args: any) => {
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
31
30
|
// @ts-ignore
|
|
32
|
-
return
|
|
33
|
-
<FormAccess {...args} options={{ template: "tailwind", iconset: "bx" }} />
|
|
34
|
-
);
|
|
31
|
+
return <FormAccess {...args} options={{ template: "tailwind", iconset: "bx" }} />;
|
|
35
32
|
};
|
|
36
33
|
|
|
37
34
|
Sandbox.args = {
|
|
@@ -42,11 +39,7 @@ Sandbox.args = {
|
|
|
42
39
|
owner: "5d0797a382461b6656d2c790",
|
|
43
40
|
access: [
|
|
44
41
|
{
|
|
45
|
-
roles: [
|
|
46
|
-
"5d0797bc872fc747da559858",
|
|
47
|
-
"5d0797bc872fc71d05559859",
|
|
48
|
-
"5d0797bc872fc7da3b55985a"
|
|
49
|
-
],
|
|
42
|
+
roles: ["5d0797bc872fc747da559858", "5d0797bc872fc71d05559859", "5d0797bc872fc7da3b55985a"],
|
|
50
43
|
type: "read_all"
|
|
51
44
|
}
|
|
52
45
|
],
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { FormSchema } from "../../interfaces";
|
|
2
|
-
import {
|
|
3
|
-
dataAccessToSubmissions,
|
|
4
|
-
getFormAccess,
|
|
5
|
-
SubmissionAccess,
|
|
6
|
-
submissionsToDataAccess,
|
|
7
|
-
updateSubmissions
|
|
8
|
-
} from "./formAccess.utils";
|
|
2
|
+
import { dataAccessToSubmissions, getFormAccess, SubmissionAccess, submissionsToDataAccess, updateSubmissions } from "./formAccess.utils";
|
|
9
3
|
|
|
10
4
|
const roles: any[] = [
|
|
11
5
|
{
|
|
@@ -24,11 +18,7 @@ describe("formAccess.utils", () => {
|
|
|
24
18
|
components: [],
|
|
25
19
|
access: [
|
|
26
20
|
{
|
|
27
|
-
roles: [
|
|
28
|
-
"5d0797bc872fc747da559858",
|
|
29
|
-
"5d0797bc872fc71d05559859",
|
|
30
|
-
"5d0797bc872fc7da3b55985a"
|
|
31
|
-
],
|
|
21
|
+
roles: ["5d0797bc872fc747da559858", "5d0797bc872fc71d05559859", "5d0797bc872fc7da3b55985a"],
|
|
32
22
|
type: "read_all"
|
|
33
23
|
}
|
|
34
24
|
],
|
|
@@ -47,11 +37,7 @@ describe("formAccess.utils", () => {
|
|
|
47
37
|
data: {
|
|
48
38
|
delete_all: [],
|
|
49
39
|
delete_own: [],
|
|
50
|
-
read_all: [
|
|
51
|
-
"5d0797bc872fc747da559858",
|
|
52
|
-
"5d0797bc872fc71d05559859",
|
|
53
|
-
"5d0797bc872fc7da3b55985a"
|
|
54
|
-
],
|
|
40
|
+
read_all: ["5d0797bc872fc747da559858", "5d0797bc872fc71d05559859", "5d0797bc872fc7da3b55985a"],
|
|
55
41
|
read_own: [],
|
|
56
42
|
update_all: [],
|
|
57
43
|
update_own: []
|
|
@@ -104,11 +90,7 @@ describe("formAccess.utils", () => {
|
|
|
104
90
|
components: [],
|
|
105
91
|
access: [
|
|
106
92
|
{
|
|
107
|
-
roles: [
|
|
108
|
-
"5d0797bc872fc747da559858",
|
|
109
|
-
"5d0797bc872fc71d05559859",
|
|
110
|
-
"5d0797bc872fc7da3b55985a"
|
|
111
|
-
],
|
|
93
|
+
roles: ["5d0797bc872fc747da559858", "5d0797bc872fc71d05559859", "5d0797bc872fc7da3b55985a"],
|
|
112
94
|
type: "read_all"
|
|
113
95
|
}
|
|
114
96
|
],
|
|
@@ -4,10 +4,7 @@ import isEqual from "lodash/isEqual";
|
|
|
4
4
|
import noop from "lodash/noop";
|
|
5
5
|
import { FormSchema, Submission } from "../../interfaces";
|
|
6
6
|
import { RoleSchema } from "../../interfaces/RoleSchema";
|
|
7
|
-
import {
|
|
8
|
-
getAccessPermissionForm,
|
|
9
|
-
getSubmissionPermissionForm
|
|
10
|
-
} from "./formAccess.schema";
|
|
7
|
+
import { getAccessPermissionForm, getSubmissionPermissionForm } from "./formAccess.schema";
|
|
11
8
|
|
|
12
9
|
export interface Choice {
|
|
13
10
|
label: string;
|
|
@@ -81,30 +78,20 @@ export function getFormAccess(roles: RoleSchema[]): FormAccessSchema {
|
|
|
81
78
|
};
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
export function dataAccessToSubmissions(
|
|
85
|
-
|
|
86
|
-
formAccess: FormAccessSchema
|
|
87
|
-
): SubmissionAccess {
|
|
88
|
-
const getKeys = (components: ExtendedComponentSchema[]) =>
|
|
89
|
-
components.map(({ key }) => key);
|
|
81
|
+
export function dataAccessToSubmissions(form: Partial<FormSchema>, formAccess: FormAccessSchema): SubmissionAccess {
|
|
82
|
+
const getKeys = (components: ExtendedComponentSchema[]) => components.map(({ key }) => key);
|
|
90
83
|
|
|
91
84
|
return {
|
|
92
85
|
access: {
|
|
93
86
|
data: accessToHash(getKeys(formAccess.access.components), form.access)
|
|
94
87
|
},
|
|
95
88
|
submissionAccess: {
|
|
96
|
-
data: accessToHash(
|
|
97
|
-
getKeys(formAccess.submissionAccess.components),
|
|
98
|
-
form.submissionAccess
|
|
99
|
-
)
|
|
89
|
+
data: accessToHash(getKeys(formAccess.submissionAccess.components), form.submissionAccess)
|
|
100
90
|
}
|
|
101
91
|
};
|
|
102
92
|
}
|
|
103
93
|
|
|
104
|
-
export function submissionsToDataAccess(
|
|
105
|
-
form: Partial<FormSchema>,
|
|
106
|
-
submissions: SubmissionAccess
|
|
107
|
-
): Partial<FormSchema> {
|
|
94
|
+
export function submissionsToDataAccess(form: Partial<FormSchema>, submissions: SubmissionAccess): Partial<FormSchema> {
|
|
108
95
|
return {
|
|
109
96
|
...cloneDeep(form),
|
|
110
97
|
access: hashToAccess(submissions.access.data),
|
|
@@ -112,20 +99,11 @@ export function submissionsToDataAccess(
|
|
|
112
99
|
};
|
|
113
100
|
}
|
|
114
101
|
|
|
115
|
-
export function shouldUpdate(
|
|
116
|
-
type: string,
|
|
117
|
-
submission: Submission<AccessRoles>,
|
|
118
|
-
submissions: SubmissionAccess
|
|
119
|
-
) {
|
|
102
|
+
export function shouldUpdate(type: string, submission: Submission<AccessRoles>, submissions: SubmissionAccess) {
|
|
120
103
|
return !isEqual(submission.data, submissions[type].data);
|
|
121
104
|
}
|
|
122
105
|
|
|
123
|
-
export function updateSubmissions(
|
|
124
|
-
type: string,
|
|
125
|
-
submission: Submission<AccessRoles>,
|
|
126
|
-
submissions: SubmissionAccess,
|
|
127
|
-
cb: Function = noop
|
|
128
|
-
) {
|
|
106
|
+
export function updateSubmissions(type: string, submission: Submission<AccessRoles>, submissions: SubmissionAccess, cb: Function = noop) {
|
|
129
107
|
if (shouldUpdate(type, submission, submissions)) {
|
|
130
108
|
submissions = {
|
|
131
109
|
...submissions,
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import FormioUtils from "formiojs/utils";
|
|
2
2
|
import React, { PropsWithChildren, ReactElement, useMemo } from "react";
|
|
3
|
-
import {
|
|
4
|
-
ActionDefaultsSchema,
|
|
5
|
-
ActionSchema,
|
|
6
|
-
FormOptions,
|
|
7
|
-
Submission
|
|
8
|
-
} from "../../interfaces";
|
|
3
|
+
import { ActionDefaultsSchema, ActionSchema, FormOptions, Submission } from "../../interfaces";
|
|
9
4
|
import { Form } from "../form/form.component";
|
|
10
5
|
|
|
11
6
|
function mapData(options: any, defaults: ActionDefaultsSchema): any {
|
|
@@ -42,13 +37,7 @@ export interface FormActionProps {
|
|
|
42
37
|
options: FormOptions;
|
|
43
38
|
}
|
|
44
39
|
|
|
45
|
-
export function FormAction({
|
|
46
|
-
actionInfo,
|
|
47
|
-
children,
|
|
48
|
-
onSubmit,
|
|
49
|
-
options,
|
|
50
|
-
...props
|
|
51
|
-
}: PropsWithChildren<FormActionProps>): ReactElement {
|
|
40
|
+
export function FormAction({ actionInfo, children, onSubmit, options, ...props }: PropsWithChildren<FormActionProps>): ReactElement {
|
|
52
41
|
const { form, submission } = useMemo(() => {
|
|
53
42
|
const submission = mapData(props.submission || {}, actionInfo.defaults);
|
|
54
43
|
const form = mapSettingsForm(actionInfo.settingsForm);
|
|
@@ -60,12 +49,7 @@ export function FormAction({
|
|
|
60
49
|
<div>
|
|
61
50
|
{children}
|
|
62
51
|
|
|
63
|
-
<Form
|
|
64
|
-
form={form}
|
|
65
|
-
submission={submission}
|
|
66
|
-
onSubmit={onSubmit}
|
|
67
|
-
options={options}
|
|
68
|
-
/>
|
|
52
|
+
<Form form={form} submission={submission} onSubmit={onSubmit} options={options} />
|
|
69
53
|
|
|
70
54
|
{children}
|
|
71
55
|
</div>
|