|
| 1 | +import React, { useState, useContext } from 'react'; |
| 2 | +import MonitorHeader from '../AComp/MonitorHeader.jsx'; |
| 3 | +import Modal from '../components/Modal.jsx'; |
| 4 | +import OverviewContext from '../context/OverviewContext'; |
| 5 | +import HealthInformationContext from '../context/DetailsContext'; |
| 6 | +import routeChart from '../assets/routeChart.png'; |
| 7 | +import ServiceDetails from '../components/ServiceDetails.jsx'; |
| 8 | + |
| 9 | +const MonitoringContainer = (props) => { |
| 10 | + const { service } = props; |
| 11 | + const { detail } = props; |
| 12 | + |
| 13 | + // Contexts have data added to them following successful IPC return. Data is later used to create charts. |
| 14 | + const serviceComponents = useContext(OverviewContext); |
| 15 | + const healthdata = useContext(HealthInformationContext); |
| 16 | + |
| 17 | + // Hook used to toggle whether or not the Modal component renders |
| 18 | + const [modalDisplay, toggleModalDisplay] = useState(false); |
| 19 | + // Hook used to set the chart that the Modal displays. The |
| 20 | + // modalDisplay state is drilled into the Modal component. |
| 21 | + const [modalChart, setModalChart] = useState(); |
| 22 | + // Hook used to set the Modal Component title. The "alt" attribute |
| 23 | + // is grabbed from the onClick event via event.path[0].alt |
| 24 | + const [chartTitle, setChartTitle] = useState(); |
| 25 | + |
| 26 | + // route button AND traffic button property |
| 27 | + const routeButtonProperty = { |
| 28 | + traffic: { |
| 29 | + id: 'Traffic', |
| 30 | + alt: 'Microservice Traffic', |
| 31 | + src: 'app/assets/chartModal.png', |
| 32 | + }, |
| 33 | + routes: { id: 'routesImage', alt: 'Route Trace', src: routeChart }, |
| 34 | + }; |
| 35 | + |
| 36 | + // declare routes array to display routes when modal is toggled |
| 37 | + const routes = []; |
| 38 | + // declare traffic array to display traffic when modal is toggled |
| 39 | + const traffic = []; |
| 40 | + |
| 41 | + // push traffic component logic traffic |
| 42 | + traffic.push( |
| 43 | + <div className="healthChartContainer"> |
| 44 | + <input |
| 45 | + onClick={() => { |
| 46 | + setChartTitle(event.path[0].alt); |
| 47 | + setModalChart(event.path[0].id); |
| 48 | + toggleModalDisplay(!modalDisplay); |
| 49 | + }} |
| 50 | + type="image" |
| 51 | + id={routeButtonProperty.traffic.id} |
| 52 | + src={routeButtonProperty.traffic.src} |
| 53 | + width="60px" |
| 54 | + alt={routeButtonProperty.traffic.alt} |
| 55 | + /> |
| 56 | + <br /> |
| 57 | + <div style={{ color: 'white', paddingLeft: '7px' }}> |
| 58 | + {routeButtonProperty.traffic.id} |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + ); |
| 62 | + |
| 63 | + // push routes component logic traffic |
| 64 | + routes.push( |
| 65 | + <div className="healthChartContainer"> |
| 66 | + <input |
| 67 | + onClick={() => { |
| 68 | + setChartTitle(event.path[0].alt); |
| 69 | + setModalChart(event.path[0].id); |
| 70 | + toggleModalDisplay(!modalDisplay); |
| 71 | + }} |
| 72 | + type="image" |
| 73 | + id={routeButtonProperty.routes.id} |
| 74 | + src="app/assets/routeChart.png" |
| 75 | + width="60px" |
| 76 | + alt={routeButtonProperty.routes.alt} |
| 77 | + /> |
| 78 | + <br /> |
| 79 | + <div style={{ color: 'white', paddingLeft: '7px' }}>Routes</div> |
| 80 | + </div> |
| 81 | + ); |
| 82 | + |
| 83 | + return ( |
| 84 | + <div className="mainContainer"> |
| 85 | + <MonitorHeader /> |
| 86 | + {modalDisplay ? ( |
| 87 | + <Modal |
| 88 | + chartTitle={chartTitle} |
| 89 | + modalChart={modalChart} |
| 90 | + service="" |
| 91 | + toggleModalDisplay={toggleModalDisplay} |
| 92 | + onClick={() => { |
| 93 | + toggleModalDisplay(!modalDisplay); |
| 94 | + }} |
| 95 | + /> |
| 96 | + ) : null} |
| 97 | + <div id="routeAndTrafficDisplay"> |
| 98 | + {routes} |
| 99 | + {traffic} |
| 100 | + </div> |
| 101 | + {detail || null} |
| 102 | + </div> |
| 103 | + ); |
| 104 | +}; |
| 105 | + |
| 106 | +export default MonitoringContainer; |
0 commit comments