@reltio/components 1.4.2153 → 1.4.2155

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.
@@ -20,7 +20,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
20
20
  };
21
21
  import { useCallback, useEffect, useState, useMemo } from 'react';
22
22
  import { andThen, fromPairs, map, otherwise, pipe, props, uniqBy, prop, propEq, when, always, assocPath, dissocPath, path, pathOr, mergeRight } from 'ramda';
23
- import { createComment as createCommentRequest, createReply as createReplyRequest, getComment as getCommentRequest, getCommentsCount as getCommentsCountRequest, updateComment as updateCommentRequest, updateReply as updateReplyRequest, deleteComment as deleteCommentRequest, deleteReply as deleteReplyRequest, getComments as getCommentsRequest, isTempUri } from '@reltio/mdm-sdk';
23
+ import { createComment as createCommentRequest, createReply as createReplyRequest, getComment as getCommentRequest, getCommentsCount as getCommentsCountRequest, getTotalCommentsCount as getTotalCommentsCountRequest, updateComment as updateCommentRequest, updateReply as updateReplyRequest, deleteComment as deleteCommentRequest, deleteReply as deleteReplyRequest, getComments as getCommentsRequest, isTempUri } from '@reltio/mdm-sdk';
24
24
  import { useMdmCollaborationPath, useMdmEntity, useMdmIsCollaborationEnabled, useMdmTenant } from '../../contexts/MdmModuleContext';
25
25
  var filterReplies = function (replyId, replies) { return replies.filter(function (reply) { return reply.replyId !== replyId; }); };
26
26
  var getUpdatedReplies = function (comment, reply) {
@@ -43,27 +43,49 @@ export var useCollaboration = function (_a) {
43
43
  var _d = useState(null), pageToken = _d[0], setPageToken = _d[1];
44
44
  var _e = useState([]), comments = _e[0], setComments = _e[1];
45
45
  var _f = useState(null), commentsMap = _f[0], setCommentsMap = _f[1];
46
- var _g = useState(null), currentComment = _g[0], setCurrentComment = _g[1];
47
- var _h = useState(false), sending = _h[0], setSending = _h[1];
48
- var _j = useState(false), loading = _j[0], setLoading = _j[1];
49
- var _k = useState({}), collaborationStateMap = _k[0], setCollaborationStateMap = _k[1];
46
+ var _g = useState(null), totalCommentsCount = _g[0], setTotalCommentsCount = _g[1];
47
+ var _h = useState(null), currentComment = _h[0], setCurrentComment = _h[1];
48
+ var _j = useState(false), sending = _j[0], setSending = _j[1];
49
+ var _k = useState(false), loading = _k[0], setLoading = _k[1];
50
+ var _l = useState({}), collaborationStateMap = _l[0], setCollaborationStateMap = _l[1];
50
51
  var addCommentsToCommentsMap = useCallback(function (commentsMap) {
51
52
  setCommentsMap(function (currentCommentsMap) { return (__assign(__assign({}, currentCommentsMap), commentsMap)); });
52
53
  }, []);
53
54
  var entityUri = entity === null || entity === void 0 ? void 0 : entity.uri;
55
+ var isCollaborationEnabledForEntity = isCollaborationEnabled && entityUri && !isTempUri(entityUri);
54
56
  var getCommentsCount = useCallback(function (objectIds, shouldResetCommentsMap) {
55
57
  if (shouldResetCommentsMap === void 0) { shouldResetCommentsMap = false; }
56
- if (isCollaborationEnabled && entityUri && !isTempUri(entityUri)) {
58
+ if (!isCollaborationEnabledForEntity || totalCommentsCount == null) {
59
+ return setCommentsMap(null);
60
+ }
61
+ if (totalCommentsCount === 0) {
62
+ return shouldResetCommentsMap && setCommentsMap({});
63
+ }
64
+ var onError = function (e) {
65
+ console.warn('Collaboration error', e);
66
+ setCommentsMap(null);
67
+ };
68
+ pipe(getCommentsCountRequest, andThen(map(props(['objectId', 'comments']))), andThen(fromPairs), andThen(shouldResetCommentsMap ? setCommentsMap : addCommentsToCommentsMap), otherwise(onError))({ uris: objectIds, tenant: tenant, collaborationPath: collaborationPath });
69
+ }, [addCommentsToCommentsMap, collaborationPath, isCollaborationEnabledForEntity, tenant, totalCommentsCount]);
70
+ var getTotalCommentsCount = useCallback(function () {
71
+ if (isCollaborationEnabledForEntity) {
57
72
  var onError = function (e) {
58
73
  console.warn('Collaboration error', e);
59
- setCommentsMap(null);
74
+ setTotalCommentsCount(null);
60
75
  };
61
- pipe(getCommentsCountRequest, andThen(map(props(['objectId', 'comments']))), andThen(fromPairs), andThen(shouldResetCommentsMap ? setCommentsMap : addCommentsToCommentsMap), otherwise(onError))({ uris: objectIds, tenant: tenant, collaborationPath: collaborationPath });
76
+ pipe(getTotalCommentsCountRequest, andThen(prop('total')), andThen(setTotalCommentsCount), otherwise(onError))({
77
+ relatedObjectUri: entityUri,
78
+ collaborationPath: collaborationPath,
79
+ tenant: tenant
80
+ });
62
81
  }
63
82
  else {
64
- setCommentsMap(null);
83
+ setTotalCommentsCount(null);
65
84
  }
66
- }, [addCommentsToCommentsMap, collaborationPath, entityUri, isCollaborationEnabled, tenant]);
85
+ }, [isCollaborationEnabledForEntity, collaborationPath, entityUri, tenant]);
86
+ useEffect(function () {
87
+ getTotalCommentsCount();
88
+ }, [getTotalCommentsCount]);
67
89
  useEffect(function () {
68
90
  getCommentsCount(objectIds, true);
69
91
  }, [objectIds, getCommentsCount]);
@@ -95,6 +117,7 @@ export var useCollaboration = function (_a) {
95
117
  return __assign(__assign({}, prevCommentsMap), (_a = {}, _a[uri] = __spreadArray(__spreadArray([], (prevCommentsMap[uri] || []), true), [{ commentId: comment.commentId, replies: 0, status: 'open' }], false), _a));
96
118
  });
97
119
  setComments(function (prevComments) { return __spreadArray([comment], prevComments, true); });
120
+ setTotalCommentsCount(function (prevCount) { return (prevCount || 0) + 1; });
98
121
  };
99
122
  var updateCommentInState = function (comment) {
100
123
  setCurrentComment(comment);
@@ -110,6 +133,7 @@ export var useCollaboration = function (_a) {
110
133
  setComments(function (prevComments) {
111
134
  return prevComments.filter(function (comment) { return comment.commentId !== commentId; });
112
135
  });
136
+ setTotalCommentsCount(function (prevCount) { return Math.max((prevCount || 0) - 1, 0); });
113
137
  };
114
138
  var createComment = useCallback(function (_a) {
115
139
  var content = _a.content, namedUsers = _a.namedUsers, objectType = _a.objectType, uri = _a.uri, relatedObjectUris = _a.relatedObjectUris;
@@ -195,6 +219,12 @@ export var useCollaboration = function (_a) {
195
219
  return comment;
196
220
  });
197
221
  });
222
+ if (isDeleteReply) {
223
+ setTotalCommentsCount(function (prevCount) { return Math.max((prevCount || 0) - 1, 0); });
224
+ }
225
+ else {
226
+ setTotalCommentsCount(function (prevCount) { return (prevCount || 0) + 1; });
227
+ }
198
228
  }, []);
199
229
  var deleteReply = useCallback(function (_a) {
200
230
  var uri = _a.uri, commentId = _a.commentId, reply = _a.reply;
@@ -289,7 +319,8 @@ export var useCollaboration = function (_a) {
289
319
  resolveThread: resolveThread,
290
320
  sending: sending,
291
321
  deleteReply: deleteReply,
292
- editReply: editReply
322
+ editReply: editReply,
323
+ totalCommentsCount: totalCommentsCount
293
324
  }); }, [
294
325
  clearCurrentComment,
295
326
  comments,
@@ -312,6 +343,7 @@ export var useCollaboration = function (_a) {
312
343
  resolveThread,
313
344
  sending,
314
345
  deleteReply,
315
- editReply
346
+ editReply,
347
+ totalCommentsCount
316
348
  ]);
317
349
  };