tycho-components 0.0.11-SNAPSHOT-7 → 0.0.11-SNAPSHOT-9

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.
@@ -1,10 +1,12 @@
1
1
  import './style.scss';
2
+ import { Comment } from './types/Comment';
2
3
  type Props = {
3
4
  uid: string;
4
5
  keywords?: Record<string, string | number | boolean>;
5
6
  references: Record<string, string | number | boolean>;
6
7
  onClose: () => void;
7
8
  mode: 'lexicon' | 'corpus' | 'parser';
9
+ onChange: (a: Comment[]) => void;
8
10
  };
9
- export default function Comments({ uid, keywords, references, onClose, mode, }: Props): import("react/jsx-runtime").JSX.Element;
11
+ export default function Comments({ uid, keywords, references, onClose, mode, onChange, }: Props): import("react/jsx-runtime").JSX.Element;
10
12
  export {};
@@ -16,7 +16,7 @@ import SecurityUtils from '../functions/SecurityUtils';
16
16
  import './style.scss';
17
17
  import { EMPTY_COMMENT_REQUEST, } from './types/Comment';
18
18
  import CommentService from './types/CommentService';
19
- export default function Comments({ uid, keywords, references, onClose, mode, }) {
19
+ export default function Comments({ uid, keywords, references, onClose, mode, onChange, }) {
20
20
  const { t } = useTranslation('comments');
21
21
  const { state } = useContext(CommonContext);
22
22
  const { isLoading, dispatchLoading } = useMessageUtils();
@@ -50,7 +50,9 @@ export default function Comments({ uid, keywords, references, onClose, mode, })
50
50
  dispatchLoading(false);
51
51
  setOpenAddComment(false);
52
52
  setComment(undefined);
53
- setComments((prev) => [...(prev || []), r.data]);
53
+ const updated = [...(comments || []), r.data];
54
+ setComments(updated);
55
+ onChange(updated);
54
56
  createdForm.reset(EMPTY_COMMENT_REQUEST);
55
57
  });
56
58
  };
@@ -62,7 +64,9 @@ export default function Comments({ uid, keywords, references, onClose, mode, })
62
64
  };
63
65
  const handleRemove = (thisComment) => {
64
66
  CommentService.remove(thisComment.id).then(() => {
65
- setComments(comments?.filter((c) => c.id !== thisComment.id));
67
+ const updated = comments?.filter((c) => c.id !== thisComment.id);
68
+ setComments(updated);
69
+ onChange(updated || []);
66
70
  });
67
71
  };
68
72
  const handleEdit = (thisComment) => {
@@ -73,6 +77,8 @@ export default function Comments({ uid, keywords, references, onClose, mode, })
73
77
  title: thisComment.title,
74
78
  requestedUser: thisComment.requested?.uid,
75
79
  });
80
+ const updated = comments?.map((c) => c.id === thisComment.id ? { ...c, ...thisComment } : c);
81
+ onChange(updated || []);
76
82
  };
77
83
  const handleUpdate = () => {
78
84
  if (!comment)
@@ -89,19 +95,20 @@ export default function Comments({ uid, keywords, references, onClose, mode, })
89
95
  useEffect(() => {
90
96
  load();
91
97
  }, []);
92
- if (!comments)
93
- return _jsx(AppLoading, {});
94
- return (_jsx(Drawer, { anchor: "right", open: true, onClose: onClose, children: _jsxs("div", { className: "comments-container", 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: () => {
98
+ return (_jsx(Drawer, { anchor: "right", open: true, onClose: onClose, children: !comments ? (_jsx(AppLoading, {})) : (_jsxs("div", { className: "comments-container", 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: () => {
95
99
  setComment(undefined);
96
100
  setOpenAddComment(!openAddComment);
97
101
  } })) })] }), _jsxs("div", { className: "body", children: [openAddComment && (_jsxs("div", { className: "form", children: [_jsx(TextField, { label: t('input.value'), attr: "value", createdForm: createdForm, showEndAdornment: false, placeholder: t('common:generic.placeholder'), required: true, multiline: true }), _jsx(TextField, { label: t('input.title'), attr: "title", createdForm: createdForm, showEndAdornment: false, placeholder: t('common:generic.placeholder') }), _jsx(SelectField, { label: t('input.user'), attr: "requestedUser", createdForm: createdForm, options: [
98
- { label: t('common:generic.placeholder.select'), value: '' },
102
+ {
103
+ label: t('common:generic.placeholder.select'),
104
+ value: '',
105
+ },
99
106
  ...FormUtils.convertList(users, 'name', 'uid'),
100
107
  ], showEndAdornment: false }), _jsxs("div", { className: "buttons", children: [comment && (_jsx(Button, { onClick: comment?.id ? handleUpdate : handleAdd, text: t('button.discard'), color: "danger" })), _jsx(Button, { onClick: comment ? handleUpdate : handleAdd, text: comment ? t('label.button.update') : t('label.button.add'), disabled: !createdForm.formState.isValid })] })] })), comments?.length === 0 && (_jsx(AppPlaceholder, { children: _jsx("span", { children: t('placeholder.comments.empty') }) })), comments?.map((el, idx) => (_jsxs("div", { className: "comment", children: [_jsxs("div", { className: "top", children: [_jsx(Avatar, { title: el.name, src: el.picture, size: "medium" }), _jsx("div", { className: "name", children: el.name }), _jsxs("div", { className: "buttons", children: [state.logged?.uid === el.user && (_jsxs(_Fragment, { children: [_jsx(IconButton, { size: "small", onClick: () => handleEdit(el), title: t('tooltip.edit'), name: "edit" }), _jsx(IconButton, { size: "small", onClick: () => handleRemove(el), title: t('tooltip.delete'), name: "delete" })] })), el.requested &&
101
108
  !el.read &&
102
109
  state.logged?.uid === el.requested.uid && (_jsx(IconButton, { size: "small", onClick: () => {
103
110
  handleMarkRead(el);
104
- }, title: t('tooltip.read'), name: "check_circle" }))] })] }), _jsxs("div", { className: "content", children: [el.title && _jsx("div", { className: "title", children: el.title }), _jsx("div", { className: "text", children: el.value }), el.requested && (_jsxs("div", { className: "date", children: [_jsx("span", { className: "me-1", children: t('label.requested.to') }), _jsx("span", { children: el.requested.name })] })), _jsxs("div", { className: "date", children: [_jsx("span", { className: "me-1", children: t('label.posted.on') }), _jsx("span", { className: "me-1", children: DateUtils.formatDateTime(el.edited ? el.edited : el.date, 'MM/dd/yyyy - HH:mm') }), el.edited && _jsx("i", { children: "edited" })] })] })] }, idx.valueOf())))] })] }) }));
111
+ }, title: t('tooltip.read'), name: "check_circle" }))] })] }), _jsxs("div", { className: "content", children: [el.title && _jsx("div", { className: "title", children: el.title }), _jsx("div", { className: "text", children: el.value }), el.requested && (_jsxs("div", { className: "date", children: [_jsx("span", { className: "me-1", children: t('label.requested.to') }), _jsx("span", { children: el.requested.name })] })), _jsxs("div", { className: "date", children: [_jsx("span", { className: "me-1", children: t('label.posted.on') }), _jsx("span", { className: "me-1", children: DateUtils.formatDateTime(el.edited ? el.edited : el.date, 'MM/dd/yyyy - HH:mm') }), el.edited && _jsx("i", { children: "edited" })] })] })] }, idx.valueOf())))] })] })) }));
105
112
  }
106
113
  const getFormSchema = (t) => yup.object().shape({
107
114
  title: yup.string().optional(),
package/dist/index.d.ts CHANGED
@@ -20,8 +20,9 @@ export { KeyboardCustomLayouts } from './VirtualKeyboard/KeyboardCustomLayout';
20
20
  export { default as DateUtils } from './functions/DateUtils';
21
21
  export { default as FormUtils } from './functions/FormUtils';
22
22
  export { default as SecurityUtils } from './functions/SecurityUtils';
23
- export type { FormFieldOption } from './AppEditable/FormFieldOption';
24
23
  export type { AppEditableField } from './AppEditable/AppEditableField';
24
+ export type { Comment } from './Comments/types/Comment';
25
+ export type { FormFieldOption } from './AppEditable/FormFieldOption';
25
26
  export type { FieldOperations, FormField } from './AppEditable/FormField';
26
27
  export type { KeyboardLayout } from './VirtualKeyboard/KeyboardCustomLayout';
27
28
  export type { User } from './configs/User';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.0.11-SNAPSHOT-7",
4
+ "version": "0.0.11-SNAPSHOT-9",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {