@@ -3,6 +3,7 @@ import { useParams } from 'react-router-dom';
3
3
import { EventContext } from '../context/EventContext' ;
4
4
import { QueryContext } from '../context/QueryContext' ;
5
5
import EventChart from '../charts/EventChart' ;
6
+ import { Button } from '@material-ui/core' ;
6
7
7
8
interface EventContainerProps {
8
9
sizing : string ;
@@ -20,6 +21,9 @@ const EventContainer: React.FC<EventContainerProps> = React.memo(props => {
20
21
const eventDataList : any [ ] = eventData . eventDataList ;
21
22
const eventTimeList : any [ ] = eventData . eventTimeList ;
22
23
const { service } = useParams < keyof Params > ( ) as Params ;
24
+ const [ currIndex , setCurrIndex ] = useState ( 0 ) ;
25
+ const [ currChunk , setCurrChunk ] = useState < JSX . Element [ ] > ( [ ] ) ;
26
+ const chunkSize = 7 ;
23
27
24
28
useEffect ( ( ) => {
25
29
const temp : JSX . Element [ ] = [ ] ;
@@ -50,6 +54,8 @@ const EventContainer: React.FC<EventContainerProps> = React.memo(props => {
50
54
}
51
55
} ) ;
52
56
setEventChartsArr ( temp ) ;
57
+ setCurrChunk ( temp . slice ( currIndex , currIndex + chunkSize ) ) ;
58
+ setCurrIndex ( currIndex + chunkSize ) ;
53
59
}
54
60
} , [ eventData , service ] ) ;
55
61
@@ -63,13 +69,36 @@ const EventContainer: React.FC<EventContainerProps> = React.memo(props => {
63
69
}
64
70
return lst ;
65
71
} ;
72
+
73
+ console . log ( 'CHUNKS' , currChunk ) ;
74
+
75
+ function nextChunk ( ) {
76
+ const nextChunk = eventChartsArr . slice ( currIndex , currIndex + chunkSize ) ;
77
+ setCurrChunk ( nextChunk ) ;
78
+ setCurrIndex ( currIndex + chunkSize ) ;
79
+ }
80
+
81
+ function prevChunk ( ) {
82
+ const prevChunk = eventChartsArr . slice ( currIndex - ( 2 * chunkSize ) , currIndex - chunkSize ) ;
83
+ setCurrChunk ( prevChunk ) ;
84
+ setCurrIndex ( currIndex - chunkSize ) ;
85
+ }
86
+
66
87
return (
67
88
< div >
68
- { service . includes ( 'kafkametrics' ) || service . includes ( 'kubernetesmetrics' )
69
- ? eventChartsArr
70
- : [ ] }
89
+ { service . includes ( 'kafkametrics' ) || service . includes ( 'kubernetesmetrics' ) ? currChunk : [ ] }
90
+ { eventChartsArr . length > chunkSize && (
91
+ < >
92
+ < Button id = "getCharts" onClick = { prevChunk } variant = "contained" color = "primary" disabled = { currIndex <= chunkSize } >
93
+ Prev
94
+ </ Button >
95
+ < Button id = "getCharts" onClick = { nextChunk } variant = "contained" color = "primary" disabled = { currIndex >= eventChartsArr . length } >
96
+ Next
97
+ </ Button >
98
+ </ >
99
+ ) }
71
100
</ div >
72
101
) ;
73
102
} ) ;
74
103
75
- export default EventContainer ;
104
+ export default EventContainer ;
0 commit comments