@overmap-ai/core 1.0.47 → 1.0.48-activity-history.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.
@@ -2047,6 +2047,7 @@ const initialState$g = {
2047
2047
  issues: {},
2048
2048
  attachments: {},
2049
2049
  comments: {},
2050
+ updates: {},
2050
2051
  visibleStatuses: [IssueStatus.BACKLOG, IssueStatus.SELECTED],
2051
2052
  visibleUserIds: null,
2052
2053
  recentIssueIds: [],
@@ -2068,6 +2069,16 @@ const issueSlice = createSlice({
2068
2069
  });
2069
2070
  },
2070
2071
  setIssueAttachments: setAttachments,
2072
+ setIssueUpdates: (state, action) => {
2073
+ if (action.payload.filter(onlyUniqueOfflineIds).length !== action.payload.length) {
2074
+ throw new Error("Tried to use setIssues reducer with duplicate ID's");
2075
+ }
2076
+ const newUpdates = {};
2077
+ for (const update of action.payload) {
2078
+ newUpdates[update.offline_id] = update;
2079
+ }
2080
+ state.updates = newUpdates;
2081
+ },
2071
2082
  setActiveIssueId: (state, action) => {
2072
2083
  state.activeIssueId = action.payload;
2073
2084
  },
@@ -2079,6 +2090,17 @@ const issueSlice = createSlice({
2079
2090
  },
2080
2091
  addIssueAttachment: addAttachment,
2081
2092
  addIssueAttachments: addAttachments,
2093
+ addIssueUpdate: (state, action) => {
2094
+ if (action.payload.offline_id in state.updates) {
2095
+ throw new Error(`Tried to add duplicate issue update with offline_id: ${action.payload.offline_id}`);
2096
+ }
2097
+ state.updates[action.payload.offline_id] = action.payload;
2098
+ },
2099
+ addIssueUpdates: (state, action) => {
2100
+ for (const update of action.payload) {
2101
+ state.updates[update.offline_id] = update;
2102
+ }
2103
+ },
2082
2104
  updateIssue: (state, action) => {
2083
2105
  if (action.payload.offline_id in state.issues) {
2084
2106
  state.issues[action.payload.offline_id] = {
@@ -2098,6 +2120,18 @@ const issueSlice = createSlice({
2098
2120
  }
2099
2121
  },
2100
2122
  removeIssueAttachment: removeAttachment,
2123
+ removeIssueUpdate: (state, action) => {
2124
+ if (action.payload in state.updates) {
2125
+ delete state.updates[action.payload];
2126
+ } else {
2127
+ throw new Error(`Failed to remove issue update because offline_id doesn't exist: ${action.payload}`);
2128
+ }
2129
+ },
2130
+ removeIssueUpdates: (state, action) => {
2131
+ for (const updateId of action.payload) {
2132
+ delete state.updates[updateId];
2133
+ }
2134
+ },
2101
2135
  removeAttachmentsOfIssue: (state, action) => {
2102
2136
  const attachments = Object.values(state.attachments).filter((a) => a.issue === action.payload);
2103
2137
  for (const attachment of attachments) {
@@ -2154,6 +2188,8 @@ const {
2154
2188
  addIssueAttachment,
2155
2189
  addIssueAttachments,
2156
2190
  addIssue,
2191
+ addIssueUpdate,
2192
+ addIssueUpdates,
2157
2193
  addOrReplaceIssueComment,
2158
2194
  addToRecentIssues,
2159
2195
  cleanRecentIssues,
@@ -2161,11 +2197,14 @@ const {
2161
2197
  removeAttachmentsOfIssue,
2162
2198
  removeIssue,
2163
2199
  removeIssueComment,
2200
+ removeIssueUpdate,
2201
+ removeIssueUpdates,
2164
2202
  removeRecentIssue,
2165
2203
  resetRecentIssues,
2166
2204
  setActiveIssueId,
2167
2205
  setIssueAttachments,
2168
2206
  setIssueComments,
2207
+ setIssueUpdates,
2169
2208
  setIssues,
2170
2209
  setVisibleStatuses,
2171
2210
  setVisibleUserIds,
@@ -2241,6 +2280,12 @@ const selectCommentsOfIssue = restructureCreateSelectorWithArgs(
2241
2280
  return Object.values(commentMapping).filter((comment) => comment.issue === issueId);
2242
2281
  })
2243
2282
  );
2283
+ const selectIssueUpdateMapping = (state) => state.issueReducer.updates;
2284
+ const selectIssueUpdatesOfIssue = restructureCreateSelectorWithArgs(
2285
+ createSelector([selectIssueUpdateMapping, (_state, issueId) => issueId], (updates, issueId) => {
2286
+ return Object.values(updates).filter((update) => update.issue === issueId);
2287
+ })
2288
+ );
2244
2289
  const selectAttachmentsOfIssue = restructureCreateSelectorWithArgs(
2245
2290
  createSelector(
2246
2291
  [selectIssueAttachments, (_state, issueId) => issueId],
@@ -2449,6 +2494,16 @@ var OrganizationAccessLevel = /* @__PURE__ */ ((OrganizationAccessLevel2) => {
2449
2494
  OrganizationAccessLevel2[OrganizationAccessLevel2["ADMIN"] = 2] = "ADMIN";
2450
2495
  return OrganizationAccessLevel2;
2451
2496
  })(OrganizationAccessLevel || {});
2497
+ var IssueUpdateChange = /* @__PURE__ */ ((IssueUpdateChange2) => {
2498
+ IssueUpdateChange2["STATUS"] = "status";
2499
+ IssueUpdateChange2["PRIORITY"] = "priority";
2500
+ IssueUpdateChange2["CATEGORY"] = "category";
2501
+ IssueUpdateChange2["DESCRIPTION"] = "description";
2502
+ IssueUpdateChange2["TITLE"] = "title";
2503
+ IssueUpdateChange2["ASSIGNED_TO"] = "assigned_to";
2504
+ IssueUpdateChange2["DUE_DATE"] = "due_date";
2505
+ return IssueUpdateChange2;
2506
+ })(IssueUpdateChange || {});
2452
2507
  var ProjectType = /* @__PURE__ */ ((ProjectType2) => {
2453
2508
  ProjectType2[ProjectType2["PERSONAL"] = 0] = "PERSONAL";
2454
2509
  ProjectType2[ProjectType2["ORGANIZATION"] = 2] = "ORGANIZATION";
@@ -5767,6 +5822,28 @@ class IssueCommentService extends BaseApiService {
5767
5822
  });
5768
5823
  }
5769
5824
  }
5825
+ class IssueUpdateService extends BaseApiService {
5826
+ async refreshStore() {
5827
+ const { store } = this.client;
5828
+ const result = await this.enqueueRequest({
5829
+ description: "Get issue updates",
5830
+ method: HttpMethod.GET,
5831
+ url: `/projects/${store.getState().projectReducer.activeProjectId}/issues/updates/`,
5832
+ blockers: [],
5833
+ blocks: []
5834
+ });
5835
+ let filteredResult = result.filter(onlyUniqueOfflineIds);
5836
+ filteredResult = filteredResult.map((comment) => {
5837
+ return { ...comment };
5838
+ });
5839
+ if (result.length !== filteredResult.length) {
5840
+ console.error(
5841
+ `Received duplicate comments from the API (new length ${filteredResult.length}); filtered in browser.`
5842
+ );
5843
+ }
5844
+ store.dispatch(setIssueUpdates(filteredResult));
5845
+ }
5846
+ }
5770
5847
  class IssueService extends BaseApiService {
5771
5848
  // Basic CRUD functions
5772
5849
  // TODO: Once all models are represented in `Created<TModel>`, use `Created` in `OptimisticModelResult`, so we don't
@@ -5845,7 +5922,83 @@ class IssueService extends BaseApiService {
5845
5922
  return [offlineIssues, promise];
5846
5923
  }
5847
5924
  update(issue) {
5925
+ const state = this.client.store.getState();
5926
+ const issueToBeUpdated = state.issueReducer.issues[issue.offline_id];
5927
+ if (!issueToBeUpdated) {
5928
+ throw new Error(
5929
+ `Attempting to update an issue with offline_id ${issue.offline_id} that doesn't exist in the store`
5930
+ );
5931
+ }
5848
5932
  this.client.store.dispatch(updateIssue(issue));
5933
+ const changes = {};
5934
+ for (const issueUpdateChange of [
5935
+ IssueUpdateChange.TITLE,
5936
+ IssueUpdateChange.DESCRIPTION,
5937
+ IssueUpdateChange.STATUS,
5938
+ IssueUpdateChange.CATEGORY,
5939
+ IssueUpdateChange.PRIORITY,
5940
+ IssueUpdateChange.ASSIGNED_TO,
5941
+ IssueUpdateChange.DUE_DATE
5942
+ ]) {
5943
+ if (issueUpdateChange in issue && issue[issueUpdateChange] !== issueToBeUpdated[issueUpdateChange]) {
5944
+ switch (issueUpdateChange) {
5945
+ case "category": {
5946
+ let categoryOrNull = null;
5947
+ const categoryIdOrNull = issue[issueUpdateChange];
5948
+ if (categoryIdOrNull) {
5949
+ categoryOrNull = state.categoryReducer.categories[categoryIdOrNull] ?? null;
5950
+ if (!categoryOrNull)
5951
+ throw new Error(
5952
+ `Trying to update issue category to ${categoryIdOrNull} which does not exist in store`
5953
+ );
5954
+ }
5955
+ changes[issueUpdateChange] = categoryOrNull ? {
5956
+ name: categoryOrNull.name,
5957
+ color: categoryOrNull.color,
5958
+ offline_id: categoryOrNull.offline_id
5959
+ } : null;
5960
+ break;
5961
+ }
5962
+ case "assigned_to": {
5963
+ let userOrNull = null;
5964
+ const userIdOrNull = issue[issueUpdateChange];
5965
+ if (userIdOrNull) {
5966
+ userOrNull = state.userReducer.users[userIdOrNull] ?? null;
5967
+ if (!userOrNull)
5968
+ throw new Error(
5969
+ `Trying to update issue assigned_to to ${userIdOrNull} which does not exist in store`
5970
+ );
5971
+ }
5972
+ changes[issueUpdateChange] = userOrNull ? {
5973
+ full_name: userOrNull.username,
5974
+ id: userOrNull.id
5975
+ } : null;
5976
+ break;
5977
+ }
5978
+ case "description":
5979
+ changes[issueUpdateChange] = issue[issueUpdateChange] ?? null;
5980
+ break;
5981
+ case "title":
5982
+ changes[issueUpdateChange] = issue[issueUpdateChange] ?? null;
5983
+ break;
5984
+ case "priority":
5985
+ changes[issueUpdateChange] = issue[issueUpdateChange];
5986
+ break;
5987
+ case "status":
5988
+ changes[issueUpdateChange] = issue[issueUpdateChange];
5989
+ break;
5990
+ case "due_date":
5991
+ changes[issueUpdateChange] = issue[issueUpdateChange] ? issue[issueUpdateChange] : null;
5992
+ }
5993
+ }
5994
+ }
5995
+ const offlineIssueUpdate = offline({
5996
+ created_by: state.userReducer.currentUser.id,
5997
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5998
+ issue: issueToBeUpdated.offline_id,
5999
+ changes
6000
+ });
6001
+ this.client.store.dispatch(addIssueUpdate(offlineIssueUpdate));
5849
6002
  const promise = this.enqueueRequest({
5850
6003
  description: "Edit issue",
5851
6004
  method: HttpMethod.PATCH,
@@ -5854,23 +6007,30 @@ class IssueService extends BaseApiService {
5854
6007
  blockers: [issue.offline_id],
5855
6008
  blocks: [issue.offline_id]
5856
6009
  });
6010
+ promise.catch(() => {
6011
+ this.client.store.dispatch(updateIssue(issueToBeUpdated));
6012
+ this.client.store.dispatch(removeIssueUpdate(offlineIssueUpdate.offline_id));
6013
+ });
5857
6014
  const fullIssue = this.client.store.getState().issueReducer.issues[issue.offline_id];
5858
6015
  return [fullIssue, promise];
5859
6016
  }
5860
6017
  async remove(id) {
5861
6018
  const { store } = this.client;
5862
6019
  const state = store.getState();
6020
+ const dispatch = store.dispatch;
5863
6021
  const backup = state.issueReducer.issues[id];
5864
6022
  if (!backup) {
5865
6023
  throw new Error(`No issue with id ${id} found in the store`);
5866
6024
  }
5867
6025
  const attachments = Object.values(state.issueReducer.attachments).filter((a) => a.issue === id);
5868
6026
  const attachmentsOfIssue = selectAttachmentsOfIssue(id)(state);
5869
- this.client.store.dispatch(removeIssue(id));
5870
- store.dispatch(addActiveProjectIssuesCount(-1));
5871
- if (attachmentsOfIssue.length > 0) {
5872
- this.client.store.dispatch(removeAttachmentsOfIssue(id));
5873
- }
6027
+ const updatesOfIssue = selectIssueUpdatesOfIssue(id)(state);
6028
+ dispatch(removeIssue(id));
6029
+ dispatch(addActiveProjectIssuesCount(-1));
6030
+ if (attachmentsOfIssue.length > 0)
6031
+ dispatch(removeAttachmentsOfIssue(id));
6032
+ if (updatesOfIssue.length > 0)
6033
+ dispatch(removeIssueUpdates(updatesOfIssue.map(({ offline_id }) => offline_id)));
5874
6034
  try {
5875
6035
  return await this.enqueueRequest({
5876
6036
  description: "Delete issue",
@@ -5880,9 +6040,10 @@ class IssueService extends BaseApiService {
5880
6040
  blocks: []
5881
6041
  });
5882
6042
  } catch (e) {
5883
- this.client.store.dispatch(addIssue(backup));
5884
- this.client.store.dispatch(addIssueAttachments(attachments));
5885
- store.dispatch(addActiveProjectIssuesCount(1));
6043
+ dispatch(addIssue(backup));
6044
+ dispatch(addIssueAttachments(attachments));
6045
+ dispatch(addIssueUpdates(updatesOfIssue));
6046
+ dispatch(addActiveProjectIssuesCount(1));
5886
6047
  throw e;
5887
6048
  }
5888
6049
  }
@@ -6064,6 +6225,7 @@ class MainService extends BaseApiService {
6064
6225
  store.dispatch(setProjectAttachments(project_attachments));
6065
6226
  });
6066
6227
  void this.client.documents.refreshStore();
6228
+ void this.client.issueUpdates.refreshStore();
6067
6229
  }
6068
6230
  store.dispatch(setIsFetchingInitialData(false));
6069
6231
  if (overwrite) {
@@ -6105,7 +6267,6 @@ class ProjectAccessService extends BaseApiService {
6105
6267
  async remove(projectAccess) {
6106
6268
  const { store } = this.client;
6107
6269
  store.dispatch(removeProjectAccess(projectAccess));
6108
- store.dispatch(removeUser(projectAccess.user));
6109
6270
  return this.enqueueRequest({
6110
6271
  description: "Delete project access",
6111
6272
  method: HttpMethod.DELETE,
@@ -7499,6 +7660,7 @@ class OvermapSDK {
7499
7660
  __publicField(this, "organizationAccess", new OrganizationAccessService(this));
7500
7661
  __publicField(this, "issues", new IssueService(this));
7501
7662
  __publicField(this, "issueComments", new IssueCommentService(this));
7663
+ __publicField(this, "issueUpdates", new IssueUpdateService(this));
7502
7664
  __publicField(this, "workspaces", new WorkspaceService(this));
7503
7665
  __publicField(this, "main", new MainService(this));
7504
7666
  __publicField(this, "components", new ComponentService(this));
@@ -15225,6 +15387,8 @@ export {
15225
15387
  IssuePriority,
15226
15388
  IssueService,
15227
15389
  IssueStatus,
15390
+ IssueUpdateChange,
15391
+ IssueUpdateService,
15228
15392
  LicenseLevel,
15229
15393
  LicenseService,
15230
15394
  LicenseStatus,
@@ -15288,6 +15452,8 @@ export {
15288
15452
  addIssue,
15289
15453
  addIssueAttachment,
15290
15454
  addIssueAttachments,
15455
+ addIssueUpdate,
15456
+ addIssueUpdates,
15291
15457
  addLicenses,
15292
15458
  addOrReplaceCategories,
15293
15459
  addOrReplaceIssueComment,
@@ -15447,6 +15613,8 @@ export {
15447
15613
  removeIssue,
15448
15614
  removeIssueAttachment,
15449
15615
  removeIssueComment,
15616
+ removeIssueUpdate,
15617
+ removeIssueUpdates,
15450
15618
  removeOrganizationAccess,
15451
15619
  removeProjectAccess,
15452
15620
  removeProjectAccessesOfProject,
@@ -15548,6 +15716,8 @@ export {
15548
15716
  selectIssueAttachmentMapping,
15549
15717
  selectIssueAttachments,
15550
15718
  selectIssueMapping,
15719
+ selectIssueUpdateMapping,
15720
+ selectIssueUpdatesOfIssue,
15551
15721
  selectIssues,
15552
15722
  selectLatestFormRevision,
15553
15723
  selectLatestRetryTime,
@@ -15644,6 +15814,7 @@ export {
15644
15814
  setIsLoading,
15645
15815
  setIssueAttachments,
15646
15816
  setIssueComments,
15817
+ setIssueUpdates,
15647
15818
  setIssues,
15648
15819
  setLicenses,
15649
15820
  setLoggedIn,