import React, {Component, PropTypes} from 'react'; import {bindActionCreators} from 'redux'; import {connect} from 'react-redux' import Dropdown from '../components/base/Dropdown'; import DropdownDivider from '../components/base/DropdownDivider'; import PromptModal from '../components/PromptModal'; import SettingsModal from '../components/SettingsModal'; import * as WorkspaceActions from '../redux/modules/workspaces'; import * as GlobalActions from '../redux/modules/global'; import * as db from '../database'; class WorkspaceDropdown extends Component { _promptUpdateName () { const workspace = this._getActiveWorkspace(this.props); PromptModal.show({ headerName: 'Rename Workspace', defaultValue: workspace.name }).then(name => { db.workspaceUpdate(workspace, {name}); }) } _workspaceCreate () { db.workspaceCreate({name: 'New Workspace'}).then(workspace => { this.props.actions.workspaces.activate(workspace); }); } _getActiveWorkspace (props) { // TODO: Factor this out into a selector const {entities, workspaces} = props || this.props; let workspace = entities.workspaces[workspaces.activeId]; if (!workspace) { workspace = entities.workspaces[Object.keys(entities.workspaces)[0]]; } return workspace; } render () { const {actions, loading, entities, ...other} = this.props; const allWorkspaces = Object.keys(entities.workspaces).map(id => entities.workspaces[id]); const workspace = this._getActiveWorkspace(this.props); return ( ) } } WorkspaceDropdown.propTypes = { loading: PropTypes.bool.isRequired, workspaces: PropTypes.shape({ activeId: PropTypes.string }), entities: PropTypes.shape({ workspaces: PropTypes.object.isRequired }).isRequired, actions: PropTypes.shape({ workspaces: PropTypes.shape({ activate: PropTypes.func.isRequired, }), global: PropTypes.shape({ importFile: PropTypes.func.isRequired, exportFile: PropTypes.func.isRequired, }) }) }; function mapStateToProps (state) { return { workspaces: state.workspaces, entities: state.entities, actions: state.actions, loading: state.global.loading }; } function mapDispatchToProps (dispatch) { return { actions: { workspaces: bindActionCreators(WorkspaceActions, dispatch), global: bindActionCreators(GlobalActions, dispatch) } } } export default connect( mapStateToProps, mapDispatchToProps )(WorkspaceDropdown);