superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: [sql lab] using react-split-pane (#3363)
Date Sun, 27 Aug 2017 22:01:26 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new aff7a82  [sql lab] using react-split-pane (#3363)
aff7a82 is described below

commit aff7a826647167862d9ad765184f7c3fa54355a6
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Sun Aug 27 15:01:24 2017 -0700

    [sql lab] using react-split-pane (#3363)
    
    * [sql lab] using react-split-pane
    
    * padding
---
 .../SqlLab/components/AceEditorWrapper.jsx         |   4 +-
 .../javascripts/SqlLab/components/ResultSet.jsx    |   6 +-
 .../javascripts/SqlLab/components/SouthPane.jsx    |  38 +-------
 .../javascripts/SqlLab/components/SqlEditor.jsx    | 108 +++++++++++++--------
 superset/assets/javascripts/SqlLab/main.less       |   6 +-
 superset/assets/package.json                       |   1 +
 6 files changed, 81 insertions(+), 82 deletions(-)

diff --git a/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx b/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx
index 15adf0b..a66d80e 100644
--- a/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx
+++ b/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx
@@ -32,6 +32,7 @@ const propTypes = {
   sql: PropTypes.string.isRequired,
   tables: PropTypes.array,
   queryEditor: PropTypes.object.isRequired,
+  height: PropTypes.string,
 };
 
 const defaultProps = {
@@ -125,8 +126,7 @@ class AceEditorWrapper extends React.PureComponent {
         theme="github"
         onLoad={this.onEditorLoad.bind(this)}
         onBlur={this.onBlur.bind(this)}
-        minLines={12}
-        maxLines={12}
+        height={this.props.height}
         onChange={this.textChange.bind(this)}
         width="100%"
         editorProps={{ $blockScrolling: true }}
diff --git a/superset/assets/javascripts/SqlLab/components/ResultSet.jsx b/superset/assets/javascripts/SqlLab/components/ResultSet.jsx
index 79c6d9c..b317ac3 100644
--- a/superset/assets/javascripts/SqlLab/components/ResultSet.jsx
+++ b/superset/assets/javascripts/SqlLab/components/ResultSet.jsx
@@ -27,7 +27,7 @@ const defaultProps = {
   cache: false,
 };
 
-const RESULT_SET_CONTROLS_HEIGHT = 46;
+const SEARCH_HEIGHT = 46;
 
 export default class ResultSet extends React.PureComponent {
   constructor(props) {
@@ -36,7 +36,6 @@ export default class ResultSet extends React.PureComponent {
       searchText: '',
       showModal: false,
       data: null,
-      height: props.search ? props.height - RESULT_SET_CONTROLS_HEIGHT : props.height,
     };
   }
   componentDidMount() {
@@ -144,6 +143,7 @@ export default class ResultSet extends React.PureComponent {
   }
   render() {
     const query = this.props.query;
+    const height = this.props.search ? this.props.height - SEARCH_HEIGHT : this.props.height;
     let sql;
 
     if (this.props.showSql) {
@@ -190,7 +190,7 @@ export default class ResultSet extends React.PureComponent {
             <FilterableTable
               data={data}
               orderedColumnKeys={results.columns.map(col => col.name)}
-              height={this.state.height}
+              height={height}
               filterText={this.state.searchText}
             />
           </div>
diff --git a/superset/assets/javascripts/SqlLab/components/SouthPane.jsx b/superset/assets/javascripts/SqlLab/components/SouthPane.jsx
index 6773ac7..8dfd0c1 100644
--- a/superset/assets/javascripts/SqlLab/components/SouthPane.jsx
+++ b/superset/assets/javascripts/SqlLab/components/SouthPane.jsx
@@ -18,6 +18,7 @@ const propTypes = {
   dataPreviewQueries: PropTypes.array.isRequired,
   actions: PropTypes.object.isRequired,
   activeSouthPaneTab: PropTypes.string,
+  height: PropTypes.number,
 };
 
 const defaultProps = {
@@ -25,40 +26,11 @@ const defaultProps = {
 };
 
 class SouthPane extends React.PureComponent {
-  constructor(props) {
-    super(props);
-    this.state = {
-      innerTabHeight: this.getInnerTabHeight(),
-    };
-  }
-  getInnerTabHeight() {
-    // hack to get height the tab container so it can be fixed and scroll in place
-    // calculate inner tab height
-
-    // document.getElementById('brace-editor').getBoundingClientRect().height;
-    const sqlEditorHeight = 192;
-
-    // document.getElementById('js-sql-toolbar').getBoundingClientRect().height;
-    const sqlToolbar = 30;
-
-    // document.getElementsByClassName('nav-tabs')[0].getBoundingClientRect().height * 2;
-    const tabsHeight = 88;
-
-    // document.getElementsByTagName('header')[0].getBoundingClientRect().height;
-    const headerHeight = 59;
-
-    const sum =
-      sqlEditorHeight +
-      sqlToolbar +
-      tabsHeight +
-      headerHeight;
-
-    return window.innerHeight - sum - 95;
-  }
   switchTab(id) {
     this.props.actions.setActiveSouthPaneTab(id);
   }
   render() {
+    const innerTabHeight = this.props.height - 55;
     let latestQuery;
     const props = this.props;
     if (props.editorQueries.length > 0) {
@@ -72,7 +44,7 @@ class SouthPane extends React.PureComponent {
           search
           query={latestQuery}
           actions={props.actions}
-          height={this.state.innerTabHeight}
+          height={innerTabHeight}
         />
       );
     } else {
@@ -91,7 +63,7 @@ class SouthPane extends React.PureComponent {
           csv={false}
           actions={props.actions}
           cache
-          height={this.state.innerTabHeight}
+          height={innerTabHeight}
         />
       </Tab>
     ));
@@ -114,7 +86,7 @@ class SouthPane extends React.PureComponent {
             title="Query History"
             eventKey="History"
           >
-            <div style={{ height: `${this.state.innerTabHeight}px`, overflow: 'scroll'
}}>
+            <div style={{ height: `${innerTabHeight}px`, overflow: 'scroll' }}>
               <QueryHistory queries={props.editorQueries} actions={props.actions} />
             </div>
           </Tab>
diff --git a/superset/assets/javascripts/SqlLab/components/SqlEditor.jsx b/superset/assets/javascripts/SqlLab/components/SqlEditor.jsx
index f96d788..5aa1497 100644
--- a/superset/assets/javascripts/SqlLab/components/SqlEditor.jsx
+++ b/superset/assets/javascripts/SqlLab/components/SqlEditor.jsx
@@ -12,9 +12,9 @@ import {
   Tooltip,
   Collapse,
 } from 'react-bootstrap';
+import SplitPane from 'react-split-pane';
 
 import Button from '../../components/Button';
-
 import SouthPane from './SouthPane';
 import SaveQuery from './SaveQuery';
 import Timer from '../../components/Timer';
@@ -50,16 +50,24 @@ class SqlEditor extends React.PureComponent {
       ctas: '',
     };
   }
-  componentDidMount() {
-    this.onMount();
-  }
-  onMount() {
+  componentWillMount() {
     if (this.state.autorun) {
       this.setState({ autorun: false });
       this.props.actions.queryEditorSetAutorun(this.props.queryEditor, false);
       this.startQuery();
     }
   }
+  componentDidMount() {
+    this.onResize();
+  }
+  onResize() {
+    const height = this.sqlEditorHeight();
+    this.setState({
+      editorPaneHeight: this.refs.ace.clientHeight,
+      southPaneHeight: height - this.refs.ace.clientHeight,
+      height,
+    });
+  }
   setQueryEditorSql(sql) {
     this.props.actions.queryEditorSetSql(this.props.queryEditor, sql);
   }
@@ -101,24 +109,7 @@ class SqlEditor extends React.PureComponent {
     const mysteryVerticalHeight = 50;
     return window.innerHeight - tabNavHeight - navBarHeight - mysteryVerticalHeight;
   }
-
-  render() {
-    const qe = this.props.queryEditor;
-    let limitWarning = null;
-    if (this.props.latestQuery && this.props.latestQuery.limit_reached) {
-      const tooltip = (
-        <Tooltip id="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.
-        </Tooltip>
-      );
-      limitWarning = (
-        <OverlayTrigger placement="left" overlay={tooltip}>
-          <Label bsStyle="warning" className="m-r-5">LIMIT</Label>
-        </OverlayTrigger>
-      );
-    }
+  renderEditorBottomBar() {
     let ctasControls;
     if (this.props.database && this.props.database.allow_ctas) {
       const ctasToolTip = 'Create table as with query results';
@@ -146,7 +137,23 @@ class SqlEditor extends React.PureComponent {
         </FormGroup>
       );
     }
-    const editorBottomBar = (
+    const qe = this.props.queryEditor;
+    let limitWarning = null;
+    if (this.props.latestQuery && this.props.latestQuery.limit_reached) {
+      const tooltip = (
+        <Tooltip id="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.
+        </Tooltip>
+      );
+      limitWarning = (
+        <OverlayTrigger placement="left" overlay={tooltip}>
+          <Label bsStyle="warning" className="m-r-5">LIMIT</Label>
+        </OverlayTrigger>
+      );
+    }
+    return (
       <div className="sql-toolbar clearfix" id="js-sql-toolbar">
         <div className="pull-left">
           <Form inline>
@@ -181,11 +188,15 @@ class SqlEditor extends React.PureComponent {
         </div>
       </div>
     );
+  }
+  render() {
+    const height = this.sqlEditorHeight();
+    const defaultNorthHeight = 200;
     return (
       <div
         className="SqlEditor"
         style={{
-          minHeight: this.sqlEditorHeight(),
+          minHeight: height,
           height: this.props.height,
         }}
       >
@@ -200,7 +211,7 @@ class SqlEditor extends React.PureComponent {
               lg={3}
             >
               <SqlEditorLeftBar
-                height={this.sqlEditorHeight()}
+                height={height}
                 queryEditor={this.props.queryEditor}
                 tables={this.props.tables}
                 actions={this.props.actions}
@@ -212,22 +223,37 @@ class SqlEditor extends React.PureComponent {
             sm={this.props.hideLeftBar ? 12 : 7}
             md={this.props.hideLeftBar ? 12 : 8}
             lg={this.props.hideLeftBar ? 12 : 9}
+            style={{ height: this.state.height }}
           >
-            <AceEditorWrapper
-              actions={this.props.actions}
-              onBlur={this.setQueryEditorSql.bind(this)}
-              queryEditor={this.props.queryEditor}
-              onAltEnter={this.runQuery.bind(this)}
-              sql={this.props.queryEditor.sql}
-              tables={this.props.tables}
-            />
-            {editorBottomBar}
-            <br />
-            <SouthPane
-              editorQueries={this.props.editorQueries}
-              dataPreviewQueries={this.props.dataPreviewQueries}
-              actions={this.props.actions}
-            />
+            <SplitPane
+              split="horizontal"
+              defaultSize={defaultNorthHeight}
+              minSize={100}
+              onChange={this.onResize.bind(this)}
+            >
+              <div ref="ace" style={{ width: '100%' }}>
+                <div>
+                  <AceEditorWrapper
+                    actions={this.props.actions}
+                    onBlur={this.setQueryEditorSql.bind(this)}
+                    queryEditor={this.props.queryEditor}
+                    onAltEnter={this.runQuery.bind(this)}
+                    sql={this.props.queryEditor.sql}
+                    tables={this.props.tables}
+                    height={((this.state.editorPaneHeight || defaultNorthHeight) - 50).toString()}
+                  />
+                  {this.renderEditorBottomBar()}
+                </div>
+              </div>
+              <div ref="south">
+                <SouthPane
+                  editorQueries={this.props.editorQueries}
+                  dataPreviewQueries={this.props.dataPreviewQueries}
+                  actions={this.props.actions}
+                  height={this.state.southPaneHeight}
+                />
+              </div>
+            </SplitPane>
           </Col>
         </Row>
       </div>
diff --git a/superset/assets/javascripts/SqlLab/main.less b/superset/assets/javascripts/SqlLab/main.less
index d5dab4c..577c8ab 100644
--- a/superset/assets/javascripts/SqlLab/main.less
+++ b/superset/assets/javascripts/SqlLab/main.less
@@ -130,9 +130,6 @@ div.Workspace {
     display: inline-block;
     background-color: #ccc;
 }
-.Pane2 {
-    width: 0;
-}
 .running {
     background-color: lime;
     color: black;
@@ -292,3 +289,6 @@ a.Link {
 .tooltip-inner {
     max-width: 500px;
 }
+.SouthPane {
+    margin-top: 10px;
+}
diff --git a/superset/assets/package.json b/superset/assets/package.json
index 6f8ed74..68b9e7c 100644
--- a/superset/assets/package.json
+++ b/superset/assets/package.json
@@ -76,6 +76,7 @@
     "react-resizable": "^1.3.3",
     "react-select": "1.0.0-rc.3",
     "react-select-fast-filter-options": "^0.2.1",
+    "react-split-pane": "^0.1.66",
     "react-syntax-highlighter": "^5.0.0",
     "react-virtualized": "^9.3.0",
     "react-virtualized-select": "^2.4.0",

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message