Skip to content

Commit e802431

Browse files
committed
user settings conflict resolved
2 parents 1d3012d + 3b2c10c commit e802431

File tree

8 files changed

+2615
-249
lines changed

8 files changed

+2615
-249
lines changed

Main.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ app.on('activate', () => {
8585
// Fired by the useEffect hook inside of the Splash.jsx component, this message route will toggle
8686
// splash property inside of settings.json to false once the Splash page renders itself just once
8787
ipcMain.on('toggleSplash', (message) => {
88-
console.log('toggleSplash message received');
88+
//console.log('toggleSplash message received');
8989
const state = JSON.parse(
9090
// read json from settings.json
9191
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
@@ -102,7 +102,7 @@ ipcMain.on('toggleSplash', (message) => {
102102
});
103103

104104
ipcMain.on('checkSplash', (message) => {
105-
console.log('checkSplash message received');
105+
//sconsole.log('checkSplash message received');
106106
const state = JSON.parse(
107107
// read json from settings.json
108108
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
@@ -116,7 +116,7 @@ ipcMain.on('checkSplash', (message) => {
116116
// Load settings JSON and returns current setup status back to the render process.
117117
// ipc 'setup' route --> Ousman
118118
ipcMain.on('setup', (message) => {
119-
console.log('setup message received');
119+
//console.log('setup message received');
120120
// assigns state to the returned the object returned from settings.json --> Ousman
121121
const state = JSON.parse(
122122
// read json from settings.json
@@ -133,30 +133,31 @@ ipcMain.on('setup', (message) => {
133133
// Loads existing settings JSON and update settings to include new services entered by the user.
134134
// on ipc 'submit' request --> Ousman
135135
ipcMain.on('submit', (message, newService) => {
136-
// assigning state to the parsed return of setting
136+
// Declares a variable state and initialize it to the returned parsed json object from the user/settings.json file
137137
const state = JSON.parse(
138138
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
139139
encoding: 'UTF-8',
140140
}),
141141
);
142-
// if statement is used to replace hard coded data. Hard coded data and the michelleWasHere key is needed to avoid a load error caused by Electron querying the database before a user has added or selected a database.
143142

144-
//* ** What is happening here --> Ousman */
143+
// Checks if setup is required by checking if the value for the state key 'setupRequired' is true
145144
if (state.setupRequired) {
145+
// If setup is required, the value for key 'setupRequired' is reassign to false and the value for key 'services' is reassign to an array with newService as its only element
146146
state.setupRequired = false;
147147
state.services = [JSON.parse(newService)];
148-
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state));
149148
} else {
150-
state.setupRequired = false;
149+
// Else the newService is pushed into the services array
151150
state.services.push(JSON.parse(newService));
152-
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state));
153-
}
151+
}
152+
153+
// Rewrites user/settings.json to show state
154+
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state));
154155
});
155156

156157
// Load settings JSON and returns updated state back to the render process.
157158
// on ipc 'dashboard' request --> Ousman
158159
ipcMain.on('dashboard', (message) => {
159-
// assign state to the parsed return of setting --> Ousman
160+
// Declares a variable state and initialize it to the returned parse json object from the user/settings.json file
160161
const state = JSON.parse(
161162
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
162163
encoding: 'UTF-8',
@@ -171,24 +172,29 @@ ipcMain.on('dashboard', (message) => {
171172
message.returnValue = dashboardList;
172173
});
173174

174-
// ipc 'deleteService' route
175+
// Deletes the service at position 'index' from the services array within the user/setting.json file,
176+
// resets the user/setting.json file to what it was originally if all of the services are deleted,
177+
// and sends the remaining services back to onDelete function within DeleteService as a response
175178
ipcMain.on('deleteService', (message, index) => {
176-
// assigns state to the returned the object returned from settings.json
179+
// Declares a variable state and initialize it to the returned parse json object from the user/settings.json file
177180
let state = JSON.parse(
178-
// read json from settings.json
179181
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
180182
encoding: 'UTF-8',
181183
}),
182184
);
185+
186+
// Send a response back with the updated services
183187
const { splash } = state;
184-
// updating the services
188+
// Checks if there is more than one services in the services array
185189
if (state.services.length > 1) {
190+
// If true, removes the service at position 'index'
186191
state.services.splice(index, 1);
187192
} else {
193+
// Else reassign state to what the user/setting.json file was originally before any database was save
188194
state = { setupRequired: true, services: ['hard', 'coded', 'in'], splash };
189195
}
190196

191-
// write json from settings.json
197+
// Rewrites json from settings.json
192198
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state), { encoding: 'UTF-8' });
193199
message.sender.send('deleteResponse', state.services);
194200
});

app/charts/microservice-traffic.jsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const MicroServiceTraffic = (props) => {
2929
}
3030

3131
else {
32-
3332
for (let i = communicationsData.length-1; i >= 0; i--) {
3433
const element = communicationsData[i];
3534
if (resObj[element.correlatingid]) resObj[element.correlatingid].push(element.currentmicroservice);
@@ -40,26 +39,30 @@ const MicroServiceTraffic = (props) => {
4039

4140
//use object values to destructure locations
4241
const tracePoints = Object.values(resObj);
43-
let position = communicationsData[0].correlatingid ? 0 : tracePoints.length-1;
44-
42+
4543
// Declare Micro-server-count dictinary to capture the amount of times a particular server is hit
4644
const microServiceCountdictionary = {};
4745

46+
//array logging every ping present in communications table ---> flat used to flatten multidimensional array and return 1d array
47+
const tracePointLog = tracePoints.flat(Infinity);
48+
4849
// iterate over Trace Points
49-
for (let i = 0; i < tracePoints[position].length; i+=1) {
50+
for (let i = 0; i < tracePointLog.length; i+=1) {
5051

5152
// populate Micro-count dictionary
52-
if (!microServiceCountdictionary[tracePoints[position][i]]) {
53-
microServiceCountdictionary[tracePoints[position][i]] = 1;
53+
if (!microServiceCountdictionary[tracePointLog[i]]) {
54+
microServiceCountdictionary[tracePointLog[i]] = 1;
5455
} else {
55-
microServiceCountdictionary[tracePoints[position][i]]+=1
56+
microServiceCountdictionary[tracePointLog[i]]+=1
5657
}
5758
};
5859

5960
// capture values of microServiceCountdictionary to use as data to populate chart object
6061
const serverPingCount = Object.values(microServiceCountdictionary);
6162

62-
63+
// variable 10 points higher than max number in microservicesDictionary aggregation --> variable allows for top level spacing on bar graph
64+
const yAxisHeadRoom = (Math.max(...serverPingCount) + 10);
65+
6366
// Create chart object data to feed into bar component
6467
const myChart = {
6568
//spread dictionary keys inorder to properly label chart x axis
@@ -70,9 +73,9 @@ const MicroServiceTraffic = (props) => {
7073
backgroundColor: 'rgba(241, 207, 70,1)',
7174
borderColor: 'rgba(0,0,0,1)',
7275
borderWidth: 1,
73-
data: [...serverPingCount, 0] // spread ping count array into data array to have chart populate the Y axis
76+
data: [...serverPingCount, 0, yAxisHeadRoom] // spread ping count array into data array to have chart populate the Y axis
7477
}
75-
]
78+
],
7679
}
7780

7881

app/components/DeleteService.jsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,48 @@ import React, { useContext } from 'react';
22
import DashboardContext from '../context/DashboardContext';
33
import SetupContext from '../context/SetupContext';
44

5-
5+
// Declare a constant ipcRenderer by deconstructing window.require('electron') so that the onDelete function can initialize an IPC Communication
66
const { ipcRenderer } = window.require('electron');
77

88

9+
// Deletes a Service
910
const DeleteService = (props) => {
10-
console.log('in the DeleteService')
11-
12-
// Used to toggle setup required if user wants delete all of the databases and the user needs to be sent to the front page.
11+
// Declares a constant setup and initialize it to the SetupContext.
12+
// SetupContext indicates whether or not an initial setup is necessary.
13+
// An initial setup is necessary when the user has not saved any database to chronos frontend application.
1314
const setup = useContext(SetupContext);
1415

15-
// List of the databases saved by users to track microservices.
16+
// Declares a variable serviceList and initialize it to the DashboardContext.
17+
// DashboardContext lists the databases saved by users.
1618
let serviceList = useContext(DashboardContext);
1719

18-
// Only happens when a DB button is clicked
20+
/*
21+
Sends a deleteService request with an index to an ipcMain.on function within the Main.js
22+
On return, the function reassigns the serviceList variable to the updated services provided within the deleteResponse. If the serviceList equals ["hard","coded","in"], then the user has no database saved to the chronos frontend application. If this is true, the function reassigns setup.setupRequired to true by invoking setup.toggleSetup with the argument 'false'. Then the function reloads the application to show the changes made to the services.
23+
*/
1924
const onDelete= (index) => {
20-
// IPC communication used to delete the button pressed.
2125
ipcRenderer.send('deleteService', index);
2226
ipcRenderer.on('deleteResponse', (event, services) => {
2327
serviceList = services;
2428
if(serviceList === ["hard","coded","in"]){
25-
setup.setupRequired =setup.toggleSetup(false);
29+
setup.setupRequired = setup.toggleSetup(false);
2630
}
2731
document.location.reload();
28-
2932
});
3033
}
3134

35+
// Declares a constant databaseButtons and initialize it an empty array
3236
const databaseButtons =[];
37+
38+
/* Iterates over the serviceList to create a button for each service. Each button is pushed into the databaseButtons array as the button is created. Each button has an onclick function that invokes the window confirm function with a warning message (ex:'Are you sure you want to delete this service?') and stores the result of invoking confirm into a constant moveForward. If the moveForward is true, then onDelete function is invoked with the index of where the service is stored within the serviceList*/
3339
for(let i = 0; i<serviceList.length; i++){
3440
databaseButtons.push(<button className="microserviceBtn deleteMicroservice" key ={"delete"+i} onClick={()=>{
35-
const moveForward = confirm(`Are you sure you want to delete ${serviceList[i]}? \n If "YES" press the "OK" button, \n else press the "Cancel" button`);
36-
// if yes run the function
41+
const moveForward = confirm(`Are you sure you want to delete ${serviceList[i]}? \n If "YES" press the "OK" button, else press the "Cancel" button`);
3742
if (moveForward){onDelete(i)}
3843

3944
}}>{serviceList[i]}</button>)
4045
}
41-
46+
// returns the title of the page with all of the services that can be deleted as buttons
4247
return (
4348
<div className="mainContainer">
4449
<h1 className='overviewTitle'>Press on the Database You Want to Delete</h1>
@@ -47,4 +52,6 @@ const DeleteService = (props) => {
4752
);
4853
};
4954

55+
// export the DeleteService function so that it can imported anywhere
5056
export default DeleteService;
57+

app/components/Modal.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ const Modal = (props) => {
2929

3030
// event.stopPropogation allows the user to interact with the chart as opposed to a click on the
3131
// chart bubbling out and closing the Modal.
32-
33-
console.log('Modal Props: ', props);
34-
console.log('Modal props.modalChart: ', modalChart);
32+
3533
return (
3634
<div id="modalWindow" onClick={() => toggleModalDisplay(!toggleModalDisplay)}>
3735
<div id="modalContent" onClick={(event) => event.stopPropagation()}>

app/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,5 @@ form {
454454
}
455455
.deleteMicroservice{
456456
padding: 10px;
457+
margin: 10px;
457458
}

0 commit comments

Comments
 (0)