@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.
@@ -118,6 +118,7 @@ var setUp = function (_a) {
118
118
  return (React.createElement(MdmModuleProvider, { values: mdmValues },
119
119
  React.createElement(CollaborationContext.Provider, { value: {
120
120
  commentsMap: {},
121
+ totalCommentsCount: null,
121
122
  currentComment: currentComment,
122
123
  createComment: function () { return Promise.resolve(); },
123
124
  editComment: function () { return Promise.resolve(); },
@@ -126,6 +126,7 @@ describe('Comment tests', function () {
126
126
  };
127
127
  var defaultCollaborationContextValue = {
128
128
  commentsMap: defaultCommentsMap,
129
+ totalCommentsCount: null,
129
130
  currentComment: defaultCurrentComment,
130
131
  createComment: function () { return Promise.resolve(); },
131
132
  editComment: function () { return Promise.resolve(); },
@@ -65,7 +65,7 @@ describe('SendMessageArea tests', function () {
65
65
  };
66
66
  var createCollaborationContext = function (props) {
67
67
  if (props === void 0) { props = {}; }
68
- return __assign({ comments: [], commentsMap: null, currentComment: null, getComment: identity, getComments: function () { return new Promise(identity); }, getCommentsCount: identity, resolveThread: identity, reOpenThread: identity, clearCurrentComment: identity, deleteComment: identity, sending: false, loading: false, pageToken: null, deleteReply: identity, createReply: function () { return new Promise(function (res) { return res(); }); }, createComment: function () { return new Promise(function (res) { return res(); }); }, editComment: function () { return new Promise(function (res) { return res(); }); }, editReply: function () { return new Promise(function (res) { return res(); }); }, getCommentState: function () { return ({}); }, clearCommentState: function () { }, updateCommentState: function () { } }, props);
68
+ return __assign({ comments: [], commentsMap: null, totalCommentsCount: null, currentComment: null, getComment: identity, getComments: function () { return new Promise(identity); }, getCommentsCount: identity, resolveThread: identity, reOpenThread: identity, clearCurrentComment: identity, deleteComment: identity, sending: false, loading: false, pageToken: null, deleteReply: identity, createReply: function () { return new Promise(function (res) { return res(); }); }, createComment: function () { return new Promise(function (res) { return res(); }); }, editComment: function () { return new Promise(function (res) { return res(); }); }, editReply: function () { return new Promise(function (res) { return res(); }); }, getCommentState: function () { return ({}); }, clearCommentState: function () { }, updateCommentState: function () { } }, props);
69
69
  };
70
70
  var createProps = function (comment, extraProps) {
71
71
  if (extraProps === void 0) { extraProps = {}; }
@@ -51,7 +51,7 @@ import { getCommentsCount, getAllUsersForTenant, Mode } from '@reltio/mdm-sdk';
51
51
  import { ScreenProfileBand } from './ScreenProfileBand';
52
52
  import { MdmModuleProvider } from '../contexts/MdmModuleContext';
53
53
  import { ActionsHookProvider } from '../contexts/ActionsHookContext';
54
- jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getCommentsCount: jest.fn(), getAllUsersForTenant: jest.fn() })); });
54
+ jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getCommentsCount: jest.fn(), getTotalCommentsCount: jest.fn(function () { return Promise.resolve({ total: 1 }); }), getAllUsersForTenant: jest.fn() })); });
55
55
  var defaultEntity = {
56
56
  uri: 'entities/uri1',
57
57
  type: 'configuration/entityTypes/HCO',
@@ -123,6 +123,7 @@ var setUp = function (_a) {
123
123
  return (react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues },
124
124
  react_1.default.createElement(CollaborationContext_1.CollaborationContext.Provider, { value: {
125
125
  commentsMap: {},
126
+ totalCommentsCount: null,
126
127
  currentComment: currentComment,
127
128
  createComment: function () { return Promise.resolve(); },
128
129
  editComment: function () { return Promise.resolve(); },
@@ -131,6 +131,7 @@ describe('Comment tests', function () {
131
131
  };
132
132
  var defaultCollaborationContextValue = {
133
133
  commentsMap: defaultCommentsMap,
134
+ totalCommentsCount: null,
134
135
  currentComment: defaultCurrentComment,
135
136
  createComment: function () { return Promise.resolve(); },
136
137
  editComment: function () { return Promise.resolve(); },
@@ -70,7 +70,7 @@ describe('SendMessageArea tests', function () {
70
70
  };
71
71
  var createCollaborationContext = function (props) {
72
72
  if (props === void 0) { props = {}; }
73
- return __assign({ comments: [], commentsMap: null, currentComment: null, getComment: ramda_1.identity, getComments: function () { return new Promise(ramda_1.identity); }, getCommentsCount: ramda_1.identity, resolveThread: ramda_1.identity, reOpenThread: ramda_1.identity, clearCurrentComment: ramda_1.identity, deleteComment: ramda_1.identity, sending: false, loading: false, pageToken: null, deleteReply: ramda_1.identity, createReply: function () { return new Promise(function (res) { return res(); }); }, createComment: function () { return new Promise(function (res) { return res(); }); }, editComment: function () { return new Promise(function (res) { return res(); }); }, editReply: function () { return new Promise(function (res) { return res(); }); }, getCommentState: function () { return ({}); }, clearCommentState: function () { }, updateCommentState: function () { } }, props);
73
+ return __assign({ comments: [], commentsMap: null, totalCommentsCount: null, currentComment: null, getComment: ramda_1.identity, getComments: function () { return new Promise(ramda_1.identity); }, getCommentsCount: ramda_1.identity, resolveThread: ramda_1.identity, reOpenThread: ramda_1.identity, clearCurrentComment: ramda_1.identity, deleteComment: ramda_1.identity, sending: false, loading: false, pageToken: null, deleteReply: ramda_1.identity, createReply: function () { return new Promise(function (res) { return res(); }); }, createComment: function () { return new Promise(function (res) { return res(); }); }, editComment: function () { return new Promise(function (res) { return res(); }); }, editReply: function () { return new Promise(function (res) { return res(); }); }, getCommentState: function () { return ({}); }, clearCommentState: function () { }, updateCommentState: function () { } }, props);
74
74
  };
75
75
  var createProps = function (comment, extraProps) {
76
76
  if (extraProps === void 0) { extraProps = {}; }
@@ -56,7 +56,7 @@ var mdm_sdk_1 = require("@reltio/mdm-sdk");
56
56
  var ScreenProfileBand_1 = require("./ScreenProfileBand");
57
57
  var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
58
58
  var ActionsHookContext_1 = require("../contexts/ActionsHookContext");
59
- jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getCommentsCount: jest.fn(), getAllUsersForTenant: jest.fn() })); });
59
+ jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getCommentsCount: jest.fn(), getTotalCommentsCount: jest.fn(function () { return Promise.resolve({ total: 1 }); }), getAllUsersForTenant: jest.fn() })); });
60
60
  var defaultEntity = {
61
61
  uri: 'entities/uri1',
62
62
  type: 'configuration/entityTypes/HCO',
@@ -22,6 +22,7 @@ export declare const InitialCollaborationContextValue: {
22
22
  pageToken: any;
23
23
  deleteReply: any;
24
24
  editReply: () => Promise<void>;
25
+ totalCommentsCount: any;
25
26
  };
26
27
  export declare const CollaborationContext: React.Context<{
27
28
  objectTypes?: CollaborationObjectTypes[];
@@ -67,6 +68,7 @@ export declare const CollaborationContext: React.Context<{
67
68
  sending: boolean;
68
69
  loading: boolean;
69
70
  pageToken: string;
71
+ totalCommentsCount: number | null;
70
72
  }>;
71
73
  export declare const CollaborationContextProvider: ({ collaboration, children }: {
72
74
  collaboration: any;
@@ -29,7 +29,8 @@ exports.InitialCollaborationContextValue = {
29
29
  loading: false,
30
30
  pageToken: null,
31
31
  deleteReply: ramda_1.identity,
32
- editReply: function () { return new Promise(ramda_1.identity); }
32
+ editReply: function () { return new Promise(ramda_1.identity); },
33
+ totalCommentsCount: null
33
34
  };
34
35
  exports.CollaborationContext = react_1.default.createContext(exports.InitialCollaborationContextValue);
35
36
  exports.CollaborationContext.displayName = 'CollaborationContext';
@@ -27,5 +27,6 @@ export declare const useCollaboration: ({ objectIds, objectTypes, enabled }: Pro
27
27
  sending: boolean;
28
28
  deleteReply: ({ uri, commentId, reply }: any) => void;
29
29
  editReply: ({ content, namedUsers, commentId, replyId }: any) => Promise<void>;
30
+ totalCommentsCount: number;
30
31
  };
31
32
  export {};
@@ -46,27 +46,49 @@ var useCollaboration = function (_a) {
46
46
  var _d = (0, react_1.useState)(null), pageToken = _d[0], setPageToken = _d[1];
47
47
  var _e = (0, react_1.useState)([]), comments = _e[0], setComments = _e[1];
48
48
  var _f = (0, react_1.useState)(null), commentsMap = _f[0], setCommentsMap = _f[1];
49
- var _g = (0, react_1.useState)(null), currentComment = _g[0], setCurrentComment = _g[1];
50
- var _h = (0, react_1.useState)(false), sending = _h[0], setSending = _h[1];
51
- var _j = (0, react_1.useState)(false), loading = _j[0], setLoading = _j[1];
52
- var _k = (0, react_1.useState)({}), collaborationStateMap = _k[0], setCollaborationStateMap = _k[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];
53
54
  var addCommentsToCommentsMap = (0, react_1.useCallback)(function (commentsMap) {
54
55
  setCommentsMap(function (currentCommentsMap) { return (__assign(__assign({}, currentCommentsMap), commentsMap)); });
55
56
  }, []);
56
57
  var entityUri = entity === null || entity === void 0 ? void 0 : entity.uri;
58
+ var isCollaborationEnabledForEntity = isCollaborationEnabled && entityUri && !(0, mdm_sdk_1.isTempUri)(entityUri);
57
59
  var getCommentsCount = (0, react_1.useCallback)(function (objectIds, shouldResetCommentsMap) {
58
60
  if (shouldResetCommentsMap === void 0) { shouldResetCommentsMap = false; }
59
- if (isCollaborationEnabled && entityUri && !(0, mdm_sdk_1.isTempUri)(entityUri)) {
61
+ if (!isCollaborationEnabledForEntity || totalCommentsCount == null) {
62
+ return setCommentsMap(null);
63
+ }
64
+ if (totalCommentsCount === 0) {
65
+ return shouldResetCommentsMap && setCommentsMap({});
66
+ }
67
+ var onError = function (e) {
68
+ console.warn('Collaboration error', e);
69
+ setCommentsMap(null);
70
+ };
71
+ (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]);
73
+ var getTotalCommentsCount = (0, react_1.useCallback)(function () {
74
+ if (isCollaborationEnabledForEntity) {
60
75
  var onError = function (e) {
61
76
  console.warn('Collaboration error', e);
62
- setCommentsMap(null);
77
+ setTotalCommentsCount(null);
63
78
  };
64
- (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 });
79
+ (0, ramda_1.pipe)(mdm_sdk_1.getTotalCommentsCount, (0, ramda_1.andThen)((0, ramda_1.prop)('total')), (0, ramda_1.andThen)(setTotalCommentsCount), (0, ramda_1.otherwise)(onError))({
80
+ relatedObjectUri: entityUri,
81
+ collaborationPath: collaborationPath,
82
+ tenant: tenant
83
+ });
65
84
  }
66
85
  else {
67
- setCommentsMap(null);
86
+ setTotalCommentsCount(null);
68
87
  }
69
- }, [addCommentsToCommentsMap, collaborationPath, entityUri, isCollaborationEnabled, tenant]);
88
+ }, [isCollaborationEnabledForEntity, collaborationPath, entityUri, tenant]);
89
+ (0, react_1.useEffect)(function () {
90
+ getTotalCommentsCount();
91
+ }, [getTotalCommentsCount]);
70
92
  (0, react_1.useEffect)(function () {
71
93
  getCommentsCount(objectIds, true);
72
94
  }, [objectIds, getCommentsCount]);
@@ -98,6 +120,7 @@ var useCollaboration = function (_a) {
98
120
  return __assign(__assign({}, prevCommentsMap), (_a = {}, _a[uri] = __spreadArray(__spreadArray([], (prevCommentsMap[uri] || []), true), [{ commentId: comment.commentId, replies: 0, status: 'open' }], false), _a));
99
121
  });
100
122
  setComments(function (prevComments) { return __spreadArray([comment], prevComments, true); });
123
+ setTotalCommentsCount(function (prevCount) { return (prevCount || 0) + 1; });
101
124
  };
102
125
  var updateCommentInState = function (comment) {
103
126
  setCurrentComment(comment);
@@ -113,6 +136,7 @@ var useCollaboration = function (_a) {
113
136
  setComments(function (prevComments) {
114
137
  return prevComments.filter(function (comment) { return comment.commentId !== commentId; });
115
138
  });
139
+ setTotalCommentsCount(function (prevCount) { return Math.max((prevCount || 0) - 1, 0); });
116
140
  };
117
141
  var createComment = (0, react_1.useCallback)(function (_a) {
118
142
  var content = _a.content, namedUsers = _a.namedUsers, objectType = _a.objectType, uri = _a.uri, relatedObjectUris = _a.relatedObjectUris;
@@ -198,6 +222,12 @@ var useCollaboration = function (_a) {
198
222
  return comment;
199
223
  });
200
224
  });
225
+ if (isDeleteReply) {
226
+ setTotalCommentsCount(function (prevCount) { return Math.max((prevCount || 0) - 1, 0); });
227
+ }
228
+ else {
229
+ setTotalCommentsCount(function (prevCount) { return (prevCount || 0) + 1; });
230
+ }
201
231
  }, []);
202
232
  var deleteReply = (0, react_1.useCallback)(function (_a) {
203
233
  var uri = _a.uri, commentId = _a.commentId, reply = _a.reply;
@@ -292,7 +322,8 @@ var useCollaboration = function (_a) {
292
322
  resolveThread: resolveThread,
293
323
  sending: sending,
294
324
  deleteReply: deleteReply,
295
- editReply: editReply
325
+ editReply: editReply,
326
+ totalCommentsCount: totalCommentsCount
296
327
  }); }, [
297
328
  clearCurrentComment,
298
329
  comments,
@@ -315,7 +346,8 @@ var useCollaboration = function (_a) {
315
346
  resolveThread,
316
347
  sending,
317
348
  deleteReply,
318
- editReply
349
+ editReply,
350
+ totalCommentsCount
319
351
  ]);
320
352
  };
321
353
  exports.useCollaboration = useCollaboration;