@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.
@@ -1728,6 +1728,16 @@ var __publicField = (obj, key, value) => {
1728
1728
  }
1729
1729
  prevAssets = null;
1730
1730
  },
1731
+ updateAssets: (state, action) => {
1732
+ for (const asset of action.payload) {
1733
+ if (asset.offline_id in state.assets) {
1734
+ state.assets[asset.offline_id] = asset;
1735
+ } else {
1736
+ throw new Error(`Tried to update asset with ID that doesn't exist: ${asset.offline_id}`);
1737
+ }
1738
+ }
1739
+ prevAssets = null;
1740
+ },
1731
1741
  removeAsset: (state, action) => {
1732
1742
  if (action.payload in state.assets) {
1733
1743
  delete state.assets[action.payload];
@@ -1736,6 +1746,16 @@ var __publicField = (obj, key, value) => {
1736
1746
  }
1737
1747
  prevAssets = null;
1738
1748
  },
1749
+ removeAssets: (state, action) => {
1750
+ for (const assetId of action.payload) {
1751
+ if (assetId in state.assets) {
1752
+ delete state.assets[assetId];
1753
+ } else {
1754
+ throw new Error(`Failed to remove asset because ID doesn't exist: ${assetId}`);
1755
+ }
1756
+ }
1757
+ prevAssets = null;
1758
+ },
1739
1759
  removeAllAssetsOfType: (state, action) => {
1740
1760
  var _a2;
1741
1761
  for (const componentId in state.assets) {
@@ -1759,7 +1779,9 @@ var __publicField = (obj, key, value) => {
1759
1779
  const {
1760
1780
  addAsset,
1761
1781
  updateAsset,
1782
+ updateAssets,
1762
1783
  removeAsset,
1784
+ removeAssets,
1763
1785
  addAssetsInBatches,
1764
1786
  setAssets,
1765
1787
  removeAllAssetsOfType,
@@ -5454,49 +5476,55 @@ var __publicField = (obj, key, value) => {
5454
5476
  throw err;
5455
5477
  });
5456
5478
  }
5457
- addBulk(assetsToCreate, workspaceId, assetTypeId) {
5479
+ // TODO: payload does not require asset_type
5480
+ bulkAdd(assetsToCreate, workspaceId, assetTypeId) {
5458
5481
  const { store } = this.client;
5459
- const fullAssets = assetsToCreate.map((asset) => {
5460
- return { ...offline(asset), submitted_at: (/* @__PURE__ */ new Date()).toISOString() };
5461
- });
5462
- const assetBatches = chunkArray(fullAssets, BULK_ADD_ASSET_BATCH_SIZE).map((assetBatch) => {
5463
- return {
5464
- batchId: uuid.v4(),
5465
- payload: {
5466
- assets: assetBatch
5467
- }
5468
- };
5469
- });
5470
- store.dispatch(addAssetsInBatches(fullAssets));
5471
- let prevBatchId = null;
5472
- const batchPromises = Promise.all(
5473
- assetBatches.map((assetBatch) => {
5474
- const { batchId, payload } = assetBatch;
5475
- const promise = this.client.enqueueRequest({
5476
- description: "Batch create assets",
5477
- method: HttpMethod.POST,
5478
- url: `/assets/types/${assetTypeId}/add-assets/`,
5479
- queryParams: {
5480
- workspace_id: workspaceId.toString()
5481
- },
5482
- payload,
5483
- blockers: prevBatchId ? [assetTypeId, prevBatchId] : [assetTypeId],
5484
- blocks: assetBatch.payload.assets.map((c) => c.offline_id).concat([batchId])
5482
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
5483
+ const assetBatches = chunkArray(assetsToCreate, BULK_ADD_ASSET_BATCH_SIZE).map(
5484
+ (assetBatch) => {
5485
+ const assetPayloads = assetBatch.map((assetPayload) => {
5486
+ return offline({
5487
+ ...assetPayload,
5488
+ submitted_at: submittedAt
5489
+ });
5485
5490
  });
5486
- promise.then((result) => {
5487
- for (const assets of Object.values(result)) {
5488
- store.dispatch(updateAsset(assets));
5489
- }
5490
- }).catch(() => {
5491
- for (const asset of assetBatch.payload.assets) {
5492
- store.dispatch(removeAsset(asset.offline_id));
5491
+ return {
5492
+ batchId: uuid.v4(),
5493
+ payload: {
5494
+ assets: assetPayloads
5493
5495
  }
5494
- });
5495
- prevBatchId = assetBatch.batchId;
5496
- return promise;
5497
- })
5496
+ };
5497
+ }
5498
5498
  );
5499
- return [fullAssets, batchPromises.then((result) => result)];
5499
+ const batchPromises = [];
5500
+ let prevBatchId = null;
5501
+ for (const assetBatch of assetBatches) {
5502
+ const { batchId, payload } = assetBatch;
5503
+ const batchAssetOfflineIds = payload.assets.map((c) => c.offline_id);
5504
+ const blockers = [assetTypeId];
5505
+ if (prevBatchId)
5506
+ blockers.push(prevBatchId);
5507
+ const blocks2 = batchAssetOfflineIds;
5508
+ blocks2.push(batchId);
5509
+ const promise = this.client.enqueueRequest({
5510
+ description: "Batch create assets",
5511
+ method: HttpMethod.POST,
5512
+ url: `/assets/types/${assetTypeId}/add-assets/`,
5513
+ queryParams: {
5514
+ workspace_id: workspaceId.toString()
5515
+ },
5516
+ payload,
5517
+ blockers,
5518
+ blocks: blocks2
5519
+ });
5520
+ prevBatchId = assetBatch.batchId;
5521
+ batchPromises.push(promise);
5522
+ }
5523
+ void Promise.all(batchPromises).then((result) => {
5524
+ const allCreatedAssets = result.flat();
5525
+ store.dispatch(addAssetsInBatches(allCreatedAssets));
5526
+ });
5527
+ return batchPromises;
5500
5528
  }
5501
5529
  async refreshStore() {
5502
5530
  const { store } = this.client;
@@ -7364,62 +7392,37 @@ var __publicField = (obj, key, value) => {
7364
7392
  // Note currently the bulkAdd method is specific to form submissions for assets
7365
7393
  // TODO: adapt the support bulk adding to any model type
7366
7394
  async bulkAdd(args) {
7367
- const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
7368
7395
  const { store } = this.client;
7369
- const offlineSubmissions = [];
7370
- const offlineAttachments = [];
7371
- const submissionOfflineIds = [];
7396
+ const { formRevision, commonFieldValues, fieldValuesByAsset } = args;
7372
7397
  const allFilesRecord = {};
7373
7398
  const { values: fileSeperatedCommonFieldValues, files: commonFiles } = separateFilesFromValues(commonFieldValues);
7374
7399
  const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
7375
- const createdBy = store.getState().userReducer.currentUser.id;
7376
7400
  const assetIdBatches = chunkArray(Object.keys(fieldValuesByAsset), MAX_BULK_ADD_SUBMISSIONS);
7377
7401
  const bulkAddBatches = await Promise.all(
7378
7402
  assetIdBatches.map(async (assetIdBatch) => {
7379
7403
  const batchId = uuid.v4();
7380
- const submissionsPayload = [];
7381
- const attachmentsPayload = [];
7382
- let files = { ...commonFiles };
7404
+ const submissionPayloads = [];
7405
+ const attachmentPayloads = [];
7406
+ const files = { ...commonFiles };
7383
7407
  for (const assetId of assetIdBatch) {
7384
7408
  const { values: fileSeperatedSubmissionSpecificValues, files: submissionSpecificFiles } = separateFilesFromValues(fieldValuesByAsset[assetId] ?? {});
7385
- files = Object.assign(files, submissionSpecificFiles);
7386
- const submissionValues = {
7387
- ...fileSeperatedCommonFieldValues,
7388
- ...fileSeperatedSubmissionSpecificValues
7389
- };
7390
- const submission = offline({
7391
- form_revision: formRevision,
7392
- values: submissionValues,
7393
- created_by: createdBy,
7394
- submitted_at: submittedAt,
7395
- asset: assetId
7396
- });
7397
- submissionOfflineIds.push(submission.offline_id);
7398
- submissionsPayload.push({
7399
- offline_id: submission.offline_id,
7409
+ Object.assign(files, submissionSpecificFiles);
7410
+ const submissionPayload = offline({
7400
7411
  asset_id: assetId,
7401
7412
  form_data: fileSeperatedSubmissionSpecificValues
7402
7413
  });
7403
- offlineSubmissions.push(submission);
7414
+ submissionPayloads.push(submissionPayload);
7404
7415
  for (const [fieldIdentifier, fileArray] of Object.entries(files)) {
7405
7416
  for (const file of fileArray) {
7406
7417
  const sha1 = await hashFile(file);
7407
7418
  await this.client.files.addCache(file, sha1);
7408
- const offlineAttachment = offline({
7409
- file_name: file.name,
7410
- file_sha1: sha1,
7411
- file: URL.createObjectURL(file),
7412
- submission: submission.offline_id,
7413
- field_identifier: fieldIdentifier
7414
- });
7415
- offlineAttachments.push(offlineAttachment);
7416
- attachmentsPayload.push({
7417
- offline_id: offlineAttachment.offline_id,
7418
- submission_id: submission.offline_id,
7419
+ const attachmentPayload = offline({
7420
+ submission_id: submissionPayload.offline_id,
7419
7421
  sha1,
7420
7422
  name: file.name,
7421
7423
  field_identifier: fieldIdentifier
7422
7424
  });
7425
+ attachmentPayloads.push(attachmentPayload);
7423
7426
  }
7424
7427
  }
7425
7428
  }
@@ -7440,58 +7443,66 @@ var __publicField = (obj, key, value) => {
7440
7443
  payload: {
7441
7444
  form_data: fileSeperatedCommonFieldValues,
7442
7445
  submitted_at: submittedAt,
7443
- submissions: submissionsPayload,
7444
- attachments: attachmentsPayload,
7446
+ submissions: submissionPayloads,
7447
+ attachments: attachmentPayloads,
7445
7448
  files: filePaylods
7446
7449
  }
7447
7450
  };
7448
7451
  })
7449
7452
  );
7450
- store.dispatch(addFormSubmissions(offlineSubmissions));
7451
- store.dispatch(addFormSubmissionAttachments(offlineAttachments));
7453
+ const batchPromises = [];
7452
7454
  let prevBatchId = null;
7453
- const batchPromises = Promise.all(
7454
- bulkAddBatches.map((batch) => {
7455
- const { payload, batchId } = batch;
7456
- const batchAssetIds = payload.submissions.map((x) => x.asset_id);
7457
- const batchSubmissionOfflineIds = payload.submissions.map((x) => x.offline_id);
7458
- const batchAttachmentsOfflineIds = payload.attachments.map((x) => x.offline_id);
7459
- const promise = this.client.enqueueRequest({
7460
- description: "Bulk add form submissions",
7461
- method: HttpMethod.POST,
7462
- url: `/forms/revisions/${formRevision}/bulk-respond/`,
7463
- payload,
7464
- blockers: prevBatchId ? batchAssetIds.concat([prevBatchId]) : batchAssetIds,
7465
- blocks: batchSubmissionOfflineIds.concat([batchId])
7466
- });
7467
- promise.then(({ submissions, attachments, presigned_urls }) => {
7468
- store.dispatch(updateFormSubmissions(submissions));
7469
- store.dispatch(updateFormSubmissionAttachments(attachments));
7470
- for (const [sha1, presigned_url] of Object.entries(presigned_urls)) {
7471
- const file = allFilesRecord[sha1];
7472
- if (!file)
7473
- continue;
7474
- void this.client.enqueueRequest({
7475
- url: presigned_url.url,
7476
- description: "Upload file",
7477
- method: HttpMethod.POST,
7478
- isExternalUrl: true,
7479
- isAuthNeeded: false,
7480
- attachmentHash: sha1,
7481
- blockers: [`s3-${file.sha1}.${file.extension}`],
7482
- blocks: [sha1],
7483
- s3url: presigned_url
7484
- });
7485
- }
7486
- }).catch(() => {
7487
- store.dispatch(deleteFormSubmissions(batchSubmissionOfflineIds));
7488
- store.dispatch(deleteFormSubmissionAttachments(batchAttachmentsOfflineIds));
7489
- });
7490
- prevBatchId = batchId;
7491
- return promise;
7492
- })
7493
- );
7494
- return [offlineSubmissions, batchPromises.then((results) => results.map(({ submissions }) => submissions))];
7455
+ for (const batch of bulkAddBatches) {
7456
+ const { payload, batchId } = batch;
7457
+ const batchAssetIds = payload.submissions.map((x) => x.asset_id);
7458
+ const batchSubmissionOfflineIds = payload.submissions.map((x) => x.offline_id);
7459
+ const batchAttachmentsOfflineIds = payload.attachments.map((x) => x.offline_id);
7460
+ const blockers = batchAssetIds;
7461
+ if (prevBatchId)
7462
+ blockers.push(prevBatchId);
7463
+ const blocks2 = [...batchSubmissionOfflineIds, ...batchAttachmentsOfflineIds, batchId];
7464
+ const promise = this.client.enqueueRequest({
7465
+ description: "Bulk add form submissions",
7466
+ method: HttpMethod.POST,
7467
+ url: `/forms/revisions/${formRevision}/bulk-respond/`,
7468
+ payload,
7469
+ blockers,
7470
+ blocks: blocks2
7471
+ });
7472
+ void promise.then(({ presigned_urls }) => {
7473
+ for (const [sha1, presignedUrl] of Object.entries(presigned_urls)) {
7474
+ const file = allFilesRecord[sha1];
7475
+ if (!file)
7476
+ continue;
7477
+ void this.client.enqueueRequest({
7478
+ url: presignedUrl.url,
7479
+ description: "Upload file",
7480
+ method: HttpMethod.POST,
7481
+ isExternalUrl: true,
7482
+ isAuthNeeded: false,
7483
+ attachmentHash: sha1,
7484
+ blockers: [`s3-${file.sha1}.${file.extension}`],
7485
+ blocks: [sha1],
7486
+ s3url: presignedUrl
7487
+ });
7488
+ }
7489
+ });
7490
+ prevBatchId = batchId;
7491
+ batchPromises.push(promise);
7492
+ }
7493
+ void Promise.all(batchPromises).then((results) => {
7494
+ const createdSubmissions = [];
7495
+ const createdAttachments = [];
7496
+ for (const result of results) {
7497
+ for (const createdSubmission of result.submissions)
7498
+ createdSubmissions.push(createdSubmission);
7499
+ for (const createdAttachment of result.attachments)
7500
+ createdAttachments.push(createdAttachment);
7501
+ }
7502
+ store.dispatch(addFormSubmissions(createdSubmissions));
7503
+ store.dispatch(addFormSubmissionAttachments(createdAttachments));
7504
+ });
7505
+ return batchPromises;
7495
7506
  }
7496
7507
  update(submission) {
7497
7508
  const { store } = this.client;
@@ -13105,10 +13116,7 @@ var __publicField = (obj, key, value) => {
13105
13116
  helpText = showInputOnly ? null : helpText;
13106
13117
  label = showInputOnly ? "" : label;
13107
13118
  const color = blocks.useSeverityColor(severity);
13108
- const value = React.useMemo(
13109
- () => Array.isArray(fieldProps.value) ? fieldProps.value : [],
13110
- [fieldProps.value]
13111
- );
13119
+ const value = React.useMemo(() => Array.isArray(fieldProps.value) ? fieldProps.value : [], [fieldProps.value]);
13112
13120
  const { onChange, onBlur } = fieldProps;
13113
13121
  const droppableId = `${inputId}-droppable`;
13114
13122
  const { disabled } = rest;
@@ -14924,39 +14932,37 @@ var __publicField = (obj, key, value) => {
14924
14932
  meta: { readonly }
14925
14933
  };
14926
14934
  }
14927
- function decodeFormValues(schema, values) {
14928
- let allFields = [];
14935
+ function flattenFields(schema) {
14936
+ const allFields = [];
14929
14937
  for (const field of schema.fields) {
14930
14938
  if (field instanceof FieldSection) {
14931
- allFields = allFields.concat(field.fields);
14939
+ for (const subField of field.fields) {
14940
+ allFields.push(subField);
14941
+ }
14932
14942
  } else {
14933
14943
  if (!(field instanceof BaseField)) {
14934
- throw new Error("Invalid field type");
14944
+ throw new Error(`Invalid field type: ${field.type}`);
14935
14945
  }
14936
14946
  allFields.push(field);
14937
14947
  }
14938
14948
  }
14949
+ return allFields;
14950
+ }
14951
+ function decodeFormValues(schema, values) {
14952
+ const allFields = flattenFields(schema);
14939
14953
  const result = {};
14940
14954
  for (const field of allFields) {
14941
- if (!(field.identifier in values))
14942
- ;
14943
- const value = values[field.identifier];
14944
- result[field.identifier] = field.decodeJsonToValue(value);
14955
+ const value = values[field.identifier] ?? null;
14956
+ if (value !== null) {
14957
+ result[field.identifier] = field.decodeJsonToValue(value);
14958
+ } else {
14959
+ result[field.identifier] = value;
14960
+ }
14945
14961
  }
14946
14962
  return result;
14947
14963
  }
14948
14964
  function encodeFormValues(schema, values) {
14949
- let allFields = [];
14950
- for (const field of schema.fields) {
14951
- if (field instanceof FieldSection) {
14952
- allFields = allFields.concat(field.fields);
14953
- } else {
14954
- if (!(field instanceof BaseField)) {
14955
- throw new Error("Invalid field type");
14956
- }
14957
- allFields.push(field);
14958
- }
14959
- }
14965
+ const allFields = flattenFields(schema);
14960
14966
  const result = {};
14961
14967
  for (const field of allFields) {
14962
14968
  const value = values[field.identifier];
@@ -16759,6 +16765,7 @@ var __publicField = (obj, key, value) => {
16759
16765
  emptyStringField,
16760
16766
  emptyTextField,
16761
16767
  encodeFormValues,
16768
+ flattenFields,
16762
16769
  formRevisionToSchema,
16763
16770
  initialFormValues,
16764
16771
  isConditionMet,
@@ -17000,6 +17007,7 @@ var __publicField = (obj, key, value) => {
17000
17007
  exports2.fileReducer = fileReducer;
17001
17008
  exports2.fileSlice = fileSlice;
17002
17009
  exports2.fileToBlob = fileToBlob;
17010
+ exports2.flattenFields = flattenFields;
17003
17011
  exports2.flipCoordinates = flipCoordinates;
17004
17012
  exports2.formReducer = formReducer;
17005
17013
  exports2.formRevisionReducer = formRevisionReducer;
@@ -17077,6 +17085,7 @@ var __publicField = (obj, key, value) => {
17077
17085
  exports2.removeAssetAttachments = removeAssetAttachments;
17078
17086
  exports2.removeAssetTypeAttachment = removeAssetTypeAttachment;
17079
17087
  exports2.removeAssetTypeAttachments = removeAssetTypeAttachments;
17088
+ exports2.removeAssets = removeAssets;
17080
17089
  exports2.removeAttachmentsOfIssue = removeAttachmentsOfIssue;
17081
17090
  exports2.removeCategory = removeCategory;
17082
17091
  exports2.removeColor = removeColor;
@@ -17394,6 +17403,7 @@ var __publicField = (obj, key, value) => {
17394
17403
  exports2.updateAssetAttachments = updateAssetAttachments;
17395
17404
  exports2.updateAssetTypeAttachment = updateAssetTypeAttachment;
17396
17405
  exports2.updateAssetTypeAttachments = updateAssetTypeAttachments;
17406
+ exports2.updateAssets = updateAssets;
17397
17407
  exports2.updateConversation = updateConversation;
17398
17408
  exports2.updateDocumentAttachment = updateDocumentAttachment;
17399
17409
  exports2.updateDocumentAttachments = updateDocumentAttachments;