Files
ohif-viewer/platform/viewer/src/components/Header/Header.js
T

124 lines
3.0 KiB
JavaScript
Raw Normal View History

2019-11-28 02:48:27 -03:00
import React, { useState, useEffect } from 'react';
2019-11-05 23:07:03 -05:00
import { Link, withRouter } from 'react-router-dom';
import { withTranslation } from 'react-i18next';
2019-11-05 23:07:03 -05:00
import PropTypes from 'prop-types';
import { Dropdown, AboutContent, withModal } from '@ohif/ui';
import { UserPreferences } from './../UserPreferences';
import OHIFLogo from '../OHIFLogo/OHIFLogo.js';
2019-11-05 23:07:03 -05:00
import './Header.css';
// Context
import AppContext from './../../context/AppContext';
2019-11-28 02:48:27 -03:00
function Header(props) {
const {
t,
user,
userManager,
modal: { show },
home,
location,
children,
} = props;
2019-11-28 02:48:27 -03:00
const [options, setOptions] = useState([]);
2019-11-28 02:48:27 -03:00
useEffect(() => {
const optionsValue = [
{
title: t('About'),
2019-06-16 22:51:28 -05:00
icon: { name: 'info' },
2019-11-05 23:07:03 -05:00
onClick: () =>
2019-11-28 02:48:27 -03:00
show({
content: AboutContent,
2019-11-05 23:07:03 -05:00
title: t('OHIF Viewer - About'),
}),
2019-05-29 08:39:54 -04:00
},
{
2019-11-28 02:48:27 -03:00
title: t('Preferences'),
icon: {
name: 'user',
},
onClick: () =>
2019-11-28 02:48:27 -03:00
show({
content: UserPreferences,
title: t('User Preferences'),
}),
},
];
2019-11-05 23:07:03 -05:00
if (user && userManager) {
2019-11-28 02:48:27 -03:00
optionsValue.push({
title: t('Logout'),
icon: { name: 'power-off' },
2019-11-05 23:07:03 -05:00
onClick: () => userManager.signoutRedirect(),
});
}
2019-11-28 02:48:27 -03:00
setOptions(optionsValue);
}, [setOptions, show, t, user, userManager]);
const { appConfig = {} } = AppContext;
const showStudyList =
appConfig.showStudyList !== undefined ? appConfig.showStudyList : true;
2019-01-01 09:23:17 -02:00
2019-10-28 14:47:57 -04:00
// ANTD -- Hamburger, Drawer, Menu
2019-11-28 02:48:27 -03:00
return (
<>
<div className="notification-bar">{t('INVESTIGATIONAL USE ONLY')}</div>
<div className={`entry-header ${home ? 'header-big' : ''}`}>
<div className="header-left-box">
{location && location.studyLink && (
<Link
to={location.studyLink}
className="header-btn header-viewerLink"
>
{t('Back to Viewer')}
</Link>
)}
2019-10-28 14:47:57 -04:00
2019-11-28 02:48:27 -03:00
{children}
2019-10-28 14:47:57 -04:00
2019-11-28 02:48:27 -03:00
{showStudyList && !home && (
<Link
className="header-btn header-studyListLinkSection"
to={{
pathname: '/',
state: { studyLink: location.pathname },
}}
>
{t('Study list')}
</Link>
)}
</div>
2019-10-28 14:47:57 -04:00
2019-11-28 02:48:27 -03:00
<div className="header-menu">
<span className="research-use">{t('INVESTIGATIONAL USE ONLY')}</span>
<Dropdown title={t('Options')} list={options} align="right" />
</div>
2019-11-28 02:48:27 -03:00
</div>
</>
);
}
2019-01-08 10:48:57 +01:00
2019-11-28 02:48:27 -03:00
Header.propTypes = {
home: PropTypes.bool.isRequired,
location: PropTypes.object.isRequired,
children: PropTypes.node,
t: PropTypes.func.isRequired,
userManager: PropTypes.object,
user: PropTypes.object,
modal: PropTypes.object,
};
Header.defaultProps = {
home: true,
children: OHIFLogo(),
};
2019-11-05 23:07:03 -05:00
export default withTranslation(['Header', 'AboutModal'])(
withRouter(withModal(Header))
);