@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,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';
|
|
@@ -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
|
+
}
|
|
@@ -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.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/published/index.js",
|
|
6
6
|
"module": "dist/published/index.js",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"yalc": "^1.0.0-pre.53"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
|
-
"@evoke-platform/context": "^1.3.2-
|
|
93
|
+
"@evoke-platform/context": "^1.3.2-0",
|
|
94
94
|
"react": "^18.1.0",
|
|
95
95
|
"react-dom": "^18.1.0"
|
|
96
96
|
},
|