@overmap-ai/core 1.0.65-mapbox.1 → 1.0.65-strip-workspace-access.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.
@@ -397,21 +397,70 @@ var __publicField = (obj, key, value) => {
397
397
  const selectAccessToken = (state) => state.authReducer.accessToken;
398
398
  const selectIsLoggedIn = (state) => state.authReducer.isLoggedIn;
399
399
  const authReducer = authSlice.reducer;
400
- const createPointGeometry = (position) => {
400
+ const coordinatesToLiteral = (coordinates) => {
401
+ return { lng: coordinates[0], lat: coordinates[1] };
402
+ };
403
+ const literalToCoordinates = (literal) => {
404
+ return [literal.lng, literal.lat];
405
+ };
406
+ const flipCoordinates = (coordinates) => {
407
+ return [coordinates[1], coordinates[0]];
408
+ };
409
+ const flipBounds = (bounds) => {
410
+ return [flipCoordinates(bounds[0]), flipCoordinates(bounds[1])];
411
+ };
412
+ function offsetPositionByMeters(originalPosition, latMeters, lngMeters) {
413
+ const { lat, lng } = originalPosition;
414
+ const earthRadius = 6378137;
415
+ const metersPerDegree = 2 * Math.PI * earthRadius / 360;
416
+ const newLng = lng + lngMeters / metersPerDegree / Math.cos(lat * Math.PI / 180);
417
+ const newLat = lat - latMeters / metersPerDegree;
418
+ return { lat: newLat, lng: newLng };
419
+ }
420
+ const createPointGeometry = (coordinates) => {
401
421
  return {
402
422
  type: "Point",
403
- coordinates: position
423
+ coordinates
404
424
  };
405
425
  };
426
+ const coordinatesAreEqual = (a, b) => {
427
+ return a[0] === b[0] && a[1] === b[1];
428
+ };
429
+ const coordinatesToText = (coordinates, decimalPlaces) => {
430
+ if (!coordinates)
431
+ return "(No Location)";
432
+ const { lat, lng } = coordinatesToLiteral(coordinates);
433
+ if (decimalPlaces)
434
+ return `${lat.toFixed(decimalPlaces)}, ${lng.toFixed(decimalPlaces)}`;
435
+ return `${lat}, ${lng}`;
436
+ };
437
+ const coordinatesToUrlText = (coordinates) => {
438
+ const { lat, lng } = coordinatesToLiteral(coordinates);
439
+ return `${lat}%2C${lng}`;
440
+ };
441
+ const openCoordsInGoogleMaps = (coordinates) => {
442
+ const url = `https://www.google.com/maps/search/?api=1&query=${coordinatesToUrlText(coordinates)}`;
443
+ window.open(url);
444
+ };
445
+ const openDirectionsInGoogleMaps = (startingPoint, destination) => {
446
+ const startingPointUrl = coordinatesToUrlText(startingPoint);
447
+ const destinationUrl = coordinatesToUrlText(destination);
448
+ const url = `https://www.google.com/maps/dir/?api=1&origin=${startingPointUrl}&destination=${destinationUrl}`;
449
+ window.open(url);
450
+ };
451
+ const worldBounds = {
452
+ type: "MultiPoint",
453
+ coordinates: [
454
+ [90, -180],
455
+ [-90, 180]
456
+ ]
457
+ };
406
458
  const createMultiPointGeometry = (coordinates) => {
407
459
  return {
408
460
  type: "MultiPoint",
409
461
  coordinates
410
462
  };
411
463
  };
412
- const coordinatesAreEqual = (a, b) => {
413
- return a[0] === b[0] && a[1] === b[1];
414
- };
415
464
  function classNames(...args) {
416
465
  const classes = [];
417
466
  for (const arg of args) {
@@ -589,11 +638,14 @@ var __publicField = (obj, key, value) => {
589
638
  return v.file_sha1 === value.file_sha1;
590
639
  }) === index;
591
640
  }
641
+ function boundsContainPoint(bounds, coordinates) {
642
+ return bounds[0][0] > coordinates[0] && bounds[1][0] < coordinates[0] && bounds[0][1] > coordinates[1] && bounds[1][1] < coordinates[1];
643
+ }
592
644
  const emailRegex = /^.+@.+\..+$/;
593
645
  const fullAssetMarkerSize = 45;
594
646
  const DEFAULT_ISSUE_STATUS = IssueStatus.BACKLOG;
595
647
  const DEFAULT_ISSUE_PRIORITY = IssuePriority.MEDIUM;
596
- const OUTBOX_RETRY_DELAY = 5e3;
648
+ const OUTBOX_RETRY_DELAY = 6e4;
597
649
  const EMPTY_ARRAY = Object.freeze([]);
598
650
  let debug = false;
599
651
  const REACT_APP_DEBUG_MEMOIZATION = {}.REACT_APP_DEBUG_MEMOIZATION || "";
@@ -2311,29 +2363,18 @@ var __publicField = (obj, key, value) => {
2311
2363
  (_state, search) => search
2312
2364
  ],
2313
2365
  (formsMapping, revisions, search) => {
2314
- const { searchTerm, maxResults, favorites, organization } = search;
2315
- const favoriteMatches = [];
2366
+ const { searchTerm, maxResults, organization } = search;
2316
2367
  const regularMatches = [];
2317
2368
  for (const [formId, form] of Object.entries(formsMapping)) {
2318
- if (favorites !== void 0 && form.favorite != favorites)
2319
- continue;
2320
2369
  if (Number.isInteger(organization) && organization !== form.organization) {
2321
2370
  continue;
2322
2371
  }
2323
2372
  const latestRevision = _selectLatestFormRevision(revisions, formId);
2324
2373
  if (latestRevision.title.toLowerCase().includes(searchTerm.toLowerCase())) {
2325
- if (form.favorite) {
2326
- favoriteMatches.push({ ...form, latestRevision });
2327
- } else {
2328
- regularMatches.push({ ...form, latestRevision });
2329
- }
2330
- }
2331
- if (favoriteMatches.length >= maxResults) {
2332
- break;
2374
+ regularMatches.push({ ...form, latestRevision });
2333
2375
  }
2334
2376
  }
2335
- const maxRegularMatches = maxResults - favoriteMatches.length;
2336
- return [...favoriteMatches, ...regularMatches.slice(0, maxRegularMatches)];
2377
+ return [...regularMatches.slice(0, maxResults)];
2337
2378
  },
2338
2379
  // as the argument is an object, we check the first level of properties for equality
2339
2380
  { memoizeOptions: { equalityCheck: shallowEqual } }
@@ -3360,62 +3401,11 @@ var __publicField = (obj, key, value) => {
3360
3401
  };
3361
3402
  const overmapReducer = toolkit.combineReducers(overmapReducers);
3362
3403
  const resetStore = "RESET";
3363
- function handleWorkspaceRemoval(draft, action) {
3364
- const workspaceId = action.payload;
3365
- const issuesVisibleInWorkspace = Object.values(draft.issueReducer.instances).filter(
3366
- (issue) => issue.visible_in_workspaces.includes(workspaceId)
3367
- );
3368
- const mainWorkspace = selectMainWorkspace(draft);
3369
- if (!mainWorkspace) {
3370
- throw new Error("Main workspace not found");
3371
- }
3372
- if (action.payload === mainWorkspace.offline_id) {
3373
- throw new Error("Tried to delete main workspace");
3374
- }
3375
- const categoriesInThisWorkspace = new Set(
3376
- selectCategoriesOfWorkspace(workspaceId)(draft).map((category) => category.offline_id)
3377
- );
3378
- for (const issue of issuesVisibleInWorkspace) {
3379
- if (issue.category && categoriesInThisWorkspace.has(issue.category)) {
3380
- issue.category = null;
3381
- }
3382
- }
3383
- const issuesWithThisWorkspaceIndex = issuesVisibleInWorkspace.filter(
3384
- (issue) => issue.index_workspace === action.payload
3385
- );
3386
- for (const issue of issuesWithThisWorkspaceIndex) {
3387
- issue.index_workspace = mainWorkspace.offline_id;
3388
- if (!issue.visible_in_workspaces.includes(mainWorkspace.offline_id)) {
3389
- issue.visible_in_workspaces.push(mainWorkspace.offline_id);
3390
- }
3391
- }
3392
- for (const issue of issuesVisibleInWorkspace) {
3393
- const indexOfWorkspace = issue.visible_in_workspaces.indexOf(workspaceId);
3394
- if (indexOfWorkspace === -1) {
3395
- throw new Error("Workspace not found in issue's visible_in_workspaces");
3396
- }
3397
- issue.visible_in_workspaces.splice(indexOfWorkspace, 1);
3398
- }
3399
- for (const issue of issuesVisibleInWorkspace) {
3400
- if (issue.visible_in_workspaces.length === 0) {
3401
- throw new Error(`Unexpected error: Issue ${issue.offline_id} has no visible_in_workspaces`);
3402
- }
3403
- if (issue.index_workspace === action.payload || !issue.index_workspace) {
3404
- throw new Error(`Failed to update index_workspace of issue ${issue.offline_id} to main workspace`);
3405
- }
3406
- }
3407
- }
3408
3404
  const overmapRootReducer = (state, action) => {
3409
3405
  if (action.type === "auth/setLoggedIn" && !action.payload) {
3410
3406
  return overmapReducer(void 0, action);
3411
3407
  }
3412
- let mutatedState = state;
3413
- if (state && action.type === "workspace/removeWorkspace") {
3414
- mutatedState = toolkit.createNextState(state, (draft) => {
3415
- handleWorkspaceRemoval(draft, action);
3416
- });
3417
- }
3418
- return overmapReducer(mutatedState, action);
3408
+ return overmapReducer(state, action);
3419
3409
  };
3420
3410
  let __OUTBOX_COORDINATOR = null;
3421
3411
  function getOutboxCoordinator() {
@@ -4034,10 +4024,17 @@ var __publicField = (obj, key, value) => {
4034
4024
  }
4035
4025
  }
4036
4026
  class CategoryService extends BaseApiService {
4037
- add(category, workspaceId) {
4038
- const offlineCategory = offline(category);
4039
- const categoryWithWorkspace = { ...offlineCategory, workspace: workspaceId };
4040
- this.dispatch(addCategory(categoryWithWorkspace));
4027
+ add(payload, workspaceId) {
4028
+ const { store } = this.client;
4029
+ const createdBy = store.getState().userReducer.currentUser.id;
4030
+ const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
4031
+ const offlineCategory = offline({
4032
+ ...payload,
4033
+ created_by: createdBy,
4034
+ submitted_at: submittedAt,
4035
+ workspace: workspaceId
4036
+ });
4037
+ this.dispatch(addCategory(offlineCategory));
4041
4038
  const promise = this.enqueueRequest({
4042
4039
  description: "Create Category",
4043
4040
  method: HttpMethod.POST,
@@ -4046,10 +4043,10 @@ var __publicField = (obj, key, value) => {
4046
4043
  workspace_id: workspaceId.toString()
4047
4044
  },
4048
4045
  payload: offlineCategory,
4049
- blockers: [],
4046
+ blockers: [workspaceId],
4050
4047
  blocks: [offlineCategory.offline_id]
4051
4048
  });
4052
- return [categoryWithWorkspace, promise];
4049
+ return [offlineCategory, promise];
4053
4050
  }
4054
4051
  update(category, workspaceId) {
4055
4052
  const state = this.client.store.getState();
@@ -4919,11 +4916,7 @@ var __publicField = (obj, key, value) => {
4919
4916
  ...issueType ? { issue_type: issueType } : {}
4920
4917
  },
4921
4918
  payload: issuePayload,
4922
- blockers: [
4923
- "add-issue",
4924
- ...issuePayload.index_workspace ? [issuePayload.index_workspace] : [],
4925
- ...issuePayload.visible_in_workspaces
4926
- ],
4919
+ blockers: ["add-issue", ...issuePayload.index_workspace ? [issuePayload.index_workspace] : []],
4927
4920
  blocks: [issuePayload.offline_id]
4928
4921
  });
4929
4922
  void promise.then((result) => {
@@ -5704,48 +5697,6 @@ var __publicField = (obj, key, value) => {
5704
5697
  });
5705
5698
  return [fullRevision, offlineFormRevisionAttachments, promise, attachmentsPromise];
5706
5699
  }
5707
- async favorite(formId, projectId) {
5708
- const { store } = this.client;
5709
- const state = store.getState();
5710
- const form = state.formReducer.instances[formId];
5711
- if (!form) {
5712
- throw new Error(`Expected form to exist, got ${form}`);
5713
- }
5714
- this.dispatch(updateForm({ ...form, favorite: true }));
5715
- try {
5716
- await this.enqueueRequest({
5717
- description: "Favorite form",
5718
- method: HttpMethod.POST,
5719
- url: `/forms/${formId}/favorite/${projectId}/`,
5720
- blockers: [formId, `favorite-${formId}`],
5721
- blocks: [`favorite-${formId}`]
5722
- });
5723
- } catch (e) {
5724
- this.dispatch(updateForm(form));
5725
- throw e;
5726
- }
5727
- }
5728
- async unfavorite(formId, projectId) {
5729
- const { store } = this.client;
5730
- const state = store.getState();
5731
- const form = state.formReducer.instances[formId];
5732
- if (!form) {
5733
- throw new Error(`Expected form to exist, got ${form}`);
5734
- }
5735
- this.dispatch(updateForm({ ...form, favorite: false }));
5736
- try {
5737
- return await this.enqueueRequest({
5738
- description: "Unfavorite form",
5739
- method: HttpMethod.DELETE,
5740
- url: `/forms/${formId}/unfavorite/${projectId}/`,
5741
- blockers: [formId, `favorite-${formId}`],
5742
- blocks: [`favorite-${formId}`]
5743
- });
5744
- } catch (e) {
5745
- this.dispatch(updateForm(form));
5746
- throw e;
5747
- }
5748
- }
5749
5700
  async delete(formId) {
5750
5701
  const { store } = this.client;
5751
5702
  const state = store.getState();
@@ -6206,13 +6157,19 @@ var __publicField = (obj, key, value) => {
6206
6157
  }
6207
6158
  }
6208
6159
  class WorkspaceService extends BaseApiService {
6209
- add(workspace) {
6210
- const offlineWorkspace = offline(workspace);
6160
+ add(payload) {
6161
+ const { store } = this.client;
6162
+ const createdBy = store.getState().userReducer.currentUser.id;
6163
+ const offlineWorkspace = offline({
6164
+ ...payload,
6165
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
6166
+ created_by: createdBy
6167
+ });
6211
6168
  this.dispatch(addWorkspace(offlineWorkspace));
6212
6169
  const promise = this.enqueueRequest({
6213
6170
  description: "Create Workspace",
6214
6171
  method: HttpMethod.POST,
6215
- url: `/projects/${workspace.project}/workspaces/`,
6172
+ url: `/projects/${payload.project}/workspaces/`,
6216
6173
  payload: offlineWorkspace,
6217
6174
  blockers: ["add-workspace"],
6218
6175
  blocks: [offlineWorkspace.offline_id]
@@ -7624,6 +7581,7 @@ var __publicField = (obj, key, value) => {
7624
7581
  exports2.authReducer = authReducer;
7625
7582
  exports2.authSlice = authSlice;
7626
7583
  exports2.blobToBase64 = blobToBase64;
7584
+ exports2.boundsContainPoint = boundsContainPoint;
7627
7585
  exports2.categoryReducer = categoryReducer;
7628
7586
  exports2.categorySlice = categorySlice;
7629
7587
  exports2.classNames = classNames;
@@ -7631,6 +7589,9 @@ var __publicField = (obj, key, value) => {
7631
7589
  exports2.clearTokens = clearTokens;
7632
7590
  exports2.constructUploadedFilePayloads = constructUploadedFilePayloads;
7633
7591
  exports2.coordinatesAreEqual = coordinatesAreEqual;
7592
+ exports2.coordinatesToLiteral = coordinatesToLiteral;
7593
+ exports2.coordinatesToText = coordinatesToText;
7594
+ exports2.coordinatesToUrlText = coordinatesToUrlText;
7634
7595
  exports2.createMultiPointGeometry = createMultiPointGeometry;
7635
7596
  exports2.createOfflineAction = createOfflineAction;
7636
7597
  exports2.createPointGeometry = createPointGeometry;
@@ -7693,6 +7654,8 @@ var __publicField = (obj, key, value) => {
7693
7654
  exports2.fileReducer = fileReducer;
7694
7655
  exports2.fileSlice = fileSlice;
7695
7656
  exports2.fileToBlob = fileToBlob;
7657
+ exports2.flipBounds = flipBounds;
7658
+ exports2.flipCoordinates = flipCoordinates;
7696
7659
  exports2.formReducer = formReducer;
7697
7660
  exports2.formRevisionAttachmentReducer = formRevisionAttachmentReducer;
7698
7661
  exports2.formRevisionAttachmentSlice = formRevisionAttachmentSlice;
@@ -7759,14 +7722,18 @@ var __publicField = (obj, key, value) => {
7759
7722
  exports2.issueUpdateSlice = issueUpdateSlice;
7760
7723
  exports2.licenseReducer = licenseReducer;
7761
7724
  exports2.licenseSlice = licenseSlice;
7725
+ exports2.literalToCoordinates = literalToCoordinates;
7762
7726
  exports2.logOnlyOnce = logOnlyOnce;
7763
7727
  exports2.markAsDeleted = markAsDeleted;
7764
7728
  exports2.markForDeletion = markForDeletion;
7765
7729
  exports2.memoize = memoize;
7766
7730
  exports2.moveDocument = moveDocument;
7767
7731
  exports2.offline = offline;
7732
+ exports2.offsetPositionByMeters = offsetPositionByMeters;
7768
7733
  exports2.onlyUniqueHashes = onlyUniqueHashes;
7769
7734
  exports2.onlyUniqueOfflineIds = onlyUniqueOfflineIds;
7735
+ exports2.openCoordsInGoogleMaps = openCoordsInGoogleMaps;
7736
+ exports2.openDirectionsInGoogleMaps = openDirectionsInGoogleMaps;
7770
7737
  exports2.organizationAccessReducer = organizationAccessReducer;
7771
7738
  exports2.organizationAccessSlice = organizationAccessSlice;
7772
7739
  exports2.organizationReducer = organizationReducer;
@@ -8082,6 +8049,7 @@ var __publicField = (obj, key, value) => {
8082
8049
  exports2.warningColor = warningColor;
8083
8050
  exports2.workspaceReducer = workspaceReducer;
8084
8051
  exports2.workspaceSlice = workspaceSlice;
8052
+ exports2.worldBounds = worldBounds;
8085
8053
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
8086
8054
  });
8087
8055
  //# sourceMappingURL=overmap-core.umd.cjs.map