Skip to content

Commit

Permalink
feat(tests sort by modified): tests sort by modified (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
manorlh authored and enudler committed May 25, 2019
1 parent 612fec0 commit 139ce27
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
8 changes: 7 additions & 1 deletion ui/src/features/configurationColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ export const getColumns = ({columnsNames, sortHeader = '', onSort, onReportView,
}, {
id: 'updated_at',
Header: () => (
<TableHeader sortable={false}>
<TableHeader sortable={true}
up={sortHeader.indexOf('updated_at') > -1 && sortHeader.indexOf('+') > -1}
down={sortHeader.indexOf('updated_at') > -1 && sortHeader.indexOf('-') > -1}
onClick={() => {
onSort('updated_at')
}}
>
Modified
</TableHeader>
),
Expand Down
32 changes: 28 additions & 4 deletions ui/src/features/get-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
})
}
}

Expand All @@ -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();
Expand Down Expand Up @@ -169,15 +191,17 @@ 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,
onReportView: this.onReportView,
onRawView: this.onRawView,
onDelete: this.onDelete,
onEdit: this.onEdit,
onRunTest: this.onRunTest
onRunTest: this.onRunTest,
onSort: this.onSort,
sortHeader: sortHeader
});

return (
Expand Down

0 comments on commit 139ce27

Please sign in to comment.