@overmap-ai/core 1.0.38-component-fields.15 → 1.0.38-component-fields.17

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.
@@ -3017,7 +3017,7 @@ const userFormSlice = createSlice({
3017
3017
  delete LATEST_REVISION_CACHE[userFormRevision.offline_id];
3018
3018
  }
3019
3019
  },
3020
- addUserFormSubmission: (state, action) => {
3020
+ updateOrCreateUserFormSubmission: (state, action) => {
3021
3021
  state.submissions[action.payload.offline_id] = action.payload;
3022
3022
  },
3023
3023
  addUserFormSubmissionAttachment: (state, action) => {
@@ -3106,7 +3106,7 @@ const {
3106
3106
  addUserForm,
3107
3107
  addUserForms,
3108
3108
  addUserFormRevisions,
3109
- addUserFormSubmission,
3109
+ updateOrCreateUserFormSubmission,
3110
3110
  addUserFormSubmissions,
3111
3111
  deleteUserFormSubmission,
3112
3112
  deleteUserFormSubmissions,
@@ -3316,6 +3316,14 @@ const selectNumberOfUserForms = createSelector([selectUserFormMapping], (userFor
3316
3316
  const selectNumberOfGeneralUserForms = createSelector([selectUserFormMapping], (userForms) => {
3317
3317
  return Object.values(userForms).filter((form) => !form.component_type && !form.component_stage).length;
3318
3318
  });
3319
+ const selectNumberOfComponentStageFormsForStage = restructureCreateSelectorWithArgs(
3320
+ createSelector(
3321
+ [selectUserFormMapping, (_state, stageId) => stageId],
3322
+ (userForms, stageId) => {
3323
+ return Object.values(userForms).filter((form) => form.component_stage === stageId).length;
3324
+ }
3325
+ )
3326
+ );
3319
3327
  const userFormReducer = userFormSlice.reducer;
3320
3328
  const initialState$1 = {
3321
3329
  emailDomains: {}
@@ -5701,6 +5709,43 @@ const separateFilesFromValues = (payload) => {
5701
5709
  return { payloadWithoutFiles, files };
5702
5710
  };
5703
5711
  class UserFormSubmissionService extends BaseApiService {
5712
+ constructor() {
5713
+ super(...arguments);
5714
+ // Attach files to submission, after uploading them to S3
5715
+ __publicField(this, "getAttachFilesPromises", (files, payload) => {
5716
+ const { store } = this.client;
5717
+ return Object.entries(files).map(async ([key, fileArray]) => {
5718
+ const attachResults = [];
5719
+ for (const file of fileArray) {
5720
+ const sha1 = await hashFile(file);
5721
+ await this.client.files.addCache(file, sha1);
5722
+ const [fileProps] = await this.client.files.uploadFileToS3(sha1);
5723
+ const submissionAttachmentPayload = offline({
5724
+ ...fileProps,
5725
+ submission: payload.offline_id,
5726
+ field_identifier: key
5727
+ });
5728
+ const attach = await this.enqueueRequest({
5729
+ description: "Attach file to form submission",
5730
+ method: HttpMethod.POST,
5731
+ url: `/forms/submission/${payload.offline_id}/attachments/`,
5732
+ payload: submissionAttachmentPayload,
5733
+ blockers: [payload.component, payload.issue, payload.form_revision].filter(
5734
+ (x) => x !== void 0
5735
+ ),
5736
+ blocks: [submissionAttachmentPayload.offline_id]
5737
+ });
5738
+ const offlinePayload = {
5739
+ ...submissionAttachmentPayload,
5740
+ file: URL.createObjectURL(file)
5741
+ };
5742
+ store.dispatch(addUserFormSubmissionAttachment(offlinePayload));
5743
+ attachResults.push(attach);
5744
+ }
5745
+ return attachResults;
5746
+ });
5747
+ });
5748
+ }
5704
5749
  add(payload) {
5705
5750
  const { store } = this.client;
5706
5751
  const state = store.getState();
@@ -5717,36 +5762,7 @@ class UserFormSubmissionService extends BaseApiService {
5717
5762
  blockers: [payload.issue, payload.component].filter((x) => x !== void 0),
5718
5763
  blocks: [payload.offline_id]
5719
5764
  });
5720
- const attachFilesPromises = Object.entries(files).map(async ([key, fileArray]) => {
5721
- const attachResults = [];
5722
- for (const file of fileArray) {
5723
- const sha1 = await hashFile(file);
5724
- await this.client.files.addCache(file, sha1);
5725
- const [fileProps] = await this.client.files.uploadFileToS3(sha1);
5726
- const submissionAttachmentPayload = offline({
5727
- ...fileProps,
5728
- submission: payload.offline_id,
5729
- field_identifier: key
5730
- });
5731
- const attach = await this.enqueueRequest({
5732
- description: "Attach file to form submission",
5733
- method: HttpMethod.POST,
5734
- url: `/forms/submission/${payload.offline_id}/attachments/`,
5735
- payload: submissionAttachmentPayload,
5736
- blockers: [payload.component, payload.issue, payload.form_revision].filter(
5737
- (x) => x !== void 0
5738
- ),
5739
- blocks: [submissionAttachmentPayload.offline_id]
5740
- });
5741
- const offlinePayload = {
5742
- ...submissionAttachmentPayload,
5743
- file: URL.createObjectURL(file)
5744
- };
5745
- store.dispatch(addUserFormSubmissionAttachment(offlinePayload));
5746
- attachResults.push(attach);
5747
- }
5748
- return attachResults;
5749
- });
5765
+ const attachFilesPromises = this.getAttachFilesPromises(files, payload);
5750
5766
  const fullOfflineResult = {
5751
5767
  ...payload,
5752
5768
  created_by: state.userReducer.currentUser.id,
@@ -5756,9 +5772,9 @@ class UserFormSubmissionService extends BaseApiService {
5756
5772
  ...fullOfflineResult,
5757
5773
  ...payloadWithoutFiles
5758
5774
  };
5759
- store.dispatch(addUserFormSubmission(offlineResultWithoutFiles));
5775
+ store.dispatch(updateOrCreateUserFormSubmission(offlineResultWithoutFiles));
5760
5776
  void promise.then((result) => {
5761
- store.dispatch(addUserFormSubmission(result));
5777
+ store.dispatch(updateOrCreateUserFormSubmission(result));
5762
5778
  return result;
5763
5779
  }).catch(() => {
5764
5780
  store.dispatch(deleteUserFormSubmission(payload.offline_id));
@@ -5766,6 +5782,26 @@ class UserFormSubmissionService extends BaseApiService {
5766
5782
  const settledPromise = Promise.all([promise, ...attachFilesPromises]).then(() => promise);
5767
5783
  return [fullOfflineResult, settledPromise];
5768
5784
  }
5785
+ update(submission) {
5786
+ const { store } = this.client;
5787
+ const { payloadWithoutFiles, files } = separateFilesFromValues(submission);
5788
+ if (!("created_by" in payloadWithoutFiles) || !("created_at" in payloadWithoutFiles)) {
5789
+ throw new Error("Expected payloadWithoutFiles to have created_by and created_at fields.");
5790
+ }
5791
+ const attachFilesPromises = this.getAttachFilesPromises(files, submission);
5792
+ store.dispatch(updateOrCreateUserFormSubmission(payloadWithoutFiles));
5793
+ const promise = this.enqueueRequest({
5794
+ description: "Patch form submission",
5795
+ method: HttpMethod.PATCH,
5796
+ url: `/submissions/${submission.offline_id}/`,
5797
+ payload: payloadWithoutFiles,
5798
+ blockers: [payloadWithoutFiles.issue, payloadWithoutFiles.component].filter(
5799
+ (x) => x !== void 0
5800
+ ),
5801
+ blocks: [payloadWithoutFiles.offline_id]
5802
+ });
5803
+ return Promise.all([promise, ...attachFilesPromises]).then(() => promise);
5804
+ }
5769
5805
  async delete(submissionId) {
5770
5806
  const { store } = this.client;
5771
5807
  const state = store.getState();
@@ -5781,7 +5817,7 @@ class UserFormSubmissionService extends BaseApiService {
5781
5817
  });
5782
5818
  } catch (e) {
5783
5819
  if (submission) {
5784
- store.dispatch(addUserFormSubmission(submission));
5820
+ store.dispatch(updateOrCreateUserFormSubmission(submission));
5785
5821
  }
5786
5822
  throw e;
5787
5823
  }
@@ -11110,7 +11146,7 @@ const FieldBuilder = memo((props) => {
11110
11146
  Input,
11111
11147
  {
11112
11148
  className: styles.grow,
11113
- placeholder: `Enter a ${type === "section" ? "section" : "field"} label`,
11149
+ placeholder: type === "section" ? "Enter a section label (optional)" : "Enter your question",
11114
11150
  value,
11115
11151
  onChange: (event) => {
11116
11152
  setValue(event.target.value);
@@ -11133,7 +11169,7 @@ const FieldBuilder = memo((props) => {
11133
11169
  TextArea,
11134
11170
  {
11135
11171
  className: styles.grow,
11136
- placeholder: `Enter a ${type === "section" ? "section" : "field"} description`,
11172
+ placeholder: `Enter a ${type === "section" ? "section" : "field"} description (optional)`,
11137
11173
  value,
11138
11174
  onChange: (event) => {
11139
11175
  setValue(event.target.value);
@@ -11907,7 +11943,6 @@ export {
11907
11943
  addUserFormRevision,
11908
11944
  addUserFormRevisionAttachment,
11909
11945
  addUserFormRevisions,
11910
- addUserFormSubmission,
11911
11946
  addUserFormSubmissionAttachment,
11912
11947
  addUserFormSubmissions,
11913
11948
  addUserForms,
@@ -12124,6 +12159,7 @@ export {
12124
12159
  selectLatestRevisionsFromComponentTypeIds,
12125
12160
  selectMainWorkspace,
12126
12161
  selectMapStyle,
12162
+ selectNumberOfComponentStageFormsForStage,
12127
12163
  selectNumberOfComponentTypesMatchingCaseInsensitiveName,
12128
12164
  selectNumberOfComponentsOfComponentType,
12129
12165
  selectNumberOfGeneralUserForms,
@@ -12240,6 +12276,7 @@ export {
12240
12276
  updateComponent,
12241
12277
  updateIssue,
12242
12278
  updateOrCreateProject,
12279
+ updateOrCreateUserFormSubmission,
12243
12280
  updateOrganizationAccess,
12244
12281
  updateProjectAccess,
12245
12282
  updateStages,