tycho-components 0.8.22 → 0.8.23

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.
@@ -17,7 +17,8 @@ type Props = {
17
17
  navigateHome?: () => void;
18
18
  navigateCorpora?: (uid: string) => void;
19
19
  navigateLogout?: () => void;
20
+ navigateNotLogged?: () => void;
20
21
  helpActions?: HelpAction[];
21
22
  };
22
- export default function Header({ tool, redirect, autoload, freeAccess, hideKeyboard, hideReplaceAll, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, helpActions, }: Props): import("react/jsx-runtime").JSX.Element;
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;
23
24
  export {};
@@ -14,16 +14,15 @@ 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, helpActions, }) {
17
+ export default function Header({ tool, redirect, autoload, freeAccess, hideKeyboard, hideReplaceAll, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, navigateNotLogged = () => {
18
+ location.href = '/auth';
19
+ }, helpActions, }) {
18
20
  const { t } = useTranslation('header');
19
21
  const { getCorpus, hasCorpus } = useCorpusUtils();
20
22
  const { isLogged } = useLoggedUtils();
21
23
  const [openKeyboard, setOpenKeyboard] = useState(false);
22
- const profileClass = cx('header-profile', {
23
- 'corpora-free': freeAccess && !hasCorpus(),
24
- });
25
24
  const homeTextsClass = cx('app-title', {
26
25
  pointer: navigateHome !== undefined,
27
26
  });
28
- 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 })] })] }), customHeader, !customHeader && (_jsx(HeaderCorpora, { redirect: redirect, autoload: autoload, freeAccess: freeAccess, navigateCorpora: navigateCorpora })), _jsxs("div", { className: profileClass, 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 })] }), 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, { freeAccess: freeAccess }), _jsxs("div", { className: homeTextsClass, onClick: () => navigateHome && navigateHome(), children: [_jsx("span", { className: "title", children: t('label.platform') }), _jsx("span", { className: "subtitle", children: tool })] })] }), 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' }))] }));
29
28
  }
@@ -15,12 +15,17 @@ export default function HeaderCorpora({ navigateCorpora, redirect, autoload, fre
15
15
  const [corpora, setCorpora] = useState([]);
16
16
  const [openCorpora, setOpenCorpora] = useState(false);
17
17
  const load = () => {
18
- CorpusService.available().then((r) => {
18
+ CorpusService.available()
19
+ .then((r) => {
19
20
  setCorpora(r.data);
21
+ })
22
+ .catch(() => {
23
+ setCorpora([]);
20
24
  });
21
25
  };
22
26
  const loadAndApply = () => {
23
- CorpusService.available().then((r) => {
27
+ CorpusService.available()
28
+ .then((r) => {
24
29
  setCorpora(r.data);
25
30
  if (uid) {
26
31
  const selectedCorpus = r.data.find((c) => c.uid === uid);
@@ -35,6 +40,9 @@ export default function HeaderCorpora({ navigateCorpora, redirect, autoload, fre
35
40
  navigateCorpora && navigateCorpora(r.data[0].uid);
36
41
  setCorpus(r.data[0]);
37
42
  }
43
+ })
44
+ .catch(() => {
45
+ setCorpora([]);
38
46
  });
39
47
  };
40
48
  const handleChooseCorpus = (thisCorpus) => {
@@ -1,6 +1,7 @@
1
1
  import './style.scss';
2
2
  type Props = {
3
3
  navigateLogout?: () => void;
4
+ navigateNotLogged: () => void;
4
5
  };
5
- export default function HeaderUser({ navigateLogout }: Props): import("react/jsx-runtime").JSX.Element;
6
+ export default function HeaderUser({ navigateLogout, navigateNotLogged, }: Props): import("react/jsx-runtime").JSX.Element;
6
7
  export {};
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
4
4
  import { Avatar, Icon, ProfileDropdown } from 'tycho-storybook';
5
5
  import { useLoggedUtils } from '../../configs/useLoggedUtils';
6
6
  import './style.scss';
7
- export default function HeaderUser({ navigateLogout }) {
7
+ export default function HeaderUser({ navigateLogout, navigateNotLogged, }) {
8
8
  const { t } = useTranslation('header');
9
9
  const { isLogged, getLogged } = useLoggedUtils();
10
10
  const [open, setOpen] = useState(false);
@@ -12,7 +12,7 @@ export default function HeaderUser({ navigateLogout }) {
12
12
  setOpen(false);
13
13
  window.open(import.meta.env.VITE_APP_RESERVED_URL, '_blank');
14
14
  };
15
- return (_jsxs("div", { className: "header-user-container", children: [isLogged() ? (_jsx(ProfileDropdown, { src: getLogged()?.picture, title: getLogged()?.name || getLogged()?.sub, onClick: (b) => setOpen(b) })) : (_jsx(Avatar, { size: "small", onClick: () => (location.href = '/auth') })), open && isLogged() && (_jsxs("div", { className: "ds-dropdown-list", children: [_jsx("div", { className: "ds-dropdown-itemlist", children: _jsx("span", { className: "label", children: `${t('profile.label.hello')} ${getLogged()?.name || getLogged()?.sub}` }) }), _jsxs("div", { className: "ds-dropdown-itemlist d-none", children: [_jsx(Icon, { name: "colors", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.theme') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: handleProfile, children: [_jsx(Icon, { name: "person", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.home') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", children: [_jsx(Icon, { name: "live_help", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.help') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: () => {
15
+ return (_jsxs("div", { className: "header-user-container", children: [isLogged() ? (_jsx(ProfileDropdown, { src: getLogged()?.picture, title: getLogged()?.name || getLogged()?.sub, onClick: (b) => setOpen(b) })) : (_jsx(Avatar, { size: "small", onClick: navigateNotLogged })), open && isLogged() && (_jsxs("div", { className: "ds-dropdown-list", children: [_jsx("div", { className: "ds-dropdown-itemlist", children: _jsx("span", { className: "label", children: `${t('profile.label.hello')} ${getLogged()?.name || getLogged()?.sub}` }) }), _jsxs("div", { className: "ds-dropdown-itemlist d-none", children: [_jsx(Icon, { name: "colors", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.theme') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: handleProfile, children: [_jsx(Icon, { name: "person", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.home') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", children: [_jsx(Icon, { name: "live_help", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.help') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: () => {
16
16
  setOpen(false);
17
17
  navigateLogout && navigateLogout();
18
18
  }, children: [_jsx(Icon, { name: "logout", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.logout') })] })] }))] }));
@@ -31,13 +31,10 @@
31
31
  }
32
32
  }
33
33
 
34
- > .header-profile {
34
+ .header-right {
35
35
  display: flex;
36
36
  align-items: center;
37
37
  padding-right: var(--spacing-150);
38
-
39
- &.corpora-free {
40
- margin-left: auto;
41
- }
38
+ gap: 8px;
42
39
  }
43
40
  }
@@ -1,10 +1,8 @@
1
1
  .language-container {
2
2
  > .ds-dropdown-container {
3
3
  .ds-dropdown-button {
4
- padding-left: 8px;
5
-
6
4
  .label {
7
- margin-right: var(--spacing-100);
5
+ margin: 0px var(--spacing-100);
8
6
  }
9
7
  }
10
8
 
@@ -9,14 +9,18 @@ const api = axios.create({
9
9
  },
10
10
  baseURL: import.meta.env.VITE_APP_URL_API,
11
11
  });
12
+ const isStorybook = () => typeof window !== 'undefined' &&
13
+ (window.location.port === '6006' || window.__STORYBOOK__);
12
14
  api.interceptors.response.use((response) => response, async (error) => {
13
15
  if (error.response?.status === 401) {
14
16
  CookieStorage.removeJwtToken();
15
17
  sessionStorage.clear();
16
18
  localStorage.clear();
17
- window.location.replace(import.meta.env.VITE_APP_AUTH_URL);
19
+ if (!isStorybook()) {
20
+ window.location.replace(import.meta.env.VITE_APP_AUTH_URL);
21
+ }
18
22
  }
19
- else if (error.response?.status === 403) {
23
+ else if (error.response?.status === 403 && !isStorybook()) {
20
24
  window.location.href = `${import.meta.env.VITE_APP_PUBLIC_URL}/unauthorized`;
21
25
  }
22
26
  else if (error.status === null) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.8.22",
4
+ "version": "0.8.23",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {