@evoke-platform/ui-components 1.6.0-testing.9 → 1.6.1-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/published/components/custom/CriteriaBuilder/CriteriaBuilder.js +1 -1
  2. package/dist/published/components/custom/FormField/AddressFieldComponent/addressFieldComponent.js +1 -1
  3. package/dist/published/components/custom/FormField/BooleanSelect/BooleanSelect.js +3 -3
  4. package/dist/published/components/custom/FormField/DatePickerSelect/DatePickerSelect.js +7 -1
  5. package/dist/published/components/custom/FormField/DateTimePickerSelect/DateTimePickerSelect.js +7 -1
  6. package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.js +6 -3
  7. package/dist/published/components/custom/FormField/TimePickerSelect/TimePickerSelect.js +13 -3
  8. package/dist/published/components/custom/FormV2/FormRenderer.d.ts +19 -0
  9. package/dist/published/components/custom/FormV2/FormRenderer.js +183 -0
  10. package/dist/published/components/custom/FormV2/components/AccordionSections.d.ts +4 -0
  11. package/dist/published/components/custom/FormV2/components/AccordionSections.js +131 -0
  12. package/dist/published/components/custom/FormV2/components/ActionButtons.d.ts +19 -0
  13. package/dist/published/components/custom/FormV2/components/ActionButtons.js +106 -0
  14. package/dist/published/components/custom/FormV2/components/FieldWrapper.d.ts +24 -0
  15. package/dist/published/components/custom/FormV2/components/FieldWrapper.js +100 -0
  16. package/dist/published/components/custom/FormV2/components/FormContext.d.ts +12 -0
  17. package/dist/published/components/custom/FormV2/components/FormContext.js +8 -0
  18. package/dist/published/components/custom/FormV2/components/FormFieldTypes/AddressFields.d.ts +17 -0
  19. package/dist/published/components/custom/FormV2/components/FormFieldTypes/AddressFields.js +50 -0
  20. package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/ActionDialog.d.ts +14 -0
  21. package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/ActionDialog.js +88 -0
  22. package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DocumentViewerCell.d.ts +13 -0
  23. package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DocumentViewerCell.js +140 -0
  24. package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DropdownRepeatableField.d.ts +17 -0
  25. package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DropdownRepeatableField.js +233 -0
  26. package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DropdownRepeatableFieldInput.d.ts +40 -0
  27. package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DropdownRepeatableFieldInput.js +95 -0
  28. package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/RepeatableField.d.ts +12 -0
  29. package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/RepeatableField.js +526 -0
  30. package/dist/published/components/custom/FormV2/components/FormFieldTypes/Criteria.d.ts +12 -0
  31. package/dist/published/components/custom/FormV2/components/FormFieldTypes/Criteria.js +93 -0
  32. package/dist/published/components/custom/FormV2/components/FormFieldTypes/DocumentFiles/Document.d.ts +16 -0
  33. package/dist/published/components/custom/FormV2/components/FormFieldTypes/DocumentFiles/Document.js +73 -0
  34. package/dist/published/components/custom/FormV2/components/FormFieldTypes/DocumentFiles/DocumentList.d.ts +13 -0
  35. package/dist/published/components/custom/FormV2/components/FormFieldTypes/DocumentFiles/DocumentList.js +179 -0
  36. package/dist/published/components/custom/FormV2/components/FormFieldTypes/Image.d.ts +12 -0
  37. package/dist/published/components/custom/FormV2/components/FormFieldTypes/Image.js +108 -0
  38. package/dist/published/components/custom/FormV2/components/FormFieldTypes/UserProperty.d.ts +16 -0
  39. package/dist/published/components/custom/FormV2/components/FormFieldTypes/UserProperty.js +129 -0
  40. package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/InstanceLookup.d.ts +15 -0
  41. package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/InstanceLookup.js +226 -0
  42. package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/ObjectPropertyInput.d.ts +4 -0
  43. package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/ObjectPropertyInput.js +439 -0
  44. package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/RelatedObjectInstance.d.ts +29 -0
  45. package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/RelatedObjectInstance.js +74 -0
  46. package/dist/published/components/custom/FormV2/components/FormSections.d.ts +4 -0
  47. package/dist/published/components/custom/FormV2/components/FormSections.js +104 -0
  48. package/dist/published/components/custom/FormV2/components/RecursiveEntryRenderer.d.ts +2 -0
  49. package/dist/published/components/custom/FormV2/components/RecursiveEntryRenderer.js +209 -0
  50. package/dist/published/components/custom/FormV2/components/TabNav.d.ts +10 -0
  51. package/dist/published/components/custom/FormV2/components/TabNav.js +23 -0
  52. package/dist/published/components/custom/FormV2/components/ValidationFiles/Validation.d.ts +3 -0
  53. package/dist/published/components/custom/FormV2/components/ValidationFiles/Validation.js +176 -0
  54. package/dist/published/components/custom/FormV2/components/ValidationFiles/ValidationErrorDisplay.d.ts +10 -0
  55. package/dist/published/components/custom/FormV2/components/ValidationFiles/ValidationErrorDisplay.js +45 -0
  56. package/dist/published/components/custom/FormV2/components/types.d.ts +122 -0
  57. package/dist/published/components/custom/FormV2/components/types.js +1 -0
  58. package/dist/published/components/custom/FormV2/components/utils.d.ts +47 -0
  59. package/dist/published/components/custom/FormV2/components/utils.js +434 -0
  60. package/dist/published/components/custom/FormV2/index.d.ts +1 -0
  61. package/dist/published/components/custom/FormV2/index.js +1 -0
  62. package/dist/published/components/custom/ResponsiveOverflow/ResponsiveOverflow.js +5 -8
  63. package/dist/published/components/custom/index.d.ts +1 -0
  64. package/dist/published/components/custom/index.js +1 -0
  65. package/dist/published/index.d.ts +2 -2
  66. package/dist/published/index.js +2 -2
  67. package/dist/published/theme/hooks.d.ts +7 -0
  68. package/dist/published/theme/hooks.js +9 -0
  69. package/package.json +4 -2
@@ -0,0 +1,226 @@
1
+ import { useApiServices } from '@evoke-platform/context';
2
+ import { Clear, Search } from '@mui/icons-material';
3
+ import { debounce, get, startCase } from 'lodash';
4
+ import { DateTime } from 'luxon';
5
+ import React, { useEffect, useState } from 'react';
6
+ import { Button, IconButton, InputAdornment, TextField, Typography, } from '../../../../../core';
7
+ import { Box, Grid } from '../../../../../layout';
8
+ import BuilderGrid from '../../../../BuilderGrid';
9
+ import { getPrefixedUrl } from '../../utils';
10
+ const SearchField = (props) => {
11
+ const { searchableColumns, filter, setFilter, searchString, setSearchString } = props;
12
+ const clearSearch = () => {
13
+ setSearchString('');
14
+ setFilter(undefined);
15
+ };
16
+ const handleSearch = async (e) => {
17
+ const searchProperties = searchableColumns.map((column) => {
18
+ const columnId = column.id;
19
+ return {
20
+ [columnId]: {
21
+ like: e.target.value,
22
+ options: 'i',
23
+ },
24
+ };
25
+ });
26
+ if (e.target.value.trim() === '' || !e.target.value) {
27
+ clearSearch();
28
+ }
29
+ else {
30
+ setSearchString(e.target.value);
31
+ setFilter({
32
+ ...filter,
33
+ where: {
34
+ or: searchProperties,
35
+ },
36
+ limit: 100,
37
+ });
38
+ }
39
+ };
40
+ return (React.createElement(TextField, { autoFocus: true, placeholder: "Search", value: searchString, onChange: (e) => handleSearch(e), size: "medium", fullWidth: true, sx: { marginBottom: '15px', marginTop: '15px' }, InputProps: {
41
+ endAdornment: (React.createElement(InputAdornment, { position: "end" },
42
+ React.createElement(IconButton, { sx: {
43
+ visibility: searchString.length > 0 ? 'visible' : 'hidden',
44
+ }, onClick: () => clearSearch() },
45
+ React.createElement(Clear, { sx: {
46
+ fontSize: '22px',
47
+ } })))),
48
+ startAdornment: (React.createElement(InputAdornment, { position: "start" },
49
+ React.createElement(Search, { sx: { fontSize: '22px', color: '#637381' } }))),
50
+ } }));
51
+ };
52
+ const InstanceLookup = (props) => {
53
+ const { object, setSelectedInstance, setRelationType, filter: criteriaFilter, mode, nestedFieldsView, layout, } = props;
54
+ const [rows, setRows] = useState([]);
55
+ const [loading, setLoading] = useState(false);
56
+ const [filter, setFilter] = useState();
57
+ const [searchString, setSearchString] = useState('');
58
+ const [searchableColumns] = useState(object.properties?.filter((property) => property.searchable) ?? []);
59
+ const apiServices = useApiServices();
60
+ const retrieveColumns = (tableViewLayout) => {
61
+ let columns = [];
62
+ if (tableViewLayout?.properties) {
63
+ for (const prop of tableViewLayout.properties) {
64
+ const propertyId = prop.id.split('.')[0];
65
+ const property = object.properties?.find((p) => p.id === propertyId);
66
+ if (property) {
67
+ if (property.type === 'address') {
68
+ columns.push({
69
+ field: prop.id,
70
+ headerName: `${property.name} - ${startCase(prop.id.split('.')[1])}`,
71
+ type: 'string',
72
+ flex: 1,
73
+ valueGetter: (params) => {
74
+ return get(params.row, prop.id) ?? '';
75
+ },
76
+ });
77
+ }
78
+ else if (property.type === 'object' || property.type === 'user') {
79
+ columns.push({
80
+ field: prop.id,
81
+ headerName: property.name,
82
+ type: 'string',
83
+ flex: 1,
84
+ valueGetter: (params) => {
85
+ return (get(params.row, !prop.id.includes('.') ? `${prop.id}.name` : prop.id) ?? '');
86
+ },
87
+ });
88
+ }
89
+ else if (property.type === 'document') {
90
+ columns.push({
91
+ field: prop.id,
92
+ headerName: property.name,
93
+ type: 'string',
94
+ flex: 1,
95
+ valueGetter: (params) => {
96
+ const row = params.row;
97
+ return (row[prop.id]?.map((v) => v.name).join(', ') ??
98
+ '');
99
+ },
100
+ });
101
+ }
102
+ else if (property.type === 'date') {
103
+ columns.push({
104
+ field: prop.id,
105
+ headerName: property.name,
106
+ type: 'string',
107
+ flex: 1,
108
+ valueFormatter: (params) => {
109
+ if (!params.value) {
110
+ return params.value;
111
+ }
112
+ // The value should really be typed as string | undefined so once asserted as defined
113
+ // the value must be a string.
114
+ return DateTime.fromISO(params.value).toLocaleString(DateTime.DATE_SHORT);
115
+ },
116
+ });
117
+ }
118
+ else if (property.type === 'date-time') {
119
+ columns.push({
120
+ field: prop.id,
121
+ headerName: property.name,
122
+ type: 'string',
123
+ flex: 1,
124
+ valueFormatter: (params) => {
125
+ if (!params.value) {
126
+ return params.value;
127
+ }
128
+ // The value should really be typed as string | undefined so once asserted as defined
129
+ // the value must be a string.
130
+ return DateTime.fromISO(params.value).toLocaleString(DateTime.DATETIME_SHORT);
131
+ },
132
+ });
133
+ }
134
+ else if (property.type === 'time') {
135
+ columns.push({
136
+ field: prop.id,
137
+ headerName: property.name,
138
+ type: 'string',
139
+ flex: 1,
140
+ valueFormatter: (params) => {
141
+ if (!params.value) {
142
+ return params.value;
143
+ }
144
+ // The value should really be typed as string | undefined so once asserted as defined
145
+ // the value must be a string.
146
+ return DateTime.fromISO(params.value).toLocaleString(DateTime.TIME_SIMPLE);
147
+ },
148
+ });
149
+ }
150
+ else {
151
+ columns.push({
152
+ field: prop.id,
153
+ headerName: property.name,
154
+ type: 'string',
155
+ flex: 1,
156
+ });
157
+ }
158
+ }
159
+ }
160
+ }
161
+ else {
162
+ const name = object.properties?.find((property) => property.id == 'name');
163
+ columns = [{ field: 'name', headerName: name?.name ?? 'Name', type: 'string', flex: 1 }];
164
+ }
165
+ return columns;
166
+ };
167
+ function fetchObjectInstance() {
168
+ setLoading(true);
169
+ const combinedFilter = {
170
+ ...criteriaFilter,
171
+ ...filter,
172
+ where: criteriaFilter?.where
173
+ ? {
174
+ and: [criteriaFilter.where, filter?.where],
175
+ }
176
+ : filter?.where,
177
+ };
178
+ apiServices.get(getPrefixedUrl(`/objects/${object.id}/instances`), { params: { filter: JSON.stringify(combinedFilter) } }, (error, objectInstances) => {
179
+ if (error) {
180
+ console.error(error);
181
+ }
182
+ else {
183
+ !!objectInstances && setRows(objectInstances);
184
+ }
185
+ setLoading(false);
186
+ });
187
+ }
188
+ useEffect(() => {
189
+ if (filter || searchString.length) {
190
+ debounce(() => fetchObjectInstance(), 500)();
191
+ }
192
+ else if (searchString === '') {
193
+ setRows([]);
194
+ }
195
+ }, [filter, searchString.length]);
196
+ return (React.createElement(Grid, { container: true, sx: { paddingBottom: '30px' } },
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
+ React.createElement(BuilderGrid, { item: 'instances', rows: rows, columns: retrieveColumns(layout), onRowClick: (params) => setSelectedInstance(params.row), initialSort: {
199
+ field: object.viewLayout?.table?.sort?.colId ?? 'name',
200
+ sort: object.viewLayout?.table?.sort?.sort ?? 'asc',
201
+ }, sx: {
202
+ height: '360px',
203
+ width: '100%',
204
+ }, hideToolbar: true, loading: loading, hideEmptyContent: true, localeText: {
205
+ noRowsLabel: searchString.length > 0
206
+ ? `No Results Found. Refine your search ${mode !== 'existingOnly' ? 'or create a new record.' : '.'}`
207
+ : 'Search to view results',
208
+ }, noRowsOverlay: React.createElement(Box, { sx: { height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' } }, searchString.length > 0 ? (React.createElement(React.Fragment, null,
209
+ React.createElement(Box, null,
210
+ React.createElement(Typography, { sx: {
211
+ fontSize: '14px',
212
+ fontWeight: 700,
213
+ textAlign: 'center',
214
+ } }, "No Results Found"),
215
+ React.createElement(Typography, { sx: {
216
+ fontSize: '14px',
217
+ textAlign: 'center',
218
+ } },
219
+ "Refine your search",
220
+ !nestedFieldsView && mode !== 'existingOnly' && (React.createElement(React.Fragment, null,
221
+ ' or ',
222
+ React.createElement(Button, { variant: "text", onClick: () => setRelationType('new'), sx: {
223
+ padding: '3px 5px',
224
+ } }, "enter a new record"))))))) : (React.createElement(Typography, { sx: { fontSize: '16px' } }, "Search to view results"))) })));
225
+ };
226
+ export default InstanceLookup;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { ObjectPropertyInputProps } from '../../types';
3
+ declare const ObjectPropertyInput: (props: ObjectPropertyInputProps) => React.JSX.Element;
4
+ export default ObjectPropertyInput;
@@ -0,0 +1,439 @@
1
+ import { useApiServices, useApp, useNavigate, } from '@evoke-platform/context';
2
+ import cleanDeep from 'clean-deep';
3
+ import { cloneDeep, debounce, isEmpty, isNil } from 'lodash';
4
+ import Handlebars from 'no-eval-handlebars';
5
+ import React, { useCallback, useEffect, useState } from 'react';
6
+ import { Close } from '../../../../../../icons';
7
+ import { useFormContext } from '../../../../../../theme/hooks';
8
+ import { Autocomplete, Button, Dialog, IconButton, Link, Paper, Snackbar, TextField, Tooltip, Typography, } from '../../../../../core';
9
+ import { Box } from '../../../../../layout';
10
+ import { encodePageSlug, getDefaultPages, getPrefixedUrl, transformToWhere } from '../../utils';
11
+ import RelatedObjectInstance from './RelatedObjectInstance';
12
+ const ObjectPropertyInput = (props) => {
13
+ const { id, instance, fieldDefinition, handleChangeObjectProperty, nestedFieldsView, readOnly, error, mode, parameters, displayOption, filter, defaultValueCriteria, sortBy, orderBy, isModal, initialValue, fieldHeight, richTextEditor, viewLayout, hasDescription, } = props;
14
+ const { fetchedOptions, setFetchedOptions } = useFormContext();
15
+ const { defaultPages, findDefaultPageSlugFor } = useApp();
16
+ const [selectedInstance, setSelectedInstance] = useState(initialValue || undefined);
17
+ const [openCreateDialog, setOpenCreateDialog] = useState(false);
18
+ const [allDefaultPages, setAllDefaultPages] = useState(defaultPages ?? {});
19
+ const [loadingOptions, setLoadingOptions] = useState(false);
20
+ const [navigationSlug, setNavigationSlug] = useState(fetchedOptions[`${id}NavigationSlug`]);
21
+ const [relatedObject, setRelatedObject] = useState(fetchedOptions[`${id}RelatedObject`]);
22
+ const [dropdownInput, setDropdownInput] = useState();
23
+ const [openOptions, setOpenOptions] = useState(false);
24
+ const [hasFetched, setHasFetched] = useState(fetchedOptions[`${id}OptionsHaveFetched`] || false);
25
+ const [options, setOptions] = useState(fetchedOptions[`${id}Options`] || []);
26
+ const [layout, setLayout] = useState();
27
+ const [appId, setAppId] = useState(fetchedOptions[`${id}AppId`]);
28
+ const [form, setForm] = useState();
29
+ const [snackbarError, setSnackbarError] = useState({
30
+ showAlert: false,
31
+ isError: true,
32
+ });
33
+ const DEFAULT_CREATE_ACTION = '_create';
34
+ const action = relatedObject?.actions?.find((action) => action.id === DEFAULT_CREATE_ACTION);
35
+ const apiServices = useApiServices();
36
+ const navigateTo = useNavigate();
37
+ const updatedCriteria = filter
38
+ ? {
39
+ where: transformToWhere(filter),
40
+ }
41
+ : undefined;
42
+ useEffect(() => {
43
+ if (relatedObject) {
44
+ let defaultViewLayout;
45
+ if (relatedObject?.viewLayout?.dropdown && displayOption === 'dropdown') {
46
+ defaultViewLayout = {
47
+ id: 'default',
48
+ name: 'Default',
49
+ objectId: relatedObject.id,
50
+ ...relatedObject.viewLayout.dropdown,
51
+ };
52
+ }
53
+ else if (relatedObject?.viewLayout?.table && displayOption === 'dialogBox') {
54
+ defaultViewLayout = {
55
+ id: 'default',
56
+ name: 'Default',
57
+ objectId: relatedObject.id,
58
+ ...relatedObject.viewLayout.table,
59
+ };
60
+ }
61
+ if (viewLayout) {
62
+ apiServices
63
+ .get(getPrefixedUrl(`/objects/${viewLayout.objectId}/${displayOption === 'dropdown' ? 'dropdown' : 'table'}Layouts/${viewLayout.id}`))
64
+ .then(setLayout)
65
+ .catch((err) => setLayout(defaultViewLayout));
66
+ }
67
+ else {
68
+ setLayout(defaultViewLayout);
69
+ }
70
+ }
71
+ }, [displayOption, relatedObject, viewLayout]);
72
+ useEffect(() => {
73
+ // setting the default value when there is default criteria
74
+ if (!isEmpty(defaultValueCriteria) && !selectedInstance && (!instance || !instance[id])) {
75
+ const updatedFilter = cleanDeep({
76
+ where: transformToWhere({ $and: [defaultValueCriteria, updatedCriteria?.where ?? {}] }),
77
+ order: orderBy && sortBy ? encodeURIComponent(sortBy + ' ' + orderBy) : undefined,
78
+ limit: 1,
79
+ });
80
+ if (updatedFilter.where) {
81
+ setLoadingOptions(true);
82
+ apiServices.get(getPrefixedUrl(`/objects/${fieldDefinition.objectId}/instances?filter=${encodeURIComponent(JSON.stringify(updatedFilter))}`), (error, instances) => {
83
+ if (error) {
84
+ console.error(error);
85
+ setLoadingOptions(false);
86
+ }
87
+ if (instances && instances.length > 0) {
88
+ setSelectedInstance(instances[0]);
89
+ handleChangeObjectProperty(id, instances[0]);
90
+ }
91
+ setLoadingOptions(false);
92
+ });
93
+ }
94
+ }
95
+ }, [fieldDefinition, defaultValueCriteria, sortBy, orderBy]);
96
+ const getDropdownOptions = useCallback((name) => {
97
+ if ((!fetchedOptions[`${id}Options`] ||
98
+ fetchedOptions[`${id}Options`].length === 0) &&
99
+ !hasFetched) {
100
+ setLoadingOptions(true);
101
+ const updatedFilter = cloneDeep(updatedCriteria) || {};
102
+ updatedFilter.limit = 100;
103
+ const { propertyId, direction } = layout?.sort ?? {
104
+ propertyId: 'name',
105
+ direction: 'asc',
106
+ };
107
+ updatedFilter.order = `${propertyId} ${direction}`;
108
+ const where = name
109
+ ? transformToWhere({
110
+ name: {
111
+ like: name,
112
+ options: 'i',
113
+ },
114
+ })
115
+ : {};
116
+ updatedFilter.where = updatedFilter.where
117
+ ? {
118
+ and: [updatedFilter.where, where],
119
+ }
120
+ : where;
121
+ apiServices.get(getPrefixedUrl(`/objects/${fieldDefinition.objectId}/instances?filter=${JSON.stringify(updatedFilter)}`), (error, instances) => {
122
+ if (error) {
123
+ console.error(error);
124
+ setLoadingOptions(false);
125
+ }
126
+ if (instances) {
127
+ setOptions(instances);
128
+ setLoadingOptions(false);
129
+ // so if you go off a section too quickly and it doesn't fetch it re-fetches but doesn't cause an infinite loop
130
+ setHasFetched(true);
131
+ }
132
+ });
133
+ }
134
+ }, [relatedObject, setLoadingOptions, setOptions, fieldDefinition, updatedCriteria, layout]);
135
+ useEffect(() => {
136
+ if (displayOption === 'dropdown') {
137
+ getDropdownOptions();
138
+ }
139
+ }, [fieldDefinition, updatedCriteria, displayOption]);
140
+ useEffect(() => {
141
+ setSelectedInstance(initialValue);
142
+ }, [initialValue]);
143
+ const debouncedGetDropdownOptions = useCallback(debounce(getDropdownOptions, 200), [updatedCriteria]);
144
+ useEffect(() => {
145
+ debouncedGetDropdownOptions(dropdownInput);
146
+ return () => debouncedGetDropdownOptions.cancel();
147
+ }, [dropdownInput]);
148
+ useEffect(() => {
149
+ if (action?.defaultFormId) {
150
+ apiServices
151
+ .get(getPrefixedUrl(`data/forms/${action.defaultFormId}`))
152
+ .then((evokeForm) => {
153
+ setForm(evokeForm);
154
+ })
155
+ .catch((error) => {
156
+ console.error('Error fetching form:', error);
157
+ });
158
+ }
159
+ }, [action]);
160
+ useEffect(() => {
161
+ if (!fetchedOptions[`${id}RelatedObject`]) {
162
+ apiServices.get(getPrefixedUrl(`/objects/${fieldDefinition.objectId}/effective?sanitizedVersion=true`), (error, object) => {
163
+ if (error) {
164
+ console.error(error);
165
+ }
166
+ else {
167
+ setRelatedObject(object);
168
+ }
169
+ });
170
+ }
171
+ }, [fieldDefinition]);
172
+ useEffect(() => {
173
+ const fetchDefaultPages = async () => {
174
+ if (parameters) {
175
+ const pages = await getDefaultPages(parameters, defaultPages, findDefaultPageSlugFor);
176
+ setAllDefaultPages(pages);
177
+ }
178
+ };
179
+ fetchDefaultPages();
180
+ }, []);
181
+ useEffect(() => {
182
+ if (fieldDefinition.objectId &&
183
+ allDefaultPages &&
184
+ allDefaultPages[fieldDefinition.objectId] &&
185
+ (!fetchedOptions?.[`${id}NavigationSlug`] || !fetchedOptions[`${id}AppId`])) {
186
+ apiServices.get(getPrefixedUrl(`/apps/${allDefaultPages[fieldDefinition.objectId].split('/').slice(1, 2)}/pages/${encodePageSlug(allDefaultPages[fieldDefinition.objectId].split('/').slice(2).join('/'))}`), (error, page) => {
187
+ if (error) {
188
+ console.error(error);
189
+ }
190
+ else {
191
+ setAppId(page?.appId);
192
+ setNavigationSlug(page?.slug);
193
+ }
194
+ });
195
+ }
196
+ }, []);
197
+ const handleClose = () => {
198
+ setOpenCreateDialog(false);
199
+ };
200
+ const compileExpression = (expression, instance) => {
201
+ const template = Handlebars.compileAST(expression);
202
+ return instance ? template(instance) : undefined;
203
+ };
204
+ useEffect(() => {
205
+ if (relatedObject && !fetchedOptions[`${id}RelatedObject`]) {
206
+ setFetchedOptions({
207
+ [`${id}RelatedObject`]: relatedObject,
208
+ });
209
+ }
210
+ if (options &&
211
+ (!fetchedOptions[`${id}Options`] || fetchedOptions[`${id}Options`].length === 0) &&
212
+ hasFetched &&
213
+ !fetchedOptions[`${id}OptionsHaveFetched`]) {
214
+ setFetchedOptions({
215
+ [`${id}Options`]: options,
216
+ [`${id}OptionsHaveFetched`]: hasFetched,
217
+ });
218
+ }
219
+ if (navigationSlug && !fetchedOptions[`${id}NavigationSlug`]) {
220
+ setFetchedOptions({
221
+ [`${id}NavigationSlug`]: navigationSlug,
222
+ });
223
+ }
224
+ }, [relatedObject, options, hasFetched]);
225
+ return (React.createElement(React.Fragment, null,
226
+ displayOption === 'dropdown' ? (React.createElement(React.Fragment, null,
227
+ React.createElement(Autocomplete, { id: id, fullWidth: true, sortBy: "NONE", open: openOptions, size: fieldHeight, componentsProps: {
228
+ popper: {
229
+ modifiers: [
230
+ {
231
+ name: 'flip',
232
+ enabled: false,
233
+ },
234
+ ],
235
+ },
236
+ }, PaperComponent: ({ children }) => {
237
+ return (React.createElement(Paper, { sx: {
238
+ borderRadius: '12px',
239
+ boxShadow: '0px 24px 48px 0px rgba(145, 158, 171, 0.2)',
240
+ '& .MuiAutocomplete-listbox': {
241
+ maxHeight: '25vh',
242
+ },
243
+ '& .MuiAutocomplete-noOptions': {
244
+ fontFamily: 'sans-serif',
245
+ fontSize: '14px',
246
+ paddingLeft: '24px',
247
+ color: 'rgba(145, 158, 171, 1)',
248
+ },
249
+ '& .MuiAutocomplete-loading': {
250
+ fontFamily: 'sans-serif',
251
+ fontSize: '14px',
252
+ paddingLeft: '24px',
253
+ color: 'rgba(145, 158, 171, 1)',
254
+ },
255
+ } },
256
+ mode !== 'newOnly' && children,
257
+ mode !== 'existingOnly' && form && (React.createElement(Button, { fullWidth: true, sx: {
258
+ justifyContent: 'flex-start',
259
+ pl: 2,
260
+ minHeight: '48px',
261
+ borderTop: '1px solid rgba(145, 158, 171, 0.24)',
262
+ borderRadius: '0p 0pc 6px 6px',
263
+ paddingLeft: '22px',
264
+ fontWeight: 400,
265
+ }, onMouseDown: (e) => {
266
+ setOpenCreateDialog(true);
267
+ }, color: 'inherit' }, "+ Add New"))));
268
+ }, sx: {
269
+ '& button.MuiButtonBase-root': {
270
+ ...(!loadingOptions &&
271
+ (instance?.[id]?.id || selectedInstance?.id)
272
+ ? {
273
+ visibility: 'visible',
274
+ }
275
+ : {}),
276
+ },
277
+ backgroundColor: 'white', // prevents the field flickering gray when loading in the value and options when it's a read only
278
+ }, noOptionsText: 'No options available', renderOption: (props, option) => {
279
+ return (React.createElement("li", { ...props, key: option.id },
280
+ React.createElement(Box, null,
281
+ React.createElement(Typography, { sx: { marginLeft: '8px', fontSize: '14px' } }, option.label),
282
+ layout?.secondaryTextExpression ? (React.createElement(Typography, { sx: { marginLeft: '8px', fontSize: '14px', color: '#637381' } }, compileExpression(layout?.secondaryTextExpression, options.find((o) => o.id === option.value)))) : null)));
283
+ }, onOpen: () => {
284
+ if (instance?.[id]?.id || selectedInstance?.id) {
285
+ setOpenOptions(false);
286
+ }
287
+ else {
288
+ setOpenOptions(true);
289
+ }
290
+ }, onClose: () => setOpenOptions(false), value: selectedInstance?.id
291
+ ? {
292
+ value: selectedInstance?.id ?? '',
293
+ label: selectedInstance?.name ?? '',
294
+ }
295
+ : null, isOptionEqualToValue: (option, value) => {
296
+ if (typeof value === 'string') {
297
+ return option.value === value;
298
+ }
299
+ return option.value === value?.value;
300
+ }, options: options.map((o) => ({ label: o.name, value: o.id })), getOptionLabel: (option) => {
301
+ return typeof option === 'string'
302
+ ? (options.find((o) => o.id === option)?.name ?? '')
303
+ : option.label;
304
+ }, onKeyDownCapture: (e) => {
305
+ // prevents keyboard trap
306
+ if (e.key === 'Tab') {
307
+ return;
308
+ }
309
+ if (selectedInstance?.id) {
310
+ e.preventDefault();
311
+ }
312
+ }, loading: loadingOptions, onChange: (event, value) => {
313
+ if (isNil(value)) {
314
+ setDropdownInput(undefined);
315
+ setSelectedInstance(undefined);
316
+ handleChangeObjectProperty(id, null);
317
+ }
318
+ else {
319
+ const selectedInstance = options.find((o) => o.id === value?.value);
320
+ setSelectedInstance(selectedInstance);
321
+ handleChangeObjectProperty(id, selectedInstance);
322
+ }
323
+ }, selectOnFocus: false, onBlur: () => setDropdownInput(undefined), renderInput: (params) => (React.createElement(TextField, { ...params, placeholder: selectedInstance?.id || readOnly ? '' : 'Select', readOnly: !loadingOptions && !selectedInstance?.id && readOnly, onChange: (event) => setDropdownInput(event.target.value), onClick: (e) => {
324
+ if (openOptions &&
325
+ e.target?.nodeName === 'svg') {
326
+ setOpenOptions(false);
327
+ }
328
+ else {
329
+ setOptions(options);
330
+ setOpenOptions(true);
331
+ }
332
+ }, sx: {
333
+ ...(!loadingOptions && selectedInstance?.id
334
+ ? {
335
+ '.MuiOutlinedInput-root': {
336
+ background: 'white',
337
+ border: 'auto',
338
+ '.MuiOutlinedInput-input': {
339
+ ...(navigationSlug
340
+ ? {
341
+ color: 'rgb(1, 78, 123)',
342
+ textDecoration: 'underline',
343
+ cursor: 'pointer',
344
+ }
345
+ : {}),
346
+ },
347
+ },
348
+ '& fieldset': {
349
+ border: readOnly ? 'none' : 'auto',
350
+ borderColor: 'auto',
351
+ },
352
+ '&:hover .MuiOutlinedInput-notchedOutline': {
353
+ border: 'auto',
354
+ },
355
+ '& svg': {
356
+ display: readOnly ? 'none' : 'block',
357
+ },
358
+ caretColor: 'white',
359
+ }
360
+ : {}),
361
+ }, InputProps: {
362
+ ...params.InputProps,
363
+ startAdornment: selectedInstance?.id ? (React.createElement(Typography, { onClick: (e) => {
364
+ if (navigationSlug && selectedInstance?.id) {
365
+ navigateTo(`/${appId}/${navigationSlug.replace(':instanceId', selectedInstance.id)}`);
366
+ }
367
+ }, sx: {
368
+ cursor: navigationSlug ? 'pointer' : 'default',
369
+ color: navigationSlug ? 'rgb(1, 78, 123)' : 'inherit',
370
+ textDecoration: navigationSlug ? 'underline' : 'none',
371
+ paddingLeft: '5px',
372
+ } }, selectedInstance?.name || '')) : null,
373
+ }, inputProps: {
374
+ ...params.inputProps,
375
+ value: selectedInstance?.id ? '' : params.inputProps.value,
376
+ ...(hasDescription ? { 'aria-describedby': `${id}-description` } : undefined),
377
+ } })), readOnly: readOnly, error: error }))) : (React.createElement(Box, { sx: {
378
+ padding: selectedInstance?.name ? '16.5px 14px' : '10.5px 0',
379
+ } },
380
+ (selectedInstance?.name || readOnly) && (React.createElement(Link, { sx: {
381
+ textDecoration: 'none',
382
+ marginRight: 1,
383
+ textDecorationLine: navigationSlug && instance?.[id] && !isModal ? 'underline' : 'none',
384
+ cursor: navigationSlug && instance?.[id] && !isModal ? 'pointer' : 'auto',
385
+ fontSize: '16px',
386
+ fontWeight: 400,
387
+ lineHeight: '24px',
388
+ textAlign: 'left',
389
+ color: navigationSlug && instance?.[id] && !isModal
390
+ ? '#0075A7'
391
+ : !selectedInstance?.id
392
+ ? '#999'
393
+ : '#212B36',
394
+ }, variant: "body2", href: navigationSlug && !isModal
395
+ ? `${'/app'}/${appId}/${navigationSlug.replace(':instanceId', selectedInstance?.id ?? '')}`
396
+ : undefined, "aria-label": selectedInstance?.name }, selectedInstance?.name ? selectedInstance?.name : readOnly && 'None')),
397
+ !readOnly && (selectedInstance || (nestedFieldsView && instance?.id)) ? (React.createElement(Tooltip, { title: `Unlink` },
398
+ React.createElement("span", null,
399
+ React.createElement(IconButton, { onClick: (event) => {
400
+ event.stopPropagation();
401
+ handleChangeObjectProperty(id, null);
402
+ setSelectedInstance(undefined);
403
+ }, sx: { p: 0, marginBottom: '4px' }, "aria-label": `Unlink` },
404
+ React.createElement(Close, { sx: { width: '20px', height: '20px' } }))))) : (React.createElement(Button, { sx: {
405
+ backgroundColor: '#DFE3E8',
406
+ color: '#212B36',
407
+ fontWeight: '700',
408
+ textTransform: 'capitalize',
409
+ '&:hover': {
410
+ backgroundColor: '#e6eaf0',
411
+ boxShadow: 'none',
412
+ },
413
+ '&:disabled': {
414
+ cursor: 'not-allowed',
415
+ pointerEvents: 'all',
416
+ },
417
+ boxShadow: 'none',
418
+ lineHeight: '2.75',
419
+ padding: '0 23px',
420
+ display: readOnly ? 'none' : 'block',
421
+ }, size: "small", variant: "contained", disableElevation: true, onClick: (event) => {
422
+ event.stopPropagation();
423
+ setOpenCreateDialog(true);
424
+ }, "aria-label": `Add` }, "Add")))),
425
+ openCreateDialog && (React.createElement(React.Fragment, null, nestedFieldsView ? (React.createElement(RelatedObjectInstance, { id: id, handleClose: handleClose, handleChangeObjectProperty: handleChangeObjectProperty, setSelectedInstance: setSelectedInstance, relatedObject: relatedObject, nestedFieldsView: nestedFieldsView, mode: mode, displayOption: displayOption, setOptions: setOptions, options: options, filter: updatedCriteria, layout: layout, fieldHeight: fieldHeight, richTextEditor: richTextEditor, form: form, action: action, setSnackbarError: setSnackbarError, selectedInstance: selectedInstance })) : (React.createElement(Dialog, { fullWidth: true, maxWidth: "md", open: openCreateDialog, onClose: (e, reason) => reason !== 'backdropClick' && handleClose },
426
+ React.createElement(Typography, { sx: {
427
+ marginTop: '28px',
428
+ fontSize: '22px',
429
+ fontWeight: 700,
430
+ marginLeft: '24px',
431
+ marginBottom: '10px',
432
+ } }, `Add ${fieldDefinition.name}`),
433
+ React.createElement(RelatedObjectInstance, { handleClose: handleClose, handleChangeObjectProperty: handleChangeObjectProperty, setSelectedInstance: setSelectedInstance, nestedFieldsView: nestedFieldsView, relatedObject: relatedObject, id: id, mode: mode, displayOption: displayOption, setOptions: setOptions, options: options, filter: updatedCriteria, layout: layout, fieldHeight: fieldHeight, richTextEditor: richTextEditor, form: form, action: action, setSnackbarError: setSnackbarError, selectedInstance: selectedInstance }))))),
434
+ React.createElement(Snackbar, { open: snackbarError.showAlert, handleClose: () => setSnackbarError({
435
+ isError: snackbarError.isError,
436
+ showAlert: false,
437
+ }), message: snackbarError.message, error: snackbarError.isError })));
438
+ };
439
+ export default ObjectPropertyInput;