|
| 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; |
0 commit comments