@evoke-platform/ui-components 1.6.0-testing.13 → 1.6.0-testing.14
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/FormField/AddressFieldComponent/addressFieldComponent.js +1 -1
- package/dist/published/components/custom/FormField/BooleanSelect/BooleanSelect.js +3 -3
- package/dist/published/components/custom/FormField/DatePickerSelect/DatePickerSelect.js +7 -1
- package/dist/published/components/custom/FormField/DateTimePickerSelect/DateTimePickerSelect.js +7 -1
- package/dist/published/components/custom/FormField/InputFieldComponent/InputFieldComponent.js +6 -3
- package/dist/published/components/custom/FormField/TimePickerSelect/TimePickerSelect.js +13 -3
- package/dist/published/components/custom/FormV2/FormRenderer.d.ts +19 -0
- package/dist/published/components/custom/FormV2/FormRenderer.js +183 -0
- package/dist/published/components/custom/FormV2/components/AccordionSections.d.ts +4 -0
- package/dist/published/components/custom/FormV2/components/AccordionSections.js +131 -0
- package/dist/published/components/custom/FormV2/components/ActionButtons.d.ts +19 -0
- package/dist/published/components/custom/FormV2/components/ActionButtons.js +106 -0
- package/dist/published/components/custom/FormV2/components/FieldWrapper.d.ts +24 -0
- package/dist/published/components/custom/FormV2/components/FieldWrapper.js +100 -0
- package/dist/published/components/custom/FormV2/components/FormContext.d.ts +12 -0
- package/dist/published/components/custom/FormV2/components/FormContext.js +8 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/AddressFields.d.ts +17 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/AddressFields.js +50 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/ActionDialog.d.ts +14 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/ActionDialog.js +88 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DocumentViewerCell.d.ts +13 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DocumentViewerCell.js +140 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DropdownRepeatableField.d.ts +17 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DropdownRepeatableField.js +233 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DropdownRepeatableFieldInput.d.ts +40 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/DropdownRepeatableFieldInput.js +95 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/RepeatableField.d.ts +12 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/CollectionFiles/RepeatableField.js +526 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/Criteria.d.ts +12 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/Criteria.js +93 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/DocumentFiles/Document.d.ts +16 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/DocumentFiles/Document.js +73 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/DocumentFiles/DocumentList.d.ts +13 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/DocumentFiles/DocumentList.js +179 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/Image.d.ts +12 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/Image.js +108 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/UserProperty.d.ts +16 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/UserProperty.js +129 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/InstanceLookup.d.ts +15 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/InstanceLookup.js +226 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/ObjectPropertyInput.d.ts +4 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/ObjectPropertyInput.js +439 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/RelatedObjectInstance.d.ts +29 -0
- package/dist/published/components/custom/FormV2/components/FormFieldTypes/relatedObjectFiles/RelatedObjectInstance.js +74 -0
- package/dist/published/components/custom/FormV2/components/FormSections.d.ts +4 -0
- package/dist/published/components/custom/FormV2/components/FormSections.js +104 -0
- package/dist/published/components/custom/FormV2/components/RecursiveEntryRenderer.d.ts +2 -0
- package/dist/published/components/custom/FormV2/components/RecursiveEntryRenderer.js +209 -0
- package/dist/published/components/custom/FormV2/components/TabNav.d.ts +10 -0
- package/dist/published/components/custom/FormV2/components/TabNav.js +23 -0
- package/dist/published/components/custom/FormV2/components/ValidationFiles/Validation.d.ts +3 -0
- package/dist/published/components/custom/FormV2/components/ValidationFiles/Validation.js +176 -0
- package/dist/published/components/custom/FormV2/components/ValidationFiles/ValidationErrorDisplay.d.ts +10 -0
- package/dist/published/components/custom/FormV2/components/ValidationFiles/ValidationErrorDisplay.js +45 -0
- package/dist/published/components/custom/FormV2/components/types.d.ts +131 -0
- package/dist/published/components/custom/FormV2/components/types.js +1 -0
- package/dist/published/components/custom/FormV2/components/utils.d.ts +47 -0
- package/dist/published/components/custom/FormV2/components/utils.js +434 -0
- package/dist/published/components/custom/FormV2/index.d.ts +1 -0
- package/dist/published/components/custom/FormV2/index.js +1 -0
- package/dist/published/components/custom/index.d.ts +1 -0
- package/dist/published/components/custom/index.js +1 -0
- package/dist/published/index.d.ts +2 -2
- package/dist/published/index.js +2 -2
- package/dist/published/theme/hooks.d.ts +7 -0
- package/dist/published/theme/hooks.js +9 -0
- package/package.json +4 -2
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Help, InfoRounded } from '@mui/icons-material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { IconButton, InputLabel, Tooltip, Typography } from '../../../core';
|
|
4
|
+
import { Box } from '../../../layout';
|
|
5
|
+
const underFieldStyles = {
|
|
6
|
+
display: 'flex',
|
|
7
|
+
flexDirection: 'row',
|
|
8
|
+
justifyContent: 'space-between',
|
|
9
|
+
alignItems: 'center',
|
|
10
|
+
};
|
|
11
|
+
const descriptionStyles = {
|
|
12
|
+
color: '#999',
|
|
13
|
+
whiteSpace: 'normal',
|
|
14
|
+
display: 'block',
|
|
15
|
+
};
|
|
16
|
+
const PrefixSuffix = (props) => {
|
|
17
|
+
const { prefix, suffix, height, isViewOnly } = props;
|
|
18
|
+
const text = prefix || suffix;
|
|
19
|
+
const prefixSuffixStyles = {
|
|
20
|
+
display: 'inline-flex',
|
|
21
|
+
alignItems: 'center',
|
|
22
|
+
background: isViewOnly ? undefined : '#f5f5f5',
|
|
23
|
+
padding: '5px',
|
|
24
|
+
border: isViewOnly ? undefined : '1px solid #ccc',
|
|
25
|
+
...(suffix && {
|
|
26
|
+
borderTopRightRadius: '5px',
|
|
27
|
+
borderBottomRightRadius: '5px',
|
|
28
|
+
marginLeft: '-5px',
|
|
29
|
+
padding: '7px 5px 7px 10px',
|
|
30
|
+
marginTop: '6px',
|
|
31
|
+
}),
|
|
32
|
+
...(prefix && {
|
|
33
|
+
borderTopLeftRadius: '5px',
|
|
34
|
+
borderBottomLeftRadius: '5px',
|
|
35
|
+
marginRight: '-5px',
|
|
36
|
+
padding: '7px 10px 7px 5px',
|
|
37
|
+
marginTop: '6px',
|
|
38
|
+
}),
|
|
39
|
+
height: height === 'small' ? 24 : 40,
|
|
40
|
+
};
|
|
41
|
+
if (!prefix && !suffix)
|
|
42
|
+
return null;
|
|
43
|
+
return (React.createElement(Box, { sx: prefixSuffixStyles },
|
|
44
|
+
React.createElement(Typography, null, text)));
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A component that wraps a FormField and adds a label,
|
|
48
|
+
* description, tooltip, prefix, suffix and word/char counts
|
|
49
|
+
*/
|
|
50
|
+
const FieldWrapper = (props) => {
|
|
51
|
+
const { inputId, label, description, tooltip, prefix, suffix, value, maxLength, errorMessage, showCharCount, inputType, viewOnly, children, fieldHeight, required, } = props;
|
|
52
|
+
const charCount = typeof value === 'string' ? value.length : 0;
|
|
53
|
+
const remainingChars = maxLength ? maxLength - charCount : undefined;
|
|
54
|
+
return (React.createElement(Box, null,
|
|
55
|
+
React.createElement(Box, { sx: { padding: '10px 0' } },
|
|
56
|
+
inputType !== 'boolean' && (React.createElement(InputLabel, { htmlFor: inputId, sx: {
|
|
57
|
+
display: 'flex',
|
|
58
|
+
alignItems: 'center',
|
|
59
|
+
color: viewOnly ? 'text.secondary' : 'text.primary',
|
|
60
|
+
fontSize: '14px',
|
|
61
|
+
} },
|
|
62
|
+
label,
|
|
63
|
+
required ? (React.createElement(Typography, { component: 'span', sx: { color: 'red', fontSize: '12px', lineHeight: '22px', paddingLeft: '4px' } }, `*`)) : null,
|
|
64
|
+
tooltip && (React.createElement(Tooltip, { placement: "right", title: tooltip },
|
|
65
|
+
React.createElement(IconButton, null,
|
|
66
|
+
React.createElement(Help, { sx: { fontSize: '14px' } })))))),
|
|
67
|
+
React.createElement(Box, { sx: {
|
|
68
|
+
display: 'flex',
|
|
69
|
+
flexDirection: 'row',
|
|
70
|
+
alignItems: viewOnly ? 'center' : 'flex-start',
|
|
71
|
+
} },
|
|
72
|
+
inputType === 'string' && (React.createElement(PrefixSuffix, { prefix: prefix, height: fieldHeight || 'medium', isViewOnly: viewOnly })),
|
|
73
|
+
React.createElement(Box, { sx: {
|
|
74
|
+
width: viewOnly && suffix ? undefined : '100%',
|
|
75
|
+
marginTop: '6px',
|
|
76
|
+
borderRadius: '8px',
|
|
77
|
+
} },
|
|
78
|
+
children,
|
|
79
|
+
inputType !== 'boolean' && (errorMessage || description || showCharCount) && (React.createElement(Box, { sx: underFieldStyles },
|
|
80
|
+
React.createElement(Box, { sx: {
|
|
81
|
+
width: '100%',
|
|
82
|
+
display: 'flex',
|
|
83
|
+
justifyContent: 'space-between',
|
|
84
|
+
alignItems: 'flex-start',
|
|
85
|
+
flexWrap: 'wrap',
|
|
86
|
+
paddingTop: '4px',
|
|
87
|
+
} },
|
|
88
|
+
React.createElement(Box, { sx: { display: 'flex', flexDirection: 'column' } },
|
|
89
|
+
errorMessage ? (React.createElement(Box, { display: 'flex', alignItems: 'center' },
|
|
90
|
+
React.createElement(InfoRounded, { color: 'error', sx: { fontSize: '.75rem', marginRight: '3px' } }),
|
|
91
|
+
React.createElement(Typography, { fontSize: '12px', color: 'error', sx: { lineHeight: '18px' } }, errorMessage))) : (React.createElement("span", null)),
|
|
92
|
+
description && (React.createElement(Typography, { id: `${inputId}-description`, variant: "caption", sx: descriptionStyles }, description))),
|
|
93
|
+
showCharCount && (React.createElement(Typography, { variant: "caption", sx: { color: '#999999', whiteSpace: 'nowrap' } },
|
|
94
|
+
remainingChars ?? charCount,
|
|
95
|
+
' ',
|
|
96
|
+
(remainingChars ?? charCount) === 1 ? 'character' : 'characters',
|
|
97
|
+
!!maxLength && ` remaining`)))))),
|
|
98
|
+
inputType === 'string' && (React.createElement(PrefixSuffix, { suffix: suffix, height: fieldHeight || 'medium', isViewOnly: viewOnly }))))));
|
|
99
|
+
};
|
|
100
|
+
export default FieldWrapper;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Obj } from '@evoke-platform/context';
|
|
3
|
+
import { FieldValues, UseFormGetValues } from 'react-hook-form';
|
|
4
|
+
type FormContextType = {
|
|
5
|
+
fetchedOptions: FieldValues;
|
|
6
|
+
setFetchedOptions: (newData: FieldValues) => void;
|
|
7
|
+
getValues: UseFormGetValues<FieldValues>;
|
|
8
|
+
stickyFooter?: boolean;
|
|
9
|
+
object?: Obj;
|
|
10
|
+
};
|
|
11
|
+
export declare const FormContext: import("react").Context<FormContextType>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { InputField, InputParameter, InputParameterReference, Property, ReadonlyField } from '@evoke-platform/context';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { FieldErrors, FieldValues } from 'react-hook-form';
|
|
4
|
+
import { Address } from '../../../FormField/AddressFieldComponent';
|
|
5
|
+
interface AddressProps {
|
|
6
|
+
entry: InputParameterReference | ReadonlyField | InputField;
|
|
7
|
+
errors?: FieldErrors;
|
|
8
|
+
handleChange: (propertyId: string, value: string | Address | undefined) => void;
|
|
9
|
+
fieldHeight?: 'small' | 'medium';
|
|
10
|
+
readOnly?: boolean;
|
|
11
|
+
parameters?: InputParameter[];
|
|
12
|
+
instance?: FieldValues;
|
|
13
|
+
entryId: string;
|
|
14
|
+
fieldDefinition: InputParameter | Property;
|
|
15
|
+
}
|
|
16
|
+
declare function AddressFields(props: AddressProps): React.JSX.Element;
|
|
17
|
+
export default AddressFields;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useApiServices, } from '@evoke-platform/context';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useFormContext } from '../../../../../theme/hooks';
|
|
4
|
+
import { Typography } from '../../../../core';
|
|
5
|
+
import FormField from '../../../FormField';
|
|
6
|
+
import FieldWrapper from '../FieldWrapper';
|
|
7
|
+
import { getPrefixedUrl, isOptionEqualToValue } from '../utils';
|
|
8
|
+
function AddressFields(props) {
|
|
9
|
+
const { entry, errors, handleChange, fieldHeight, readOnly, parameters, instance, entryId, fieldDefinition } = props;
|
|
10
|
+
const { getValues } = useFormContext();
|
|
11
|
+
const apiServices = useApiServices();
|
|
12
|
+
const addressObject = entryId.split('.')[0];
|
|
13
|
+
const addressField = entryId.split('.')[1];
|
|
14
|
+
const addressValues = entry.type === 'readonlyField' ? instance?.[addressObject] : getValues(addressObject);
|
|
15
|
+
const fieldValue = addressValues?.[addressField];
|
|
16
|
+
const display = entry?.display;
|
|
17
|
+
const validation = fieldDefinition?.validation
|
|
18
|
+
? fieldDefinition.validation
|
|
19
|
+
: {};
|
|
20
|
+
const queryAddresses = async (query) => {
|
|
21
|
+
return await apiServices.get(getPrefixedUrl(`/locations/search`), {
|
|
22
|
+
params: { query: query },
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const handleAddressChange = (name, value) => {
|
|
26
|
+
if (addressField === 'line1' && typeof value === 'object' && value.line1) {
|
|
27
|
+
const addressKeys = ['line1', 'city', 'county', 'state', 'zipCode'];
|
|
28
|
+
addressKeys.forEach((key) => {
|
|
29
|
+
const fullKey = `${addressObject}.${key}`;
|
|
30
|
+
if (parameters?.some((p) => p.id === fullKey)) {
|
|
31
|
+
const fieldValue = value[key];
|
|
32
|
+
handleChange(fullKey, fieldValue);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
handleChange(name, value);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const addressErrors = errors?.[addressObject];
|
|
41
|
+
const addressFieldError = addressErrors?.[addressField];
|
|
42
|
+
return (React.createElement(FieldWrapper, { inputId: entryId, inputType: "string", label: display?.label || 'default', description: !readOnly ? display?.description : undefined, tooltip: display?.tooltip, value: fieldValue, maxLength: 'maxLength' in validation ? validation?.maxLength : 0, required: entry.display?.required || false, showCharCount: !readOnly && display?.charCount, viewOnly: !!readOnly, prefix: display?.prefix, suffix: display?.suffix }, !readOnly ? (React.createElement(FormField, { property: fieldDefinition, defaultValue: fieldValue, onChange: handleAddressChange, isMultiLineText: !!display?.rowCount, readOnly: entry.type === 'readonlyField', ...(addressField === 'line1' && { queryAddresses }), mask: validation?.mask, placeholder: display?.placeholder, isOptionEqualToValue: isOptionEqualToValue, size: fieldHeight, error: !!addressFieldError, errorMessage: addressFieldError?.message, additionalProps: {
|
|
43
|
+
...(display?.description && {
|
|
44
|
+
inputProps: {
|
|
45
|
+
'aria-describedby': `${entryId}-description`,
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
} })) : (React.createElement(Typography, { variant: "body1", key: entryId, sx: { height: '24px', paddingTop: '6px' } }, fieldValue))));
|
|
49
|
+
}
|
|
50
|
+
export default AddressFields;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Action, ActionType, EvokeForm, InputParameter, Obj } from '@evoke-platform/context';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export type ActionDialogProps = {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
action: Action;
|
|
7
|
+
instanceInput: Record<string, unknown>;
|
|
8
|
+
handleSubmit: (actionType: ActionType, input: Record<string, unknown> | undefined, instanceId?: string, setSubmitting?: (value: boolean) => void) => void;
|
|
9
|
+
object: Obj;
|
|
10
|
+
instanceId?: string;
|
|
11
|
+
relatedParameter?: InputParameter;
|
|
12
|
+
relatedForm?: EvokeForm;
|
|
13
|
+
};
|
|
14
|
+
export declare const ActionDialog: (props: ActionDialogProps) => React.JSX.Element;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useApiServices } from '@evoke-platform/context';
|
|
2
|
+
import { Close } from '@mui/icons-material';
|
|
3
|
+
import React, { useEffect, useState } from 'react';
|
|
4
|
+
import { Dialog, DialogContent, DialogTitle, IconButton, Skeleton } from '../../../../../core';
|
|
5
|
+
import { Box } from '../../../../../layout';
|
|
6
|
+
import ErrorComponent from '../../../../ErrorComponent';
|
|
7
|
+
import { getPrefixedUrl } from '../../utils';
|
|
8
|
+
const styles = {
|
|
9
|
+
button: {
|
|
10
|
+
textTransform: 'initial',
|
|
11
|
+
fontSize: '14px',
|
|
12
|
+
fontWeight: 700,
|
|
13
|
+
marginRight: '10px',
|
|
14
|
+
},
|
|
15
|
+
dialogTitle: {
|
|
16
|
+
fontSize: '18px',
|
|
17
|
+
fontWeight: 700,
|
|
18
|
+
paddingTop: '35px',
|
|
19
|
+
paddingBottom: '20px',
|
|
20
|
+
},
|
|
21
|
+
closeIcon: {
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
right: '17px',
|
|
24
|
+
top: '22px',
|
|
25
|
+
},
|
|
26
|
+
cancelBtn: {
|
|
27
|
+
border: '1px solid #ced4da',
|
|
28
|
+
width: '75px',
|
|
29
|
+
marginRight: '10px',
|
|
30
|
+
color: 'black',
|
|
31
|
+
},
|
|
32
|
+
deleteBtn: {
|
|
33
|
+
color: '#ffffff',
|
|
34
|
+
backgroundColor: '#A12723',
|
|
35
|
+
'&:hover': { backgroundColor: '#A12723' },
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
export const ActionDialog = (props) => {
|
|
39
|
+
const { open, onClose, action, object, instanceId, relatedForm, instanceInput } = props;
|
|
40
|
+
const [loading, setLoading] = useState(false);
|
|
41
|
+
const [hasAccess, setHasAccess] = useState();
|
|
42
|
+
const [form, setForm] = useState();
|
|
43
|
+
const apiServices = useApiServices();
|
|
44
|
+
const isDeleteAction = action.type === 'delete';
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (instanceId) {
|
|
47
|
+
setLoading(true);
|
|
48
|
+
apiServices.get(getPrefixedUrl(`/objects/${object.id}/instances/${instanceId}/checkAccess`), {
|
|
49
|
+
params: { action: 'execute', field: action.id },
|
|
50
|
+
}, (error, result) => {
|
|
51
|
+
setHasAccess(result?.result ?? false);
|
|
52
|
+
setLoading(false);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
setHasAccess(true);
|
|
57
|
+
setLoading(false);
|
|
58
|
+
}
|
|
59
|
+
}, [object, instanceId]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
setForm(isDeleteAction && !form
|
|
62
|
+
? {
|
|
63
|
+
id: '',
|
|
64
|
+
name: '',
|
|
65
|
+
entries: [
|
|
66
|
+
{
|
|
67
|
+
type: 'content',
|
|
68
|
+
html: `<p>You are about to delete ${instanceInput?.name}. Deleted records can't be restored. Are you sure you want to continue?</p>`,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
objectId: object.id,
|
|
72
|
+
actionId: '_delete',
|
|
73
|
+
display: {
|
|
74
|
+
submitLabel: 'Delete',
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
: relatedForm);
|
|
78
|
+
}, [relatedForm, action, form]);
|
|
79
|
+
return (React.createElement(Dialog, { maxWidth: 'md', fullWidth: true, open: open, onClose: (e, reason) => reason !== 'backdropClick' && onClose() },
|
|
80
|
+
React.createElement(DialogTitle, { sx: styles.dialogTitle },
|
|
81
|
+
React.createElement(IconButton, { sx: styles.closeIcon, onClick: onClose },
|
|
82
|
+
React.createElement(Close, { fontSize: "small" })),
|
|
83
|
+
action && hasAccess && !loading ? action?.name : ''),
|
|
84
|
+
React.createElement(DialogContent, { sx: { paddingBottom: loading ? undefined : '0px' } }, hasAccess ? (React.createElement(Box, { sx: { width: '100%', marginTop: '10px' } })) : (React.createElement(React.Fragment, null, loading ? (React.createElement(React.Fragment, null,
|
|
85
|
+
React.createElement(Skeleton, { height: '30px', animation: 'wave' }),
|
|
86
|
+
React.createElement(Skeleton, { height: '30px', animation: 'wave' }),
|
|
87
|
+
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' } })))))));
|
|
88
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ObjectInstance } from '@evoke-platform/context';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export type DocumentViewerCellProps = {
|
|
4
|
+
instance: ObjectInstance;
|
|
5
|
+
propertyId: string;
|
|
6
|
+
setSnackbarError: (error: {
|
|
7
|
+
showAlert: boolean;
|
|
8
|
+
message?: string;
|
|
9
|
+
isError?: boolean;
|
|
10
|
+
}) => void;
|
|
11
|
+
smallerThanMd?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare const DocumentViewerCell: (props: DocumentViewerCellProps) => React.JSX.Element;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { useApiServices } from '@evoke-platform/context';
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { AutorenewRounded, Close, FileWithExtension, LaunchRounded } from '../../../../../../icons';
|
|
4
|
+
import { Button, Dialog, DialogContent, DialogTitle, IconButton, Menu, MenuItem, Typography, } from '../../../../../core';
|
|
5
|
+
import { Grid } from '../../../../../layout';
|
|
6
|
+
import { getPrefixedUrl } from '../../utils';
|
|
7
|
+
const DocumentView = (props) => {
|
|
8
|
+
const { document } = props;
|
|
9
|
+
return (React.createElement(React.Fragment, null,
|
|
10
|
+
React.createElement(Grid, { item: true, sx: {
|
|
11
|
+
display: 'flex',
|
|
12
|
+
justifyContent: 'center',
|
|
13
|
+
padding: '7px',
|
|
14
|
+
} },
|
|
15
|
+
React.createElement(FileWithExtension, { fontFamily: "Arial", fileExtension: document.name?.split('.')?.pop() ?? '', sx: {
|
|
16
|
+
height: '1rem',
|
|
17
|
+
width: '1rem',
|
|
18
|
+
} })),
|
|
19
|
+
React.createElement(Grid, { item: true, xs: 12, sx: {
|
|
20
|
+
width: '100%',
|
|
21
|
+
overflow: 'hidden',
|
|
22
|
+
textOverflow: 'ellipsis',
|
|
23
|
+
} },
|
|
24
|
+
React.createElement(Typography, { noWrap: true, sx: {
|
|
25
|
+
fontSize: '14px',
|
|
26
|
+
fontWeight: 700,
|
|
27
|
+
lineHeight: '15px',
|
|
28
|
+
width: '100%',
|
|
29
|
+
} }, document?.name))));
|
|
30
|
+
};
|
|
31
|
+
export const DocumentViewerCell = (props) => {
|
|
32
|
+
const { instance, propertyId, setSnackbarError, smallerThanMd } = props;
|
|
33
|
+
const apiServices = useApiServices();
|
|
34
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
35
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
36
|
+
const downloadDocument = async (doc, instance) => {
|
|
37
|
+
setIsLoading(true);
|
|
38
|
+
try {
|
|
39
|
+
const documentResponse = await apiServices.get(getPrefixedUrl(`/objects/${instance.objectId}/instances/${instance.id}/documents/${doc.id}/content`), { responseType: 'blob' });
|
|
40
|
+
const contentType = documentResponse.type;
|
|
41
|
+
const blob = new Blob([documentResponse], { type: contentType });
|
|
42
|
+
const url = URL.createObjectURL(blob);
|
|
43
|
+
// Let the browser handle whether to open the document to view in a new tab or download it.
|
|
44
|
+
window.open(url, '_blank');
|
|
45
|
+
setIsLoading(false);
|
|
46
|
+
URL.revokeObjectURL(url);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
const status = error.status;
|
|
50
|
+
let message = 'An error occurred while downloading the document.';
|
|
51
|
+
if (status === 403) {
|
|
52
|
+
message = 'You do not have permission to download this document.';
|
|
53
|
+
}
|
|
54
|
+
else if (status === 404) {
|
|
55
|
+
message = 'Document not found.';
|
|
56
|
+
}
|
|
57
|
+
setIsLoading(false);
|
|
58
|
+
setSnackbarError({
|
|
59
|
+
showAlert: true,
|
|
60
|
+
message,
|
|
61
|
+
isError: true,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
return (React.createElement(React.Fragment, null, instance[propertyId]?.length ? (React.createElement(React.Fragment, null,
|
|
66
|
+
React.createElement(Button, { sx: {
|
|
67
|
+
display: 'flex',
|
|
68
|
+
alignItems: 'center',
|
|
69
|
+
justifyContent: 'flex-start',
|
|
70
|
+
padding: '6px 10px',
|
|
71
|
+
}, color: 'inherit', onClick: async (event) => {
|
|
72
|
+
event.stopPropagation();
|
|
73
|
+
const documents = instance[propertyId];
|
|
74
|
+
if (documents.length === 1) {
|
|
75
|
+
await downloadDocument(documents[0], instance);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
setAnchorEl(event.currentTarget);
|
|
79
|
+
}
|
|
80
|
+
}, variant: "text", "aria-haspopup": "menu", "aria-controls": `document-menu-${instance.id}-${propertyId}`, "aria-expanded": anchorEl ? 'true' : 'false' },
|
|
81
|
+
isLoading ? (React.createElement(AutorenewRounded, { sx: {
|
|
82
|
+
color: '#637381',
|
|
83
|
+
width: '20px',
|
|
84
|
+
height: '20px',
|
|
85
|
+
} })) : (React.createElement(LaunchRounded, { sx: {
|
|
86
|
+
color: '#637381',
|
|
87
|
+
width: '20px',
|
|
88
|
+
height: '20px',
|
|
89
|
+
} })),
|
|
90
|
+
React.createElement(Typography, { sx: {
|
|
91
|
+
marginLeft: '8px',
|
|
92
|
+
fontWeight: 400,
|
|
93
|
+
fontSize: '14px',
|
|
94
|
+
} }, isLoading ? 'Preparing document...' : 'View Document')),
|
|
95
|
+
!smallerThanMd ? (React.createElement(Menu, { id: `document-menu-${instance.id}-${propertyId}`, anchorEl: anchorEl, open: Boolean(anchorEl), onClose: () => {
|
|
96
|
+
setAnchorEl(null);
|
|
97
|
+
}, sx: {
|
|
98
|
+
'& .MuiPaper-root': {
|
|
99
|
+
borderRadius: '12px',
|
|
100
|
+
boxShadow: 'rgba(145, 158, 171, 0.2)',
|
|
101
|
+
},
|
|
102
|
+
}, variant: 'menu', PaperProps: {
|
|
103
|
+
tabIndex: 0,
|
|
104
|
+
sx: {
|
|
105
|
+
maxHeight: 200,
|
|
106
|
+
maxWidth: 300,
|
|
107
|
+
minWidth: 300,
|
|
108
|
+
},
|
|
109
|
+
component: 'nav',
|
|
110
|
+
} }, instance[propertyId].map((document) => (React.createElement(MenuItem, { key: document.id, onClick: async (e) => {
|
|
111
|
+
setAnchorEl(null);
|
|
112
|
+
await downloadDocument(document, instance);
|
|
113
|
+
}, "aria-label": document.name },
|
|
114
|
+
React.createElement(DocumentView, { document: document })))))) : (React.createElement(Dialog, { open: Boolean(anchorEl), onClose: () => setAnchorEl(null) },
|
|
115
|
+
React.createElement(DialogTitle, { sx: {
|
|
116
|
+
display: 'flex',
|
|
117
|
+
justifyContent: 'space-between',
|
|
118
|
+
alignItems: 'center',
|
|
119
|
+
paddingBottom: '0px',
|
|
120
|
+
} },
|
|
121
|
+
React.createElement(Typography, { sx: { fontSize: '14px', color: '#637381' } }, "Select a document to download"),
|
|
122
|
+
React.createElement(IconButton, { onClick: () => setAnchorEl(null) },
|
|
123
|
+
React.createElement(Close, { fontSize: "small" }))),
|
|
124
|
+
React.createElement(DialogContent, { sx: { padding: '20px 16px' } }, instance[propertyId].map((document) => (React.createElement(Grid, null,
|
|
125
|
+
React.createElement(Button, { color: 'inherit', onClick: async () => {
|
|
126
|
+
setAnchorEl(null);
|
|
127
|
+
await downloadDocument(document, instance);
|
|
128
|
+
}, sx: {
|
|
129
|
+
maxWidth: '100%',
|
|
130
|
+
overflow: 'hidden',
|
|
131
|
+
textOverflow: 'ellipsis',
|
|
132
|
+
whiteSpace: 'nowrap',
|
|
133
|
+
padding: '2px 0px',
|
|
134
|
+
}, key: document.id },
|
|
135
|
+
React.createElement(DocumentView, { document: document })))))))))) : (React.createElement(Typography, { sx: {
|
|
136
|
+
fontStyle: 'italic',
|
|
137
|
+
marginLeft: '12px',
|
|
138
|
+
fontSize: '14px',
|
|
139
|
+
} }, "No documents"))));
|
|
140
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ObjWithRoot as EvokeObjectWithRoot, InputParameter, ObjectInstance, Property, ViewLayoutEntityReference } from '@evoke-platform/context';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { FieldValues } from 'react-hook-form';
|
|
4
|
+
export type DropdownRepeatableFieldProps = {
|
|
5
|
+
id: string;
|
|
6
|
+
fieldDefinition: InputParameter | Property;
|
|
7
|
+
instance?: FieldValues;
|
|
8
|
+
criteria?: object;
|
|
9
|
+
readOnly: boolean;
|
|
10
|
+
initialMiddleObjectInstances: ObjectInstance[];
|
|
11
|
+
middleObject: EvokeObjectWithRoot;
|
|
12
|
+
fieldHeight?: 'small' | 'medium';
|
|
13
|
+
hasDescription?: boolean;
|
|
14
|
+
viewLayout?: ViewLayoutEntityReference;
|
|
15
|
+
};
|
|
16
|
+
declare const DropdownRepeatableField: (props: DropdownRepeatableFieldProps) => React.JSX.Element;
|
|
17
|
+
export default DropdownRepeatableField;
|