@reltio/components 1.4.2155 → 1.4.2157

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.
Files changed (71) hide show
  1. package/BarChart/helpers.js +3 -0
  2. package/ChartLegend/styles.js +2 -1
  3. package/ChartTooltip/styles.js +2 -1
  4. package/CollaborationItem/components/CommentTarget/styles.js +2 -1
  5. package/ComplexAttributeLabel/styles.js +2 -1
  6. package/DefaultCellValueRenderer/styles.js +1 -1
  7. package/EditModeComplexAttribute/styles.js +2 -1
  8. package/EntitySelector/components/EntityOption/styles.js +1 -1
  9. package/HOCs/withFilter/components/FilterChip/styles.js +1 -1
  10. package/HOCs/withReactSelectMuiSkin/styles.js +2 -1
  11. package/HierarchyNodeTitle/styles.js +1 -1
  12. package/InlineSimpleAttribute/styles.js +2 -1
  13. package/PivotingTooltip/components/PivotingTooltipContent/styles.js +2 -1
  14. package/PivotingTooltip/styles.js +2 -1
  15. package/ProfileBand/styles.js +4 -1
  16. package/ProfileCard/components/ProfileCardContent/styles.js +2 -2
  17. package/ProfilesList/styles.js +6 -3
  18. package/ReadOnlyComplexAttribute/styles.js +2 -1
  19. package/ScreenProfileBand/ScreenProfileBand.test.js +1 -1
  20. package/SimpleAttribute/styles.js +2 -1
  21. package/TableWithBars/components/AttributeCellRenderer/styles.js +1 -1
  22. package/TypeaheadEditor/styles.js +2 -1
  23. package/ValueChip/styles.js +1 -1
  24. package/cjs/BarChart/helpers.js +3 -0
  25. package/cjs/ChartLegend/styles.js +2 -1
  26. package/cjs/ChartTooltip/styles.js +2 -1
  27. package/cjs/CollaborationItem/components/CommentTarget/styles.js +2 -1
  28. package/cjs/ComplexAttributeLabel/styles.js +2 -1
  29. package/cjs/DefaultCellValueRenderer/styles.js +1 -1
  30. package/cjs/EditModeComplexAttribute/styles.js +2 -1
  31. package/cjs/EntitySelector/components/EntityOption/styles.js +1 -1
  32. package/cjs/HOCs/withFilter/components/FilterChip/styles.js +1 -1
  33. package/cjs/HOCs/withReactSelectMuiSkin/styles.js +2 -1
  34. package/cjs/HierarchyNodeTitle/styles.js +1 -1
  35. package/cjs/InlineSimpleAttribute/styles.js +2 -1
  36. package/cjs/PivotingTooltip/components/PivotingTooltipContent/styles.js +2 -1
  37. package/cjs/PivotingTooltip/styles.js +2 -1
  38. package/cjs/ProfileBand/styles.js +4 -1
  39. package/cjs/ProfileCard/components/ProfileCardContent/styles.js +2 -2
  40. package/cjs/ProfilesList/styles.js +6 -3
  41. package/cjs/ReadOnlyComplexAttribute/styles.js +2 -1
  42. package/cjs/ScreenProfileBand/ScreenProfileBand.test.js +1 -1
  43. package/cjs/SimpleAttribute/styles.js +2 -1
  44. package/cjs/TableWithBars/components/AttributeCellRenderer/styles.js +1 -1
  45. package/cjs/TypeaheadEditor/styles.js +2 -1
  46. package/cjs/ValueChip/styles.js +1 -1
  47. package/cjs/constants/theme.d.ts +5 -0
  48. package/cjs/constants/theme.js +5 -0
  49. package/cjs/features/activity-log/ActivitiesFactory/components/SimpleActivity/styles.js +2 -1
  50. package/cjs/features/activity-log/EntityObject/styles.js +1 -0
  51. package/cjs/features/activity-log/Field/styles.js +2 -1
  52. package/cjs/features/activity-log/PotentialMatchRecord/components/PotentialMatchField/styles.js +2 -1
  53. package/cjs/features/activity-log/RelationObject/styles.js +2 -1
  54. package/cjs/features/workflow/AttributesChanges/components/DiffRenderer/styles.js +2 -1
  55. package/cjs/features/workflow/AttributesChanges/styles.js +2 -1
  56. package/cjs/hooks/useCollaboration/useCollaboration.d.ts +2 -1
  57. package/cjs/hooks/useCollaboration/useCollaboration.js +24 -18
  58. package/cjs/hooks/useCollaboration/useCollaboration.test.js +112 -171
  59. package/constants/theme.d.ts +5 -0
  60. package/constants/theme.js +5 -0
  61. package/features/activity-log/ActivitiesFactory/components/SimpleActivity/styles.js +2 -1
  62. package/features/activity-log/EntityObject/styles.js +1 -0
  63. package/features/activity-log/Field/styles.js +2 -1
  64. package/features/activity-log/PotentialMatchRecord/components/PotentialMatchField/styles.js +2 -1
  65. package/features/activity-log/RelationObject/styles.js +2 -1
  66. package/features/workflow/AttributesChanges/components/DiffRenderer/styles.js +2 -1
  67. package/features/workflow/AttributesChanges/styles.js +2 -1
  68. package/hooks/useCollaboration/useCollaboration.d.ts +2 -1
  69. package/hooks/useCollaboration/useCollaboration.js +24 -18
  70. package/hooks/useCollaboration/useCollaboration.test.js +112 -171
  71. package/package.json +2 -2
@@ -12,7 +12,8 @@ exports.useStyles = (0, styles_1.makeStyles)(function (theme) { return ({
12
12
  color: theme.palette.primary.main,
13
13
  fontSize: '12px',
14
14
  letterSpacing: 0,
15
- lineHeight: '16px'
15
+ lineHeight: '16px',
16
+ whiteSpace: 'break-spaces'
16
17
  },
17
18
  disabledLink: {
18
19
  pointerEvents: 'none',
@@ -19,7 +19,8 @@ exports.useStyles = (0, styles_1.makeStyles)(function (theme) { return ({
19
19
  label: {
20
20
  fontSize: '12px',
21
21
  letterSpacing: 0,
22
- lineHeight: '16px'
22
+ lineHeight: '16px',
23
+ whiteSpace: 'break-spaces'
23
24
  },
24
25
  showMoreLink: {
25
26
  marginTop: '8px'
@@ -3,8 +3,9 @@ type Props = {
3
3
  objectIds?: string[];
4
4
  objectTypes?: CollaborationObjectTypes[];
5
5
  enabled?: boolean;
6
+ needsTotalCount?: boolean;
6
7
  };
7
- export declare const useCollaboration: ({ objectIds, objectTypes, enabled }: Props) => {
8
+ export declare const useCollaboration: ({ objectIds, objectTypes, enabled, needsTotalCount }: Props) => {
8
9
  clearCurrentComment: () => void;
9
10
  comments: Comment[];
10
11
  commentsMap: CommentsMap;
@@ -38,19 +38,19 @@ var getUpdatedReplies = function (comment, reply) {
38
38
  var defaultObjectIds = [];
39
39
  var catchErrorInRequest = function (e) { return console.warn('Collaboration error', e); };
40
40
  var useCollaboration = function (_a) {
41
- var _b = _a.objectIds, objectIds = _b === void 0 ? defaultObjectIds : _b, objectTypes = _a.objectTypes, _c = _a.enabled, enabled = _c === void 0 ? true : _c;
41
+ var _b = _a.objectIds, objectIds = _b === void 0 ? defaultObjectIds : _b, objectTypes = _a.objectTypes, _c = _a.enabled, enabled = _c === void 0 ? true : _c, _d = _a.needsTotalCount, needsTotalCount = _d === void 0 ? false : _d;
42
42
  var entity = (0, MdmModuleContext_1.useMdmEntity)();
43
43
  var tenant = (0, MdmModuleContext_1.useMdmTenant)();
44
44
  var collaborationPath = (0, MdmModuleContext_1.useMdmCollaborationPath)();
45
45
  var isCollaborationEnabled = (0, MdmModuleContext_1.useMdmIsCollaborationEnabled)() && enabled;
46
- var _d = (0, react_1.useState)(null), pageToken = _d[0], setPageToken = _d[1];
47
- var _e = (0, react_1.useState)([]), comments = _e[0], setComments = _e[1];
48
- var _f = (0, react_1.useState)(null), commentsMap = _f[0], setCommentsMap = _f[1];
49
- var _g = (0, react_1.useState)(null), totalCommentsCount = _g[0], setTotalCommentsCount = _g[1];
50
- var _h = (0, react_1.useState)(null), currentComment = _h[0], setCurrentComment = _h[1];
51
- var _j = (0, react_1.useState)(false), sending = _j[0], setSending = _j[1];
52
- var _k = (0, react_1.useState)(false), loading = _k[0], setLoading = _k[1];
53
- var _l = (0, react_1.useState)({}), collaborationStateMap = _l[0], setCollaborationStateMap = _l[1];
46
+ var _e = (0, react_1.useState)(null), pageToken = _e[0], setPageToken = _e[1];
47
+ var _f = (0, react_1.useState)([]), comments = _f[0], setComments = _f[1];
48
+ var _g = (0, react_1.useState)(null), commentsMap = _g[0], setCommentsMap = _g[1];
49
+ var _h = (0, react_1.useState)(null), totalCommentsCount = _h[0], setTotalCommentsCount = _h[1];
50
+ var _j = (0, react_1.useState)(null), currentComment = _j[0], setCurrentComment = _j[1];
51
+ var _k = (0, react_1.useState)(false), sending = _k[0], setSending = _k[1];
52
+ var _l = (0, react_1.useState)(false), loading = _l[0], setLoading = _l[1];
53
+ var _m = (0, react_1.useState)({}), collaborationStateMap = _m[0], setCollaborationStateMap = _m[1];
54
54
  var addCommentsToCommentsMap = (0, react_1.useCallback)(function (commentsMap) {
55
55
  setCommentsMap(function (currentCommentsMap) { return (__assign(__assign({}, currentCommentsMap), commentsMap)); });
56
56
  }, []);
@@ -58,18 +58,16 @@ var useCollaboration = function (_a) {
58
58
  var isCollaborationEnabledForEntity = isCollaborationEnabled && entityUri && !(0, mdm_sdk_1.isTempUri)(entityUri);
59
59
  var getCommentsCount = (0, react_1.useCallback)(function (objectIds, shouldResetCommentsMap) {
60
60
  if (shouldResetCommentsMap === void 0) { shouldResetCommentsMap = false; }
61
- if (!isCollaborationEnabledForEntity || totalCommentsCount == null) {
62
- return setCommentsMap(null);
63
- }
64
- if (totalCommentsCount === 0) {
65
- return shouldResetCommentsMap && setCommentsMap({});
61
+ if (!isCollaborationEnabledForEntity) {
62
+ setCommentsMap(null);
63
+ return;
66
64
  }
67
65
  var onError = function (e) {
68
66
  console.warn('Collaboration error', e);
69
67
  setCommentsMap(null);
70
68
  };
71
69
  (0, ramda_1.pipe)(mdm_sdk_1.getCommentsCount, (0, ramda_1.andThen)((0, ramda_1.map)((0, ramda_1.props)(['objectId', 'comments']))), (0, ramda_1.andThen)(ramda_1.fromPairs), (0, ramda_1.andThen)(shouldResetCommentsMap ? setCommentsMap : addCommentsToCommentsMap), (0, ramda_1.otherwise)(onError))({ uris: objectIds, tenant: tenant, collaborationPath: collaborationPath });
72
- }, [addCommentsToCommentsMap, collaborationPath, isCollaborationEnabledForEntity, tenant, totalCommentsCount]);
70
+ }, [addCommentsToCommentsMap, collaborationPath, isCollaborationEnabledForEntity, tenant]);
73
71
  var getTotalCommentsCount = (0, react_1.useCallback)(function () {
74
72
  if (isCollaborationEnabledForEntity) {
75
73
  var onError = function (e) {
@@ -87,8 +85,10 @@ var useCollaboration = function (_a) {
87
85
  }
88
86
  }, [isCollaborationEnabledForEntity, collaborationPath, entityUri, tenant]);
89
87
  (0, react_1.useEffect)(function () {
90
- getTotalCommentsCount();
91
- }, [getTotalCommentsCount]);
88
+ if (needsTotalCount) {
89
+ getTotalCommentsCount();
90
+ }
91
+ }, [getTotalCommentsCount, needsTotalCount]);
92
92
  (0, react_1.useEffect)(function () {
93
93
  getCommentsCount(objectIds, true);
94
94
  }, [objectIds, getCommentsCount]);
@@ -127,16 +127,22 @@ var useCollaboration = function (_a) {
127
127
  setComments((0, ramda_1.map)((0, ramda_1.when)((0, ramda_1.propEq)('commentId', comment.commentId), (0, ramda_1.always)(comment))));
128
128
  };
129
129
  var deleteCommentFromState = function (commentId, uri) {
130
+ var repliesCountFromComments;
131
+ var repliesCountFromCommentsMap;
130
132
  setCurrentComment(null);
131
133
  setCommentsMap(function (prevCommentsMap) {
132
134
  var _a;
135
+ var _b, _c;
136
+ repliesCountFromCommentsMap = (_c = (_b = prevCommentsMap === null || prevCommentsMap === void 0 ? void 0 : prevCommentsMap[uri]) === null || _b === void 0 ? void 0 : _b.find(function (c) { return c.commentId === commentId; })) === null || _c === void 0 ? void 0 : _c.replies;
133
137
  var comments = prevCommentsMap[uri] || [];
134
138
  return __assign(__assign({}, prevCommentsMap), (_a = {}, _a[uri] = comments.filter(function (c) { return c.commentId !== commentId; }), _a));
135
139
  });
136
140
  setComments(function (prevComments) {
141
+ var _a;
142
+ repliesCountFromComments = (_a = prevComments.find(function (comment) { return comment.commentId === commentId; })) === null || _a === void 0 ? void 0 : _a.replies.length;
137
143
  return prevComments.filter(function (comment) { return comment.commentId !== commentId; });
138
144
  });
139
- setTotalCommentsCount(function (prevCount) { return Math.max((prevCount || 0) - 1, 0); });
145
+ setTotalCommentsCount(function (prevCount) { var _a; return Math.max((prevCount || 0) - (1 + ((_a = repliesCountFromComments !== null && repliesCountFromComments !== void 0 ? repliesCountFromComments : repliesCountFromCommentsMap) !== null && _a !== void 0 ? _a : 0)), 0); });
140
146
  };
141
147
  var createComment = (0, react_1.useCallback)(function (_a) {
142
148
  var content = _a.content, namedUsers = _a.namedUsers, objectType = _a.objectType, uri = _a.uri, relatedObjectUris = _a.relatedObjectUris;
@@ -97,31 +97,6 @@ describe('useCollaboration behaviour', function () {
97
97
  expect(mdm_sdk_1.getCommentsCount).not.toHaveBeenCalled();
98
98
  expect(mdm_sdk_1.getTotalCommentsCount).not.toHaveBeenCalled();
99
99
  });
100
- it('should not call getCommentsCount if totalCommentsCount is 0', function () { return __awaiter(void 0, void 0, void 0, function () {
101
- var result;
102
- return __generator(this, function (_a) {
103
- switch (_a.label) {
104
- case 0:
105
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 0 });
106
- result = setUp().result;
107
- return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
108
- return __generator(this, function (_a) {
109
- switch (_a.label) {
110
- case 0: return [4 /*yield*/, Promise.resolve()];
111
- case 1:
112
- _a.sent();
113
- return [2 /*return*/];
114
- }
115
- });
116
- }); })];
117
- case 1:
118
- _a.sent();
119
- expect(mdm_sdk_1.getCommentsCount).not.toHaveBeenCalled();
120
- expect(result.current.commentsMap).toEqual({});
121
- return [2 /*return*/];
122
- }
123
- });
124
- }); });
125
100
  it('should call getCommentsCount if collaboration is enabled and uris is undefined and update commentsMap value', function () { return __awaiter(void 0, void 0, void 0, function () {
126
101
  var result;
127
102
  return __generator(this, function (_a) {
@@ -152,7 +127,7 @@ describe('useCollaboration behaviour', function () {
152
127
  }
153
128
  });
154
129
  }); });
155
- it('should call getCommentsCount if collaboration is enabled and totalCommentsCount is more then 0 and update commentsMap value', function () { return __awaiter(void 0, void 0, void 0, function () {
130
+ it('should call getCommentsCount if collaboration is enabled and update commentsMap value', function () { return __awaiter(void 0, void 0, void 0, function () {
156
131
  var comments, result;
157
132
  return __generator(this, function (_a) {
158
133
  switch (_a.label) {
@@ -162,8 +137,12 @@ describe('useCollaboration behaviour', function () {
162
137
  { commentId: 'id2', status: 'open', replies: 2 }
163
138
  ];
164
139
  mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: comments }]);
165
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 2 });
166
140
  result = setUp({ props: { objectIds: ['uri1'] } }).result;
141
+ expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
142
+ uris: ['uri1'],
143
+ tenant: 'alenat',
144
+ collaborationPath: defaultMdmValues.collaborationPath
145
+ });
167
146
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
168
147
  return __generator(this, function (_a) {
169
148
  switch (_a.label) {
@@ -176,24 +155,19 @@ describe('useCollaboration behaviour', function () {
176
155
  }); })];
177
156
  case 1:
178
157
  _a.sent();
179
- expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
180
- uris: ['uri1'],
181
- tenant: 'alenat',
182
- collaborationPath: defaultMdmValues.collaborationPath
183
- });
184
158
  expect(result.current.commentsMap).toEqual({ uri1: comments });
185
159
  return [2 /*return*/];
186
160
  }
187
161
  });
188
162
  }); });
189
- it('should set commentsMap value as null in case of unsuccessful getCommentsCount request', function () { return __awaiter(void 0, void 0, void 0, function () {
163
+ it('should set commentsMap value as null in case of unsuccessful request', function () { return __awaiter(void 0, void 0, void 0, function () {
190
164
  var result;
191
165
  return __generator(this, function (_a) {
192
166
  switch (_a.label) {
193
167
  case 0:
194
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 1 });
195
- mdm_sdk_1.getCommentsCount.mockRejectedValueOnce(new Error('Fail'));
168
+ mdm_sdk_1.getCommentsCount.mockRejectedValueOnce(null);
196
169
  result = setUp().result;
170
+ expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalled();
197
171
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
198
172
  return __generator(this, function (_a) {
199
173
  switch (_a.label) {
@@ -206,7 +180,6 @@ describe('useCollaboration behaviour', function () {
206
180
  }); })];
207
181
  case 1:
208
182
  _a.sent();
209
- expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalled();
210
183
  expect(result.current.commentsMap).toBe(null);
211
184
  return [2 /*return*/];
212
185
  }
@@ -228,20 +201,7 @@ describe('useCollaboration behaviour', function () {
228
201
  return Promise.resolve([{ objectId: 'uri2', comments: secondComments }]);
229
202
  }
230
203
  });
231
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 3 });
232
204
  result = setUp({ props: { objectIds: ['uri1'] } }).result;
233
- return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
234
- return __generator(this, function (_a) {
235
- switch (_a.label) {
236
- case 0: return [4 /*yield*/, Promise.resolve()];
237
- case 1:
238
- _a.sent();
239
- return [2 /*return*/];
240
- }
241
- });
242
- }); })];
243
- case 1:
244
- _a.sent();
245
205
  expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
246
206
  uris: ['uri1'],
247
207
  tenant: 'alenat',
@@ -253,7 +213,7 @@ describe('useCollaboration behaviour', function () {
253
213
  return [2 /*return*/];
254
214
  });
255
215
  }); })];
256
- case 2:
216
+ case 1:
257
217
  _a.sent();
258
218
  expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
259
219
  uris: ['uri2'],
@@ -281,20 +241,7 @@ describe('useCollaboration behaviour', function () {
281
241
  return Promise.resolve([{ objectId: 'uri2', comments: secondComments }]);
282
242
  }
283
243
  });
284
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 3 });
285
244
  _a = setUp({ props: { objectIds: ['uri1'] } }), result = _a.result, rerender = _a.rerender;
286
- return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
287
- return __generator(this, function (_a) {
288
- switch (_a.label) {
289
- case 0: return [4 /*yield*/, Promise.resolve()];
290
- case 1:
291
- _a.sent();
292
- return [2 /*return*/];
293
- }
294
- });
295
- }); })];
296
- case 1:
297
- _b.sent();
298
245
  expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
299
246
  uris: ['uri1'],
300
247
  tenant: 'alenat',
@@ -312,7 +259,7 @@ describe('useCollaboration behaviour', function () {
312
259
  }
313
260
  });
314
261
  }); })];
315
- case 2:
262
+ case 1:
316
263
  _b.sent();
317
264
  expect(mdm_sdk_1.getCommentsCount).toHaveBeenCalledWith({
318
265
  uris: ['uri2'],
@@ -449,12 +396,7 @@ describe('useCollaboration behaviour', function () {
449
396
  replies: 2
450
397
  }
451
398
  ];
452
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 3 });
453
- mdm_sdk_1.getCommentsCount
454
- .mockResolvedValueOnce([{ objectId: 'uri1', comments: comments }])
455
- .mockResolvedValueOnce([
456
- { objectId: 'uri1', comments: __spreadArray(__spreadArray([], comments, true), [{ commentId: 'commentId', replies: 0, status: 'open' }], false) }
457
- ]);
399
+ mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: comments }]);
458
400
  mdm_sdk_1.createComment.mockResolvedValueOnce([{ commentId: 'commentId' }]);
459
401
  result = setUp().result;
460
402
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -472,16 +414,33 @@ describe('useCollaboration behaviour', function () {
472
414
  expect(result.current.commentsMap).toEqual({ uri1: comments });
473
415
  expect(result.current.currentComment).toBe(null);
474
416
  expect(result.current.sending).toBe(false);
417
+ (0, react_hooks_1.act)(function () {
418
+ result.current.createComment({
419
+ content: 'content',
420
+ namedUsers: [],
421
+ objectType: 'entity',
422
+ relatedObjectUris: ['uri1'],
423
+ uri: 'uri1'
424
+ });
425
+ });
426
+ expect(result.current.sending).toBe(true);
427
+ expect(mdm_sdk_1.createComment).toHaveBeenCalledWith({
428
+ collaborationPath: '123',
429
+ tenant: 'alenat',
430
+ data: {
431
+ objectId: 'uri1',
432
+ content: 'content',
433
+ relatedObjectUris: ['uri1'],
434
+ objectType: 'entity',
435
+ visibility: 'public',
436
+ namedUsers: [],
437
+ permanentLink: 'https://tst-01.reltio.com/nui/alenat/profile?entityUri=entities%2F2jWtLtNc&commentId=%7BcommentId%7D'
438
+ }
439
+ });
475
440
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
476
441
  return __generator(this, function (_a) {
477
442
  switch (_a.label) {
478
- case 0: return [4 /*yield*/, result.current.createComment({
479
- content: 'content',
480
- namedUsers: [],
481
- objectType: 'entity',
482
- relatedObjectUris: ['uri1'],
483
- uri: 'uri1'
484
- })];
443
+ case 0: return [4 /*yield*/, Promise.resolve()];
485
444
  case 1:
486
445
  _a.sent();
487
446
  return [2 /*return*/];
@@ -498,23 +457,15 @@ describe('useCollaboration behaviour', function () {
498
457
  uri1: __spreadArray(__spreadArray([], comments, true), [{ commentId: 'commentId', replies: 0, status: 'open' }], false)
499
458
  });
500
459
  mdm_sdk_1.createComment.mockResolvedValueOnce([{ commentId: 'commentId2' }]);
501
- mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([
502
- { objectId: 'uri1', comments: __spreadArray(__spreadArray([], comments, true), [{ commentId: 'commentId', replies: 0, status: 'open' }], false) },
503
- { objectId: 'uri2', comments: [{ commentId: 'commentId2', replies: 0, status: 'open' }] }
504
- ]);
505
460
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
506
461
  return __generator(this, function (_a) {
507
- switch (_a.label) {
508
- case 0: return [4 /*yield*/, result.current.createComment({
509
- content: 'content',
510
- namedUsers: [],
511
- objectType: 'entity',
512
- uri: 'uri2'
513
- })];
514
- case 1:
515
- _a.sent();
516
- return [2 /*return*/];
517
- }
462
+ result.current.createComment({
463
+ content: 'content',
464
+ namedUsers: [],
465
+ objectType: 'entity',
466
+ uri: 'uri2'
467
+ });
468
+ return [2 /*return*/];
518
469
  });
519
470
  }); })];
520
471
  case 3:
@@ -543,14 +494,7 @@ describe('useCollaboration behaviour', function () {
543
494
  { commentId: 'id1', content: 'first comment', status: 'open', replies: [] },
544
495
  { commentId: 'id2', content: 'second comment', status: 'open', replies: [] }
545
496
  ];
546
- mdm_sdk_1.getCommentsCount
547
- .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
548
- .mockResolvedValueOnce([
549
- { objectId: 'uri1', comments: [commentsCount[0], { commentId: 'id2', status: 'open', replies: 3 }] }
550
- ])
551
- .mockResolvedValueOnce([
552
- { objectId: 'uri1', comments: [commentsCount[0], { commentId: 'id2', status: 'resolved', replies: 4 }] }
553
- ]);
497
+ mdm_sdk_1.getCommentsCount.mockResolvedValue([{ objectId: 'uri1', comments: commentsCount }]);
554
498
  mdm_sdk_1.getComments.mockResolvedValue({ items: comments });
555
499
  mdm_sdk_1.getComment.mockResolvedValueOnce({
556
500
  commentId: 'id2',
@@ -683,11 +627,7 @@ describe('useCollaboration behaviour', function () {
683
627
  { commentId: 'id1', status: 'open', content: 'first comment', replies: [] },
684
628
  { commentId: 'id2', status: 'open', content: 'second comment', replies: [] }
685
629
  ];
686
- mdm_sdk_1.getCommentsCount
687
- .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
688
- .mockResolvedValueOnce([
689
- { objectId: 'uri1', comments: [commentsCount[0], { commentId: 'id2', status: 'resolved', replies: 3 }] }
690
- ]);
630
+ mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
691
631
  mdm_sdk_1.getComment.mockResolvedValueOnce({ commentId: 'id2', replies: [] });
692
632
  mdm_sdk_1.getComments.mockResolvedValue({ items: comments });
693
633
  mdm_sdk_1.createReply.mockResolvedValueOnce([{ content: '', action: 'resolve' }]);
@@ -760,11 +700,7 @@ describe('useCollaboration behaviour', function () {
760
700
  { commentId: 'id1', status: 'open', content: 'first comment', replies: [] },
761
701
  { commentId: 'id2', status: 'open', content: 'second comment', replies: [] }
762
702
  ];
763
- mdm_sdk_1.getCommentsCount
764
- .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
765
- .mockResolvedValueOnce([
766
- { objectId: 'uri1', comments: [commentsCount[0], { commentId: 'id2', status: 'open', replies: 3 }] }
767
- ]);
703
+ mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
768
704
  mdm_sdk_1.getComment.mockResolvedValueOnce({ commentId: 'id2', replies: [] });
769
705
  mdm_sdk_1.getComments.mockResolvedValue({
770
706
  items: comments
@@ -937,12 +873,9 @@ describe('useCollaboration behaviour', function () {
937
873
  { commentId: 'id1', content: 'text 1', status: 'open', replies: [] },
938
874
  { commentId: 'id2', content: 'text2', status: 'open', replies: [] }
939
875
  ];
940
- expectedCommentsCount = [{ commentId: 'id2', status: 'open', replies: 0 }];
941
- expectedComments = [{ commentId: 'id2', content: 'text2', status: 'open', replies: [] }];
942
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 2 });
943
- mdm_sdk_1.getCommentsCount
944
- .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
945
- .mockResolvedValueOnce([{ objectId: 'uri1', comments: expectedCommentsCount }]);
876
+ expectedCommentsCount = commentsCount.slice(1);
877
+ expectedComments = comments.slice(1);
878
+ mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
946
879
  mdm_sdk_1.getComments.mockResolvedValueOnce({ items: comments });
947
880
  mdm_sdk_1.deleteComment.mockResolvedValueOnce('');
948
881
  result = setUp().result;
@@ -957,20 +890,28 @@ describe('useCollaboration behaviour', function () {
957
890
  expect(result.current.comments).toEqual(comments);
958
891
  expect(result.current.commentsMap).toEqual({ uri1: commentsCount });
959
892
  expect(result.current.sending).toBe(false);
893
+ (0, react_hooks_1.act)(function () {
894
+ result.current.deleteComment({ commentId: 'id1', uri: 'uri1' });
895
+ });
896
+ expect(result.current.sending).toBe(true);
897
+ expect(mdm_sdk_1.deleteComment).toHaveBeenCalledWith({
898
+ collaborationPath: '123',
899
+ tenant: 'alenat',
900
+ commentId: 'id1'
901
+ });
960
902
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
961
903
  return __generator(this, function (_a) {
962
- result.current.deleteComment({ commentId: 'id1', uri: 'uri1' });
963
- return [2 /*return*/];
904
+ switch (_a.label) {
905
+ case 0: return [4 /*yield*/, Promise.resolve()];
906
+ case 1:
907
+ _a.sent();
908
+ return [2 /*return*/];
909
+ }
964
910
  });
965
911
  }); })];
966
912
  case 2:
967
913
  _a.sent();
968
914
  expect(result.current.sending).toBe(false);
969
- expect(mdm_sdk_1.deleteComment).toHaveBeenCalledWith({
970
- collaborationPath: '123',
971
- tenant: 'alenat',
972
- commentId: 'id1'
973
- });
974
915
  expect(result.current.commentsMap).toEqual({
975
916
  uri1: expectedCommentsCount
976
917
  });
@@ -988,23 +929,13 @@ describe('useCollaboration behaviour', function () {
988
929
  { commentId: 'id1', status: 'open', replies: 1 },
989
930
  { commentId: 'id2', status: 'open', replies: 2 }
990
931
  ];
991
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: commentsCount.length });
992
- mdm_sdk_1.getCommentsCount
993
- .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
994
- .mockResolvedValueOnce([
995
- { objectId: 'uri1', comments: [commentsCount[0], { commentId: 'id2', status: 'open', replies: 2 }] },
996
- { objectId: 'uri2', comments: [] }
997
- ]);
932
+ mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
998
933
  mdm_sdk_1.createReply.mockResolvedValueOnce([{ content: 'reply message' }]);
999
934
  result = setUp().result;
1000
935
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1001
936
  return __generator(this, function (_a) {
1002
- switch (_a.label) {
1003
- case 0: return [4 /*yield*/, Promise.resolve()];
1004
- case 1:
1005
- _a.sent();
1006
- return [2 /*return*/];
1007
- }
937
+ Promise.resolve();
938
+ return [2 /*return*/];
1008
939
  });
1009
940
  }); })];
1010
941
  case 1:
@@ -1021,9 +952,6 @@ describe('useCollaboration behaviour', function () {
1021
952
  uri: 'uri2'
1022
953
  })];
1023
954
  case 1:
1024
- _a.sent();
1025
- return [4 /*yield*/, Promise.resolve()];
1026
- case 2:
1027
955
  _a.sent();
1028
956
  return [2 /*return*/];
1029
957
  }
@@ -1050,23 +978,14 @@ describe('useCollaboration behaviour', function () {
1050
978
  ];
1051
979
  expectedCommentsCount = [{ commentId: 'id1', status: 'open', replies: 0 }];
1052
980
  expectedComments = [{ commentId: 'id1', content: 'text 1', status: 'open', replies: [] }];
1053
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 2 }).mockResolvedValueOnce({ total: 1 });
1054
- mdm_sdk_1.getCommentsCount
1055
- .mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }])
1056
- .mockResolvedValueOnce([{ objectId: 'uri1', comments: expectedCommentsCount }]);
981
+ mdm_sdk_1.getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
1057
982
  mdm_sdk_1.getComments.mockResolvedValue({ items: comments });
1058
983
  mdm_sdk_1.deleteReply.mockResolvedValueOnce('');
1059
984
  result = setUp().result;
1060
985
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1061
986
  return __generator(this, function (_a) {
1062
- switch (_a.label) {
1063
- case 0:
1064
- result.current.getComments('uri');
1065
- return [4 /*yield*/, Promise.resolve()];
1066
- case 1:
1067
- _a.sent();
1068
- return [2 /*return*/];
1069
- }
987
+ result.current.getComments('uri');
988
+ return [2 /*return*/];
1070
989
  });
1071
990
  }); })];
1072
991
  case 1:
@@ -1074,16 +993,24 @@ describe('useCollaboration behaviour', function () {
1074
993
  expect(result.current.comments).toEqual(comments);
1075
994
  expect(result.current.commentsMap).toEqual({ uri1: commentsCount });
1076
995
  expect(result.current.sending).toBe(false);
996
+ (0, react_hooks_1.act)(function () {
997
+ result.current.deleteReply({
998
+ commentId: 'id1',
999
+ uri: 'uri1',
1000
+ reply: comments[0].replies[0]
1001
+ });
1002
+ });
1003
+ expect(result.current.sending).toBe(true);
1004
+ expect(mdm_sdk_1.deleteReply).toHaveBeenCalledWith({
1005
+ collaborationPath: '123',
1006
+ tenant: 'alenat',
1007
+ commentId: 'id1',
1008
+ replyId: 'replyId1'
1009
+ });
1077
1010
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1078
1011
  return __generator(this, function (_a) {
1079
1012
  switch (_a.label) {
1080
- case 0:
1081
- result.current.deleteReply({
1082
- commentId: 'id1',
1083
- uri: 'uri1',
1084
- reply: comments[0].replies[0]
1085
- });
1086
- return [4 /*yield*/, Promise.resolve()];
1013
+ case 0: return [4 /*yield*/, Promise.resolve()];
1087
1014
  case 1:
1088
1015
  _a.sent();
1089
1016
  return [2 /*return*/];
@@ -1093,12 +1020,6 @@ describe('useCollaboration behaviour', function () {
1093
1020
  case 2:
1094
1021
  _a.sent();
1095
1022
  expect(result.current.sending).toBe(false);
1096
- expect(mdm_sdk_1.deleteReply).toHaveBeenCalledWith({
1097
- collaborationPath: '123',
1098
- tenant: 'alenat',
1099
- commentId: 'id1',
1100
- replyId: 'replyId1'
1101
- });
1102
1023
  expect(result.current.commentsMap).toEqual({
1103
1024
  uri1: expectedCommentsCount
1104
1025
  });
@@ -1130,7 +1051,6 @@ describe('useCollaboration behaviour', function () {
1130
1051
  mdm_sdk_1.updateReply.mockResolvedValueOnce(editedReply);
1131
1052
  mdm_sdk_1.getComment.mockResolvedValueOnce(initialComment);
1132
1053
  mdm_sdk_1.getComments.mockResolvedValueOnce({ items: initialComments });
1133
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 2 });
1134
1054
  result = setUp().result;
1135
1055
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1136
1056
  return __generator(this, function (_a) {
@@ -1187,7 +1107,6 @@ describe('useCollaboration behaviour', function () {
1187
1107
  return __generator(this, function (_a) {
1188
1108
  switch (_a.label) {
1189
1109
  case 0:
1190
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 1 });
1191
1110
  result = setUp().result;
1192
1111
  expect(result.current.getCommentState('attrUri', 'commentUri')).toEqual({});
1193
1112
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -1230,7 +1149,6 @@ describe('useCollaboration behaviour', function () {
1230
1149
  return __generator(this, function (_a) {
1231
1150
  switch (_a.label) {
1232
1151
  case 0:
1233
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 1 });
1234
1152
  result = setUp().result;
1235
1153
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1236
1154
  return __generator(this, function (_a) {
@@ -1267,7 +1185,6 @@ describe('useCollaboration behaviour', function () {
1267
1185
  return __generator(this, function (_a) {
1268
1186
  switch (_a.label) {
1269
1187
  case 0:
1270
- mdm_sdk_1.getTotalCommentsCount.mockResolvedValue({ total: 1 });
1271
1188
  result = setUp().result;
1272
1189
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1273
1190
  return __generator(this, function (_a) {
@@ -1331,13 +1248,37 @@ describe('useCollaboration behaviour', function () {
1331
1248
  expect(result.current.totalCommentsCount).toBe(null);
1332
1249
  expect(mdm_sdk_1.getTotalCommentsCount).not.toHaveBeenCalled();
1333
1250
  });
1334
- it('should call getTotalCommentsCount if collaboration is enabled and update totalCommentsCount value', function () { return __awaiter(void 0, void 0, void 0, function () {
1251
+ it('should not call getTotalCommentsCount and update totalCommentsCount value if collaboration is enabled but needsTotalCount is false', function () { return __awaiter(void 0, void 0, void 0, function () {
1252
+ return __generator(this, function (_a) {
1253
+ switch (_a.label) {
1254
+ case 0:
1255
+ mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 15 });
1256
+ setUp();
1257
+ expect(mdm_sdk_1.getTotalCommentsCount).not.toHaveBeenCalled();
1258
+ return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1259
+ return __generator(this, function (_a) {
1260
+ switch (_a.label) {
1261
+ case 0: return [4 /*yield*/, Promise.resolve()];
1262
+ case 1:
1263
+ _a.sent();
1264
+ return [2 /*return*/];
1265
+ }
1266
+ });
1267
+ }); })];
1268
+ case 1:
1269
+ _a.sent();
1270
+ expect(mdm_sdk_1.getTotalCommentsCount).not.toHaveBeenCalled();
1271
+ return [2 /*return*/];
1272
+ }
1273
+ });
1274
+ }); });
1275
+ it('should call getTotalCommentsCount and update totalCommentsCount value if collaboration is enabled and needsTotalCount is true', function () { return __awaiter(void 0, void 0, void 0, function () {
1335
1276
  var result;
1336
1277
  return __generator(this, function (_a) {
1337
1278
  switch (_a.label) {
1338
1279
  case 0:
1339
1280
  mdm_sdk_1.getTotalCommentsCount.mockResolvedValueOnce({ total: 15 });
1340
- result = setUp().result;
1281
+ result = setUp({ props: { needsTotalCount: true } }).result;
1341
1282
  expect(mdm_sdk_1.getTotalCommentsCount).toHaveBeenCalledWith({
1342
1283
  relatedObjectUri: '1',
1343
1284
  collaborationPath: '123',
@@ -1366,7 +1307,7 @@ describe('useCollaboration behaviour', function () {
1366
1307
  switch (_a.label) {
1367
1308
  case 0:
1368
1309
  mdm_sdk_1.getTotalCommentsCount.mockRejectedValueOnce(new Error('Network error'));
1369
- result = setUp().result;
1310
+ result = setUp({ props: { needsTotalCount: true } }).result;
1370
1311
  expect(mdm_sdk_1.getTotalCommentsCount).toHaveBeenCalled();
1371
1312
  return [4 /*yield*/, (0, react_hooks_1.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
1372
1313
  return __generator(this, function (_a) {