@overmap-ai/core 1.0.50-fix-error-messaging.0 → 1.0.50

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.
@@ -1561,6 +1561,7 @@ const selectHiddenCategoryCount = (state) => {
1561
1561
  };
1562
1562
  const categoryReducer = categorySlice.reducer;
1563
1563
  function setAttachments(state, action) {
1564
+ state.attachments = {};
1564
1565
  for (const attachment of action.payload) {
1565
1566
  state.attachments[attachment.offline_id] = attachment;
1566
1567
  }
@@ -1715,6 +1716,9 @@ const selectAllComponentAttachments = createSelector(
1715
1716
  [selectComponentAttachmentMapping],
1716
1717
  (mapping) => Object.values(mapping)
1717
1718
  );
1719
+ const selectComponentAttachment = (attachmentId) => (state) => {
1720
+ return state.componentReducer.attachments[attachmentId];
1721
+ };
1718
1722
  const selectAttachmentsOfComponent = restructureCreateSelectorWithArgs(
1719
1723
  createSelector(
1720
1724
  [selectAllComponentAttachments, (_state, componentId) => componentId],
@@ -2004,6 +2008,9 @@ const selectAllComponentTypeAttachments = createSelector(
2004
2008
  [selectComponentTypeAttachmentMapping],
2005
2009
  (mapping) => Object.values(mapping)
2006
2010
  );
2011
+ const selectComponentTypeAttachment = (attachmentId) => (state) => {
2012
+ return state.componentTypeReducer.attachments[attachmentId];
2013
+ };
2007
2014
  const selectAttachmentsOfComponentType = restructureCreateSelectorWithArgs(
2008
2015
  createSelector(
2009
2016
  [selectAllComponentTypeAttachments, (_state, componentTypeId) => componentTypeId],
@@ -2398,6 +2405,9 @@ const selectAttachmentsOfIssue = restructureCreateSelectorWithArgs(
2398
2405
  }
2399
2406
  )
2400
2407
  );
2408
+ const selectIssueAttachment = (attachmentId) => (root) => {
2409
+ return root.issueReducer.attachments[attachmentId];
2410
+ };
2401
2411
  const selectAttachmentsOfIssueByType = restructureCreateSelectorWithArgs(
2402
2412
  createSelector(
2403
2413
  [selectIssueAttachments, (_state, issueId) => issueId],
@@ -3852,7 +3862,8 @@ const selectSortedEmailDomains = (state) => Object.values(state.emailDomainsRedu
3852
3862
  );
3853
3863
  const emailDomainsReducer = emailDomainsSlice.reducer;
3854
3864
  const initialState$1 = {
3855
- documents: {}
3865
+ documents: {},
3866
+ attachments: {}
3856
3867
  };
3857
3868
  const documentSlice = createSlice({
3858
3869
  name: "documents",
@@ -3989,10 +4000,28 @@ const documentSlice = createSlice({
3989
4000
  }
3990
4001
  delete state.documents[documentId];
3991
4002
  }
3992
- }
4003
+ },
4004
+ setDocumentAttachments: setAttachments,
4005
+ addDocumentAttachment: addAttachment,
4006
+ addDocumentAttachments: addAttachments,
4007
+ updateDocumentAttachment: updateAttachment,
4008
+ removeDocumentAttachment: removeAttachment,
4009
+ removeDocumentAttachments: removeAttachments
3993
4010
  }
3994
4011
  });
3995
- const { setDocuments, addDocuments, updateDocuments, moveDocument, removeDocuments } = documentSlice.actions;
4012
+ const {
4013
+ setDocuments,
4014
+ addDocuments,
4015
+ updateDocuments,
4016
+ moveDocument,
4017
+ removeDocuments,
4018
+ setDocumentAttachments,
4019
+ addDocumentAttachment,
4020
+ addDocumentAttachments,
4021
+ updateDocumentAttachment,
4022
+ removeDocumentAttachment,
4023
+ removeDocumentAttachments
4024
+ } = documentSlice.actions;
3996
4025
  const selectDocumentsMapping = (state) => state.documentsReducer.documents;
3997
4026
  const selectDocuments = createSelector(
3998
4027
  [selectDocumentsMapping],
@@ -4022,6 +4051,39 @@ const selectRootDocuments = createSelector(
4022
4051
  [selectDocuments],
4023
4052
  (documents) => documents.filter((document2) => !document2.parent_document)
4024
4053
  );
4054
+ const selectDocumentAttachmentMapping = (state) => state.documentsReducer.attachments;
4055
+ const selectAllDocumentAttachments = createSelector(
4056
+ [selectDocumentAttachmentMapping],
4057
+ (mapping) => Object.values(mapping)
4058
+ );
4059
+ const selectDocumentAttachment = (attachmentId) => (state) => {
4060
+ return state.documentsReducer.attachments[attachmentId];
4061
+ };
4062
+ const selectAttachmentsOfDocument = restructureCreateSelectorWithArgs(
4063
+ createSelector(
4064
+ [selectAllDocumentAttachments, (_state, documentId) => documentId],
4065
+ (attachments, documentId) => {
4066
+ return attachments.filter(({ document: document2 }) => documentId === document2);
4067
+ }
4068
+ )
4069
+ );
4070
+ const selectAttachmentsOfDocumentByType = restructureCreateSelectorWithArgs(
4071
+ createSelector(
4072
+ [selectAllDocumentAttachments, (_state, documentId) => documentId],
4073
+ (attachments, documentId) => {
4074
+ const attachmentsOfProject = attachments.filter(({ document: document2 }) => documentId === document2);
4075
+ const fileAttachments = attachmentsOfProject.filter(
4076
+ // this null check here is necessary, there are cases where file_type is null or undefined
4077
+ ({ file_type }) => !file_type || !file_type.startsWith("image/")
4078
+ );
4079
+ const imageAttachments = attachmentsOfProject.filter(
4080
+ // this null check here is necessary, there are cases where file_type is null or undefined
4081
+ ({ file_type }) => file_type && file_type.startsWith("image/")
4082
+ );
4083
+ return { fileAttachments, imageAttachments };
4084
+ }
4085
+ )
4086
+ );
4025
4087
  const documentsReducer = documentSlice.reducer;
4026
4088
  const initialState = {
4027
4089
  version: 0
@@ -4602,7 +4664,8 @@ class AttachmentService extends BaseApiService {
4602
4664
  issue_attachments: Object.values(state.issueReducer.attachments),
4603
4665
  component_attachments: Object.values(state.componentReducer.attachments),
4604
4666
  component_type_attachments: Object.values(state.componentTypeReducer.attachments),
4605
- project_attachments: Object.values(state.projectReducer.attachments)
4667
+ project_attachments: Object.values(state.projectReducer.attachments),
4668
+ document_attachments: Object.values(state.documentsReducer.attachments)
4606
4669
  };
4607
4670
  return [allAttachments, promise];
4608
4671
  }
@@ -4706,8 +4769,8 @@ class AttachmentService extends BaseApiService {
4706
4769
  });
4707
4770
  return [offlineAttachment, promise];
4708
4771
  }
4709
- async addProjectAttachment(attachmentPayload) {
4710
- const { description: description2, project, file_sha1, offline_id } = attachmentPayload;
4772
+ async addDocumentAttachment(attachmentPayload) {
4773
+ const { description: description2, document: document2, file_sha1, offline_id } = attachmentPayload;
4711
4774
  if (!attachmentPayload.file.objectURL) {
4712
4775
  throw new Error("Expected attachmentPayload.file.objectURL to be defined.");
4713
4776
  }
@@ -4720,24 +4783,24 @@ class AttachmentService extends BaseApiService {
4720
4783
  created_by: this.client.store.getState().userReducer.currentUser.id
4721
4784
  };
4722
4785
  await this.client.files.addCache(attachmentPayload.file, file_sha1);
4723
- this.client.store.dispatch(addProjectAttachment(offlineAttachment));
4786
+ this.client.store.dispatch(addDocumentAttachment(offlineAttachment));
4724
4787
  const [fileProps] = await this.client.files.uploadFileToS3(file_sha1);
4725
4788
  const promise = this.enqueueRequest({
4726
4789
  description: "Create attachment",
4727
4790
  method: HttpMethod.POST,
4728
- url: `/projects/${project}/attach/`,
4729
- blocks: [offline_id, project.toString()],
4791
+ url: `/documents/${document2}/attach/`,
4792
+ blocks: [offline_id, document2],
4730
4793
  blockers: [file_sha1],
4731
4794
  payload: {
4732
4795
  offline_id,
4733
- project,
4796
+ document: document2,
4734
4797
  description: description2 ?? "",
4735
4798
  submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
4736
4799
  ...fileProps
4737
4800
  }
4738
4801
  });
4739
4802
  promise.catch((error2) => {
4740
- this.client.store.dispatch(removeProjectAttachment(offlineAttachment.offline_id));
4803
+ this.client.store.dispatch(removeDocumentAttachment(offlineAttachment.offline_id));
4741
4804
  throw error2;
4742
4805
  });
4743
4806
  return [offlineAttachment, promise];
@@ -4808,7 +4871,7 @@ class AttachmentService extends BaseApiService {
4808
4871
  return photoAttachmentPromise(file);
4809
4872
  });
4810
4873
  }
4811
- attachFilesToProject(filesToSubmit, projectId) {
4874
+ attachFilesToDocument(filesToSubmit, documentId) {
4812
4875
  return filesToSubmit.map((file) => {
4813
4876
  if (!(file instanceof File)) {
4814
4877
  throw new Error("Expected a File instance.");
@@ -4819,12 +4882,12 @@ class AttachmentService extends BaseApiService {
4819
4882
  file: file2,
4820
4883
  file_name: file2.name,
4821
4884
  file_type: file2.type,
4822
- project: projectId,
4885
+ document: documentId,
4823
4886
  file_sha1: hash,
4824
4887
  submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
4825
4888
  created_by: this.client.store.getState().userReducer.currentUser.id
4826
4889
  });
4827
- return this.addProjectAttachment(attachment);
4890
+ return this.addDocumentAttachment(attachment);
4828
4891
  };
4829
4892
  return photoAttachmentPromise(file);
4830
4893
  });
@@ -5004,9 +5067,9 @@ class AttachmentService extends BaseApiService {
5004
5067
  const promise = performRequest2();
5005
5068
  return [offlineAttachment, promise];
5006
5069
  }
5007
- async replaceProjectAttachmentFile(attachmentId, newFile) {
5070
+ async replaceDocumentAttachmentFile(attachmentId, newFile) {
5008
5071
  const { store } = this.client;
5009
- const attachment = store.getState().projectReducer.attachments[attachmentId];
5072
+ const attachment = store.getState().documentsReducer.attachments[attachmentId];
5010
5073
  if (!attachment)
5011
5074
  throw new Error(`Attachment ${attachmentId} not found`);
5012
5075
  let oldFile = void 0;
@@ -5020,7 +5083,7 @@ class AttachmentService extends BaseApiService {
5020
5083
  throw new Error(`newFile["objectURL"] is unexpectedly ${newFile.objectURL}`);
5021
5084
  }
5022
5085
  store.dispatch(
5023
- updateProjectAttachment({
5086
+ updateDocumentAttachment({
5024
5087
  ...attachment,
5025
5088
  file_sha1: newSha1,
5026
5089
  file: URL.createObjectURL(newFile)
@@ -5028,13 +5091,13 @@ class AttachmentService extends BaseApiService {
5028
5091
  );
5029
5092
  await this.client.files.addCache(newFile, newSha1);
5030
5093
  const [fileProps] = await this.client.files.uploadFileToS3(newSha1).catch((e) => {
5031
- store.dispatch(updateProjectAttachment(attachment));
5094
+ store.dispatch(updateDocumentAttachment(attachment));
5032
5095
  throw e;
5033
5096
  });
5034
5097
  const promise2 = this.enqueueRequest({
5035
5098
  description: "Edit attachment",
5036
5099
  method: HttpMethod.PATCH,
5037
- url: `/attachments/projects/${attachment.offline_id}/`,
5100
+ url: `/attachments/documents/${attachment.offline_id}/`,
5038
5101
  isResponseBlob: false,
5039
5102
  payload: fileProps,
5040
5103
  blockers: [attachmentId, newSha1],
@@ -5047,7 +5110,7 @@ class AttachmentService extends BaseApiService {
5047
5110
  } catch (e) {
5048
5111
  if (oldFile) {
5049
5112
  store.dispatch(
5050
- updateProjectAttachment({
5113
+ updateDocumentAttachment({
5051
5114
  ...attachment,
5052
5115
  file_sha1: attachment.file_sha1,
5053
5116
  file: URL.createObjectURL(oldFile)
@@ -5117,20 +5180,20 @@ class AttachmentService extends BaseApiService {
5117
5180
  blocks: [componentTypeAttachmentId]
5118
5181
  });
5119
5182
  }
5120
- deleteProjectAttachment(projectAttachmentId) {
5183
+ deleteDocumentAttachment(documentAttachmentId) {
5121
5184
  const { store } = this.client;
5122
- const attachment = selectProjectAttachmentMapping(store.getState())[projectAttachmentId];
5185
+ const attachment = store.getState().documentsReducer.attachments[documentAttachmentId];
5123
5186
  if (!attachment) {
5124
- throw new Error(`Attachment ${projectAttachmentId} not found`);
5187
+ throw new Error(`Attachment ${documentAttachmentId} not found`);
5125
5188
  }
5126
- store.dispatch(removeProjectAttachment(projectAttachmentId));
5189
+ store.dispatch(removeDocumentAttachment(documentAttachmentId));
5127
5190
  void this.client.files.removeCache(attachment.file_sha1);
5128
5191
  return this.enqueueRequest({
5129
- description: "Delete attachment",
5192
+ description: "Delete document attachment",
5130
5193
  method: HttpMethod.DELETE,
5131
- url: `/attachments/projects/${projectAttachmentId}/`,
5132
- blockers: [projectAttachmentId],
5133
- blocks: [projectAttachmentId]
5194
+ url: `/attachments/documents/${documentAttachmentId}/`,
5195
+ blockers: [documentAttachmentId],
5196
+ blocks: [documentAttachmentId]
5134
5197
  });
5135
5198
  }
5136
5199
  }
@@ -6367,11 +6430,18 @@ class MainService extends BaseApiService {
6367
6430
  if (currentProjectId) {
6368
6431
  const [_offlineAttachments, promise] = this.client.attachments.fetchAll(currentProjectId);
6369
6432
  void promise.then((result) => {
6370
- const { issue_attachments, component_type_attachments, component_attachments, project_attachments } = result;
6433
+ const {
6434
+ issue_attachments,
6435
+ component_type_attachments,
6436
+ component_attachments,
6437
+ project_attachments,
6438
+ document_attachments
6439
+ } = result;
6371
6440
  store.dispatch(setIssueAttachments(issue_attachments));
6372
6441
  store.dispatch(setComponentAttachments(component_attachments));
6373
6442
  store.dispatch(setComponentTypeAttachments(component_type_attachments));
6374
6443
  store.dispatch(setProjectAttachments(project_attachments));
6444
+ store.dispatch(setDocumentAttachments(document_attachments));
6375
6445
  });
6376
6446
  void this.client.documents.refreshStore();
6377
6447
  void this.client.issueUpdates.refreshStore();
@@ -15631,6 +15701,8 @@ export {
15631
15701
  addComponentTypeAttachment,
15632
15702
  addComponentTypeAttachments,
15633
15703
  addComponentsInBatches,
15704
+ addDocumentAttachment,
15705
+ addDocumentAttachments,
15634
15706
  addDocuments,
15635
15707
  addEmailDomain,
15636
15708
  addFavouriteProjectId,
@@ -15794,6 +15866,8 @@ export {
15794
15866
  removeComponentAttachments,
15795
15867
  removeComponentTypeAttachment,
15796
15868
  removeComponentTypeAttachments,
15869
+ removeDocumentAttachment,
15870
+ removeDocumentAttachments,
15797
15871
  removeDocuments,
15798
15872
  removeEmailDomain,
15799
15873
  removeFavouriteProjectId,
@@ -15841,6 +15915,7 @@ export {
15841
15915
  selectAllAttachments,
15842
15916
  selectAllComponentAttachments,
15843
15917
  selectAllComponentTypeAttachments,
15918
+ selectAllDocumentAttachments,
15844
15919
  selectAllProjectAttachments,
15845
15920
  selectAncestorIdsOfDocument,
15846
15921
  selectAppearance,
@@ -15848,6 +15923,8 @@ export {
15848
15923
  selectAttachmentsOfComponentByType,
15849
15924
  selectAttachmentsOfComponentType,
15850
15925
  selectAttachmentsOfComponentTypeByType,
15926
+ selectAttachmentsOfDocument,
15927
+ selectAttachmentsOfDocumentByType,
15851
15928
  selectAttachmentsOfIssue,
15852
15929
  selectAttachmentsOfIssueByType,
15853
15930
  selectAttachmentsOfProject,
@@ -15863,9 +15940,11 @@ export {
15863
15940
  selectCompletedStageIdsForComponent,
15864
15941
  selectCompletedStages,
15865
15942
  selectComponent,
15943
+ selectComponentAttachment,
15866
15944
  selectComponentAttachmentMapping,
15867
15945
  selectComponentSubmissionMapping,
15868
15946
  selectComponentType,
15947
+ selectComponentTypeAttachment,
15869
15948
  selectComponentTypeAttachmentMapping,
15870
15949
  selectComponentTypeForm,
15871
15950
  selectComponentTypeFromComponent,
@@ -15883,6 +15962,8 @@ export {
15883
15962
  selectCurrentUser,
15884
15963
  selectDeletedRequests,
15885
15964
  selectDocument,
15965
+ selectDocumentAttachment,
15966
+ selectDocumentAttachmentMapping,
15886
15967
  selectDocuments,
15887
15968
  selectDocumentsMapping,
15888
15969
  selectEmailDomainsAsMapping,
@@ -15904,6 +15985,7 @@ export {
15904
15985
  selectIsLoading,
15905
15986
  selectIsLoggedIn,
15906
15987
  selectIssue,
15988
+ selectIssueAttachment,
15907
15989
  selectIssueAttachmentMapping,
15908
15990
  selectIssueAttachments,
15909
15991
  selectIssueMapping,
@@ -15997,6 +16079,7 @@ export {
15997
16079
  setComponents,
15998
16080
  setCreateProjectType,
15999
16081
  setCurrentUser,
16082
+ setDocumentAttachments,
16000
16083
  setDocuments,
16001
16084
  setEmailDomains,
16002
16085
  setEnableClustering,
@@ -16051,6 +16134,7 @@ export {
16051
16134
  updateComponent,
16052
16135
  updateComponentAttachment,
16053
16136
  updateComponentTypeAttachment,
16137
+ updateDocumentAttachment,
16054
16138
  updateDocuments,
16055
16139
  updateIssue,
16056
16140
  updateIssueAttachment,