Files
mattermost/webapp/components/sidebar_header.jsx
Christopher Speller 2bbedd9def Updating client dependencies. Switching to yarn. (#6433)
* Updating client dependancies. Switching to using yarn.

* Updating React

* Moving pure components to using function syntax (performance gains with newer react version)

* Updating client dependancies.

* Ignore .yarninstall

* Enabling pre-lockfile because it's the entire point of using yarn.

* Removing old webpack config

* Moving to new prop-types

* Fixing ESLint Errors

* Updating jest snapshots.

* Cleaning up package.json
2017-05-18 09:28:18 -04:00

127 lines
3.8 KiB
JavaScript

import PropTypes from 'prop-types';
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import Client from 'client/web_client.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import * as Utils from 'utils/utils.jsx';
import SidebarHeaderDropdown from './sidebar_header_dropdown.jsx';
import {Tooltip, OverlayTrigger} from 'react-bootstrap';
import {Preferences, TutorialSteps, Constants} from 'utils/constants.jsx';
import {createMenuTip} from 'components/tutorial/tutorial_tip.jsx';
export default class SidebarHeader extends React.Component {
constructor(props) {
super(props);
this.toggleDropdown = this.toggleDropdown.bind(this);
this.onPreferenceChange = this.onPreferenceChange.bind(this);
this.state = this.getStateFromStores();
}
componentDidMount() {
PreferenceStore.addChangeListener(this.onPreferenceChange);
}
componentWillUnmount() {
PreferenceStore.removeChangeListener(this.onPreferenceChange);
}
getStateFromStores() {
const tutorialStep = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, this.props.currentUser.id, 999);
return {showTutorialTip: tutorialStep === TutorialSteps.MENU_POPOVER && !Utils.isMobile()};
}
onPreferenceChange() {
this.setState(this.getStateFromStores());
}
toggleDropdown(e) {
e.preventDefault();
this.refs.dropdown.toggleDropdown();
}
render() {
var me = this.props.currentUser;
var profilePicture = null;
if (!me) {
return null;
}
if (me.last_picture_update) {
profilePicture = (
<img
className='user__picture'
src={Client.getUsersRoute() + '/' + me.id + '/image?time=' + me.last_picture_update}
/>
);
}
let tutorialTip = null;
if (this.state.showTutorialTip) {
tutorialTip = createMenuTip(this.toggleDropdown);
}
let teamNameWithToolTip = null;
if (this.props.teamDescription === '') {
teamNameWithToolTip = (
<div className='team__name'>{this.props.teamDisplayName}</div>
);
} else {
teamNameWithToolTip = (
<OverlayTrigger
trigger={['hover', 'focus']}
delayShow={Constants.OVERLAY_TIME_DELAY}
placement='bottom'
overlay={<Tooltip id='team-name__tooltip'>{this.props.teamDescription}</Tooltip>}
ref='descriptionOverlay'
>
<div className='team__name'>{this.props.teamDisplayName}</div>
</OverlayTrigger>
);
}
return (
<div className='team__header theme'>
{tutorialTip}
<div>
{profilePicture}
<div className='header__info'>
<div className='user__name'>{'@' + me.username}</div>
{teamNameWithToolTip}
</div>
</div>
<SidebarHeaderDropdown
ref='dropdown'
teamType={this.props.teamType}
teamDisplayName={this.props.teamDisplayName}
teamName={this.props.teamName}
currentUser={this.props.currentUser}
/>
</div>
);
}
}
SidebarHeader.defaultProps = {
teamDisplayName: '',
teamDescription: '',
teamType: ''
};
SidebarHeader.propTypes = {
teamDisplayName: PropTypes.string,
teamDescription: PropTypes.string,
teamName: PropTypes.string,
teamType: PropTypes.string,
currentUser: PropTypes.object
};