@evoke-platform/ui-components 1.8.0-testing.1 → 1.8.0-testing.10
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/core/TextField/TextField.js +3 -2
- package/dist/published/components/custom/DataGrid/index.d.ts +1 -0
- 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/Form/utils.js +76 -44
- 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 +56 -109
- 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 +108 -2
- package/dist/published/components/custom/index.d.ts +1 -0
- package/dist/published/index.d.ts +1 -1
- package/dist/published/theme/hooks.d.ts +4 -0
- package/package.json +5 -2
|
@@ -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>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LocalDateTime } from '@js-joda/core';
|
|
2
2
|
import jsonLogic from 'json-logic-js';
|
|
3
|
-
import { get, isArray, isEmpty, isObject, omit, startCase, transform } from 'lodash';
|
|
3
|
+
import { get, isArray, isEmpty, isObject, omit, pick, startCase, transform } from 'lodash';
|
|
4
4
|
import { DateTime } from 'luxon';
|
|
5
5
|
import Handlebars from 'no-eval-handlebars';
|
|
6
6
|
import { defaultRuleProcessorMongoDB, formatQuery, parseMongoDB } from 'react-querybuilder';
|
|
@@ -116,7 +116,7 @@ export const getEntryId = (entry) => {
|
|
|
116
116
|
};
|
|
117
117
|
export function getPrefixedUrl(url) {
|
|
118
118
|
const wcsMatchers = ['/apps', '/pages', '/widgets'];
|
|
119
|
-
const dataMatchers = ['/objects', '/correspondenceTemplates', '/documents', '/payments', '/locations'];
|
|
119
|
+
const dataMatchers = ['/objects', '/correspondenceTemplates', '/documents', '/payments', '/forms', '/locations'];
|
|
120
120
|
const signalrMatchers = ['/hubs'];
|
|
121
121
|
const accessManagementMatchers = ['/users'];
|
|
122
122
|
const workflowMatchers = ['/workflows'];
|
|
@@ -562,3 +562,109 @@ export const docProperties = [
|
|
|
562
562
|
type: 'string',
|
|
563
563
|
},
|
|
564
564
|
];
|
|
565
|
+
export const uploadDocuments = async (files, metadata, apiServices, instanceId, objectId) => {
|
|
566
|
+
const allDocuments = [];
|
|
567
|
+
const formData = new FormData();
|
|
568
|
+
for (const [index, file] of files.entries()) {
|
|
569
|
+
if ('size' in file) {
|
|
570
|
+
formData.append(`files[${index}]`, file);
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
allDocuments.push(file);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (metadata) {
|
|
577
|
+
for (const [key, value] of Object.entries(metadata)) {
|
|
578
|
+
formData.append(key, value);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const docs = await apiServices.post(getPrefixedUrl(`/objects/${objectId}/instances/${instanceId}/documents`), formData);
|
|
582
|
+
return allDocuments.concat(docs?.map((doc) => ({
|
|
583
|
+
id: doc.id,
|
|
584
|
+
name: doc.name,
|
|
585
|
+
})) ?? []);
|
|
586
|
+
};
|
|
587
|
+
export const deleteDocuments = async (submittedFields, requestSuccess, apiServices, object, instance, action, setSnackbarError) => {
|
|
588
|
+
const documentProperties = action?.parameters
|
|
589
|
+
? action.parameters.filter((param) => param.type === 'document')
|
|
590
|
+
: object?.properties?.filter((prop) => prop.type === 'document');
|
|
591
|
+
for (const docProperty of documentProperties ?? []) {
|
|
592
|
+
const savedValue = submittedFields[docProperty.id];
|
|
593
|
+
const originalValue = instance?.[docProperty.id];
|
|
594
|
+
const documentsToRemove = requestSuccess
|
|
595
|
+
? (originalValue?.filter((file) => !savedValue?.some((f) => f.id === file.id)) ?? [])
|
|
596
|
+
: (savedValue?.filter((file) => !originalValue?.some((f) => f.id === file.id)) ?? []);
|
|
597
|
+
for (const doc of documentsToRemove) {
|
|
598
|
+
try {
|
|
599
|
+
await apiServices?.delete(getPrefixedUrl(`/objects/${object.id}/instances/${instance.id}/documents/${doc.id}`));
|
|
600
|
+
}
|
|
601
|
+
catch (error) {
|
|
602
|
+
if (error) {
|
|
603
|
+
setSnackbarError &&
|
|
604
|
+
setSnackbarError({
|
|
605
|
+
showAlert: true,
|
|
606
|
+
message: `An error occurred while removing document '${doc.name}'`,
|
|
607
|
+
isError: true,
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
/**
|
|
615
|
+
* Transforms a form submission into a format safe for API submission.
|
|
616
|
+
*
|
|
617
|
+
* Responsibilities:
|
|
618
|
+
* - Uploads any files found in submission fields.
|
|
619
|
+
* - Normalizes related objects (keeping only id and name not the whole instance).
|
|
620
|
+
* - Converts an object of undefined address fields to undefined instead of an empty object.
|
|
621
|
+
* - Normalizes LocalDateTime values to API-friendly format.
|
|
622
|
+
* - Converts empty strings or undefined values to null.
|
|
623
|
+
* - Optionally reports file upload errors via snackbar.
|
|
624
|
+
*
|
|
625
|
+
* Returns the cleaned submission ready for submitting.
|
|
626
|
+
*/
|
|
627
|
+
export async function formatSubmission(submission, apiServices, objectId, instanceId, setSnackbarError) {
|
|
628
|
+
for (const [key, value] of Object.entries(submission)) {
|
|
629
|
+
if (isArray(value)) {
|
|
630
|
+
const fileInArray = value.some((item) => item instanceof File);
|
|
631
|
+
if (fileInArray && instanceId) {
|
|
632
|
+
try {
|
|
633
|
+
const uploadedDocuments = await uploadDocuments(value, {
|
|
634
|
+
type: '',
|
|
635
|
+
view_permission: '',
|
|
636
|
+
}, apiServices, instanceId, objectId);
|
|
637
|
+
submission[key] = uploadedDocuments;
|
|
638
|
+
}
|
|
639
|
+
catch (err) {
|
|
640
|
+
if (err) {
|
|
641
|
+
setSnackbarError &&
|
|
642
|
+
setSnackbarError({
|
|
643
|
+
showAlert: true,
|
|
644
|
+
message: `An error occurred while uploading associated documents`,
|
|
645
|
+
isError: true,
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
return submission;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
// if there are address fields with no value address needs to be set to undefined to be able to submit
|
|
652
|
+
}
|
|
653
|
+
else if (typeof value === 'object' && value !== null) {
|
|
654
|
+
if (Object.values(value).every((v) => v === undefined)) {
|
|
655
|
+
submission[key] = undefined;
|
|
656
|
+
// only submit the name and id of a related object
|
|
657
|
+
}
|
|
658
|
+
else if ('id' in value && 'name' in value) {
|
|
659
|
+
submission[key] = pick(value, 'id', 'name');
|
|
660
|
+
}
|
|
661
|
+
else if (value instanceof LocalDateTime) {
|
|
662
|
+
submission[key] = normalizeDateTime(value);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
else if (value === '' || value === undefined) {
|
|
666
|
+
submission[key] = null;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
return submission;
|
|
670
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { BuilderGrid } from './BuilderGrid';
|
|
2
2
|
export { CriteriaBuilder, getReadableQuery } from './CriteriaBuilder';
|
|
3
3
|
export { DataGrid } from './DataGrid';
|
|
4
|
+
export type { GridSortModel } from './DataGrid';
|
|
4
5
|
export { ErrorComponent } from './ErrorComponent';
|
|
5
6
|
export { Form } from './Form';
|
|
6
7
|
export type { FormRef } from './Form';
|
|
@@ -3,7 +3,7 @@ export { CalendarPicker, DateTimePicker, MonthPicker, PickersDay, StaticDateTime
|
|
|
3
3
|
export * from './colors';
|
|
4
4
|
export * from './components/core';
|
|
5
5
|
export { BuilderGrid, CriteriaBuilder, DataGrid, ErrorComponent, Form, FormContext, FormField, FormRenderer, FormRendererContainer, getReadableQuery, HistoryLog, MenuBar, MultiSelect, RecursiveEntryRenderer, RepeatableField, ResponsiveOverflow, RichTextViewer, UserAvatar, } from './components/custom';
|
|
6
|
-
export type { FormRef } from './components/custom';
|
|
6
|
+
export type { FormRef, GridSortModel } from './components/custom';
|
|
7
7
|
export { NumericFormat } from './components/custom/FormField/InputFieldComponent';
|
|
8
8
|
export { Box, Container, Grid, Stack } from './components/layout';
|
|
9
9
|
export * from './theme';
|
|
@@ -126,4 +126,8 @@ export declare function useFormContext(): {
|
|
|
126
126
|
fieldHeight?: "medium" | "small" | undefined;
|
|
127
127
|
triggerFieldReset?: boolean | undefined;
|
|
128
128
|
showSubmitError?: boolean | undefined;
|
|
129
|
+
associatedObject?: {
|
|
130
|
+
instanceId?: string | undefined;
|
|
131
|
+
propertyId?: string | undefined;
|
|
132
|
+
} | undefined;
|
|
129
133
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evoke-platform/ui-components",
|
|
3
|
-
"version": "1.8.0-testing.
|
|
3
|
+
"version": "1.8.0-testing.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/published/index.js",
|
|
6
6
|
"module": "dist/published/index.js",
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
"icons.ts",
|
|
10
10
|
"colors.ts"
|
|
11
11
|
],
|
|
12
|
+
"sideEffects": [
|
|
13
|
+
"*.css"
|
|
14
|
+
],
|
|
12
15
|
"exports": {
|
|
13
16
|
".": "./dist/published/index.js",
|
|
14
17
|
"./colors": "./dist/published/colors/index.js",
|
|
@@ -87,7 +90,7 @@
|
|
|
87
90
|
"yalc": "^1.0.0-pre.53"
|
|
88
91
|
},
|
|
89
92
|
"peerDependencies": {
|
|
90
|
-
"@evoke-platform/context": "^1.3.
|
|
93
|
+
"@evoke-platform/context": "^1.3.2-0",
|
|
91
94
|
"react": "^18.1.0",
|
|
92
95
|
"react-dom": "^18.1.0"
|
|
93
96
|
},
|