From 139ce275ac9b343a37802c3e6a340727c933ce3a Mon Sep 17 00:00:00 2001 From: manorlh <44364426+manorlh@users.noreply.github.com> Date: Sat, 25 May 2019 16:54:02 +0300 Subject: [PATCH] feat(tests sort by modified): tests sort by modified (#141) --- ui/src/features/configurationColumn.js | 8 ++++++- ui/src/features/get-tests.js | 32 ++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/ui/src/features/configurationColumn.js b/ui/src/features/configurationColumn.js index 7f692ac0f..0bbf3fe81 100644 --- a/ui/src/features/configurationColumn.js +++ b/ui/src/features/configurationColumn.js @@ -47,7 +47,13 @@ export const getColumns = ({columnsNames, sortHeader = '', onSort, onReportView, }, { id: 'updated_at', Header: () => ( - + -1 && sortHeader.indexOf('+') > -1} + down={sortHeader.indexOf('updated_at') > -1 && sortHeader.indexOf('-') > -1} + onClick={() => { + onSort('updated_at') + }} + > Modified ), diff --git a/ui/src/features/get-tests.js b/ui/src/features/get-tests.js index bfc231779..f29faf5fd 100644 --- a/ui/src/features/get-tests.js +++ b/ui/src/features/get-tests.js @@ -43,13 +43,16 @@ class getTests extends React.Component { testToDelete: undefined, createTest: false, testForEdit: null, - sortedTests: [] + sortedTests: [], + sortHeader:'' } } componentDidUpdate(prevProps) { if (prevProps.tests !== this.props.tests) { - this.setState({sortedTests: [...this.props.tests]}) + this.setState({sortedTests: [...this.props.tests]},()=>{ + this.onSort('updated_at'); + }) } } @@ -74,6 +77,25 @@ class getTests extends React.Component { }); this.setState({sortedTests: newSorted}) }; + + onSort = (field) => { + const {sortHeader} = this.state; + let isAsc = false; + if (sortHeader.includes(field)) { + isAsc = !sortHeader.includes('+') + } else { + isAsc = true; + } + let sortedReport; + if (isAsc) { + sortedReport = _.chain(this.state.sortedTests).sortBy(field).reverse().value(); + } else { + sortedReport = _.chain(this.state.sortedTests).sortBy(field).value(); + } + this.setState({sortedTests: sortedReport, sortHeader: `${field}${isAsc ? '+' : '-'}`}) + }; + + submitDelete = () => { this.props.deleteTest(this.state.testToDelete.id); this.props.getAllTests(); @@ -169,7 +191,7 @@ class getTests extends React.Component { } render() { - const {sortedTests} = this.state; + const {sortedTests, sortHeader} = this.state; const noDataText = this.props.errorOnGetJobs ? errorMsgGetTests : this.loader(); const columns = getColumns({ columnsNames, @@ -177,7 +199,9 @@ class getTests extends React.Component { onRawView: this.onRawView, onDelete: this.onDelete, onEdit: this.onEdit, - onRunTest: this.onRunTest + onRunTest: this.onRunTest, + onSort: this.onSort, + sortHeader: sortHeader }); return (