@evoke-platform/ui-components 1.0.0-dev.217 → 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.
Files changed (58) hide show
  1. package/dist/published/components/custom/Form/Common/Form.d.ts +38 -0
  2. package/dist/published/components/custom/Form/Common/Form.js +413 -0
  3. package/dist/published/components/custom/Form/Common/FormComponentWrapper.d.ts +26 -0
  4. package/dist/published/components/custom/Form/Common/FormComponentWrapper.js +79 -0
  5. package/dist/published/components/custom/Form/Common/index.d.ts +2 -0
  6. package/dist/published/components/custom/Form/Common/index.js +2 -0
  7. package/dist/published/components/custom/Form/FormComponents/ButtonComponent.d.ts +37 -0
  8. package/dist/published/components/custom/Form/FormComponents/ButtonComponent.js +150 -0
  9. package/dist/published/components/custom/Form/FormComponents/DocumentComponent/Document.d.ts +17 -0
  10. package/dist/published/components/custom/Form/FormComponents/DocumentComponent/Document.js +80 -0
  11. package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentComponent.d.ts +23 -0
  12. package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentComponent.js +154 -0
  13. package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentList.d.ts +15 -0
  14. package/dist/published/components/custom/Form/FormComponents/DocumentComponent/DocumentList.js +172 -0
  15. package/dist/published/components/custom/Form/FormComponents/FormFieldComponent.d.ts +41 -0
  16. package/dist/published/components/custom/Form/FormComponents/FormFieldComponent.js +409 -0
  17. package/dist/published/components/custom/Form/FormComponents/ImageComponent/Image.d.ts +15 -0
  18. package/dist/published/components/custom/Form/FormComponents/ImageComponent/Image.js +111 -0
  19. package/dist/published/components/custom/Form/FormComponents/ImageComponent/ImageComponent.d.ts +23 -0
  20. package/dist/published/components/custom/Form/FormComponents/ImageComponent/ImageComponent.js +112 -0
  21. package/dist/published/components/custom/Form/FormComponents/ObjectComponent/InstanceLookup.d.ts +20 -0
  22. package/dist/published/components/custom/Form/FormComponents/ObjectComponent/InstanceLookup.js +229 -0
  23. package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectComponent.d.ts +34 -0
  24. package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectComponent.js +150 -0
  25. package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectPropertyInput.d.ts +3 -0
  26. package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectPropertyInput.js +306 -0
  27. package/dist/published/components/custom/Form/FormComponents/ObjectComponent/RelatedObjectInstance.d.ts +24 -0
  28. package/dist/published/components/custom/Form/FormComponents/ObjectComponent/RelatedObjectInstance.js +126 -0
  29. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ActionDialog.d.ts +21 -0
  30. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ActionDialog.js +96 -0
  31. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ManyToMany/DropdownRepeatableField.d.ts +15 -0
  32. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ManyToMany/DropdownRepeatableField.js +158 -0
  33. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ManyToMany/DropdownRepeatableFieldInput.d.ts +39 -0
  34. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/ManyToMany/DropdownRepeatableFieldInput.js +89 -0
  35. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableField.d.ts +12 -0
  36. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableField.js +369 -0
  37. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableFieldComponent.d.ts +20 -0
  38. package/dist/published/components/custom/Form/FormComponents/RepeatableFieldComponent/RepeatableFieldComponent.js +57 -0
  39. package/dist/published/components/custom/Form/FormComponents/UserComponent/UserComponent.d.ts +26 -0
  40. package/dist/published/components/custom/Form/FormComponents/UserComponent/UserComponent.js +99 -0
  41. package/dist/published/components/custom/Form/FormComponents/UserComponent/UserProperty.d.ts +23 -0
  42. package/dist/published/components/custom/Form/FormComponents/UserComponent/UserProperty.js +115 -0
  43. package/dist/published/components/custom/Form/FormComponents/ViewOnlyComponent.d.ts +20 -0
  44. package/dist/published/components/custom/Form/FormComponents/ViewOnlyComponent.js +83 -0
  45. package/dist/published/components/custom/Form/FormComponents/index.d.ts +8 -0
  46. package/dist/published/components/custom/Form/FormComponents/index.js +8 -0
  47. package/dist/published/components/custom/Form/index.d.ts +3 -0
  48. package/dist/published/components/custom/Form/index.js +3 -0
  49. package/dist/published/components/custom/Form/types.d.ts +109 -0
  50. package/dist/published/components/custom/Form/types.js +1 -0
  51. package/dist/published/components/custom/Form/utils.d.ts +45 -0
  52. package/dist/published/components/custom/Form/utils.js +1036 -0
  53. package/dist/published/components/custom/index.d.ts +1 -0
  54. package/dist/published/components/custom/index.js +1 -0
  55. package/dist/published/index.d.ts +1 -1
  56. package/dist/published/index.js +1 -1
  57. package/dist/published/styles/form-component.css +152 -0
  58. package/package.json +18 -5
@@ -0,0 +1,306 @@
1
+ import cleanDeep from 'clean-deep';
2
+ import Handlebars from 'handlebars';
3
+ import { cloneDeep, debounce, isEmpty, isNil, pick } from 'lodash';
4
+ import React, { useCallback, useEffect, useState } from 'react';
5
+ import { Close } from '../../../../../icons';
6
+ import { Autocomplete, Button, Dialog, IconButton, Link, Paper, TextField, Tooltip, Typography, } from '../../../../core';
7
+ import { Box } from '../../../../layout';
8
+ import { getPrefixedUrl, normalizeDates, transformToWhere } from '../../utils';
9
+ import { RelatedObjectInstance } from './RelatedObjectInstance';
10
+ export const ObjectPropertyInput = (props) => {
11
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
12
+ const { id, instance, property, apiServices, defaultPages, handleChangeObjectProperty, nestedFieldsView, canUpdateProperty, error, navigateTo, mode, displayOption, filter, defaultValueCriteria, sortBy, orderBy, setSnackbarError, isModal, user, } = props;
13
+ const [relatedObject, setRelatedObject] = useState();
14
+ const [openCreateDialog, setOpenCreateDialog] = useState(false);
15
+ const [selectedInstance, setSelectedInstance] = useState();
16
+ const [dropdownInput, setDropdownInput] = useState();
17
+ const [loadingOptions, setLoadingOptions] = useState(false);
18
+ const [options, setOptions] = useState([]);
19
+ const [openOptions, setOpenOptions] = useState(false);
20
+ const DEFAULT_CREATE_ACTION = '_create';
21
+ useEffect(() => {
22
+ var _a;
23
+ if (!isEmpty(defaultValueCriteria) && !selectedInstance && !instance[property.id]) {
24
+ const updatedFilter = cleanDeep({
25
+ where: transformToWhere({ $and: [defaultValueCriteria, (_a = filter === null || filter === void 0 ? void 0 : filter.where) !== null && _a !== void 0 ? _a : {}] }),
26
+ order: orderBy && sortBy ? encodeURIComponent(sortBy + ' ' + orderBy) : undefined,
27
+ limit: 1,
28
+ });
29
+ if (updatedFilter.where) {
30
+ setLoadingOptions(true);
31
+ apiServices.get(getPrefixedUrl(`/objects/${property.objectId}/instances?filter=${encodeURIComponent(JSON.stringify(updatedFilter))}`), (error, instances) => {
32
+ if (error) {
33
+ console.error(error);
34
+ setLoadingOptions(false);
35
+ }
36
+ if (instances) {
37
+ setSelectedInstance(instances[0]);
38
+ handleChangeObjectProperty(property.id, { id: instances[0].id, name: instances[0].name });
39
+ }
40
+ setLoadingOptions(false);
41
+ });
42
+ }
43
+ }
44
+ }, [property, defaultValueCriteria, sortBy, orderBy, apiServices]);
45
+ const getDropdownOptions = useCallback((name) => {
46
+ setLoadingOptions(true);
47
+ let updatedFilter = cloneDeep(filter);
48
+ if (!updatedFilter) {
49
+ updatedFilter = {};
50
+ }
51
+ updatedFilter.limit = 100;
52
+ updatedFilter.order = 'name ASC';
53
+ const where = name
54
+ ? transformToWhere({
55
+ name: {
56
+ like: name,
57
+ options: 'i',
58
+ },
59
+ })
60
+ : {};
61
+ updatedFilter.where = updatedFilter.where
62
+ ? {
63
+ and: [updatedFilter.where, where],
64
+ }
65
+ : where;
66
+ apiServices.get(getPrefixedUrl(`/objects/${property.objectId}/instances?filter=${JSON.stringify(updatedFilter)}`), (error, instances) => {
67
+ if (error) {
68
+ console.error(error);
69
+ setLoadingOptions(false);
70
+ }
71
+ if (instances) {
72
+ normalizeDates(instances, relatedObject);
73
+ setOptions(instances);
74
+ setLoadingOptions(false);
75
+ }
76
+ });
77
+ }, [relatedObject, setLoadingOptions, setOptions, property, filter]);
78
+ useEffect(() => {
79
+ if (displayOption === 'dropdown') {
80
+ getDropdownOptions();
81
+ }
82
+ }, [property, filter, displayOption, getDropdownOptions]);
83
+ const debouncedGetDropdownOptions = useCallback(debounce(getDropdownOptions, 500), [
84
+ filter,
85
+ property,
86
+ getDropdownOptions,
87
+ ]);
88
+ useEffect(() => {
89
+ debouncedGetDropdownOptions(dropdownInput);
90
+ return () => debouncedGetDropdownOptions.cancel();
91
+ }, [dropdownInput, debouncedGetDropdownOptions]);
92
+ useEffect(() => {
93
+ apiServices.get(getPrefixedUrl(`/objects/${property.objectId}/effective?sanitizedVersion=true`), (error, object) => {
94
+ if (error) {
95
+ console.error(error);
96
+ }
97
+ else {
98
+ setRelatedObject(object);
99
+ }
100
+ });
101
+ }, [property]);
102
+ const handleClose = () => {
103
+ setOpenCreateDialog(false);
104
+ };
105
+ const compileExpression = (expression, instance) => {
106
+ const template = Handlebars.compile(expression);
107
+ return instance ? template(instance) : undefined;
108
+ };
109
+ const navigationSlug = defaultPages && property.objectId && defaultPages[property.objectId];
110
+ return (React.createElement(React.Fragment, null,
111
+ displayOption === 'dropdown' ? (React.createElement(React.Fragment, null,
112
+ React.createElement(Autocomplete, { id: id, fullWidth: true, open: openOptions, componentsProps: {
113
+ popper: {
114
+ modifiers: [
115
+ {
116
+ name: 'flip',
117
+ enabled: false,
118
+ },
119
+ ],
120
+ },
121
+ }, PaperComponent: ({ children }) => {
122
+ var _a;
123
+ return (React.createElement(Paper, { sx: {
124
+ borderRadius: '12px',
125
+ boxShadow: '0px 24px 48px 0px rgba(145, 158, 171, 0.2)',
126
+ '& .MuiAutocomplete-listbox': {
127
+ maxHeight: '25vh',
128
+ },
129
+ '& .MuiAutocomplete-noOptions': {
130
+ fontFamily: 'sans-serif',
131
+ fontSize: '14px',
132
+ paddingLeft: '24px',
133
+ color: 'rgba(145, 158, 171, 1)',
134
+ },
135
+ '& .MuiAutocomplete-loading': {
136
+ fontFamily: 'sans-serif',
137
+ fontSize: '14px',
138
+ paddingLeft: '24px',
139
+ color: 'rgba(145, 158, 171, 1)',
140
+ },
141
+ } },
142
+ children,
143
+ mode !== 'existingOnly' &&
144
+ ((_a = relatedObject === null || relatedObject === void 0 ? void 0 : relatedObject.actions) === null || _a === void 0 ? void 0 : _a.some((a) => a.id === DEFAULT_CREATE_ACTION)) && (React.createElement(Button, { fullWidth: true, sx: {
145
+ justifyContent: 'flex-start',
146
+ pl: 2,
147
+ minHeight: '48px',
148
+ borderTop: '1px solid rgba(145, 158, 171, 0.24)',
149
+ borderRadius: '0p 0pc 6px 6px',
150
+ paddingLeft: '22px',
151
+ fontWeight: 400,
152
+ }, onMouseDown: (e) => {
153
+ setOpenCreateDialog(true);
154
+ }, color: 'inherit' }, "+ Add New"))));
155
+ }, sx: {
156
+ '& button.MuiButtonBase-root': Object.assign({}, (!loadingOptions &&
157
+ (((_a = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _a === void 0 ? void 0 : _a.id) || (selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.id))
158
+ ? {
159
+ visibility: 'visible',
160
+ }
161
+ : {})),
162
+ }, noOptionsText: 'No options available', renderOption: (props, option) => {
163
+ var _a, _b, _c, _d;
164
+ return (React.createElement("li", Object.assign({}, props, { key: option.id }),
165
+ React.createElement(Box, null,
166
+ React.createElement(Typography, { sx: { marginLeft: '8px', fontSize: '14px' } }, option.label),
167
+ ((_b = (_a = relatedObject === null || relatedObject === void 0 ? void 0 : relatedObject.viewLayout) === null || _a === void 0 ? void 0 : _a.dropdown) === null || _b === void 0 ? void 0 : _b.secondaryTextExpression) ? (React.createElement(Typography, { sx: { marginLeft: '8px', fontSize: '14px', color: '#637381' } }, compileExpression((_d = (_c = relatedObject === null || relatedObject === void 0 ? void 0 : relatedObject.viewLayout) === null || _c === void 0 ? void 0 : _c.dropdown) === null || _d === void 0 ? void 0 : _d.secondaryTextExpression, options.find((o) => o.id === option.value)))) : null)));
168
+ }, onOpen: () => {
169
+ var _a;
170
+ if (((_a = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _a === void 0 ? void 0 : _a.id) || (selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.id)) {
171
+ setOpenOptions(false);
172
+ }
173
+ else {
174
+ setOpenOptions(true);
175
+ }
176
+ }, onClose: () => setOpenOptions(false), value: ((_b = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _b === void 0 ? void 0 : _b.id) || (selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.id)
177
+ ? {
178
+ value: (_e = (_d = (_c = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.id) !== null && _e !== void 0 ? _e : '',
179
+ label: (_h = (_g = (_f = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _f === void 0 ? void 0 : _f.name) !== null && _g !== void 0 ? _g : selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.name) !== null && _h !== void 0 ? _h : '',
180
+ }
181
+ : null, isOptionEqualToValue: (option, value) => {
182
+ if (typeof value === 'string') {
183
+ return option.value === value;
184
+ }
185
+ return option.value === (value === null || value === void 0 ? void 0 : value.value);
186
+ }, options: options.map((o) => ({ label: o.name, value: o.id })), getOptionLabel: (option) => {
187
+ var _a, _b;
188
+ return typeof option === 'string'
189
+ ? (_b = (_a = options.find((o) => o.id === option)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : ''
190
+ : option.label;
191
+ }, onKeyDownCapture: (e) => {
192
+ var _a;
193
+ if (((_a = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _a === void 0 ? void 0 : _a.id) || (selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.id)) {
194
+ e.preventDefault();
195
+ }
196
+ }, loading: loadingOptions, onChange: (event, value) => {
197
+ if (isNil(value)) {
198
+ setDropdownInput(undefined); // refresh search options
199
+ setSelectedInstance(undefined);
200
+ handleChangeObjectProperty(property.id, null);
201
+ }
202
+ else {
203
+ const selectedInstance = options.find((o) => o.id === (value === null || value === void 0 ? void 0 : value.value));
204
+ setSelectedInstance(selectedInstance);
205
+ handleChangeObjectProperty(property.id, pick(selectedInstance, 'id', 'name'));
206
+ }
207
+ }, selectOnFocus: false, onBlur: () => setDropdownInput(undefined), renderInput: (params) => {
208
+ var _a, _b;
209
+ return (React.createElement(TextField, Object.assign({}, params, { placeholder: 'Select', readOnly: !loadingOptions &&
210
+ !!(((_a = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _a === void 0 ? void 0 : _a.id) ||
211
+ (selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.id)), onChange: (event) => setDropdownInput(event.target.value), onClick: (e) => {
212
+ var _a, _b, _c, _d, _e, _f, _g;
213
+ if (navigationSlug &&
214
+ ['DIV', 'INPUT'].includes((_a = e.target) === null || _a === void 0 ? void 0 : _a.nodeName) &&
215
+ (((_b = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _b === void 0 ? void 0 : _b.id) ||
216
+ (selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.id))) {
217
+ navigateTo &&
218
+ navigateTo(navigationSlug.replace(':instanceId', (_e = (_d = (_c = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.id) !== null && _e !== void 0 ? _e : ''));
219
+ }
220
+ if (openOptions &&
221
+ ((_f = e.target) === null || _f === void 0 ? void 0 : _f.nodeName) === 'svg') {
222
+ setOpenOptions(false);
223
+ }
224
+ else if (!['DIV', 'INPUT'].includes((_g = e.target) === null || _g === void 0 ? void 0 : _g.nodeName) &&
225
+ !selectedInstance) {
226
+ setOptions(options);
227
+ setOpenOptions(true);
228
+ }
229
+ }, sx: Object.assign({}, (!loadingOptions &&
230
+ (((_b = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _b === void 0 ? void 0 : _b.id) ||
231
+ (selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.id))
232
+ ? {
233
+ '.MuiOutlinedInput-root': {
234
+ background: 'white',
235
+ border: 'auto',
236
+ '.MuiOutlinedInput-input': Object.assign({}, (navigationSlug
237
+ ? {
238
+ color: 'rgb(1, 78, 123)',
239
+ textDecoration: 'underline',
240
+ cursor: 'pointer',
241
+ }
242
+ : {})),
243
+ },
244
+ '& fieldset': { borderColor: 'auto' },
245
+ '&:hover .MuiOutlinedInput-notchedOutline': {
246
+ border: 'auto',
247
+ },
248
+ caretColor: 'white',
249
+ }
250
+ : {})) })));
251
+ }, readOnly: !loadingOptions && !canUpdateProperty, error: error }))) : (React.createElement(Box, { sx: {
252
+ padding: ((_k = (_j = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _j === void 0 ? void 0 : _j.name) !== null && _k !== void 0 ? _k : selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.name)
253
+ ? '16.5px 14px'
254
+ : '10.5px 0',
255
+ } },
256
+ ((_o = (_m = (_l = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _l === void 0 ? void 0 : _l.name) !== null && _m !== void 0 ? _m : selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.name) !== null && _o !== void 0 ? _o : '') && (React.createElement(Link, { sx: {
257
+ textDecoration: 'none',
258
+ marginRight: 1,
259
+ textDecorationLine: navigationSlug && (instance === null || instance === void 0 ? void 0 : instance[property.id]) && !isModal ? 'underline' : 'none',
260
+ cursor: navigationSlug && (instance === null || instance === void 0 ? void 0 : instance[property.id]) && !isModal ? 'pointer' : 'auto',
261
+ fontSize: '16px',
262
+ fontWeight: 400,
263
+ lineHeight: '24px',
264
+ textAlign: 'left',
265
+ color: navigationSlug && (instance === null || instance === void 0 ? void 0 : instance[property.id]) && !isModal ? '#0075A7' : '#212B36',
266
+ }, variant: "body2", href: navigationSlug && (instance === null || instance === void 0 ? void 0 : instance[property.id]) && !isModal
267
+ ? `${process.env.REACT_APP_API_ROOT ? '' : '/app'}${navigationSlug.replace(':instanceId', (_r = (_q = (_p = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _p === void 0 ? void 0 : _p.id) !== null && _q !== void 0 ? _q : selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.id) !== null && _r !== void 0 ? _r : '')}`
268
+ : undefined, "aria-label": (_t = (_s = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _s === void 0 ? void 0 : _s.name) !== null && _t !== void 0 ? _t : selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.name }, (_w = (_v = (_u = instance === null || instance === void 0 ? void 0 : instance[property.id]) === null || _u === void 0 ? void 0 : _u.name) !== null && _v !== void 0 ? _v : selectedInstance === null || selectedInstance === void 0 ? void 0 : selectedInstance.name) !== null && _w !== void 0 ? _w : '')),
269
+ canUpdateProperty &&
270
+ ((instance === null || instance === void 0 ? void 0 : instance[property.id]) || selectedInstance || (nestedFieldsView && (instance === null || instance === void 0 ? void 0 : instance.id))) ? (React.createElement(Tooltip, { title: `Unlink` },
271
+ React.createElement("span", null,
272
+ React.createElement(IconButton, { onClick: (event) => {
273
+ event.stopPropagation();
274
+ handleChangeObjectProperty(property.id, null);
275
+ setSelectedInstance(undefined);
276
+ }, sx: { p: 0, marginBottom: '4px' }, "aria-label": `Unlink` },
277
+ React.createElement(Close, { sx: { width: '20px', height: '20px' } }))))) : (React.createElement(Button, { sx: {
278
+ backgroundColor: '#DFE3E8',
279
+ color: '#212B36',
280
+ fontWeight: '700',
281
+ textTransform: 'capitalize',
282
+ '&:hover': {
283
+ backgroundColor: '#e6eaf0',
284
+ boxShadow: 'none',
285
+ },
286
+ '&:disabled': {
287
+ cursor: 'not-allowed',
288
+ pointerEvents: 'all',
289
+ },
290
+ boxShadow: 'none',
291
+ lineHeight: '2.75',
292
+ padding: '0 23px',
293
+ }, size: "small", variant: "contained", disableElevation: true, onClick: (event) => {
294
+ event.stopPropagation();
295
+ setOpenCreateDialog(true);
296
+ }, "aria-label": `Add`, disabled: !canUpdateProperty }, "Add")))),
297
+ openCreateDialog && (React.createElement(React.Fragment, null, nestedFieldsView ? (React.createElement(RelatedObjectInstance, { apiServices: apiServices, handleClose: handleClose, handleChangeObjectProperty: handleChangeObjectProperty, instance: instance, setSelectedInstance: setSelectedInstance, relatedObject: relatedObject, property: property, nestedFieldsView: nestedFieldsView, mode: mode, setSnackbarError: setSnackbarError, displayOption: displayOption, setOptions: setOptions, options: options, filter: filter, user: user })) : (React.createElement(Dialog, { fullWidth: true, maxWidth: "md", open: openCreateDialog, onClose: (e, reason) => reason !== 'backdropClick' && handleClose },
298
+ React.createElement(Typography, { sx: {
299
+ marginTop: '28px',
300
+ fontSize: '22px',
301
+ fontWeight: 700,
302
+ marginLeft: '24px',
303
+ marginBottom: '10px',
304
+ } }, `Add ${property.name}`),
305
+ React.createElement(RelatedObjectInstance, { apiServices: apiServices, handleClose: handleClose, handleChangeObjectProperty: handleChangeObjectProperty, instance: instance, setSnackbarError: setSnackbarError, setSelectedInstance: setSelectedInstance, nestedFieldsView: nestedFieldsView, relatedObject: relatedObject, property: property, mode: mode, displayOption: displayOption, setOptions: setOptions, options: options, filter: filter, user: user })))))));
306
+ };
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import { ApiServices, Obj, ObjectInstance, Property, Reference, UserAccount } from '@evoke-platform/context';
3
+ export declare type RelatedObjectInstanceProps = {
4
+ relatedObject?: Obj;
5
+ property: Property;
6
+ apiServices: ApiServices;
7
+ setSelectedInstance: (selectedInstance: ObjectInstance) => void;
8
+ handleChangeObjectProperty: (propertyId: string, instance?: Reference | null) => void;
9
+ instance: ObjectInstance;
10
+ handleClose: () => void;
11
+ mode: 'default' | 'existingOnly';
12
+ setSnackbarError?: (snackbarError: {
13
+ showAlert: boolean;
14
+ message?: string;
15
+ isError?: boolean;
16
+ }) => void;
17
+ nestedFieldsView?: boolean;
18
+ displayOption?: 'dropdown' | 'dialogBox';
19
+ setOptions: (options: ObjectInstance[]) => void;
20
+ options: ObjectInstance[];
21
+ filter?: Record<string, unknown>;
22
+ user?: UserAccount;
23
+ };
24
+ export declare const RelatedObjectInstance: (props: RelatedObjectInstanceProps) => JSX.Element;
@@ -0,0 +1,126 @@
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 { useAuthenticationContext, } from '@evoke-platform/context';
11
+ import { LocalDateTime } from '@js-joda/core';
12
+ import { isObject, pick } from 'lodash';
13
+ import React, { useState } from 'react';
14
+ import { InfoRounded } from '../../../../../icons';
15
+ import { Alert, Button, FormControlLabel, Radio, RadioGroup } from '../../../../core';
16
+ import { Box, Grid } from '../../../../layout';
17
+ import { Form } from '../../../Form';
18
+ import { getPrefixedUrl, normalizeDateTime, normalizeDates } from '../../utils';
19
+ import { InstanceLookup } from './InstanceLookup';
20
+ const styles = {
21
+ actionButtons: {
22
+ padding: '8px 8px 24px 8px',
23
+ marginRight: '18px',
24
+ marginBotton: '16px',
25
+ display: 'flex',
26
+ justifyContent: 'flex-end',
27
+ alignItems: 'center',
28
+ },
29
+ };
30
+ const DEFAULT_CREATE_ACTION = '_create';
31
+ export const RelatedObjectInstance = (props) => {
32
+ var _a;
33
+ const { relatedObject, property, setSelectedInstance, handleChangeObjectProperty, handleClose, apiServices, setSnackbarError, nestedFieldsView, mode, displayOption, setOptions, options, filter, user, } = props;
34
+ const [relationType, setRelationType] = useState(displayOption === 'dropdown' ? 'new' : 'existing');
35
+ const [selectedRow, setSelectedRow] = useState();
36
+ const [errors, setErrors] = useState([]);
37
+ const userAccount = user !== null && user !== void 0 ? user : (_a = useAuthenticationContext()) === null || _a === void 0 ? void 0 : _a.account;
38
+ const linkExistingInstance = () => __awaiter(void 0, void 0, void 0, function* () {
39
+ if (selectedRow) {
40
+ setSelectedInstance(selectedRow);
41
+ handleChangeObjectProperty(property.id, pick(selectedRow, 'id', 'name'));
42
+ }
43
+ onClose();
44
+ });
45
+ const queryAddresses = (query) => __awaiter(void 0, void 0, void 0, function* () {
46
+ return yield apiServices.get(getPrefixedUrl(`/locations/search`), {
47
+ params: { query: query },
48
+ });
49
+ });
50
+ const onClose = () => {
51
+ handleClose();
52
+ setErrors([]);
53
+ };
54
+ const createNewInstance = (submission) => __awaiter(void 0, void 0, void 0, function* () {
55
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
56
+ if (!relatedObject) {
57
+ // Handle the case where relatedObject is undefined
58
+ return { isSuccessful: false };
59
+ }
60
+ let isSuccessful = false;
61
+ let error;
62
+ if (isObject(submission)) {
63
+ // date-time fields are stored in the database in ISO format so convert all
64
+ // LocalDateTime objects to ISO format.
65
+ submission = Object.entries(submission).reduce((agg, [key, value]) => Object.assign(agg, {
66
+ [key]: value instanceof LocalDateTime ? normalizeDateTime(value) : value,
67
+ }), {});
68
+ }
69
+ try {
70
+ const instance = yield apiServices.post(getPrefixedUrl(`/objects/${relatedObject.id}/instances/actions`), {
71
+ actionId: DEFAULT_CREATE_ACTION,
72
+ input: submission,
73
+ });
74
+ handleChangeObjectProperty(property.id, pick(instance, 'id', 'name'));
75
+ setSelectedInstance(instance);
76
+ setSnackbarError && setSnackbarError({ showAlert: true, message: 'New instance created', isError: false });
77
+ normalizeDates([instance]);
78
+ setOptions(options.concat([instance]));
79
+ onClose();
80
+ isSuccessful = true;
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ }
83
+ catch (err) {
84
+ setSnackbarError &&
85
+ setSnackbarError({
86
+ showAlert: true,
87
+ message: (_k = (_g = (_f = (_e = (_d = (_c = (_b = err.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.details) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.message) !== null && _g !== void 0 ? _g : (_j = (_h = err.data) === null || _h === void 0 ? void 0 : _h.error) === null || _j === void 0 ? void 0 : _j.message) !== null && _k !== void 0 ? _k : `An error occurred. The new instance was not created.`,
88
+ isError: true,
89
+ });
90
+ error = (_m = (_l = err.response) === null || _l === void 0 ? void 0 : _l.data) === null || _m === void 0 ? void 0 : _m.error;
91
+ onClose();
92
+ }
93
+ return { isSuccessful, error };
94
+ });
95
+ return (React.createElement(Box, { sx: { background: nestedFieldsView ? '#F4F6F8' : 'none', borderRadius: '8px' } },
96
+ React.createElement(Box, { sx: { padding: '8px 24px 20px', '.MuiInputBase-root': { background: '#FFFF', borderRadius: '8px' } } },
97
+ !nestedFieldsView && displayOption !== 'dropdown' && mode !== 'existingOnly' && (React.createElement(Grid, { container: true },
98
+ React.createElement(Grid, { container: true, item: true },
99
+ React.createElement(RadioGroup, { row: true, "aria-labelledby": "related-object-link-type", onChange: (event) => {
100
+ event.target.value === 'existing' && setErrors([]);
101
+ setRelationType(event.target.value);
102
+ }, value: relationType },
103
+ React.createElement(FormControlLabel, { value: "existing", control: React.createElement(Radio, null), label: "Existing" }),
104
+ React.createElement(FormControlLabel, { value: "new", control: React.createElement(Radio, null), label: "New" }))))),
105
+ (errors === null || errors === void 0 ? void 0 : errors.length) ? (React.createElement(Alert, { severity: "error", sx: { margin: '10px 0', borderRadius: '8px' }, icon: React.createElement(InfoRounded, { sx: { color: '#A22723' } }) }, errors.length === 1 ? (React.createElement(React.Fragment, null,
106
+ "There is ",
107
+ React.createElement("strong", null, "1"),
108
+ " error")) : (React.createElement(React.Fragment, null,
109
+ "There are ",
110
+ React.createElement("strong", null, errors.length),
111
+ " errors")))) : undefined,
112
+ relationType === 'new' ? (React.createElement(Box, { sx: { width: '100%' } },
113
+ React.createElement(Form, { actionId: "_create", actionType: "create", object: relatedObject, onSave: createNewInstance, submitButtonLabel: 'Add', closeModal: onClose, apiServices: apiServices, clearable: true, objectInputCommonProps: {
114
+ apiServices: apiServices,
115
+ setSnackbarError: setSnackbarError,
116
+ }, queryAddresses: queryAddresses, user: userAccount }))) : (relatedObject && (React.createElement(React.Fragment, null,
117
+ React.createElement(InstanceLookup, { apiServices: apiServices, nestedFieldsView: nestedFieldsView, setRelationType: setRelationType, object: relatedObject, setSelectedInstance: setSelectedRow, mode: mode, filter: filter }))))),
118
+ relationType !== 'new' && (React.createElement(Box, { sx: styles.actionButtons },
119
+ React.createElement(Button, { onClick: onClose, color: 'inherit', sx: {
120
+ border: '1px solid #ced4da',
121
+ width: '75px',
122
+ marginRight: '0px',
123
+ color: 'black',
124
+ } }, "Cancel"),
125
+ React.createElement(Button, { sx: { marginLeft: '8px', width: '85px', '&:hover': { boxShadow: 'none' } }, onClick: linkExistingInstance, variant: "contained" }, "Add")))));
126
+ };
@@ -0,0 +1,21 @@
1
+ /// <reference types="react" />
2
+ import { Action, ApiServices, Obj, Property, UserAccount } from '@evoke-platform/context';
3
+ import { ObjectPropertyInputProps } from '../../types';
4
+ export declare type ActionDialogProps = {
5
+ open: boolean;
6
+ onClose: () => void;
7
+ action: Action;
8
+ instanceInput: Record<string, unknown>;
9
+ handleSubmit: (actionType: 'delete' | 'update' | 'create', input: Record<string, unknown> | undefined, instanceId?: string, setSubmitting?: (value: boolean) => void) => Promise<{
10
+ isSuccessful: boolean;
11
+ error?: Record<string, unknown>;
12
+ }>;
13
+ object: Obj;
14
+ objectInputCommonProps: ObjectPropertyInputProps;
15
+ instanceId?: string;
16
+ relatedProperty?: Property;
17
+ apiServices: ApiServices;
18
+ queryAddresses?: unknown;
19
+ user?: UserAccount;
20
+ };
21
+ export declare const ActionDialog: (props: ActionDialogProps) => JSX.Element;
@@ -0,0 +1,96 @@
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 { concat } from 'lodash';
11
+ import React, { useEffect, useState } from 'react';
12
+ import { Close } from '../../../../../icons';
13
+ import { Button, Dialog, DialogContent, DialogTitle, IconButton, LoadingButton, Skeleton, Typography, } from '../../../../core';
14
+ import { ErrorComponent, Form } from '../../../../custom';
15
+ import { Box } from '../../../../layout';
16
+ import { convertComponentsToForm, convertFormToComponents, getPrefixedUrl } from '../../utils';
17
+ const styles = {
18
+ button: {
19
+ textTransform: 'initial',
20
+ fontSize: '14px',
21
+ fontWeight: 700,
22
+ marginRight: '10px',
23
+ },
24
+ dialogTitle: {
25
+ fontSize: '18px',
26
+ fontWeight: 700,
27
+ paddingTop: '35px',
28
+ paddingBottom: '20px',
29
+ },
30
+ closeIcon: {
31
+ position: 'absolute',
32
+ right: '17px',
33
+ top: '22px',
34
+ },
35
+ cancelBtn: {
36
+ border: '1px solid #ced4da',
37
+ width: '75px',
38
+ marginRight: '10px',
39
+ color: 'black',
40
+ },
41
+ deleteBtn: {
42
+ color: '#ffffff',
43
+ backgroundColor: '#A12723',
44
+ '&:hover': { backgroundColor: '#A12723' },
45
+ },
46
+ };
47
+ export const ActionDialog = (props) => {
48
+ const { open, onClose, action, instanceInput, handleSubmit, apiServices, object, instanceId, relatedProperty, objectInputCommonProps, queryAddresses, user, } = props;
49
+ const [updatedObject, setUpdatedObject] = useState();
50
+ const [hasAccess, setHasAccess] = useState();
51
+ const [loading, setLoading] = useState(false);
52
+ const [submitting, setSubmitting] = useState(false);
53
+ useEffect(() => {
54
+ if (instanceId) {
55
+ setLoading(true);
56
+ apiServices.get(getPrefixedUrl(`/objects/${object.id}/instances/${instanceId}/checkAccess`), {
57
+ params: { action: 'execute', field: action.id },
58
+ }, (error, result) => {
59
+ var _a;
60
+ setHasAccess((_a = result === null || result === void 0 ? void 0 : result.result) !== null && _a !== void 0 ? _a : false);
61
+ setLoading(false);
62
+ });
63
+ }
64
+ else {
65
+ setHasAccess(true);
66
+ setLoading(false);
67
+ }
68
+ }, [object, instanceId]);
69
+ useEffect(() => {
70
+ var _a, _b, _c, _d, _e, _f;
71
+ const input = (((_a = action === null || action === void 0 ? void 0 : action.form) === null || _a === void 0 ? void 0 : _a.entries) && action.parameters) || (action === null || action === void 0 ? void 0 : action.inputProperties)
72
+ ? (_c = (((_b = action.form) === null || _b === void 0 ? void 0 : _b.entries) && action.parameters
73
+ ? convertFormToComponents(action.form.entries, action.parameters, object)
74
+ : action === null || action === void 0 ? void 0 : action.inputProperties)) === null || _c === void 0 ? void 0 : _c.filter((inputProperty) => (inputProperty === null || inputProperty === void 0 ? void 0 : inputProperty.key) !== (relatedProperty === null || relatedProperty === void 0 ? void 0 : relatedProperty.relatedPropertyId))
75
+ : undefined;
76
+ const updatedAction = Object.assign(Object.assign({}, action), { form: input ? { entries: convertComponentsToForm(input) } : undefined });
77
+ const properties = (_d = object === null || object === void 0 ? void 0 : object.properties) === null || _d === void 0 ? void 0 : _d.filter((prop) => (prop === null || prop === void 0 ? void 0 : prop.id) !== (relatedProperty === null || relatedProperty === void 0 ? void 0 : relatedProperty.relatedPropertyId));
78
+ setUpdatedObject(Object.assign(Object.assign({}, object), { properties, actions: concat((_f = (_e = object === null || object === void 0 ? void 0 : object.actions) === null || _e === void 0 ? void 0 : _e.filter((a) => (a === null || a === void 0 ? void 0 : a.id) !== action.id)) !== null && _f !== void 0 ? _f : [], [updatedAction]) }));
79
+ }, [object]);
80
+ return (React.createElement(Dialog, { maxWidth: 'md', fullWidth: true, open: open, onClose: (e, reason) => reason !== 'backdropClick' && onClose },
81
+ React.createElement(DialogTitle, { sx: styles.dialogTitle },
82
+ React.createElement(IconButton, { sx: styles.closeIcon, onClick: onClose },
83
+ React.createElement(Close, { fontSize: "small" })),
84
+ action && hasAccess && !loading ? action === null || action === void 0 ? void 0 : action.name : ''),
85
+ React.createElement(DialogContent, null, hasAccess ? (React.createElement(Box, { sx: { width: '100%', marginTop: '10px' } }, (action === null || action === void 0 ? void 0 : action.type) === 'delete' ? (React.createElement(React.Fragment, null,
86
+ React.createElement(Typography, null,
87
+ "Are you sure you want to delete this ", object === null || object === void 0 ? void 0 :
88
+ object.name,
89
+ "?"),
90
+ React.createElement(Box, { sx: { padding: '25ox 0 10px 0', display: 'flex', justifyContent: 'flex-end' } },
91
+ React.createElement(Button, { sx: Object.assign(Object.assign({}, styles.button), styles.cancelBtn), onClick: onClose }, "Cancel"),
92
+ React.createElement(LoadingButton, { sx: Object.assign(Object.assign({}, styles.button), styles.deleteBtn), onClick: () => handleSubmit('delete', undefined, instanceId, setSubmitting), loading: submitting }, "Delete")))) : (updatedObject && (React.createElement(Form, { actionId: action.id, actionType: action.type, apiServices: objectInputCommonProps.apiServices, object: updatedObject, instance: instanceInput, onSave: (data, setSubmitting) => __awaiter(void 0, void 0, void 0, function* () { return handleSubmit(action.type, data, instanceId, setSubmitting); }), objectInputCommonProps: objectInputCommonProps, closeModal: onClose, queryAddresses: queryAddresses, user: user }))))) : (React.createElement(React.Fragment, null, loading ? (React.createElement(React.Fragment, null,
93
+ React.createElement(Skeleton, { height: '30px', animation: 'wave' }),
94
+ React.createElement(Skeleton, { height: '30px', animation: 'wave' }),
95
+ React.createElement(Skeleton, { height: '30px', animation: 'wave' }))) : (React.createElement(ErrorComponent, { code: 'AccessDenied', message: 'You do not have permission to perform this action.', styles: { boxShadow: 'none' } })))))));
96
+ };
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import { ApiServices, ObjWithRoot, ObjectInstance, Property } from '@evoke-platform/context';
3
+ export declare type DropdownRepeatableFieldProps = {
4
+ id: string;
5
+ property: Property;
6
+ instance: ObjectInstance;
7
+ criteria?: object;
8
+ readOnly: boolean;
9
+ apiServices: ApiServices;
10
+ initialMiddleObjectInstances: ObjectInstance[];
11
+ middleObject: ObjWithRoot;
12
+ getMiddleObjectInstances: () => Promise<ObjectInstance[]>;
13
+ fieldHeight?: 'small' | 'medium';
14
+ };
15
+ export declare const DropdownRepeatableField: (props: DropdownRepeatableFieldProps) => JSX.Element;