@@ -34,10 +34,14 @@ import React from 'react'
3434
3535interface StateProps {
3636 jobs : Job [ ]
37- totalCount : number
3837 isJobsInit : boolean
3938 isJobsLoading : boolean
4039 selectedNamespace : Nullable < string >
40+ totalCount : number
41+ }
42+
43+ interface JobsState {
44+ page : number
4145}
4246
4347interface DispatchProps {
@@ -58,15 +62,16 @@ const Jobs: React.FC<JobsProps> = ({
5862 fetchJobs,
5963 resetJobs,
6064} ) => {
61- const theme = createTheme ( useTheme ( ) )
62-
63- const [ state , setState ] = React . useState ( {
65+ const defaultState = {
6466 page : 0 ,
65- } )
66-
67+ }
68+ const [ state , setState ] = React . useState < JobsState > ( defaultState )
69+
70+ const theme = createTheme ( useTheme ( ) )
71+
6772 React . useEffect ( ( ) => {
6873 if ( selectedNamespace ) {
69- fetchJobs ( selectedNamespace , PAGE_SIZE , state . page )
74+ fetchJobs ( selectedNamespace , PAGE_SIZE , state . page * PAGE_SIZE )
7075 }
7176 } , [ selectedNamespace , state . page ] )
7277
@@ -167,55 +172,55 @@ const Jobs: React.FC<JobsProps> = ({
167172 } ) }
168173 </ TableBody >
169174 </ Table >
170- </ >
175+ < Box display = { 'flex' } justifyContent = { 'flex-end' } alignItems = { 'center' } mb = { 2 } >
176+ < MqText subdued >
177+ < >
178+ { PAGE_SIZE * state . page + 1 } -{ ' ' }
179+ { Math . min ( PAGE_SIZE * ( state . page + 1 ) , totalCount ) } of { totalCount }
180+ </ >
181+ </ MqText >
182+ < Tooltip title = { i18next . t ( 'events_route.previous_page' ) } >
183+ < span >
184+ < IconButton
185+ sx = { {
186+ marginLeft : theme . spacing ( 2 ) ,
187+ } }
188+ color = 'primary'
189+ disabled = { state . page === 0 }
190+ onClick = { ( ) => handleClickPage ( 'prev' ) }
191+ size = 'large'
192+ >
193+ < ChevronLeftRounded />
194+ </ IconButton >
195+ </ span >
196+ </ Tooltip >
197+ < Tooltip title = { i18next . t ( 'events_route.next_page' ) } >
198+ < span >
199+ < IconButton
200+ color = 'primary'
201+ onClick = { ( ) => handleClickPage ( 'next' ) }
202+ size = 'large'
203+ disabled = { state . page === Math . ceil ( totalCount / PAGE_SIZE ) - 1 }
204+ >
205+ < ChevronRightRounded />
206+ </ IconButton >
207+ </ span >
208+ </ Tooltip >
209+ </ Box >
210+ </ >
171211 ) }
172- < Box display = { 'flex' } justifyContent = { 'flex-end' } alignItems = { 'center' } mb = { 2 } >
173- < MqText subdued >
174- < >
175- { PAGE_SIZE * state . page + 1 } - { Math . min ( PAGE_SIZE * ( state . page + 1 ) , totalCount ) } { ' ' }
176- of { totalCount }
177- </ >
178- </ MqText >
179- < Tooltip title = { i18next . t ( 'events_route.previous_page' ) } >
180- < span >
181- < IconButton
182- sx = { {
183- marginLeft : theme . spacing ( 2 ) ,
184- } }
185- color = 'primary'
186- disabled = { state . page === 0 }
187- onClick = { ( ) => handleClickPage ( 'prev' ) }
188- size = 'large'
189- >
190- < ChevronLeftRounded />
191- </ IconButton >
192- </ span >
193- </ Tooltip >
194- < Tooltip title = { i18next . t ( 'events_route.next_page' ) } >
195- < span >
196- < IconButton
197- color = 'primary'
198- onClick = { ( ) => handleClickPage ( 'next' ) }
199- size = 'large'
200- disabled = { state . page === Math . ceil ( totalCount / PAGE_SIZE ) - 1 }
201- >
202- < ChevronRightRounded />
203- </ IconButton >
204- </ span >
205- </ Tooltip >
206- </ Box >
207212 </ >
208213 </ MqScreenLoad >
209214 </ Container >
210215 )
211216}
212217
213218const mapStateToProps = ( state : IState ) => ( {
214- isJobsInit : state . jobs . init ,
215219 jobs : state . jobs . result ,
216- totalCount : state . jobs . totalCount ,
220+ isJobsInit : state . jobs . init ,
217221 isJobsLoading : state . jobs . isLoading ,
218222 selectedNamespace : state . namespaces . selectedNamespace ,
223+ totalCount : state . jobs . totalCount ,
219224} )
220225
221226const mapDispatchToProps = ( dispatch : Redux . Dispatch ) =>
0 commit comments