@overmap-ai/core 1.0.50-bulk-form-submission.1 → 1.0.50-bulk-form-submission.3

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.
@@ -1551,15 +1551,6 @@ function updateAttachment(state, action) {
1551
1551
  throw new Error(`Attachment ${action.payload.offline_id} does not exist.`);
1552
1552
  }
1553
1553
  }
1554
- function updateAttachments(state, action) {
1555
- for (const attachment of action.payload) {
1556
- if (attachment.offline_id in state.attachments) {
1557
- state.attachments[attachment.offline_id] = attachment;
1558
- } else {
1559
- throw new Error(`Attachment ${attachment.offline_id} does not exist.`);
1560
- }
1561
- }
1562
- }
1563
1554
  function removeAttachment(state, action) {
1564
1555
  if (action.payload in state.attachments) {
1565
1556
  delete state.attachments[action.payload];
@@ -2159,7 +2150,6 @@ const issueSlice = createSlice({
2159
2150
  }
2160
2151
  },
2161
2152
  updateIssueAttachment: updateAttachment,
2162
- updateIssueAttachments: updateAttachments,
2163
2153
  removeIssue: (state, action) => {
2164
2154
  if (action.payload in state.issues) {
2165
2155
  delete state.issues[action.payload];
@@ -2168,7 +2158,6 @@ const issueSlice = createSlice({
2168
2158
  }
2169
2159
  },
2170
2160
  removeIssueAttachment: removeAttachment,
2171
- removeIssueAttachments: removeAttachments,
2172
2161
  removeIssueUpdate: (state, action) => {
2173
2162
  if (action.payload in state.updates) {
2174
2163
  delete state.updates[action.payload];
@@ -2278,7 +2267,6 @@ const {
2278
2267
  addToRecentIssues,
2279
2268
  cleanRecentIssues,
2280
2269
  removeIssueAttachment,
2281
- removeIssueAttachments,
2282
2270
  removeAttachmentsOfIssue,
2283
2271
  removeIssue,
2284
2272
  removeIssueUpdate,
@@ -2292,7 +2280,6 @@ const {
2292
2280
  setVisibleStatuses,
2293
2281
  setVisibleUserIds,
2294
2282
  updateIssueAttachment,
2295
- updateIssueAttachments,
2296
2283
  updateIssue,
2297
2284
  // Commments
2298
2285
  addIssueComment,
@@ -4805,23 +4792,6 @@ class BaseApiService {
4805
4792
  }
4806
4793
  }
4807
4794
  class AttachmentService extends BaseApiService {
4808
- processPresignedUrls(presignedUrls) {
4809
- for (const [sha1, presignedUrl] of Object.entries(presignedUrls)) {
4810
- console.debug(sha1, presignedUrl);
4811
- void this.enqueueRequest({
4812
- url: presignedUrl.url,
4813
- description: "Upload file to S3",
4814
- method: HttpMethod.POST,
4815
- isExternalUrl: true,
4816
- isAuthNeeded: false,
4817
- attachmentHash: sha1,
4818
- // TODO: can we use the sha1 as the blocker?
4819
- blockers: [`s3-${sha1}`],
4820
- blocks: [sha1],
4821
- s3url: presignedUrl
4822
- });
4823
- }
4824
- }
4825
4795
  fetchAll(projectId) {
4826
4796
  const promise = this.enqueueRequest({
4827
4797
  description: "Fetch attachments",
@@ -4848,7 +4818,6 @@ class AttachmentService extends BaseApiService {
4848
4818
  }
4849
4819
  const offlineAttachment = {
4850
4820
  ...attachmentPayload,
4851
- // TODO: just handle creating the objectURL in here, then the front end doesn't need to worry about it
4852
4821
  file: attachmentPayload.file.objectURL,
4853
4822
  file_name: attachmentPayload.file.name,
4854
4823
  file_type: attachmentPayload.file.type,
@@ -4882,7 +4851,6 @@ class AttachmentService extends BaseApiService {
4882
4851
  }
4883
4852
  const offlineAttachment = {
4884
4853
  ...attachmentPayload,
4885
- // TODO: just handle creating the objectURL in here, then the front end doesn't need to worry about it
4886
4854
  file: attachmentPayload.file.objectURL,
4887
4855
  file_name: attachmentPayload.file.name,
4888
4856
  file_type: attachmentPayload.file.type,
@@ -4916,7 +4884,6 @@ class AttachmentService extends BaseApiService {
4916
4884
  }
4917
4885
  const offlineAttachment = {
4918
4886
  ...attachmentPayload,
4919
- // TODO: just handle creating the objectURL in here, then the front end doesn't need to worry about it
4920
4887
  file: attachmentPayload.file.objectURL,
4921
4888
  file_name: attachmentPayload.file.name,
4922
4889
  file_type: attachmentPayload.file.type,
@@ -4982,54 +4949,26 @@ class AttachmentService extends BaseApiService {
4982
4949
  /** the outer Promise is needed to await the hashing of each file, which is required before offline use. If wanting to
4983
4950
  * attach promise handlers to the request to add the attachment in the backend, apply it on the promise returned from the
4984
4951
  * OptimisticModelResult. */
4985
- // note the method is only marked as async since files needs to be hashed
4986
- async attachFilesToIssue(files, issueId) {
4987
- const { store } = this.client;
4988
- const offlineAttachments = [];
4989
- const attachmentsPayload = [];
4990
- const currentUser = store.getState().userReducer.currentUser;
4991
- const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4992
- for (const file of files) {
4993
- const attachment = offline({
4994
- file: URL.createObjectURL(file),
4995
- file_name: file.name,
4996
- file_type: file.type,
4997
- file_sha1: await hashFile(file),
4998
- description: "",
4999
- submitted_at: submittedAt,
5000
- created_by: currentUser.id,
5001
- issue: issueId
5002
- });
5003
- attachmentsPayload.push({
5004
- offline_id: attachment.offline_id,
5005
- name: attachment.file_name,
5006
- sha1: attachment.file_sha1,
5007
- description: attachment.description,
5008
- created_by: attachment.created_by,
5009
- issue_id: attachment.issue
5010
- });
5011
- offlineAttachments.push(attachment);
5012
- }
5013
- store.dispatch(addIssueAttachments(offlineAttachments));
5014
- const promise = this.enqueueRequest({
5015
- description: "Attach files to issue",
5016
- method: HttpMethod.POST,
5017
- url: `/issues/${issueId}/attach/`,
5018
- payload: {
5019
- submitted_at: submittedAt,
5020
- attachments: attachmentsPayload,
5021
- files: await constructUploadedFilePayloads(files)
5022
- },
5023
- blocks: offlineAttachments.map((attachment) => attachment.offline_id),
5024
- blockers: offlineAttachments.map((attachment) => attachment.file_sha1)
5025
- });
5026
- promise.then(({ attachments, presigned_urls }) => {
5027
- store.dispatch(updateIssueAttachments(attachments));
5028
- this.processPresignedUrls(presigned_urls);
5029
- }).catch(() => {
5030
- store.dispatch(removeIssueAttachments(offlineAttachments.map((attachment) => attachment.offline_id)));
4952
+ attachFilesToIssue(filesToSubmit, issueId) {
4953
+ return filesToSubmit.map((file) => {
4954
+ if (!(file instanceof File)) {
4955
+ throw new Error("Expected a File instance.");
4956
+ }
4957
+ const photoAttachmentPromise = async (file2) => {
4958
+ const hash = await hashFile(file2);
4959
+ const attachment = offline({
4960
+ file: file2,
4961
+ file_name: file2.name,
4962
+ file_type: file2.type,
4963
+ issue: issueId,
4964
+ file_sha1: hash,
4965
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
4966
+ created_by: this.client.store.getState().userReducer.currentUser.id
4967
+ });
4968
+ return this.addIssueAttachment(attachment);
4969
+ };
4970
+ return photoAttachmentPromise(file);
5031
4971
  });
5032
- return [offlineAttachments, promise.then(({ attachments }) => attachments)];
5033
4972
  }
5034
4973
  attachFilesToComponent(filesToSubmit, componentId) {
5035
4974
  return filesToSubmit.map((file) => {
@@ -16176,7 +16115,6 @@ export {
16176
16115
  removeFavouriteProjectId,
16177
16116
  removeIssue,
16178
16117
  removeIssueAttachment,
16179
- removeIssueAttachments,
16180
16118
  removeIssueComment,
16181
16119
  removeIssueComments,
16182
16120
  removeIssueUpdate,
@@ -16455,7 +16393,6 @@ export {
16455
16393
  updateFormSubmissions,
16456
16394
  updateIssue,
16457
16395
  updateIssueAttachment,
16458
- updateIssueAttachments,
16459
16396
  updateLicense,
16460
16397
  updateOrCreateProject,
16461
16398
  updateOrganizationAccess,