tycho-components 0.12.3 → 0.13.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.
@@ -4,7 +4,6 @@ type Props = {
4
4
  tool: string;
5
5
  redirect?: string;
6
6
  autoload?: boolean;
7
- freeAccess?: boolean;
8
7
  hideKeyboard?: boolean;
9
8
  hideReplaceAll?: boolean;
10
9
  parser?: boolean;
@@ -20,5 +19,5 @@ type Props = {
20
19
  navigateNotLogged?: () => void;
21
20
  helpActions?: HelpAction[];
22
21
  };
23
- export default function Header({ tool, redirect, autoload, freeAccess, hideKeyboard, hideReplaceAll, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, navigateNotLogged, helpActions, }: Props): import("react/jsx-runtime").JSX.Element;
22
+ export default function Header({ tool, redirect, autoload, hideKeyboard, hideReplaceAll, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, navigateNotLogged, helpActions, }: Props): import("react/jsx-runtime").JSX.Element;
24
23
  export {};
@@ -14,7 +14,7 @@ import HeaderReplaceAll from './HeaderReplaceAll';
14
14
  import HeaderUser from './HeaderUser';
15
15
  import HelpButton from './HelpButton';
16
16
  import './styles.scss';
17
- export default function Header({ tool, redirect, autoload, freeAccess, hideKeyboard, hideReplaceAll, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, navigateNotLogged = () => {
17
+ export default function Header({ tool, redirect, autoload, hideKeyboard, hideReplaceAll, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, navigateNotLogged = () => {
18
18
  location.href = '/auth';
19
19
  }, helpActions, }) {
20
20
  const { t } = useTranslation('header');
@@ -24,5 +24,5 @@ export default function Header({ tool, redirect, autoload, freeAccess, hideKeybo
24
24
  const homeTextsClass = cx('app-title', {
25
25
  pointer: navigateHome !== undefined,
26
26
  });
27
- return (_jsxs("div", { className: "ds-header", children: [_jsxs("div", { className: "header-left", children: [_jsx(HeaderApps, { freeAccess: freeAccess }), _jsxs("div", { className: homeTextsClass, onClick: () => navigateHome && navigateHome(), children: [_jsx("span", { className: "title", children: t('label.platform') }), _jsx("span", { className: "subtitle", children: tool })] })] }), _jsx("div", { className: "header-center", children: customHeader ? (customHeader) : (_jsx(HeaderCorpora, { redirect: redirect, autoload: autoload, freeAccess: freeAccess, navigateCorpora: navigateCorpora })) }), _jsxs("div", { className: "header-right", children: [!hideReplaceAll && _jsx(HeaderReplaceAll, {}), !hideKeyboard && (_jsx(IconButton, { onClick: () => setOpenKeyboard(!openKeyboard), name: "keyboard", size: "medium", title: t('tooltip.keyboard') })), _jsx(HelpButton, { helpActions: helpActions }), notifications && isLogged() && (_jsx(HeaderNotifications, { uid: notifications.ref, mode: notifications.mode })), _jsx(LanguageSelector, {}), !freeAccess && (_jsx(HeaderUser, { navigateLogout: navigateLogout, navigateNotLogged: navigateNotLogged }))] }), openKeyboard && (_jsx(VirtualKeyboard, { onClose: () => setOpenKeyboard(false), closeLabel: t('button.close'), defaultLayout: keyboardLayout || getCorpus().keyboardLayout || 'english' }))] }));
27
+ return (_jsxs("div", { className: "ds-header", children: [_jsxs("div", { className: "header-left", children: [_jsx(HeaderApps, {}), _jsxs("div", { className: homeTextsClass, onClick: () => navigateHome && navigateHome(), children: [_jsx("span", { className: "title", children: t('label.platform') }), _jsx("span", { className: "subtitle", children: tool })] })] }), _jsx("div", { className: "header-center", children: customHeader ? (customHeader) : (_jsx(HeaderCorpora, { redirect: redirect, autoload: autoload, navigateCorpora: navigateCorpora })) }), _jsxs("div", { className: "header-right", children: [!hideReplaceAll && _jsx(HeaderReplaceAll, {}), !hideKeyboard && (_jsx(IconButton, { onClick: () => setOpenKeyboard(!openKeyboard), name: "keyboard", size: "medium", title: t('tooltip.keyboard') })), _jsx(HelpButton, { helpActions: helpActions }), notifications && isLogged() && (_jsx(HeaderNotifications, { uid: notifications.ref, mode: notifications.mode })), _jsx(LanguageSelector, {}), _jsx(HeaderUser, { navigateLogout: navigateLogout, navigateNotLogged: navigateNotLogged })] }), openKeyboard && (_jsx(VirtualKeyboard, { onClose: () => setOpenKeyboard(false), closeLabel: t('button.close'), defaultLayout: keyboardLayout || getCorpus().keyboardLayout || 'english' }))] }));
28
28
  }
@@ -1,6 +1,2 @@
1
1
  import './style.scss';
2
- type Props = {
3
- freeAccess?: boolean;
4
- };
5
- export default function HeaderApps({ freeAccess }: Props): import("react/jsx-runtime").JSX.Element;
6
- export {};
2
+ export default function HeaderApps(): import("react/jsx-runtime").JSX.Element;
@@ -8,10 +8,10 @@ import { useLoggedUtils } from '../../configs/useLoggedUtils';
8
8
  import { AvailableApps } from '../types/App';
9
9
  import logo from './logo.png';
10
10
  import './style.scss';
11
- export default function HeaderApps({ freeAccess }) {
11
+ export default function HeaderApps() {
12
12
  const { t } = useTranslation('header-app');
13
13
  const { getCorpus, hasCorpus } = useCorpusUtils();
14
- const { hasLexiconAccess, hasParserAccess, isAdminOfAnyCorpus } = useLoggedUtils();
14
+ const { hasLexiconAccess, hasParserAccess, isAdminOfAnyCorpus, isLogged } = useLoggedUtils();
15
15
  const [open, setOpen] = useState(false);
16
16
  const goto = (app, blank) => {
17
17
  const shouldAppendCorpusUid = app.appendCorpusUid !== false;
@@ -26,7 +26,7 @@ export default function HeaderApps({ freeAccess }) {
26
26
  }
27
27
  };
28
28
  const renderItem = (item, idx) => {
29
- if (!item.visibility && freeAccess)
29
+ if (!item.visibility && isLogged())
30
30
  return null;
31
31
  if (item.admin && !isAdminOfAnyCorpus())
32
32
  return null;
@@ -1,9 +1,8 @@
1
- import "./style.scss";
1
+ import './style.scss';
2
2
  type Props = {
3
3
  navigateCorpora?: (uid: string) => void;
4
4
  autoload?: boolean;
5
5
  redirect?: string;
6
- freeAccess?: boolean;
7
6
  };
8
- export default function HeaderCorpora({ navigateCorpora, redirect, autoload, freeAccess, }: Props): import("react/jsx-runtime").JSX.Element;
7
+ export default function HeaderCorpora({ navigateCorpora, redirect, autoload, }: Props): import("react/jsx-runtime").JSX.Element;
9
8
  export {};
@@ -1,16 +1,18 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useEffect, useState } from "react";
3
- import { useTranslation } from "react-i18next";
4
- import { useParams } from "react-router-dom";
5
- import AppModal from "../../AppModal";
6
- import AppPicture from "../../AppPicture";
7
- import { useCorpusUtils } from "../../configs/useCorpusUtils";
8
- import CorpusService from "../types/CorpusService";
9
- import HeaderCorpus from "./HeaderCorpus";
10
- import "./style.scss";
11
- export default function HeaderCorpora({ navigateCorpora, redirect, autoload, freeAccess, }) {
12
- const { t } = useTranslation("header");
2
+ import { useEffect, useState } from 'react';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { useParams } from 'react-router-dom';
5
+ import AppModal from '../../AppModal';
6
+ import AppPicture from '../../AppPicture';
7
+ import { useCorpusUtils } from '../../configs/useCorpusUtils';
8
+ import { useLoggedUtils } from '../../configs/useLoggedUtils';
9
+ import CorpusService from '../types/CorpusService';
10
+ import HeaderCorpus from './HeaderCorpus';
11
+ import './style.scss';
12
+ export default function HeaderCorpora({ navigateCorpora, redirect, autoload, }) {
13
+ const { t } = useTranslation('header');
13
14
  const { setCorpus, getCorpus, hasCorpus } = useCorpusUtils();
15
+ const { isLogged } = useLoggedUtils();
14
16
  const { uid } = useParams();
15
17
  const [corpora, setCorpora] = useState([]);
16
18
  const [openCorpora, setOpenCorpora] = useState(false);
@@ -56,7 +58,7 @@ export default function HeaderCorpora({ navigateCorpora, redirect, autoload, fre
56
58
  }
57
59
  };
58
60
  const handleCorpusClick = () => {
59
- if (freeAccess && hasCorpus()) {
61
+ if (isLogged() && hasCorpus()) {
60
62
  navigateCorpora && navigateCorpora(getCorpus().uid);
61
63
  }
62
64
  else {
@@ -69,5 +71,5 @@ export default function HeaderCorpora({ navigateCorpora, redirect, autoload, fre
69
71
  useEffect(() => {
70
72
  autoload && loadAndApply();
71
73
  }, [autoload]);
72
- return (_jsxs(_Fragment, { children: [hasCorpus() && _jsx(HeaderCorpus, { onClick: handleCorpusClick }), openCorpora && (_jsx(AppModal, { className: "modal-corpora", title: t("label.choose"), close: () => setOpenCorpora(false), children: corpora.map((corpus) => (_jsxs("div", { className: "item", onClick: () => handleChooseCorpus(corpus), children: [_jsx(AppPicture, { src: corpus.picture, title: corpus.name, className: "modal-corpus-image" }), _jsx("span", { children: corpus.name })] }, corpus.uid))) }))] }));
74
+ return (_jsxs(_Fragment, { children: [hasCorpus() && _jsx(HeaderCorpus, { onClick: handleCorpusClick }), openCorpora && (_jsx(AppModal, { className: "modal-corpora", title: t('label.choose'), close: () => setOpenCorpora(false), children: corpora.map((corpus) => (_jsxs("div", { className: "item", onClick: () => handleChooseCorpus(corpus), children: [_jsx(AppPicture, { src: corpus.picture, title: corpus.name, className: "modal-corpus-image" }), _jsx("span", { children: corpus.name })] }, corpus.uid))) }))] }));
73
75
  }
@@ -1,5 +1,6 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { SelectItem } from 'tycho-storybook/dist/SelectField/SelectField';
3
+ import { AppFormField } from '../AppForm/AppFormField';
3
4
  declare const FormUtils: {
4
5
  convertEnum: (values: Record<string, string>, t?: TFunction, prefix?: string) => SelectItem[];
5
6
  convertList: (values: any, labelAttr: string, valueAttr: string) => SelectItem[];
@@ -7,5 +8,6 @@ declare const FormUtils: {
7
8
  booleanOptions: (t: TFunction) => SelectItem[];
8
9
  convertMap: (values: Record<string, any> | undefined) => SelectItem[];
9
10
  sortByLabel: (items: SelectItem[]) => SelectItem[];
11
+ filterFieldsByUserRole: (fields: AppFormField[], hasRole: (role: string) => boolean) => AppFormField[];
10
12
  };
11
13
  export default FormUtils;
@@ -1,3 +1,4 @@
1
+ const filterFieldsByUserRole = (fields, hasRole) => fields.filter((field) => !field.role || hasRole(field.role));
1
2
  const convertEnum = (values, t, prefix) => {
2
3
  if (!t)
3
4
  return Object.entries(values).map(([key, label]) => ({
@@ -52,5 +53,6 @@ const FormUtils = {
52
53
  booleanOptions,
53
54
  convertMap,
54
55
  sortByLabel,
56
+ filterFieldsByUserRole,
55
57
  };
56
58
  export default FormUtils;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.12.3",
4
+ "version": "0.13.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {