diff --git a/pkg/ui/v1beta1/frontend/src/components/HP/Monitor/HPJobTable.jsx b/pkg/ui/v1beta1/frontend/src/components/HP/Monitor/HPJobTable.jsx index 19ec18d19a9..5ca5c423907 100644 --- a/pkg/ui/v1beta1/frontend/src/components/HP/Monitor/HPJobTable.jsx +++ b/pkg/ui/v1beta1/frontend/src/components/HP/Monitor/HPJobTable.jsx @@ -12,12 +12,14 @@ import TableSortLabel from '@material-ui/core/TableSortLabel'; import { fetchHPJobTrialInfo } from '../../../actions/hpMonitorActions'; import { HP_MONITOR_MODULE } from '../../../constants/constants'; +import TablePagination from '@material-ui/core/TablePagination'; const styles = theme => ({ root: { width: '100%', marginTop: theme.spacing.unit * 3, overflowX: 'auto', + marginBottom: theme.spacing.unit * 3, }, table: { minWidth: 700, @@ -52,7 +54,7 @@ class HPJobTable extends React.Component { constructor(props) { super(props); - this.state = { orderByIdx: 1, order: 'asc' }; + this.state = { orderByIdx: 1, order: 'asc', rowsPerPage: 10, page: 0 }; } onChangeSortHeaderIndex = headerIndex => () => { @@ -89,86 +91,123 @@ class HPJobTable extends React.Component { return stabilizedData.map(el => el[0]); }; + onChangePage = (event, newPage) => { + this.setState({ page: newPage }); + }; + + onChangeRowsPerPage = event => { + this.setState({ rowsPerPage: parseInt(event.target.value, 10), page: 0 }); + }; + render() { const { classes } = this.props; + const emptyRows = + this.state.rowsPerPage - + Math.min( + this.state.rowsPerPage, + this.props.data.length - this.state.page * this.state.rowsPerPage, + ); + return ( - {this.props.jobData.length > 1 && ( - - - - {this.props.headers.map((header, idx) => ( - - 1 && ( +
+
+ + + {this.props.headers.map((header, idx) => ( + - {header} - - - ))} - - - - {this.stableSort(this.props.data, this.getComparator()).map((row, idx) => ( - - {row.map((element, index) => { - if (index === 0 && row[1] === 'Succeeded') { - return ( - - {element} - - ); - } else if (index === 1) { - if (element === 'Created') { - return ( - - {element} - - ); - } else if (element === 'Running') { - return ( - - {element} - - ); - } else if (element === 'Succeeded') { - return ( - - {element} - - ); - } else if (element === 'Killed') { - return ( - - {element} - - ); - } else if (element === 'Failed') { - return ( - - {element} - - ); - } - } - return {element}; - })} + + {header} + + + ))} - ))} - -
+ + + {this.stableSort(this.props.data, this.getComparator()) + .slice( + this.state.page * this.state.rowsPerPage, + this.state.page * this.state.rowsPerPage + this.state.rowsPerPage, + ) + .map((row, idx) => ( + + {row.map((element, index) => { + if (index === 0 && row[1] === 'Succeeded') { + return ( + + {element} + + ); + } else if (index === 1) { + if (element === 'Created') { + return ( + + {element} + + ); + } else if (element === 'Running') { + return ( + + {element} + + ); + } else if (element === 'Succeeded') { + return ( + + {element} + + ); + } else if (element === 'Killed') { + return ( + + {element} + + ); + } else if (element === 'Failed') { + return ( + + {element} + + ); + } + } + return {element}; + })} + + ))} + + {emptyRows > 0 && ( + + + + )} + + + + )}
); @@ -177,7 +216,6 @@ class HPJobTable extends React.Component { const mapStateToProps = state => { return { - jobData: state[HP_MONITOR_MODULE].jobData, headers: state[HP_MONITOR_MODULE].jobData[0], data: state[HP_MONITOR_MODULE].jobData.slice(1), };