2017-02-28 21:32:23 +00:00
|
|
|
import React, {PureComponent, PropTypes} from 'react';
|
2016-11-16 17:18:39 +00:00
|
|
|
import classnames from 'classnames';
|
2017-03-08 05:52:17 +00:00
|
|
|
import EnvironmentsModal from '../modals/workspace-environments-edit-modal';
|
2016-12-21 23:37:48 +00:00
|
|
|
import {Dropdown, DropdownDivider, DropdownButton, DropdownItem, DropdownHint} from '../base/dropdown';
|
2016-11-16 17:18:39 +00:00
|
|
|
import {showModal} from '../modals/index';
|
2016-11-23 19:33:24 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2016-11-16 17:18:39 +00:00
|
|
|
|
2017-02-28 21:32:23 +00:00
|
|
|
class EnvironmentsDropdown extends PureComponent {
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
className,
|
|
|
|
workspace,
|
|
|
|
environments,
|
|
|
|
activeEnvironment,
|
|
|
|
handleChangeEnvironment,
|
|
|
|
...other
|
|
|
|
} = this.props;
|
2016-11-16 17:18:39 +00:00
|
|
|
|
2017-02-28 21:32:23 +00:00
|
|
|
// NOTE: Base environment might not exist if the users hasn't managed environments yet.
|
|
|
|
const baseEnvironment = environments.find(e => e.parentId === workspace._id);
|
|
|
|
const subEnvironments = environments.filter(
|
|
|
|
e => e.parentId === (baseEnvironment && baseEnvironment._id)
|
|
|
|
);
|
|
|
|
|
|
|
|
let description;
|
|
|
|
if (!activeEnvironment || activeEnvironment === baseEnvironment) {
|
|
|
|
description = 'No Environment';
|
|
|
|
} else {
|
|
|
|
description = activeEnvironment.name;
|
|
|
|
}
|
2016-11-16 17:18:39 +00:00
|
|
|
|
2017-02-28 21:32:23 +00:00
|
|
|
return (
|
|
|
|
<Dropdown {...other} className={classnames(className, 'wide')}>
|
|
|
|
<DropdownButton className="btn btn--super-compact no-wrap">
|
|
|
|
<div className="sidebar__menu__thing">
|
|
|
|
<span>{description}</span>
|
2017-03-03 20:09:08 +00:00
|
|
|
{' '}
|
2017-03-08 05:52:17 +00:00
|
|
|
<i className="fa fa-caret-down"/>
|
2017-02-28 21:32:23 +00:00
|
|
|
</div>
|
|
|
|
</DropdownButton>
|
|
|
|
<DropdownDivider>Switch Environment</DropdownDivider>
|
|
|
|
{subEnvironments.map(environment => (
|
|
|
|
<DropdownItem key={environment._id}
|
|
|
|
onClick={e => {
|
|
|
|
handleChangeEnvironment(environment._id);
|
|
|
|
trackEvent('Environment', 'Activate');
|
|
|
|
}}>
|
2017-03-08 05:52:17 +00:00
|
|
|
<i className="fa fa-random"/> Use <strong>{environment.name}</strong>
|
2017-02-28 21:32:23 +00:00
|
|
|
</DropdownItem>
|
|
|
|
))}
|
|
|
|
<DropdownItem onClick={() => {
|
|
|
|
baseEnvironment && handleChangeEnvironment(null);
|
|
|
|
trackEvent('Environment', 'Deactivate');
|
|
|
|
}}>
|
2017-03-08 05:52:17 +00:00
|
|
|
<i className="fa fa-empty"/> No Environment
|
2016-11-16 17:18:39 +00:00
|
|
|
</DropdownItem>
|
2017-02-28 21:32:23 +00:00
|
|
|
<DropdownDivider>General</DropdownDivider>
|
|
|
|
<DropdownItem onClick={e => showModal(EnvironmentsModal, workspace)}>
|
|
|
|
<i className="fa fa-wrench"></i> Manage Environments
|
|
|
|
<DropdownHint char="E"/>
|
|
|
|
</DropdownItem>
|
|
|
|
</Dropdown>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2017-02-28 21:32:23 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-16 17:18:39 +00:00
|
|
|
|
|
|
|
EnvironmentsDropdown.propTypes = {
|
|
|
|
// Functions
|
|
|
|
handleChangeEnvironment: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
// Other
|
|
|
|
workspace: PropTypes.object.isRequired,
|
|
|
|
environments: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
|
|
|
|
|
// Optional
|
2017-03-08 05:52:17 +00:00
|
|
|
activeEnvironment: PropTypes.object,
|
|
|
|
className: PropTypes.string
|
2016-11-16 17:18:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default EnvironmentsDropdown;
|