@@ -34,10 +34,14 @@ import React from 'react'
34
34
35
35
interface StateProps {
36
36
jobs : Job [ ]
37
- totalCount : number
38
37
isJobsInit : boolean
39
38
isJobsLoading : boolean
40
39
selectedNamespace : Nullable < string >
40
+ totalCount : number
41
+ }
42
+
43
+ interface JobsState {
44
+ page : number
41
45
}
42
46
43
47
interface DispatchProps {
@@ -58,15 +62,16 @@ const Jobs: React.FC<JobsProps> = ({
58
62
fetchJobs,
59
63
resetJobs,
60
64
} ) => {
61
- const theme = createTheme ( useTheme ( ) )
62
-
63
- const [ state , setState ] = React . useState ( {
65
+ const defaultState = {
64
66
page : 0 ,
65
- } )
66
-
67
+ }
68
+ const [ state , setState ] = React . useState < JobsState > ( defaultState )
69
+
70
+ const theme = createTheme ( useTheme ( ) )
71
+
67
72
React . useEffect ( ( ) => {
68
73
if ( selectedNamespace ) {
69
- fetchJobs ( selectedNamespace , PAGE_SIZE , state . page )
74
+ fetchJobs ( selectedNamespace , PAGE_SIZE , state . page * PAGE_SIZE )
70
75
}
71
76
} , [ selectedNamespace , state . page ] )
72
77
@@ -167,55 +172,55 @@ const Jobs: React.FC<JobsProps> = ({
167
172
} ) }
168
173
</ TableBody >
169
174
</ 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
+ </ >
171
211
) }
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 >
207
212
</ >
208
213
</ MqScreenLoad >
209
214
</ Container >
210
215
)
211
216
}
212
217
213
218
const mapStateToProps = ( state : IState ) => ( {
214
- isJobsInit : state . jobs . init ,
215
219
jobs : state . jobs . result ,
216
- totalCount : state . jobs . totalCount ,
220
+ isJobsInit : state . jobs . init ,
217
221
isJobsLoading : state . jobs . isLoading ,
218
222
selectedNamespace : state . namespaces . selectedNamespace ,
223
+ totalCount : state . jobs . totalCount ,
219
224
} )
220
225
221
226
const mapDispatchToProps = ( dispatch : Redux . Dispatch ) =>
0 commit comments