import React from 'react'; import { DropdownButton, MenuItem, Tab, Tabs } from 'react-bootstrap'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import * as Actions from '../actions'; import SqlEditor from './SqlEditor'; import shortid from 'shortid'; let queryCount = 1; class QueryEditors extends React.Component { renameTab(qe) { const newTitle = prompt('Enter a new title for the tab'); if (newTitle) { this.props.actions.queryEditorSetTitle(qe, newTitle); } } activeQueryEditor() { const qeid = this.props.tabHistory[this.props.tabHistory.length - 1]; for (let i = 0; i < this.props.queryEditors.length; i++) { const qe = this.props.queryEditors[i]; if (qe.id === qeid) { return qe; } } return null; } newQueryEditor() { queryCount++; const activeQueryEditor = this.activeQueryEditor(); const qe = { id: shortid.generate(), title: `Untitled Query ${queryCount}`, dbId: (activeQueryEditor) ? activeQueryEditor.dbId : null, schema: (activeQueryEditor) ? activeQueryEditor.schema : null, autorun: false, sql: 'SELECT ...', }; this.props.actions.addQueryEditor(qe); } handleSelect(key) { if (key === 'add_tab') { this.newQueryEditor(); } else { this.props.actions.setActiveQueryEditor({ id: key }); } } render() { const editors = this.props.queryEditors.map((qe, i) => { let latestQuery = this.props.queries[qe.latestQueryId]; const database = this.props.databases[qe.dbId]; const state = (latestQuery) ? latestQuery.state : ''; const tabTitle = (