@reltio/components 1.4.818 → 1.4.819

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.
@@ -11,5 +11,5 @@ declare type Props = {
11
11
  messagesRef?: React.RefCallback<HTMLDivElement>;
12
12
  comment?: CommentType;
13
13
  };
14
- export declare const CollaborationItem: ({ uri, relatedObjectUris, objectType, classes, popperRef, messagesRef, comment }: Props) => JSX.Element;
14
+ export declare const CollaborationItem: React.MemoExoticComponent<({ uri, relatedObjectUris, objectType, classes, popperRef, messagesRef, comment }: Props) => JSX.Element>;
15
15
  export {};
@@ -29,7 +29,7 @@ var Comment_1 = require("./Comment/Comment");
29
29
  var RepliedComment_1 = require("./RepliedComment/RepliedComment");
30
30
  var SendMessageArea_1 = require("./SendMessageArea/SendMessageArea");
31
31
  var styles_1 = require("./styles");
32
- var CollaborationItem = function (_a) {
32
+ exports.CollaborationItem = react_1.memo(function (_a) {
33
33
  var uri = _a.uri, relatedObjectUris = _a.relatedObjectUris, objectType = _a.objectType, classes = _a.classes, popperRef = _a.popperRef, messagesRef = _a.messagesRef, comment = _a.comment;
34
34
  var inputRef = react_1.useRef();
35
35
  var styles = styles_1.useStyles({ classes: classes });
@@ -51,5 +51,4 @@ var CollaborationItem = function (_a) {
51
51
  react_1.default.createElement(Box_1.default, { className: styles.replies }, comment.replies.map(function (reply) { return (react_1.default.createElement(RepliedComment_1.RepliedComment, { key: reply.replyId, className: styles.repliedComment, reply: reply })); }))),
52
52
  sendMessageArea)),
53
53
  !comment && sendMessageArea));
54
- };
55
- exports.CollaborationItem = CollaborationItem;
54
+ });
@@ -3,7 +3,9 @@ import { CollaborationObjectTypes, Comment, CommentsMap, Reply } from '@reltio/m
3
3
  export declare const CollaborationContext: React.Context<{
4
4
  objectTypes?: CollaborationObjectTypes[];
5
5
  commentsMap: CommentsMap;
6
+ comments: Comment[];
6
7
  currentComment: Comment;
8
+ getComments: (uri: string, pageToken?: string) => void;
7
9
  getComment: (commentId: Comment['commentId']) => void;
8
10
  createComment: (params: Pick<Comment, 'content' | 'namedUsers' | 'objectType' | 'relatedObjectUris'> & {
9
11
  uri: string;
@@ -29,4 +31,5 @@ export declare const CollaborationContext: React.Context<{
29
31
  clearCurrentComment: () => void;
30
32
  sending: boolean;
31
33
  loading: boolean;
34
+ pageToken: string;
32
35
  }>;
@@ -7,9 +7,11 @@ exports.CollaborationContext = void 0;
7
7
  var react_1 = __importDefault(require("react"));
8
8
  var noop = function () { };
9
9
  exports.CollaborationContext = react_1.default.createContext({
10
+ comments: [],
10
11
  commentsMap: null,
11
12
  currentComment: null,
12
13
  getComment: noop,
14
+ getComments: function () { return new Promise(noop); },
13
15
  createComment: function () { return new Promise(noop); },
14
16
  editComment: function () { return new Promise(noop); },
15
17
  createReply: function () { return new Promise(noop); },
@@ -18,6 +20,7 @@ exports.CollaborationContext = react_1.default.createContext({
18
20
  clearCurrentComment: noop,
19
21
  deleteComment: noop,
20
22
  sending: false,
21
- loading: false
23
+ loading: false,
24
+ pageToken: null
22
25
  });
23
26
  exports.CollaborationContext.displayName = 'CollaborationContext';
@@ -2,6 +2,7 @@ import { CollaborationObjectTypes, Comment, CommentsMap } from '@reltio/mdm-sdk'
2
2
  export declare const useCollaboration: (objectIds?: string[], objectTypes?: CollaborationObjectTypes[]) => {
3
3
  commentsMap: CommentsMap;
4
4
  currentComment: Comment;
5
+ comments: Comment[];
5
6
  getComment: (commentId: string) => void;
6
7
  createReply: ({ content, namedUsers, commentId, action, uri }: any) => Promise<void>;
7
8
  editComment: ({ content, namedUsers, objectType, uri, relatedObjectUris, commentId, replies }: any) => Promise<void>;
@@ -13,4 +14,6 @@ export declare const useCollaboration: (objectIds?: string[], objectTypes?: Coll
13
14
  sending: boolean;
14
15
  loading: boolean;
15
16
  objectTypes: CollaborationObjectTypes[];
17
+ getComments: (relatedObjectUri: string, pageToken?: string) => void;
18
+ pageToken: string;
16
19
  };
@@ -33,10 +33,12 @@ var useCollaboration = function (objectIds, objectTypes) {
33
33
  var tenant = react_redux_1.useSelector(mdm_module_1.default.selectors.getTenant);
34
34
  var collaborationPath = react_redux_1.useSelector(mdm_module_1.default.selectors.getCollaborationPath);
35
35
  var isCollaborationEnabled = react_redux_1.useSelector(mdm_module_1.default.selectors.isCollaborationEnabled);
36
- var _a = react_1.useState(null), commentsMap = _a[0], setCommentsMap = _a[1];
37
- var _b = react_1.useState(null), currentComment = _b[0], setCurrentComment = _b[1];
38
- var _c = react_1.useState(false), sending = _c[0], setSending = _c[1];
39
- var _d = react_1.useState(false), loading = _d[0], setLoading = _d[1];
36
+ var _a = react_1.useState(null), pageToken = _a[0], setPageToken = _a[1];
37
+ var _b = react_1.useState([]), comments = _b[0], setComments = _b[1];
38
+ var _c = react_1.useState(null), commentsMap = _c[0], setCommentsMap = _c[1];
39
+ var _d = react_1.useState(null), currentComment = _d[0], setCurrentComment = _d[1];
40
+ var _e = react_1.useState(false), sending = _e[0], setSending = _e[1];
41
+ var _f = react_1.useState(false), loading = _f[0], setLoading = _f[1];
40
42
  react_1.useEffect(function () {
41
43
  if (isCollaborationEnabled && entity) {
42
44
  var onError = function (e) {
@@ -49,6 +51,20 @@ var useCollaboration = function (objectIds, objectTypes) {
49
51
  setCommentsMap(null);
50
52
  }
51
53
  }, [entity, isCollaborationEnabled, tenant, collaborationPath, objectIds]);
54
+ var getComments = react_1.useCallback(function (relatedObjectUri, pageToken) {
55
+ mdm_sdk_1.getComments({ collaborationPath: collaborationPath, tenant: tenant, relatedObjectUri: relatedObjectUri, pageToken: pageToken })
56
+ .then(function (_a) {
57
+ var items = _a.items, nextPageToken = _a.nextPageToken;
58
+ setComments(function (prevComments) {
59
+ if (!pageToken) {
60
+ return items;
61
+ }
62
+ return ramda_1.uniqBy(ramda_1.prop('commentId'), __spreadArray(__spreadArray([], prevComments), items));
63
+ });
64
+ setPageToken(nextPageToken);
65
+ })
66
+ .catch(catchErrorInRequest);
67
+ }, [collaborationPath, tenant]);
52
68
  var getComment = react_1.useCallback(function (commentId) {
53
69
  setLoading(true);
54
70
  mdm_sdk_1.getComment({ collaborationPath: collaborationPath, tenant: tenant, commentId: commentId })
@@ -62,17 +78,11 @@ var useCollaboration = function (objectIds, objectTypes) {
62
78
  var _a;
63
79
  return __assign(__assign({}, prevCommentsMap), (_a = {}, _a[uri] = __spreadArray(__spreadArray([], (prevCommentsMap[uri] || [])), [{ commentId: comment.commentId, replies: 0, status: 'open' }]), _a));
64
80
  });
81
+ setComments(function (prevComments) { return __spreadArray([comment], prevComments); });
65
82
  };
66
- var updateCommentInState = function (comment, uri) {
83
+ var updateCommentInState = function (comment) {
67
84
  setCurrentComment(comment);
68
- setCommentsMap(function (prevCommentsMap) {
69
- var _a;
70
- var comments = (prevCommentsMap[uri] || []).map(function (c) {
71
- return c.commentId === comment.commentId
72
- ? __assign(__assign({}, comment), { replies: (typeof comment.replies === 'number' ? comment.replies : comment.replies.length) || 0 }) : c;
73
- });
74
- return __assign(__assign({}, prevCommentsMap), (_a = {}, _a[uri] = comments, _a));
75
- });
85
+ setComments(ramda_1.map(ramda_1.when(ramda_1.propEq('commentId', comment.commentId), ramda_1.always(comment))));
76
86
  };
77
87
  var deleteCommentFromState = function (commentId, uri) {
78
88
  setCurrentComment(null);
@@ -81,6 +91,9 @@ var useCollaboration = function (objectIds, objectTypes) {
81
91
  var comments = prevCommentsMap[uri] || [];
82
92
  return __assign(__assign({}, prevCommentsMap), (_a = {}, _a[uri] = comments.filter(function (c) { return c.commentId !== commentId; }), _a));
83
93
  });
94
+ setComments(function (prevComments) {
95
+ return prevComments.filter(function (comment) { return comment.commentId !== commentId; });
96
+ });
84
97
  };
85
98
  var createComment = react_1.useCallback(function (_a) {
86
99
  var content = _a.content, namedUsers = _a.namedUsers, objectType = _a.objectType, uri = _a.uri, relatedObjectUris = _a.relatedObjectUris;
@@ -117,7 +130,7 @@ var useCollaboration = function (objectIds, objectTypes) {
117
130
  replies: replies
118
131
  };
119
132
  return mdm_sdk_1.updateComment({ collaborationPath: collaborationPath, tenant: tenant, data: data })
120
- .then(function (comment) { return updateCommentInState(__assign(__assign({}, comment), { replies: replies }), uri); })
133
+ .then(function (comment) { return updateCommentInState(__assign(__assign({}, comment), { replies: replies })); })
121
134
  .catch(catchErrorInRequest)
122
135
  .finally(function () { return setSending(false); });
123
136
  }, [collaborationPath, tenant]);
@@ -129,7 +142,7 @@ var useCollaboration = function (objectIds, objectTypes) {
129
142
  .catch(catchErrorInRequest)
130
143
  .finally(function () { return setSending(false); });
131
144
  }, [collaborationPath, tenant]);
132
- var updateReply = react_1.useCallback(function (reply, uri, commentId) {
145
+ var updateReplyInState = react_1.useCallback(function (reply, uri, commentId) {
133
146
  var newStatus = reply.action === 'resolve' ? 'resolved' : 'open';
134
147
  if (newStatus === 'resolved') {
135
148
  setCurrentComment(function (prevCurrentComment) {
@@ -154,6 +167,14 @@ var useCollaboration = function (objectIds, objectTypes) {
154
167
  return comment;
155
168
  }), _a)));
156
169
  });
170
+ setComments(function (prevComments) {
171
+ return prevComments.map(function (comment) {
172
+ if (comment.commentId === commentId) {
173
+ return __assign(__assign({}, comment), { status: newStatus, replies: __spreadArray(__spreadArray([], comment.replies), [reply]) });
174
+ }
175
+ return comment;
176
+ });
177
+ });
157
178
  }, []);
158
179
  var createReply = react_1.useCallback(function (_a) {
159
180
  var content = _a.content, namedUsers = _a.namedUsers, commentId = _a.commentId, action = _a.action, uri = _a.uri;
@@ -166,11 +187,11 @@ var useCollaboration = function (objectIds, objectTypes) {
166
187
  return mdm_sdk_1.createReply({ collaborationPath: collaborationPath, tenant: tenant, commentId: commentId, data: data })
167
188
  .then(function (_a) {
168
189
  var reply = _a[0];
169
- return updateReply(reply, uri, commentId);
190
+ return updateReplyInState(reply, uri, commentId);
170
191
  })
171
192
  .catch(catchErrorInRequest)
172
193
  .finally(function () { return setSending(false); });
173
- }, [collaborationPath, tenant, updateReply]);
194
+ }, [collaborationPath, tenant, updateReplyInState]);
174
195
  var resolveThread = react_1.useCallback(function (_a) {
175
196
  var commentId = _a.commentId, uri = _a.uri;
176
197
  createReply({ content: '', namedUsers: [], commentId: commentId, action: 'resolve', uri: uri });
@@ -185,6 +206,7 @@ var useCollaboration = function (objectIds, objectTypes) {
185
206
  return {
186
207
  commentsMap: commentsMap,
187
208
  currentComment: currentComment,
209
+ comments: comments,
188
210
  getComment: getComment,
189
211
  createReply: createReply,
190
212
  editComment: editComment,
@@ -195,7 +217,9 @@ var useCollaboration = function (objectIds, objectTypes) {
195
217
  reOpenThread: reOpenThread,
196
218
  sending: sending,
197
219
  loading: loading,
198
- objectTypes: objectTypes
220
+ objectTypes: objectTypes,
221
+ getComments: getComments,
222
+ pageToken: pageToken
199
223
  };
200
224
  };
201
225
  exports.useCollaboration = useCollaboration;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.818",
3
+ "version": "1.4.819",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "@date-io/moment": "^1.3.5",
8
8
  "@react-google-maps/api": "^2.7.0",
9
- "@reltio/mdm-module": "^1.4.818",
10
- "@reltio/mdm-sdk": "^1.4.818",
9
+ "@reltio/mdm-module": "^1.4.819",
10
+ "@reltio/mdm-sdk": "^1.4.819",
11
11
  "classnames": "^2.2.5",
12
12
  "frontend-collective-react-dnd-scrollzone": "^1.0.2",
13
13
  "nanoid": "^2.0.0",