tycho-components 0.34.0 → 0.35.0

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.
@@ -2,10 +2,11 @@ import './style.scss';
2
2
  import { Comment } from './types/Comment';
3
3
  type Props = {
4
4
  comment: Comment;
5
+ hasEditAccess?: boolean;
5
6
  onRemove: () => void;
6
7
  onUpdate: (c: Comment) => void;
7
8
  onEdit: () => void;
8
9
  onReply: () => void;
9
10
  };
10
- export default function CommentInfo({ comment, onRemove, onUpdate, onEdit, onReply, }: Props): import("react/jsx-runtime").JSX.Element;
11
+ export default function CommentInfo({ comment, hasEditAccess, onRemove, onUpdate, onEdit, onReply, }: Props): import("react/jsx-runtime").JSX.Element;
11
12
  export {};
@@ -6,7 +6,7 @@ import CommonContext from '../../configs/CommonContext';
6
6
  import DateUtils from '../../functions/DateUtils';
7
7
  import './style.scss';
8
8
  import CommentService from './CommentService';
9
- export default function CommentInfo({ comment, onRemove, onUpdate, onEdit, onReply, }) {
9
+ export default function CommentInfo({ comment, hasEditAccess = true, onRemove, onUpdate, onEdit, onReply, }) {
10
10
  const { t } = useTranslation('comments');
11
11
  const { state } = useContext(CommonContext);
12
12
  const handleMarkRead = () => {
@@ -27,5 +27,5 @@ export default function CommentInfo({ comment, onRemove, onUpdate, onEdit, onRep
27
27
  return false;
28
28
  return !requested.read;
29
29
  };
30
- return (_jsxs("div", { className: "comment", children: [_jsxs("div", { className: "top", children: [_jsx(Avatar, { title: comment.name, src: comment.picture, size: comment.reply ? 'small' : 'medium' }), _jsx("div", { className: "name", children: comment.name }), _jsxs("div", { className: "buttons", children: [!comment.reply && (_jsx(IconButton, { size: "small", onClick: onReply, title: t('tooltip.reply'), name: "reply" })), state.logged?.uid === comment.user && (_jsxs(_Fragment, { children: [_jsx(IconButton, { size: comment.reply ? 'x-small' : 'small', onClick: onEdit, title: t('tooltip.edit'), name: "edit" }), _jsx(IconButton, { size: comment.reply ? 'x-small' : 'small', onClick: handleRemove, title: t('tooltip.delete'), name: "delete" })] })), isNotRead(comment) && (_jsx(IconButton, { size: comment.reply ? 'x-small' : 'small', onClick: handleMarkRead, title: t('tooltip.read'), name: "check_circle" }))] })] }), _jsxs("div", { className: "content", children: [comment.title && _jsx("div", { className: "title", children: comment.title }), _jsx("div", { className: "text", children: comment.value }), comment.requested && (_jsxs("div", { className: "date", children: [_jsx("span", { className: "me-1", children: t('label.requested.to') }), _jsx("span", { children: comment.requested.map((e) => e.name).join(', ') })] })), _jsxs("div", { className: "date", children: [_jsx("span", { className: "me-1", children: t('label.posted.on') }), _jsx("span", { className: "me-1", children: DateUtils.formatDateTime(comment.edited ? comment.edited : comment.date, 'MM/dd/yyyy - HH:mm') }), comment.edited && _jsx("i", { children: t('label.edited') })] })] })] }));
30
+ return (_jsxs("div", { className: "comment", children: [_jsxs("div", { className: "top", children: [_jsx(Avatar, { title: comment.name, src: comment.picture, size: comment.reply ? 'small' : 'medium' }), _jsx("div", { className: "name", children: comment.name }), _jsxs("div", { className: "buttons", children: [hasEditAccess && !comment.reply && (_jsx(IconButton, { size: "small", onClick: onReply, title: t('tooltip.reply'), name: "reply" })), hasEditAccess && state.logged?.uid === comment.user && (_jsxs(_Fragment, { children: [_jsx(IconButton, { size: comment.reply ? 'x-small' : 'small', onClick: onEdit, title: t('tooltip.edit'), name: "edit" }), _jsx(IconButton, { size: comment.reply ? 'x-small' : 'small', onClick: handleRemove, title: t('tooltip.delete'), name: "delete" })] })), isNotRead(comment) && (_jsx(IconButton, { size: comment.reply ? 'x-small' : 'small', onClick: handleMarkRead, title: t('tooltip.read'), name: "check_circle" }))] })] }), _jsxs("div", { className: "content", children: [comment.title && _jsx("div", { className: "title", children: comment.title }), _jsx("div", { className: "text", children: comment.value }), comment.requested && (_jsxs("div", { className: "date", children: [_jsx("span", { className: "me-1", children: t('label.requested.to') }), _jsx("span", { children: comment.requested.map((e) => e.name).join(', ') })] })), _jsxs("div", { className: "date", children: [_jsx("span", { className: "me-1", children: t('label.posted.on') }), _jsx("span", { className: "me-1", children: DateUtils.formatDateTime(comment.edited ? comment.edited : comment.date, 'MM/dd/yyyy - HH:mm') }), comment.edited && _jsx("i", { children: t('label.edited') })] })] })] }));
31
31
  }
@@ -34,7 +34,7 @@ export default function Comments({ uid, keywords, references, mode, onClose, onC
34
34
  };
35
35
  const hasEditAccess = useMemo(() => {
36
36
  return SecurityUtils.hasAccess(uid, ['ADMIN', 'EDITOR'], mode);
37
- }, [uid]);
37
+ }, [uid, mode]);
38
38
  const hasReplies = (thisComment) => comments && comments.some((c) => c.reply === thisComment.id);
39
39
  const getReplies = (thisComment) => comments?.filter((c) => c.reply === thisComment.id) || [];
40
40
  useEffect(() => {
@@ -43,7 +43,7 @@ export default function Comments({ uid, keywords, references, mode, onClose, onC
43
43
  return (_jsx(Drawer, { anchor: "right", open: true, onClose: onClose, children: !comments ? (_jsx(AppLoading, {})) : (_jsxs("div", { className: "comments-container", id: "comment-top", children: [_jsxs("div", { className: "header", children: [_jsx(IconButton, { name: "close", size: "small", mode: "ghost", onClick: onClose }), _jsx("span", { className: "title", children: t('label.title.comments') }), _jsx("div", { className: "actions", children: hasEditAccess && (_jsx(Button, { text: t('button.add'), icon: "add", mode: "outlined", size: "small", className: "edit-button", onClick: () => {
44
44
  setComment(undefined);
45
45
  setOpenAddComment(!openAddComment);
46
- } })) })] }), _jsxs("div", { className: "body", children: [openAddComment && (_jsx(CommentAdd, { uid: uid, mode: mode, users: users, references: references, keywords: keywords, comment: comment, reply: reply, onClose: () => {
46
+ } })) })] }), _jsxs("div", { className: "body", children: [hasEditAccess && openAddComment && (_jsx(CommentAdd, { uid: uid, mode: mode, users: users, references: references, keywords: keywords, comment: comment, reply: reply, onClose: () => {
47
47
  setComment(undefined);
48
48
  setReply(undefined);
49
49
  setOpenAddComment(false);
@@ -59,7 +59,7 @@ export default function Comments({ uid, keywords, references, mode, onClose, onC
59
59
  setComments(updated);
60
60
  onChange?.(updated);
61
61
  }
62
- } })), comments?.length === 0 && (_jsx(AppPlaceholder, { text: t('placeholder.comments.empty') })), comments?.map((el, idx) => (_jsxs("div", { className: "thread", children: [!el.reply && (_jsx(CommentInfo, { comment: el, onRemove: () => {
62
+ } })), comments?.length === 0 && (_jsx(AppPlaceholder, { text: t('placeholder.comments.empty') })), comments?.map((el, idx) => (_jsxs("div", { className: "thread", children: [!el.reply && (_jsx(CommentInfo, { comment: el, hasEditAccess: hasEditAccess, onRemove: () => {
63
63
  const updated = comments?.filter((c) => c.id !== el.id);
64
64
  setComments(updated);
65
65
  onChange && onChange(updated || []);
@@ -75,7 +75,7 @@ export default function Comments({ uid, keywords, references, mode, onClose, onC
75
75
  setReply(el);
76
76
  setOpenAddComment(true);
77
77
  UsabilityUtils.goToAnchor('comment-top');
78
- } })), hasReplies(el) && (_jsx("div", { className: "replies", children: getReplies(el).map((rel, idy) => (_jsx(CommentInfo, { comment: rel, onRemove: () => {
78
+ } })), hasReplies(el) && (_jsx("div", { className: "replies", children: getReplies(el).map((rel, idy) => (_jsx(CommentInfo, { comment: rel, hasEditAccess: hasEditAccess, onRemove: () => {
79
79
  const updated = comments?.filter((c) => c.id !== rel.id);
80
80
  setComments(updated);
81
81
  onChange && onChange(updated || []);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.34.0",
4
+ "version": "0.35.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {