You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2019/03/20 15:32:13 UTC
[incubator-superset] branch master updated: [SQL Lab] Fixed
TableElement sorting functionality and tests (#7069) (#7070)
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 30f88ca [SQL Lab] Fixed TableElement sorting functionality and tests (#7069) (#7070)
30f88ca is described below
commit 30f88caf552fa6fcf96c3232a3876181981bf8e9
Author: Enrico Berti <he...@enricoberti.com>
AuthorDate: Wed Mar 20 16:32:04 2019 +0100
[SQL Lab] Fixed TableElement sorting functionality and tests (#7069) (#7070)
---
superset/assets/spec/javascripts/sqllab/TableElement_spec.jsx | 2 +-
superset/assets/src/SqlLab/components/TableElement.jsx | 11 ++++++++++-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/superset/assets/spec/javascripts/sqllab/TableElement_spec.jsx b/superset/assets/spec/javascripts/sqllab/TableElement_spec.jsx
index 53327c3..c01d066 100644
--- a/superset/assets/spec/javascripts/sqllab/TableElement_spec.jsx
+++ b/superset/assets/spec/javascripts/sqllab/TableElement_spec.jsx
@@ -57,7 +57,7 @@ describe('TableElement', () => {
expect(wrapper.find(ColumnElement).first().props().column.name).toBe('id');
wrapper.find('.sort-cols').simulate('click');
expect(wrapper.state().sortColumns).toBe(true);
- expect(wrapper.find(ColumnElement).first().props().column.name).toBe('last_login');
+ expect(wrapper.find(ColumnElement).first().props().column.name).toBe('active');
});
it('calls the collapseTable action', () => {
const wrapper = mount(<TableElement {...mockedProps} />);
diff --git a/superset/assets/src/SqlLab/components/TableElement.jsx b/superset/assets/src/SqlLab/components/TableElement.jsx
index 2854c21..96027a9 100644
--- a/superset/assets/src/SqlLab/components/TableElement.jsx
+++ b/superset/assets/src/SqlLab/components/TableElement.jsx
@@ -204,7 +204,16 @@ class TableElement extends React.PureComponent {
if (table.columns) {
cols = table.columns.slice();
if (this.state.sortColumns) {
- cols.sort((a, b) => a.name.toUpperCase() > b.name.toUpperCase());
+ cols.sort((a, b) => {
+ const colA = a.name.toUpperCase();
+ const colB = b.name.toUpperCase();
+ if (colA < colB) {
+ return -1;
+ } else if (colA > colB) {
+ return 1;
+ }
+ return 0;
+ });
}
}
const metadata = (