@overmap-ai/core 1.0.58-asset-description.4 → 1.0.58-asset-description.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/forms/index.d.ts +1 -1
- package/dist/overmap-core.js +125 -87
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +125 -87
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/sdk/services/UserFormSubmissionService.d.ts +3 -3
- package/dist/utils/array.d.ts +1 -0
- package/package.json +1 -1
package/dist/forms/index.d.ts
CHANGED
package/dist/overmap-core.js
CHANGED
|
@@ -7249,6 +7249,15 @@ class UserFormService extends BaseApiService {
|
|
|
7249
7249
|
store.dispatch(setFormRevisionAttachments(Object.values(result.attachments)));
|
|
7250
7250
|
}
|
|
7251
7251
|
}
|
|
7252
|
+
function chunkArray(arr, chunkSize) {
|
|
7253
|
+
const chunks = [];
|
|
7254
|
+
let index2 = 0;
|
|
7255
|
+
const arrLength = arr.length;
|
|
7256
|
+
while (index2 < arrLength) {
|
|
7257
|
+
chunks.push(arr.slice(index2, index2 += chunkSize));
|
|
7258
|
+
}
|
|
7259
|
+
return chunks;
|
|
7260
|
+
}
|
|
7252
7261
|
const isArrayOfFiles = (value) => {
|
|
7253
7262
|
return Array.isArray(value) && value[0] instanceof File;
|
|
7254
7263
|
};
|
|
@@ -7269,6 +7278,7 @@ const separateFilesFromValues = (values) => {
|
|
|
7269
7278
|
}
|
|
7270
7279
|
return { values: newValues, files };
|
|
7271
7280
|
};
|
|
7281
|
+
const MAX_BULK_ADD_SUBMISSIONS = 1e3;
|
|
7272
7282
|
class UserFormSubmissionService extends BaseApiService {
|
|
7273
7283
|
constructor() {
|
|
7274
7284
|
super(...arguments);
|
|
@@ -7355,103 +7365,129 @@ class UserFormSubmissionService extends BaseApiService {
|
|
|
7355
7365
|
const offlineSubmissions = [];
|
|
7356
7366
|
const offlineAttachments = [];
|
|
7357
7367
|
const submissionOfflineIds = [];
|
|
7358
|
-
const
|
|
7359
|
-
const attachmentsPayload = [];
|
|
7360
|
-
let files = {};
|
|
7368
|
+
const allFilesRecord = {};
|
|
7361
7369
|
const { values: fileSeperatedCommonFieldValues, files: commonFiles } = separateFilesFromValues(commonFieldValues);
|
|
7362
|
-
files = commonFiles;
|
|
7363
7370
|
const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7364
7371
|
const createdBy = store.getState().userReducer.currentUser.id;
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
7377
|
-
|
|
7378
|
-
|
|
7379
|
-
|
|
7380
|
-
|
|
7381
|
-
|
|
7382
|
-
|
|
7383
|
-
|
|
7384
|
-
|
|
7385
|
-
const sha1 = await hashFile(file);
|
|
7386
|
-
await this.client.files.addCache(file, sha1);
|
|
7387
|
-
const offlineAttachment = offline({
|
|
7388
|
-
file_name: file.name,
|
|
7389
|
-
file_sha1: sha1,
|
|
7390
|
-
file: URL.createObjectURL(file),
|
|
7391
|
-
submission: submission.offline_id,
|
|
7392
|
-
field_identifier: fieldIdentifier
|
|
7372
|
+
const assetIdBatches = chunkArray(Object.keys(fieldValuesByAsset), MAX_BULK_ADD_SUBMISSIONS);
|
|
7373
|
+
const bulkAddBatches = await Promise.all(
|
|
7374
|
+
assetIdBatches.map(async (assetIdBatch) => {
|
|
7375
|
+
const batchId = v4();
|
|
7376
|
+
const submissionsPayload = [];
|
|
7377
|
+
const attachmentsPayload = [];
|
|
7378
|
+
let files = { ...commonFiles };
|
|
7379
|
+
for (const assetId of assetIdBatch) {
|
|
7380
|
+
const { values: fileSeperatedSubmissionSpecificValues, files: submissionSpecificFiles } = separateFilesFromValues(fieldValuesByAsset[assetId] ?? {});
|
|
7381
|
+
files = Object.assign(files, submissionSpecificFiles);
|
|
7382
|
+
const submissionValues = {
|
|
7383
|
+
...fileSeperatedCommonFieldValues,
|
|
7384
|
+
...fileSeperatedSubmissionSpecificValues
|
|
7385
|
+
};
|
|
7386
|
+
const submission = offline({
|
|
7387
|
+
form_revision: formRevision,
|
|
7388
|
+
values: submissionValues,
|
|
7389
|
+
created_by: createdBy,
|
|
7390
|
+
submitted_at: submittedAt,
|
|
7391
|
+
asset: assetId
|
|
7393
7392
|
});
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
offline_id:
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
name: file.name,
|
|
7400
|
-
field_identifier: fieldIdentifier
|
|
7393
|
+
submissionOfflineIds.push(submission.offline_id);
|
|
7394
|
+
submissionsPayload.push({
|
|
7395
|
+
offline_id: submission.offline_id,
|
|
7396
|
+
asset_id: assetId,
|
|
7397
|
+
form_data: fileSeperatedSubmissionSpecificValues
|
|
7401
7398
|
});
|
|
7399
|
+
offlineSubmissions.push(submission);
|
|
7400
|
+
for (const [fieldIdentifier, fileArray] of Object.entries(files)) {
|
|
7401
|
+
for (const file of fileArray) {
|
|
7402
|
+
const sha1 = await hashFile(file);
|
|
7403
|
+
await this.client.files.addCache(file, sha1);
|
|
7404
|
+
const offlineAttachment = offline({
|
|
7405
|
+
file_name: file.name,
|
|
7406
|
+
file_sha1: sha1,
|
|
7407
|
+
file: URL.createObjectURL(file),
|
|
7408
|
+
submission: submission.offline_id,
|
|
7409
|
+
field_identifier: fieldIdentifier
|
|
7410
|
+
});
|
|
7411
|
+
offlineAttachments.push(offlineAttachment);
|
|
7412
|
+
attachmentsPayload.push({
|
|
7413
|
+
offline_id: offlineAttachment.offline_id,
|
|
7414
|
+
submission_id: submission.offline_id,
|
|
7415
|
+
sha1,
|
|
7416
|
+
name: file.name,
|
|
7417
|
+
field_identifier: fieldIdentifier
|
|
7418
|
+
});
|
|
7419
|
+
}
|
|
7420
|
+
}
|
|
7402
7421
|
}
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
|
|
7414
|
-
|
|
7422
|
+
const filePaylods = [];
|
|
7423
|
+
for (const file of Object.values(files).flat()) {
|
|
7424
|
+
const sha1 = await hashFile(file);
|
|
7425
|
+
const filePayload = {
|
|
7426
|
+
sha1,
|
|
7427
|
+
extension: file.name.split(".").pop() || "",
|
|
7428
|
+
file_type: file.type,
|
|
7429
|
+
size: file.size
|
|
7430
|
+
};
|
|
7431
|
+
allFilesRecord[sha1] = filePayload;
|
|
7432
|
+
filePaylods.push(filePayload);
|
|
7433
|
+
}
|
|
7434
|
+
return {
|
|
7435
|
+
batchId,
|
|
7436
|
+
payload: {
|
|
7437
|
+
form_data: fileSeperatedCommonFieldValues,
|
|
7438
|
+
submitted_at: submittedAt,
|
|
7439
|
+
submissions: submissionsPayload,
|
|
7440
|
+
attachments: attachmentsPayload,
|
|
7441
|
+
files: filePaylods
|
|
7442
|
+
}
|
|
7443
|
+
};
|
|
7444
|
+
})
|
|
7445
|
+
);
|
|
7415
7446
|
store.dispatch(addFormSubmissions(offlineSubmissions));
|
|
7416
7447
|
store.dispatch(addFormSubmissionAttachments(offlineAttachments));
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
files: Object.values(filesRecord)
|
|
7427
|
-
},
|
|
7428
|
-
blockers: Object.keys(fieldValuesByAsset),
|
|
7429
|
-
blocks: submissionOfflineIds
|
|
7430
|
-
});
|
|
7431
|
-
promise.then(({ submissions, attachments, presigned_urls }) => {
|
|
7432
|
-
store.dispatch(updateFormSubmissions(submissions));
|
|
7433
|
-
store.dispatch(updateFormSubmissionAttachments(attachments));
|
|
7434
|
-
for (const [sha1, presigned_url] of Object.entries(presigned_urls)) {
|
|
7435
|
-
const file = filesRecord[sha1];
|
|
7436
|
-
if (!file)
|
|
7437
|
-
continue;
|
|
7438
|
-
void this.client.enqueueRequest({
|
|
7439
|
-
url: presigned_url.url,
|
|
7440
|
-
description: "Upload file",
|
|
7448
|
+
let prevBatchId = null;
|
|
7449
|
+
const batchPromises = Promise.all(
|
|
7450
|
+
bulkAddBatches.map((batch) => {
|
|
7451
|
+
const { payload, batchId } = batch;
|
|
7452
|
+
const batchAssetIds = payload.submissions.map((x) => x.asset_id);
|
|
7453
|
+
const batchSubmissionOfflineIds = payload.submissions.map((x) => x.offline_id);
|
|
7454
|
+
const batchAttachmentsOfflineIds = payload.attachments.map((x) => x.offline_id);
|
|
7455
|
+
const promise = this.client.enqueueRequest({
|
|
7456
|
+
description: "Bulk add form submissions",
|
|
7441
7457
|
method: HttpMethod.POST,
|
|
7442
|
-
|
|
7443
|
-
|
|
7444
|
-
|
|
7445
|
-
|
|
7446
|
-
blocks: [sha1],
|
|
7447
|
-
s3url: presigned_url
|
|
7458
|
+
url: `/forms/revisions/${formRevision}/bulk-respond/`,
|
|
7459
|
+
payload,
|
|
7460
|
+
blockers: prevBatchId ? batchAssetIds.concat([prevBatchId]) : batchAssetIds,
|
|
7461
|
+
blocks: batchSubmissionOfflineIds.concat([batchId])
|
|
7448
7462
|
});
|
|
7449
|
-
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
|
|
7454
|
-
|
|
7463
|
+
promise.then(({ submissions, attachments, presigned_urls }) => {
|
|
7464
|
+
store.dispatch(updateFormSubmissions(submissions));
|
|
7465
|
+
store.dispatch(updateFormSubmissionAttachments(attachments));
|
|
7466
|
+
for (const [sha1, presigned_url] of Object.entries(presigned_urls)) {
|
|
7467
|
+
const file = allFilesRecord[sha1];
|
|
7468
|
+
if (!file)
|
|
7469
|
+
continue;
|
|
7470
|
+
void this.client.enqueueRequest({
|
|
7471
|
+
url: presigned_url.url,
|
|
7472
|
+
description: "Upload file",
|
|
7473
|
+
method: HttpMethod.POST,
|
|
7474
|
+
isExternalUrl: true,
|
|
7475
|
+
isAuthNeeded: false,
|
|
7476
|
+
attachmentHash: sha1,
|
|
7477
|
+
blockers: [`s3-${file.sha1}.${file.extension}`],
|
|
7478
|
+
blocks: [sha1],
|
|
7479
|
+
s3url: presigned_url
|
|
7480
|
+
});
|
|
7481
|
+
}
|
|
7482
|
+
}).catch(() => {
|
|
7483
|
+
store.dispatch(deleteFormSubmissions(batchSubmissionOfflineIds));
|
|
7484
|
+
store.dispatch(deleteFormSubmissionAttachments(batchAttachmentsOfflineIds));
|
|
7485
|
+
});
|
|
7486
|
+
prevBatchId = batchId;
|
|
7487
|
+
return promise;
|
|
7488
|
+
})
|
|
7489
|
+
);
|
|
7490
|
+
return [offlineSubmissions, batchPromises.then((results) => results.map(({ submissions }) => submissions))];
|
|
7455
7491
|
}
|
|
7456
7492
|
update(submission) {
|
|
7457
7493
|
const { store } = this.client;
|
|
@@ -16720,6 +16756,7 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
16720
16756
|
emptyTextField,
|
|
16721
16757
|
encodeFormValues,
|
|
16722
16758
|
formRevisionToSchema,
|
|
16759
|
+
initialFormValues,
|
|
16723
16760
|
isConditionMet,
|
|
16724
16761
|
useFieldInput,
|
|
16725
16762
|
useFieldInputs,
|
|
@@ -16983,6 +17020,7 @@ export {
|
|
|
16983
17020
|
hashFile,
|
|
16984
17021
|
hideAllCategories,
|
|
16985
17022
|
hideCategory,
|
|
17023
|
+
initialFormValues,
|
|
16986
17024
|
isConditionMet,
|
|
16987
17025
|
isToday,
|
|
16988
17026
|
issueReducer,
|