Skip to content

Commit d0d19e9

Browse files
authored
Merge pull request #9 from brunoportela/notificationAdjusts
live update and display error notifications based on last viewed database
2 parents bee62ea + bf6a05b commit d0d19e9

File tree

4 files changed

+68
-48
lines changed

4 files changed

+68
-48
lines changed

app/charts/RequestTypesChart.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ const RequestTypesChart: React.FC = React.memo(() => {
3131
let type;
3232
commsData.forEach((obj: IObject) => {
3333
type = obj.request;
34-
console.log('L34:', type);
34+
// console.log('L34:', type);
3535
if (type in requestTypes) {
3636
requestTypes[type] += 1;
3737
} else {
3838
requestTypes[type] = 0;
3939
requestTypes[type]++;
4040
}
41-
console.log(requestTypes)
41+
// console.log(requestTypes)
4242
});
4343

4444
return (
@@ -53,7 +53,6 @@ const RequestTypesChart: React.FC = React.memo(() => {
5353
marker: {
5454
colors: ['#fc4039', '#4b54ea', '#32b44f', '#3788fc', '#9c27b0', '#febc2c'],
5555
},
56-
5756
},
5857
]}
5958
config={{
@@ -78,7 +77,7 @@ const RequestTypesChart: React.FC = React.memo(() => {
7877
x: 0.5,
7978
font: {
8079
size: 7,
81-
}
80+
},
8281
},
8382
}}
8483
/>

app/charts/ResponseCodesChart.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface IObj {
1414
}
1515

1616
type responseCodes = {
17-
[key: string]: number
17+
[key: string]: number;
1818
};
1919

2020
const ResponseCodesChart: React.FC = React.memo(() => {
@@ -65,7 +65,7 @@ const ResponseCodesChart: React.FC = React.memo(() => {
6565
}
6666
});
6767

68-
console.log(responseCodes);
68+
// console.log(responseCodes);
6969

7070
return (
7171
<Plot
@@ -126,7 +126,7 @@ const ResponseCodesChart: React.FC = React.memo(() => {
126126
x: 0.5,
127127
font: {
128128
size: 7,
129-
}
129+
},
130130
},
131131
}}
132132
/>

app/charts/RouteChart.jsx

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { makeStyles } from '@material-ui/core/styles';
22
import React, { useContext } from 'react';
3-
import { CommsContext } from '../context/CommsContext';
43
import Graph from 'react-graph-vis';
4+
import { CommsContext } from '../context/CommsContext';
55

66
const RouteChart = React.memo(() => {
77
const communicationsData = useContext(CommsContext).commsData;
@@ -26,10 +26,10 @@ const RouteChart = React.memo(() => {
2626
resObj[element.correlatingid].push({
2727
microservice: element.microservice,
2828
time: element.time,
29-
request: element.request, //here
29+
request: element.request, // here
3030
});
3131
}
32-
//? What does this else block do?
32+
// ? What does this else block do?
3333
} else {
3434
for (let i = communicationsData.length - 1; i >= 0; i--) {
3535
const element = communicationsData[i];
@@ -49,7 +49,6 @@ const RouteChart = React.memo(() => {
4949
}
5050
}
5151

52-
5352
// Filter the array so that only subarrays w/ len > 1 are kept.
5453
// (len == 1 means there's only one point in the route. There's no meaningful data to be gained from those.)
5554
const tracePoints = Object.values(resObj).filter(subArray => subArray.length > 1);
@@ -72,26 +71,26 @@ const RouteChart = React.memo(() => {
7271
// ======Graphs logic =======//
7372
const nodeListObj = {};
7473
const edgeListObj = {};
75-
for (let route of tracePoints) {
74+
for (const route of tracePoints) {
7675
for (let i = 0; i < route.length; i += 1) {
7776
// check if node exists if not then add node
78-
let id = route[i].microservice;
77+
const id = route[i].microservice;
7978
if (nodeListObj[id] === undefined) {
80-
nodeListObj[id] = {
81-
id: id,
82-
label: id
83-
}
79+
nodeListObj[id] = {
80+
id,
81+
label: id,
82+
};
8483
}
8584
// add edge from node to node (repeat til end)
8685
if (i !== 0) {
87-
let from = route[i - 1].microservice;
88-
let to = id;
89-
let request = route[i - 1].request; //here
90-
let edgeStr = JSON.stringify({ from, to, request })
86+
const from = route[i - 1].microservice;
87+
const to = id;
88+
const { request } = route[i - 1]; // here
89+
const edgeStr = JSON.stringify({ from, to, request });
9190
let duration = new Date(route[i].time) - new Date(route[i - 1].time);
9291
// only want one edge per route with the average duration
9392
if (edgeListObj[edgeStr]) {
94-
//? wrong math
93+
// ? wrong math
9594
duration = (duration + edgeListObj[edgeStr]) / 2;
9695
}
9796
edgeListObj[edgeStr] = duration;
@@ -102,10 +101,12 @@ const RouteChart = React.memo(() => {
102101
// turn objects into valid arrays to input into graph
103102
const nodeList = Object.values(nodeListObj);
104103
const edgeList = [];
105-
for (let [edgeStr, duration] of Object.entries(edgeListObj)) {
104+
for (const [edgeStr, duration] of Object.entries(edgeListObj)) {
106105
const edge = JSON.parse(edgeStr);
107-
console.log(edge.request)
108-
edge.label = edge.request ? `${edge.request} - ${(duration * 10).toFixed(0)} ms` : `${(duration * 10).toFixed(0)} ms`
106+
// console.log(edge.request)
107+
edge.label = edge.request
108+
? `${edge.request} - ${(duration * 10).toFixed(0)} ms`
109+
: `${(duration * 10).toFixed(0)} ms`;
109110
edgeList.push(edge);
110111
}
111112

@@ -120,12 +121,12 @@ const RouteChart = React.memo(() => {
120121
hierarchical: false,
121122
},
122123
edges: {
123-
color: "#444d56",
124+
color: '#444d56',
124125
physics: true,
125126
smooth: {
126-
type: "curvedCCW",
127-
forceDirection: "none",
128-
roundness: 0.3
127+
type: 'curvedCCW',
128+
forceDirection: 'none',
129+
roundness: 0.3,
129130
},
130131
font: {
131132
color: '#444d56',
@@ -141,27 +142,38 @@ const RouteChart = React.memo(() => {
141142
},
142143
highlight: {
143144
background: '#fc4039',
144-
}
145+
},
145146
},
146147
shape: 'circle',
147148
font: {
148149
color: '#ffffff',
149150
size: 10,
150-
face: 'roboto'
151+
face: 'roboto',
151152
},
152-
}
153-
}
153+
},
154+
};
154155

155156
const events = {
156-
select: function (event) {
157-
let { nodes, edges } = event;
157+
select(event) {
158+
const { nodes, edges } = event;
158159
},
159160
};
160161

161162
return (
162-
<div className='traceContainer'>
163-
<span id='tracesTitle'>Route Traces</span>
164-
<Graph className={classes.paper} graph={graph} options={options} events={events} style={{ fontFamily: 'Roboto', boxShadow: '3px 3px 6px 1px rgb(175, 175, 175)', backgroundColor: 'white', borderRadius: '3px' }} />
163+
<div className="traceContainer">
164+
<span id="tracesTitle">Route Traces</span>
165+
<Graph
166+
className={classes.paper}
167+
graph={graph}
168+
options={options}
169+
events={events}
170+
style={{
171+
fontFamily: 'Roboto',
172+
boxShadow: '3px 3px 6px 1px rgb(175, 175, 175)',
173+
backgroundColor: 'white',
174+
borderRadius: '3px',
175+
}}
176+
/>
165177
</div>
166178
);
167179
});

app/components/Occupied.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,15 @@ const Occupied = React.memo(() => {
5656
const [index, setIndex] = useState<number>(0);
5757
const [app, setApp] = useState<string>('');
5858
const [searchTerm, setSearchTerm] = useState<string>('');
59+
const [clickedAt, setClickedAt] = useState<string>('2000-01-01T00:00:00Z'); // init at year 2000
60+
5961
// Dynamic refs
6062
const delRef = useRef<any>([]);
6163
useEffect(() => {
6264
setServicesData([]);
6365
getApplications();
64-
// update communication data from last visited database
65-
for (const app of applications) {
66-
const temp = commsData;
67-
const newComm = fetchCommsData('', true);
68-
setCommsData([...temp, newComm])
69-
}
7066
}, []);
71-
67+
7268
// Ask user for deletetion confirmation
7369
const confirmDelete = (event: ClickEvent, app: string, i: number) => {
7470
const message = `The application '${app}' will be permanently deleted. Continue?`;
@@ -194,6 +190,19 @@ const Occupied = React.memo(() => {
194190
}));
195191

196192
let classes = (mode === 'light mode')? useStylesLight({} as StyleProps) : useStylesDark({} as StyleProps) ;
193+
194+
// update notification count based on statuscode >= 400
195+
const notification = commsData.filter((item: { responsestatus: number; }) => item.responsestatus >= 400)
196+
.filter((item: { time: string; }) => {
197+
const d1 = new Date(item.time);
198+
const d2 = new Date(clickedAt);
199+
return d1 > d2;
200+
});
201+
202+
const updateNotification = () => {
203+
const timestamp = new Date();
204+
setClickedAt(timestamp.toISOString())
205+
}
197206
return (
198207
<div className="entireArea">
199208
<div className="dashboardArea">
@@ -222,10 +231,10 @@ const Occupied = React.memo(() => {
222231
</div>
223232

224233

225-
<div className="notificationsIconArea">
226-
<span className="notificationsTooltip">You have {commsData.length} new alerts</span>
234+
<div className="notificationsIconArea" onClick={updateNotification}>
235+
<span className="notificationsTooltip">You have {notification ? notification.length : 0} new alerts</span>
227236
< NotificationsIcon className="navIcon" id="notificationsIcon" />
228-
<Badge badgeContent={commsData.length} color="secondary"/>
237+
<Badge badgeContent={notification ? notification.length : 0} color="secondary"/>
229238
</div>
230239

231240

0 commit comments

Comments
 (0)