2017-05-18 09:28:18 -04:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
2017-04-12 08:27:57 -04:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
2015-06-14 23:53:32 -08:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
2016-09-29 10:58:30 -04:00
|
|
|
import React from 'react';
|
2015-10-30 11:35:16 -04:00
|
|
|
|
2016-03-14 08:50:46 -04:00
|
|
|
import PreferenceStore from 'stores/preference_store.jsx';
|
2016-04-05 09:21:20 -04:00
|
|
|
import * as Utils from 'utils/utils.jsx';
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2016-09-29 10:58:30 -04:00
|
|
|
import SidebarHeaderDropdown from './sidebar_header_dropdown.jsx';
|
2016-03-14 08:50:46 -04:00
|
|
|
import {Tooltip, OverlayTrigger} from 'react-bootstrap';
|
|
|
|
|
|
2017-01-23 06:11:37 -03:00
|
|
|
import {Preferences, TutorialSteps, Constants} from 'utils/constants.jsx';
|
2016-04-05 09:21:20 -04:00
|
|
|
import {createMenuTip} from 'components/tutorial/tutorial_tip.jsx';
|
2017-06-06 09:45:36 -04:00
|
|
|
import StatusDropdown from 'components/status_dropdown/index.jsx';
|
2016-04-05 09:21:20 -04:00
|
|
|
|
2015-08-31 09:35:31 -07:00
|
|
|
export default class SidebarHeader extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
2015-07-23 14:59:43 +05:00
|
|
|
|
2015-10-30 11:35:16 -04:00
|
|
|
this.state = this.getStateFromStores();
|
|
|
|
|
}
|
2016-09-29 10:58:30 -04:00
|
|
|
|
2015-10-30 11:35:16 -04:00
|
|
|
componentDidMount() {
|
|
|
|
|
PreferenceStore.addChangeListener(this.onPreferenceChange);
|
2017-06-06 09:45:36 -04:00
|
|
|
window.addEventListener('resize', this.handleResize);
|
2015-10-30 11:35:16 -04:00
|
|
|
}
|
2016-09-29 10:58:30 -04:00
|
|
|
|
2015-10-30 11:35:16 -04:00
|
|
|
componentWillUnmount() {
|
|
|
|
|
PreferenceStore.removeChangeListener(this.onPreferenceChange);
|
2017-06-06 09:45:36 -04:00
|
|
|
window.removeEventListener('resize', this.handleResize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleResize = () => {
|
|
|
|
|
const isMobile = Utils.isMobile();
|
|
|
|
|
this.setState({isMobile});
|
2015-10-30 11:35:16 -04:00
|
|
|
}
|
2016-09-29 10:58:30 -04:00
|
|
|
|
2017-06-06 09:45:36 -04:00
|
|
|
getPreferences = () => {
|
|
|
|
|
if (!this.props.currentUser) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
2016-02-08 07:26:10 -05:00
|
|
|
const tutorialStep = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, this.props.currentUser.id, 999);
|
2017-06-06 09:45:36 -04:00
|
|
|
const showTutorialTip = tutorialStep === TutorialSteps.MENU_POPOVER && !Utils.isMobile();
|
2015-10-30 11:35:16 -04:00
|
|
|
|
2017-06-06 09:45:36 -04:00
|
|
|
return {showTutorialTip};
|
2015-10-30 11:35:16 -04:00
|
|
|
}
|
2016-09-29 10:58:30 -04:00
|
|
|
|
2017-06-06 09:45:36 -04:00
|
|
|
getStateFromStores = () => {
|
|
|
|
|
const preferences = this.getPreferences();
|
|
|
|
|
const isMobile = Utils.isMobile();
|
|
|
|
|
return {...preferences, isMobile};
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
2016-09-29 10:58:30 -04:00
|
|
|
|
2017-06-06 09:45:36 -04:00
|
|
|
onPreferenceChange = () => {
|
|
|
|
|
this.setState(this.getPreferences());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleDropdown = (e) => {
|
2015-09-17 22:00:33 -07:00
|
|
|
e.preventDefault();
|
2016-09-13 13:00:48 -03:00
|
|
|
|
2016-09-29 10:58:30 -04:00
|
|
|
this.refs.dropdown.toggleDropdown();
|
2015-08-31 09:35:31 -07:00
|
|
|
}
|
2016-09-29 10:58:30 -04:00
|
|
|
|
2017-06-06 09:45:36 -04:00
|
|
|
renderStatusDropdown = () => {
|
|
|
|
|
if (this.state.isMobile) {
|
2015-07-15 09:03:28 -07:00
|
|
|
return null;
|
|
|
|
|
}
|
2017-06-06 09:45:36 -04:00
|
|
|
return (
|
|
|
|
|
<StatusDropdown/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2017-06-06 09:45:36 -04:00
|
|
|
render() {
|
|
|
|
|
const statusDropdown = this.renderStatusDropdown();
|
2015-08-04 09:40:58 -07:00
|
|
|
|
2015-10-30 11:35:16 -04:00
|
|
|
let tutorialTip = null;
|
|
|
|
|
if (this.state.showTutorialTip) {
|
2016-04-05 09:21:20 -04:00
|
|
|
tutorialTip = createMenuTip(this.toggleDropdown);
|
2015-10-30 11:35:16 -04:00
|
|
|
}
|
|
|
|
|
|
2016-12-01 23:23:28 +01:00
|
|
|
let teamNameWithToolTip = null;
|
|
|
|
|
if (this.props.teamDescription === '') {
|
|
|
|
|
teamNameWithToolTip = (
|
|
|
|
|
<div className='team__name'>{this.props.teamDisplayName}</div>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
teamNameWithToolTip = (
|
|
|
|
|
<OverlayTrigger
|
|
|
|
|
trigger={['hover', 'focus']}
|
2017-01-23 06:11:37 -03:00
|
|
|
delayShow={Constants.OVERLAY_TIME_DELAY}
|
2016-12-01 23:23:28 +01:00
|
|
|
placement='bottom'
|
|
|
|
|
overlay={<Tooltip id='team-name__tooltip'>{this.props.teamDescription}</Tooltip>}
|
|
|
|
|
ref='descriptionOverlay'
|
|
|
|
|
>
|
|
|
|
|
<div className='team__name'>{this.props.teamDisplayName}</div>
|
|
|
|
|
</OverlayTrigger>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-14 23:53:32 -08:00
|
|
|
return (
|
2015-08-04 09:40:58 -07:00
|
|
|
<div className='team__header theme'>
|
2015-10-30 11:35:16 -04:00
|
|
|
{tutorialTip}
|
2017-06-06 09:45:36 -04:00
|
|
|
<div className='header__info'>
|
|
|
|
|
<div className='user__name'>{'@' + this.props.currentUser.username}</div>
|
|
|
|
|
{teamNameWithToolTip}
|
2017-01-06 22:11:42 +05:00
|
|
|
</div>
|
2016-09-29 10:58:30 -04:00
|
|
|
<SidebarHeaderDropdown
|
2015-08-31 09:35:31 -07:00
|
|
|
ref='dropdown'
|
|
|
|
|
teamType={this.props.teamType}
|
2015-10-01 17:52:47 -07:00
|
|
|
teamDisplayName={this.props.teamDisplayName}
|
|
|
|
|
teamName={this.props.teamName}
|
2016-02-08 07:26:10 -05:00
|
|
|
currentUser={this.props.currentUser}
|
2015-08-31 09:35:31 -07:00
|
|
|
/>
|
2017-06-06 09:45:36 -04:00
|
|
|
{statusDropdown}
|
2015-06-14 23:53:32 -08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-08-31 09:35:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SidebarHeader.defaultProps = {
|
2016-02-08 07:26:10 -05:00
|
|
|
teamDisplayName: '',
|
2016-12-01 23:23:28 +01:00
|
|
|
teamDescription: '',
|
2015-08-31 09:35:31 -07:00
|
|
|
teamType: ''
|
|
|
|
|
};
|
|
|
|
|
SidebarHeader.propTypes = {
|
2017-05-18 09:28:18 -04:00
|
|
|
teamDisplayName: PropTypes.string,
|
|
|
|
|
teamDescription: PropTypes.string,
|
|
|
|
|
teamName: PropTypes.string,
|
|
|
|
|
teamType: PropTypes.string,
|
|
|
|
|
currentUser: PropTypes.object
|
2015-08-31 09:35:31 -07:00
|
|
|
};
|