|
1 | | -import React from 'react'; |
2 | | -import RequestTypesChart from '../charts/request-type-chart.jsx'; |
3 | | -import ResponseCodesChart from '../charts/response-code-chart.jsx'; |
4 | | -import SpeedChart from '../charts/speed-chart.jsx'; |
5 | | -import ProcessesChart from '../charts/processes-chart.jsx'; |
6 | | -import TemperatureChart from '../charts/temperature-chart.jsx' |
7 | | -import LatencyChart from '../charts/latency-chart.jsx'; |
8 | | -import MemoryChart from '../charts/memory-chart.jsx'; |
| 1 | +/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ |
| 2 | +import React, { useState } from 'react'; |
| 3 | +import Modal from './Modal.jsx'; |
9 | 4 |
|
10 | | -// Renders charts created with health and communication data for a selected database. |
| 5 | +// Renders health info detail buttons |
11 | 6 | const ServiceDetails = (props) => { |
| 7 | + const { service } = props; |
| 8 | + // Hook used to toggle whether or not the Modal component renders |
| 9 | + const [modalDisplay, toggleModalDisplay] = useState(false); |
| 10 | + // Hook used to set the chart that the Modal displays. The |
| 11 | + // modalDisplay state is drilled into the Modal component. |
| 12 | + const [modalChart, setModalChart] = useState(); |
| 13 | + // Hook used to set the Modal Component title. The "alt" attribute |
| 14 | + // is grabbed from the onClick event via event.path[0].alt |
| 15 | + const [chartTitle, setChartTitle] = useState(); |
| 16 | + |
| 17 | + // Dictionary used by the healthInfoButtons loop below |
| 18 | + const buttonProperties = [ |
| 19 | + { id: 'request', alt: 'Request Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' }, |
| 20 | + { id: 'response', alt: 'Response Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' }, |
| 21 | + { id: 'speed', alt: 'Speed Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' }, |
| 22 | + { id: 'processes', alt: 'Processes Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' }, |
| 23 | + { id: 'latency', alt: 'Latency Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' }, |
| 24 | + { id: 'temperature', alt: 'Temperature Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' }, |
| 25 | + { id: 'memory', alt: 'Memory Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' }, |
| 26 | + ]; |
| 27 | + |
| 28 | + // Create the Health Info buttons and their associated properties. Each time a button is clicked, |
| 29 | + // setChartTitle will grab a title to render in the Modal component, setModalChart will grab the |
| 30 | + // correct chart to render, and toggleModalDisplay will actually render the Modal display |
| 31 | + const healthInfoButtons = []; |
| 32 | + for (let i = 0; i < buttonProperties.length; i += 1) { |
| 33 | + healthInfoButtons.push( |
| 34 | + <div className="healthChartContainer"> |
| 35 | + <input |
| 36 | + onClick={() => { |
| 37 | + setChartTitle(event.path[0].alt); |
| 38 | + setModalChart(event.path[0].id); |
| 39 | + toggleModalDisplay(!modalDisplay); |
| 40 | + }} |
| 41 | + type="image" |
| 42 | + id={buttonProperties[i].id} |
| 43 | + src={buttonProperties[i].src} |
| 44 | + width="50px" |
| 45 | + alt={buttonProperties[i].alt} |
| 46 | + /> |
| 47 | + </div>, |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + |
12 | 52 | return ( |
13 | | - <div> |
| 53 | + <div id="serviceDetailsContainer"> |
| 54 | + {modalDisplay ? ( |
| 55 | + <Modal |
| 56 | + chartTitle={chartTitle} |
| 57 | + service={service} |
| 58 | + modalChart={modalChart} |
| 59 | + toggleModalDisplay={toggleModalDisplay} |
| 60 | + onClick={() => { |
| 61 | + toggleModalDisplay(!modalDisplay); |
| 62 | + }} |
| 63 | + /> |
| 64 | + ) : null} |
14 | 65 | <button className="backButton" type="button" onClick={() => document.location.reload()}>Back</button> |
15 | | - <div> |
16 | | - <h3>Request Types</h3> |
17 | | - <RequestTypesChart service={props.service} /> |
18 | | - </div> |
19 | | - <div> |
20 | | - <h3>Response Codes </h3> |
21 | | - <ResponseCodesChart service={props.service} /> |
22 | | - </div> |
23 | | - <div> |
24 | | - <h3>Speed Chart</h3> |
25 | | - <SpeedChart service={props.service} /> |
26 | | - </div> |
27 | | - <div> |
28 | | - <h3>Processes Chart</h3> |
29 | | - <ProcessesChart service={props.service} /> |
30 | | - </div> |
31 | | - <div> |
32 | | - <h3>Latency</h3> |
33 | | - <LatencyChart service={props.service} /> |
34 | | - </div> |
35 | | - <div> |
36 | | - <h3>Temperature Chart</h3> |
37 | | - <TemperatureChart service={props.service} /> |
38 | | - </div> |
39 | | - <div> |
40 | | - <h3>Memory Chart</h3> |
41 | | - <MemoryChart service={props.service} /> |
| 66 | + <h3 id="microserviceHealthTitle">Microservice Health</h3> |
| 67 | + <div id="healthGrid"> |
| 68 | + {healthInfoButtons} |
42 | 69 | </div> |
43 | 70 | </div> |
44 | 71 | ); |
|
0 commit comments