From db1ed2a765d317e55377f2550f169b78f981b4a0 Mon Sep 17 00:00:00 2001 From: vera-liu Date: Tue, 22 Nov 2016 13:21:07 -0800 Subject: [PATCH] Calculate height dynamically using jquery for scrollable sqllab (#1611) * Calculate height dynamically using jquery for scrollable sqllab components * Move editorHeight to App.jsx * Calculate height dynamically for query search --- .../javascripts/SqlLab/components/App.jsx | 23 ++++++++++++++++--- .../SqlLab/components/QuerySearch.jsx | 7 ++++-- .../SqlLab/components/SqlEditor.jsx | 10 +++++++- .../SqlLab/components/TabbedSqlEditors.jsx | 2 ++ superset/assets/javascripts/SqlLab/main.css | 4 ++-- superset/templates/appbuilder/navbar.html | 2 +- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/superset/assets/javascripts/SqlLab/components/App.jsx b/superset/assets/javascripts/SqlLab/components/App.jsx index 7eba77fd5a..32bc709bbf 100644 --- a/superset/assets/javascripts/SqlLab/components/App.jsx +++ b/superset/assets/javascripts/SqlLab/components/App.jsx @@ -1,3 +1,4 @@ +const $ = window.$ = require('jquery'); import * as Actions from '../actions'; import React from 'react'; @@ -14,13 +15,29 @@ class App extends React.PureComponent { super(props); this.state = { hash: window.location.hash, + contentHeight: this.getHeight(), }; } componentDidMount() { + /* eslint-disable react/no-did-mount-set-state */ + this.setState({ contentHeight: this.getHeight() }); window.addEventListener('hashchange', this.onHashChanged.bind(this)); + window.addEventListener('resize', this.handleResize.bind(this)); } componentWillUnmount() { window.removeEventListener('hashchange', this.onHashChanged.bind(this)); + window.removeEventListener('resize', this.handleResize.bind(this)); + } + getHeight() { + const navHeight = 90; + const headerHeight = $('.nav-tabs').outerHeight() ? + $('.nav-tabs').outerHeight() : $('#search-header').outerHeight(); + const warningHeight = $('#navbar-warning').outerHeight(); + const alertHeight = $('#sqllab-alerts').outerHeight(); + return `${window.innerHeight - navHeight - headerHeight - warningHeight - alertHeight}px`; + } + handleResize() { + this.setState({ contentHeight: this.getHeight() }); } onHashChanged() { this.setState({ hash: window.location.hash }); @@ -32,7 +49,7 @@ class App extends React.PureComponent {
- +
@@ -41,13 +58,13 @@ class App extends React.PureComponent { content = (
- +
); } return (
- +
{content}
diff --git a/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx b/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx index 1fd81185ca..2ed9253a81 100644 --- a/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx +++ b/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx @@ -127,7 +127,7 @@ class QuerySearch extends React.PureComponent { render() { return (
-
+