@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.
@@ -6,4 +6,4 @@ import { UserFormRevision } from "../typings";
6
6
  export declare const hasKeys: (errors: object) => boolean;
7
7
  export declare const validateForm: (schema: ISchema, form: Form | FormikUserFormRevision) => FormikErrors<Form> | FormikErrors<import('./builder/typings').NewForm> | undefined;
8
8
  export declare const initialFormValues: (fields: BaseFormElement[], values: Form) => Form;
9
- export declare const useAttachImagesToFormRevisionFields: (revision: UserFormRevision) => UserFormRevision;
9
+ export declare const useAttachImagesToFormRevisionFields: (revision: UserFormRevision | undefined) => UserFormRevision | undefined;
@@ -1677,6 +1677,22 @@ const componentStageSlice = createSlice({
1677
1677
  action.payload.forEach((id) => {
1678
1678
  delete state.stages[id];
1679
1679
  });
1680
+ },
1681
+ linkStageToForm: (state, action) => {
1682
+ const { stageId, formId: formId2 } = action.payload;
1683
+ const stage = state.stages[stageId];
1684
+ if (!stage) {
1685
+ throw new Error("No stage exists with the id " + stageId);
1686
+ }
1687
+ stage.user_form = formId2;
1688
+ },
1689
+ unlinkStageToForm: (state, action) => {
1690
+ const { stageId } = action.payload;
1691
+ const stage = state.stages[stageId];
1692
+ if (!stage) {
1693
+ throw new Error("No stage exists with the id " + stageId);
1694
+ }
1695
+ delete stage.user_form;
1680
1696
  }
1681
1697
  }
1682
1698
  });
@@ -1721,7 +1737,7 @@ const selectStagesFromStageIds = restructureCreateSelectorWithArgs(
1721
1737
  return stageIds.map((offline_id) => stageMapping[offline_id]).filter((stage) => !!stage);
1722
1738
  })
1723
1739
  );
1724
- const { addStages, updateStages, removeStages } = componentStageSlice.actions;
1740
+ const { addStages, updateStages, removeStages, linkStageToForm, unlinkStageToForm } = componentStageSlice.actions;
1725
1741
  const componentStageReducer = componentStageSlice.reducer;
1726
1742
  const initialState$g = {
1727
1743
  componentTypes: {},
@@ -3097,22 +3113,6 @@ const userFormSlice = createSlice({
3097
3113
  }
3098
3114
  form.favorite = false;
3099
3115
  },
3100
- attachFormToComponentStage: (state, action) => {
3101
- const { formId: formId2, componentStageId } = action.payload;
3102
- const form = state.userForms[formId2];
3103
- if (!form) {
3104
- throw new Error("No form exists with the id " + formId2);
3105
- }
3106
- form.component_stage = componentStageId;
3107
- },
3108
- removeFormFromComponentStage: (state, action) => {
3109
- const { formId: formId2 } = action.payload;
3110
- const form = state.userForms[formId2];
3111
- if (!form) {
3112
- throw new Error("No form exists with the id " + formId2);
3113
- }
3114
- form.component_stage = void 0;
3115
- },
3116
3116
  deleteUserForm: (state, action) => {
3117
3117
  delete state.userForms[action.payload];
3118
3118
  }
@@ -3128,8 +3128,6 @@ const {
3128
3128
  deleteUserFormSubmissions,
3129
3129
  favoriteForm,
3130
3130
  unfavoriteForm,
3131
- attachFormToComponentStage,
3132
- removeFormFromComponentStage,
3133
3131
  deleteUserForm,
3134
3132
  deleteUserFormRevision,
3135
3133
  deleteUserFormRevisions,
@@ -3216,7 +3214,6 @@ const selectUserForm = (formId2) => (state) => {
3216
3214
  const selectSubmissionMapping = (state) => state.userFormReducer.submissions;
3217
3215
  const selectSubmissions = createSelector([selectSubmissionMapping], (submissions) => Object.values(submissions));
3218
3216
  const selectRevisionMapping = (state) => state.userFormReducer.revisions;
3219
- const selectRevisionAttachmentsMapping = (state) => state.userFormReducer.revisionAttachments;
3220
3217
  const selectRevisions = createSelector([selectRevisionMapping], (revisions) => Object.values(revisions));
3221
3218
  const selectRevisionsForForm = restructureCreateSelectorWithArgs(
3222
3219
  createSelector([selectRevisions, (_state, formId2) => formId2], (revisions, formId2) => {
@@ -3286,38 +3283,6 @@ const selectLatestRevisionsFromComponentTypeIds = restructureCreateSelectorWithA
3286
3283
  }
3287
3284
  )
3288
3285
  );
3289
- const selectComponentStageFormLatestRevision = restructureCreateSelectorWithArgs(
3290
- createSelector(
3291
- [
3292
- selectUserFormMapping,
3293
- selectRevisionMapping,
3294
- (_state, componentStageId) => componentStageId
3295
- ],
3296
- (userForms, revisions, componentStageId) => {
3297
- const form = Object.values(userForms).find((userForm) => userForm.component_stage === componentStageId);
3298
- return form ? _selectLatestFormRevision(revisions, form.offline_id) : void 0;
3299
- }
3300
- )
3301
- );
3302
- const selectLatestRevisionsFromComponentStageIds = restructureCreateSelectorWithArgs(
3303
- createSelector(
3304
- [
3305
- selectUserFormMapping,
3306
- selectRevisionMapping,
3307
- (_state, componentStageIds) => componentStageIds
3308
- ],
3309
- (userForms, revisions, componentStageIds) => {
3310
- const componentStageIdsSet = new Set(componentStageIds);
3311
- const ret = {};
3312
- for (const form of Object.values(userForms)) {
3313
- if (form.component_stage && componentStageIdsSet.has(form.component_stage)) {
3314
- ret[form.component_stage] = _selectLatestFormRevision(revisions, form.offline_id);
3315
- }
3316
- }
3317
- return ret;
3318
- }
3319
- )
3320
- );
3321
3286
  const selectLatestRevisionByFormId = createSelector([selectRevisionMapping], (revisions) => {
3322
3287
  const latestRevisions = {};
3323
3288
  for (const revision of Object.values(revisions)) {
@@ -3329,19 +3294,6 @@ const selectLatestRevisionByFormId = createSelector([selectRevisionMapping], (re
3329
3294
  }
3330
3295
  return latestRevisions;
3331
3296
  });
3332
- const selectAllRevisionAttachmentsByLatestRevisionId = createSelector(
3333
- [selectUserFormMapping, selectRevisionMapping, selectRevisionAttachmentsMapping],
3334
- (forms, revisions, attachments) => {
3335
- const mappedAttachments = {};
3336
- for (const form of Object.values(forms)) {
3337
- const latestRevision = _selectLatestFormRevision(revisions, form.offline_id);
3338
- if (attachments[latestRevision.offline_id] !== void 0) {
3339
- mappedAttachments[latestRevision.offline_id] = attachments[latestRevision.offline_id];
3340
- }
3341
- }
3342
- return mappedAttachments;
3343
- }
3344
- );
3345
3297
  const selectNumberOfUserForms = createSelector([selectUserFormMapping], (userForms) => {
3346
3298
  return Object.keys(userForms).length;
3347
3299
  });
@@ -4713,6 +4665,39 @@ class ComponentStageService extends BaseApiService {
4713
4665
  blocks: [componentStage.offline_id]
4714
4666
  });
4715
4667
  }
4668
+ async linkForm(stageId, formId2) {
4669
+ const { store } = this.client;
4670
+ store.dispatch(linkStageToForm({ stageId, formId: formId2 }));
4671
+ try {
4672
+ await this.enqueueRequest({
4673
+ description: "Link component stage to form",
4674
+ method: HttpMethod.POST,
4675
+ url: `/components/stages/${stageId}/associate-with-form/`,
4676
+ payload: { user_form: formId2 },
4677
+ blockers: [stageId, formId2],
4678
+ blocks: [stageId]
4679
+ });
4680
+ } catch (e) {
4681
+ store.dispatch(unlinkStageToForm({ stageId }));
4682
+ throw e;
4683
+ }
4684
+ }
4685
+ async unlinkForm(stageId, formId2) {
4686
+ const { store } = this.client;
4687
+ store.dispatch(unlinkStageToForm({ stageId }));
4688
+ try {
4689
+ await this.enqueueRequest({
4690
+ description: "Unlink component stage from form",
4691
+ method: HttpMethod.DELETE,
4692
+ url: `/components/stages/${stageId}/associate-with-form/`,
4693
+ blockers: [stageId, formId2],
4694
+ blocks: [stageId]
4695
+ });
4696
+ } catch (e) {
4697
+ store.dispatch(linkStageToForm({ stageId, formId: formId2 }));
4698
+ throw e;
4699
+ }
4700
+ }
4716
4701
  async refreshStore() {
4717
4702
  const { store } = this.client;
4718
4703
  const result = await this.enqueueRequest({
@@ -5498,13 +5483,10 @@ class UserFormService extends BaseApiService {
5498
5483
  });
5499
5484
  });
5500
5485
  }
5501
- async add(state, initialRevision, url, ownerUser, ownerOrganization, componentTypeId, componentStageId) {
5486
+ async add(state, initialRevision, url, ownerUser, ownerOrganization, componentTypeId) {
5502
5487
  if (!!ownerUser === !!ownerOrganization) {
5503
5488
  throw new Error("Exactly one of ownerUser and ownerOrganization must be defined.");
5504
5489
  }
5505
- if (componentTypeId && componentStageId) {
5506
- throw new Error("At most one of componentTypeId and componentStageId should be defined.");
5507
- }
5508
5490
  const ownerAttrs = {
5509
5491
  owner_user: ownerUser,
5510
5492
  owner_organization: ownerOrganization
@@ -5520,7 +5502,6 @@ class UserFormService extends BaseApiService {
5520
5502
  submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5521
5503
  created_by: currentUser.id,
5522
5504
  ...componentTypeId && { component_type: componentTypeId },
5523
- ...componentStageId && { component_stage: componentStageId },
5524
5505
  ...ownerAttrs
5525
5506
  };
5526
5507
  const { payloadWithoutImage, images } = await separateImageFromFields(offlineRevisionPayload);
@@ -5543,10 +5524,9 @@ class UserFormService extends BaseApiService {
5543
5524
  payload: {
5544
5525
  ...offlineFormPayload,
5545
5526
  ...componentTypeId && { component_type: componentTypeId },
5546
- ...componentStageId && { component_stage: componentStageId },
5547
5527
  initial_revision: payloadWithoutImage
5548
5528
  },
5549
- blockers: [componentTypeId, componentStageId].filter((x) => x !== void 0),
5529
+ blockers: [componentTypeId].filter((x) => x !== void 0),
5550
5530
  blocks: [offlineFormPayload.offline_id, payloadWithoutImage.offline_id]
5551
5531
  });
5552
5532
  const attachImagesPromises = this.getAttachImagePromises(images, offlineRevisionPayload.offline_id);
@@ -5558,7 +5538,7 @@ class UserFormService extends BaseApiService {
5558
5538
  const settledPromise = Promise.all([formPromise, ...attachImagesPromises]).then(() => formPromise);
5559
5539
  return [retForm, retRevision, formPromise, settledPromise];
5560
5540
  }
5561
- async addForOrganization(initialRevision, componentTypeId, componentStageId) {
5541
+ async addForOrganization(initialRevision, componentTypeId) {
5562
5542
  const state = this.client.store.getState();
5563
5543
  const activeOrganizationId = state.organizationReducer.activeOrganizationId;
5564
5544
  if (!activeOrganizationId) {
@@ -5570,22 +5550,13 @@ class UserFormService extends BaseApiService {
5570
5550
  `/forms/in-organization/${activeOrganizationId}/`,
5571
5551
  void 0,
5572
5552
  activeOrganizationId,
5573
- componentTypeId,
5574
- componentStageId
5553
+ componentTypeId
5575
5554
  );
5576
5555
  }
5577
- async addForCurrentUser(initialRevision, componentTypeId, componentStageId) {
5556
+ async addForCurrentUser(initialRevision, componentTypeId) {
5578
5557
  const state = this.client.store.getState();
5579
5558
  const currentUser = state.userReducer.currentUser;
5580
- return await this.add(
5581
- state,
5582
- initialRevision,
5583
- "/forms/my-forms/",
5584
- currentUser.id,
5585
- void 0,
5586
- componentTypeId,
5587
- componentStageId
5588
- );
5559
+ return await this.add(state, initialRevision, "/forms/my-forms/", currentUser.id, void 0, componentTypeId);
5589
5560
  }
5590
5561
  async createRevision(formId2, revision) {
5591
5562
  const offlineRevision = offline(revision);
@@ -5658,39 +5629,6 @@ class UserFormService extends BaseApiService {
5658
5629
  throw e;
5659
5630
  }
5660
5631
  }
5661
- async attachToComponentStage(formId2, componentStageId) {
5662
- const { store } = this.client;
5663
- store.dispatch(attachFormToComponentStage({ formId: formId2, componentStageId }));
5664
- try {
5665
- await this.enqueueRequest({
5666
- description: "Attach form to component stage",
5667
- method: HttpMethod.POST,
5668
- url: `/forms/${formId2}/associate-with-stage/`,
5669
- payload: { component_stage: componentStageId },
5670
- blockers: [formId2, componentStageId],
5671
- blocks: [formId2]
5672
- });
5673
- } catch (e) {
5674
- store.dispatch(removeFormFromComponentStage({ formId: formId2 }));
5675
- throw e;
5676
- }
5677
- }
5678
- async removeFromComponentStage(formId2, componentStageId) {
5679
- const { store } = this.client;
5680
- store.dispatch(removeFormFromComponentStage({ formId: formId2 }));
5681
- try {
5682
- await this.enqueueRequest({
5683
- description: "Remove form from component stage",
5684
- method: HttpMethod.DELETE,
5685
- url: `/forms/${formId2}/associate-with-stage/`,
5686
- blockers: [formId2, componentStageId],
5687
- blocks: [formId2]
5688
- });
5689
- } catch (e) {
5690
- store.dispatch(attachFormToComponentStage({ formId: formId2, componentStageId }));
5691
- throw e;
5692
- }
5693
- }
5694
5632
  async delete(formId2) {
5695
5633
  const { store } = this.client;
5696
5634
  const state = store.getState();
@@ -10371,10 +10309,12 @@ const initialFormValues = (fields, values) => {
10371
10309
  };
10372
10310
  const useAttachImagesToFormRevisionFields = (revision) => {
10373
10311
  const { sdk } = useSDK();
10374
- const attachments = useAppSelector(selectRevisionAttachments(revision.offline_id));
10312
+ const attachments = useAppSelector(selectRevisionAttachments((revision == null ? void 0 : revision.offline_id) ?? ""));
10375
10313
  return useMemo(() => {
10314
+ if (!revision || !attachments)
10315
+ return revision;
10376
10316
  const revisionCopy = structuredClone(revision);
10377
- for (const attachment of attachments ?? []) {
10317
+ for (const attachment of attachments) {
10378
10318
  const filePromise = sdk.files.fetchFileFromUrl(attachment.file, attachment.file_sha1, attachment.file_name);
10379
10319
  let sectionIndex = -1;
10380
10320
  let fieldIndex = -1;
@@ -10459,6 +10399,9 @@ const FormSubmissionViewer = memo(
10459
10399
  );
10460
10400
  }
10461
10401
  const revisionWithImages = useAttachImagesToFormRevisionFields(revision);
10402
+ if (!revisionWithImages) {
10403
+ throw new Error("Expected revisionWithImages to be defined");
10404
+ }
10462
10405
  const schema = useMemo(() => {
10463
10406
  return formRevisionToSchema(revisionWithImages, { readonly: true });
10464
10407
  }, [revisionWithImages]);
@@ -11784,8 +11727,9 @@ const FormBuilder = memo(
11784
11727
  }),
11785
11728
  [initialTitle]
11786
11729
  );
11730
+ const revisionWithImages = useAttachImagesToFormRevisionFields(revision);
11787
11731
  const formik = useFormik({
11788
- initialValues: wrapRootFieldsWithFieldSection(revision) ?? initialValues,
11732
+ initialValues: wrapRootFieldsWithFieldSection(revisionWithImages) ?? initialValues,
11789
11733
  validate,
11790
11734
  onSubmit: onSave,
11791
11735
  validateOnChange: false,
@@ -12027,7 +11971,6 @@ export {
12027
11971
  addUsers,
12028
11972
  addWorkspace,
12029
11973
  areArraysEqual,
12030
- attachFormToComponentStage,
12031
11974
  authReducer,
12032
11975
  authSlice,
12033
11976
  blobToBase64,
@@ -12106,6 +12049,7 @@ export {
12106
12049
  issueReducer,
12107
12050
  issueSlice,
12108
12051
  issueToSearchResult,
12052
+ linkStageToForm,
12109
12053
  literalToCoordinates,
12110
12054
  logOnlyOnce,
12111
12055
  makeClient,
@@ -12150,7 +12094,6 @@ export {
12150
12094
  removeComponent,
12151
12095
  removeEmailDomain,
12152
12096
  removeFavouriteProjectId,
12153
- removeFormFromComponentStage,
12154
12097
  removeIssue,
12155
12098
  removeIssueComment,
12156
12099
  removeOrganizationAccess,
@@ -12183,7 +12126,6 @@ export {
12183
12126
  selectActiveWorkspace,
12184
12127
  selectActiveWorkspaceId,
12185
12128
  selectAllAttachments,
12186
- selectAllRevisionAttachmentsByLatestRevisionId,
12187
12129
  selectAppearance,
12188
12130
  selectCategories,
12189
12131
  selectCategoriesOfWorkspace,
@@ -12196,7 +12138,6 @@ export {
12196
12138
  selectCompletedStageIdsForComponent,
12197
12139
  selectCompletedStages,
12198
12140
  selectComponent,
12199
- selectComponentStageFormLatestRevision,
12200
12141
  selectComponentType,
12201
12142
  selectComponentTypeForm,
12202
12143
  selectComponentTypeFromComponent,
@@ -12236,7 +12177,6 @@ export {
12236
12177
  selectLatestFormRevision,
12237
12178
  selectLatestRetryTime,
12238
12179
  selectLatestRevisionByFormId,
12239
- selectLatestRevisionsFromComponentStageIds,
12240
12180
  selectLatestRevisionsFromComponentTypeIds,
12241
12181
  selectMainWorkspace,
12242
12182
  selectMapStyle,
@@ -12351,6 +12291,7 @@ export {
12351
12291
  unfavoriteForm,
12352
12292
  unhideAllCategories,
12353
12293
  unhideCategory,
12294
+ unlinkStageToForm,
12354
12295
  updateActiveOrganization,
12355
12296
  updateAttachment,
12356
12297
  updateComponent,