[SQL Lab] Fixed TableElement sorting functionality and tests (#7069) (#7070)

This commit is contained in:
Enrico Berti 2019-03-20 16:32:04 +01:00 committed by Maxime Beauchemin
parent 209e7a9d91
commit 30f88caf55
2 changed files with 11 additions and 2 deletions

View File

@ -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} />);

View File

@ -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 = (