@overmap-ai/core 1.0.58-asset-description.8 → 1.0.58-asset-description.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/forms/fields/utils.d.ts +1 -0
- package/dist/overmap-core.js +125 -139
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +125 -139
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/sdk/services/AssetService.d.ts +2 -2
- package/dist/sdk/services/UserFormSubmissionService.d.ts +9 -2
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ export declare const deserializeField: (serializedField: ISerializedOnlyField) =
|
|
|
10
10
|
export declare const deserialize: (serialized: ISerializedField) => AnyField | FieldSection;
|
|
11
11
|
export type PartialFormRevision = Pick<UserFormRevision, "title" | "fields" | "description"> & Partial<UserFormRevision>;
|
|
12
12
|
export declare function formRevisionToSchema(formRevision: PartialFormRevision, meta?: Partial<SchemaMeta>): ISchema;
|
|
13
|
+
export declare function flattenFields(schema: ISchema): AnyField[];
|
|
13
14
|
export declare function decodeFormValues(schema: ISchema, values: Record<string, string>): Record<string, FieldValue>;
|
|
14
15
|
export declare function encodeFormValues(schema: ISchema, values: Record<string, FieldValue>): Record<string, string>;
|
|
15
16
|
export declare function valueIsFile(v: FieldValue | Promise<File>[] | undefined): v is File[] | Promise<File>[];
|
package/dist/overmap-core.js
CHANGED
|
@@ -5409,7 +5409,6 @@ function chunkArray(arr, chunkSize) {
|
|
|
5409
5409
|
}
|
|
5410
5410
|
return chunks;
|
|
5411
5411
|
}
|
|
5412
|
-
const BULK_ADD_ASSET_BATCH_SIZE = 1e3;
|
|
5413
5412
|
class AssetService extends BaseApiService {
|
|
5414
5413
|
// Basic CRUD functions
|
|
5415
5414
|
add(asset, workspaceId) {
|
|
@@ -5486,45 +5485,53 @@ class AssetService extends BaseApiService {
|
|
|
5486
5485
|
throw err;
|
|
5487
5486
|
});
|
|
5488
5487
|
}
|
|
5489
|
-
|
|
5488
|
+
// TODO: payload does not require asset_type
|
|
5489
|
+
bulkAdd(assetsToCreate, workspaceId, assetTypeId, batchSize) {
|
|
5490
5490
|
const { store } = this.client;
|
|
5491
|
-
const
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5491
|
+
const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5492
|
+
const assetBatches = chunkArray(assetsToCreate, batchSize).map((assetBatch) => {
|
|
5493
|
+
const assetPayloads = assetBatch.map((assetPayload) => {
|
|
5494
|
+
return offline({
|
|
5495
|
+
...assetPayload,
|
|
5496
|
+
submitted_at: submittedAt
|
|
5497
|
+
});
|
|
5498
|
+
});
|
|
5495
5499
|
return {
|
|
5496
5500
|
batchId: v4(),
|
|
5497
5501
|
payload: {
|
|
5498
|
-
assets:
|
|
5502
|
+
assets: assetPayloads
|
|
5499
5503
|
}
|
|
5500
5504
|
};
|
|
5501
5505
|
});
|
|
5502
|
-
|
|
5506
|
+
const batchPromises = [];
|
|
5503
5507
|
let prevBatchId = null;
|
|
5504
|
-
const
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
)
|
|
5527
|
-
|
|
5508
|
+
for (const assetBatch of assetBatches) {
|
|
5509
|
+
const { batchId, payload } = assetBatch;
|
|
5510
|
+
const batchAssetOfflineIds = payload.assets.map((c) => c.offline_id);
|
|
5511
|
+
const blockers = [assetTypeId];
|
|
5512
|
+
if (prevBatchId)
|
|
5513
|
+
blockers.push(prevBatchId);
|
|
5514
|
+
const blocks = batchAssetOfflineIds;
|
|
5515
|
+
blocks.push(batchId);
|
|
5516
|
+
const promise = this.client.enqueueRequest({
|
|
5517
|
+
description: "Batch create assets",
|
|
5518
|
+
method: HttpMethod.POST,
|
|
5519
|
+
url: `/assets/types/${assetTypeId}/add-assets/`,
|
|
5520
|
+
queryParams: {
|
|
5521
|
+
workspace_id: workspaceId.toString()
|
|
5522
|
+
},
|
|
5523
|
+
payload,
|
|
5524
|
+
blockers,
|
|
5525
|
+
blocks
|
|
5526
|
+
});
|
|
5527
|
+
prevBatchId = assetBatch.batchId;
|
|
5528
|
+
batchPromises.push(promise);
|
|
5529
|
+
}
|
|
5530
|
+
void Promise.all(batchPromises).then((result) => {
|
|
5531
|
+
const allCreatedAssets = result.flat();
|
|
5532
|
+
store.dispatch(addAssetsInBatches(allCreatedAssets));
|
|
5533
|
+
});
|
|
5534
|
+
return batchPromises;
|
|
5528
5535
|
}
|
|
5529
5536
|
async refreshStore() {
|
|
5530
5537
|
const { store } = this.client;
|
|
@@ -7310,7 +7317,6 @@ const separateFilesFromValues = (values) => {
|
|
|
7310
7317
|
}
|
|
7311
7318
|
return { values: newValues, files };
|
|
7312
7319
|
};
|
|
7313
|
-
const MAX_BULK_ADD_SUBMISSIONS = 1e3;
|
|
7314
7320
|
class UserFormSubmissionService extends BaseApiService {
|
|
7315
7321
|
constructor() {
|
|
7316
7322
|
super(...arguments);
|
|
@@ -7391,63 +7397,38 @@ class UserFormSubmissionService extends BaseApiService {
|
|
|
7391
7397
|
}
|
|
7392
7398
|
// Note currently the bulkAdd method is specific to form submissions for assets
|
|
7393
7399
|
// TODO: adapt the support bulk adding to any model type
|
|
7394
|
-
async bulkAdd(args) {
|
|
7395
|
-
const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
|
|
7400
|
+
async bulkAdd(args, batchSize) {
|
|
7396
7401
|
const { store } = this.client;
|
|
7397
|
-
const
|
|
7398
|
-
const offlineAttachments = [];
|
|
7399
|
-
const submissionOfflineIds = [];
|
|
7402
|
+
const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
|
|
7400
7403
|
const allFilesRecord = {};
|
|
7401
7404
|
const { values: fileSeperatedCommonFieldValues, files: commonFiles } = separateFilesFromValues(commonFieldValues);
|
|
7402
7405
|
const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7403
|
-
const
|
|
7404
|
-
const assetIdBatches = chunkArray(Object.keys(fieldValuesByAsset), MAX_BULK_ADD_SUBMISSIONS);
|
|
7406
|
+
const assetIdBatches = chunkArray(Object.keys(fieldValuesByAsset), batchSize);
|
|
7405
7407
|
const bulkAddBatches = await Promise.all(
|
|
7406
7408
|
assetIdBatches.map(async (assetIdBatch) => {
|
|
7407
7409
|
const batchId = v4();
|
|
7408
|
-
const
|
|
7409
|
-
const
|
|
7410
|
-
|
|
7410
|
+
const submissionPayloads = [];
|
|
7411
|
+
const attachmentPayloads = [];
|
|
7412
|
+
const files = { ...commonFiles };
|
|
7411
7413
|
for (const assetId of assetIdBatch) {
|
|
7412
7414
|
const { values: fileSeperatedSubmissionSpecificValues, files: submissionSpecificFiles } = separateFilesFromValues(fieldValuesByAsset[assetId] ?? {});
|
|
7413
|
-
|
|
7414
|
-
const
|
|
7415
|
-
...fileSeperatedCommonFieldValues,
|
|
7416
|
-
...fileSeperatedSubmissionSpecificValues
|
|
7417
|
-
};
|
|
7418
|
-
const submission = offline({
|
|
7419
|
-
form_revision: formRevision,
|
|
7420
|
-
values: submissionValues,
|
|
7421
|
-
created_by: createdBy,
|
|
7422
|
-
submitted_at: submittedAt,
|
|
7423
|
-
asset: assetId
|
|
7424
|
-
});
|
|
7425
|
-
submissionOfflineIds.push(submission.offline_id);
|
|
7426
|
-
submissionsPayload.push({
|
|
7427
|
-
offline_id: submission.offline_id,
|
|
7415
|
+
Object.assign(files, submissionSpecificFiles);
|
|
7416
|
+
const submissionPayload = offline({
|
|
7428
7417
|
asset_id: assetId,
|
|
7429
7418
|
form_data: fileSeperatedSubmissionSpecificValues
|
|
7430
7419
|
});
|
|
7431
|
-
|
|
7420
|
+
submissionPayloads.push(submissionPayload);
|
|
7432
7421
|
for (const [fieldIdentifier, fileArray] of Object.entries(files)) {
|
|
7433
7422
|
for (const file of fileArray) {
|
|
7434
7423
|
const sha1 = await hashFile(file);
|
|
7435
7424
|
await this.client.files.addCache(file, sha1);
|
|
7436
|
-
const
|
|
7437
|
-
|
|
7438
|
-
file_sha1: sha1,
|
|
7439
|
-
file: URL.createObjectURL(file),
|
|
7440
|
-
submission: submission.offline_id,
|
|
7441
|
-
field_identifier: fieldIdentifier
|
|
7442
|
-
});
|
|
7443
|
-
offlineAttachments.push(offlineAttachment);
|
|
7444
|
-
attachmentsPayload.push({
|
|
7445
|
-
offline_id: offlineAttachment.offline_id,
|
|
7446
|
-
submission_id: submission.offline_id,
|
|
7425
|
+
const attachmentPayload = offline({
|
|
7426
|
+
submission_id: submissionPayload.offline_id,
|
|
7447
7427
|
sha1,
|
|
7448
7428
|
name: file.name,
|
|
7449
7429
|
field_identifier: fieldIdentifier
|
|
7450
7430
|
});
|
|
7431
|
+
attachmentPayloads.push(attachmentPayload);
|
|
7451
7432
|
}
|
|
7452
7433
|
}
|
|
7453
7434
|
}
|
|
@@ -7468,58 +7449,66 @@ class UserFormSubmissionService extends BaseApiService {
|
|
|
7468
7449
|
payload: {
|
|
7469
7450
|
form_data: fileSeperatedCommonFieldValues,
|
|
7470
7451
|
submitted_at: submittedAt,
|
|
7471
|
-
submissions:
|
|
7472
|
-
attachments:
|
|
7452
|
+
submissions: submissionPayloads,
|
|
7453
|
+
attachments: attachmentPayloads,
|
|
7473
7454
|
files: filePaylods
|
|
7474
7455
|
}
|
|
7475
7456
|
};
|
|
7476
7457
|
})
|
|
7477
7458
|
);
|
|
7478
|
-
|
|
7479
|
-
store.dispatch(addFormSubmissionAttachments(offlineAttachments));
|
|
7459
|
+
const batchPromises = [];
|
|
7480
7460
|
let prevBatchId = null;
|
|
7481
|
-
const
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
}
|
|
7514
|
-
}
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7461
|
+
for (const batch of bulkAddBatches) {
|
|
7462
|
+
const { payload, batchId } = batch;
|
|
7463
|
+
const batchAssetIds = payload.submissions.map((x) => x.asset_id);
|
|
7464
|
+
const batchSubmissionOfflineIds = payload.submissions.map((x) => x.offline_id);
|
|
7465
|
+
const batchAttachmentsOfflineIds = payload.attachments.map((x) => x.offline_id);
|
|
7466
|
+
const blockers = batchAssetIds;
|
|
7467
|
+
if (prevBatchId)
|
|
7468
|
+
blockers.push(prevBatchId);
|
|
7469
|
+
const blocks = [...batchSubmissionOfflineIds, ...batchAttachmentsOfflineIds, batchId];
|
|
7470
|
+
const promise = this.client.enqueueRequest({
|
|
7471
|
+
description: "Bulk add form submissions",
|
|
7472
|
+
method: HttpMethod.POST,
|
|
7473
|
+
url: `/forms/revisions/${formRevision}/bulk-respond/`,
|
|
7474
|
+
payload,
|
|
7475
|
+
blockers,
|
|
7476
|
+
blocks
|
|
7477
|
+
});
|
|
7478
|
+
void promise.then(({ presigned_urls }) => {
|
|
7479
|
+
for (const [sha1, presignedUrl] of Object.entries(presigned_urls)) {
|
|
7480
|
+
const file = allFilesRecord[sha1];
|
|
7481
|
+
if (!file)
|
|
7482
|
+
continue;
|
|
7483
|
+
void this.client.enqueueRequest({
|
|
7484
|
+
url: presignedUrl.url,
|
|
7485
|
+
description: "Upload file",
|
|
7486
|
+
method: HttpMethod.POST,
|
|
7487
|
+
isExternalUrl: true,
|
|
7488
|
+
isAuthNeeded: false,
|
|
7489
|
+
attachmentHash: sha1,
|
|
7490
|
+
blockers: [`s3-${file.sha1}.${file.extension}`],
|
|
7491
|
+
blocks: [sha1],
|
|
7492
|
+
s3url: presignedUrl
|
|
7493
|
+
});
|
|
7494
|
+
}
|
|
7495
|
+
});
|
|
7496
|
+
prevBatchId = batchId;
|
|
7497
|
+
batchPromises.push(promise);
|
|
7498
|
+
}
|
|
7499
|
+
void Promise.all(batchPromises).then((results) => {
|
|
7500
|
+
const createdSubmissions = [];
|
|
7501
|
+
const createdAttachments = [];
|
|
7502
|
+
for (const result of results) {
|
|
7503
|
+
for (const createdSubmission of result.submissions)
|
|
7504
|
+
createdSubmissions.push(createdSubmission);
|
|
7505
|
+
for (const createdAttachment of result.attachments)
|
|
7506
|
+
createdAttachments.push(createdAttachment);
|
|
7507
|
+
}
|
|
7508
|
+
store.dispatch(addFormSubmissions(createdSubmissions));
|
|
7509
|
+
store.dispatch(addFormSubmissionAttachments(createdAttachments));
|
|
7510
|
+
});
|
|
7511
|
+
return batchPromises;
|
|
7523
7512
|
}
|
|
7524
7513
|
update(submission) {
|
|
7525
7514
|
const { store } = this.client;
|
|
@@ -13133,10 +13122,7 @@ const MultiStringInput = memo((props) => {
|
|
|
13133
13122
|
helpText = showInputOnly ? null : helpText;
|
|
13134
13123
|
label = showInputOnly ? "" : label;
|
|
13135
13124
|
const color = useSeverityColor(severity);
|
|
13136
|
-
const value = useMemo(
|
|
13137
|
-
() => Array.isArray(fieldProps.value) ? fieldProps.value : [],
|
|
13138
|
-
[fieldProps.value]
|
|
13139
|
-
);
|
|
13125
|
+
const value = useMemo(() => Array.isArray(fieldProps.value) ? fieldProps.value : [], [fieldProps.value]);
|
|
13140
13126
|
const { onChange, onBlur } = fieldProps;
|
|
13141
13127
|
const droppableId = `${inputId}-droppable`;
|
|
13142
13128
|
const { disabled } = rest;
|
|
@@ -14952,39 +14938,37 @@ function formRevisionToSchema(formRevision, meta = {}) {
|
|
|
14952
14938
|
meta: { readonly }
|
|
14953
14939
|
};
|
|
14954
14940
|
}
|
|
14955
|
-
function
|
|
14956
|
-
|
|
14941
|
+
function flattenFields(schema) {
|
|
14942
|
+
const allFields = [];
|
|
14957
14943
|
for (const field of schema.fields) {
|
|
14958
14944
|
if (field instanceof FieldSection) {
|
|
14959
|
-
|
|
14945
|
+
for (const subField of field.fields) {
|
|
14946
|
+
allFields.push(subField);
|
|
14947
|
+
}
|
|
14960
14948
|
} else {
|
|
14961
14949
|
if (!(field instanceof BaseField)) {
|
|
14962
|
-
throw new Error(
|
|
14950
|
+
throw new Error(`Invalid field type: ${field.type}`);
|
|
14963
14951
|
}
|
|
14964
14952
|
allFields.push(field);
|
|
14965
14953
|
}
|
|
14966
14954
|
}
|
|
14955
|
+
return allFields;
|
|
14956
|
+
}
|
|
14957
|
+
function decodeFormValues(schema, values) {
|
|
14958
|
+
const allFields = flattenFields(schema);
|
|
14967
14959
|
const result = {};
|
|
14968
14960
|
for (const field of allFields) {
|
|
14969
|
-
|
|
14970
|
-
|
|
14971
|
-
|
|
14972
|
-
|
|
14961
|
+
const value = values[field.identifier] ?? null;
|
|
14962
|
+
if (value !== null) {
|
|
14963
|
+
result[field.identifier] = field.decodeJsonToValue(value);
|
|
14964
|
+
} else {
|
|
14965
|
+
result[field.identifier] = value;
|
|
14966
|
+
}
|
|
14973
14967
|
}
|
|
14974
14968
|
return result;
|
|
14975
14969
|
}
|
|
14976
14970
|
function encodeFormValues(schema, values) {
|
|
14977
|
-
|
|
14978
|
-
for (const field of schema.fields) {
|
|
14979
|
-
if (field instanceof FieldSection) {
|
|
14980
|
-
allFields = allFields.concat(field.fields);
|
|
14981
|
-
} else {
|
|
14982
|
-
if (!(field instanceof BaseField)) {
|
|
14983
|
-
throw new Error("Invalid field type");
|
|
14984
|
-
}
|
|
14985
|
-
allFields.push(field);
|
|
14986
|
-
}
|
|
14987
|
-
}
|
|
14971
|
+
const allFields = flattenFields(schema);
|
|
14988
14972
|
const result = {};
|
|
14989
14973
|
for (const field of allFields) {
|
|
14990
14974
|
const value = values[field.identifier];
|
|
@@ -16787,6 +16771,7 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
16787
16771
|
emptyStringField,
|
|
16788
16772
|
emptyTextField,
|
|
16789
16773
|
encodeFormValues,
|
|
16774
|
+
flattenFields,
|
|
16790
16775
|
formRevisionToSchema,
|
|
16791
16776
|
initialFormValues,
|
|
16792
16777
|
isConditionMet,
|
|
@@ -17029,6 +17014,7 @@ export {
|
|
|
17029
17014
|
fileReducer,
|
|
17030
17015
|
fileSlice,
|
|
17031
17016
|
fileToBlob,
|
|
17017
|
+
flattenFields,
|
|
17032
17018
|
flipCoordinates,
|
|
17033
17019
|
formReducer,
|
|
17034
17020
|
formRevisionReducer,
|