Skip to content

Commit e893ce4

Browse files
author
Jeffrey Na
committed
EventContainer implemented functionality to display charts in chunks
1 parent fe31fdc commit e893ce4

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

app/containers/EventContainer.tsx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useParams } from 'react-router-dom';
33
import { EventContext } from '../context/EventContext';
44
import { QueryContext } from '../context/QueryContext';
55
import EventChart from '../charts/EventChart';
6+
import { Button } from '@material-ui/core';
67

78
interface EventContainerProps {
89
sizing: string;
@@ -20,6 +21,9 @@ const EventContainer: React.FC<EventContainerProps> = React.memo(props => {
2021
const eventDataList: any[] = eventData.eventDataList;
2122
const eventTimeList: any[] = eventData.eventTimeList;
2223
const { service } = useParams<keyof Params>() as Params;
24+
const [currIndex, setCurrIndex] = useState(0);
25+
const [currChunk, setCurrChunk] = useState<JSX.Element[]>([]);
26+
const chunkSize = 7;
2327

2428
useEffect(() => {
2529
const temp: JSX.Element[] = [];
@@ -50,6 +54,8 @@ const EventContainer: React.FC<EventContainerProps> = React.memo(props => {
5054
}
5155
});
5256
setEventChartsArr(temp);
57+
setCurrChunk(temp.slice(currIndex, currIndex + chunkSize));
58+
setCurrIndex(currIndex + chunkSize);
5359
}
5460
}, [eventData, service]);
5561

@@ -63,13 +69,36 @@ const EventContainer: React.FC<EventContainerProps> = React.memo(props => {
6369
}
6470
return lst;
6571
};
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+
6687
return (
6788
<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+
)}
71100
</div>
72101
);
73102
});
74103

75-
export default EventContainer;
104+
export default EventContainer;

0 commit comments

Comments
 (0)