tycho-components 0.0.11-SNAPSHOT-5 → 0.0.11-SNAPSHOT-7

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,9 +1,10 @@
1
1
  import './style.scss';
2
2
  type Props = {
3
- lexicon: string;
4
- entry: string;
5
- keywords: Record<string, string | number | boolean>;
3
+ uid: string;
4
+ keywords?: Record<string, string | number | boolean>;
5
+ references: Record<string, string | number | boolean>;
6
6
  onClose: () => void;
7
+ mode: 'lexicon' | 'corpus' | 'parser';
7
8
  };
8
- export default function Comments({ lexicon, entry, keywords, onClose }: Props): import("react/jsx-runtime").JSX.Element;
9
+ export default function Comments({ uid, keywords, references, onClose, mode, }: Props): import("react/jsx-runtime").JSX.Element;
9
10
  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({ lexicon, entry, keywords, onClose }) {
19
+ export default function Comments({ uid, keywords, references, onClose, mode, }) {
20
20
  const { t } = useTranslation('comments');
21
21
  const { state } = useContext(CommonContext);
22
22
  const { isLoading, dispatchLoading } = useMessageUtils();
@@ -31,8 +31,8 @@ export default function Comments({ lexicon, entry, keywords, onClose }) {
31
31
  const load = async () => {
32
32
  try {
33
33
  const [commentsResponse, usersResponse] = await Promise.all([
34
- CommentService.find(lexicon, entry),
35
- CommentService.findAvailableUsers(lexicon),
34
+ CommentService.find(uid, mode, references),
35
+ CommentService.findAvailableUsers(uid, mode),
36
36
  ]);
37
37
  setComments(commentsResponse.data);
38
38
  setUsers(usersResponse.data);
@@ -46,7 +46,7 @@ export default function Comments({ lexicon, entry, keywords, onClose }) {
46
46
  if (isLoading())
47
47
  return;
48
48
  dispatchLoading(true);
49
- CommentService.add(lexicon, entry, createdForm.getValues(), keywords).then((r) => {
49
+ CommentService.add(uid, mode, createdForm.getValues(), references, keywords).then((r) => {
50
50
  dispatchLoading(false);
51
51
  setOpenAddComment(false);
52
52
  setComment(undefined);
@@ -84,8 +84,8 @@ export default function Comments({ lexicon, entry, keywords, onClose }) {
84
84
  });
85
85
  };
86
86
  const hasEditAccess = useMemo(() => {
87
- return SecurityUtils.hasAccess(lexicon, ['ADMIN', 'EDITOR']);
88
- }, [lexicon]);
87
+ return SecurityUtils.hasAccess(uid, ['ADMIN', 'EDITOR'], mode);
88
+ }, [uid]);
89
89
  useEffect(() => {
90
90
  load();
91
91
  }, []);
@@ -1,6 +1,7 @@
1
1
  import './style.scss';
2
2
  type Props = {
3
- lexicon: string;
3
+ uid: string;
4
+ mode: 'lexicon' | 'corpus' | 'parser';
4
5
  };
5
- export default function HeaderNotifications({ lexicon }: Props): import("react/jsx-runtime").JSX.Element;
6
+ export default function HeaderNotifications({ uid, mode }: Props): import("react/jsx-runtime").JSX.Element;
6
7
  export {};
@@ -6,7 +6,7 @@ import { Avatar, IconButton } from 'tycho-storybook';
6
6
  import DateUtils from '../../functions/DateUtils';
7
7
  import CommentService from '../types/CommentService';
8
8
  import './style.scss';
9
- export default function HeaderNotifications({ lexicon }) {
9
+ export default function HeaderNotifications({ uid, mode }) {
10
10
  const navigate = useNavigate();
11
11
  const { t } = useTranslation('comments');
12
12
  const [open, setOpen] = useState(false);
@@ -21,7 +21,7 @@ export default function HeaderNotifications({ lexicon }) {
21
21
  const serviceMethod = tab === 'read'
22
22
  ? CommentService.findReadNotifications
23
23
  : CommentService.findNotifications;
24
- serviceMethod(lexicon).then((r) => {
24
+ serviceMethod(uid, mode).then((r) => {
25
25
  if (tab !== 'read') {
26
26
  setComments(r.data);
27
27
  }
@@ -30,7 +30,7 @@ export default function HeaderNotifications({ lexicon }) {
30
30
  };
31
31
  useEffect(() => {
32
32
  load();
33
- }, [lexicon, tab]);
33
+ }, [uid, tab]);
34
34
  return (_jsxs("div", { className: "ds-dropdown-container notifications-container", children: [_jsx(IconButton, { name: "notifications_active", className: comments && comments.length > 0 ? 'shake' : '', size: "medium", onClick: () => setOpen(!open) }), open && (_jsx("div", { className: "ds-dropdown-list", children: _jsxs("div", { className: "notifications-panel", children: [_jsxs("div", { className: "header", children: [_jsx("span", { children: t('notification.title') }), _jsx(IconButton, { name: "close", size: "small", mode: "ghost", onClick: () => setOpen(false) })] }), _jsxs("div", { className: "tabs", children: [_jsxs("button", { className: tab === 'unread' ? 'active-tab' : '', onClick: () => setTab('unread'), children: [t('notification.unread'), " (", comments?.length || 0, ")"] }), _jsx("button", { className: tab === 'read' ? 'active-tab' : '', onClick: () => setTab('read'), children: t('notification.all') })] }), _jsxs("div", { className: "content", children: [notifications &&
35
35
  notifications.map((not, idx) => (_jsxs("div", { className: "item", onClick: () => handleOpen(not), children: [_jsx(Avatar, { src: not.picture, size: "small" }), _jsxs("div", { className: "message", children: [_jsx("span", { className: "text", children: _jsx(Trans, { t: t, i18nKey: "notification.text", values: {
36
36
  user: not.name,
@@ -1,6 +1,6 @@
1
1
  export type CommentRequest = {
2
2
  title?: string;
3
- value: string;
3
+ value?: string;
4
4
  requestedUser?: string;
5
5
  };
6
6
  export type Comment = {
@@ -1,13 +1,13 @@
1
1
  import { User } from '../../configs/User';
2
2
  import { Comment, CommentRequest } from './Comment';
3
+ declare function findNotifications(uid: string, mode: string): Promise<import("axios").AxiosResponse<Comment[], any>>;
4
+ declare function findReadNotifications(uid: string, mode: string): Promise<import("axios").AxiosResponse<Comment[], any>>;
3
5
  declare function markRead(id: string): Promise<import("axios").AxiosResponse<Comment, any>>;
4
6
  declare function update(id: string, comment: CommentRequest): Promise<import("axios").AxiosResponse<Comment, any>>;
5
7
  declare function remove(id: string): Promise<import("axios").AxiosResponse<Comment, any>>;
6
- declare function add(lexicon: string, entry: string, comment: CommentRequest, keywords: Record<string, string | number | boolean>): Promise<import("axios").AxiosResponse<Comment, any>>;
7
- declare function find(lexicon: string, entry?: string): Promise<import("axios").AxiosResponse<Comment[], any>>;
8
- declare function findNotifications(lexicon: string): Promise<import("axios").AxiosResponse<Comment[], any>>;
9
- declare function findReadNotifications(lexicon: string): Promise<import("axios").AxiosResponse<Comment[], any>>;
10
- declare function findAvailableUsers(lexicon: string): Promise<import("axios").AxiosResponse<User[], any>>;
8
+ declare function add(uid: string, mode: string, comment: CommentRequest, references: Record<string, string | number | boolean>, keywords?: Record<string, string | number | boolean>): Promise<import("axios").AxiosResponse<Comment, any>>;
9
+ declare function find(uid: string, mode: string, request: Record<string, string | number | boolean>): Promise<import("axios").AxiosResponse<Comment[], any>>;
10
+ declare function findAvailableUsers(uid: string, mode: string): Promise<import("axios").AxiosResponse<User[], any>>;
11
11
  declare const CommentService: {
12
12
  add: typeof add;
13
13
  remove: typeof remove;
@@ -1,35 +1,31 @@
1
1
  import api from '../../configs/api';
2
+ function findNotifications(uid, mode) {
3
+ return api.get(`${import.meta.env.VITE_APP_COMMENT_API_URL}/${mode}/notifications/${uid}`);
4
+ }
5
+ function findReadNotifications(uid, mode) {
6
+ return api.get(`${import.meta.env.VITE_APP_COMMENT_API_URL}/${mode}/notifications/read/${uid}`);
7
+ }
2
8
  function markRead(id) {
3
9
  return api.put(`${import.meta.env.VITE_APP_COMMENT_API_URL}/${id}`);
4
10
  }
5
11
  function update(id, comment) {
6
- return api.patch(`${import.meta.env.VITE_APP_COMMENT_API_URL}/lexicon/${id}`, { ...comment });
12
+ return api.patch(`${import.meta.env.VITE_APP_COMMENT_API_URL}/${id}`, { ...comment });
7
13
  }
8
14
  function remove(id) {
9
15
  return api.delete(`${import.meta.env.VITE_APP_COMMENT_API_URL}/${id}`);
10
16
  }
11
- function add(lexicon, entry, comment, keywords) {
12
- return api.post(`${import.meta.env.VITE_APP_COMMENT_API_URL}/lexicon/${lexicon}`, {
17
+ function add(uid, mode, comment, references, keywords) {
18
+ return api.post(`${import.meta.env.VITE_APP_COMMENT_API_URL}/${mode}/${uid}`, {
13
19
  ...comment,
14
- entry,
20
+ ...references,
15
21
  keywords,
16
22
  });
17
23
  }
18
- function find(lexicon, entry) {
19
- return api.get(`${import.meta.env.VITE_APP_COMMENT_API_URL}/lexicon/${lexicon}`, {
20
- params: {
21
- entry,
22
- },
23
- });
24
- }
25
- function findNotifications(lexicon) {
26
- return api.get(`${import.meta.env.VITE_APP_COMMENT_API_URL}/lexicon/notifications/${lexicon}`);
27
- }
28
- function findReadNotifications(lexicon) {
29
- return api.get(`${import.meta.env.VITE_APP_COMMENT_API_URL}/lexicon/notifications/read/${lexicon}`);
24
+ function find(uid, mode, request) {
25
+ return api.post(`${import.meta.env.VITE_APP_COMMENT_API_URL}/${mode}/find/${uid}`, request);
30
26
  }
31
- function findAvailableUsers(lexicon) {
32
- return api.get(`${import.meta.env.VITE_APP_AUTH_API}/lexicon/${lexicon}`);
27
+ function findAvailableUsers(uid, mode) {
28
+ return api.get(`${import.meta.env.VITE_APP_AUTH_API}/${mode}/${uid}`);
33
29
  }
34
30
  const CommentService = {
35
31
  add,
@@ -1,6 +1,6 @@
1
1
  import { User } from '../configs/User';
2
2
  declare const SecurityUtils: {
3
- hasAccess: (uid: string, roles: string[]) => boolean;
3
+ hasAccess: (uid: string, roles: string[], mode: "lexicon" | "corpus" | "parser") => boolean;
4
4
  parseJwt: (token: string) => User;
5
5
  };
6
6
  export default SecurityUtils;
@@ -1,13 +1,13 @@
1
1
  import CookieStorage from '../configs/CookieStorage';
2
2
  import { UserStatus } from '../configs/User';
3
- const hasAccess = (uid, roles) => {
3
+ const hasAccess = (uid, roles, mode) => {
4
4
  const token = CookieStorage.getJwtToken();
5
5
  if (!token)
6
6
  return false;
7
7
  const logged = parseJwt(token);
8
8
  if (logged.status && logged.status === UserStatus.SUPER)
9
9
  return true;
10
- return roles.some((role) => logged.permissions.includes(`ROLE_${role}_LEXICON_${uid}`));
10
+ return roles.some((role) => logged.permissions.includes(`ROLE_${role}_${mode.toUpperCase()}_${uid}`));
11
11
  };
12
12
  const parseJwt = (token) => {
13
13
  const base64Url = token.split('.')[1];
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-5",
4
+ "version": "0.0.11-SNAPSHOT-7",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {