Skip to content

Commit dfc4055

Browse files
committed
merging dev branch into elena/updatingToDB feature branch. Merge branch 'dev' into elena/updatingToDB
2 parents a9bc618 + 4c9da1f commit dfc4055

File tree

12 files changed

+85
-21
lines changed

12 files changed

+85
-21
lines changed

app/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import './stylesheets/scrollBar.scss';
55

66

77
// this is the fitness gram pacer test
8+
// React memo helps with rendering optimization. The components within React memo will only be rerendered if prompt has changed
89
const App: React.FC = React.memo(() => {
910
return (
1011
<div>

app/components/Splash.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import '../stylesheets/Splash.scss';
33

4+
//Chronos logo when first starting the electron app. Has the picture for 4 seconds.
45
const Splash: React.FC = React.memo(props => {
56
const [visible, setVisible] = useState(true);
67

app/containers/DashboardContainer.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,22 @@ import AwsContextProvider from '../context/AwsContext';
1313
import '../stylesheets/Dashboard.scss';
1414

1515
const DashboardContainer = React.memo(() => {
16+
1617
const [visible, setVisible] = useState(false);
1718

19+
/**
20+
* When DashBoard Container first mounted, visible is default to false, so that the Splash component can be stay visible.
21+
* After 4 seconds, set the DashBoard Container visibility to true
22+
*/
1823
useEffect(() => {
1924
setTimeout(() => setVisible(true), 4000);
2025
}, []);
2126

27+
/**
28+
* 1. Provide access to use ReactRouter
29+
* 2. Provide access to serveral Context Providers (a.k.a Data Bank), including Application, Dashboard, Comms, Docker, Health, Event, Query, Aws
30+
* 3. Child Component: SidebarContainer and MainContainer
31+
*/
2232
return (
2333
<>
2434
{visible && (

app/containers/GraphsContainer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ const GraphsContainer: React.FC = React.memo(props => {
156156
};
157157

158158
const HealthAndEventButtons: JSX.Element[] = getHealthAndEventComponents();
159-
159+
console.log({GraphsContainer: selectedMetrics})
160+
console.log({GraphsContainer: chart});
160161
return (
161162
<>
162163
<nav id="navigationBar">

app/containers/HealthContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
5151
const metric: string = Object.keys(serviceMetric)[0];
5252
const valueList = Object.values(serviceMetric)[0];
5353
const newTimeList: any = getTime(timelist, serviceName, metric, categoryName);
54-
// console.log('valueList is', valueList); -> 50 values in an array
55-
// console.log('newTimeList array is:', newTimeList); -> 50 values in an array
54+
// console.log('valueList is', valueList); //-> 50 values in an array
55+
// console.log('newTimeList array is:', newTimeList); //-> 50 values in an array
5656
if (selectedMetricsList.includes(metric)) {
5757
const re = /_/g;
5858
const newHealthChart = (

app/containers/SidebarContainer.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ import { ApplicationContext } from '../context/ApplicationContext';
1111
import { AwsContext } from '../context/AwsContext';
1212

1313
const SidebarContainer = React.memo(props => {
14-
const { intervalID } = useContext(ApplicationContext);
15-
const { isLoading, setLoadingState } = useContext(AwsContext);
14+
// Extract invervalID from ApplicationContext. Initival value: intervalID = null
15+
const { intervalID } = useContext (ApplicationContext);
16+
// Extract isLoading and setLoading state from AwsContext. Initial value: isLoading = true
17+
const { isLoading, setLoadingState } = useContext(AwsContext);
1618

1719
// clear interval and set loading state to true when leaving graph containers
20+
21+
/**
22+
* @function handleCLick - check if the 'intervalID' exists. If so, theres a timer running and the fuunction clears the timer using @function clearInterval - function.
23+
* Checks if variable 'isLoading' is false and if so the content is not loading and therefore, sets it to true using the setLoadingState function.
24+
*/
1825
const handleClick = () => {
1926
if(intervalID) clearInterval(intervalID);
2027
if(!isLoading) setLoadingState(true);

app/context/ApplicationContext.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
2424
const [savedMetrics, setSavedMetrics] = useState({});
2525
const [appIndex, setAppIndex] = useState<number>(0);
2626
const [intervalID, setIntervalID] = useState<NodeJS.Timeout | null>(null);
27-
28-
function tryParseJSON(jsonString: any) {
27+
28+
/**
29+
* @function tryParseJson - a function that will parse the JSON data into an object. If there is any error during parsing (a.k.a there is a circular inside the JSON data), console log the error
30+
* @param jsonString - JSON data that is received from backend
31+
* @return an object with all information from backend
32+
*/
33+
function tryParseJSON(jsonString: string) {
2934
try {
3035
const o = JSON.parse(jsonString);
3136

@@ -38,6 +43,17 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
3843
return false;
3944
}
4045

46+
/**
47+
* @function fetchServicesNames - a function that will take an application name and update the state of `serviceData` based on backend response
48+
* 1. Take in an application name
49+
*
50+
* 2. Send a `servicesRequest` to backend
51+
*
52+
* 3. Upon `servicesResponse`, parse the received JSON data and assign it to `servicesData`
53+
*
54+
* 4. Remove the listener for `servicesResponse`
55+
* @param application - application name
56+
*/
4157
const fetchServicesNames = useCallback((application: string) => {
4258
console.log('app when fetch services name', application);
4359
// setApp(application);
@@ -46,6 +62,7 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
4662

4763
ipcRenderer.on('servicesResponse', (event: Electron.Event, data: any) => {
4864
let result: any;
65+
// Parse JSON data into object
4966
if (tryParseJSON(data)) result = JSON.parse(data);
5067
console.log('result from ipcrenderer services response is: ', result);
5168
setServicesData(result);
@@ -62,6 +79,10 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
6279
});
6380
}, []);
6481

82+
/**
83+
* @function getSavedMetrics - a function that will wait for backend `savedMetricsResponse` to update metrics using `setSavedMetrics`
84+
* Trying to find what the data type needs to be.
85+
*/
6586
const getSavedMetrics = useCallback(() => {
6687
ipcRenderer.send('savedMetricsRequest');
6788
ipcRenderer.on('savedMetricsResponse', (event: Electron.Event, data: any) => {

app/context/CommsContext.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ const CommsContextProvider: React.FC<Props> = React.memo((props) => {
3737
return false;
3838
}
3939

40+
41+
/**
42+
* @function fetchCommsData - uses useCallback Hook returns a memoized callback function.
43+
* One reason to use useCallback is to prevent a component from re-rendering unless its props have changed.
44+
* fetches the data
45+
*/
4046
const fetchCommsData = useCallback((app: string, live: boolean) => {
4147

4248
if (app !== currentApp || live) {
@@ -47,6 +53,7 @@ const CommsContextProvider: React.FC<Props> = React.memo((props) => {
4753
let result: any;
4854
if (tryParseJSON(data)) result = JSON.parse(data);
4955
console.log('communication data from fetch request is: ', result);
56+
console.log(data);
5057
setCommsData(result);
5158
});
5259
}

app/context/EventContext.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ const EventContextProvider: React.FC<Props> = React.memo(({ children }) => {
3434
return false;
3535
}
3636

37+
/**
38+
* @function fetchEventData - takes parameter arg.
39+
* Checks if arg is strictly equals to 'kafkametrics', if so removes the event listerner suing the ipcRenderer.removeAllListeners.
40+
* Sends a message using 'ipcRenderer.send'.
41+
* This function seems to be fetching event data and updating the state accordingly.
42+
* Problem: trying to change type any to something some concrete.
43+
*/
44+
3745
const fetchEventData = useCallback((arg: any) => {
3846
if (arg === 'kafkametrics') {
3947
ipcRenderer.removeAllListeners('kafkaResponse');
@@ -89,7 +97,9 @@ const EventContextProvider: React.FC<Props> = React.memo(({ children }) => {
8997
// }
9098
// });
9199
// }, []);
92-
100+
/**
101+
* @function transformEventData - seems like this function tranforms raw data into a format that can be visualize in graphs.
102+
*/
93103
const transformEventData = (data: any[]) => {
94104
const dataList: any[] = [];
95105
const timeList: any[] = [];
@@ -119,7 +129,7 @@ const EventContextProvider: React.FC<Props> = React.memo(({ children }) => {
119129
});
120130
}
121131
});
122-
return { eventDataList: dataList, eventTimeList: timeList };
132+
return { eventDataList: dataList, eventTimeList: timeList };
123133
};
124134

125135
return (
@@ -134,5 +144,4 @@ const EventContextProvider: React.FC<Props> = React.memo(({ children }) => {
134144
</EventContext.Provider>
135145
);
136146
});
137-
138147
export default EventContextProvider;

app/context/HealthContext.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
3434
return false;
3535
}
3636

37+
38+
/**
39+
* @function fetchEventData - sending a request to the backend to retrieve data.
40+
* Data is then parsed and the setHealthData is then set.
41+
*/
3742
const fetchHealthData = useCallback(serv => {
3843
ipcRenderer.removeAllListeners('healthResponse');
3944

40-
let temp: any[] = [];
45+
let temp: string[] = [];
4146
console.log('the cb being passed into fetch health data from graphscontainer is: ', serv);
4247

4348
Promise.all(

0 commit comments

Comments
 (0)