From 53cd05d74af0c5b07307b1c17c86e7c14d868d39 Mon Sep 17 00:00:00 2001 From: Jesse Yang Date: Fri, 2 Oct 2020 12:15:06 -0700 Subject: [PATCH] perf(explore): render datasource details only when needed (#10924) --- .../components/DatasourceControl_spec.jsx | 8 +- .../components/controls/DatasourceControl.jsx | 85 ++++++++++++------- 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/superset-frontend/spec/javascripts/explore/components/DatasourceControl_spec.jsx b/superset-frontend/spec/javascripts/explore/components/DatasourceControl_spec.jsx index 3f7af15063d..592fb975e77 100644 --- a/superset-frontend/spec/javascripts/explore/components/DatasourceControl_spec.jsx +++ b/superset-frontend/spec/javascripts/explore/components/DatasourceControl_spec.jsx @@ -60,14 +60,14 @@ describe('DatasourceControl', () => { }); } - it('renders a Modal', () => { + it('should not render Modal', () => { const wrapper = setup(); - expect(wrapper.find(DatasourceModal)).toExist(); + expect(wrapper.find(DatasourceModal)).toHaveLength(0); }); - it('renders a ChangeDatasourceModal', () => { + it('should not render ChangeDatasourceModal', () => { const wrapper = setup(); - expect(wrapper.find(ChangeDatasourceModal)).toExist(); + expect(wrapper.find(ChangeDatasourceModal)).toHaveLength(0); }); it('show or hide Edit Datasource option', () => { diff --git a/superset-frontend/src/explore/components/controls/DatasourceControl.jsx b/superset-frontend/src/explore/components/controls/DatasourceControl.jsx index eb62c58409b..d805c934258 100644 --- a/superset-frontend/src/explore/components/controls/DatasourceControl.jsx +++ b/superset-frontend/src/explore/components/controls/DatasourceControl.jsx @@ -73,6 +73,17 @@ const Styles = styled.div` } `; +/** + * used in column details. + */ +const ColumnsCol = styled(Col)` + overflow: auto; /* for very very long columns names */ + white-space: nowrap; /* make sure tooltip trigger is on the same line as the metric */ + .and-more { + padding-left: 38px; + } +`; + class DatasourceControl extends React.PureComponent { constructor(props) { super(props); @@ -116,6 +127,8 @@ class DatasourceControl extends React.PureComponent { renderDatasource() { const { datasource } = this.props; + const { showDatasource } = this.state; + const maxNumColumns = 50; return (
@@ -125,24 +138,32 @@ class DatasourceControl extends React.PureComponent { {` ${datasource.database.name} `}
- - - Columns - {datasource.columns.map(col => ( -
- -
- ))} - - - Metrics - {datasource.metrics.map(m => ( -
- -
- ))} - -
+ {showDatasource && ( + + + Columns + {datasource.columns.slice(0, maxNumColumns).map(col => ( +
+ +
+ ))} + {datasource.columns.length > maxNumColumns && ( +
...
+ )} +
+ + Metrics + {datasource.metrics.slice(0, maxNumColumns).map(m => ( +
+ +
+ ))} + {datasource.columns.length > maxNumColumns && ( +
...
+ )} +
+
+ )} ); @@ -214,18 +235,22 @@ class DatasourceControl extends React.PureComponent { {this.renderDatasource()} - - + {showEditDatasourceModal && ( + + )} + {showChangeDatasourceModal && ( + + )} ); }