@evoke-platform/ui-components 1.0.0-dev.226 → 1.0.0-dev.228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/published/components/core/Accordion/Accordion.js +1 -1
- package/dist/published/components/core/Accordion/AccordionActions/AccordionActions.js +1 -1
- package/dist/published/components/core/Accordion/AccordionDetails/AccordionDetails.js +1 -1
- package/dist/published/components/core/Accordion/AccordionSummary/AccordionSummary.js +1 -1
- package/dist/published/components/core/Alert/Alert.js +8 -9
- package/dist/published/components/core/AlertTitle/AlertTitle.js +1 -1
- package/dist/published/components/core/AppBar/AppBar.js +1 -1
- package/dist/published/components/core/Autocomplete/Autocomplete.js +33 -15
- package/dist/published/components/core/Autocomplete/Autocomplete.test.js +1 -1
- package/dist/published/components/core/Avatar/Avatar.js +7 -4
- package/dist/published/components/core/Backdrop/Backdrop.js +1 -1
- package/dist/published/components/core/Badge/Badge.js +1 -1
- package/dist/published/components/core/Breadcrumbs/Breadcrumbs.js +1 -1
- package/dist/published/components/core/Button/Button.js +1 -1
- package/dist/published/components/core/ButtonGroup/ButtonGroup.js +1 -1
- package/dist/published/components/core/Card/Card.js +1 -1
- package/dist/published/components/core/Checkbox/Checkbox.js +1 -1
- package/dist/published/components/core/Chip/Chip.js +1 -1
- package/dist/published/components/core/CircularProgress/CircularProgress.js +1 -1
- package/dist/published/components/core/Collapse/Collapse.js +1 -1
- package/dist/published/components/core/DatePicker/DatePicker.js +4 -16
- package/dist/published/components/core/DateTimePicker/DateTimePicker.js +3 -15
- package/dist/published/components/core/Dialog/Dialog.js +1 -1
- package/dist/published/components/core/Dialog/DialogActions/DialogActions.js +2 -13
- package/dist/published/components/core/Dialog/DialogContent/DialogContent.js +1 -1
- package/dist/published/components/core/Dialog/DialogContentText/DialogContentText.js +1 -1
- package/dist/published/components/core/Dialog/DialogTitle/DialogTitle.js +1 -1
- package/dist/published/components/core/Divider/Divider.js +1 -1
- package/dist/published/components/core/Drawer/Drawer.js +1 -1
- package/dist/published/components/core/FieldError/FieldError.js +1 -2
- package/dist/published/components/core/FormElements/FormControl/FormControl.js +1 -1
- package/dist/published/components/core/FormElements/FormControlLabel/FormControlLabel.js +1 -1
- package/dist/published/components/core/FormElements/FormGroup/FormGroup.js +1 -1
- package/dist/published/components/core/FormElements/FormHelperText/FormHelperText.js +1 -1
- package/dist/published/components/core/FormElements/FormLabel/FormLabel.js +1 -1
- package/dist/published/components/core/IconButton/IconButton.js +1 -1
- package/dist/published/components/core/LinearProgress/LinearProgress.js +1 -1
- package/dist/published/components/core/Link/Link.js +1 -1
- package/dist/published/components/core/List/List.js +1 -1
- package/dist/published/components/core/List/ListItem.js +1 -1
- package/dist/published/components/core/List/ListItemText/ListItemText.js +1 -1
- package/dist/published/components/core/LoadingButton/LoadingButton.js +1 -1
- package/dist/published/components/core/LocalizationProvider/LocalizationProvider.js +3 -14
- package/dist/published/components/core/Menu/Menu.js +1 -1
- package/dist/published/components/core/Menu/MenuItem/MenuItem.js +1 -1
- package/dist/published/components/core/Paper/Paper.js +1 -1
- package/dist/published/components/core/Popover/Popover.js +1 -1
- package/dist/published/components/core/Popper/Popper.js +1 -1
- package/dist/published/components/core/RadioGroup/Radio.js +1 -1
- package/dist/published/components/core/RadioGroup/RadioGroup.js +1 -1
- package/dist/published/components/core/Select/Select.js +11 -4
- package/dist/published/components/core/Skeleton/Skeleton.js +1 -1
- package/dist/published/components/core/Snackbar/Snackbar.js +2 -2
- package/dist/published/components/core/StaticDatePicker/StaticDatePicker.js +3 -15
- package/dist/published/components/core/Stepper/Step/Step.js +1 -1
- package/dist/published/components/core/Stepper/StepButton/StepButton.js +1 -1
- package/dist/published/components/core/Stepper/StepConnector/StepConnector.js +1 -1
- package/dist/published/components/core/Stepper/StepContent/StepContent.js +1 -1
- package/dist/published/components/core/Stepper/StepIcon/StepIcon.js +1 -1
- package/dist/published/components/core/Stepper/StepLabel/StepLabel.js +1 -1
- package/dist/published/components/core/Stepper/Stepper.js +1 -1
- package/dist/published/components/core/Switch/Switch.js +1 -1
- package/dist/published/components/core/Table/Table.js +1 -1
- package/dist/published/components/core/Tabs/Tab/Tab.js +1 -1
- package/dist/published/components/core/Tabs/Tabs.js +1 -1
- package/dist/published/components/core/TextField/TextField.js +12 -6
- package/dist/published/components/core/ToggleButton/ToggleButton.js +1 -1
- package/dist/published/components/core/ToggleButtonGroup/ToggleButtonGroup.js +1 -1
- package/dist/published/components/core/Tooltip/Tooltip.js +15 -2
- package/dist/published/components/core/Typography/index.js +1 -1
- package/dist/published/components/custom/BuilderGrid/BuilderGrid.js +33 -29
- package/dist/published/components/custom/BuilderGrid/BuilderGridToolbar.js +1 -2
- package/dist/published/components/custom/BuilderGrid/EmptyContent.js +4 -5
- package/dist/published/components/custom/BuilderGrid/EmptyContentIllustration.js +6 -1
- package/dist/published/components/custom/BuilderGrid/ToolbarActions.js +3 -1
- package/dist/published/components/custom/CriteriaBuilder/CriteriaBuilder.js +46 -27
- package/dist/published/components/custom/CriteriaBuilder/CriteriaBuilder.test.js +12 -21
- package/dist/published/components/custom/CriteriaBuilder/ValueEditor.js +27 -34
- package/dist/published/components/custom/DataGrid/DataGrid.js +38 -33
- package/dist/published/components/custom/DataGrid/DateTimeCustomOperator.js +3 -5
- package/dist/published/components/custom/DataGrid/Toolbar.js +3 -4
- package/dist/published/components/custom/ErrorComponent/ErrorComponent.js +11 -1
- package/dist/published/components/custom/Form/Common/Form.js +106 -80
- package/dist/published/components/custom/Form/Common/FormComponentWrapper.js +20 -11
- package/dist/published/components/custom/Form/FormComponents/ButtonComponent.js +9 -20
- package/dist/published/components/custom/Form/FormComponents/DocumentComponent/Document.js +10 -20
- package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentComponent.js +24 -28
- package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentList.js +49 -64
- package/dist/published/components/custom/Form/FormComponents/FormFieldComponent.d.ts +1 -0
- package/dist/published/components/custom/Form/FormComponents/FormFieldComponent.js +109 -34
- package/dist/published/components/custom/Form/FormComponents/ImageComponent/Image.d.ts +2 -0
- package/dist/published/components/custom/Form/FormComponents/ImageComponent/Image.js +13 -25
- package/dist/published/components/custom/Form/FormComponents/ImageComponent/ImageComponent.d.ts +3 -1
- package/dist/published/components/custom/Form/FormComponents/ImageComponent/ImageComponent.js +30 -9
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/InstanceLookup.js +26 -31
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectComponent.d.ts +5 -4
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectComponent.js +70 -22
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectPropertyInput.js +93 -75
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/RelatedObjectInstance.d.ts +2 -2
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/RelatedObjectInstance.js +17 -26
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ActionDialog.js +20 -24
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ManyToMany/DropdownRepeatableField.js +22 -33
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ManyToMany/DropdownRepeatableFieldInput.js +12 -9
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableField.js +105 -82
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableFieldComponent.js +8 -6
- package/dist/published/components/custom/Form/FormComponents/UserComponent/UserComponent.d.ts +3 -1
- package/dist/published/components/custom/Form/FormComponents/UserComponent/UserComponent.js +55 -12
- package/dist/published/components/custom/Form/FormComponents/UserComponent/UserProperty.js +32 -30
- package/dist/published/components/custom/Form/FormComponents/ViewOnlyComponent.js +12 -9
- package/dist/published/components/custom/Form/types.d.ts +5 -5
- package/dist/published/components/custom/Form/utils.js +611 -446
- package/dist/published/components/custom/FormField/AddressFieldComponent/AddressFieldComponent.test.js +41 -54
- package/dist/published/components/custom/FormField/AddressFieldComponent/addressFieldComponent.js +7 -8
- package/dist/published/components/custom/FormField/BooleanSelect/BooleanSelect.js +1 -1
- package/dist/published/components/custom/FormField/BooleanSelect/BooleanSelect.test.js +5 -14
- package/dist/published/components/custom/FormField/DatePickerSelect/DatePickerSelect.js +2 -2
- package/dist/published/components/custom/FormField/DatePickerSelect/DatePickerSelect.test.js +12 -21
- package/dist/published/components/custom/FormField/DateTimePickerSelect/DateTimePickerSelect.js +2 -2
- package/dist/published/components/custom/FormField/DateTimePickerSelect/DateTimePickerSelect.test.js +12 -21
- package/dist/published/components/custom/FormField/FileUpload/FileUpload.js +10 -11
- package/dist/published/components/custom/FormField/FormField.js +10 -10
- package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.js +22 -30
- package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.test.js +8 -17
- package/dist/published/components/custom/FormField/Select/Select.js +5 -6
- package/dist/published/components/custom/FormField/Select/Select.test.js +18 -27
- package/dist/published/components/custom/FormField/TimePickerSelect/TimePickerSelect.js +4 -4
- package/dist/published/components/custom/HistoryLog/DisplayedProperty.js +12 -13
- package/dist/published/components/custom/HistoryLog/HistoryData.js +49 -45
- package/dist/published/components/custom/HistoryLog/HistoryLoading.js +5 -5
- package/dist/published/components/custom/HistoryLog/index.js +5 -6
- package/dist/published/components/custom/Menubar/Menubar.js +2 -2
- package/dist/published/components/custom/MultiSelect/MultiSelect.js +38 -50
- package/dist/published/components/custom/MultiSelect/SortableItem.js +1 -1
- package/dist/published/components/custom/RepeatableField/RepeatableField.js +14 -16
- package/dist/published/components/custom/UserAvatar/UserAvatar.js +12 -5
- package/dist/published/components/custom/util.js +1 -1
- package/dist/published/components/layout/Box/Box.js +1 -1
- package/dist/published/components/layout/Container/Container.js +1 -1
- package/dist/published/components/layout/Grid/Grid.js +1 -1
- package/dist/published/components/layout/Stack/Stack.js +1 -1
- package/dist/published/icons/custom/FileWithExtension.js +8 -4
- package/dist/published/icons/custom/Inherited.js +8 -6
- package/dist/published/icons/custom/Overrides.js +9 -7
- package/dist/published/icons/custom/TrashCan.js +10 -8
- package/dist/published/icons/custom/UploadCloud.js +9 -7
- package/dist/published/stories/Accordion.stories.js +2 -2
- package/dist/published/stories/Alert.stories.js +1 -1
- package/dist/published/stories/AlertTitle.stories.js +1 -1
- package/dist/published/stories/Autocomplete.stories.js +2 -2
- package/dist/published/stories/Avatar.stories.js +1 -1
- package/dist/published/stories/Backdrop.stories.js +1 -1
- package/dist/published/stories/Badge.stories.js +1 -1
- package/dist/published/stories/Box.stories.js +2 -2
- package/dist/published/stories/Breadcrumbs.stories.js +1 -1
- package/dist/published/stories/Button.stories.js +1 -1
- package/dist/published/stories/ButtonGroup.stories.js +1 -1
- package/dist/published/stories/Card.stories.js +1 -1
- package/dist/published/stories/Checkbox.stories.js +1 -1
- package/dist/published/stories/Chip.stories.js +1 -1
- package/dist/published/stories/CircularProgress.stories.js +1 -1
- package/dist/published/stories/Collapse.stories.js +1 -1
- package/dist/published/stories/Container.stories.js +1 -1
- package/dist/published/stories/CriteriaBuilder.stories.js +7 -3
- package/dist/published/stories/DataGrid.stories.js +3 -3
- package/dist/published/stories/DatePicker.stories.js +3 -14
- package/dist/published/stories/Dialog.stories.js +1 -1
- package/dist/published/stories/Divider.stories.js +1 -1
- package/dist/published/stories/Drawer.stories.js +2 -2
- package/dist/published/stories/FormControl.stories.js +1 -1
- package/dist/published/stories/FormControlLabel.stories.js +1 -1
- package/dist/published/stories/FormField.stories.js +3 -12
- package/dist/published/stories/FormGroup.stories.js +1 -1
- package/dist/published/stories/FormHelperText.stories.js +1 -1
- package/dist/published/stories/FormLabel.stories.js +1 -1
- package/dist/published/stories/Grid.stories.js +1 -1
- package/dist/published/stories/HistoryLog.stories.js +1 -1
- package/dist/published/stories/IconButton.stories.js +4 -4
- package/dist/published/stories/LinearProgress.stories.js +1 -1
- package/dist/published/stories/Link.stories.js +1 -1
- package/dist/published/stories/List.stories.js +2 -2
- package/dist/published/stories/Menu.stories.js +2 -2
- package/dist/published/stories/MenuBar.stories.js +1 -1
- package/dist/published/stories/MultiSelect.stories.js +3 -3
- package/dist/published/stories/Palette.stories.js +11 -11
- package/dist/published/stories/Paper.stories.js +1 -1
- package/dist/published/stories/RadioGroup.stories.js +1 -1
- package/dist/published/stories/RepeatableField.stories.js +6 -7
- package/dist/published/stories/RichTextViewer.stories.js +1 -1
- package/dist/published/stories/Skeleton.stories.js +1 -1
- package/dist/published/stories/Snackbar.stories.js +1 -1
- package/dist/published/stories/Stack.stories.js +1 -1
- package/dist/published/stories/StaticDatePicker.stories.js +3 -14
- package/dist/published/stories/Stepper.stories.js +3 -3
- package/dist/published/stories/Switch.stories.js +1 -1
- package/dist/published/stories/Table.stories.js +2 -2
- package/dist/published/stories/Tabs.stories.js +6 -17
- package/dist/published/stories/TextField.stories.js +1 -1
- package/dist/published/stories/TimePicker.stories.js +3 -14
- package/dist/published/stories/TimePickerSelect.stories.js +3 -14
- package/dist/published/stories/ToggleButton.stories.js +4 -4
- package/dist/published/theme/UIThemeProvider.js +1 -2
- package/package.json +1 -1
@@ -1,12 +1,3 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
1
|
import { useApp, useAuthenticationContext, } from '@evoke-platform/context';
|
11
2
|
import { Components, Form as FormIO } from '@formio/react';
|
12
3
|
import { flatten } from 'flat';
|
@@ -25,13 +16,12 @@ const usePrevious = (value) => {
|
|
25
16
|
return ref.current;
|
26
17
|
};
|
27
18
|
export function Form(props) {
|
28
|
-
var _a;
|
29
19
|
const { clearable, closeModal, onSave, submitButtonLabel, instance, object, objectInputCommonProps, actionId, actionType, associatedObject, onAutoSave, apiServices, navigateTo, document, queryAddresses, user, isReadOnly, fieldHeight, richTextEditor, } = props;
|
30
20
|
const [formKey, setFormKey] = useState();
|
31
21
|
const [componentProps, setComponentProps] = useState([]);
|
32
22
|
const [snackbarError, setSnackbarError] = useState();
|
33
23
|
const prevFormKey = usePrevious(formKey);
|
34
|
-
const userAccount = user
|
24
|
+
const userAccount = user ?? useAuthenticationContext()?.account;
|
35
25
|
const { defaultPages, findDefaultPageSlugFor } = useApp();
|
36
26
|
const rebuildFormComponents = () => {
|
37
27
|
const viewDetailsComponents = {
|
@@ -53,7 +43,30 @@ export function Form(props) {
|
|
53
43
|
ViewOnlyImage: ImageComponent,
|
54
44
|
ViewOnlyTime: ViewOnlyComponent,
|
55
45
|
};
|
56
|
-
Components.setComponents(
|
46
|
+
Components.setComponents({
|
47
|
+
...Components.components,
|
48
|
+
Boolean: FormFieldComponent,
|
49
|
+
Columns: Components.components.columns,
|
50
|
+
DateTime: FormFieldComponent,
|
51
|
+
Date: FormFieldComponent,
|
52
|
+
Select: FormFieldComponent,
|
53
|
+
MultiSelect: FormFieldComponent,
|
54
|
+
Object: ObjectComponent,
|
55
|
+
User: UserComponent,
|
56
|
+
TextField: FormFieldComponent,
|
57
|
+
Decimal: FormFieldComponent,
|
58
|
+
Document: DocumentComponent,
|
59
|
+
Integer: FormFieldComponent,
|
60
|
+
Buttons: ButtonComponent,
|
61
|
+
Content: Components.components.content,
|
62
|
+
RichText: richTextEditor,
|
63
|
+
Section: Components.components.tabs,
|
64
|
+
ManyToManyRepeatableField: RepeatableFieldComponent,
|
65
|
+
RepeatableField: RepeatableFieldComponent,
|
66
|
+
Image: ImageComponent,
|
67
|
+
Time: FormFieldComponent,
|
68
|
+
...(isReadOnly && viewDetailsComponents),
|
69
|
+
});
|
57
70
|
buildComponents();
|
58
71
|
};
|
59
72
|
useEffect(() => {
|
@@ -68,55 +81,59 @@ export function Form(props) {
|
|
68
81
|
buildComponents();
|
69
82
|
}
|
70
83
|
}, [formKey]);
|
71
|
-
const buildComponents = () =>
|
72
|
-
|
73
|
-
const action = (_b = object === null || object === void 0 ? void 0 : object.actions) === null || _b === void 0 ? void 0 : _b.find((action) => action.id === actionId);
|
84
|
+
const buildComponents = async () => {
|
85
|
+
const action = object?.actions?.find((action) => action.id === actionId);
|
74
86
|
let input;
|
75
|
-
const parameters =
|
76
|
-
? action.parameters.filter((param) => param.id !==
|
77
|
-
: action
|
87
|
+
const parameters = associatedObject?.propertyId && action?.parameters
|
88
|
+
? action.parameters.filter((param) => param.id !== associatedObject?.propertyId)
|
89
|
+
: action?.parameters;
|
78
90
|
if (parameters && object) {
|
79
|
-
input =
|
91
|
+
input = action?.form?.entries
|
80
92
|
? convertFormToComponents(action.form.entries, parameters, object)
|
81
|
-
: parameters.filter((param) =>
|
93
|
+
: parameters.filter((param) => object.properties?.some((prop) => prop.id === param.id));
|
82
94
|
}
|
83
95
|
else {
|
84
|
-
input =
|
96
|
+
input = action?.inputProperties ?? (action?.type === 'delete' ? [] : undefined);
|
85
97
|
}
|
86
|
-
let visibleObjectProperties = object
|
98
|
+
let visibleObjectProperties = object?.properties;
|
87
99
|
if (associatedObject) {
|
88
100
|
// Eliminates the associated object's field from the form
|
89
|
-
visibleObjectProperties = visibleObjectProperties
|
101
|
+
visibleObjectProperties = visibleObjectProperties?.filter((property) => property.id !== associatedObject.propertyId);
|
90
102
|
}
|
91
103
|
let foundDefaultPages = defaultPages;
|
92
|
-
const relatedObjectProperties = visibleObjectProperties
|
104
|
+
const relatedObjectProperties = visibleObjectProperties?.filter((property) => property.type === 'object');
|
93
105
|
if (relatedObjectProperties) {
|
94
|
-
foundDefaultPages =
|
95
|
-
const result =
|
106
|
+
foundDefaultPages = await relatedObjectProperties.reduce(async (acc, property) => {
|
107
|
+
const result = await acc;
|
96
108
|
if (property.objectId && defaultPages && defaultPages[property.objectId]) {
|
97
|
-
const slug =
|
109
|
+
const slug = await findDefaultPageSlugFor(property.objectId);
|
98
110
|
if (slug) {
|
99
|
-
return
|
111
|
+
return { ...result, [property.objectId]: slug };
|
100
112
|
}
|
101
113
|
}
|
102
114
|
return result;
|
103
|
-
}
|
115
|
+
}, Promise.resolve({}));
|
104
116
|
}
|
105
|
-
const allDefaultPages =
|
117
|
+
const allDefaultPages = { ...defaultPages, ...foundDefaultPages };
|
106
118
|
if (input && visibleObjectProperties) {
|
107
|
-
if (input.length ||
|
119
|
+
if (input.length || action?.type !== 'delete') {
|
108
120
|
// formIO builder-configured input properties exist
|
109
|
-
const newComponentProps =
|
110
|
-
|
121
|
+
const newComponentProps = await addObjectPropertiesToComponentProps(visibleObjectProperties, input, instance, {
|
122
|
+
...objectInputCommonProps,
|
123
|
+
defaultPages: allDefaultPages,
|
124
|
+
navigateTo,
|
125
|
+
apiServices,
|
126
|
+
user: userAccount,
|
127
|
+
}, undefined, isReadOnly, allDefaultPages, navigateTo, queryAddresses, apiServices, !!closeModal, fieldHeight);
|
111
128
|
const components = isReadOnly ? newComponentProps : [...newComponentProps, BottomButtons];
|
112
129
|
setComponentProps(components);
|
113
130
|
}
|
114
131
|
else {
|
115
132
|
// this condition is used for the delete action's modal form
|
116
133
|
setComponentProps([
|
117
|
-
...(
|
134
|
+
...(await addObjectPropertiesToComponentProps(visibleObjectProperties, [
|
118
135
|
{
|
119
|
-
html: `<p>${
|
136
|
+
html: `<p>${action?.type === 'delete' ? 'This action cannot be undone.' : 'Are you sure?'}</p>`,
|
120
137
|
label: 'Content',
|
121
138
|
customClass: '',
|
122
139
|
refreshOnChange: false,
|
@@ -182,33 +199,41 @@ export function Form(props) {
|
|
182
199
|
addons: [],
|
183
200
|
id: 'eahbwo',
|
184
201
|
},
|
185
|
-
], instance,
|
186
|
-
|
202
|
+
], instance, {
|
203
|
+
...objectInputCommonProps,
|
204
|
+
defaultPages: allDefaultPages,
|
205
|
+
navigateTo,
|
206
|
+
apiServices,
|
207
|
+
user: userAccount,
|
208
|
+
}, undefined, undefined, undefined, undefined, undefined, undefined, !!closeModal, fieldHeight)),
|
187
209
|
BottomButtons,
|
188
210
|
]);
|
189
211
|
}
|
190
212
|
}
|
191
|
-
else if (object
|
213
|
+
else if (object?.properties) {
|
192
214
|
// If form.io form is not configured and no inputProperties are
|
193
215
|
// set, use object properties to build form.
|
194
|
-
const propertiesInForm = object.properties.filter((prop) => prop.id !==
|
216
|
+
const propertiesInForm = object.properties.filter((prop) => prop.id !== associatedObject?.propertyId && (action?.type !== 'create' || prop.type !== 'document'));
|
195
217
|
setComponentProps([
|
196
|
-
...buildComponentPropsFromObjectProperties(propertiesInForm, object.id, instance,
|
218
|
+
...buildComponentPropsFromObjectProperties(propertiesInForm, object.id, instance, {
|
219
|
+
...objectInputCommonProps,
|
220
|
+
defaultPages: allDefaultPages,
|
221
|
+
navigateTo,
|
197
222
|
apiServices,
|
198
|
-
user
|
223
|
+
user,
|
224
|
+
}, !!action, undefined, isReadOnly, queryAddresses, !!closeModal, fieldHeight),
|
199
225
|
!isReadOnly && BottomButtons,
|
200
226
|
]);
|
201
227
|
}
|
202
228
|
else if (document) {
|
203
|
-
const documentProperties = toPairs(flatten(document
|
229
|
+
const documentProperties = toPairs(flatten(document ?? {}));
|
204
230
|
setComponentProps([
|
205
231
|
...buildComponentPropsFromDocumentProperties(documentProperties, isReadOnly, undefined, fieldHeight),
|
206
232
|
!isReadOnly && BottomButtons,
|
207
233
|
]);
|
208
234
|
}
|
209
|
-
}
|
210
|
-
const uploadDocuments = (files, metadata) =>
|
211
|
-
var _e;
|
235
|
+
};
|
236
|
+
const uploadDocuments = async (files, metadata) => {
|
212
237
|
const allDocuments = [];
|
213
238
|
const formData = new FormData();
|
214
239
|
for (const [index, file] of files.entries()) {
|
@@ -224,29 +249,32 @@ export function Form(props) {
|
|
224
249
|
formData.append(key, value);
|
225
250
|
}
|
226
251
|
}
|
227
|
-
const docs =
|
228
|
-
return allDocuments.concat(
|
229
|
-
}
|
230
|
-
const saveDocuments = (submittedFields, action) =>
|
231
|
-
|
232
|
-
const documentProperties = (action === null || action === void 0 ? void 0 : action.parameters)
|
252
|
+
const docs = await apiServices?.post(getPrefixedUrl(`/objects/${object?.id}/instances/${instance?.id}/documents`), formData);
|
253
|
+
return allDocuments.concat(docs?.map((doc) => ({ id: doc.id, name: doc.name })) ?? []);
|
254
|
+
};
|
255
|
+
const saveDocuments = async (submittedFields, action) => {
|
256
|
+
const documentProperties = action?.parameters
|
233
257
|
? action.parameters.filter((param) => param.type === 'document')
|
234
|
-
:
|
258
|
+
: object?.properties?.filter((prop) => prop.type === 'document');
|
235
259
|
let allEntries = null;
|
236
|
-
for (const docProperty of documentProperties
|
260
|
+
for (const docProperty of documentProperties ?? []) {
|
237
261
|
const value = submittedFields[docProperty.id];
|
238
262
|
// skip if the document list did not change
|
239
|
-
if (value === undefined || !instance || isEqual(instance
|
263
|
+
if (value === undefined || !instance || isEqual(instance?.[docProperty.id], value)) {
|
240
264
|
continue;
|
241
265
|
}
|
242
266
|
let savedDocuments = null;
|
243
267
|
if (value && value.some((doc) => doc instanceof File)) {
|
244
268
|
if (!allEntries) {
|
245
|
-
allEntries =
|
269
|
+
allEntries = getFlattenEntries(action?.form?.entries ?? []) ?? [];
|
246
270
|
}
|
247
271
|
const docEntry = allEntries.find((entry) => entry.parameterId === docProperty.id);
|
248
272
|
try {
|
249
|
-
savedDocuments =
|
273
|
+
savedDocuments = await uploadDocuments(value, {
|
274
|
+
type: '',
|
275
|
+
view_permission: '',
|
276
|
+
...docEntry?.documentMetadata,
|
277
|
+
});
|
250
278
|
}
|
251
279
|
catch (error) {
|
252
280
|
setSnackbarError({ message: `An error occurred while uploading associated documents` });
|
@@ -260,32 +288,30 @@ export function Form(props) {
|
|
260
288
|
submittedFields[docProperty.id] = savedDocuments;
|
261
289
|
}
|
262
290
|
return true;
|
263
|
-
}
|
264
|
-
const deleteDocuments = (submittedFields, requestSuccess, action) =>
|
265
|
-
|
266
|
-
const documentProperties = (action === null || action === void 0 ? void 0 : action.parameters)
|
291
|
+
};
|
292
|
+
const deleteDocuments = async (submittedFields, requestSuccess, action) => {
|
293
|
+
const documentProperties = action?.parameters
|
267
294
|
? action.parameters.filter((param) => param.type === 'document')
|
268
|
-
:
|
269
|
-
for (const docProperty of documentProperties
|
295
|
+
: object?.properties?.filter((prop) => prop.type === 'document');
|
296
|
+
for (const docProperty of documentProperties ?? []) {
|
270
297
|
const savedValue = submittedFields[docProperty.id];
|
271
|
-
const originalValue = instance
|
298
|
+
const originalValue = instance?.[docProperty.id];
|
272
299
|
const documentsToRemove = requestSuccess
|
273
|
-
?
|
274
|
-
:
|
300
|
+
? originalValue?.filter((file) => !savedValue?.some((f) => f.id === file.id)) ?? []
|
301
|
+
: savedValue?.filter((file) => !originalValue?.some((f) => f.id === file.id)) ?? [];
|
275
302
|
for (const doc of documentsToRemove) {
|
276
303
|
try {
|
277
|
-
|
304
|
+
await apiServices?.delete(getPrefixedUrl(`/objects/${object?.id}/instances/${instance?.id}/documents/${doc.id}`));
|
278
305
|
}
|
279
306
|
catch (error) {
|
280
|
-
if (
|
307
|
+
if (error.response?.status !== 404) {
|
281
308
|
setSnackbarError({ message: `An error occurred while removing document '${doc.name}'` });
|
282
309
|
}
|
283
310
|
}
|
284
311
|
}
|
285
312
|
}
|
286
|
-
}
|
287
|
-
const saveHandler = (submission, type, setError, setSubmitting) =>
|
288
|
-
var _p;
|
313
|
+
};
|
314
|
+
const saveHandler = async (submission, type, setError, setSubmitting) => {
|
289
315
|
const submittedFields = {};
|
290
316
|
for (const field in submission.data) {
|
291
317
|
const value = submission.data[field];
|
@@ -299,32 +325,32 @@ export function Form(props) {
|
|
299
325
|
//OPTIMIZATION TODO: See if type can be inferred from the event target
|
300
326
|
if (type === 'submit') {
|
301
327
|
if (onSave) {
|
302
|
-
const action =
|
303
|
-
const documentsUploaded =
|
328
|
+
const action = object?.actions?.find((action) => action.id === actionId);
|
329
|
+
const documentsUploaded = await saveDocuments(submittedFields, action);
|
304
330
|
if (documentsUploaded) {
|
305
331
|
try {
|
306
|
-
const { isSuccessful, error } =
|
332
|
+
const { isSuccessful, error } = await onSave(submittedFields, setSubmitting);
|
307
333
|
setError(error);
|
308
334
|
// Delete the documents that were removed if save was successful,
|
309
335
|
// otherwise delete the documents that were uploaded.
|
310
|
-
|
336
|
+
await deleteDocuments(submittedFields, isSuccessful, action);
|
311
337
|
!error && !closeModal && setFormKey(Date.now());
|
312
338
|
}
|
313
339
|
catch (err) {
|
314
340
|
// If the save fails, delete the documents that were just uploaded
|
315
|
-
|
341
|
+
await deleteDocuments(submittedFields, false, action);
|
316
342
|
}
|
317
343
|
}
|
318
344
|
}
|
319
345
|
}
|
320
346
|
else {
|
321
347
|
if (onAutoSave) {
|
322
|
-
const documentsUploaded =
|
348
|
+
const documentsUploaded = await saveDocuments(submittedFields);
|
323
349
|
if (!documentsUploaded) {
|
324
350
|
return;
|
325
351
|
}
|
326
352
|
try {
|
327
|
-
const { isSuccessful, error } =
|
353
|
+
const { isSuccessful, error } = await onAutoSave(submittedFields);
|
328
354
|
// Delete the documents that were removed if save was successful,
|
329
355
|
// otherwise delete the documents that were uploaded.
|
330
356
|
deleteDocuments(submittedFields, isSuccessful);
|
@@ -336,7 +362,7 @@ export function Form(props) {
|
|
336
362
|
}
|
337
363
|
}
|
338
364
|
}
|
339
|
-
}
|
365
|
+
};
|
340
366
|
const BottomButtons = {
|
341
367
|
type: 'Buttons',
|
342
368
|
key: 'cancel-submit',
|
@@ -367,7 +393,7 @@ export function Form(props) {
|
|
367
393
|
key: 'save-draft',
|
368
394
|
variant: 'outlined',
|
369
395
|
isModal: !!closeModal,
|
370
|
-
onClick: (data, setError, setSubmitting) =>
|
396
|
+
onClick: async (data, setError, setSubmitting) => await saveHandler(data, 'draft', setError, setSubmitting),
|
371
397
|
style: { lineHeight: '2.75', margin: '5px', padding: '0 10px' },
|
372
398
|
}
|
373
399
|
: undefined,
|
@@ -408,6 +434,6 @@ export function Form(props) {
|
|
408
434
|
React.createElement(Box, { display: 'flex', width: '100%', justifyContent: 'space-between' },
|
409
435
|
React.createElement(Skeleton, { width: '48%', sx: { borderRadius: '8px', height: '40px' } }),
|
410
436
|
React.createElement(Skeleton, { width: '48%', sx: { borderRadius: '8px', height: '40px' } })))),
|
411
|
-
React.createElement(Snackbar, { open: !!
|
437
|
+
React.createElement(Snackbar, { open: !!snackbarError?.message, handleClose: () => setSnackbarError(undefined), message: snackbarError?.message, error: true })));
|
412
438
|
}
|
413
439
|
export default Form;
|
@@ -16,17 +16,26 @@ const descriptionStyles = {
|
|
16
16
|
const PrefixSuffix = (props) => {
|
17
17
|
const { prefix, suffix, height } = props;
|
18
18
|
const text = prefix || suffix;
|
19
|
-
const prefixSuffixStyles =
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
const prefixSuffixStyles = {
|
20
|
+
display: 'inline-flex',
|
21
|
+
alignItems: 'center',
|
22
|
+
background: '#f5f5f5',
|
23
|
+
padding: '5px',
|
24
|
+
border: '1px solid #ccc',
|
25
|
+
...(suffix && {
|
26
|
+
borderTopRightRadius: '5px',
|
27
|
+
borderBottomRightRadius: '5px',
|
28
|
+
marginLeft: '-5px',
|
29
|
+
paddingLeft: '10px',
|
30
|
+
}),
|
31
|
+
...(prefix && {
|
32
|
+
borderTopLeftRadius: '5px',
|
33
|
+
borderBottomLeftRadius: '5px',
|
34
|
+
marginRight: '-5px',
|
35
|
+
paddingRight: '10px',
|
36
|
+
}),
|
37
|
+
height: height,
|
38
|
+
};
|
30
39
|
if (!prefix && !suffix)
|
31
40
|
return null;
|
32
41
|
return (React.createElement(Box, { sx: prefixSuffixStyles },
|
@@ -1,12 +1,3 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
11
2
|
import { ReactComponent } from '@formio/react';
|
12
3
|
import { groupBy, isEmpty } from 'lodash';
|
@@ -21,12 +12,11 @@ export class ButtonComponent extends ReactComponent {
|
|
21
12
|
constructor(component, options, data) {
|
22
13
|
super(component, options, data);
|
23
14
|
this.getButton = (buttonAction) => {
|
24
|
-
|
25
|
-
return (_a = this.component.components) === null || _a === void 0 ? void 0 : _a.find((button) => button && button.action == buttonAction);
|
15
|
+
return this.component.components?.find((button) => button && button.action == buttonAction);
|
26
16
|
};
|
27
17
|
this.handleCancel = (event) => {
|
28
18
|
const cancelButton = this.getButton('cancel');
|
29
|
-
cancelButton
|
19
|
+
cancelButton?.onClick(event);
|
30
20
|
};
|
31
21
|
this.handleSaveDraft = (setSubmitting) => {
|
32
22
|
setSubmitting(true);
|
@@ -79,17 +69,16 @@ export class ButtonComponent extends ReactComponent {
|
|
79
69
|
setTimeout(() => {
|
80
70
|
const element = document.getElementById(`error-list-${this.root.id}`);
|
81
71
|
submitButton.isModal
|
82
|
-
? element
|
72
|
+
? element?.scrollIntoView({ block: 'nearest' })
|
83
73
|
: this.scrollIntoViewWithOffset(element, 170);
|
84
74
|
}, 0);
|
85
75
|
setSubmitting(false);
|
86
76
|
}
|
87
77
|
};
|
88
78
|
this.scrollIntoViewWithOffset = (el, offset) => {
|
89
|
-
var _a, _b, _c;
|
90
79
|
window.scrollTo({
|
91
80
|
behavior: 'smooth',
|
92
|
-
top:
|
81
|
+
top: el?.getBoundingClientRect()?.top - document?.body?.getBoundingClientRect()?.top - offset,
|
93
82
|
});
|
94
83
|
};
|
95
84
|
this.setButtonKey = (value) => {
|
@@ -103,15 +92,15 @@ export class ButtonComponent extends ReactComponent {
|
|
103
92
|
this.buttonKey = nanoid();
|
104
93
|
}
|
105
94
|
setError(error) {
|
106
|
-
if (
|
95
|
+
if (error?.statusCode === 422) {
|
107
96
|
for (const [key, details] of Object.entries(groupBy(error.details, 'path'))) {
|
108
97
|
this.emit(`error-${key.replace('/', '')}`, details);
|
109
98
|
}
|
110
99
|
setTimeout(() => {
|
111
100
|
const submitButton = this.getButton('submit');
|
112
101
|
const element = document.getElementById(`error-list-${this.root.id}`);
|
113
|
-
|
114
|
-
? element
|
102
|
+
submitButton?.isModal
|
103
|
+
? element?.scrollIntoView({ block: 'nearest' })
|
115
104
|
: this.scrollIntoViewWithOffset(element, 170);
|
116
105
|
}, 100);
|
117
106
|
}
|
@@ -131,7 +120,7 @@ export class ButtonComponent extends ReactComponent {
|
|
131
120
|
const Button = (props) => {
|
132
121
|
const { button, handleSubmit, handleCancel, handleSaveDraft, setButtonKey } = props;
|
133
122
|
const [submitting, setSubmitting] = useState(false);
|
134
|
-
return (React.createElement(LoadingButton, { sx: button.style, variant: button.variant, onClick: (event) =>
|
123
|
+
return (React.createElement(LoadingButton, { sx: button.style, variant: button.variant, onClick: async (event) => {
|
135
124
|
switch (button.action) {
|
136
125
|
case 'submit':
|
137
126
|
handleSubmit(setSubmitting);
|
@@ -146,5 +135,5 @@ const Button = (props) => {
|
|
146
135
|
default:
|
147
136
|
button.onClick();
|
148
137
|
}
|
149
|
-
}
|
138
|
+
}, loading: submitting }, button.label));
|
150
139
|
};
|
@@ -1,12 +1,3 @@
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
-
});
|
9
|
-
};
|
10
1
|
import { isNil } from 'lodash';
|
11
2
|
import React, { useEffect, useState } from 'react';
|
12
3
|
import { useDropzone } from 'react-dropzone';
|
@@ -16,7 +7,6 @@ import { Box, Grid } from '../../../../layout';
|
|
16
7
|
import { getPrefixedUrl } from '../../utils';
|
17
8
|
import { DocumentList } from './DocumentList';
|
18
9
|
export const Document = (props) => {
|
19
|
-
var _a;
|
20
10
|
const { id, handleChange, property, instance, canUpdateProperty, apiServices, error, objectId, value, validate } = props;
|
21
11
|
const [documents, setDocuments] = useState();
|
22
12
|
const [hasUpdatePermission, setHasUpdatePermission] = useState();
|
@@ -25,8 +15,8 @@ export const Document = (props) => {
|
|
25
15
|
setDocuments(value);
|
26
16
|
}, [value]);
|
27
17
|
useEffect(() => {
|
28
|
-
const currentValue = instance
|
29
|
-
if (currentValue
|
18
|
+
const currentValue = instance?.[property.id];
|
19
|
+
if (currentValue?.length) {
|
30
20
|
setDocuments(currentValue);
|
31
21
|
}
|
32
22
|
}, [property]);
|
@@ -40,19 +30,19 @@ export const Document = (props) => {
|
|
40
30
|
.then((accessCheck) => setHasUpdatePermission(accessCheck.result));
|
41
31
|
}
|
42
32
|
};
|
43
|
-
const handleUpload = (files) =>
|
44
|
-
const newDocuments = [...(documents
|
33
|
+
const handleUpload = async (files) => {
|
34
|
+
const newDocuments = [...(documents ?? []), ...(files ?? [])];
|
45
35
|
setDocuments(newDocuments);
|
46
36
|
handleChange(property.id, newDocuments);
|
47
|
-
}
|
48
|
-
const uploadDisabled = !!
|
37
|
+
};
|
38
|
+
const uploadDisabled = !!validate?.maxDocuments && (documents?.length ?? 0) >= validate.maxDocuments;
|
49
39
|
const { getRootProps, getInputProps, open } = useDropzone({
|
50
40
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
51
41
|
onDrop: (files) => handleUpload(files),
|
52
42
|
disabled: uploadDisabled,
|
53
43
|
});
|
54
44
|
return (React.createElement(React.Fragment, null,
|
55
|
-
canUpdateProperty && hasUpdatePermission && (React.createElement(Box,
|
45
|
+
canUpdateProperty && hasUpdatePermission && (React.createElement(Box, { sx: {
|
56
46
|
margin: '5px 0',
|
57
47
|
height: '115px',
|
58
48
|
borderRadius: '8px',
|
@@ -62,8 +52,8 @@ export const Document = (props) => {
|
|
62
52
|
border: `1px dashed ${error ? 'red' : uploadDisabled ? '#DFE3E8' : '#858585'}`,
|
63
53
|
position: 'relative',
|
64
54
|
cursor: uploadDisabled ? 'cursor' : 'pointer',
|
65
|
-
}
|
66
|
-
React.createElement("input",
|
55
|
+
}, ...getRootProps(), onClick: open },
|
56
|
+
React.createElement("input", { ...getInputProps({ id }), disabled: uploadDisabled }),
|
67
57
|
React.createElement(Grid, { container: true, sx: { width: '100%' } },
|
68
58
|
React.createElement(Grid, { item: true, xs: 12, sx: { display: 'flex', justifyContent: 'center', paddingBottom: '7px' } },
|
69
59
|
React.createElement(UploadCloud, { sx: { color: uploadDisabled ? '#919EAB' : '#919EAB', width: '50px', height: '30px' } })),
|
@@ -76,5 +66,5 @@ export const Document = (props) => {
|
|
76
66
|
"to upload"))))),
|
77
67
|
canUpdateProperty && isNil(hasUpdatePermission) && (React.createElement(Skeleton, { variant: "rectangular", height: "115px", sx: { margin: '5px 0', borderRadius: '8px' } })),
|
78
68
|
React.createElement(DocumentList, { property: property, instance: instance, objectId: objectId, handleChange: handleChange, value: value, apiServices: apiServices, setSnackbarError: (type, message) => setSnackbarError({ message, type }), canUpdateProperty: canUpdateProperty && !!hasUpdatePermission }),
|
79
|
-
React.createElement(Snackbar, { open: !!
|
69
|
+
React.createElement(Snackbar, { open: !!snackbarError?.message, handleClose: () => setSnackbarError(null), message: snackbarError?.message, error: snackbarError?.type === 'error' })));
|
80
70
|
};
|