@overmap-ai/core 1.0.58-asset-description.7 → 1.0.58-asset-description.9
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 +153 -143
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +153 -143
- 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/dist/store/slices/assetSlice.d.ts +3 -1
- 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
|
@@ -1738,6 +1738,16 @@ const assetSlice = createSlice({
|
|
|
1738
1738
|
}
|
|
1739
1739
|
prevAssets = null;
|
|
1740
1740
|
},
|
|
1741
|
+
updateAssets: (state, action) => {
|
|
1742
|
+
for (const asset of action.payload) {
|
|
1743
|
+
if (asset.offline_id in state.assets) {
|
|
1744
|
+
state.assets[asset.offline_id] = asset;
|
|
1745
|
+
} else {
|
|
1746
|
+
throw new Error(`Tried to update asset with ID that doesn't exist: ${asset.offline_id}`);
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
prevAssets = null;
|
|
1750
|
+
},
|
|
1741
1751
|
removeAsset: (state, action) => {
|
|
1742
1752
|
if (action.payload in state.assets) {
|
|
1743
1753
|
delete state.assets[action.payload];
|
|
@@ -1746,6 +1756,16 @@ const assetSlice = createSlice({
|
|
|
1746
1756
|
}
|
|
1747
1757
|
prevAssets = null;
|
|
1748
1758
|
},
|
|
1759
|
+
removeAssets: (state, action) => {
|
|
1760
|
+
for (const assetId of action.payload) {
|
|
1761
|
+
if (assetId in state.assets) {
|
|
1762
|
+
delete state.assets[assetId];
|
|
1763
|
+
} else {
|
|
1764
|
+
throw new Error(`Failed to remove asset because ID doesn't exist: ${assetId}`);
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
prevAssets = null;
|
|
1768
|
+
},
|
|
1749
1769
|
removeAllAssetsOfType: (state, action) => {
|
|
1750
1770
|
var _a2;
|
|
1751
1771
|
for (const componentId in state.assets) {
|
|
@@ -1769,7 +1789,9 @@ const assetSlice = createSlice({
|
|
|
1769
1789
|
const {
|
|
1770
1790
|
addAsset,
|
|
1771
1791
|
updateAsset,
|
|
1792
|
+
updateAssets,
|
|
1772
1793
|
removeAsset,
|
|
1794
|
+
removeAssets,
|
|
1773
1795
|
addAssetsInBatches,
|
|
1774
1796
|
setAssets,
|
|
1775
1797
|
removeAllAssetsOfType,
|
|
@@ -5464,49 +5486,55 @@ class AssetService extends BaseApiService {
|
|
|
5464
5486
|
throw err;
|
|
5465
5487
|
});
|
|
5466
5488
|
}
|
|
5467
|
-
|
|
5489
|
+
// TODO: payload does not require asset_type
|
|
5490
|
+
bulkAdd(assetsToCreate, workspaceId, assetTypeId) {
|
|
5468
5491
|
const { store } = this.client;
|
|
5469
|
-
const
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
}
|
|
5478
|
-
};
|
|
5479
|
-
});
|
|
5480
|
-
store.dispatch(addAssetsInBatches(fullAssets));
|
|
5481
|
-
let prevBatchId = null;
|
|
5482
|
-
const batchPromises = Promise.all(
|
|
5483
|
-
assetBatches.map((assetBatch) => {
|
|
5484
|
-
const { batchId, payload } = assetBatch;
|
|
5485
|
-
const promise = this.client.enqueueRequest({
|
|
5486
|
-
description: "Batch create assets",
|
|
5487
|
-
method: HttpMethod.POST,
|
|
5488
|
-
url: `/assets/types/${assetTypeId}/add-assets/`,
|
|
5489
|
-
queryParams: {
|
|
5490
|
-
workspace_id: workspaceId.toString()
|
|
5491
|
-
},
|
|
5492
|
-
payload,
|
|
5493
|
-
blockers: prevBatchId ? [assetTypeId, prevBatchId] : [assetTypeId],
|
|
5494
|
-
blocks: assetBatch.payload.assets.map((c) => c.offline_id).concat([batchId])
|
|
5492
|
+
const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5493
|
+
const assetBatches = chunkArray(assetsToCreate, BULK_ADD_ASSET_BATCH_SIZE).map(
|
|
5494
|
+
(assetBatch) => {
|
|
5495
|
+
const assetPayloads = assetBatch.map((assetPayload) => {
|
|
5496
|
+
return offline({
|
|
5497
|
+
...assetPayload,
|
|
5498
|
+
submitted_at: submittedAt
|
|
5499
|
+
});
|
|
5495
5500
|
});
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
}).catch(() => {
|
|
5501
|
-
for (const asset of assetBatch.payload.assets) {
|
|
5502
|
-
store.dispatch(removeAsset(asset.offline_id));
|
|
5501
|
+
return {
|
|
5502
|
+
batchId: v4(),
|
|
5503
|
+
payload: {
|
|
5504
|
+
assets: assetPayloads
|
|
5503
5505
|
}
|
|
5504
|
-
}
|
|
5505
|
-
|
|
5506
|
-
return promise;
|
|
5507
|
-
})
|
|
5506
|
+
};
|
|
5507
|
+
}
|
|
5508
5508
|
);
|
|
5509
|
-
|
|
5509
|
+
const batchPromises = [];
|
|
5510
|
+
let prevBatchId = null;
|
|
5511
|
+
for (const assetBatch of assetBatches) {
|
|
5512
|
+
const { batchId, payload } = assetBatch;
|
|
5513
|
+
const batchAssetOfflineIds = payload.assets.map((c) => c.offline_id);
|
|
5514
|
+
const blockers = [assetTypeId];
|
|
5515
|
+
if (prevBatchId)
|
|
5516
|
+
blockers.push(prevBatchId);
|
|
5517
|
+
const blocks = batchAssetOfflineIds;
|
|
5518
|
+
blocks.push(batchId);
|
|
5519
|
+
const promise = this.client.enqueueRequest({
|
|
5520
|
+
description: "Batch create assets",
|
|
5521
|
+
method: HttpMethod.POST,
|
|
5522
|
+
url: `/assets/types/${assetTypeId}/add-assets/`,
|
|
5523
|
+
queryParams: {
|
|
5524
|
+
workspace_id: workspaceId.toString()
|
|
5525
|
+
},
|
|
5526
|
+
payload,
|
|
5527
|
+
blockers,
|
|
5528
|
+
blocks
|
|
5529
|
+
});
|
|
5530
|
+
prevBatchId = assetBatch.batchId;
|
|
5531
|
+
batchPromises.push(promise);
|
|
5532
|
+
}
|
|
5533
|
+
void Promise.all(batchPromises).then((result) => {
|
|
5534
|
+
const allCreatedAssets = result.flat();
|
|
5535
|
+
store.dispatch(addAssetsInBatches(allCreatedAssets));
|
|
5536
|
+
});
|
|
5537
|
+
return batchPromises;
|
|
5510
5538
|
}
|
|
5511
5539
|
async refreshStore() {
|
|
5512
5540
|
const { store } = this.client;
|
|
@@ -7374,62 +7402,37 @@ class UserFormSubmissionService extends BaseApiService {
|
|
|
7374
7402
|
// Note currently the bulkAdd method is specific to form submissions for assets
|
|
7375
7403
|
// TODO: adapt the support bulk adding to any model type
|
|
7376
7404
|
async bulkAdd(args) {
|
|
7377
|
-
const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
|
|
7378
7405
|
const { store } = this.client;
|
|
7379
|
-
const
|
|
7380
|
-
const offlineAttachments = [];
|
|
7381
|
-
const submissionOfflineIds = [];
|
|
7406
|
+
const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
|
|
7382
7407
|
const allFilesRecord = {};
|
|
7383
7408
|
const { values: fileSeperatedCommonFieldValues, files: commonFiles } = separateFilesFromValues(commonFieldValues);
|
|
7384
7409
|
const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7385
|
-
const createdBy = store.getState().userReducer.currentUser.id;
|
|
7386
7410
|
const assetIdBatches = chunkArray(Object.keys(fieldValuesByAsset), MAX_BULK_ADD_SUBMISSIONS);
|
|
7387
7411
|
const bulkAddBatches = await Promise.all(
|
|
7388
7412
|
assetIdBatches.map(async (assetIdBatch) => {
|
|
7389
7413
|
const batchId = v4();
|
|
7390
|
-
const
|
|
7391
|
-
const
|
|
7392
|
-
|
|
7414
|
+
const submissionPayloads = [];
|
|
7415
|
+
const attachmentPayloads = [];
|
|
7416
|
+
const files = { ...commonFiles };
|
|
7393
7417
|
for (const assetId of assetIdBatch) {
|
|
7394
7418
|
const { values: fileSeperatedSubmissionSpecificValues, files: submissionSpecificFiles } = separateFilesFromValues(fieldValuesByAsset[assetId] ?? {});
|
|
7395
|
-
|
|
7396
|
-
const
|
|
7397
|
-
...fileSeperatedCommonFieldValues,
|
|
7398
|
-
...fileSeperatedSubmissionSpecificValues
|
|
7399
|
-
};
|
|
7400
|
-
const submission = offline({
|
|
7401
|
-
form_revision: formRevision,
|
|
7402
|
-
values: submissionValues,
|
|
7403
|
-
created_by: createdBy,
|
|
7404
|
-
submitted_at: submittedAt,
|
|
7405
|
-
asset: assetId
|
|
7406
|
-
});
|
|
7407
|
-
submissionOfflineIds.push(submission.offline_id);
|
|
7408
|
-
submissionsPayload.push({
|
|
7409
|
-
offline_id: submission.offline_id,
|
|
7419
|
+
Object.assign(files, submissionSpecificFiles);
|
|
7420
|
+
const submissionPayload = offline({
|
|
7410
7421
|
asset_id: assetId,
|
|
7411
7422
|
form_data: fileSeperatedSubmissionSpecificValues
|
|
7412
7423
|
});
|
|
7413
|
-
|
|
7424
|
+
submissionPayloads.push(submissionPayload);
|
|
7414
7425
|
for (const [fieldIdentifier, fileArray] of Object.entries(files)) {
|
|
7415
7426
|
for (const file of fileArray) {
|
|
7416
7427
|
const sha1 = await hashFile(file);
|
|
7417
7428
|
await this.client.files.addCache(file, sha1);
|
|
7418
|
-
const
|
|
7419
|
-
|
|
7420
|
-
file_sha1: sha1,
|
|
7421
|
-
file: URL.createObjectURL(file),
|
|
7422
|
-
submission: submission.offline_id,
|
|
7423
|
-
field_identifier: fieldIdentifier
|
|
7424
|
-
});
|
|
7425
|
-
offlineAttachments.push(offlineAttachment);
|
|
7426
|
-
attachmentsPayload.push({
|
|
7427
|
-
offline_id: offlineAttachment.offline_id,
|
|
7428
|
-
submission_id: submission.offline_id,
|
|
7429
|
+
const attachmentPayload = offline({
|
|
7430
|
+
submission_id: submissionPayload.offline_id,
|
|
7429
7431
|
sha1,
|
|
7430
7432
|
name: file.name,
|
|
7431
7433
|
field_identifier: fieldIdentifier
|
|
7432
7434
|
});
|
|
7435
|
+
attachmentPayloads.push(attachmentPayload);
|
|
7433
7436
|
}
|
|
7434
7437
|
}
|
|
7435
7438
|
}
|
|
@@ -7450,58 +7453,66 @@ class UserFormSubmissionService extends BaseApiService {
|
|
|
7450
7453
|
payload: {
|
|
7451
7454
|
form_data: fileSeperatedCommonFieldValues,
|
|
7452
7455
|
submitted_at: submittedAt,
|
|
7453
|
-
submissions:
|
|
7454
|
-
attachments:
|
|
7456
|
+
submissions: submissionPayloads,
|
|
7457
|
+
attachments: attachmentPayloads,
|
|
7455
7458
|
files: filePaylods
|
|
7456
7459
|
}
|
|
7457
7460
|
};
|
|
7458
7461
|
})
|
|
7459
7462
|
);
|
|
7460
|
-
|
|
7461
|
-
store.dispatch(addFormSubmissionAttachments(offlineAttachments));
|
|
7463
|
+
const batchPromises = [];
|
|
7462
7464
|
let prevBatchId = null;
|
|
7463
|
-
const
|
|
7464
|
-
|
|
7465
|
-
|
|
7466
|
-
|
|
7467
|
-
|
|
7468
|
-
|
|
7469
|
-
|
|
7470
|
-
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
}
|
|
7496
|
-
}
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7465
|
+
for (const batch of bulkAddBatches) {
|
|
7466
|
+
const { payload, batchId } = batch;
|
|
7467
|
+
const batchAssetIds = payload.submissions.map((x) => x.asset_id);
|
|
7468
|
+
const batchSubmissionOfflineIds = payload.submissions.map((x) => x.offline_id);
|
|
7469
|
+
const batchAttachmentsOfflineIds = payload.attachments.map((x) => x.offline_id);
|
|
7470
|
+
const blockers = batchAssetIds;
|
|
7471
|
+
if (prevBatchId)
|
|
7472
|
+
blockers.push(prevBatchId);
|
|
7473
|
+
const blocks = [...batchSubmissionOfflineIds, ...batchAttachmentsOfflineIds, batchId];
|
|
7474
|
+
const promise = this.client.enqueueRequest({
|
|
7475
|
+
description: "Bulk add form submissions",
|
|
7476
|
+
method: HttpMethod.POST,
|
|
7477
|
+
url: `/forms/revisions/${formRevision}/bulk-respond/`,
|
|
7478
|
+
payload,
|
|
7479
|
+
blockers,
|
|
7480
|
+
blocks
|
|
7481
|
+
});
|
|
7482
|
+
void promise.then(({ presigned_urls }) => {
|
|
7483
|
+
for (const [sha1, presignedUrl] of Object.entries(presigned_urls)) {
|
|
7484
|
+
const file = allFilesRecord[sha1];
|
|
7485
|
+
if (!file)
|
|
7486
|
+
continue;
|
|
7487
|
+
void this.client.enqueueRequest({
|
|
7488
|
+
url: presignedUrl.url,
|
|
7489
|
+
description: "Upload file",
|
|
7490
|
+
method: HttpMethod.POST,
|
|
7491
|
+
isExternalUrl: true,
|
|
7492
|
+
isAuthNeeded: false,
|
|
7493
|
+
attachmentHash: sha1,
|
|
7494
|
+
blockers: [`s3-${file.sha1}.${file.extension}`],
|
|
7495
|
+
blocks: [sha1],
|
|
7496
|
+
s3url: presignedUrl
|
|
7497
|
+
});
|
|
7498
|
+
}
|
|
7499
|
+
});
|
|
7500
|
+
prevBatchId = batchId;
|
|
7501
|
+
batchPromises.push(promise);
|
|
7502
|
+
}
|
|
7503
|
+
void Promise.all(batchPromises).then((results) => {
|
|
7504
|
+
const createdSubmissions = [];
|
|
7505
|
+
const createdAttachments = [];
|
|
7506
|
+
for (const result of results) {
|
|
7507
|
+
for (const createdSubmission of result.submissions)
|
|
7508
|
+
createdSubmissions.push(createdSubmission);
|
|
7509
|
+
for (const createdAttachment of result.attachments)
|
|
7510
|
+
createdAttachments.push(createdAttachment);
|
|
7511
|
+
}
|
|
7512
|
+
store.dispatch(addFormSubmissions(createdSubmissions));
|
|
7513
|
+
store.dispatch(addFormSubmissionAttachments(createdAttachments));
|
|
7514
|
+
});
|
|
7515
|
+
return batchPromises;
|
|
7505
7516
|
}
|
|
7506
7517
|
update(submission) {
|
|
7507
7518
|
const { store } = this.client;
|
|
@@ -13115,10 +13126,7 @@ const MultiStringInput = memo((props) => {
|
|
|
13115
13126
|
helpText = showInputOnly ? null : helpText;
|
|
13116
13127
|
label = showInputOnly ? "" : label;
|
|
13117
13128
|
const color = useSeverityColor(severity);
|
|
13118
|
-
const value = useMemo(
|
|
13119
|
-
() => Array.isArray(fieldProps.value) ? fieldProps.value : [],
|
|
13120
|
-
[fieldProps.value]
|
|
13121
|
-
);
|
|
13129
|
+
const value = useMemo(() => Array.isArray(fieldProps.value) ? fieldProps.value : [], [fieldProps.value]);
|
|
13122
13130
|
const { onChange, onBlur } = fieldProps;
|
|
13123
13131
|
const droppableId = `${inputId}-droppable`;
|
|
13124
13132
|
const { disabled } = rest;
|
|
@@ -14934,39 +14942,37 @@ function formRevisionToSchema(formRevision, meta = {}) {
|
|
|
14934
14942
|
meta: { readonly }
|
|
14935
14943
|
};
|
|
14936
14944
|
}
|
|
14937
|
-
function
|
|
14938
|
-
|
|
14945
|
+
function flattenFields(schema) {
|
|
14946
|
+
const allFields = [];
|
|
14939
14947
|
for (const field of schema.fields) {
|
|
14940
14948
|
if (field instanceof FieldSection) {
|
|
14941
|
-
|
|
14949
|
+
for (const subField of field.fields) {
|
|
14950
|
+
allFields.push(subField);
|
|
14951
|
+
}
|
|
14942
14952
|
} else {
|
|
14943
14953
|
if (!(field instanceof BaseField)) {
|
|
14944
|
-
throw new Error(
|
|
14954
|
+
throw new Error(`Invalid field type: ${field.type}`);
|
|
14945
14955
|
}
|
|
14946
14956
|
allFields.push(field);
|
|
14947
14957
|
}
|
|
14948
14958
|
}
|
|
14959
|
+
return allFields;
|
|
14960
|
+
}
|
|
14961
|
+
function decodeFormValues(schema, values) {
|
|
14962
|
+
const allFields = flattenFields(schema);
|
|
14949
14963
|
const result = {};
|
|
14950
14964
|
for (const field of allFields) {
|
|
14951
|
-
|
|
14952
|
-
|
|
14953
|
-
|
|
14954
|
-
|
|
14965
|
+
const value = values[field.identifier] ?? null;
|
|
14966
|
+
if (value !== null) {
|
|
14967
|
+
result[field.identifier] = field.decodeJsonToValue(value);
|
|
14968
|
+
} else {
|
|
14969
|
+
result[field.identifier] = value;
|
|
14970
|
+
}
|
|
14955
14971
|
}
|
|
14956
14972
|
return result;
|
|
14957
14973
|
}
|
|
14958
14974
|
function encodeFormValues(schema, values) {
|
|
14959
|
-
|
|
14960
|
-
for (const field of schema.fields) {
|
|
14961
|
-
if (field instanceof FieldSection) {
|
|
14962
|
-
allFields = allFields.concat(field.fields);
|
|
14963
|
-
} else {
|
|
14964
|
-
if (!(field instanceof BaseField)) {
|
|
14965
|
-
throw new Error("Invalid field type");
|
|
14966
|
-
}
|
|
14967
|
-
allFields.push(field);
|
|
14968
|
-
}
|
|
14969
|
-
}
|
|
14975
|
+
const allFields = flattenFields(schema);
|
|
14970
14976
|
const result = {};
|
|
14971
14977
|
for (const field of allFields) {
|
|
14972
14978
|
const value = values[field.identifier];
|
|
@@ -16769,6 +16775,7 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
16769
16775
|
emptyStringField,
|
|
16770
16776
|
emptyTextField,
|
|
16771
16777
|
encodeFormValues,
|
|
16778
|
+
flattenFields,
|
|
16772
16779
|
formRevisionToSchema,
|
|
16773
16780
|
initialFormValues,
|
|
16774
16781
|
isConditionMet,
|
|
@@ -17011,6 +17018,7 @@ export {
|
|
|
17011
17018
|
fileReducer,
|
|
17012
17019
|
fileSlice,
|
|
17013
17020
|
fileToBlob,
|
|
17021
|
+
flattenFields,
|
|
17014
17022
|
flipCoordinates,
|
|
17015
17023
|
formReducer,
|
|
17016
17024
|
formRevisionReducer,
|
|
@@ -17088,6 +17096,7 @@ export {
|
|
|
17088
17096
|
removeAssetAttachments,
|
|
17089
17097
|
removeAssetTypeAttachment,
|
|
17090
17098
|
removeAssetTypeAttachments,
|
|
17099
|
+
removeAssets,
|
|
17091
17100
|
removeAttachmentsOfIssue,
|
|
17092
17101
|
removeCategory,
|
|
17093
17102
|
removeColor,
|
|
@@ -17405,6 +17414,7 @@ export {
|
|
|
17405
17414
|
updateAssetAttachments,
|
|
17406
17415
|
updateAssetTypeAttachment,
|
|
17407
17416
|
updateAssetTypeAttachments,
|
|
17417
|
+
updateAssets,
|
|
17408
17418
|
updateConversation,
|
|
17409
17419
|
updateDocumentAttachment,
|
|
17410
17420
|
updateDocumentAttachments,
|