@@ -2,56 +2,26 @@ import React, {Component} from 'react';
2
2
import { connect } from 'react-redux' ;
3
3
import { Link } from 'react-router-dom' ;
4
4
import PropTypes from 'prop-types' ;
5
- import { list , reset , page } from '../../actions/{{{ lc }}}/list' ;
5
+ import { list , reset } from '../../actions/{{{ lc }}}/list' ;
6
6
import { success } from '../../actions/{{{ lc }}}/delete' ;
7
- import { paginationRoute , itemToLinks } from '../../utils/helpers' ;
7
+ import { itemToLinks } from '../../utils/helpers' ;
8
8
9
9
class List extends Component {
10
10
static propTypes = {
11
11
error : PropTypes . string ,
12
12
loading : PropTypes . bool . isRequired ,
13
- items : PropTypes . array . isRequired ,
13
+ data : PropTypes . object . isRequired ,
14
14
deletedItem : PropTypes . object ,
15
15
list : PropTypes . func . isRequired ,
16
16
reset : PropTypes . func . isRequired ,
17
- page : PropTypes . func . isRequired ,
18
17
} ;
19
18
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
- ) ;
19
+ componentDidMount ( ) {
20
+ this . props . list ( this . props . match . params . page && decodeURIComponent ( this . props . match . params . page ) ) ;
51
21
}
52
22
53
- componentDidMount ( ) {
54
- this . props . list ( ) ;
23
+ componentWillReceiveProps ( nextProps ) {
24
+ if ( this . props . match . params . page !== nextProps . match . params . page ) nextProps . list ( nextProps . match . params . page && decodeURIComponent ( nextProps . match . params . page ) ) ;
55
25
}
56
26
57
27
componentWillUnmount ( ) {
@@ -65,7 +35,8 @@ class List extends Component {
65
35
{ this . props . loading && < div className = "alert alert-info" > Loading...</ div > }
66
36
{ this . props . deletedItem && < div className = "alert alert-success" > { this . props . deletedItem [ '@id' ] } deleted.</ div > }
67
37
{ this . props . error && < div className = "alert alert-danger" > { this . props . error } </ div > }
68
- { this . pagination ( ) }
38
+
39
+ < p > < Link to = "create" className = "btn btn-default" > Create</ Link > </ p >
69
40
70
41
< div className = "table-responsive" >
71
42
< table className = "table table-striped table-hover" >
@@ -80,7 +51,7 @@ class List extends Component {
80
51
</ tr >
81
52
</ thead >
82
53
< tbody >
83
- { this . props . items . map ( item =>
54
+ { this . props . data [ '{{{ hydraPrefix }}}member' ] && this . props . data [ '{{{ hydraPrefix }}}member' ] . map ( item =>
84
55
< tr className = { item [ '@id' ] } key = { item [ '@id' ] } >
85
56
< td > < Link to = { `show/${ encodeURIComponent ( item [ '@id' ] ) } ` } > { item [ '@id' ] } </ Link > </ td >
86
57
{ { #each fields} }
@@ -104,25 +75,37 @@ class List extends Component {
104
75
</ table >
105
76
</ div >
106
77
107
- < Link to = "create" className = "btn btn-default" > Create </ Link >
78
+ { this . pagination ( ) }
108
79
</ div > ;
109
80
}
81
+
82
+ pagination ( ) {
83
+ const view = this . props . data [ 'hydra:view' ] ;
84
+ if ( ! view ) return ;
85
+
86
+ const { '{{{ hydraPrefix }}}first' : first , '{{{ hydraPrefix }}}previous' : previous , '{{{ hydraPrefix }}}next' : next , '{{{ hydraPrefix }}}last' : last } = view ;
87
+
88
+ return < nav aria-label = "Page navigation" >
89
+ < Link to = '.' className = { `btn btn-default${ previous ? '' : ' disabled' } ` } > < span aria-hidden = "true" > ⇐</ span > First</ Link >
90
+ < Link to = { ! previous || previous === first ? '.' : encodeURIComponent ( previous ) } className = { `btn btn-default${ previous ? '' : ' disabled' } ` } > < span aria-hidden = "true" > ←</ span > Previous</ Link >
91
+ < Link to = { next ? encodeURIComponent ( next ) : '#' } className = { `btn btn-default${ next ? '' : ' disabled' } ` } > Next < span aria-hidden = "true" > →</ span > </ Link >
92
+ < Link to = { last ? encodeURIComponent ( last ) : '#' } className = { `btn btn-default${ next ? '' : ' disabled' } ` } > Last < span aria-hidden = "true" > ⇒</ span > </ Link >
93
+ </ nav > ;
94
+ }
110
95
}
111
96
112
97
const mapStateToProps = ( state ) => {
113
98
return {
114
- items : state . { { { lc } } } . list . items ,
99
+ data : state . { { { lc } } } . list . data ,
115
100
error : state . { { { lc } } } . list . error,
116
101
loading : state . { { { lc } } } . list . loading ,
117
102
deletedItem : state . { { { lc } } } . del . deleted,
118
- view : state . { { { lc } } } . list . view ,
119
103
} ;
120
104
} ;
121
105
122
106
const mapDispatchToProps = ( dispatch ) => {
123
107
return {
124
- list : ( ) => dispatch ( list ( ) ) ,
125
- page : ( arg ) => dispatch ( page ( arg ) ) ,
108
+ list : ( page ) => dispatch ( list ( page ) ) ,
126
109
reset : ( ) => {
127
110
dispatch ( reset ( ) ) ;
128
111
dispatch ( success ( null ) ) ;
0 commit comments