import React from 'react'; import { Col, FormGroup, InputGroup, Form, FormControl, Label, OverlayTrigger, Row, Tooltip, Collapse, } from 'react-bootstrap'; import Button from '../../components/Button'; import SouthPane from './SouthPane'; import Timer from '../../components/Timer'; import SqlEditorLeftBar from './SqlEditorLeftBar'; import AceEditorWrapper from './AceEditorWrapper'; import { STATE_BSSTYLE_MAP } from '../constants.js'; import RunQueryActionButton from './RunQueryActionButton'; const propTypes = { actions: React.PropTypes.object.isRequired, height: React.PropTypes.string.isRequired, database: React.PropTypes.object, latestQuery: React.PropTypes.object, networkOn: React.PropTypes.bool, tables: React.PropTypes.array.isRequired, editorQueries: React.PropTypes.array.isRequired, dataPreviewQueries: React.PropTypes.array.isRequired, queryEditor: React.PropTypes.object.isRequired, hideLeftBar: React.PropTypes.bool, }; const defaultProps = { networkOn: true, database: null, latestQuery: null, hideLeftBar: false, }; class SqlEditor extends React.PureComponent { constructor(props) { super(props); this.state = { autorun: props.queryEditor.autorun, ctas: '', }; } componentDidMount() { this.onMount(); } onMount() { if (this.state.autorun) { this.setState({ autorun: false }); this.props.actions.queryEditorSetAutorun(this.props.queryEditor, false); this.startQuery(); } } runQuery(runAsync = false) { let effectiveRunAsync = runAsync; if (!this.props.database.allow_run_sync) { effectiveRunAsync = true; } this.startQuery(effectiveRunAsync); } startQuery(runAsync = false, ctas = false) { const qe = this.props.queryEditor; const query = { dbId: qe.dbId, sql: qe.selectedText ? qe.selectedText : qe.sql, sqlEditorId: qe.id, tab: qe.title, schema: qe.schema, tempTableName: ctas ? this.state.ctas : '', runAsync, ctas, }; this.props.actions.runQuery(query); this.props.actions.setActiveSouthPaneTab('Results'); } stopQuery() { this.props.actions.stopQuery(this.props.latestQuery); } createTableAs() { this.startQuery(true, true); } setQueryEditorSql(sql) { this.props.actions.queryEditorSetSql(this.props.queryEditor, sql); } ctasChanged(event) { this.setState({ ctas: event.target.value }); } sqlEditorHeight() { // quick hack to make the white bg of the tab stretch full height. const tabNavHeight = 40; const navBarHeight = 56; const mysteryVerticalHeight = 50; return window.innerHeight - tabNavHeight - navBarHeight - mysteryVerticalHeight; } render() { let limitWarning = null; if (this.props.latestQuery && this.props.latestQuery.limit_reached) { const tooltip = ( It appears that the number of rows in the query results displayed was limited on the server side to the {this.props.latestQuery.rows} limit. ); limitWarning = ( ); } let ctasControls; if (this.props.database && this.props.database.allow_ctas) { const ctasToolTip = 'Create table as with query results'; ctasControls = ( ); } const editorBottomBar = (
{ctasControls}
{limitWarning} {this.props.latestQuery && }
); return (
{editorBottomBar}
); } } SqlEditor.defaultProps = defaultProps; SqlEditor.propTypes = propTypes; export default SqlEditor;