Skip to content

Commit 8f37578

Browse files
committed
Managing App State
1 parent 61957a2 commit 8f37578

5 files changed

Lines changed: 46 additions & 38 deletions

File tree

app/AComp/Microservices.jsx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1-
import React, { useContext } from 'react';
1+
import React, { useContext, useState, useEffect } from 'react';
2+
import OverviewContext from '../context/OverviewContext';
23
import HealthInformationContext from '../context/DetailsContext';
34
import ServiceDetails from '../components/ServiceDetails.jsx';
45

6+
57
const { ipcRenderer } = window.require('electron');
68

79
const Microservices = (props) => {
8-
const { overviewState, setDetails, index } = props;
10+
const { index, setDetails } = props;
11+
// Overview state used to create service buttons
12+
const [overviewState, setOverviewState] = useState([]);
13+
// const [detailsSelected, setDetails] = useState();
14+
// Contexts have data added to them following successful IPC return. Data is later used to create charts.
15+
const serviceComponents = useContext(OverviewContext);
16+
17+
useEffect(() => {
18+
// IPC communication used to initiate query for information on microservices.
19+
ipcRenderer.send('overviewRequest', index);
20+
// IPC listener responsible for retrieving infomation from asynchronous main process message.
21+
ipcRenderer.on('overviewResponse', (event, data) => {
22+
// Adds to state and context.
23+
// console.log(JSON.parse(data));
24+
setOverviewState(Object.values(JSON.parse(data)));
25+
serviceComponents.overviewData = JSON.parse(data);
26+
});
27+
}, []);
28+
929
// Holds the buttons generated for unique services.
1030
const componentButtons = [];
1131

@@ -26,6 +46,7 @@ const Microservices = (props) => {
2646
type="button"
2747
key={`serviceItem${index}${i}`}
2848
onClick={() => {
49+
console.log(element.currentmicroservice);
2950
// IPC communication used to initiate query for information on microservice health information.
3051
ipcRenderer.send('detailsRequest', index);
3152

@@ -35,12 +56,10 @@ const Microservices = (props) => {
3556
healthdata.detailData = Object.values(JSON.parse(data));
3657
// Updates state. Triggers rerender.
3758
setDetails(
38-
<ServiceDetails
39-
service={element.currentmicroservice}
40-
setDetails={setDetails}
41-
/>
59+
<ServiceDetails service={element.currentmicroservice} />
4260
);
4361
});
62+
// setSelection(<Monitoring detailsSelected={detailsSelected} />);
4463
}}
4564
>
4665
{element.currentmicroservice}
@@ -59,18 +78,17 @@ const Microservices = (props) => {
5978
type="button"
6079
key={`serviceItem${index}${i}`}
6180
onClick={() => {
62-
ipcRenderer.send('detailsRequest', props.index);
63-
81+
ipcRenderer.send('detailsRequest', index);
82+
6483
// IPC listener responsible for retrieving infomation from asynchronous main process message.
6584
ipcRenderer.on('detailsResponse', (event, data) => {
6685
// Adds returned data to context.
86+
console.log(element.currentmicroservice);
6787
healthdata.detailData = Object.values(JSON.parse(data));
6888
// Updates state. Triggers rerender.
6989
setDetails(
70-
<ServiceDetails
71-
service={element.currentMicroservice}
72-
setDetails={setDetails}
73-
/>
90+
<ServiceDetails service={element.currentmicroservice} />
91+
7492
);
7593
});
7694
}}

app/components/ServiceDetails.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import Modal from './Modal.jsx';
55
// Renders charts created with health and communication data for a selected database.
66
const ServiceDetails = (props) => {
77
// Renders health info detail buttons
8-
const { service, setDetails } = props;
8+
const { service } = props;
9+
console.log(service);
910
// Hook used to toggle whether or not the Modal component renders
1011
const [modalDisplay, toggleModalDisplay] = useState(false);
1112
// Hook used to set the chart that the Modal displays. The
@@ -85,7 +86,7 @@ const ServiceDetails = (props) => {
8586
onClick={() => {
8687
// document.location.reload()
8788
console.log('should clear data');
88-
setDetails(null);
89+
// setDetails(null);
8990
}}
9091
>
9192
Clear Health Data

app/containers/DashboardContainer.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import '../stylesheets/dashboard.css';
77
const DashboardContainer = () => {
88
// Used to hold the buttons created for each database found in context.
99
const [serviceSelected, setSelection] = useState();
10-
// const [detailsSelected, setDetails] = useState();
10+
const [detailsSelected, setDetails] = useState();
1111
return (
1212
<div className="servicesDashboardContainer">
13-
<SidebarContainer setSelection={setSelection} />
13+
<SidebarContainer setSelection={setSelection} setDetails={setDetails} />
1414
<div className="databsaseList">
15-
{serviceSelected}
15+
{serviceSelected || <Monitoring detailsSelected={detailsSelected} />}
1616
</div>
1717
</div>
1818
);

app/containers/SideBarContainer.jsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import Extras from '../AComp/Extras.jsx';
44
import SetupContext from '../context/SetupContext';
55
import DashboardContext from '../context/DashboardContext';
66
import Microservices from '../AComp/Microservices.jsx';
7-
import OverviewContext from '../context/OverviewContext';
87
import ServicesList from '../AComp/ServicesList.jsx';
98
import AddService from '../components/AddService.jsx';
109
import DeleteService from '../components/DeleteService.jsx';
11-
import Monitoring from './MonitoringContainer.jsx';
10+
// import Monitoring from './MonitoringContainer.jsx';
1211
import '../stylesheets/sidebar.css';
1312

1413
const { ipcRenderer } = window.require('electron');
@@ -18,17 +17,15 @@ const SidebarContainer = (props) => {
1817
// Used to toggle setup required if user wants to add a new database.
1918
const setup = useContext(SetupContext);
2019

21-
const { setSelection } = props;
20+
const { setSelection, setDetails} = props;
2221

23-
const [detailsSelected, setDetails] = useState();
22+
2423
// List of the databases saved by users to track microservices.
2524
const serviceList = useContext(DashboardContext);
2625

27-
// Overview state used to create service buttons
28-
const [overviewState, setOverviewState] = useState([]);
26+
2927

30-
// Contexts have data added to them following successful IPC return. Data is later used to create charts.
31-
const serviceComponents = useContext(OverviewContext);
28+
3229
const [index, setIndex] = useState();
3330
const [isclicked, setClicked] = useState('false');
3431

@@ -41,16 +38,8 @@ const SidebarContainer = (props) => {
4138
const ServicesClick = (e) => {
4239
clickToggle(e);
4340
setIndex(e.target.id);
44-
// const event = e.target.id;
45-
ipcRenderer.send('overviewRequest', e.target.id);
46-
// IPC listener responsible for retrieving infomation from asynchronous main process message.
47-
ipcRenderer.on('overviewResponse', (event, data) => {
48-
// Adds to state and context.
49-
// console.log(JSON.parse(data));
50-
setOverviewState(Object.values(JSON.parse(data)));
51-
serviceComponents.overviewData = JSON.parse(data);
52-
});
53-
setSelection(<Monitoring detailsSelected={detailsSelected} />);
41+
42+
// setSelection(<Monitoring detailsSelected={detailsSelected} />);
5443
};
5544
// Click function for AddService
5645
const AddClick = () => {
@@ -75,9 +64,9 @@ const SidebarContainer = (props) => {
7564
/>
7665
{isclicked === 'true' ? (
7766
<Microservices
78-
overviewState={overviewState}
79-
setDetails={setDetails}
67+
setSelection={setSelection}
8068
index={index}
69+
setDetails={setDetails}
8170
/>
8271
) : null}
8372
<Extras

user/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"setupRequired":false,"services":[["test","MongoDB","mongodb+srv://alon:testing123@cluster0-phsei.mongodb.net/test?retryWrites=true&w=majority"]],"splash":true}
1+
{"setupRequired":false,"services":[["test","MongoDB","mongodb+srv://alon:testing123@cluster0-phsei.mongodb.net/test?retryWrites=true&w=majority"]],"splash":false}

0 commit comments

Comments
 (0)