Skip to content

Commit 2fc0ee2

Browse files
committed
removed promise.all as well as a couple unnessary awaits
1 parent af075c4 commit 2fc0ee2

3 files changed

Lines changed: 16 additions & 34 deletions

File tree

app/context/DashboardContext.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ const DashboardContextProvider = React.memo((props: any) => {
4747

4848
const [user, setUser] = useState<string>('guest');
4949
const [applications, setApplications] = useState<string[][]>([]);
50-
console.log({applications})
5150
const [mode, setMode] = useState<string>('light');
5251

5352
const getApplications = useCallback(() => {

app/context/HealthContext.tsx

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,48 +56,30 @@ const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
5656
*/
5757

5858
const fetchHealthData = useCallback(async servers => {
59-
// ipcRenderer.removeAllListeners('healthResponse');
6059

6160
let temp: HealthDataObject[] = [];
62-
await Promise.all(servers.map( async (service: string) => {
63-
ipcRenderer.removeAllListeners('healthResponse');
61+
servers.map( async (service: string) => {
6462

65-
try {
66-
const newPromise: any = await new Promise((resolve, reject) => {
67-
ipcRenderer.send('healthRequest', `${service}`);
68-
ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
69-
//V14: the line does not appear necessary, leaving it here commented out in case another group runs into a problem
70-
// if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
71-
const response = JSON.parse(data);
72-
// console.log({response})
73-
const [ dbName ] = Object.keys(response[0])
74-
//result exists, has a length prop, and the service name and database name are same
75-
console.log({service,dbName})
76-
//V14: this block is needed here because of unecessary calls for each service
77-
//a prior group was getting the dbName from the response object and since objects dont remember
78-
//insertion order they are running all the calls for each service in the array
79-
if (response && response.length && `${service}` === dbName) {
80-
resolve(response[0]);
81-
}
82-
// }
83-
});
84-
})
85-
temp.push(newPromise);
86-
if (checkServicesComplete(temp, [`${service}`])) {
87-
console.log({temp})
63+
try {
8864

65+
ipcRenderer.removeAllListeners('healthResponse');
66+
ipcRenderer.send('healthRequest', `${service}`);
67+
ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
68+
69+
const response = JSON.parse(data);
70+
temp.push(response[0]);
71+
72+
if(temp.length === servers.length) {
73+
console.log(temp.length,servers.length)
8974
setServices([`${service}`]);
9075
let transformedData: any = {};
9176
transformedData = healthTransformer(temp); //must match the setHealthData STATE format
9277
setHealthData(transformedData);
9378
}
94-
} catch (err) {
95-
console.log("healthcontext.tsx ERROR: ", err);
96-
};
97-
}
98-
99-
))
100-
} , []);
79+
});
80+
} catch (err) {
81+
console.log("healthcontext.tsx ERROR: ", err);
82+
}})} , []);
10183

10284
const checkServicesComplete = (temp: any[], servers: string[]) => {
10385
if (temp.length !== servers.length) {

app/context/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface HealthDataObject {
3838

3939
export function healthTransformer(healthData: HealthDataObject[]) {
4040
// make an object for storing different services' metrics data
41+
console.log({healthData})
4142
const serviceMetricsObject = {};
4243
// loop through the services in the healthData array
4344
healthData.forEach(serviceObj => {

0 commit comments

Comments
 (0)