@@ -2,9 +2,9 @@ import React, {Component} from 'react';
22import { connect } from 'react-redux' ;
33import { Link } from 'react-router-dom' ;
44import PropTypes from 'prop-types' ;
5- import { list , reset } from '../../actions/{{{ lc }}}/list' ;
5+ import { list , reset , page } from '../../actions/{{{ lc }}}/list' ;
66import { success } from '../../actions/{{{ lc }}}/delete' ;
7- import { itemToLinks } from '../../utils/helpers' ;
7+ import { paginationRoute , itemToLinks } from '../../utils/helpers' ;
88
99class List extends Component {
1010 static propTypes = {
@@ -14,8 +14,42 @@ class List extends Component {
1414 deletedItem : PropTypes . object ,
1515 list : PropTypes . func . isRequired ,
1616 reset : PropTypes . func . isRequired ,
17+ page : PropTypes . func . isRequired ,
1718 } ;
1819
20+ pagination ( ) {
21+ return (
22+ < span >
23+ < button
24+ type = "button"
25+ className = "btn btn-basic btn-sm"
26+ onClick = { ( ) => this . props . page ( paginationRoute ( this . props . view [ '{{{ hydraPrefix }}}first' ] ) ) }
27+ disabled = { ! this . props . view [ '{{{ hydraPrefix }}}previous' ] }
28+ > First</ button >
29+
30+ < button
31+ type = "button"
32+ className = "btn btn-basic btn-sm"
33+ onClick = { ( ) => this . props . page ( paginationRoute ( this . props . view [ '{{{ hydraPrefix }}}previous' ] ) ) }
34+ disabled = { ! this . props . view [ '{{{ hydraPrefix }}}previous' ] }
35+ > Previous</ button >
36+
37+ < button
38+ type = "button" className = "btn btn-basic btn-sm"
39+ onClick = { ( ) => this . props . page ( paginationRoute ( this . props . view [ '{{{ hydraPrefix }}}next' ] ) ) }
40+ disabled = { ! this . props . view [ '{{{ hydraPrefix }}}next' ] }
41+ > Next</ button >
42+
43+ < button
44+ type = "button" className = "btn btn-basic btn-sm"
45+ onClick = { ( ) => this . props . page ( paginationRoute ( this . props . view [ '{{{ hydraPrefix }}}last' ] ) ) }
46+ disabled = { ! this . props . view [ '{{{ hydraPrefix }}}next' ] }
47+ > Last</ button >
48+
49+ </ span >
50+ ) ;
51+ }
52+
1953 componentDidMount ( ) {
2054 this . props . list ( ) ;
2155 }
@@ -31,6 +65,7 @@ class List extends Component {
3165 { this . props . loading && < div className = "alert alert-info" > Loading...</ div > }
3266 { this . props . deletedItem && < div className = "alert alert-success" > { this . props . deletedItem [ '@id' ] } deleted.</ div > }
3367 { this . props . error && < div className = "alert alert-danger" > { this . props . error } </ div > }
68+ { this . pagination ( ) }
3469
3570 < div className = "table-responsive" >
3671 < table className = "table table-striped table-hover" >
@@ -80,12 +115,14 @@ const mapStateToProps = (state) => {
80115 error : state . { { { lc } } } . list . error,
81116 loading : state . { { { lc } } } . list . loading ,
82117 deletedItem : state . { { { lc } } } . del . deleted,
118+ view : state . { { { lc } } } . list . view ,
83119 } ;
84120} ;
85121
86122const mapDispatchToProps = ( dispatch ) => {
87123 return {
88124 list : ( ) => dispatch ( list ( ) ) ,
125+ page : ( arg ) => dispatch ( page ( arg ) ) ,
89126 reset : ( ) => {
90127 dispatch ( reset ( ) ) ;
91128 dispatch ( success ( null ) ) ;
0 commit comments