@evoke-platform/ui-components 1.0.0-dev.216 → 1.0.0-dev.218
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/LICENSE +1 -1
- package/colors.ts +1 -1
- 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/Accordion/index.d.ts +2 -2
- package/dist/published/components/core/Accordion/index.js +2 -2
- package/dist/published/components/core/Alert/Alert.js +3 -3
- 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.d.ts +2 -2
- package/dist/published/components/core/Autocomplete/Autocomplete.js +2 -2
- package/dist/published/components/core/Autocomplete/Autocomplete.test.js +1 -1
- package/dist/published/components/core/Avatar/Avatar.js +1 -1
- 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 +3 -3
- package/dist/published/components/core/DateTimePicker/DateTimePicker.js +3 -3
- package/dist/published/components/core/Dialog/Dialog.js +1 -1
- package/dist/published/components/core/Dialog/DialogActions/DialogActions.d.ts +2 -2
- package/dist/published/components/core/Dialog/DialogActions/DialogActions.js +1 -1
- 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/Dialog/index.d.ts +2 -2
- package/dist/published/components/core/Dialog/index.js +2 -2
- 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 +2 -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/FormElements/index.d.ts +3 -3
- package/dist/published/components/core/FormElements/index.js +3 -3
- 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 +4 -4
- 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/Menu/index.d.ts +1 -1
- package/dist/published/components/core/Menu/index.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 +1 -1
- package/dist/published/components/core/Skeleton/Skeleton.js +1 -1
- package/dist/published/components/core/Snackbar/Snackbar.d.ts +2 -2
- package/dist/published/components/core/Snackbar/Snackbar.js +1 -1
- package/dist/published/components/core/StaticDatePicker/StaticDatePicker.js +2 -2
- 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/Stepper/index.d.ts +5 -5
- package/dist/published/components/core/Stepper/index.js +5 -5
- 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/Tabs/index.d.ts +2 -2
- package/dist/published/components/core/Tabs/index.js +2 -2
- package/dist/published/components/core/TextField/TextField.js +1 -1
- package/dist/published/components/core/TextField/TextField.test.js +1 -1
- 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 +1 -1
- package/dist/published/components/core/Typography/index.js +1 -1
- package/dist/published/components/core/index.d.ts +23 -23
- package/dist/published/components/core/index.js +22 -22
- package/dist/published/components/custom/BuilderGrid/BuilderGrid.d.ts +3 -3
- package/dist/published/components/custom/BuilderGrid/BuilderGrid.js +1 -1
- package/dist/published/components/custom/BuilderGrid/BuilderGridToolbar.d.ts +2 -2
- package/dist/published/components/custom/BuilderGrid/ToolbarActions.d.ts +2 -2
- package/dist/published/components/custom/CriteriaBuilder/CriteriaBuilder.d.ts +3 -3
- package/dist/published/components/custom/CriteriaBuilder/CriteriaBuilder.js +2 -2
- package/dist/published/components/custom/CriteriaBuilder/ValueEditor.d.ts +1 -1
- package/dist/published/components/custom/CriteriaBuilder/ValueEditor.js +3 -3
- package/dist/published/components/custom/DataGrid/DataGrid.d.ts +1 -1
- package/dist/published/components/custom/DataGrid/DataGrid.js +4 -5
- package/dist/published/components/custom/DataGrid/DateTimeCustomOperator.js +1 -1
- package/dist/published/components/custom/DataGrid/Toolbar.d.ts +1 -1
- package/dist/published/components/custom/DataGrid/Toolbar.js +3 -3
- package/dist/published/components/custom/ErrorComponent/ErrorComponent.d.ts +2 -2
- package/dist/published/components/custom/ErrorComponent/ErrorComponent.js +2 -2
- package/dist/published/components/custom/Form/Common/Form.d.ts +38 -0
- package/dist/published/components/custom/Form/Common/Form.js +413 -0
- package/dist/published/components/custom/Form/Common/FormComponentWrapper.d.ts +26 -0
- package/dist/published/components/custom/Form/Common/FormComponentWrapper.js +79 -0
- package/dist/published/components/custom/Form/Common/index.d.ts +2 -0
- package/dist/published/components/custom/Form/Common/index.js +2 -0
- package/dist/published/components/custom/Form/FormComponents/ButtonComponent.d.ts +37 -0
- package/dist/published/components/custom/Form/FormComponents/ButtonComponent.js +150 -0
- package/dist/published/components/custom/Form/FormComponents/DocumentComponent/Document.d.ts +17 -0
- package/dist/published/components/custom/Form/FormComponents/DocumentComponent/Document.js +80 -0
- package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentComponent.d.ts +23 -0
- package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentComponent.js +154 -0
- package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentList.d.ts +15 -0
- package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentList.js +172 -0
- package/dist/published/components/custom/Form/FormComponents/FormFieldComponent.d.ts +41 -0
- package/dist/published/components/custom/Form/FormComponents/FormFieldComponent.js +409 -0
- package/dist/published/components/custom/Form/FormComponents/ImageComponent/Image.d.ts +15 -0
- package/dist/published/components/custom/Form/FormComponents/ImageComponent/Image.js +111 -0
- package/dist/published/components/custom/Form/FormComponents/ImageComponent/ImageComponent.d.ts +23 -0
- package/dist/published/components/custom/Form/FormComponents/ImageComponent/ImageComponent.js +112 -0
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/InstanceLookup.d.ts +20 -0
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/InstanceLookup.js +229 -0
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectComponent.d.ts +34 -0
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectComponent.js +150 -0
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectPropertyInput.d.ts +3 -0
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectPropertyInput.js +306 -0
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/RelatedObjectInstance.d.ts +24 -0
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/RelatedObjectInstance.js +126 -0
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ActionDialog.d.ts +21 -0
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ActionDialog.js +96 -0
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ManyToMany/DropdownRepeatableField.d.ts +15 -0
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ManyToMany/DropdownRepeatableField.js +158 -0
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ManyToMany/DropdownRepeatableFieldInput.d.ts +39 -0
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ManyToMany/DropdownRepeatableFieldInput.js +89 -0
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableField.d.ts +12 -0
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableField.js +369 -0
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableFieldComponent.d.ts +20 -0
- package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableFieldComponent.js +57 -0
- package/dist/published/components/custom/Form/FormComponents/UserComponent/UserComponent.d.ts +26 -0
- package/dist/published/components/custom/Form/FormComponents/UserComponent/UserComponent.js +99 -0
- package/dist/published/components/custom/Form/FormComponents/UserComponent/UserProperty.d.ts +23 -0
- package/dist/published/components/custom/Form/FormComponents/UserComponent/UserProperty.js +115 -0
- package/dist/published/components/custom/Form/FormComponents/ViewOnlyComponent.d.ts +20 -0
- package/dist/published/components/custom/Form/FormComponents/ViewOnlyComponent.js +83 -0
- package/dist/published/components/custom/Form/FormComponents/index.d.ts +8 -0
- package/dist/published/components/custom/Form/FormComponents/index.js +8 -0
- package/dist/published/components/custom/Form/index.d.ts +3 -0
- package/dist/published/components/custom/Form/index.js +3 -0
- package/dist/published/components/custom/Form/types.d.ts +109 -0
- package/dist/published/components/custom/Form/types.js +1 -0
- package/dist/published/components/custom/Form/utils.d.ts +45 -0
- package/dist/published/components/custom/Form/utils.js +1036 -0
- package/dist/published/components/custom/FormField/AddressFieldComponent/AddressFieldComponent.test.js +1 -1
- package/dist/published/components/custom/FormField/AddressFieldComponent/addressFieldComponent.js +1 -1
- package/dist/published/components/custom/FormField/BooleanSelect/BooleanSelect.test.js +1 -1
- package/dist/published/components/custom/FormField/DatePickerSelect/DatePickerSelect.test.js +3 -3
- package/dist/published/components/custom/FormField/DateTimePickerSelect/DateTimePickerSelect.js +2 -2
- package/dist/published/components/custom/FormField/DateTimePickerSelect/DateTimePickerSelect.test.js +4 -4
- package/dist/published/components/custom/FormField/FormField.d.ts +4 -4
- package/dist/published/components/custom/FormField/FormField.js +1 -1
- package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.js +1 -1
- package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.test.js +1 -1
- package/dist/published/components/custom/FormField/Select/Select.test.js +1 -1
- package/dist/published/components/custom/FormField/TimePickerSelect/TimePickerSelect.js +4 -4
- package/dist/published/components/custom/Menubar/Menubar.js +1 -1
- package/dist/published/components/custom/Menubar/Menubar.test.js +2 -2
- package/dist/published/components/custom/MultiSelect/MultiSelect.js +7 -7
- package/dist/published/components/custom/MultiSelect/SortableItem.js +2 -2
- package/dist/published/components/custom/RepeatableField/RepeatableField.js +4 -4
- package/dist/published/components/custom/index.d.ts +1 -0
- package/dist/published/components/custom/index.js +1 -0
- package/dist/published/components/custom/util.js +1 -1
- package/dist/published/components/layout/Box/Box.d.ts +2 -2
- 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/TrashCan.d.ts +1 -1
- package/dist/published/icons/custom/TrashCan.js +1 -1
- package/dist/published/icons/custom/index.d.ts +1 -1
- package/dist/published/icons/custom/index.js +1 -1
- package/dist/published/index.d.ts +3 -3
- package/dist/published/index.js +2 -2
- package/dist/published/stories/Accordion.stories.d.ts +1 -1
- package/dist/published/stories/Accordion.stories.js +2 -2
- package/dist/published/stories/Alert.stories.d.ts +1 -1
- package/dist/published/stories/AlertTitle.stories.d.ts +1 -1
- package/dist/published/stories/Appbar.stories.d.ts +1 -1
- package/dist/published/stories/Appbar.stories.js +2 -2
- package/dist/published/stories/Autocomplete.stories.d.ts +1 -1
- package/dist/published/stories/Autocomplete.stories.js +3 -3
- package/dist/published/stories/Avatar.stories.d.ts +1 -1
- package/dist/published/stories/Backdrop.stories.d.ts +1 -1
- package/dist/published/stories/Backdrop.stories.js +3 -3
- package/dist/published/stories/Badge.stories.d.ts +1 -1
- package/dist/published/stories/Badge.stories.js +1 -1
- package/dist/published/stories/Box.stories.d.ts +1 -1
- package/dist/published/stories/Breadcrumbs.stories.d.ts +1 -1
- package/dist/published/stories/Button.stories.d.ts +1 -1
- package/dist/published/stories/ButtonGroup.stories.d.ts +1 -1
- package/dist/published/stories/Card.stories.d.ts +1 -1
- package/dist/published/stories/Card.stories.js +1 -1
- package/dist/published/stories/Checkbox.stories.d.ts +1 -1
- package/dist/published/stories/Chip.stories.d.ts +1 -1
- package/dist/published/stories/CircularProgress.stories.d.ts +1 -1
- package/dist/published/stories/Collapse.stories.d.ts +1 -1
- package/dist/published/stories/Collapse.stories.js +1 -1
- package/dist/published/stories/Container.stories.d.ts +1 -1
- package/dist/published/stories/Container.stories.js +3 -3
- package/dist/published/stories/DataGrid.stories.d.ts +1 -1
- package/dist/published/stories/DataGrid.stories.js +1 -1
- package/dist/published/stories/DatePicker.stories.d.ts +1 -1
- package/dist/published/stories/Dialog.stories.d.ts +1 -1
- package/dist/published/stories/Dialog.stories.js +3 -3
- package/dist/published/stories/Divider.stories.d.ts +1 -1
- package/dist/published/stories/Drawer.stories.d.ts +1 -1
- package/dist/published/stories/Drawer.stories.js +4 -4
- package/dist/published/stories/FormControl.stories.d.ts +1 -1
- package/dist/published/stories/FormControl.stories.js +1 -1
- package/dist/published/stories/FormControlLabel.stories.d.ts +1 -1
- package/dist/published/stories/FormGroup.stories.d.ts +1 -1
- package/dist/published/stories/FormHelperText.stories.d.ts +1 -1
- package/dist/published/stories/FormLabel.stories.d.ts +1 -1
- package/dist/published/stories/FormLabel.stories.js +2 -2
- package/dist/published/stories/Grid.stories.d.ts +1 -1
- package/dist/published/stories/IconButton.stories.d.ts +1 -1
- package/dist/published/stories/IconButton.stories.js +1 -1
- package/dist/published/stories/LinearProgress.stories.d.ts +1 -1
- package/dist/published/stories/Link.stories.d.ts +1 -1
- package/dist/published/stories/List.stories.d.ts +1 -1
- package/dist/published/stories/List.stories.js +3 -3
- package/dist/published/stories/Menu.stories.d.ts +1 -1
- package/dist/published/stories/Menu.stories.js +3 -3
- package/dist/published/stories/MenuBar.stories.d.ts +1 -1
- package/dist/published/stories/MenuBar.stories.js +1 -1
- package/dist/published/stories/MultiSelect.stories.d.ts +1 -1
- package/dist/published/stories/MultiSelect.stories.js +1 -1
- package/dist/published/stories/Palette.stories.d.ts +1 -1
- package/dist/published/stories/Palette.stories.js +1 -1
- package/dist/published/stories/Paper.stories.d.ts +1 -1
- package/dist/published/stories/Paper.stories.js +1 -1
- package/dist/published/stories/RadioGroup.stories.d.ts +1 -1
- package/dist/published/stories/RadioGroup.stories.js +1 -1
- package/dist/published/stories/RepeatableField.stories.d.ts +1 -1
- package/dist/published/stories/RepeatableField.stories.js +1 -1
- package/dist/published/stories/Skeleton.stories.d.ts +1 -1
- package/dist/published/stories/Snackbar.stories.d.ts +1 -1
- package/dist/published/stories/Snackbar.stories.js +3 -3
- package/dist/published/stories/Stack.stories.d.ts +1 -1
- package/dist/published/stories/StaticDatePicker.stories.d.ts +1 -1
- package/dist/published/stories/Stepper.stories.d.ts +2 -2
- package/dist/published/stories/Stepper.stories.js +6 -6
- package/dist/published/stories/Switch.stories.d.ts +1 -1
- package/dist/published/stories/Table.stories.d.ts +1 -1
- package/dist/published/stories/Table.stories.js +1 -1
- package/dist/published/stories/Tabs.stories.d.ts +1 -1
- package/dist/published/stories/TextField.stories.d.ts +1 -1
- package/dist/published/stories/TimePicker.stories.d.ts +1 -1
- package/dist/published/stories/TimePicker.stories.js +1 -1
- package/dist/published/stories/TimePickerSelect.stories.d.ts +1 -1
- package/dist/published/stories/ToggleButton.stories.d.ts +1 -1
- package/dist/published/stories/ToggleButton.stories.js +3 -3
- package/dist/published/stories/Typography.stories.d.ts +1 -1
- package/dist/published/stories/Typography.stories.js +1 -1
- package/dist/published/styles/form-component.css +152 -0
- package/dist/published/theme/UIThemeProvider.d.ts +2 -2
- package/dist/published/theme/UIThemeProvider.js +1 -1
- package/dist/published/util/date.d.ts +1 -1
- package/dist/published/util/date.js +1 -1
- package/icons.ts +1 -1
- package/package.json +21 -7
@@ -0,0 +1,1036 @@
|
|
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
|
+
import { camelCase, get, isArray, isEmpty, isNil, isObject, isUndefined, pick, startCase, transform, uniq, } from 'lodash';
|
11
|
+
import { DateTime } from 'luxon';
|
12
|
+
import { nanoid } from 'nanoid';
|
13
|
+
// The following functions are used to build the FormIO form components from the form parameters.
|
14
|
+
export function determineComponentType(properties, parameter) {
|
15
|
+
if (!parameter)
|
16
|
+
return;
|
17
|
+
switch (parameter.type) {
|
18
|
+
case 'string': {
|
19
|
+
if (parameter.enum)
|
20
|
+
return 'Select';
|
21
|
+
return 'TextField';
|
22
|
+
}
|
23
|
+
case 'date-time':
|
24
|
+
return 'DateTime';
|
25
|
+
case 'collection': {
|
26
|
+
const property = properties.find((property) => property.id === parameter.id);
|
27
|
+
if (!property)
|
28
|
+
return undefined;
|
29
|
+
return (property === null || property === void 0 ? void 0 : property.manyToManyPropertyId) ? 'ManyToManyRepeatableField' : 'RepeatableField';
|
30
|
+
}
|
31
|
+
case 'document':
|
32
|
+
return 'Document';
|
33
|
+
case 'array':
|
34
|
+
return 'MultiSelect';
|
35
|
+
case 'number':
|
36
|
+
return 'Decimal';
|
37
|
+
case 'richText':
|
38
|
+
return 'RichText';
|
39
|
+
case 'date':
|
40
|
+
case 'integer':
|
41
|
+
case 'image':
|
42
|
+
case 'object':
|
43
|
+
case 'time':
|
44
|
+
case 'user':
|
45
|
+
case 'boolean':
|
46
|
+
return startCase(parameter.type);
|
47
|
+
default:
|
48
|
+
return 'TextField';
|
49
|
+
}
|
50
|
+
}
|
51
|
+
export function determineParameterType(componentType) {
|
52
|
+
switch (componentType) {
|
53
|
+
case 'Select':
|
54
|
+
case 'Content':
|
55
|
+
case 'TextField':
|
56
|
+
return 'string';
|
57
|
+
case 'DateTime':
|
58
|
+
return 'date-time';
|
59
|
+
case 'RepeatableField':
|
60
|
+
return 'collection';
|
61
|
+
case 'MultiSelect':
|
62
|
+
return 'array';
|
63
|
+
case 'Decimal':
|
64
|
+
return 'number';
|
65
|
+
case 'RichText':
|
66
|
+
return 'richText';
|
67
|
+
case 'ManyToManyRepeatableField':
|
68
|
+
return 'collection';
|
69
|
+
default:
|
70
|
+
return camelCase(componentType);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
export function getFlattenEntries(entries) {
|
74
|
+
return entries.reduce((acc, entry) => {
|
75
|
+
if (entry.type === 'sections') {
|
76
|
+
const subEntries = entry.sections.flatMap((s) => { var _a; return (_a = s.entries) !== null && _a !== void 0 ? _a : []; });
|
77
|
+
return acc.concat(getFlattenEntries(subEntries !== null && subEntries !== void 0 ? subEntries : []));
|
78
|
+
}
|
79
|
+
else if (entry.type === 'columns') {
|
80
|
+
const subEntries = entry.columns.flatMap((c) => { var _a; return (_a = c.entries) !== null && _a !== void 0 ? _a : []; });
|
81
|
+
return acc.concat(getFlattenEntries(subEntries !== null && subEntries !== void 0 ? subEntries : []));
|
82
|
+
}
|
83
|
+
else if (entry.type === 'content') {
|
84
|
+
return acc;
|
85
|
+
}
|
86
|
+
else {
|
87
|
+
return acc.concat([entry]);
|
88
|
+
}
|
89
|
+
}, []);
|
90
|
+
}
|
91
|
+
export function convertFormToComponents(entries, parameters, object) {
|
92
|
+
return entries
|
93
|
+
.map((entry) => {
|
94
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17;
|
95
|
+
if (entry.type === 'sections') {
|
96
|
+
return {
|
97
|
+
type: 'Section',
|
98
|
+
key: nanoid(),
|
99
|
+
verticalLayout: true,
|
100
|
+
label: 'Section',
|
101
|
+
components: entry.sections.map((section) => {
|
102
|
+
var _a;
|
103
|
+
return ({
|
104
|
+
key: nanoid(),
|
105
|
+
label: section.label,
|
106
|
+
components: ((_a = section.entries) === null || _a === void 0 ? void 0 : _a.length)
|
107
|
+
? convertFormToComponents(section.entries, parameters, object)
|
108
|
+
: [],
|
109
|
+
});
|
110
|
+
}),
|
111
|
+
conditional: typeof entry.visibility !== 'string' && ((_b = (_a = entry.visibility) === null || _a === void 0 ? void 0 : _a.conditions) === null || _b === void 0 ? void 0 : _b.length)
|
112
|
+
? {
|
113
|
+
show: entry.visibility.conditions[0].operator === 'eq',
|
114
|
+
when: entry.visibility.conditions[0].property,
|
115
|
+
eq: entry.visibility.conditions[0].value,
|
116
|
+
}
|
117
|
+
: {
|
118
|
+
json: entry.visibility,
|
119
|
+
},
|
120
|
+
};
|
121
|
+
}
|
122
|
+
else if (entry.type === 'columns') {
|
123
|
+
return {
|
124
|
+
type: 'Columns',
|
125
|
+
key: nanoid(),
|
126
|
+
label: 'Columns',
|
127
|
+
columns: entry.columns.map((column) => {
|
128
|
+
var _a;
|
129
|
+
return (Object.assign(Object.assign({}, column), { size: 'md', currentWidth: column.width, components: ((_a = column.entries) === null || _a === void 0 ? void 0 : _a.length)
|
130
|
+
? convertFormToComponents(column.entries, parameters, object)
|
131
|
+
: [] }));
|
132
|
+
}),
|
133
|
+
conditional: typeof entry.visibility !== 'string' && ((_d = (_c = entry.visibility) === null || _c === void 0 ? void 0 : _c.conditions) === null || _d === void 0 ? void 0 : _d.length)
|
134
|
+
? {
|
135
|
+
show: entry.visibility.conditions[0].operator === 'eq',
|
136
|
+
when: entry.visibility.conditions[0].property,
|
137
|
+
eq: entry.visibility.conditions[0].value,
|
138
|
+
}
|
139
|
+
: {
|
140
|
+
json: entry.visibility,
|
141
|
+
},
|
142
|
+
};
|
143
|
+
}
|
144
|
+
else if (entry.type === 'content') {
|
145
|
+
return {
|
146
|
+
type: 'Content',
|
147
|
+
key: nanoid(),
|
148
|
+
html: entry.html,
|
149
|
+
conditional: typeof entry.visibility !== 'string' && ((_f = (_e = entry.visibility) === null || _e === void 0 ? void 0 : _e.conditions) === null || _f === void 0 ? void 0 : _f.length)
|
150
|
+
? {
|
151
|
+
show: entry.visibility.conditions[0].operator === 'eq',
|
152
|
+
when: entry.visibility.conditions[0].property,
|
153
|
+
eq: entry.visibility.conditions[0].value,
|
154
|
+
}
|
155
|
+
: {
|
156
|
+
json: entry.visibility,
|
157
|
+
},
|
158
|
+
};
|
159
|
+
}
|
160
|
+
else {
|
161
|
+
const displayOptions = entry.display;
|
162
|
+
const parameter = parameters.find((parameter) => parameter.id === entry.parameterId);
|
163
|
+
if (!parameter) {
|
164
|
+
return;
|
165
|
+
}
|
166
|
+
let property = (_h = (_g = object.properties) === null || _g === void 0 ? void 0 : _g.find((p) => p.id === entry.parameterId)) !== null && _h !== void 0 ? _h : {
|
167
|
+
id: entry.parameterId,
|
168
|
+
};
|
169
|
+
if ((_j = property.id) === null || _j === void 0 ? void 0 : _j.includes('.')) {
|
170
|
+
const topLevelProperty = (_k = object.properties) === null || _k === void 0 ? void 0 : _k.find((p) => { var _a; return p.id === ((_a = property.id) === null || _a === void 0 ? void 0 : _a.split('.')[0]) && (p.type === 'address' || p.type === 'user'); });
|
171
|
+
property = {
|
172
|
+
id: property.id,
|
173
|
+
name: (topLevelProperty === null || topLevelProperty === void 0 ? void 0 : topLevelProperty.name)
|
174
|
+
? `${topLevelProperty.name} ${startCase(property.id.split('.')[1])}`
|
175
|
+
: startCase(property.id.split('.')[1]),
|
176
|
+
};
|
177
|
+
}
|
178
|
+
const type = determineComponentType((_l = object.properties) !== null && _l !== void 0 ? _l : [], parameter);
|
179
|
+
if (!type) {
|
180
|
+
return;
|
181
|
+
}
|
182
|
+
return Object.assign(Object.assign({}, pick(displayOptions, 'label', 'description', 'tooltip', 'prefix', 'suffix', 'readOnly', 'mode')), { initialValue: type === 'Select'
|
183
|
+
? (_m = entry.enumWithLabels) === null || _m === void 0 ? void 0 : _m.find((c) => c.value === (displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.defaultValue))
|
184
|
+
: type === 'MultiSelect' && isArray(displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.defaultValue)
|
185
|
+
? (_o = entry.enumWithLabels) === null || _o === void 0 ? void 0 : _o.filter((c) => (displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.defaultValue).includes(c.value))
|
186
|
+
: type !== 'Object'
|
187
|
+
? displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.defaultValue
|
188
|
+
: undefined, isMultiLineText: parameter.type === 'string' && (displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.rowCount) ? true : false, rows: displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.rowCount, key: parameter.id, type, multiple: ['array', 'document'].includes(parameter.type), data: {
|
189
|
+
values: entry.enumWithLabels,
|
190
|
+
}, property: property, defaultToCurrentTime: (displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.defaultValue) === 'currentTime' && parameter.type === 'time' ? true : false, defaultToCurrentDate: (displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.defaultValue) === 'currentDate' && parameter.type === 'date' ? true : false, defaultValueCriteria: parameter.type === 'object' && (displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.defaultValue)
|
191
|
+
? displayOptions.defaultValue.criteria
|
192
|
+
: undefined, sortBy: parameter.type === 'object' && (displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.defaultValue)
|
193
|
+
? (_p = displayOptions.defaultValue) === null || _p === void 0 ? void 0 : _p.sortBy
|
194
|
+
: undefined, orderBy: parameter.type === 'object' &&
|
195
|
+
((_q = displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.defaultValue) === null || _q === void 0 ? void 0 : _q.orderBy)
|
196
|
+
? (_r = displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.defaultValue) === null || _r === void 0 ? void 0 : _r.orderBy
|
197
|
+
: undefined, inputMask: parameter.type === 'string' ? (_s = parameter.validation) === null || _s === void 0 ? void 0 : _s.mask : undefined, inputMaskPlacholderChar: displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.placeholderChar, placeholder: displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.placeholder, tableView: false, displayOption: parameter.type === 'object' ? displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.relatedObjectDisplay : undefined, labelPosition: 'top', dataSrc: ((_t = property.enum) === null || _t === void 0 ? void 0 : _t.length) ? 'values' : undefined, showCharCount: displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.charCount, objectId: object.id, validate: {
|
198
|
+
required: displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.required,
|
199
|
+
criteria: ['collection', 'object'].includes((_u = parameter.type) !== null && _u !== void 0 ? _u : '')
|
200
|
+
? (_v = parameter.validation) === null || _v === void 0 ? void 0 : _v.criteria
|
201
|
+
: undefined,
|
202
|
+
regexes: parameter.type === 'string'
|
203
|
+
? (_x = (_w = parameter.validation) === null || _w === void 0 ? void 0 : _w.rules) === null || _x === void 0 ? void 0 : _x.map((rule) => {
|
204
|
+
var _a;
|
205
|
+
return (Object.assign(Object.assign({}, rule), { errorMessage: (_a = rule.errorMessage) !== null && _a !== void 0 ? _a : 'Property is not in a valid format' }));
|
206
|
+
})
|
207
|
+
: [],
|
208
|
+
operator: (_z = (_y = parameter.validation) === null || _y === void 0 ? void 0 : _y.operator) !== null && _z !== void 0 ? _z : 'any',
|
209
|
+
minLength: parameter.type === 'string'
|
210
|
+
? (_0 = parameter.validation) === null || _0 === void 0 ? void 0 : _0.minLength
|
211
|
+
: undefined,
|
212
|
+
maxLength: parameter.type === 'string'
|
213
|
+
? (_1 = parameter.validation) === null || _1 === void 0 ? void 0 : _1.maxLength
|
214
|
+
: undefined,
|
215
|
+
minDate: parameter.type === 'date' ? (_2 = parameter.validation) === null || _2 === void 0 ? void 0 : _2.from : undefined,
|
216
|
+
maxDate: parameter.type === 'date' ? (_3 = parameter.validation) === null || _3 === void 0 ? void 0 : _3.to : undefined,
|
217
|
+
minTime: parameter.type === 'time' ? (_4 = parameter.validation) === null || _4 === void 0 ? void 0 : _4.from : undefined,
|
218
|
+
maxTime: parameter.type === 'time' ? (_5 = parameter.validation) === null || _5 === void 0 ? void 0 : _5.to : undefined,
|
219
|
+
min: ['integer', 'number'].includes((_6 = parameter.type) !== null && _6 !== void 0 ? _6 : '')
|
220
|
+
? (_7 = parameter.validation) === null || _7 === void 0 ? void 0 : _7.minimum
|
221
|
+
: undefined,
|
222
|
+
max: ['integer', 'number'].includes((_8 = parameter.type) !== null && _8 !== void 0 ? _8 : '')
|
223
|
+
? (_9 = parameter.validation) === null || _9 === void 0 ? void 0 : _9.maximum
|
224
|
+
: undefined,
|
225
|
+
minDocuments: parameter.type === 'document'
|
226
|
+
? (_10 = parameter.validation) === null || _10 === void 0 ? void 0 : _10.minDocuments
|
227
|
+
: undefined,
|
228
|
+
maxDocuments: parameter.type === 'document'
|
229
|
+
? (_11 = parameter.validation) === null || _11 === void 0 ? void 0 : _11.maxDocuments
|
230
|
+
: undefined,
|
231
|
+
customMessage: ['integer', 'number', 'date', 'time', 'document'].includes((_12 = parameter.type) !== null && _12 !== void 0 ? _12 : '')
|
232
|
+
? (_13 = parameter.validation) === null || _13 === void 0 ? void 0 : _13.errorMessage
|
233
|
+
: '',
|
234
|
+
}, id: nanoid(7), isAddressLine1: ((_14 = property.id) === null || _14 === void 0 ? void 0 : _14.split('.')[1]) === 'line1' ? true : false, addressPropertyId: ((_15 = property.id) === null || _15 === void 0 ? void 0 : _15.split('.')[1]) === 'line1' ? (_16 = property.id) === null || _16 === void 0 ? void 0 : _16.split('.')[0] : undefined, input: true, widget: (parameter.type === 'string' && parameter.enum) || parameter.type === 'array'
|
235
|
+
? 'choicejs'
|
236
|
+
: undefined, conditional: (displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.visibility) &&
|
237
|
+
typeof (displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.visibility) !== 'string' &&
|
238
|
+
((_17 = displayOptions.visibility.conditions) === null || _17 === void 0 ? void 0 : _17.length)
|
239
|
+
? {
|
240
|
+
show: (displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.visibility.conditions[0].operator) === 'eq',
|
241
|
+
when: displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.visibility.conditions[0].property,
|
242
|
+
eq: displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.visibility.conditions[0].value,
|
243
|
+
}
|
244
|
+
: {
|
245
|
+
json: displayOptions === null || displayOptions === void 0 ? void 0 : displayOptions.visibility,
|
246
|
+
} });
|
247
|
+
}
|
248
|
+
})
|
249
|
+
.filter((item) => item);
|
250
|
+
}
|
251
|
+
export function convertComponentsToForm(components) {
|
252
|
+
return components.map((component) => {
|
253
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
254
|
+
if (component.type === 'Section') {
|
255
|
+
return Object.assign({ type: 'sections', label: component.label, sections: (_a = component.components) === null || _a === void 0 ? void 0 : _a.map((section) => {
|
256
|
+
var _a;
|
257
|
+
return ({
|
258
|
+
key: nanoid(),
|
259
|
+
label: section.label,
|
260
|
+
entries: ((_a = section.components) === null || _a === void 0 ? void 0 : _a.length) ? convertComponentsToForm(section.components) : [],
|
261
|
+
});
|
262
|
+
}) }, (((_b = component.conditional) === null || _b === void 0 ? void 0 : _b.json) ||
|
263
|
+
(((_c = component.conditional) === null || _c === void 0 ? void 0 : _c.when) && !isUndefined((_d = component.conditional) === null || _d === void 0 ? void 0 : _d.show) && ((_e = component.conditional) === null || _e === void 0 ? void 0 : _e.eq))
|
264
|
+
? {
|
265
|
+
visibility: component.conditional.json
|
266
|
+
? component.conditional.json
|
267
|
+
: {
|
268
|
+
operator: 'all',
|
269
|
+
conditions: [
|
270
|
+
{
|
271
|
+
property: component.conditional.when,
|
272
|
+
operator: component.conditional.show ? 'eq' : 'ne',
|
273
|
+
value: component.conditional.eq,
|
274
|
+
},
|
275
|
+
],
|
276
|
+
},
|
277
|
+
}
|
278
|
+
: {}));
|
279
|
+
}
|
280
|
+
else if (component.type === 'Columns') {
|
281
|
+
return Object.assign({ type: 'columns', label: component.label, columns: (_f = component.columns) === null || _f === void 0 ? void 0 : _f.map((column) => {
|
282
|
+
var _a;
|
283
|
+
return ({
|
284
|
+
width: column.width,
|
285
|
+
entries: ((_a = column.components) === null || _a === void 0 ? void 0 : _a.length) ? convertComponentsToForm(column.components) : [],
|
286
|
+
});
|
287
|
+
}) }, (((_g = component.conditional) === null || _g === void 0 ? void 0 : _g.json) ||
|
288
|
+
(((_h = component.conditional) === null || _h === void 0 ? void 0 : _h.when) && !isUndefined((_j = component.conditional) === null || _j === void 0 ? void 0 : _j.show) && ((_k = component.conditional) === null || _k === void 0 ? void 0 : _k.eq))
|
289
|
+
? {
|
290
|
+
visibility: component.conditional.json
|
291
|
+
? component.conditional.json
|
292
|
+
: {
|
293
|
+
operator: 'all',
|
294
|
+
conditions: [
|
295
|
+
{
|
296
|
+
property: component.conditional.when,
|
297
|
+
operator: component.conditional.show ? 'eq' : 'ne',
|
298
|
+
value: component.conditional.eq,
|
299
|
+
},
|
300
|
+
],
|
301
|
+
},
|
302
|
+
}
|
303
|
+
: {}));
|
304
|
+
}
|
305
|
+
else if (component.type === 'Content') {
|
306
|
+
return Object.assign({ type: 'content', html: (_l = component.html) !== null && _l !== void 0 ? _l : '' }, (((_m = component.conditional) === null || _m === void 0 ? void 0 : _m.json) ||
|
307
|
+
(((_o = component.conditional) === null || _o === void 0 ? void 0 : _o.when) && !isUndefined((_p = component.conditional) === null || _p === void 0 ? void 0 : _p.show) && ((_q = component.conditional) === null || _q === void 0 ? void 0 : _q.eq))
|
308
|
+
? {
|
309
|
+
visibility: component.conditional.json
|
310
|
+
? component.conditional.json
|
311
|
+
: {
|
312
|
+
operator: 'all',
|
313
|
+
conditions: [
|
314
|
+
{
|
315
|
+
property: component.conditional.when,
|
316
|
+
operator: component.conditional.show ? 'eq' : 'ne',
|
317
|
+
value: component.conditional.eq,
|
318
|
+
},
|
319
|
+
],
|
320
|
+
},
|
321
|
+
}
|
322
|
+
: {}));
|
323
|
+
}
|
324
|
+
else {
|
325
|
+
return {
|
326
|
+
type: 'input',
|
327
|
+
parameterId: component.key,
|
328
|
+
display: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (component.label ? { label: component.label } : {})), (component.description ? { description: component.description } : {})), (component.tooltip ? { tooltip: component.tooltip } : {})), (component.placeholder ? { placeholder: component.placeholder } : {})), (component.prefix ? { prefix: component.prefix } : {})), (component.suffix ? { suffix: component.suffix } : {})), (component.readOnly ? { readOnly: component.readOnly } : {})), (component.mode ? { mode: component.mode } : {})), (((_r = component.validate) === null || _r === void 0 ? void 0 : _r.required) ? { required: (_s = component.validate) === null || _s === void 0 ? void 0 : _s.required } : {})), (component.displayOption ? { relatedObjectDisplay: component.displayOption } : {})), (component.defaultToCurrentDate ||
|
329
|
+
component.defaultToCurrentTime ||
|
330
|
+
component.initialValue ||
|
331
|
+
component.defaultValueCriteria
|
332
|
+
? {
|
333
|
+
defaultValue: component.defaultToCurrentDate
|
334
|
+
? 'currentDate'
|
335
|
+
: component.defaultToCurrentTime
|
336
|
+
? 'currentTime'
|
337
|
+
: component.defaultValueCriteria
|
338
|
+
? Object.assign(Object.assign({ criteria: component.defaultValueCriteria }, (component.sortBy ? { sortBy: component.sortBy } : {})), (component.orderBy ? { sortBy: component.orderBy } : {})) : isArray(component.initialValue)
|
339
|
+
? component.initialValue.map((c) => c.value)
|
340
|
+
: ((_t = component.initialValue) === null || _t === void 0 ? void 0 : _t.value)
|
341
|
+
? (_u = component.initialValue) === null || _u === void 0 ? void 0 : _u.value
|
342
|
+
: component.initialValue,
|
343
|
+
}
|
344
|
+
: {})), (component.rows ? { rowCount: component.rows } : {})), (component.inputMaskPlaceholderChar
|
345
|
+
? { placeholderChar: component.inputMaskPlaceholderChar }
|
346
|
+
: {})), (component.showCharCount ? { charCount: true } : {})), (((_v = component.conditional) === null || _v === void 0 ? void 0 : _v.json) ||
|
347
|
+
(((_w = component.conditional) === null || _w === void 0 ? void 0 : _w.when) &&
|
348
|
+
!isUndefined((_x = component.conditional) === null || _x === void 0 ? void 0 : _x.show) &&
|
349
|
+
((_y = component.conditional) === null || _y === void 0 ? void 0 : _y.eq))
|
350
|
+
? {
|
351
|
+
visibility: component.conditional.json
|
352
|
+
? component.conditional.json
|
353
|
+
: {
|
354
|
+
operator: 'all',
|
355
|
+
conditions: [
|
356
|
+
{
|
357
|
+
property: component.conditional.when,
|
358
|
+
operator: component.conditional.show ? 'eq' : 'ne',
|
359
|
+
value: component.conditional.eq,
|
360
|
+
},
|
361
|
+
],
|
362
|
+
},
|
363
|
+
}
|
364
|
+
: {})),
|
365
|
+
enumWithLabels: (_z = component.data) === null || _z === void 0 ? void 0 : _z.values,
|
366
|
+
};
|
367
|
+
}
|
368
|
+
});
|
369
|
+
}
|
370
|
+
// The following functions are used to support the many-to-many relationship collection property.
|
371
|
+
export function getMiddleObjectFilter(property, instance) {
|
372
|
+
const filterProperty = `${property.relatedPropertyId}.id`;
|
373
|
+
const filter = { where: { [filterProperty]: instance === null || instance === void 0 ? void 0 : instance.id } };
|
374
|
+
return filter;
|
375
|
+
}
|
376
|
+
export function getMiddleObject(instance, property, endObjectId, endObjectName) {
|
377
|
+
if (property.relatedPropertyId && property.manyToManyPropertyId) {
|
378
|
+
const middleObject = {
|
379
|
+
[property.relatedPropertyId]: {
|
380
|
+
id: instance.id,
|
381
|
+
name: instance.name,
|
382
|
+
},
|
383
|
+
[property.manyToManyPropertyId]: {
|
384
|
+
id: endObjectId,
|
385
|
+
name: endObjectName,
|
386
|
+
},
|
387
|
+
};
|
388
|
+
return middleObject;
|
389
|
+
}
|
390
|
+
}
|
391
|
+
export function getMiddleInstance(instanceId, property, middleObjectInstances) {
|
392
|
+
return middleObjectInstances.find((o) => { var _a; return property.manyToManyPropertyId && ((_a = o[property.manyToManyPropertyId]) === null || _a === void 0 ? void 0 : _a.id) === instanceId; });
|
393
|
+
}
|
394
|
+
// The following function is used to prefix the URL with the appropriate path.
|
395
|
+
export function getPrefixedUrl(url) {
|
396
|
+
const wcsMatchers = ['/apps', '/pages', '/widgets'];
|
397
|
+
const dataMatchers = ['/objects', '/correspondenceTemplates', '/documents', '/payments', '/locations'];
|
398
|
+
const signalrMatchers = ['/hubs'];
|
399
|
+
const accessManagementMatchers = ['/users'];
|
400
|
+
const workflowMatchers = ['/workflows'];
|
401
|
+
if (wcsMatchers.some((endpoint) => url.startsWith(endpoint)))
|
402
|
+
return `/webContent${url}`;
|
403
|
+
if (dataMatchers.some((endpoint) => url.startsWith(endpoint)))
|
404
|
+
return `/data${url}`;
|
405
|
+
if (signalrMatchers.some((endpoint) => url.startsWith(endpoint)))
|
406
|
+
return `/signalr${url}`;
|
407
|
+
if (accessManagementMatchers.some((endpoint) => url.startsWith(endpoint)))
|
408
|
+
return `/accessManagement${url}`;
|
409
|
+
if (workflowMatchers.some((endpoint) => url.startsWith(endpoint)))
|
410
|
+
return `/workflow${url}`;
|
411
|
+
return url;
|
412
|
+
}
|
413
|
+
// The following function adds the object properties to the form components.
|
414
|
+
// This function is used when there is no form configured in the form builder.
|
415
|
+
export function addObjectPropertiesToComponentProps(properties,
|
416
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
417
|
+
formComponents, instance, objectPropertyInputProps, autoSave, readOnly, defaultPages, navigateTo, queryAddresses, apiServices, isModal, fieldHeight) {
|
418
|
+
var _a;
|
419
|
+
return __awaiter(this, void 0, void 0, function* () {
|
420
|
+
return [
|
421
|
+
...(yield Promise.all((_a = formComponents === null || formComponents === void 0 ? void 0 : formComponents.filter((component) => !isUndefined(component) && !isNil(component))) === null || _a === void 0 ? void 0 : _a.map((component) => __awaiter(this, void 0, void 0, function* () {
|
422
|
+
var _b, _c, _d, _e, _f, _g;
|
423
|
+
const property = properties
|
424
|
+
.flatMap((property) => {
|
425
|
+
if (property.type === 'address') {
|
426
|
+
return [
|
427
|
+
{
|
428
|
+
id: `${property.id}.line1`,
|
429
|
+
name: `${property.name} Line 1`,
|
430
|
+
type: 'string',
|
431
|
+
},
|
432
|
+
{
|
433
|
+
id: `${property.id}.line2`,
|
434
|
+
name: `${property.name} Line 2`,
|
435
|
+
type: 'string',
|
436
|
+
},
|
437
|
+
{
|
438
|
+
id: `${property.id}.city`,
|
439
|
+
name: `${property.name} City`,
|
440
|
+
type: 'string',
|
441
|
+
},
|
442
|
+
{
|
443
|
+
id: `${property.id}.county`,
|
444
|
+
name: `${property.name} County`,
|
445
|
+
type: 'string',
|
446
|
+
},
|
447
|
+
{
|
448
|
+
id: `${property.id}.state`,
|
449
|
+
name: `${property.name} State`,
|
450
|
+
type: 'string',
|
451
|
+
},
|
452
|
+
{
|
453
|
+
id: `${property.id}.zipCode`,
|
454
|
+
name: `${property.name} Zip Code`,
|
455
|
+
type: 'string',
|
456
|
+
},
|
457
|
+
];
|
458
|
+
}
|
459
|
+
return property;
|
460
|
+
})
|
461
|
+
.find((property) => property.id === component.key);
|
462
|
+
const id = (_b = property === null || property === void 0 ? void 0 : property.id) !== null && _b !== void 0 ? _b : component.key;
|
463
|
+
if (component.type === 'Content') {
|
464
|
+
return component;
|
465
|
+
}
|
466
|
+
if (component.type === 'Date') {
|
467
|
+
if (component.initialValue) {
|
468
|
+
component.initialValue = DateTime.fromISO(component.initialValue).toISODate();
|
469
|
+
}
|
470
|
+
// This will overwrite the default value
|
471
|
+
if (component.defaultToCurrentDate) {
|
472
|
+
component.initialValue = DateTime.now().toISODate();
|
473
|
+
}
|
474
|
+
}
|
475
|
+
if (component.type === 'DateTime') {
|
476
|
+
if (component.initialValue) {
|
477
|
+
component.initialValue = DateTime.fromISO(component.initialValue).toISO();
|
478
|
+
}
|
479
|
+
// This will overwrite the default value
|
480
|
+
if (component.defaultToCurrentDate) {
|
481
|
+
component.initialValue = DateTime.now().toISO();
|
482
|
+
}
|
483
|
+
}
|
484
|
+
if (component.type === 'Time') {
|
485
|
+
if (component.initialValue) {
|
486
|
+
component.initialValue = DateTime.fromISO(component.initialValue).toISOTime({
|
487
|
+
includeOffset: false,
|
488
|
+
suppressMilliseconds: true,
|
489
|
+
});
|
490
|
+
}
|
491
|
+
// This will overwrite the default value
|
492
|
+
if (component.defaultToCurrentTime) {
|
493
|
+
component.initialValue = DateTime.now().toISOTime({
|
494
|
+
includeOffset: false,
|
495
|
+
suppressMilliseconds: true,
|
496
|
+
});
|
497
|
+
}
|
498
|
+
}
|
499
|
+
// if a conditional date is in a format other than yyyy-mm-dd, convert it to that format
|
500
|
+
if (component.conditional &&
|
501
|
+
((_c = formComponents.find((formComponent) => formComponent.key === component.conditional.when)) === null || _c === void 0 ? void 0 : _c.type) === 'Date') {
|
502
|
+
component.conditional.eq = new Date(component.conditional.eq).toISOString().split('T')[0];
|
503
|
+
}
|
504
|
+
const [propertyId, nestedPropertyId] = id.split('.');
|
505
|
+
let instanceValue;
|
506
|
+
if (nestedPropertyId) {
|
507
|
+
instanceValue = (instance === null || instance === void 0 ? void 0 : instance[propertyId])
|
508
|
+
? instance[propertyId][nestedPropertyId]
|
509
|
+
: undefined;
|
510
|
+
}
|
511
|
+
else {
|
512
|
+
instanceValue = instance && id ? instance[id] : undefined;
|
513
|
+
}
|
514
|
+
// only add fieldComponents if the property exists on the sanitized object
|
515
|
+
if (property) {
|
516
|
+
if (property.manyToManyPropertyId &&
|
517
|
+
apiServices &&
|
518
|
+
!component.middleObject &&
|
519
|
+
!component.initialMiddleObjectInstances) {
|
520
|
+
const getMiddleObjectInstances = () => __awaiter(this, void 0, void 0, function* () {
|
521
|
+
const filter = instance ? getMiddleObjectFilter(property, instance) : {};
|
522
|
+
try {
|
523
|
+
return yield apiServices.get(getPrefixedUrl(`/objects/${property.objectId}/instances`), { params: { filter: JSON.stringify(filter) } });
|
524
|
+
}
|
525
|
+
catch (err) {
|
526
|
+
console.log(err);
|
527
|
+
return [];
|
528
|
+
}
|
529
|
+
});
|
530
|
+
const middleObject = yield apiServices.get(getPrefixedUrl(`/objects/${property.objectId}/effective?sanitizedVersion=true`), {
|
531
|
+
params: { filter: { fields: ['properties', 'actions', 'rootObjectId'] } },
|
532
|
+
});
|
533
|
+
const initialMiddleObjectInstances = yield getMiddleObjectInstances();
|
534
|
+
return Object.assign(Object.assign(Object.assign({}, component), (component.type === 'Object' && objectPropertyInputProps)), { defaultValue: getDefaultValue(isNil(instanceValue) ? component.initialValue : instanceValue, (_d = component === null || component === void 0 ? void 0 : component.data) === null || _d === void 0 ? void 0 : _d.values), property, type: `${readOnly ? 'ViewOnly' : ''}${component.type}`, readOnly: component.readOnly || readOnly || (property === null || property === void 0 ? void 0 : property.formula), multiple: ['array', 'document'].includes(property.type), instance: instance, fromFormBuilder: true, apiServices: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.apiServices, user: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.user, autoSave,
|
535
|
+
fieldHeight, customDefaultValue: component.type === 'Select'
|
536
|
+
? () => getDefaultValue(isNil(instanceValue) ? component.initialValue : instanceValue)
|
537
|
+
: undefined, queryAddresses: component.isAddressLine1 || ['collection', 'object'].includes(property === null || property === void 0 ? void 0 : property.type)
|
538
|
+
? queryAddresses
|
539
|
+
: undefined, initialMiddleObjectInstances,
|
540
|
+
middleObject,
|
541
|
+
getMiddleObjectInstances,
|
542
|
+
isModal });
|
543
|
+
}
|
544
|
+
return Object.assign(Object.assign(Object.assign({}, component), (component.type === 'Object' && objectPropertyInputProps)), { type: `${readOnly ? 'ViewOnly' : ''}${component.type}`, defaultValue: getDefaultValue(isNil(instanceValue) ? component.initialValue : instanceValue, (_e = component === null || component === void 0 ? void 0 : component.data) === null || _e === void 0 ? void 0 : _e.values), property, readOnly: component.readOnly || readOnly || (property === null || property === void 0 ? void 0 : property.formula), multiple: ['array', 'document'].includes(property.type), instance: instance, fromFormBuilder: true, apiServices: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.apiServices, user: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.user, fieldHeight,
|
545
|
+
autoSave, customDefaultValue: component.type === 'Select'
|
546
|
+
? () => getDefaultValue(isNil(instanceValue) ? component.initialValue : instanceValue)
|
547
|
+
: undefined, queryAddresses: component.isAddressLine1 || ['collection', 'object'].includes(property === null || property === void 0 ? void 0 : property.type)
|
548
|
+
? queryAddresses
|
549
|
+
: undefined, isOptionEqualToValue: component.type === 'Select' || component.type === 'MultiSelect'
|
550
|
+
? (option, value) => {
|
551
|
+
if (typeof value === 'object' && 'value' in value) {
|
552
|
+
return option.value === value.value;
|
553
|
+
}
|
554
|
+
return option.value === value;
|
555
|
+
}
|
556
|
+
: undefined, getOptionLabel: component.type === 'Select' || component.type === 'MultiSelect'
|
557
|
+
? (option) => {
|
558
|
+
var _a, _b, _c;
|
559
|
+
if (option) {
|
560
|
+
return (_c = (_b = (_a = component.data) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b.find((op) => op.value ===
|
561
|
+
(typeof option === 'string' ? option : option.value))) === null || _c === void 0 ? void 0 : _c.label;
|
562
|
+
}
|
563
|
+
}
|
564
|
+
: undefined, isModal });
|
565
|
+
}
|
566
|
+
if (component.columns) {
|
567
|
+
for (const column of component.columns) {
|
568
|
+
column.components = yield addObjectPropertiesToComponentProps(properties, column.components, instance, objectPropertyInputProps, autoSave, readOnly, undefined, undefined, queryAddresses, apiServices, isModal, fieldHeight);
|
569
|
+
}
|
570
|
+
return component;
|
571
|
+
}
|
572
|
+
if (component.components) {
|
573
|
+
for (const item of component.components) {
|
574
|
+
const nestedFieldProperty = properties.find((property) => property.id === item.key);
|
575
|
+
if (item.type) {
|
576
|
+
item.defaultValue = getDefaultValue(!instance || isNil(get(instance, item.key))
|
577
|
+
? item.initialValue
|
578
|
+
: get(instance, item.key), (_f = item === null || item === void 0 ? void 0 : item.data) === null || _f === void 0 ? void 0 : _f.values);
|
579
|
+
item.customDefaultValue =
|
580
|
+
item.type === 'Select'
|
581
|
+
? () => getDefaultValue(!instance || isNil(instance[item === null || item === void 0 ? void 0 : item.key])
|
582
|
+
? item.initialValue
|
583
|
+
: instance[item.key], undefined)
|
584
|
+
: undefined;
|
585
|
+
if (item.type.includes('RepeatableField') && !!instance) {
|
586
|
+
item.instance = instance;
|
587
|
+
}
|
588
|
+
}
|
589
|
+
if (nestedFieldProperty) {
|
590
|
+
item.type = `${readOnly ? 'ViewOnly' : ''}${item.type}`;
|
591
|
+
item.property = nestedFieldProperty;
|
592
|
+
}
|
593
|
+
item.instance = instance;
|
594
|
+
item.readOnly = item.readOnly || readOnly;
|
595
|
+
item.autoSave = autoSave;
|
596
|
+
item.apiServices = objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.apiServices;
|
597
|
+
item.user = objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.user;
|
598
|
+
item.defaultPages = defaultPages;
|
599
|
+
item.navigateTo = navigateTo;
|
600
|
+
item.isModal = isModal;
|
601
|
+
item.fieldHeight = fieldHeight;
|
602
|
+
if (item.addressPropertyId) {
|
603
|
+
item.queryAddresses = queryAddresses;
|
604
|
+
}
|
605
|
+
if (((_g = item.property) === null || _g === void 0 ? void 0 : _g.manyToManyPropertyId) &&
|
606
|
+
apiServices &&
|
607
|
+
!item.middleObject &&
|
608
|
+
!item.initialMiddleObjectInstances) {
|
609
|
+
const getMiddleObjectInstances = () => __awaiter(this, void 0, void 0, function* () {
|
610
|
+
const filter = instance ? getMiddleObjectFilter(item.property, instance) : {};
|
611
|
+
return yield apiServices.get(getPrefixedUrl(`/objects/${item.property.objectId}/instances`), { params: { filter: JSON.stringify(filter) } });
|
612
|
+
});
|
613
|
+
const middleObject = yield apiServices.get(getPrefixedUrl(`/objects/${item.property.objectId}/effective?sanitizedVersion=true`), {
|
614
|
+
params: { filter: { fields: ['properties', 'actions', 'rootObjectId'] } },
|
615
|
+
});
|
616
|
+
const initialMiddleObjectInstances = yield getMiddleObjectInstances();
|
617
|
+
item.initialMiddleObjectInstances = initialMiddleObjectInstances;
|
618
|
+
item.middleObject = middleObject;
|
619
|
+
item.getMiddleObjectInstances = getMiddleObjectInstances;
|
620
|
+
}
|
621
|
+
}
|
622
|
+
return Object.assign(Object.assign(Object.assign({ components: yield addObjectPropertiesToComponentProps(properties, component.components, instance, objectPropertyInputProps, autoSave, readOnly, defaultPages, navigateTo, queryAddresses, apiServices, isModal, fieldHeight) }, component), (component.type === 'Object' && objectPropertyInputProps)), { type: `${readOnly ? 'ViewOnly' : ''}${component.type}`, properties: properties, property, instance: instance, fromFormBuilder: true, apiServices: apiServices, user: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.user, autoSave, queryAddresses: component.isAddressLine1 ? queryAddresses : undefined, isModal,
|
623
|
+
fieldHeight });
|
624
|
+
}
|
625
|
+
})))).filter((component) => !!component),
|
626
|
+
];
|
627
|
+
});
|
628
|
+
}
|
629
|
+
export function getDefaultValue(initialValue, selectOptions) {
|
630
|
+
var _a;
|
631
|
+
if (!isEmpty(initialValue) || (initialValue !== undefined && typeof initialValue === 'number')) {
|
632
|
+
if (Array.isArray(initialValue)) {
|
633
|
+
return initialValue.map((option) => {
|
634
|
+
if (option && typeof option === 'object' && 'value' in option) {
|
635
|
+
return option.value;
|
636
|
+
}
|
637
|
+
else {
|
638
|
+
return option;
|
639
|
+
}
|
640
|
+
});
|
641
|
+
}
|
642
|
+
else if (initialValue && typeof initialValue === 'object' && 'value' in initialValue) {
|
643
|
+
return initialValue['value'];
|
644
|
+
}
|
645
|
+
else {
|
646
|
+
if (selectOptions === null || selectOptions === void 0 ? void 0 : selectOptions.length) {
|
647
|
+
return (_a = selectOptions === null || selectOptions === void 0 ? void 0 : selectOptions.find((option) => option.value === initialValue)) === null || _a === void 0 ? void 0 : _a.label;
|
648
|
+
}
|
649
|
+
return initialValue;
|
650
|
+
}
|
651
|
+
}
|
652
|
+
return undefined;
|
653
|
+
}
|
654
|
+
// The following function adds the configured properties to the form components.
|
655
|
+
// This function is used when there is a form configured in the form builder.
|
656
|
+
export const buildComponentPropsFromObjectProperties = (properties, objectId, instance, objectPropertyInputProps, hasActionPermissions, autoSave, readOnly, queryAddresses, isModal, fieldHeight) => {
|
657
|
+
const matchType = (type) => {
|
658
|
+
switch (type) {
|
659
|
+
case 'boolean':
|
660
|
+
return 'Boolean';
|
661
|
+
case 'datetime':
|
662
|
+
return 'Datetime';
|
663
|
+
case 'date':
|
664
|
+
return 'Date';
|
665
|
+
case 'document':
|
666
|
+
return 'Document';
|
667
|
+
case 'number':
|
668
|
+
return 'Decimal';
|
669
|
+
case 'integer':
|
670
|
+
return 'Integer';
|
671
|
+
case 'object':
|
672
|
+
return 'Object';
|
673
|
+
case 'select':
|
674
|
+
return 'Select';
|
675
|
+
case 'array':
|
676
|
+
return 'MultiSelect';
|
677
|
+
case 'image':
|
678
|
+
return 'Image';
|
679
|
+
case 'richText':
|
680
|
+
return 'RichText';
|
681
|
+
case 'time':
|
682
|
+
return 'Time';
|
683
|
+
case 'date-time':
|
684
|
+
return 'DateTime';
|
685
|
+
case 'user':
|
686
|
+
return 'User';
|
687
|
+
default:
|
688
|
+
return 'TextField';
|
689
|
+
}
|
690
|
+
};
|
691
|
+
properties = properties.filter((property) => property.type !== 'collection');
|
692
|
+
return properties.flatMap((property) => {
|
693
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
694
|
+
if (property.type === 'address') {
|
695
|
+
const type = readOnly ? 'ViewOnlyTextField' : 'TextField';
|
696
|
+
return [
|
697
|
+
{
|
698
|
+
type,
|
699
|
+
key: `${property.id}.line1`,
|
700
|
+
label: `${property.name} Line 1`,
|
701
|
+
inputMask: property.mask,
|
702
|
+
readOnly: !hasActionPermissions || readOnly || !!(property === null || property === void 0 ? void 0 : property.formula),
|
703
|
+
instance: instance,
|
704
|
+
defaultValue: instance ? (_a = instance[property.id]) === null || _a === void 0 ? void 0 : _a[`line1`] : undefined,
|
705
|
+
user: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.user,
|
706
|
+
property: {
|
707
|
+
id: `${property.id}.line1`,
|
708
|
+
name: `${property.name} Line 1`,
|
709
|
+
type: 'string',
|
710
|
+
},
|
711
|
+
validate: {
|
712
|
+
required: property.required,
|
713
|
+
},
|
714
|
+
isAddressLine1: true,
|
715
|
+
addressPropertyId: property.id,
|
716
|
+
objectId,
|
717
|
+
fieldHeight,
|
718
|
+
autoSave,
|
719
|
+
queryAddresses,
|
720
|
+
},
|
721
|
+
{
|
722
|
+
type,
|
723
|
+
key: `${property.id}.line2`,
|
724
|
+
label: `${property.name} Line 2`,
|
725
|
+
inputMask: property.mask,
|
726
|
+
readOnly: !hasActionPermissions || readOnly || !!(property === null || property === void 0 ? void 0 : property.formula),
|
727
|
+
instance: instance,
|
728
|
+
defaultValue: instance ? (_b = instance[property.id]) === null || _b === void 0 ? void 0 : _b[`line2`] : undefined,
|
729
|
+
user: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.user,
|
730
|
+
property: {
|
731
|
+
id: `${property.id}.line2`,
|
732
|
+
name: `${property.name} Line 2`,
|
733
|
+
type: 'string',
|
734
|
+
},
|
735
|
+
objectId,
|
736
|
+
fieldHeight,
|
737
|
+
autoSave,
|
738
|
+
},
|
739
|
+
{
|
740
|
+
type,
|
741
|
+
key: `${property.id}.city`,
|
742
|
+
label: `${property.name} City`,
|
743
|
+
inputMask: property.mask,
|
744
|
+
readOnly: !hasActionPermissions || readOnly || !!(property === null || property === void 0 ? void 0 : property.formula),
|
745
|
+
instance: instance,
|
746
|
+
defaultValue: instance ? (_c = instance[property.id]) === null || _c === void 0 ? void 0 : _c[`city`] : undefined,
|
747
|
+
user: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.user,
|
748
|
+
property: {
|
749
|
+
id: `${property.id}.city`,
|
750
|
+
name: `${property.name} City`,
|
751
|
+
type: 'string',
|
752
|
+
},
|
753
|
+
validate: {
|
754
|
+
required: property.required,
|
755
|
+
},
|
756
|
+
objectId,
|
757
|
+
fieldHeight,
|
758
|
+
autoSave,
|
759
|
+
},
|
760
|
+
{
|
761
|
+
type,
|
762
|
+
key: `${property.id}.county`,
|
763
|
+
label: `${property.name} County`,
|
764
|
+
inputMask: property.mask,
|
765
|
+
readOnly: !hasActionPermissions || readOnly || !!(property === null || property === void 0 ? void 0 : property.formula),
|
766
|
+
instance: instance,
|
767
|
+
defaultValue: instance ? (_d = instance[property.id]) === null || _d === void 0 ? void 0 : _d[`county`] : undefined,
|
768
|
+
user: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.user,
|
769
|
+
property: {
|
770
|
+
id: `${property.id}.county`,
|
771
|
+
name: `${property.name} County`,
|
772
|
+
type: 'string',
|
773
|
+
},
|
774
|
+
fieldHeight,
|
775
|
+
autoSave,
|
776
|
+
},
|
777
|
+
{
|
778
|
+
type,
|
779
|
+
key: `${property.id}.state`,
|
780
|
+
label: `${property.name} State`,
|
781
|
+
inputMask: property.mask,
|
782
|
+
readOnly: !hasActionPermissions || readOnly || !!(property === null || property === void 0 ? void 0 : property.formula),
|
783
|
+
instance: instance,
|
784
|
+
defaultValue: instance ? (_e = instance[property.id]) === null || _e === void 0 ? void 0 : _e[`state`] : undefined,
|
785
|
+
user: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.user,
|
786
|
+
property: {
|
787
|
+
id: `${property.id}.state`,
|
788
|
+
name: `${property.name} State`,
|
789
|
+
type: 'string',
|
790
|
+
},
|
791
|
+
validate: {
|
792
|
+
required: property.required,
|
793
|
+
},
|
794
|
+
objectId,
|
795
|
+
fieldHeight,
|
796
|
+
autoSave,
|
797
|
+
},
|
798
|
+
{
|
799
|
+
type,
|
800
|
+
key: `${property.id}.zipCode`,
|
801
|
+
label: `${property.name} Zip Code`,
|
802
|
+
inputMask: property.mask,
|
803
|
+
readOnly: !hasActionPermissions || readOnly || !!(property === null || property === void 0 ? void 0 : property.formula),
|
804
|
+
instance: instance,
|
805
|
+
defaultValue: instance ? (_f = instance[property.id]) === null || _f === void 0 ? void 0 : _f[`zipCode`] : undefined,
|
806
|
+
user: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.user,
|
807
|
+
property: {
|
808
|
+
id: `${property.id}.zipCode`,
|
809
|
+
name: `${property.name} Zip Code`,
|
810
|
+
type: 'string',
|
811
|
+
},
|
812
|
+
validate: {
|
813
|
+
required: property.required,
|
814
|
+
},
|
815
|
+
objectId,
|
816
|
+
fieldHeight,
|
817
|
+
autoSave,
|
818
|
+
},
|
819
|
+
];
|
820
|
+
}
|
821
|
+
let minDate = (_h = (_g = property.validation) === null || _g === void 0 ? void 0 : _g.from) !== null && _h !== void 0 ? _h : '';
|
822
|
+
let maxDate = (_k = (_j = property.validation) === null || _j === void 0 ? void 0 : _j.to) !== null && _k !== void 0 ? _k : '';
|
823
|
+
if (minDate && /^{{.*}}$/.test(minDate)) {
|
824
|
+
const fragments = minDate.split(/\s/);
|
825
|
+
if (fragments.length === 1) {
|
826
|
+
minDate = minDate.replace(/^{{/, '{{input.');
|
827
|
+
}
|
828
|
+
else {
|
829
|
+
minDate = fragments
|
830
|
+
.map((fragment, index) => {
|
831
|
+
if (index === 1) {
|
832
|
+
return `input.${fragment}`;
|
833
|
+
}
|
834
|
+
return fragment;
|
835
|
+
})
|
836
|
+
.join(' ');
|
837
|
+
}
|
838
|
+
}
|
839
|
+
if (maxDate && /^{{.*}}$/.test(maxDate)) {
|
840
|
+
const fragments = maxDate.split(/\s/);
|
841
|
+
if (fragments.length === 1) {
|
842
|
+
maxDate = maxDate.replace(/^{{/, '{{input.');
|
843
|
+
}
|
844
|
+
else {
|
845
|
+
maxDate = fragments
|
846
|
+
.map((fragment, index) => {
|
847
|
+
if (index === 1) {
|
848
|
+
return `input.${fragment}`;
|
849
|
+
}
|
850
|
+
return fragment;
|
851
|
+
})
|
852
|
+
.join(' ');
|
853
|
+
}
|
854
|
+
}
|
855
|
+
return Object.assign(Object.assign({ type: `${readOnly ? 'ViewOnly' : ''}${matchType(property.type)}`, key: property.id, label: property.name, inputMask: property.mask, multiple: ['array', 'document'].includes(property.type), readOnly: !hasActionPermissions || readOnly || !!(property === null || property === void 0 ? void 0 : property.formula), instance: instance, validate: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ required: property.required }, (property.type === 'date' &&
|
856
|
+
property.validation && {
|
857
|
+
minDate,
|
858
|
+
maxDate,
|
859
|
+
customMessage: property.validation.errorMessage,
|
860
|
+
})), (property.type === 'date-time' &&
|
861
|
+
property.validation && {
|
862
|
+
minTime: property.validation.from,
|
863
|
+
maxTime: property.validation.to,
|
864
|
+
customMessage: (property === null || property === void 0 ? void 0 : property.validation).errorMessage,
|
865
|
+
})), (property.type === 'time' &&
|
866
|
+
property.validation && {
|
867
|
+
minTime: property.validation.from,
|
868
|
+
maxTime: property.validation.to,
|
869
|
+
customMessage: (property === null || property === void 0 ? void 0 : property.validation).errorMessage,
|
870
|
+
})), ((property.type === 'integer' || property.type === 'number') &&
|
871
|
+
property.validation && {
|
872
|
+
min: property.validation.minimum,
|
873
|
+
max: property.validation.maximum,
|
874
|
+
customMessage: property.validation.errorMessage,
|
875
|
+
})), (property.type === 'string' &&
|
876
|
+
property.validation &&
|
877
|
+
Object.hasOwnProperty.call(property.validation, 'rules') && {
|
878
|
+
operator: property.validation.operator,
|
879
|
+
regexes: (_l = property.validation.rules) === null || _l === void 0 ? void 0 : _l.map((rule) => {
|
880
|
+
var _a;
|
881
|
+
return (Object.assign(Object.assign({}, rule), { errorMessage: ((_a = rule.errorMessage) === null || _a === void 0 ? void 0 : _a.length)
|
882
|
+
? rule.errorMessage
|
883
|
+
: 'Property is not in a valid format' }));
|
884
|
+
}),
|
885
|
+
})), (property.type === 'document' &&
|
886
|
+
property.validation && {
|
887
|
+
minDocuments: property.validation.minDocuments,
|
888
|
+
maxDocuments: property.validation.maxDocuments,
|
889
|
+
customMessage: property.validation.errorMessage,
|
890
|
+
})), property.validation), objectId }, (property.type === 'object' && objectPropertyInputProps)), { defaultValue: instance ? instance[property.id] : undefined, user: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.user, apiServices: objectPropertyInputProps === null || objectPropertyInputProps === void 0 ? void 0 : objectPropertyInputProps.apiServices, property: property, fieldHeight,
|
891
|
+
autoSave, queryAddresses: ['collection', 'object'].includes(property === null || property === void 0 ? void 0 : property.type) ? queryAddresses : undefined, isModal });
|
892
|
+
});
|
893
|
+
};
|
894
|
+
// The following function is used to build the form components from the document properties.
|
895
|
+
export const buildComponentPropsFromDocumentProperties = (documentProperties, readOnly, autoSave, fieldHeight) => {
|
896
|
+
return documentProperties.map(([keyName, value]) => {
|
897
|
+
return {
|
898
|
+
type: keyName === 'metadata.view_permission'
|
899
|
+
? `${readOnly ? 'ViewOnly' : ''}Select`
|
900
|
+
: `${readOnly ? 'ViewOnly' : ''}TextField`,
|
901
|
+
key: keyName,
|
902
|
+
label: startCase(keyName.replace('metadata.', '')),
|
903
|
+
readOnly: !keyName.includes('metadata.') || readOnly,
|
904
|
+
defaultValue: value,
|
905
|
+
autoSave,
|
906
|
+
fieldHeight,
|
907
|
+
};
|
908
|
+
});
|
909
|
+
};
|
910
|
+
// The following variable and functions are used to support the "Related Object" properies.
|
911
|
+
export const OPERATOR_MAP = {
|
912
|
+
$and: 'and',
|
913
|
+
$or: 'or',
|
914
|
+
$eq: 'eq',
|
915
|
+
$ne: 'neq',
|
916
|
+
$lt: 'lt',
|
917
|
+
$lte: 'lte',
|
918
|
+
$gt: 'gt',
|
919
|
+
$gte: 'gte',
|
920
|
+
$in: 'inq',
|
921
|
+
$nin: 'nin',
|
922
|
+
$regex: 'regexp',
|
923
|
+
$exists: 'exists',
|
924
|
+
$not: 'not',
|
925
|
+
};
|
926
|
+
export function transformToWhere(mongoQuery) {
|
927
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
928
|
+
return transform(mongoQuery, (result, value, key) => {
|
929
|
+
const newKey = typeof key === 'string' && key.startsWith('$') ? OPERATOR_MAP[key] : key;
|
930
|
+
if (newKey === undefined) {
|
931
|
+
throw new Error(`Unsupported operator ${key}`);
|
932
|
+
}
|
933
|
+
result[newKey] = isObject(value) ? transformToWhere(value) : value;
|
934
|
+
});
|
935
|
+
}
|
936
|
+
export function updateCriteriaInputs(criteria, field, fieldValue, isInputField) {
|
937
|
+
var _a;
|
938
|
+
for (const [key, value] of Object.entries(criteria)) {
|
939
|
+
if (isArray(value)) {
|
940
|
+
for (const index in value) {
|
941
|
+
if (isObject(value[index])) {
|
942
|
+
updateCriteriaInputs(value[index], field, fieldValue, isInputField);
|
943
|
+
}
|
944
|
+
else {
|
945
|
+
value[index] =
|
946
|
+
typeof value[index] === 'string'
|
947
|
+
? ((_a = value[index]) === null || _a === void 0 ? void 0 : _a.replaceAll(!isInputField ? `{{{${field}}}}` : `{{{input.${field}}}}`, fieldValue !== null && fieldValue !== void 0 ? fieldValue : '').trim()) || undefined
|
948
|
+
: value !== null && value !== void 0 ? value : undefined;
|
949
|
+
}
|
950
|
+
}
|
951
|
+
}
|
952
|
+
else if (isObject(value)) {
|
953
|
+
updateCriteriaInputs(value, field, fieldValue, isInputField);
|
954
|
+
}
|
955
|
+
else {
|
956
|
+
criteria[key] =
|
957
|
+
typeof value === 'string'
|
958
|
+
? (value === null || value === void 0 ? void 0 : value.replaceAll(!isInputField ? `{{{${field}}}}` : `{{{input.${field}}}}`, fieldValue !== null && fieldValue !== void 0 ? fieldValue : '').trim()) || undefined
|
959
|
+
: value !== null && value !== void 0 ? value : undefined;
|
960
|
+
}
|
961
|
+
}
|
962
|
+
}
|
963
|
+
export function getAllCriteriaInputs(criteria) {
|
964
|
+
const result = [];
|
965
|
+
for (const [, value] of Object.entries(criteria)) {
|
966
|
+
if (isArray(value)) {
|
967
|
+
for (const item of value) {
|
968
|
+
if (item && typeof item === 'object') {
|
969
|
+
const inputProps = getAllCriteriaInputs(item);
|
970
|
+
inputProps && result.push(...inputProps);
|
971
|
+
}
|
972
|
+
else {
|
973
|
+
const inputProps = typeof item === 'string' ? item.match(/{{{input\..*}}}/g) : undefined;
|
974
|
+
inputProps && result.push(...inputProps);
|
975
|
+
}
|
976
|
+
}
|
977
|
+
}
|
978
|
+
else if (value && typeof value === 'object') {
|
979
|
+
const inputProps = getAllCriteriaInputs(value);
|
980
|
+
inputProps && result.push(...inputProps);
|
981
|
+
}
|
982
|
+
else {
|
983
|
+
const inputProps = typeof value === 'string' ? value.match(/{{{input\..*}}}/g) : undefined;
|
984
|
+
inputProps && result.push(...inputProps);
|
985
|
+
}
|
986
|
+
}
|
987
|
+
return uniq(result.map((item) => item.replace('{{{input.', '').replace('}}}', '')));
|
988
|
+
}
|
989
|
+
export function isPropertyVisible(conditional, formData) {
|
990
|
+
const isConditional = !!(conditional === null || conditional === void 0 ? void 0 : conditional.when);
|
991
|
+
if (!isConditional) {
|
992
|
+
return true;
|
993
|
+
}
|
994
|
+
const valueOfConditional = get(formData, conditional.when);
|
995
|
+
if (conditional.show) {
|
996
|
+
return valueOfConditional === conditional.eq;
|
997
|
+
}
|
998
|
+
else {
|
999
|
+
return valueOfConditional !== conditional.eq;
|
1000
|
+
}
|
1001
|
+
}
|
1002
|
+
// The following function is used to normalize date and time values.
|
1003
|
+
export function normalizeDateTime(dateTime) {
|
1004
|
+
return new Date(dateTime.toString()).toISOString();
|
1005
|
+
}
|
1006
|
+
export function normalizeDates(instances, object) {
|
1007
|
+
var _a, _b;
|
1008
|
+
const dateProps = ['date', 'date-time', 'time'];
|
1009
|
+
const properties = (_b = (_a = object === null || object === void 0 ? void 0 : object.properties) === null || _a === void 0 ? void 0 : _a.filter((property) => dateProps.includes(property.type)).reduce((agg, property) => Object.assign(agg, { [property.id]: property.type }), {})) !== null && _b !== void 0 ? _b : {};
|
1010
|
+
const propKeys = Object.keys(properties);
|
1011
|
+
instances.forEach((instance) => {
|
1012
|
+
Object.keys(instance).forEach((key) => {
|
1013
|
+
// Ignore non-datelike and empty fields.
|
1014
|
+
if (!propKeys.includes(key) || !instance[key]) {
|
1015
|
+
return;
|
1016
|
+
}
|
1017
|
+
switch (properties[key]) {
|
1018
|
+
case 'date':
|
1019
|
+
// Casting here is valid because the value has already been
|
1020
|
+
// determined to be a datelike field that is non-empty.
|
1021
|
+
instance[key] = DateTime.fromISO(instance[key]).toLocaleString(DateTime.DATE_SHORT);
|
1022
|
+
break;
|
1023
|
+
case 'date-time':
|
1024
|
+
// Casting here is valid because the value has already been
|
1025
|
+
// determined to be a datelike field that is non-empty.
|
1026
|
+
instance[key] = DateTime.fromISO(instance[key]).toLocaleString(DateTime.DATETIME_SHORT);
|
1027
|
+
break;
|
1028
|
+
case 'time':
|
1029
|
+
// Casting here is valid because the value has already been
|
1030
|
+
// determined to be a datelike field that is non-empty.
|
1031
|
+
instance[key] = DateTime.fromISO(instance[key]).toLocaleString(DateTime.TIME_SIMPLE);
|
1032
|
+
break;
|
1033
|
+
}
|
1034
|
+
});
|
1035
|
+
});
|
1036
|
+
}
|