@overmap-ai/core 1.0.48-activity-history.2 → 1.0.48-activity-history.3

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.
package/README.md CHANGED
File without changes
@@ -2144,20 +2144,55 @@ const issueSlice = createSlice({
2144
2144
  setVisibleUserIds: (state, action) => {
2145
2145
  state.visibleUserIds = [...new Set(action.payload)];
2146
2146
  },
2147
- setIssueComments: (state, action) => {
2147
+ // Comments
2148
+ addIssueComment: (state, action) => {
2149
+ if (action.payload.offline_id in state.comments) {
2150
+ throw new Error(
2151
+ `Tried to add issue comment with offline_id: ${action.payload.offline_id} that already exists`
2152
+ );
2153
+ }
2154
+ state.comments[action.payload.offline_id] = action.payload;
2155
+ },
2156
+ addIssueComments: (state, action) => {
2157
+ for (const comment of action.payload) {
2158
+ if (comment.offline_id in state.comments) {
2159
+ throw new Error(
2160
+ `Tried to add issue comment with offline_id: ${comment.offline_id} that already exists`
2161
+ );
2162
+ }
2163
+ }
2148
2164
  for (const comment of action.payload) {
2149
2165
  state.comments[comment.offline_id] = comment;
2150
2166
  }
2151
2167
  },
2168
+ setIssueComment: (state, action) => {
2169
+ state.comments[action.payload.offline_id] = action.payload;
2170
+ },
2171
+ setIssueComments: (state, action) => {
2172
+ const newComments = {};
2173
+ for (const comment of action.payload) {
2174
+ newComments[comment.offline_id] = comment;
2175
+ }
2176
+ state.comments = newComments;
2177
+ },
2152
2178
  addOrReplaceIssueComment: (state, action) => {
2153
2179
  state.comments[action.payload.offline_id] = action.payload;
2154
2180
  },
2155
2181
  removeIssueComment: (state, action) => {
2156
- if (action.payload in state.comments) {
2157
- delete state.comments[action.payload];
2158
- } else {
2182
+ if (!(action.payload in state.comments)) {
2159
2183
  throw new Error(`Failed to remove issue comment because ID doesn't exist: ${action.payload}`);
2160
2184
  }
2185
+ delete state.comments[action.payload];
2186
+ },
2187
+ removeIssueComments: (state, action) => {
2188
+ for (const commentId of action.payload) {
2189
+ if (!(commentId in state.comments)) {
2190
+ throw new Error(`Failed to remove issue comment because ID doesn't exist: ${commentId}`);
2191
+ }
2192
+ }
2193
+ for (const commentId of action.payload) {
2194
+ delete state.comments[commentId];
2195
+ }
2161
2196
  },
2162
2197
  cleanRecentIssues: (state) => {
2163
2198
  state.recentIssueIds = state.recentIssueIds.filter((recentIssue) => state.issues[recentIssue.offlineId]);
@@ -2196,20 +2231,25 @@ const {
2196
2231
  removeIssueAttachment,
2197
2232
  removeAttachmentsOfIssue,
2198
2233
  removeIssue,
2199
- removeIssueComment,
2200
2234
  removeIssueUpdate,
2201
2235
  removeIssueUpdates,
2202
2236
  removeRecentIssue,
2203
2237
  resetRecentIssues,
2204
2238
  setActiveIssueId,
2205
2239
  setIssueAttachments,
2206
- setIssueComments,
2207
2240
  setIssueUpdates,
2208
2241
  setIssues,
2209
2242
  setVisibleStatuses,
2210
2243
  setVisibleUserIds,
2211
2244
  updateIssueAttachment,
2212
- updateIssue
2245
+ updateIssue,
2246
+ // Commments
2247
+ addIssueComment,
2248
+ addIssueComments,
2249
+ setIssueComment,
2250
+ setIssueComments,
2251
+ removeIssueComment,
2252
+ removeIssueComments
2213
2253
  } = issueSlice.actions;
2214
2254
  const selectIssueMapping = (state) => state.issueReducer.issues;
2215
2255
  const selectRecentIssueIds = (state) => state.issueReducer.recentIssueIds;
@@ -5766,49 +5806,36 @@ class ComponentTypeService extends BaseApiService {
5766
5806
  }
5767
5807
  }
5768
5808
  class IssueCommentService extends BaseApiService {
5809
+ // Omit author and submitted_at since these will always be set internally
5769
5810
  add(comment) {
5770
- const offlinePayload = offline(comment);
5771
- const submittedAt = (/* @__PURE__ */ new Date()).toISOString();
5772
5811
  const { store } = this.client;
5773
- const offlineComment = {
5774
- ...offlinePayload,
5812
+ const offlineComment = offline({
5813
+ ...comment,
5775
5814
  author: store.getState().userReducer.currentUser.id,
5776
- created_at: submittedAt
5777
- };
5778
- store.dispatch(addOrReplaceIssueComment(offlineComment));
5815
+ submitted_at: (/* @__PURE__ */ new Date()).toISOString(),
5816
+ resolved: false
5817
+ });
5818
+ store.dispatch(addIssueComment(offlineComment));
5779
5819
  const promise = this.enqueueRequest({
5780
5820
  description: `${truncate(comment.content, 80)}`,
5781
5821
  method: HttpMethod.POST,
5782
5822
  url: `/issues/${comment.issue}/comment/`,
5783
- payload: { ...offlinePayload, submitted_at: submittedAt },
5823
+ payload: offlineComment,
5784
5824
  blockers: [comment.issue],
5785
- blocks: [offlinePayload.offline_id]
5825
+ blocks: [offlineComment.offline_id]
5826
+ });
5827
+ promise.catch(() => {
5828
+ store.dispatch(removeIssueComment(offlineComment.offline_id));
5786
5829
  });
5787
5830
  return [offlineComment, promise];
5788
5831
  }
5789
- async refreshStore() {
5832
+ update(comment) {
5790
5833
  const { store } = this.client;
5791
- const result = await this.enqueueRequest({
5792
- description: "Get comments",
5793
- method: HttpMethod.GET,
5794
- // TODO: Choose between /issues/comments/in-project/${projectId}/ and /projects/${projectId}/issue-comments/
5795
- url: `/projects/${store.getState().projectReducer.activeProjectId}/comments/`,
5796
- blockers: [],
5797
- blocks: []
5798
- });
5799
- let filteredResult = result.filter(onlyUniqueOfflineIds);
5800
- filteredResult = filteredResult.map((comment) => {
5801
- return { ...comment };
5802
- });
5803
- if (result.length !== filteredResult.length) {
5804
- console.error(
5805
- `Received duplicate comments from the API (new length ${filteredResult.length}); filtered in browser.`
5806
- );
5834
+ const commentToUpdate = store.getState().issueReducer.comments[comment.offline_id];
5835
+ if (!commentToUpdate) {
5836
+ throw new Error(`Comment with offline_id ${comment.offline_id} not found in store`);
5807
5837
  }
5808
- store.dispatch(setIssueComments(filteredResult));
5809
- }
5810
- update(comment) {
5811
- this.client.store.dispatch(addOrReplaceIssueComment(comment));
5838
+ store.dispatch(setIssueComment(comment));
5812
5839
  const promise = this.enqueueRequest({
5813
5840
  description: `Edit comment: ${truncate(comment.content, 80)}`,
5814
5841
  method: HttpMethod.PATCH,
@@ -5817,17 +5844,40 @@ class IssueCommentService extends BaseApiService {
5817
5844
  blockers: [comment.issue],
5818
5845
  blocks: [comment.offline_id]
5819
5846
  });
5847
+ promise.catch(() => {
5848
+ store.dispatch(setIssueComment(commentToUpdate));
5849
+ });
5820
5850
  return [comment, promise];
5821
5851
  }
5822
5852
  remove(offline_id) {
5853
+ const commentToRemove = this.client.store.getState().issueReducer.comments[offline_id];
5854
+ if (!commentToRemove) {
5855
+ throw new Error(`Comment with offline_id ${offline_id} not found in store`);
5856
+ }
5823
5857
  this.client.store.dispatch(removeIssueComment(offline_id));
5824
- return this.enqueueRequest({
5858
+ const promise = this.enqueueRequest({
5825
5859
  description: "Delete comment",
5826
5860
  method: HttpMethod.DELETE,
5827
5861
  url: `/issues/comments/${offline_id}/`,
5828
5862
  blockers: [offline_id],
5829
5863
  blocks: []
5830
5864
  });
5865
+ promise.catch(() => {
5866
+ this.client.store.dispatch(addIssueComment(commentToRemove));
5867
+ });
5868
+ return promise;
5869
+ }
5870
+ async refreshStore() {
5871
+ const { store } = this.client;
5872
+ const result = await this.enqueueRequest({
5873
+ description: "Get comments",
5874
+ method: HttpMethod.GET,
5875
+ // TODO: Choose between /issues/comments/in-project/${projectId}/ and /projects/${projectId}/issue-comments/
5876
+ url: `/projects/${store.getState().projectReducer.activeProjectId}/comments/`,
5877
+ blockers: [],
5878
+ blocks: []
5879
+ });
5880
+ store.dispatch(setIssueComments(result));
5831
5881
  }
5832
5882
  }
5833
5883
  class IssueUpdateService extends BaseApiService {
@@ -15484,6 +15534,8 @@ export {
15484
15534
  addIssue,
15485
15535
  addIssueAttachment,
15486
15536
  addIssueAttachments,
15537
+ addIssueComment,
15538
+ addIssueComments,
15487
15539
  addIssueUpdate,
15488
15540
  addIssueUpdates,
15489
15541
  addLicenses,
@@ -15645,6 +15697,7 @@ export {
15645
15697
  removeIssue,
15646
15698
  removeIssueAttachment,
15647
15699
  removeIssueComment,
15700
+ removeIssueComments,
15648
15701
  removeIssueUpdate,
15649
15702
  removeIssueUpdates,
15650
15703
  removeOrganizationAccess,
@@ -15845,6 +15898,7 @@ export {
15845
15898
  setIsImportingProjectFile,
15846
15899
  setIsLoading,
15847
15900
  setIssueAttachments,
15901
+ setIssueComment,
15848
15902
  setIssueComments,
15849
15903
  setIssueUpdates,
15850
15904
  setIssues,