import React, {Component, PropTypes} from 'react'; import classnames from 'classnames'; import {ipcRenderer, shell} from 'electron'; import {Dropdown, DropdownDivider, DropdownButton, DropdownItem, DropdownHint, DropdownRight} from '../base/dropdown'; import PromptModal from '../modals/PromptModal'; import SettingsModal, {TAB_INDEX_EXPORT} from '../modals/SettingsModal'; import * as models from '../../../models'; import {getAppVersion} from '../../../common/constants'; import {showModal} from '../modals/index'; import {trackEvent} from '../../../analytics/index'; import Link from '../base/Link'; import WorkspaceSettingsModal from '../modals/WorkspaceSettingsModal'; import WorkspaceShareSettingsModal from '../modals/WorkspaceShareSettingsModal'; import * as session from '../../../sync/session'; import PromptButton from '../base/PromptButton'; import LoginModal from '../modals/LoginModal'; class WorkspaceDropdown extends Component { state = { loggedIn: false }; _handleDropdownOpen = () => { if (this.state.loggedIn !== session.isLoggedIn()) { this.setState({loggedIn: session.isLoggedIn()}); } }; _handleShowLogin = () => { showModal(LoginModal); }; _handleShowExport = () => showModal(SettingsModal, TAB_INDEX_EXPORT); _handleShowSettings = () => showModal(SettingsModal); _handleShowWorkspaceSettings = () => { showModal(WorkspaceSettingsModal, { workspace: this.props.activeWorkspace, }); }; _handleShowShareSettings = () => { showModal(WorkspaceShareSettingsModal, { workspace: this.props.activeWorkspace, }); }; _handleSwitchWorkspace = workspaceId => { this.props.handleSetActiveWorkspace(workspaceId); trackEvent('Workspace', 'Switch'); }; _handleWorkspaceCreate = async noTrack => { const name = await showModal(PromptModal, { headerName: 'Create New Workspace', defaultValue: 'My Workspace', submitName: 'Create', selectText: true }); const workspace = await models.workspace.create({name}); this.props.handleSetActiveWorkspace(workspace._id); if (!noTrack) { trackEvent('Workspace', 'Create'); } }; render () { const { className, workspaces, activeWorkspace, isLoading, ...other } = this.props; const nonActiveWorkspaces = workspaces.filter(w => w._id !== activeWorkspace._id); const classes = classnames(className, 'wide', 'workspace-dropdown'); return (

{isLoading ? : null} {" "}
{activeWorkspace.name}

{activeWorkspace.name} Workspace Settings Share {activeWorkspace.name} Switch Workspace {nonActiveWorkspaces.map(w => ( To {w.name} ))} New Workspace Insomnia Version {getAppVersion()} App Settings Import/Export {!this.state.loggedIn ? [ Log In , Upgrade to Plus , ] : [ Manage Account , Log Out , ]}
) } } WorkspaceDropdown.propTypes = { isLoading: PropTypes.bool.isRequired, handleImportFile: PropTypes.func.isRequired, handleExportFile: PropTypes.func.isRequired, handleSetActiveWorkspace: PropTypes.func.isRequired, workspaces: PropTypes.arrayOf(PropTypes.object).isRequired, activeWorkspace: PropTypes.object.isRequired, }; export default WorkspaceDropdown;