Skip to content

Commit c996642

Browse files
authored
Merge pull request #14 from Chronos2-0/jenae/ben/route_with_microservices
Jenae/ben/route with microservices
2 parents 4304d7c + f733051 commit c996642

11 files changed

Lines changed: 91 additions & 29 deletions

.DS_Store

0 Bytes
Binary file not shown.

app/assets/latencyChart.png

93.5 KB
Loading

app/assets/memoryChart.png

8.28 KB
Loading

app/assets/processingChart.png

56 KB
Loading

app/assets/routeChart.png

87.9 KB
Loading

app/assets/speedChart.png

32.8 KB
Loading

app/assets/tempChart.png

11.6 KB
Loading

app/charts/route-trace.jsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,50 @@
11
import React, { useContext } from 'react';
2-
import { Doughnut } from 'react-chartjs-2';
32
import CommunicationsContext from '../context/OverviewContext';
43

54
const RouteLocations = (props) => {
65
const communicationsData = useContext(CommunicationsContext).overviewData;
76

8-
console.log('THIS IS ROUTE TRACE: ', communicationsData);
9-
7+
//initialize an empty object resObj. This object will store the microservice names as values and its corresponding correlatingId or correlatingid as keys. The microservice names will be stored in array within the order it was to the database.
108
const resObj = {};
11-
for (let i = 0; i < communicationsData.length; i+=1) {
9+
10+
if(communicationsData.length>0 && communicationsData[0]["_id"]){
11+
//Sort the communication array from latest to earliest document
12+
communicationsData.sort((a,b)=>{ new Date(a.timeSent) - new Date(b.timeSent)})
13+
14+
//Iterate over sorted communicationsData array from the end to the beginning
15+
for (let i = communicationsData.length-1; i >= 0; i--) {
16+
//declare a constant element and initialize it as the object at index i of the communicationsData array
17+
const element = communicationsData[i];
18+
//Pushes the microservice name into the object
19+
if (resObj[element.correlatingId]) {
20+
resObj[element.correlatingId].push(element.currentMicroservice);
21+
}
22+
else resObj[element.correlatingId] = [element.currentMicroservice];
23+
// initializing the object with the first microservice
24+
}
25+
}
26+
else{
27+
for (let i = communicationsData.length-1; i >= 0; i--) {
1228
const element = communicationsData[i];
1329
if (resObj[element.correlatingid]) resObj[element.correlatingid].push(element.currentmicroservice);
14-
else {resObj[element.correlatingid] = [element.currentmicroservice]};
30+
else resObj[element.correlatingid] = [element.currentmicroservice];
31+
// initializing the object with the first microservice
1532
};
33+
}
1634

1735
//use object values to destructure locations
1836
const tracePoints = Object.values(resObj);
19-
console.log('THIS IS TRACEPOINTES: ', tracePoints[0]);
20-
37+
let position = tracePoints.length-1;
38+
2139
const resArray = [];
22-
for (let i = 0; i < tracePoints[0].length; i+=1) {
40+
for (let i = 0; i < tracePoints[position].length; i+=1) {
2341
resArray.push(
2442
<div className="RouteCircle" key={i}>
25-
<p id="routeText">Point {i+1}: {tracePoints[0][i]}</p>
43+
<p id="routeText">Point {i+1}: {tracePoints[position][i]}</p>
2644
</div>
2745
)
2846
};
2947

30-
31-
// console.log('ARRAY OF LOCATIONS: ', resObj);
3248
return (
3349
<div>
3450
{resArray}

app/components/ServiceDetails.jsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import React, { useState } from 'react';
22
import Modal from './Modal.jsx';
33
import pieChart from '../assets/pieChart.png'
4-
import RequestTypesChart from '../charts/request-type-chart.jsx';
5-
import ResponseCodesChart from '../charts/response-code-chart.jsx';
6-
import RouteTrace from '../charts/route-trace.jsx';
7-
import SpeedChart from '../charts/speed-chart.jsx';
8-
import ProcessesChart from '../charts/processes-chart.jsx';
9-
import TemperatureChart from '../charts/temperature-chart.jsx'
10-
import LatencyChart from '../charts/latency-chart.jsx';
11-
import MemoryChart from '../charts/memory-chart.jsx';
4+
import memoryChart from '../assets/memoryChart.png'
5+
import tempChart from '../assets/tempChart.png'
6+
import speedChart from '../assets/speedChart.png'
7+
import latencyChart from '../assets/latencyChart.png'
8+
import processingChart from '../assets/processingChart.png'
129

1310
// Renders charts created with health and communication data for a selected database.
1411
const ServiceDetails = (props) => {
@@ -30,13 +27,13 @@ const ServiceDetails = (props) => {
3027

3128
const buttonProperties = [
3229
{ id: 'request', alt: 'Request Data', src: pieChart },
33-
{ id: 'response', alt: 'Response Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
34-
{ id: 'routes', alt: 'Route Trace', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
35-
{ id: 'speed', alt: 'Speed Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
36-
{ id: 'processes', alt: 'Processes Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
37-
{ id: 'latency', alt: 'Latency Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
38-
{ id: 'temperature', alt: 'Temperature Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
39-
{ id: 'memory', alt: 'Memory Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
30+
{ id: 'response', alt: 'Response Data', src: pieChart },
31+
// { id: 'routes', alt: 'Route Trace', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
32+
{ id: 'speed', alt: 'Speed Data', src: speedChart},
33+
{ id: 'processes', alt: 'Processes Data', src: processingChart },
34+
{ id: 'latency', alt: 'Latency Data', src: latencyChart },
35+
{ id: 'temperature', alt: 'Temperature Data', src: tempChart },
36+
{ id: 'memory', alt: 'Memory Data', src: memoryChart },
4037
];
4138

4239
// Create the Health Info buttons and their associated properties. Each time a button is clicked,

app/components/ServiceOverview.jsx

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useState, useEffect, useContext } from 'react';
22
import OverviewContext from '../context/OverviewContext';
33
import HealthInformationContext from '../context/DetailsContext';
44
import ServiceDetails from './ServiceDetails.jsx';
5+
import Modal from './Modal.jsx';
6+
import routeChart from '../assets/routeChart.png'
57

68
const { ipcRenderer } = window.require('electron');
79

@@ -24,13 +26,46 @@ const ServiceOverview = (props) => {
2426
// IPC listener responsible for retrieving infomation from asynchronous main process message.
2527
ipcRenderer.on('overviewResponse', (event, data) => {
2628
// Adds to state and context.
27-
console.log('THIS IS ARRAY IN OVERVIEWRESPONSE: ', Object.values(JSON.parse(data)));
2829
setOverviewState(Object.values(JSON.parse(data)));
29-
// dialog.showMessageBox({shit:'Broke'});
3030
serviceComponents.overviewData = JSON.parse(data);
3131
});
3232
}, []);
3333

34+
//Add routes to the display
35+
// Hook used to toggle whether or not the Modal component renders
36+
const [modalDisplay, toggleModalDisplay] = useState(false);
37+
// Hook used to set the chart that the Modal displays. The
38+
// modalDisplay state is drilled into the Modal component.
39+
const [modalChart, setModalChart] = useState();
40+
// Hook used to set the Modal Component title. The "alt" attribute
41+
// is grabbed from the onClick event via event.path[0].alt
42+
const [chartTitle, setChartTitle] = useState();
43+
44+
const routeButtonProperty = { id: 'routes', alt: 'Route Trace', src: routeChart };
45+
const routes = [];
46+
routes.push(
47+
<div>
48+
<div className="healthChartContainer">
49+
<input
50+
onClick={() => {
51+
setChartTitle(event.path[0].alt);
52+
setModalChart(event.path[0].id);
53+
toggleModalDisplay(!modalDisplay);
54+
}}
55+
type="image"
56+
id={routeButtonProperty.id}
57+
src={routeButtonProperty.src}
58+
width="60px"
59+
alt={routeButtonProperty.alt}
60+
/>
61+
<br/>
62+
<div style={{color:'white', paddingLeft:'7px'}}>
63+
{routeButtonProperty.id}
64+
</div>
65+
</div>
66+
</div>,
67+
);
68+
3469
// Filters data received from IPC to the communications database to create a list of the services tracked in the provided database,
3570
const serviceList = () => {
3671
// Holds the buttons generated for unique services.
@@ -111,6 +146,20 @@ const ServiceOverview = (props) => {
111146
</div>
112147
<div />
113148
<div className="servicesList">{serviceList()}</div>
149+
{/* adding the route tracer button */}
150+
<h3>Trace Last Route</h3>
151+
{modalDisplay ? (
152+
<Modal
153+
chartTitle={chartTitle}
154+
modalChart={modalChart}
155+
service=""
156+
toggleModalDisplay={toggleModalDisplay}
157+
onClick={() => {
158+
toggleModalDisplay(!modalDisplay);
159+
}}
160+
/>
161+
) : null}
162+
{routes}
114163
</div>
115164
);
116165
};

0 commit comments

Comments
 (0)