@overmap-ai/core 1.0.38-component-fields.32 → 1.0.38-component-fields.34

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.
@@ -1673,6 +1673,22 @@ var __publicField = (obj, key, value) => {
1673
1673
  action.payload.forEach((id) => {
1674
1674
  delete state.stages[id];
1675
1675
  });
1676
+ },
1677
+ linkStageToForm: (state, action) => {
1678
+ const { stageId, formId: formId2 } = action.payload;
1679
+ const stage = state.stages[stageId];
1680
+ if (!stage) {
1681
+ throw new Error("No stage exists with the id " + stageId);
1682
+ }
1683
+ stage.user_form = formId2;
1684
+ },
1685
+ unlinkStageToForm: (state, action) => {
1686
+ const { stageId } = action.payload;
1687
+ const stage = state.stages[stageId];
1688
+ if (!stage) {
1689
+ throw new Error("No stage exists with the id " + stageId);
1690
+ }
1691
+ delete stage.user_form;
1676
1692
  }
1677
1693
  }
1678
1694
  });
@@ -1717,7 +1733,7 @@ var __publicField = (obj, key, value) => {
1717
1733
  return stageIds.map((offline_id) => stageMapping[offline_id]).filter((stage) => !!stage);
1718
1734
  })
1719
1735
  );
1720
- const { addStages, updateStages, removeStages } = componentStageSlice.actions;
1736
+ const { addStages, updateStages, removeStages, linkStageToForm, unlinkStageToForm } = componentStageSlice.actions;
1721
1737
  const componentStageReducer = componentStageSlice.reducer;
1722
1738
  const initialState$g = {
1723
1739
  componentTypes: {},
@@ -3093,22 +3109,6 @@ var __publicField = (obj, key, value) => {
3093
3109
  }
3094
3110
  form.favorite = false;
3095
3111
  },
3096
- attachFormToComponentStage: (state, action) => {
3097
- const { formId: formId2, componentStageId } = action.payload;
3098
- const form = state.userForms[formId2];
3099
- if (!form) {
3100
- throw new Error("No form exists with the id " + formId2);
3101
- }
3102
- form.component_stage = componentStageId;
3103
- },
3104
- removeFormFromComponentStage: (state, action) => {
3105
- const { formId: formId2 } = action.payload;
3106
- const form = state.userForms[formId2];
3107
- if (!form) {
3108
- throw new Error("No form exists with the id " + formId2);
3109
- }
3110
- form.component_stage = void 0;
3111
- },
3112
3112
  deleteUserForm: (state, action) => {
3113
3113
  delete state.userForms[action.payload];
3114
3114
  }
@@ -3124,8 +3124,6 @@ var __publicField = (obj, key, value) => {
3124
3124
  deleteUserFormSubmissions,
3125
3125
  favoriteForm,
3126
3126
  unfavoriteForm,
3127
- attachFormToComponentStage,
3128
- removeFormFromComponentStage,
3129
3127
  deleteUserForm,
3130
3128
  deleteUserFormRevision,
3131
3129
  deleteUserFormRevisions,
@@ -3212,7 +3210,6 @@ var __publicField = (obj, key, value) => {
3212
3210
  const selectSubmissionMapping = (state) => state.userFormReducer.submissions;
3213
3211
  const selectSubmissions = toolkit.createSelector([selectSubmissionMapping], (submissions) => Object.values(submissions));
3214
3212
  const selectRevisionMapping = (state) => state.userFormReducer.revisions;
3215
- const selectRevisionAttachmentsMapping = (state) => state.userFormReducer.revisionAttachments;
3216
3213
  const selectRevisions = toolkit.createSelector([selectRevisionMapping], (revisions) => Object.values(revisions));
3217
3214
  const selectRevisionsForForm = restructureCreateSelectorWithArgs(
3218
3215
  toolkit.createSelector([selectRevisions, (_state, formId2) => formId2], (revisions, formId2) => {
@@ -3282,38 +3279,6 @@ var __publicField = (obj, key, value) => {
3282
3279
  }
3283
3280
  )
3284
3281
  );
3285
- const selectComponentStageFormLatestRevision = restructureCreateSelectorWithArgs(
3286
- toolkit.createSelector(
3287
- [
3288
- selectUserFormMapping,
3289
- selectRevisionMapping,
3290
- (_state, componentStageId) => componentStageId
3291
- ],
3292
- (userForms, revisions, componentStageId) => {
3293
- const form = Object.values(userForms).find((userForm) => userForm.component_stage === componentStageId);
3294
- return form ? _selectLatestFormRevision(revisions, form.offline_id) : void 0;
3295
- }
3296
- )
3297
- );
3298
- const selectLatestRevisionsFromComponentStageIds = restructureCreateSelectorWithArgs(
3299
- toolkit.createSelector(
3300
- [
3301
- selectUserFormMapping,
3302
- selectRevisionMapping,
3303
- (_state, componentStageIds) => componentStageIds
3304
- ],
3305
- (userForms, revisions, componentStageIds) => {
3306
- const componentStageIdsSet = new Set(componentStageIds);
3307
- const ret = {};
3308
- for (const form of Object.values(userForms)) {
3309
- if (form.component_stage && componentStageIdsSet.has(form.component_stage)) {
3310
- ret[form.component_stage] = _selectLatestFormRevision(revisions, form.offline_id);
3311
- }
3312
- }
3313
- return ret;
3314
- }
3315
- )
3316
- );
3317
3282
  const selectLatestRevisionByFormId = toolkit.createSelector([selectRevisionMapping], (revisions) => {
3318
3283
  const latestRevisions = {};
3319
3284
  for (const revision of Object.values(revisions)) {
@@ -3325,19 +3290,6 @@ var __publicField = (obj, key, value) => {
3325
3290
  }
3326
3291
  return latestRevisions;
3327
3292
  });
3328
- const selectAllRevisionAttachmentsByLatestRevisionId = toolkit.createSelector(
3329
- [selectUserFormMapping, selectRevisionMapping, selectRevisionAttachmentsMapping],
3330
- (forms, revisions, attachments) => {
3331
- const mappedAttachments = {};
3332
- for (const form of Object.values(forms)) {
3333
- const latestRevision = _selectLatestFormRevision(revisions, form.offline_id);
3334
- if (attachments[latestRevision.offline_id] !== void 0) {
3335
- mappedAttachments[latestRevision.offline_id] = attachments[latestRevision.offline_id];
3336
- }
3337
- }
3338
- return mappedAttachments;
3339
- }
3340
- );
3341
3293
  const selectNumberOfUserForms = toolkit.createSelector([selectUserFormMapping], (userForms) => {
3342
3294
  return Object.keys(userForms).length;
3343
3295
  });
@@ -4709,6 +4661,39 @@ var __publicField = (obj, key, value) => {
4709
4661
  blocks: [componentStage.offline_id]
4710
4662
  });
4711
4663
  }
4664
+ async linkForm(stageId, formId2) {
4665
+ const { store } = this.client;
4666
+ store.dispatch(linkStageToForm({ stageId, formId: formId2 }));
4667
+ try {
4668
+ await this.enqueueRequest({
4669
+ description: "Link component stage to form",
4670
+ method: HttpMethod.POST,
4671
+ url: `/components/stages/${stageId}/associate-with-form/`,
4672
+ payload: { user_form: formId2 },
4673
+ blockers: [stageId, formId2],
4674
+ blocks: [stageId]
4675
+ });
4676
+ } catch (e) {
4677
+ store.dispatch(unlinkStageToForm({ stageId }));
4678
+ throw e;
4679
+ }
4680
+ }
4681
+ async unlinkForm(stageId, formId2) {
4682
+ const { store } = this.client;
4683
+ store.dispatch(unlinkStageToForm({ stageId }));
4684
+ try {
4685
+ await this.enqueueRequest({
4686
+ description: "Unlink component stage from form",
4687
+ method: HttpMethod.DELETE,
4688
+ url: `/components/stages/${stageId}/associate-with-form/`,
4689
+ blockers: [stageId, formId2],
4690
+ blocks: [stageId]
4691
+ });
4692
+ } catch (e) {
4693
+ store.dispatch(linkStageToForm({ stageId, formId: formId2 }));
4694
+ throw e;
4695
+ }
4696
+ }
4712
4697
  async refreshStore() {
4713
4698
  const { store } = this.client;
4714
4699
  const result = await this.enqueueRequest({
@@ -5494,13 +5479,10 @@ var __publicField = (obj, key, value) => {
5494
5479
  });
5495
5480
  });
5496
5481
  }
5497
- async add(state, initialRevision, url, ownerUser, ownerOrganization, componentTypeId, componentStageId) {
5482
+ async add(state, initialRevision, url, ownerUser, ownerOrganization, componentTypeId) {
5498
5483
  if (!!ownerUser === !!ownerOrganization) {
5499
5484
  throw new Error("Exactly one of ownerUser and ownerOrganization must be defined.");
5500
5485
  }
5501
- if (componentTypeId && componentStageId) {
5502
- throw new Error("At most one of componentTypeId and componentStageId should be defined.");
5503
- }
5504
5486
  const ownerAttrs = {
5505
5487
  owner_user: ownerUser,
5506
5488
  owner_organization: ownerOrganization
@@ -5516,7 +5498,6 @@ var __publicField = (obj, key, value) => {
5516
5498
  submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5517
5499
  created_by: currentUser.id,
5518
5500
  ...componentTypeId && { component_type: componentTypeId },
5519
- ...componentStageId && { component_stage: componentStageId },
5520
5501
  ...ownerAttrs
5521
5502
  };
5522
5503
  const { payloadWithoutImage, images } = await separateImageFromFields(offlineRevisionPayload);
@@ -5539,10 +5520,9 @@ var __publicField = (obj, key, value) => {
5539
5520
  payload: {
5540
5521
  ...offlineFormPayload,
5541
5522
  ...componentTypeId && { component_type: componentTypeId },
5542
- ...componentStageId && { component_stage: componentStageId },
5543
5523
  initial_revision: payloadWithoutImage
5544
5524
  },
5545
- blockers: [componentTypeId, componentStageId].filter((x) => x !== void 0),
5525
+ blockers: [componentTypeId].filter((x) => x !== void 0),
5546
5526
  blocks: [offlineFormPayload.offline_id, payloadWithoutImage.offline_id]
5547
5527
  });
5548
5528
  const attachImagesPromises = this.getAttachImagePromises(images, offlineRevisionPayload.offline_id);
@@ -5554,7 +5534,7 @@ var __publicField = (obj, key, value) => {
5554
5534
  const settledPromise = Promise.all([formPromise, ...attachImagesPromises]).then(() => formPromise);
5555
5535
  return [retForm, retRevision, formPromise, settledPromise];
5556
5536
  }
5557
- async addForOrganization(initialRevision, componentTypeId, componentStageId) {
5537
+ async addForOrganization(initialRevision, componentTypeId) {
5558
5538
  const state = this.client.store.getState();
5559
5539
  const activeOrganizationId = state.organizationReducer.activeOrganizationId;
5560
5540
  if (!activeOrganizationId) {
@@ -5566,22 +5546,13 @@ var __publicField = (obj, key, value) => {
5566
5546
  `/forms/in-organization/${activeOrganizationId}/`,
5567
5547
  void 0,
5568
5548
  activeOrganizationId,
5569
- componentTypeId,
5570
- componentStageId
5549
+ componentTypeId
5571
5550
  );
5572
5551
  }
5573
- async addForCurrentUser(initialRevision, componentTypeId, componentStageId) {
5552
+ async addForCurrentUser(initialRevision, componentTypeId) {
5574
5553
  const state = this.client.store.getState();
5575
5554
  const currentUser = state.userReducer.currentUser;
5576
- return await this.add(
5577
- state,
5578
- initialRevision,
5579
- "/forms/my-forms/",
5580
- currentUser.id,
5581
- void 0,
5582
- componentTypeId,
5583
- componentStageId
5584
- );
5555
+ return await this.add(state, initialRevision, "/forms/my-forms/", currentUser.id, void 0, componentTypeId);
5585
5556
  }
5586
5557
  async createRevision(formId2, revision) {
5587
5558
  const offlineRevision = offline(revision);
@@ -5654,39 +5625,6 @@ var __publicField = (obj, key, value) => {
5654
5625
  throw e;
5655
5626
  }
5656
5627
  }
5657
- async attachToComponentStage(formId2, componentStageId) {
5658
- const { store } = this.client;
5659
- store.dispatch(attachFormToComponentStage({ formId: formId2, componentStageId }));
5660
- try {
5661
- await this.enqueueRequest({
5662
- description: "Attach form to component stage",
5663
- method: HttpMethod.POST,
5664
- url: `/forms/${formId2}/associate-with-stage/`,
5665
- payload: { component_stage: componentStageId },
5666
- blockers: [formId2, componentStageId],
5667
- blocks: [formId2]
5668
- });
5669
- } catch (e) {
5670
- store.dispatch(removeFormFromComponentStage({ formId: formId2 }));
5671
- throw e;
5672
- }
5673
- }
5674
- async removeFromComponentStage(formId2, componentStageId) {
5675
- const { store } = this.client;
5676
- store.dispatch(removeFormFromComponentStage({ formId: formId2 }));
5677
- try {
5678
- await this.enqueueRequest({
5679
- description: "Remove form from component stage",
5680
- method: HttpMethod.DELETE,
5681
- url: `/forms/${formId2}/associate-with-stage/`,
5682
- blockers: [formId2, componentStageId],
5683
- blocks: [formId2]
5684
- });
5685
- } catch (e) {
5686
- store.dispatch(attachFormToComponentStage({ formId: formId2, componentStageId }));
5687
- throw e;
5688
- }
5689
- }
5690
5628
  async delete(formId2) {
5691
5629
  const { store } = this.client;
5692
5630
  const state = store.getState();
@@ -10367,10 +10305,12 @@ var __publicField = (obj, key, value) => {
10367
10305
  };
10368
10306
  const useAttachImagesToFormRevisionFields = (revision) => {
10369
10307
  const { sdk } = useSDK();
10370
- const attachments = useAppSelector(selectRevisionAttachments(revision.offline_id));
10308
+ const attachments = useAppSelector(selectRevisionAttachments((revision == null ? void 0 : revision.offline_id) ?? ""));
10371
10309
  return React.useMemo(() => {
10310
+ if (!revision || !attachments)
10311
+ return revision;
10372
10312
  const revisionCopy = structuredClone(revision);
10373
- for (const attachment of attachments ?? []) {
10313
+ for (const attachment of attachments) {
10374
10314
  const filePromise = sdk.files.fetchFileFromUrl(attachment.file, attachment.file_sha1, attachment.file_name);
10375
10315
  let sectionIndex = -1;
10376
10316
  let fieldIndex = -1;
@@ -10455,6 +10395,9 @@ var __publicField = (obj, key, value) => {
10455
10395
  );
10456
10396
  }
10457
10397
  const revisionWithImages = useAttachImagesToFormRevisionFields(revision);
10398
+ if (!revisionWithImages) {
10399
+ throw new Error("Expected revisionWithImages to be defined");
10400
+ }
10458
10401
  const schema = React.useMemo(() => {
10459
10402
  return formRevisionToSchema(revisionWithImages, { readonly: true });
10460
10403
  }, [revisionWithImages]);
@@ -11780,8 +11723,9 @@ var __publicField = (obj, key, value) => {
11780
11723
  }),
11781
11724
  [initialTitle]
11782
11725
  );
11726
+ const revisionWithImages = useAttachImagesToFormRevisionFields(revision);
11783
11727
  const formik$1 = formik.useFormik({
11784
- initialValues: wrapRootFieldsWithFieldSection(revision) ?? initialValues,
11728
+ initialValues: wrapRootFieldsWithFieldSection(revisionWithImages) ?? initialValues,
11785
11729
  validate,
11786
11730
  onSubmit: onSave,
11787
11731
  validateOnChange: false,
@@ -12022,7 +11966,6 @@ var __publicField = (obj, key, value) => {
12022
11966
  exports2.addUsers = addUsers;
12023
11967
  exports2.addWorkspace = addWorkspace;
12024
11968
  exports2.areArraysEqual = areArraysEqual;
12025
- exports2.attachFormToComponentStage = attachFormToComponentStage;
12026
11969
  exports2.authReducer = authReducer;
12027
11970
  exports2.authSlice = authSlice;
12028
11971
  exports2.blobToBase64 = blobToBase64;
@@ -12101,6 +12044,7 @@ var __publicField = (obj, key, value) => {
12101
12044
  exports2.issueReducer = issueReducer;
12102
12045
  exports2.issueSlice = issueSlice;
12103
12046
  exports2.issueToSearchResult = issueToSearchResult;
12047
+ exports2.linkStageToForm = linkStageToForm;
12104
12048
  exports2.literalToCoordinates = literalToCoordinates;
12105
12049
  exports2.logOnlyOnce = logOnlyOnce;
12106
12050
  exports2.makeClient = makeClient;
@@ -12145,7 +12089,6 @@ var __publicField = (obj, key, value) => {
12145
12089
  exports2.removeComponent = removeComponent;
12146
12090
  exports2.removeEmailDomain = removeEmailDomain;
12147
12091
  exports2.removeFavouriteProjectId = removeFavouriteProjectId;
12148
- exports2.removeFormFromComponentStage = removeFormFromComponentStage;
12149
12092
  exports2.removeIssue = removeIssue;
12150
12093
  exports2.removeIssueComment = removeIssueComment;
12151
12094
  exports2.removeOrganizationAccess = removeOrganizationAccess;
@@ -12178,7 +12121,6 @@ var __publicField = (obj, key, value) => {
12178
12121
  exports2.selectActiveWorkspace = selectActiveWorkspace;
12179
12122
  exports2.selectActiveWorkspaceId = selectActiveWorkspaceId;
12180
12123
  exports2.selectAllAttachments = selectAllAttachments;
12181
- exports2.selectAllRevisionAttachmentsByLatestRevisionId = selectAllRevisionAttachmentsByLatestRevisionId;
12182
12124
  exports2.selectAppearance = selectAppearance;
12183
12125
  exports2.selectCategories = selectCategories;
12184
12126
  exports2.selectCategoriesOfWorkspace = selectCategoriesOfWorkspace;
@@ -12191,7 +12133,6 @@ var __publicField = (obj, key, value) => {
12191
12133
  exports2.selectCompletedStageIdsForComponent = selectCompletedStageIdsForComponent;
12192
12134
  exports2.selectCompletedStages = selectCompletedStages;
12193
12135
  exports2.selectComponent = selectComponent;
12194
- exports2.selectComponentStageFormLatestRevision = selectComponentStageFormLatestRevision;
12195
12136
  exports2.selectComponentType = selectComponentType;
12196
12137
  exports2.selectComponentTypeForm = selectComponentTypeForm;
12197
12138
  exports2.selectComponentTypeFromComponent = selectComponentTypeFromComponent;
@@ -12231,7 +12172,6 @@ var __publicField = (obj, key, value) => {
12231
12172
  exports2.selectLatestFormRevision = selectLatestFormRevision;
12232
12173
  exports2.selectLatestRetryTime = selectLatestRetryTime;
12233
12174
  exports2.selectLatestRevisionByFormId = selectLatestRevisionByFormId;
12234
- exports2.selectLatestRevisionsFromComponentStageIds = selectLatestRevisionsFromComponentStageIds;
12235
12175
  exports2.selectLatestRevisionsFromComponentTypeIds = selectLatestRevisionsFromComponentTypeIds;
12236
12176
  exports2.selectMainWorkspace = selectMainWorkspace;
12237
12177
  exports2.selectMapStyle = selectMapStyle;
@@ -12346,6 +12286,7 @@ var __publicField = (obj, key, value) => {
12346
12286
  exports2.unfavoriteForm = unfavoriteForm;
12347
12287
  exports2.unhideAllCategories = unhideAllCategories;
12348
12288
  exports2.unhideCategory = unhideCategory;
12289
+ exports2.unlinkStageToForm = unlinkStageToForm;
12349
12290
  exports2.updateActiveOrganization = updateActiveOrganization;
12350
12291
  exports2.updateAttachment = updateAttachment;
12351
12292
  exports2.updateComponent = updateComponent;