File tree Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -17,17 +17,15 @@ export const List = styled.div `
1717const ExtendedList = styled ( List ) ( getExtendedStyles ( ) ) ;
1818
1919const NUM_LINKS = 5 ;
20- const fillRange = ( start , end ) => {
21- return Array ( end - start + 1 ) . fill ( ) . map ( ( item , index ) => start + index ) ;
22- } ;
20+ const fillRange = ( start , end ) => Array ( end - start + 1 ) . fill ( ) . map ( ( item , index ) => start + index ) ;
2321
2422const getPages = ( currentPage = 1 , total = 0 ) => {
2523 var padding = Math . floor ( NUM_LINKS / 2 ) ;
2624 var left = ( currentPage - padding < padding ) ? 1 : currentPage - padding ;
2725 var right = ( left + NUM_LINKS - 1 > total ) ? total : left + NUM_LINKS - 1 ;
2826
29- left = ( right === total ) ?
30- ( right - NUM_LINKS < 1 ) ? 1 : right - NUM_LINKS + 1
27+ left = ( right === total )
28+ ? ( right - NUM_LINKS < 1 ) ? 1 : right - NUM_LINKS + 1
3129 : left ;
3230
3331 return fillRange ( left , right ) ;
Original file line number Diff line number Diff line change @@ -105,13 +105,27 @@ export default function reducer(state = {}, action) {
105105 dir : payload . dir
106106 } ,
107107 } ) ,
108- [ actions . SET_LIMIT ] : ( ) => stateUpdater ( {
109- isFetching : true ,
110- query : {
111- limit : parseInt ( payload . limit , 10 ) ,
112- offset : ( tableState . query . page - 1 ) * tableState . query . limit
113- } ,
114- } ) ,
108+ [ actions . SET_LIMIT ] : ( ) => {
109+ let maxPage = 1 ;
110+ if ( payload . limit > 0 ) {
111+ maxPage = ( tableState . query . count / payload . limit ) || 1
112+ }
113+ const currentPage = tableState . query . page > maxPage ? maxPage : tableState . query . page ;
114+ const offset = ( currentPage - 1 ) * payload . limit ;
115+
116+ let page = 1 ;
117+ if ( payload . limit > 0 ) {
118+ page = ( offset / payload . limit ) + 1 ;
119+ }
120+ return stateUpdater ( {
121+ isFetching : true ,
122+ query : {
123+ limit : parseInt ( payload . limit , 10 ) ,
124+ page,
125+ offset
126+ } ,
127+ } )
128+ } ,
115129 [ actions . SET_FILTER ] : ( ) => {
116130 var updatedFilters = { } ;
117131 if ( ! payload . clear ) {
You can’t perform that action at this time.
0 commit comments