@overmap-ai/core 1.0.60-forms-refactor-1.0 → 1.0.60-forms-refactor-1.1

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.
@@ -2357,11 +2357,11 @@ const selectLatestFormRevisionsOfAssetTypes = restructureCreateSelectorWithArgs(
2357
2357
  selectFormRevisionMapping,
2358
2358
  (_state, assetTypeIds) => assetTypeIds
2359
2359
  ],
2360
- (userForms, revisions, assetTypeIds) => {
2360
+ (formsMapping, revisions, assetTypeIds) => {
2361
2361
  const assetTypeIdsSet = new Set(assetTypeIds);
2362
2362
  const formsOfAssetTypes = {};
2363
2363
  const ret = {};
2364
- for (const form of Object.values(userForms)) {
2364
+ for (const form of Object.values(formsMapping)) {
2365
2365
  if (form.asset_type && assetTypeIdsSet.has(form.asset_type)) {
2366
2366
  formsOfAssetTypes[form.offline_id] = form;
2367
2367
  }
@@ -2414,22 +2414,22 @@ const selectFilteredForms = restructureCreateSelectorWithArgs(
2414
2414
  (state) => state.formRevisionReducer.instances,
2415
2415
  (_state, search) => search
2416
2416
  ],
2417
- (userForms, revisions, search) => {
2417
+ (formsMapping, revisions, search) => {
2418
2418
  const { searchTerm, maxResults, favorites, organization } = search;
2419
2419
  const favoriteMatches = [];
2420
2420
  const regularMatches = [];
2421
- for (const [userFormId, userForm] of Object.entries(userForms)) {
2422
- if (favorites !== void 0 && userForm.favorite != favorites)
2421
+ for (const [formId, form] of Object.entries(formsMapping)) {
2422
+ if (favorites !== void 0 && form.favorite != favorites)
2423
2423
  continue;
2424
- if (Number.isInteger(organization) && organization !== userForm.organization) {
2424
+ if (Number.isInteger(organization) && organization !== form.organization) {
2425
2425
  continue;
2426
2426
  }
2427
- const latestRevision = _selectLatestFormRevision(revisions, userFormId);
2427
+ const latestRevision = _selectLatestFormRevision(revisions, formId);
2428
2428
  if (latestRevision.title.toLowerCase().includes(searchTerm.toLowerCase())) {
2429
- if (userForm.favorite) {
2430
- favoriteMatches.push({ ...userForm, latestRevision });
2429
+ if (form.favorite) {
2430
+ favoriteMatches.push({ ...form, latestRevision });
2431
2431
  } else {
2432
- regularMatches.push({ ...userForm, latestRevision });
2432
+ regularMatches.push({ ...form, latestRevision });
2433
2433
  }
2434
2434
  }
2435
2435
  if (favoriteMatches.length >= maxResults) {
@@ -2443,35 +2443,33 @@ const selectFilteredForms = restructureCreateSelectorWithArgs(
2443
2443
  { memoizeOptions: { equalityCheck: shallowEqual } }
2444
2444
  )
2445
2445
  );
2446
- const selectForm = restructureCreateSelectorWithArgs(
2447
- createSelector([selectFormsMapping, (_, formId) => formId], (userForms, formId) => {
2448
- return userForms[formId];
2449
- })
2450
- );
2446
+ const selectForm = (formId) => (state) => {
2447
+ return state.formReducer.instances[formId];
2448
+ };
2451
2449
  const selectFormMapping = (state) => {
2452
2450
  return state.formReducer.instances;
2453
2451
  };
2454
2452
  const selectFormOfAssetType = restructureCreateSelectorWithArgs(
2455
2453
  createSelector(
2456
2454
  [selectFormMapping, (_state, assetTypeId) => assetTypeId],
2457
- (userForms, assetTypeId) => {
2458
- return Object.values(userForms).find((userForm) => userForm.asset_type === assetTypeId);
2455
+ (formsMapping, assetTypeId) => {
2456
+ return Object.values(formsMapping).find((form) => form.asset_type === assetTypeId);
2459
2457
  }
2460
2458
  )
2461
2459
  );
2462
2460
  const selectFormOfIssueType = restructureCreateSelectorWithArgs(
2463
2461
  createSelector(
2464
2462
  [selectFormMapping, (_state, issueTypeId) => issueTypeId],
2465
- (userForms, issueTypeId) => {
2466
- return Object.values(userForms).find((userForm) => userForm.issue_type === issueTypeId);
2463
+ (formsMapping, issueTypeId) => {
2464
+ return Object.values(formsMapping).find((form) => form.issue_type === issueTypeId);
2467
2465
  }
2468
2466
  )
2469
2467
  );
2470
- const selectFormsCount = createSelector([selectFormMapping], (userForms) => {
2471
- return Object.keys(userForms).length;
2468
+ const selectFormsCount = createSelector([selectFormMapping], (formsMapping) => {
2469
+ return Object.keys(formsMapping).length;
2472
2470
  });
2473
- const selectGeneralFormCount = createSelector([selectFormMapping], (userForms) => {
2474
- return Object.values(userForms).filter((form) => !form.asset_type).length;
2471
+ const selectGeneralFormCount = createSelector([selectFormMapping], (formsMapping) => {
2472
+ return Object.values(formsMapping).filter((form) => !form.asset_type).length;
2475
2473
  });
2476
2474
  const formReducer = formSlice.reducer;
2477
2475
  const submissionAdapter = createModelAdapter((submission) => submission.offline_id);
@@ -2691,12 +2689,12 @@ const {
2691
2689
  deleteFormRevisionAttachment,
2692
2690
  deleteFormRevisionAttachments
2693
2691
  } = formRevisionAttachmentSlice.actions;
2694
- const selectUserFormRevisionAttachmentsMapping = (state) => {
2692
+ const selectFormRevisionAttachmentsMapping = (state) => {
2695
2693
  return state.formRevisionAttachmentReducer.instances;
2696
2694
  };
2697
2695
  const selectAttachmentsOfFormRevision = restructureCreateSelectorWithArgs(
2698
2696
  createSelector(
2699
- [selectUserFormRevisionAttachmentsMapping, (_state, revisionId) => revisionId],
2697
+ [selectFormRevisionAttachmentsMapping, (_state, revisionId) => revisionId],
2700
2698
  (attachments, revisionId) => {
2701
2699
  return Object.values(attachments).filter((attachment) => attachment.revision === revisionId);
2702
2700
  }
@@ -5631,17 +5629,17 @@ class FormService extends BaseApiService {
5631
5629
  async delete(formId) {
5632
5630
  const { store } = this.client;
5633
5631
  const state = store.getState();
5634
- const userForm = selectForm(formId)(state);
5635
- if (!userForm) {
5636
- throw new Error("Expected userForm to exist");
5632
+ const form = selectForm(formId)(state);
5633
+ if (!form) {
5634
+ throw new Error("Expected form to exist");
5637
5635
  }
5638
- const userFormSubmissions = selectFormSubmissionsOfForm(formId)(state);
5639
- if (userFormSubmissions && userFormSubmissions.length > 0) {
5640
- this.dispatch(deleteFormSubmissions(userFormSubmissions.map(({ offline_id }) => offline_id)));
5636
+ const formSubmissions = selectFormSubmissionsOfForm(formId)(state);
5637
+ if (formSubmissions && formSubmissions.length > 0) {
5638
+ this.dispatch(deleteFormSubmissions(formSubmissions.map(({ offline_id }) => offline_id)));
5641
5639
  }
5642
- const userFormRevisions = selectFormRevisionsOfForm(formId)(state);
5643
- if (userFormRevisions && userFormRevisions.length > 0) {
5644
- this.dispatch(deleteFormRevisions(userFormRevisions.map(({ offline_id }) => offline_id)));
5640
+ const formRevisions = selectFormRevisionsOfForm(formId)(state);
5641
+ if (formRevisions && formRevisions.length > 0) {
5642
+ this.dispatch(deleteFormRevisions(formRevisions.map(({ offline_id }) => offline_id)));
5645
5643
  }
5646
5644
  this.dispatch(deleteForm(formId));
5647
5645
  try {
@@ -5653,12 +5651,12 @@ class FormService extends BaseApiService {
5653
5651
  blocks: []
5654
5652
  });
5655
5653
  } catch (e) {
5656
- this.dispatch(addForm(userForm));
5657
- if (userFormRevisions && userFormRevisions.length > 0) {
5658
- this.dispatch(addFormRevisions(userFormRevisions));
5654
+ this.dispatch(addForm(form));
5655
+ if (formRevisions && formRevisions.length > 0) {
5656
+ this.dispatch(addFormRevisions(formRevisions));
5659
5657
  }
5660
- if (userFormSubmissions && userFormSubmissions.length > 0) {
5661
- this.dispatch(addFormSubmissions(userFormSubmissions));
5658
+ if (formSubmissions && formSubmissions.length > 0) {
5659
+ this.dispatch(addFormSubmissions(formSubmissions));
5662
5660
  }
5663
5661
  throw e;
5664
5662
  }
@@ -7503,6 +7501,7 @@ export {
7503
7501
  selectFormOfAssetType,
7504
7502
  selectFormOfIssueType,
7505
7503
  selectFormRevision,
7504
+ selectFormRevisionAttachmentsMapping,
7506
7505
  selectFormRevisionMapping,
7507
7506
  selectFormRevisions,
7508
7507
  selectFormRevisionsOfForm,
@@ -7602,7 +7601,6 @@ export {
7602
7601
  selectTeamsOfUser,
7603
7602
  selectUploadUrl,
7604
7603
  selectUser,
7605
- selectUserFormRevisionAttachmentsMapping,
7606
7604
  selectUsersAsMapping,
7607
7605
  selectWorkspaceById,
7608
7606
  selectWorkspaceMapping,