import React, {Component, PropTypes} from 'react'; import {ipcRenderer} from 'electron'; import classnames from 'classnames'; import EnvironmentsModal from '../modals/WorkspaceEnvironmentsEditModal'; import {Dropdown, DropdownDivider, DropdownButton, DropdownItem, DropdownHint} from '../base/dropdown'; import {showModal} from '../modals/index'; import {trackEvent} from '../../../analytics/index'; const EnvironmentsDropdown = ({ className, workspace, environments, activeEnvironment, handleChangeEnvironment, ...other }) => { // 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; } return (
{description} {" "}
Switch Environment {subEnvironments.map(environment => ( { handleChangeEnvironment(environment._id); trackEvent('Environment', 'Activate'); }}> Use {environment.name} ))} { baseEnvironment && handleChangeEnvironment(null); trackEvent('Environment', 'Deactivate'); }}> No Environment General showModal(EnvironmentsModal, workspace)}> Manage Environments
) }; EnvironmentsDropdown.propTypes = { // Functions handleChangeEnvironment: PropTypes.func.isRequired, // Other workspace: PropTypes.object.isRequired, environments: PropTypes.arrayOf(PropTypes.object).isRequired, // Optional activeEnvironment: PropTypes.object, }; export default EnvironmentsDropdown;