@@ -6,28 +6,40 @@ import ServiceDetails from './ServiceDetails.jsx';
66const { ipcRenderer } = window . require ( 'electron' ) ;
77
88const ServiceOverview = ( props ) => {
9+ // Overview state used to create service buttons
910 const [ overviewState , setOverviewState ] = useState ( [ ] ) ;
11+
12+ // Details state used to cause rerender on user selection.
1013 const [ detailsSelected , setDetails ] = useState ( ) ;
14+
15+ // Contexts have data added to them following successful IPC return. Data is later used to create charts.
1116 const serviceComponents = useContext ( OverviewContext ) ;
1217 const healthdata = useContext ( HealthInformationContext ) ;
1318
19+ // Only happens when the component mounts.
1420 useEffect ( ( ) => {
1521 // IPC communication used to initiate query for information on microservices.
1622 ipcRenderer . send ( 'overviewRequest' , props . index ) ;
1723
1824 // IPC listener responsible for retrieving infomation from asynchronous main process message.
1925 ipcRenderer . on ( 'overviewResponse' , ( event , data ) => {
26+ // Adds to state and context.
2027 setOverviewState ( Object . values ( JSON . parse ( data ) ) ) ;
2128 serviceComponents . overviewData = JSON . parse ( data ) ;
2229 } ) ;
2330 } , [ ] ) ;
2431
25- const renderState = ( ) => {
32+ // Filters data received from IPC to the communications database to create a list of the services tracked in the provided database,
33+ const serviceList = ( ) => {
34+ // Holds the buttons generated for unique services.
2635 const componentButtons = [ ] ;
36+
37+ // Tracks which services already have button created.
2738 const serviceCache = { } ;
39+
2840 for ( let i = 0 ; i < overviewState . length ; i += 1 ) {
2941 const element = overviewState [ i ] ;
30- // SQL
42+ // If SQL
3143 if ( element . currentmicroservice ) {
3244 if ( ! ( element . currentmicroservice in serviceCache ) ) {
3345 const button = (
@@ -36,12 +48,14 @@ const ServiceOverview = (props) => {
3648 type = "button"
3749 key = { `serviceItem${ props . index } ${ i } ` }
3850 onClick = { ( ) => {
51+ // IPC communication used to initiate query for information on microservice health information.
3952 ipcRenderer . send ( 'detailsRequest' , props . index ) ;
4053
4154 // IPC listener responsible for retrieving infomation from asynchronous main process message.
4255 ipcRenderer . on ( 'detailsResponse' , ( event , data ) => {
43- // setHealthData(Object.values(JSON.parse( data)));
56+ // Adds returned data to context
4457 healthdata . detailData = Object . values ( JSON . parse ( data ) ) ;
58+ // Updates state. Triggers rerender.
4559 setDetails ( < ServiceDetails service = { element . currentmicroservice } /> ) ;
4660 } ) ;
4761 } }
@@ -50,12 +64,10 @@ const ServiceOverview = (props) => {
5064 </ button >
5165 ) ;
5266 componentButtons . push ( button ) ;
53- serviceCache [ element . currentmicroservice ] = 1 ;
54- } else {
55- serviceCache [ element . currentmicroservice ] += 1 ;
67+ serviceCache [ element . currentmicroservice ] = true ;
5668 }
5769 } else if ( element . currentMicroservice ) {
58- // Mongo
70+ // If Mongo
5971 if ( element . currentMicroservice ) {
6072 if ( ! ( element . currentMicroservice in serviceCache ) ) {
6173 const button = (
@@ -68,7 +80,9 @@ const ServiceOverview = (props) => {
6880
6981 // IPC listener responsible for retrieving infomation from asynchronous main process message.
7082 ipcRenderer . on ( 'detailsResponse' , ( event , data ) => {
83+ // Adds returned data to context.
7184 healthdata . detailData = Object . values ( JSON . parse ( data ) ) ;
85+ // Updates state. Triggers rerender.
7286 setDetails ( < ServiceDetails service = { element . currentMicroservice } /> ) ;
7387 } ) ;
7488 } }
@@ -77,9 +91,7 @@ const ServiceOverview = (props) => {
7791 </ button >
7892 ) ;
7993 componentButtons . push ( button ) ;
80- serviceCache [ element . currentMicroservice ] = 1 ;
81- } else {
82- serviceCache [ element . currentMicroservice ] += 1 ;
94+ serviceCache [ element . currentMicroservice ] = true ;
8395 }
8496 }
8597 }
@@ -95,7 +107,7 @@ const ServiceOverview = (props) => {
95107 < h1 className = 'overviewTitle' > Microservices Overview</ h1 >
96108 </ div >
97109 < div />
98- < div className = "servicesList" > { renderState ( ) } </ div >
110+ < div className = "servicesList" > { serviceList ( ) } </ div >
99111 </ div >
100112 ) ;
101113} ;
0 commit comments