@evoke-platform/ui-components 1.8.0-testing.4 → 1.8.0-testing.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/published/components/custom/Form/FormComponents/ObjectComponent/ObjectPropertyInput.js +4 -0
- package/dist/published/components/custom/Form/FormComponents/UserComponent/UserProperty.js +4 -0
- package/dist/published/components/custom/FormV2/FormRenderer.d.ts +4 -0
- package/dist/published/components/custom/FormV2/FormRenderer.js +13 -14
- package/dist/published/components/custom/FormV2/FormRendererContainer.d.ts +4 -0
- package/dist/published/components/custom/FormV2/FormRendererContainer.js +60 -108
- package/dist/published/components/custom/FormV2/components/FormContext.d.ts +4 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/ActionDialog.d.ts +9 -5
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/ActionDialog.js +12 -24
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/RepeatableField.d.ts +5 -1
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/RepeatableField.js +80 -30
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/InstanceLookup.js +1 -1
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/ObjectPropertyInput.js +51 -27
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/RelatedObjectInstance.d.ts +5 -5
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/RelatedObjectInstance.js +45 -7
- package/dist/published/components/custom/FormV2/components/RecursiveEntryRenderer.js +7 -4
- package/dist/published/components/custom/FormV2/components/ValidationFiles/ValidationErrorDisplay.d.ts +3 -0
- package/dist/published/components/custom/FormV2/components/ValidationFiles/ValidationErrorDisplay.js +1 -3
- package/dist/published/components/custom/FormV2/components/types.d.ts +7 -1
- package/dist/published/components/custom/FormV2/components/utils.d.ts +27 -2
- package/dist/published/components/custom/FormV2/components/utils.js +107 -1
- package/dist/published/theme/hooks.d.ts +4 -0
- package/package.json +2 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useApiServices, useNotification, } from '@evoke-platform/context';
|
|
2
|
-
import {
|
|
3
|
-
import { get, isEqual, isObject, pick, startCase } from 'lodash';
|
|
2
|
+
import { get, isEqual, pick, startCase } from 'lodash';
|
|
4
3
|
import { DateTime } from 'luxon';
|
|
5
4
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
6
5
|
import sift from 'sift';
|
|
@@ -11,7 +10,7 @@ import { Accordion, AccordionDetails, AccordionSummary, Button, IconButton, Skel
|
|
|
11
10
|
import { Box } from '../../../../../layout';
|
|
12
11
|
import { getReadableQuery } from '../../../../CriteriaBuilder';
|
|
13
12
|
import { retrieveCustomErrorMessage } from '../../../../Form/utils';
|
|
14
|
-
import {
|
|
13
|
+
import { deleteDocuments, formatSubmission, getPrefixedUrl, transformToWhere } from '../../utils';
|
|
15
14
|
import { ActionDialog } from './ActionDialog';
|
|
16
15
|
import { DocumentViewerCell } from './DocumentViewerCell';
|
|
17
16
|
const styles = {
|
|
@@ -36,7 +35,7 @@ const styles = {
|
|
|
36
35
|
},
|
|
37
36
|
};
|
|
38
37
|
const RepeatableField = (props) => {
|
|
39
|
-
const { fieldDefinition, canUpdateProperty, criteria, viewLayout } = props;
|
|
38
|
+
const { fieldDefinition, canUpdateProperty, criteria, viewLayout, entry, createActionId, updateActionId, deleteActionId, } = props;
|
|
40
39
|
const { fetchedOptions, setFetchedOptions, instance } = useFormContext();
|
|
41
40
|
const { instanceChanges } = useNotification();
|
|
42
41
|
const apiServices = useApiServices();
|
|
@@ -54,11 +53,49 @@ const RepeatableField = (props) => {
|
|
|
54
53
|
const [hasCreateAction, setHasCreateAction] = useState(fetchedOptions[`${fieldDefinition.id}HasCreateAction`] || false);
|
|
55
54
|
const [loading, setLoading] = useState((relatedObject && relatedInstances) || !fieldDefinition ? false : true);
|
|
56
55
|
const [tableViewLayout, setTableViewLayout] = useState(fetchedOptions[`${fieldDefinition.id}TableViewLayout`]);
|
|
56
|
+
const [createForm, setCreateForm] = useState(fetchedOptions[`${fieldDefinition.id}-createForm`]);
|
|
57
|
+
const [updateForm, setUpdateForm] = useState(fetchedOptions[`${fieldDefinition.id}-updateForm`]);
|
|
58
|
+
const [deleteForm, setDeleteForm] = useState(fetchedOptions[`${fieldDefinition.id}-deleteForm`]);
|
|
57
59
|
const [snackbarError, setSnackbarError] = useState({
|
|
58
60
|
showAlert: false,
|
|
59
61
|
isError: false,
|
|
60
62
|
});
|
|
61
|
-
const
|
|
63
|
+
const createAction = relatedObject?.actions?.find((item) => item.id === createActionId);
|
|
64
|
+
const updateAction = relatedObject?.actions?.find((item) => item.id === updateActionId);
|
|
65
|
+
const deleteAction = relatedObject?.actions?.find((item) => item.id === deleteActionId);
|
|
66
|
+
function getForm(setForm, action, formId) {
|
|
67
|
+
if (formId || action?.defaultFormId) {
|
|
68
|
+
apiServices
|
|
69
|
+
.get(getPrefixedUrl(`data/forms/${formId || action?.defaultFormId}`))
|
|
70
|
+
.then((evokeForm) => {
|
|
71
|
+
setForm(evokeForm);
|
|
72
|
+
})
|
|
73
|
+
.catch((error) => {
|
|
74
|
+
console.error(error);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else if (action) {
|
|
78
|
+
apiServices
|
|
79
|
+
.get(getPrefixedUrl('data/forms'), {
|
|
80
|
+
params: {
|
|
81
|
+
filter: {
|
|
82
|
+
where: {
|
|
83
|
+
actionId: action.id,
|
|
84
|
+
objectId: fieldDefinition.objectId,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
.then((matchingForms) => {
|
|
90
|
+
if (matchingForms.length === 1) {
|
|
91
|
+
setForm(matchingForms[0]);
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
.catch((error) => {
|
|
95
|
+
console.error(error);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
62
99
|
const fetchRelatedInstances = useCallback(async (refetch = false) => {
|
|
63
100
|
let relatedObject;
|
|
64
101
|
if (fieldDefinition.objectId) {
|
|
@@ -168,6 +205,14 @@ const RepeatableField = (props) => {
|
|
|
168
205
|
if (relatedObject)
|
|
169
206
|
fetchCriteriaObjects();
|
|
170
207
|
}, [fetchCriteriaObjects, relatedObject]);
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (createAction && !createForm)
|
|
210
|
+
getForm(setCreateForm, createAction); // TODO: pass entry.display?.createForm as a third argument
|
|
211
|
+
if (updateAction && !updateForm)
|
|
212
|
+
getForm(setUpdateForm, updateAction); // TODO: pass entry.display?.updateForm as a third argument
|
|
213
|
+
if (deleteAction && !deleteForm)
|
|
214
|
+
getForm(setDeleteForm, deleteAction); // TODO: pass entry.display?.deleteForm as a third argument
|
|
215
|
+
}, [entry.display, createAction, updateAction, deleteAction]);
|
|
171
216
|
useEffect(() => {
|
|
172
217
|
if (relatedObject?.rootObjectId) {
|
|
173
218
|
// pass true here so while it doesn't refetch on every tab change it does refetch on changes made
|
|
@@ -226,11 +271,7 @@ const RepeatableField = (props) => {
|
|
|
226
271
|
})
|
|
227
272
|
.then((checkAccess) => {
|
|
228
273
|
const action = relatedObject.actions?.find((item) => item.id === '_create');
|
|
229
|
-
if (action &&
|
|
230
|
-
fieldDefinition.relatedPropertyId &&
|
|
231
|
-
// TODO: replace with the entries create form or defaultFormId of the
|
|
232
|
-
// default create action, keeping it like this to get minimum changes out so other can use it
|
|
233
|
-
!!fieldDefinition.createForm) {
|
|
274
|
+
if (action && fieldDefinition.relatedPropertyId) {
|
|
234
275
|
const { relatedObjectProperty, criteria } = retrieveCriteria(fieldDefinition.relatedPropertyId, action, relatedObject);
|
|
235
276
|
if (!criteria || JSON.stringify(criteria).includes('{{{input.') || !relatedObjectProperty) {
|
|
236
277
|
setHasCreateAction(checkAccess.result);
|
|
@@ -301,22 +342,17 @@ const RepeatableField = (props) => {
|
|
|
301
342
|
},
|
|
302
343
|
'min-width': '44px',
|
|
303
344
|
}, variant: "text", onClick: () => setReloadOnErrorTrigger((prevState) => !prevState) }, "Retry")));
|
|
304
|
-
const save = async (
|
|
305
|
-
//
|
|
306
|
-
|
|
307
|
-
if (
|
|
308
|
-
input = Object.entries(input).reduce((agg, [key, value]) => Object.assign(agg, {
|
|
309
|
-
[key]: value instanceof LocalDateTime ? normalizeDateTime(value) : value,
|
|
310
|
-
}), {});
|
|
311
|
-
}
|
|
312
|
-
if (actionType === 'create') {
|
|
345
|
+
const save = async (action, input, instanceId) => {
|
|
346
|
+
// when save is called we know that fieldDefinition is a parameter and fieldDefinition.objectId is defined
|
|
347
|
+
input = await formatSubmission(input, apiServices, fieldDefinition.objectId, instanceId);
|
|
348
|
+
if (action.type === 'create' && createActionId) {
|
|
313
349
|
const updatedInput = {
|
|
314
350
|
...input,
|
|
315
351
|
[fieldDefinition?.relatedPropertyId]: { id: instance?.id },
|
|
316
352
|
};
|
|
317
353
|
try {
|
|
318
354
|
const instance = await apiServices.post(getPrefixedUrl(`/objects/${fieldDefinition.objectId}/instances/actions`), {
|
|
319
|
-
actionId:
|
|
355
|
+
actionId: createActionId,
|
|
320
356
|
input: updatedInput,
|
|
321
357
|
});
|
|
322
358
|
const hasAccess = fieldDefinition?.relatedPropertyId && fieldDefinition.relatedPropertyId in instance;
|
|
@@ -337,13 +373,16 @@ const RepeatableField = (props) => {
|
|
|
337
373
|
else {
|
|
338
374
|
const relatedObjectId = relatedObject?.id;
|
|
339
375
|
try {
|
|
340
|
-
await apiServices.post(getPrefixedUrl(`/objects/${relatedObjectId}/instances/${instanceId}/actions`), {
|
|
341
|
-
actionId: `_${
|
|
376
|
+
const response = await apiServices.post(getPrefixedUrl(`/objects/${relatedObjectId}/instances/${instanceId}/actions`), {
|
|
377
|
+
actionId: `_${action.type}`,
|
|
342
378
|
input: pick(input, relatedObject?.properties
|
|
343
379
|
?.filter((property) => !property.formula && property.type !== 'collection')
|
|
344
380
|
.map((property) => property.id) ?? []),
|
|
345
381
|
});
|
|
346
|
-
if (
|
|
382
|
+
if (response && relatedObject && instance) {
|
|
383
|
+
deleteDocuments(input, !!response, apiServices, relatedObject, instance, action);
|
|
384
|
+
}
|
|
385
|
+
if (action.type === 'delete') {
|
|
347
386
|
setRelatedInstances((prevInstances) => prevInstances.filter((instance) => instance.id !== instanceId));
|
|
348
387
|
}
|
|
349
388
|
else {
|
|
@@ -357,7 +396,7 @@ const RepeatableField = (props) => {
|
|
|
357
396
|
setSnackbarError({
|
|
358
397
|
showAlert: true,
|
|
359
398
|
message: retrieveCustomErrorMessage(err) ??
|
|
360
|
-
`An error occurred while ${
|
|
399
|
+
`An error occurred while ${action.type === 'delete' ? ' deleting' : ' updating'} an instance`,
|
|
361
400
|
isError: true,
|
|
362
401
|
});
|
|
363
402
|
}
|
|
@@ -501,7 +540,7 @@ const RepeatableField = (props) => {
|
|
|
501
540
|
cursor: 'pointer',
|
|
502
541
|
},
|
|
503
542
|
}
|
|
504
|
-
: {}, onClick:
|
|
543
|
+
: {}, onClick: updateActionId &&
|
|
505
544
|
canUpdateProperty &&
|
|
506
545
|
prop.id === 'name'
|
|
507
546
|
? () => editRow(relatedInstance.id)
|
|
@@ -511,16 +550,27 @@ const RepeatableField = (props) => {
|
|
|
511
550
|
users?.find((user) => get(relatedInstance, `${prop.id.split('.')[0]}.id`) === user.id)?.status === 'Inactive' && (React.createElement("span", null, ' (Inactive)'))))));
|
|
512
551
|
}),
|
|
513
552
|
canUpdateProperty && (React.createElement(TableCell, { sx: { width: '80px' } },
|
|
514
|
-
|
|
515
|
-
React.createElement(IconButton, { "aria-label": `edit-collection-instance-${index}`, onClick: () => editRow(relatedInstance.id) },
|
|
553
|
+
updateActionId && (React.createElement(IconButton, { "aria-label": `edit-collection-instance-${index}`, onClick: () => editRow(relatedInstance.id) },
|
|
516
554
|
React.createElement(Tooltip, { title: "Edit" },
|
|
517
555
|
React.createElement(Edit, null)))),
|
|
518
556
|
React.createElement(IconButton, { "aria-label": `delete-collection-instance-${index}`, onClick: () => deleteRow(relatedInstance.id) },
|
|
519
557
|
React.createElement(Tooltip, { title: "Delete" },
|
|
520
558
|
React.createElement(TrashCan, { sx: { ':hover': { color: '#A12723' } } })))))))))))),
|
|
521
|
-
hasCreateAction && (React.createElement(Button, { variant: "contained", sx: styles.addButton, onClick: addRow, "aria-label": 'Add' }, "Add"))),
|
|
522
|
-
relatedObject && openDialog && (React.createElement(ActionDialog, { object: relatedObject, open: openDialog, onClose: () => setOpenDialog(false),
|
|
523
|
-
(dialogType === 'create'
|
|
559
|
+
hasCreateAction && createActionId && (React.createElement(Button, { variant: "contained", sx: styles.addButton, onClick: addRow, "aria-label": 'Add' }, "Add"))),
|
|
560
|
+
relatedObject && openDialog && (React.createElement(ActionDialog, { object: relatedObject, open: openDialog, onClose: () => setOpenDialog(false), handleSubmit: save, action: relatedObject?.actions?.find((a) => a.id ===
|
|
561
|
+
(dialogType === 'create'
|
|
562
|
+
? createActionId
|
|
563
|
+
: dialogType === 'update'
|
|
564
|
+
? updateActionId
|
|
565
|
+
: deleteActionId)), relatedFormId: dialogType === 'create'
|
|
566
|
+
? createForm?.id
|
|
567
|
+
: dialogType === 'update'
|
|
568
|
+
? updateForm?.id
|
|
569
|
+
: dialogType === 'delete'
|
|
570
|
+
? deleteForm?.id
|
|
571
|
+
: undefined, instanceId: selectedRow, relatedParameter: fieldDefinition, associatedObject: instance?.id && fieldDefinition.relatedPropertyId
|
|
572
|
+
? { instanceId: instance.id, propertyId: fieldDefinition.relatedPropertyId }
|
|
573
|
+
: undefined })),
|
|
524
574
|
React.createElement(Snackbar, { open: snackbarError.showAlert, handleClose: () => setSnackbarError({ isError: snackbarError.isError, showAlert: false }), message: snackbarError.message, error: snackbarError.isError })));
|
|
525
575
|
};
|
|
526
576
|
export default RepeatableField;
|
|
@@ -193,7 +193,7 @@ const InstanceLookup = (props) => {
|
|
|
193
193
|
setRows([]);
|
|
194
194
|
}
|
|
195
195
|
}, [filter, searchString.length]);
|
|
196
|
-
return (React.createElement(Grid, { container: true, sx: {
|
|
196
|
+
return (React.createElement(Grid, { container: true, sx: { padding: '30px 24px' } },
|
|
197
197
|
React.createElement(Grid, { item: true, xs: 12 }, searchableColumns.length ? (React.createElement(SearchField, { searchString: searchString, setSearchString: setSearchString, filter: filter, setFilter: setFilter, searchableColumns: searchableColumns })) : (React.createElement(Typography, { sx: { fontSize: '16px', fontWeight: '700' } }, "There are no searchable properties configured for this object"))),
|
|
198
198
|
React.createElement(BuilderGrid, { item: 'instances', rows: rows, columns: retrieveColumns(layout), onRowClick: (params) => setSelectedInstance(params.row), initialSort: {
|
|
199
199
|
field: object.viewLayout?.table?.sort?.colId ?? 'name',
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { useApiServices, useApp, useNavigate, } from '@evoke-platform/context';
|
|
2
2
|
import cleanDeep from 'clean-deep';
|
|
3
|
-
import { cloneDeep, debounce, isEmpty, isNil } from 'lodash';
|
|
3
|
+
import { cloneDeep, debounce, isEmpty, isEqual, isNil } from 'lodash';
|
|
4
4
|
import Handlebars from 'no-eval-handlebars';
|
|
5
|
-
import React, { useCallback, useEffect, useState } from 'react';
|
|
5
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
6
6
|
import { Close } from '../../../../../../icons';
|
|
7
7
|
import { useFormContext } from '../../../../../../theme/hooks';
|
|
8
|
-
import { Autocomplete, Button, Dialog, IconButton, Link, Paper, Snackbar, TextField, Tooltip, Typography, } from '../../../../../core';
|
|
8
|
+
import { Autocomplete, Button, Dialog, DialogContent, DialogTitle, IconButton, Link, Paper, Snackbar, TextField, Tooltip, Typography, } from '../../../../../core';
|
|
9
9
|
import { Box } from '../../../../../layout';
|
|
10
10
|
import { encodePageSlug, getDefaultPages, getPrefixedUrl, transformToWhere } from '../../utils';
|
|
11
11
|
import RelatedObjectInstance from './RelatedObjectInstance';
|
|
12
12
|
const ObjectPropertyInput = (props) => {
|
|
13
|
-
const { id, fieldDefinition, nestedFieldsView, readOnly, error, mode, displayOption, filter, defaultValueCriteria, sortBy, orderBy, isModal, initialValue, viewLayout, hasDescription, } = props;
|
|
13
|
+
const { id, fieldDefinition, nestedFieldsView, readOnly, error, mode, displayOption, filter, defaultValueCriteria, sortBy, orderBy, isModal, initialValue, viewLayout, hasDescription, createActionId, formId, } = props;
|
|
14
14
|
const { fetchedOptions, setFetchedOptions, parameters, fieldHeight, handleChange: handleChangeObjectField, instance, } = useFormContext();
|
|
15
15
|
const { defaultPages, findDefaultPageSlugFor } = useApp();
|
|
16
16
|
const [selectedInstance, setSelectedInstance] = useState(initialValue || undefined);
|
|
@@ -30,15 +30,12 @@ const ObjectPropertyInput = (props) => {
|
|
|
30
30
|
showAlert: false,
|
|
31
31
|
isError: true,
|
|
32
32
|
});
|
|
33
|
-
const
|
|
34
|
-
const action = relatedObject?.actions?.find((action) => action.id === DEFAULT_CREATE_ACTION);
|
|
33
|
+
const action = relatedObject?.actions?.find((action) => action.id === createActionId);
|
|
35
34
|
const apiServices = useApiServices();
|
|
36
35
|
const navigateTo = useNavigate();
|
|
37
|
-
const updatedCriteria =
|
|
38
|
-
? {
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
: undefined;
|
|
36
|
+
const updatedCriteria = useMemo(() => {
|
|
37
|
+
return filter ? { where: transformToWhere(filter) } : undefined;
|
|
38
|
+
}, [filter]);
|
|
42
39
|
useEffect(() => {
|
|
43
40
|
if (relatedObject) {
|
|
44
41
|
let defaultViewLayout;
|
|
@@ -94,10 +91,12 @@ const ObjectPropertyInput = (props) => {
|
|
|
94
91
|
}
|
|
95
92
|
}, [fieldDefinition, defaultValueCriteria, sortBy, orderBy]);
|
|
96
93
|
const getDropdownOptions = useCallback((name) => {
|
|
97
|
-
if ((!fetchedOptions[`${id}Options`] ||
|
|
98
|
-
fetchedOptions[`${id}Options`].length === 0) &&
|
|
99
|
-
!hasFetched)
|
|
94
|
+
if (((!fetchedOptions?.[`${id}Options`] ||
|
|
95
|
+
(fetchedOptions?.[`${id}Options`]).length === 0) &&
|
|
96
|
+
!hasFetched) ||
|
|
97
|
+
!isEqual(fetchedOptions?.[`${id}UpdatedCriteria`], updatedCriteria)) {
|
|
100
98
|
setLoadingOptions(true);
|
|
99
|
+
setFetchedOptions && setFetchedOptions({ [`${id}UpdatedCriteria`]: updatedCriteria });
|
|
101
100
|
const updatedFilter = cloneDeep(updatedCriteria) || {};
|
|
102
101
|
updatedFilter.limit = 100;
|
|
103
102
|
const { propertyId, direction } = layout?.sort ?? {
|
|
@@ -146,17 +145,38 @@ const ObjectPropertyInput = (props) => {
|
|
|
146
145
|
return () => debouncedGetDropdownOptions.cancel();
|
|
147
146
|
}, [dropdownInput]);
|
|
148
147
|
useEffect(() => {
|
|
149
|
-
if (action?.defaultFormId) {
|
|
148
|
+
if (formId || action?.defaultFormId) {
|
|
150
149
|
apiServices
|
|
151
|
-
.get(getPrefixedUrl(`data/forms/${action
|
|
150
|
+
.get(getPrefixedUrl(`data/forms/${formId || action?.defaultFormId}`))
|
|
152
151
|
.then((evokeForm) => {
|
|
153
152
|
setForm(evokeForm);
|
|
154
153
|
})
|
|
155
154
|
.catch((error) => {
|
|
156
|
-
console.error(
|
|
155
|
+
console.error(error);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
else if (action) {
|
|
159
|
+
apiServices
|
|
160
|
+
.get(getPrefixedUrl('data/forms'), {
|
|
161
|
+
params: {
|
|
162
|
+
filter: {
|
|
163
|
+
where: {
|
|
164
|
+
actionId: action.id,
|
|
165
|
+
objectId: fieldDefinition.objectId,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
})
|
|
170
|
+
.then((matchingForms) => {
|
|
171
|
+
if (matchingForms.length === 1) {
|
|
172
|
+
setForm(matchingForms[0]);
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
.catch((error) => {
|
|
176
|
+
console.error(error);
|
|
157
177
|
});
|
|
158
178
|
}
|
|
159
|
-
}, [action]);
|
|
179
|
+
}, [action, formId]);
|
|
160
180
|
useEffect(() => {
|
|
161
181
|
if (!fetchedOptions[`${id}RelatedObject`]) {
|
|
162
182
|
apiServices.get(getPrefixedUrl(`/objects/${fieldDefinition.objectId}/effective?sanitizedVersion=true`), (error, object) => {
|
|
@@ -254,7 +274,7 @@ const ObjectPropertyInput = (props) => {
|
|
|
254
274
|
},
|
|
255
275
|
} },
|
|
256
276
|
mode !== 'newOnly' && children,
|
|
257
|
-
mode !== 'existingOnly' &&
|
|
277
|
+
mode !== 'existingOnly' && createActionId && (React.createElement(Button, { fullWidth: true, sx: {
|
|
258
278
|
justifyContent: 'flex-start',
|
|
259
279
|
pl: 2,
|
|
260
280
|
minHeight: '48px',
|
|
@@ -422,15 +442,19 @@ const ObjectPropertyInput = (props) => {
|
|
|
422
442
|
event.stopPropagation();
|
|
423
443
|
setOpenCreateDialog(true);
|
|
424
444
|
}, "aria-label": `Add` }, "Add")))),
|
|
425
|
-
openCreateDialog && (React.createElement(React.Fragment, null, nestedFieldsView ? (React.createElement(RelatedObjectInstance, { id: id, handleClose: handleClose, setSelectedInstance: setSelectedInstance, relatedObject: relatedObject, nestedFieldsView: nestedFieldsView, mode: mode, displayOption: displayOption, setOptions: setOptions, options: options, filter: updatedCriteria, layout: layout,
|
|
426
|
-
React.createElement(
|
|
427
|
-
|
|
428
|
-
fontSize: '22px',
|
|
445
|
+
openCreateDialog && (React.createElement(React.Fragment, null, nestedFieldsView ? (React.createElement(RelatedObjectInstance, { id: id, handleClose: handleClose, setSelectedInstance: setSelectedInstance, relatedObject: relatedObject, nestedFieldsView: nestedFieldsView, mode: mode, displayOption: displayOption, setOptions: setOptions, options: options, filter: updatedCriteria, layout: layout, formId: form?.id, actionId: createActionId, setSnackbarError: setSnackbarError, fieldDefinition: fieldDefinition })) : (React.createElement(Dialog, { fullWidth: true, maxWidth: "md", open: openCreateDialog, onClose: (e, reason) => reason !== 'backdropClick' && handleClose },
|
|
446
|
+
React.createElement(DialogTitle, { sx: {
|
|
447
|
+
fontSize: '18px',
|
|
429
448
|
fontWeight: 700,
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
449
|
+
paddingTop: '35px',
|
|
450
|
+
paddingBottom: '20px',
|
|
451
|
+
borderBottom: '1px solid #e9ecef',
|
|
452
|
+
} },
|
|
453
|
+
React.createElement(IconButton, { sx: { position: 'absolute', right: '17px', top: '22px' }, onClick: handleClose },
|
|
454
|
+
React.createElement(Close, { fontSize: "small" })),
|
|
455
|
+
form?.name ?? `Add ${fieldDefinition.name}`),
|
|
456
|
+
React.createElement(DialogContent, { sx: { padding: '0px' } },
|
|
457
|
+
React.createElement(RelatedObjectInstance, { handleClose: handleClose, setSelectedInstance: setSelectedInstance, nestedFieldsView: nestedFieldsView, relatedObject: relatedObject, id: id, mode: mode, displayOption: displayOption, setOptions: setOptions, options: options, filter: updatedCriteria, layout: layout, formId: formId ?? form?.id, actionId: createActionId, setSnackbarError: setSnackbarError, fieldDefinition: fieldDefinition })))))),
|
|
434
458
|
React.createElement(Snackbar, { open: snackbarError.showAlert, handleClose: () => setSnackbarError({
|
|
435
459
|
isError: snackbarError.isError,
|
|
436
460
|
showAlert: false,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InputParameter, Obj, ObjectInstance, TableViewLayout } from '@evoke-platform/context';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { BaseProps } from '../../types';
|
|
4
4
|
export type RelatedObjectInstanceProps = BaseProps & {
|
|
5
|
-
relatedObject: Obj | undefined;
|
|
6
5
|
id: string;
|
|
6
|
+
relatedObject: Obj | undefined;
|
|
7
7
|
setSelectedInstance: (selectedInstance: ObjectInstance) => void;
|
|
8
8
|
handleClose: () => void;
|
|
9
9
|
mode: 'default' | 'existingOnly' | 'newOnly';
|
|
@@ -18,9 +18,9 @@ export type RelatedObjectInstanceProps = BaseProps & {
|
|
|
18
18
|
options: ObjectInstance[];
|
|
19
19
|
filter?: Record<string, unknown>;
|
|
20
20
|
layout?: TableViewLayout;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
formId?: string;
|
|
22
|
+
actionId?: string;
|
|
23
|
+
fieldDefinition: InputParameter;
|
|
24
24
|
};
|
|
25
25
|
declare const RelatedObjectInstance: (props: RelatedObjectInstanceProps) => React.JSX.Element;
|
|
26
26
|
export default RelatedObjectInstance;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { useApiServices } from '@evoke-platform/context';
|
|
1
2
|
import { InfoRounded } from '@mui/icons-material';
|
|
2
3
|
import React, { useState } from 'react';
|
|
3
4
|
import { useFormContext } from '../../../../../../theme/hooks';
|
|
4
5
|
import { Alert, Button, FormControlLabel, Radio, RadioGroup } from '../../../../../core';
|
|
5
6
|
import { Box, Grid } from '../../../../../layout';
|
|
7
|
+
import FormRendererContainer from '../../../FormRendererContainer';
|
|
8
|
+
import { formatSubmission, getPrefixedUrl } from '../../utils';
|
|
6
9
|
import InstanceLookup from './InstanceLookup';
|
|
7
10
|
const styles = {
|
|
8
11
|
actionButtons: {
|
|
@@ -14,11 +17,12 @@ const styles = {
|
|
|
14
17
|
},
|
|
15
18
|
};
|
|
16
19
|
const RelatedObjectInstance = (props) => {
|
|
17
|
-
const { relatedObject, id, setSelectedInstance, handleClose, nestedFieldsView, mode, displayOption, filter, layout,
|
|
18
|
-
const { handleChange: handleChangeObjectField } = useFormContext();
|
|
20
|
+
const { relatedObject, id, setSelectedInstance, handleClose, nestedFieldsView, mode, displayOption, filter, layout, formId, actionId, fieldDefinition, setSnackbarError, setOptions, options, } = props;
|
|
21
|
+
const { handleChange: handleChangeObjectField, richTextEditor, stickyFooter, fieldHeight } = useFormContext();
|
|
19
22
|
const [errors, setErrors] = useState([]);
|
|
20
23
|
const [selectedRow, setSelectedRow] = useState();
|
|
21
24
|
const [relationType, setRelationType] = useState(displayOption === 'dropdown' ? 'new' : 'existing');
|
|
25
|
+
const apiServices = useApiServices();
|
|
22
26
|
const linkExistingInstance = async () => {
|
|
23
27
|
if (selectedRow) {
|
|
24
28
|
setSelectedInstance(selectedRow);
|
|
@@ -30,19 +34,53 @@ const RelatedObjectInstance = (props) => {
|
|
|
30
34
|
handleClose();
|
|
31
35
|
setErrors([]);
|
|
32
36
|
};
|
|
37
|
+
const createNewInstance = async (submission) => {
|
|
38
|
+
if (!relatedObject) {
|
|
39
|
+
// Handle the case where relatedObject is undefined
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
submission = await formatSubmission(submission, apiServices, relatedObject.id);
|
|
43
|
+
try {
|
|
44
|
+
await apiServices
|
|
45
|
+
.post(getPrefixedUrl(`/objects/${relatedObject.id}/instances/actions`), {
|
|
46
|
+
actionId: actionId,
|
|
47
|
+
input: submission,
|
|
48
|
+
})
|
|
49
|
+
.then((response) => {
|
|
50
|
+
handleChangeObjectField(id, response);
|
|
51
|
+
setSelectedInstance(response);
|
|
52
|
+
setSnackbarError({
|
|
53
|
+
showAlert: true,
|
|
54
|
+
message: 'New instance created',
|
|
55
|
+
isError: false,
|
|
56
|
+
});
|
|
57
|
+
setOptions(options.concat([response]));
|
|
58
|
+
onClose();
|
|
59
|
+
});
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
setSnackbarError({
|
|
64
|
+
showAlert: true,
|
|
65
|
+
message: err.response?.data?.error?.details?.[0]?.message ??
|
|
66
|
+
err.response?.data?.error?.message ??
|
|
67
|
+
`An error occurred. The new instance was not created.`,
|
|
68
|
+
isError: true,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
33
72
|
return (React.createElement(Box, { sx: {
|
|
34
73
|
background: nestedFieldsView ? '#F4F6F8' : 'none',
|
|
35
74
|
borderRadius: '8px',
|
|
36
75
|
} },
|
|
37
76
|
React.createElement(Box, { sx: {
|
|
38
|
-
padding: '8px 24px 0px',
|
|
39
77
|
'.MuiInputBase-root': { background: '#FFFF', borderRadius: '8px' },
|
|
40
78
|
} },
|
|
41
79
|
!nestedFieldsView &&
|
|
42
80
|
displayOption !== 'dropdown' &&
|
|
43
81
|
mode !== 'existingOnly' &&
|
|
44
82
|
mode !== 'newOnly' &&
|
|
45
|
-
|
|
83
|
+
actionId && (React.createElement(Grid, { container: true, sx: { paddingX: '24px' } },
|
|
46
84
|
React.createElement(Grid, { container: true, item: true },
|
|
47
85
|
React.createElement(RadioGroup, { row: true, "aria-labelledby": "related-object-link-type", onChange: (event) => {
|
|
48
86
|
event.target.value === 'existing' && setErrors([]);
|
|
@@ -57,9 +95,9 @@ const RelatedObjectInstance = (props) => {
|
|
|
57
95
|
"There are ",
|
|
58
96
|
React.createElement("strong", null, errors.length),
|
|
59
97
|
" errors")))) : undefined,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
React.createElement(InstanceLookup, { colspan: 12, nestedFieldsView: nestedFieldsView, setRelationType: setRelationType, object: relatedObject, setSelectedInstance: setSelectedRow, mode: mode, filter: filter, layout: layout }))))
|
|
98
|
+
relationType === 'new' || mode === 'newOnly' ? (React.createElement(Box, { sx: { width: '100%' } },
|
|
99
|
+
React.createElement(FormRendererContainer, { formId: formId, display: { fieldHeight: fieldHeight ?? 'medium' }, actionId: actionId, stickyFooter: stickyFooter, objectId: fieldDefinition.objectId, onClose: onClose, onSubmit: createNewInstance, richTextEditor: richTextEditor }))) : ((mode === 'default' || mode === 'existingOnly') &&
|
|
100
|
+
relatedObject && (React.createElement(InstanceLookup, { colspan: 12, nestedFieldsView: nestedFieldsView, setRelationType: setRelationType, object: relatedObject, setSelectedInstance: setSelectedRow, mode: mode, filter: filter, layout: layout })))),
|
|
63
101
|
relationType !== 'new' && mode !== 'newOnly' && (React.createElement(Box, { sx: styles.actionButtons },
|
|
64
102
|
React.createElement(Button, { onClick: onClose, color: 'inherit', sx: {
|
|
65
103
|
border: '1px solid #ced4da',
|
|
@@ -38,7 +38,7 @@ function getFieldWrapperProps(fieldDefinition, entry, entryId, fieldValue, displ
|
|
|
38
38
|
}
|
|
39
39
|
export function RecursiveEntryRenderer(props) {
|
|
40
40
|
const { entry, isDocument } = props;
|
|
41
|
-
const { fetchedOptions, setFetchedOptions, object, getValues, errors, instance, richTextEditor, parameters, handleChange, fieldHeight, triggerFieldReset, } = useFormContext();
|
|
41
|
+
const { fetchedOptions, setFetchedOptions, object, getValues, errors, instance, richTextEditor, parameters, handleChange, fieldHeight, triggerFieldReset, associatedObject, } = useFormContext();
|
|
42
42
|
// If the entry is hidden, clear its value and any nested values, and skip rendering
|
|
43
43
|
if (!entryIsVisible(entry, getValues(), instance)) {
|
|
44
44
|
return null;
|
|
@@ -78,6 +78,8 @@ export function RecursiveEntryRenderer(props) {
|
|
|
78
78
|
return def;
|
|
79
79
|
}, [entry, parameters, object]);
|
|
80
80
|
const validation = fieldDefinition?.validation || {};
|
|
81
|
+
if (associatedObject?.propertyId === entryId)
|
|
82
|
+
return null;
|
|
81
83
|
useEffect(() => {
|
|
82
84
|
if (fieldDefinition?.type === 'collection' && fieldDefinition?.manyToManyPropertyId && instance) {
|
|
83
85
|
fetchCollectionData(apiServices, fieldDefinition, setFetchedOptions, instance.id, fetchedOptions, initialMiddleObjectInstances);
|
|
@@ -107,7 +109,9 @@ export function RecursiveEntryRenderer(props) {
|
|
|
107
109
|
? display?.defaultValue.orderBy
|
|
108
110
|
: undefined, defaultValueCriteria: typeof display?.defaultValue === 'object' && 'criteria' in display.defaultValue
|
|
109
111
|
? display?.defaultValue?.criteria
|
|
110
|
-
: undefined, viewLayout: display?.viewLayout, hasDescription: !!display?.description
|
|
112
|
+
: undefined, viewLayout: display?.viewLayout, hasDescription: !!display?.description,
|
|
113
|
+
// formId={display?.createFormId} // TODO: this should be added as part of the builder update
|
|
114
|
+
createActionId: '_create' })));
|
|
111
115
|
}
|
|
112
116
|
else if (fieldDefinition.type === 'user') {
|
|
113
117
|
return (React.createElement(FieldWrapper, { ...getFieldWrapperProps(fieldDefinition, entry, entryId, fieldValue, display, errors) },
|
|
@@ -116,7 +120,7 @@ export function RecursiveEntryRenderer(props) {
|
|
|
116
120
|
else if (fieldDefinition.type === 'collection') {
|
|
117
121
|
return fieldDefinition?.manyToManyPropertyId ? (middleObject && initialMiddleObjectInstances && (React.createElement(FieldWrapper, { ...getFieldWrapperProps(fieldDefinition, entry, entryId, fieldValue, display, errors) },
|
|
118
122
|
React.createElement(DropdownRepeatableField, { initialMiddleObjectInstances: fetchedOptions[`${entryId}MiddleObjectInstances`] || initialMiddleObjectInstances, fieldDefinition: fieldDefinition, id: entryId, middleObject: middleObject, readOnly: entry.type === 'readonlyField', criteria: validation?.criteria, hasDescription: !!display?.description })))) : (React.createElement(FieldWrapper, { ...getFieldWrapperProps(fieldDefinition, entry, entryId, fieldValue, display, errors) },
|
|
119
|
-
React.createElement(RepeatableField, { fieldDefinition: fieldDefinition, canUpdateProperty: entry.type !== 'readonlyField', criteria: validation?.criteria, viewLayout: display?.viewLayout })));
|
|
123
|
+
React.createElement(RepeatableField, { fieldDefinition: fieldDefinition, canUpdateProperty: entry.type !== 'readonlyField', criteria: validation?.criteria, viewLayout: display?.viewLayout, entry: entry, createActionId: '_create', updateActionId: '_update', deleteActionId: '_delete' })));
|
|
120
124
|
}
|
|
121
125
|
else if (fieldDefinition.type === 'richText') {
|
|
122
126
|
return (React.createElement(FieldWrapper, { ...getFieldWrapperProps(fieldDefinition, entry, entryId, fieldValue, display, errors) }, richTextEditor ? (React.createElement(richTextEditor, {
|
|
@@ -140,7 +144,6 @@ export function RecursiveEntryRenderer(props) {
|
|
|
140
144
|
else {
|
|
141
145
|
// Add `aria-describedby` to ensure screen readers read the description
|
|
142
146
|
// when the input is tabbed into.
|
|
143
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
144
147
|
const additionalProps = {};
|
|
145
148
|
if (fieldDefinition.enum && display?.description) {
|
|
146
149
|
additionalProps.renderInput = (params) => (React.createElement(TextField, { ...params, inputProps: {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { FieldErrors } from 'react-hook-form';
|
|
2
3
|
export type ValidationErrorDisplayProps = {
|
|
3
4
|
formId: string;
|
|
4
5
|
title?: string;
|
|
6
|
+
errors?: FieldErrors;
|
|
7
|
+
showSubmitError?: boolean;
|
|
5
8
|
};
|
|
6
9
|
declare function ValidationErrorDisplay(props: ValidationErrorDisplayProps): React.JSX.Element | null;
|
|
7
10
|
export default ValidationErrorDisplay;
|
package/dist/published/components/custom/FormV2/components/ValidationFiles/ValidationErrorDisplay.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useResponsive } from '../../../../../theme';
|
|
3
|
-
import { useFormContext } from '../../../../../theme/hooks';
|
|
4
3
|
import { List, ListItem, Typography } from '../../../../core';
|
|
5
4
|
import { Box } from '../../../../layout';
|
|
6
5
|
function ValidationErrorDisplay(props) {
|
|
7
|
-
const { formId, title } = props;
|
|
8
|
-
const { errors, showSubmitError } = useFormContext();
|
|
6
|
+
const { formId, title, errors, showSubmitError } = props;
|
|
9
7
|
const { isSm, isXs } = useResponsive();
|
|
10
8
|
function extractErrorMessages(errors) {
|
|
11
9
|
const messages = [];
|
|
@@ -38,7 +38,7 @@ export type SimpleEditorProps = {
|
|
|
38
38
|
};
|
|
39
39
|
export type ObjectPropertyInputProps = {
|
|
40
40
|
id: string;
|
|
41
|
-
fieldDefinition: InputParameter;
|
|
41
|
+
fieldDefinition: InputParameter | Property;
|
|
42
42
|
mode: 'default' | 'existingOnly' | 'newOnly';
|
|
43
43
|
nestedFieldsView?: boolean;
|
|
44
44
|
readOnly?: boolean;
|
|
@@ -53,6 +53,8 @@ export type ObjectPropertyInputProps = {
|
|
|
53
53
|
initialValue?: ObjectInstance | null;
|
|
54
54
|
viewLayout?: ViewLayoutEntityReference;
|
|
55
55
|
hasDescription?: boolean;
|
|
56
|
+
createActionId?: string;
|
|
57
|
+
formId?: string;
|
|
56
58
|
};
|
|
57
59
|
export type Page = {
|
|
58
60
|
id: string;
|
|
@@ -85,6 +87,10 @@ export type ExpandedSection = Section & {
|
|
|
85
87
|
export type EntryRendererProps = BaseProps & {
|
|
86
88
|
entry: FormEntry;
|
|
87
89
|
isDocument?: boolean;
|
|
90
|
+
associatedObject?: {
|
|
91
|
+
instanceId?: string;
|
|
92
|
+
propertyId?: string;
|
|
93
|
+
};
|
|
88
94
|
};
|
|
89
95
|
export type SectionsProps = {
|
|
90
96
|
entry: Sections;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Action, ApiServices, Column, Columns, FormEntry, InputField, InputParameter, InputParameterReference, Obj, ObjectInstance, Property, Section, Sections, UserAccount } from '@evoke-platform/context';
|
|
2
3
|
import { LocalDateTime } from '@js-joda/core';
|
|
3
4
|
import { FieldErrors, FieldValues } from 'react-hook-form';
|
|
4
5
|
import { AutocompleteOption } from '../../../core';
|
|
5
|
-
import { Document, DocumentData } from './types';
|
|
6
|
+
import { Document, DocumentData, SavedDocumentReference } from './types';
|
|
6
7
|
export declare const scrollIntoViewWithOffset: (el: HTMLElement, offset: number, container?: HTMLElement) => void;
|
|
7
8
|
export declare const normalizeDateTime: (dateTime: LocalDateTime) => string;
|
|
8
9
|
export declare function isAddressProperty(key: string): boolean;
|
|
@@ -61,3 +62,27 @@ export declare function formatDataToDoc(data: DocumentData): {
|
|
|
61
62
|
export declare function getUnnestedEntries(entries: FormEntry[]): FormEntry[];
|
|
62
63
|
export declare const isEmptyWithDefault: (fieldValue: unknown, entry: InputParameterReference | InputField, instance: Record<string, unknown> | object) => boolean | "" | 0 | undefined;
|
|
63
64
|
export declare const docProperties: Property[];
|
|
65
|
+
export declare const uploadDocuments: (files: (File | SavedDocumentReference)[], metadata: Record<string, string>, apiServices: ApiServices, instanceId: string, objectId: string) => Promise<SavedDocumentReference[]>;
|
|
66
|
+
export declare const deleteDocuments: (submittedFields: FieldValues, requestSuccess: boolean, apiServices: ApiServices, object: Obj, instance: FieldValues, action?: Action, setSnackbarError?: React.Dispatch<React.SetStateAction<{
|
|
67
|
+
showAlert: boolean;
|
|
68
|
+
message?: string;
|
|
69
|
+
isError: boolean;
|
|
70
|
+
}>>) => Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Transforms a form submission into a format safe for API submission.
|
|
73
|
+
*
|
|
74
|
+
* Responsibilities:
|
|
75
|
+
* - Uploads any files found in submission fields.
|
|
76
|
+
* - Normalizes related objects (keeping only id and name not the whole instance).
|
|
77
|
+
* - Converts an object of undefined address fields to undefined instead of an empty object.
|
|
78
|
+
* - Normalizes LocalDateTime values to API-friendly format.
|
|
79
|
+
* - Converts empty strings or undefined values to null.
|
|
80
|
+
* - Optionally reports file upload errors via snackbar.
|
|
81
|
+
*
|
|
82
|
+
* Returns the cleaned submission ready for submitting.
|
|
83
|
+
*/
|
|
84
|
+
export declare function formatSubmission(submission: FieldValues, apiServices: ApiServices, objectId: string, instanceId?: string, setSnackbarError?: React.Dispatch<React.SetStateAction<{
|
|
85
|
+
showAlert: boolean;
|
|
86
|
+
message?: string;
|
|
87
|
+
isError: boolean;
|
|
88
|
+
}>>): Promise<FieldValues>;
|