1+ import React , { useContext , useEffect } from 'react' ;
2+ import { ApplicationContext } from '../../context/ApplicationContext' ;
3+ import { DashboardContext } from '../../context/DashboardContext' ;
4+ import { Typography } from '@material-ui/core' ;
5+ import { AwsContext } from '../../context/AwsContext' ;
6+ import './styles.scss' ;
7+ import { useLocation } from 'react-router-dom' ;
8+ import EC2GraphsComponent from './EC2GraphsComponent' ;
9+ import ECSGraphsComponent from './ECSGraphsComponent' ;
10+ import EKSGraphsComponent from './EKSGraphsComponent' ;
11+
12+ const AwsGraphsContainer = ( ) => {
13+ const { app, appIndex, setIntervalID, intervalID } = useContext ( ApplicationContext ) ;
14+ const { user } = useContext ( DashboardContext ) ;
15+ const { awsAppInfo, fetchAwsData, fetchAwsEcsData, fetchAwsEksData, fetchAwsAppInfo } = useContext ( AwsContext ) ;
16+ const { state } = useLocation ( ) ;
17+ const { typeOfService } = state ;
18+ const [ awsLive , setAwsLive ] = React . useState ( false ) ;
19+
20+ useEffect ( ( ) => {
21+ if ( awsLive ) {
22+ const id = setInterval ( ( ) => {
23+ fetchAwsAppInfo ( user , appIndex ) ;
24+ if ( typeOfService === 'AWS/EC2' ) {
25+ fetchAwsData ( user , appIndex ) ;
26+ }
27+ if ( typeOfService === 'AWS/ECS' ) {
28+ fetchAwsEcsData ( user , appIndex ) ;
29+ }
30+ if ( typeOfService === 'AWS/EKS' ) {
31+ fetchAwsEksData ( user , appIndex ) ;
32+ }
33+ } , 10000 ) ;
34+ setIntervalID ( id ) ;
35+ } else {
36+ if ( intervalID ) {
37+ clearInterval ( intervalID ) ;
38+ }
39+ }
40+
41+ return ( ) => {
42+ if ( intervalID ) {
43+ clearInterval ( intervalID ) ;
44+ }
45+ } ;
46+ } , [ awsLive , user , appIndex , typeOfService , fetchAwsAppInfo , fetchAwsData , fetchAwsEcsData , fetchAwsEksData , intervalID , setIntervalID ] ) ;
47+
48+ return (
49+ < div className = "AWS-container" >
50+ < div className = "AWS-header" >
51+ < Typography variant = "h3" > { app } </ Typography >
52+ < p > Metrics for AWS Service</ p >
53+ < button onClick = { ( ) => setAwsLive ( ! awsLive ) } >
54+ { awsLive ? 'Stop Live Update' : 'Start Live Update' }
55+ </ button >
56+ </ div >
57+ { typeOfService === 'AWS/ECS' && < ECSGraphsComponent region = { awsAppInfo . region } typeOfService = { typeOfService } /> }
58+ { typeOfService === 'AWS/EC2' && < EC2GraphsComponent /> }
59+ { typeOfService === 'AWS/EKS' && < EKSGraphsComponent awsEksData = { awsAppInfo . awsUrl } /> }
60+ </ div >
61+ ) ;
62+ } ;
63+
64+ export default AwsGraphsContainer ;
0 commit comments