Skip to content

Commit 58e8dba

Browse files
committed
reset settings JSON
2 parents a201ac4 + b4a6ff5 commit 58e8dba

File tree

5 files changed

+88
-1
lines changed

5 files changed

+88
-1
lines changed

Main.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,29 @@ ipcMain.on('dashboard', (message) => {
119119
message.returnValue = dashboardList;
120120
});
121121

122+
//ipc 'deleteService' route
123+
ipcMain.on('deleteService', (message, index) => {
124+
//assigns state to the returned the object returned from settings.json
125+
let state = JSON.parse(
126+
//read json from settings.json
127+
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
128+
encoding: 'UTF-8',
129+
}),
130+
);
131+
// updating the services
132+
if(state.services.length > 1){
133+
state.services.splice(index,1);
134+
}else{
135+
state= {"setupRequired":true, "services":["hard","coded","in"] }
136+
}
137+
138+
//write json from settings.json
139+
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state), {
140+
encoding: 'UTF-8'})
141+
message.sender.send('deleteResponse', state.services);
142+
});
143+
144+
122145
// Queries the database for communications information and returns it back to the render process.
123146
ipcMain.on('overviewRequest', (message, index) => {
124147
const services = JSON.parse(

app/components/DeleteService.jsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React, { useContext } from 'react';
2+
import DashboardContext from '../context/DashboardContext';
3+
import SetupContext from '../context/SetupContext';
4+
5+
6+
const { ipcRenderer } = window.require('electron');
7+
8+
9+
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.
13+
const setup = useContext(SetupContext);
14+
15+
// List of the databases saved by users to track microservices.
16+
let serviceList = useContext(DashboardContext);
17+
18+
// Only happens when a DB button is clicked
19+
const onDelete= (index) => {
20+
// IPC communication used to delete the button pressed.
21+
ipcRenderer.send('deleteService', index);
22+
ipcRenderer.on('deleteResponse', (event, services) => {
23+
serviceList = services;
24+
if(serviceList === ["hard","coded","in"]){
25+
setup.setupRequired =setup.toggleSetup(false);
26+
}
27+
document.location.reload();
28+
29+
});
30+
}
31+
32+
const databaseButtons =[];
33+
for(let i = 0; i<serviceList.length; i++){
34+
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
37+
if (moveForward){onDelete(i)}
38+
39+
}}>{serviceList[i]}</button>)
40+
}
41+
42+
return (
43+
<div className="mainContainer">
44+
<h1 className='overviewTitle'>Press on the Database You Want to Delete</h1>
45+
<div className="servicesList">{databaseButtons}</div>
46+
</div>
47+
);
48+
};
49+
50+
export default DeleteService;

app/components/ServicesDashboard.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ServiceOverview from './ServiceOverview.jsx';
33
import DashboardContext from '../context/DashboardContext';
44
import SetupContext from '../context/SetupContext';
55
import AddService from './AddService.jsx';
6+
import DeleteService from './DeleteService.jsx';
67

78
const ServicesDashboard = (props) => {
89
// Used to toggle setup required if user wants to add a new database.
@@ -55,6 +56,16 @@ const ServicesDashboard = (props) => {
5556
>
5657
Add Database
5758
</button>
59+
<button
60+
className="overviewSubmitBtn"
61+
type="submit"
62+
key="goToDeletePage"
63+
onClick={() => {
64+
setSelection(<DeleteService />);
65+
}}
66+
>
67+
Delete Database
68+
</button>
5869
</div>
5970
<div className="left-bottom">
6071
<button

app/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,6 @@ form {
349349
font-size: 2vh;
350350
/* margin-top: -4%; */
351351
}
352+
.deleteMicroservice{
353+
padding: 10px;
354+
}

user/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"setupRequired":false,"services":[["Ousman Microservice","SQL","\tpostgres://wcdnbpvl:[email protected]:5432/wcdnbpvl"],["MSlocation1 - Ousman","SQL","postgres://mnspuhgt:[email protected]:5432/mnspuhgt"]]}
1+
{"setupRequired":true,"services":["hard","coded","in"]}

0 commit comments

Comments
 (0)