Skip to content

Commit

Permalink
[SQL Lab] Fixed TableElement sorting functionality and tests (#7069) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoberti authored and mistercrunch committed Mar 20, 2019
1 parent 209e7a9 commit 30f88ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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} />);
Expand Down
11 changes: 10 additions & 1 deletion superset/assets/src/SqlLab/components/TableElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit 30f88ca

Please sign in to comment.