Skip to content

Commit aab593c

Browse files
authored
Merge pull request #27 from oslabs-beta/front_test_with_chronos_tranck
Front test with chronos tranck
2 parents 4a71046 + e6e8f3d commit aab593c

File tree

5 files changed

+55
-86
lines changed

5 files changed

+55
-86
lines changed

app/components/TransferColumns.tsx

+15-10
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ const TransferColumns = React.memo(() => {
6666
const [targetKeys, setTargetKeys] = useState([]);
6767
const [metricsPool, setMetricsPool] = useState<any[]>([]);
6868
const [listReady, setListReady] = useState(false);
69+
const [isEvent, setIsEvent] = useState(false);
6970
const [disabled, setDisabled] = useState(false);
7071
const [showSearch, setShowSearch] = useState(true);
7172
const { setSelectedMetrics } = useContext(QueryContext);
7273
const {healthData} = useContext(HealthContext);
7374
const { eventData } = useContext(EventContext);
7475
const eventDataList = eventData.eventDataList;
76+
const healthDataList = healthData.healthDataList;
7577

7678
// const datalist = [
7779
// {
@@ -88,6 +90,7 @@ const TransferColumns = React.memo(() => {
8890
const appendMetrics = (eventDataList, healthDatalist) => {
8991
let pool: any[] = [];
9092
if (healthDatalist && healthDatalist.length > 0) {
93+
setIsEvent(false);
9194
healthDatalist.forEach(category => {
9295
const tag: string = Object.keys(category)[0]; //Memory
9396
const serviceObj: {} = category[tag][0]; // { books: [{ disk_usage: [10, 20] }, { clockSpeed: [8, 16] }] }
@@ -107,6 +110,7 @@ const TransferColumns = React.memo(() => {
107110

108111
}
109112
if (eventDataList && eventDataList.length > 0) {
113+
setIsEvent(true);
110114
eventDataList.forEach(metric => {
111115
const temp = {};
112116
const metricName: string = Object.keys(metric)[0];
@@ -122,20 +126,21 @@ const TransferColumns = React.memo(() => {
122126
setMetricsPool(pool);
123127
};
124128

125-
useEffect(() => {
126-
if (healthData.healthDataList && healthData.healthDataList.length >0 && eventDataList && eventDataList.length > 0) {
127-
setListReady(true);
128-
}
129-
}, [healthData.healthDataList, eventDataList]);
129+
// useEffect(() => {
130+
// if ((healthDataList && healthDataList.length >0) || (eventDataList && eventDataList.length > 0)) {
131+
// setListReady(true);
132+
// }
133+
// }, [healthDataList, eventDataList]);
130134

131135

132-
const isMount = useIsMount();
136+
//const isMount = useIsMount();
133137

134138
useEffect(() => {
135-
if (!isMount) {
136-
appendMetrics(eventDataList, healthData.healthDataList);
137-
}
138-
}, [listReady]);
139+
// if (!isMount) {
140+
appendMetrics(eventDataList, healthDataList);
141+
// }
142+
}, [isEvent, healthDataList, eventDataList]);
143+
139144

140145
const leftTableColumns = [
141146
{

app/containers/GraphsContainer.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ const GraphsContainer: React.FC<GraphsContainerProps> = React.memo(props => {
7373
setInterval(() => {
7474
fetchCommsData(app, live);
7575
fetchHealthData(serviceArray);
76-
fetchEventData();
76+
fetchEventData(serviceArray[0]);
7777
}, 3000)
7878
);
7979
} else {
8080
if (intervalID) clearInterval(intervalID);
8181
fetchCommsData(app, live);
8282
fetchHealthData(serviceArray);
83-
fetchEventData();
83+
fetchEventData(serviceArray[0]);
8484
}
8585

8686
return () => {

app/context/EventContext.tsx

+22-20
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ export const EventContext = React.createContext<any>(null);
88

99
/**
1010
* MANAGES THE FOLLOWING DATA AND ACTIONS:
11-
* @property {Array} eventDataList
12-
* @property {Array} eventTimeList
11+
* @property {Object} eventData
1312
* @method fetchEventData
14-
* @method setEventDataList
15-
* @method setEventTimeList
13+
* @method setEventData
14+
1615
*/
1716

1817
const EventContextProvider: React.FC = React.memo(({ children }) => {
1918
const [eventData, setEventData] = useState({"eventDataList":[], "eventTimeList": []});
20-
// const [eventDataList, setEventDataList] = useState<any[]>([]);
21-
// const [eventTimeList, setEventTimeList] = useState<any[]>([]);
2219

2320
function tryParseJSON(jsonString: any) {
2421
try {
@@ -32,20 +29,25 @@ const EventContextProvider: React.FC = React.memo(({ children }) => {
3229
return false;
3330
}
3431

35-
const fetchEventData = useCallback(() => {
36-
ipcRenderer.removeAllListeners('kafkaResponse');
37-
ipcRenderer.send('kafkaRequest');
38-
ipcRenderer.on('kafkaResponse', (event: Electron.Event, data: any) => {
39-
let result: any;
40-
if (tryParseJSON(data)) result = JSON.parse(data);
41-
// console.log("eventData in eventcontext");
42-
// console.log(JSON.stringify(result));
43-
// console.log("result in EventContext", JSON.stringify(result));
44-
let transformedData : any = {};
45-
transformedData = transformEventData(result);
32+
const fetchEventData = useCallback((serv) => {
33+
if(serv === 'kafkametrics'){
34+
console.log("in fetchEventData in EventContext!!");
35+
ipcRenderer.removeAllListeners('kafkaResponse');
36+
ipcRenderer.send('kafkaRequest');
37+
ipcRenderer.on('kafkaResponse', (event: Electron.Event, data: any) => {
38+
let result: any;
39+
if (tryParseJSON(data)) result = JSON.parse(data);
40+
console.log("eventData in eventcontext");
41+
console.log(JSON.stringify(result));
42+
console.log("result in EventContext", JSON.stringify(result));
43+
let transformedData : any = {};
44+
transformedData = transformEventData(result[0]['kafkametrics']);
45+
46+
setEventData(transformedData);
47+
});
48+
49+
}
4650

47-
setEventData(transformedData);
48-
});
4951

5052
}, []);
5153

@@ -82,7 +84,7 @@ const EventContextProvider: React.FC = React.memo(({ children }) => {
8284
});
8385
}
8486
});
85-
// console.log("datalist in EventContext:", JSON.stringify(dataList));
87+
console.log("datalist in EventContext:", JSON.stringify(dataList));
8688
return {"eventDataList": dataList, "eventTimeList": timeList};
8789
};
8890

app/context/HealthContext.tsx

+14-53
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ export const HealthContext = React.createContext<any>(null);
99

1010
/**
1111
* MANAGES THE FOLLOWING DATA AND ACTIONS:
12-
* @property {Object} datalist At most, 50 points of health data
13-
* @property {Object} timelist Health data timestamps
12+
* @property {Object} healthData
1413
* @method setServices
15-
* @method setDataList
16-
* @method setTimeList
14+
* @method setHealthData
15+
1716
*/
1817

1918
const HealthContextProvider: React.FC = React.memo(({ children }) => {
@@ -43,26 +42,14 @@ const HealthContextProvider: React.FC = React.memo(({ children }) => {
4342
let temp: any[] = [];
4443

4544
Promise.all(
46-
serv.map((service: string) =>
47-
new Promise((resolve, reject) => {
45+
serv.map((service: string) =>{
46+
// if(service !== 'kafkametrics'){
47+
48+
return new Promise((resolve, reject) => {
4849
console.log('serv in healthcontext:', JSON.stringify(serv));
4950
ipcRenderer.send('healthRequest', service);
5051
ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
51-
52-
53-
//second query customers
54-
// [
55-
// {
56-
// customers: [
57-
// { metric: "disk_usage", category: "Memory", time: 1, value: 10 },
58-
// { metric: "disk_usage", category: "Memory", time: 2, value: 20 },
59-
// { metric: "clockSpeed", category: "Memory", time: 1, value: 8 },
60-
// { metric: "clockSpeed", category: "Memory", time: 2, value: 16 },
61-
// { metric: "cpu_temp", category: "CPU", time: 1, value: 100 },
62-
// { metric: "cpu_temp", category: "CPU", time: 2, value: 200 },
63-
// ],
64-
// },
65-
// ]
52+
6653
let result: any[];
6754
if (tryParseJSON(data)) {
6855
console.log("data in HealthContext:", data);
@@ -76,33 +63,11 @@ const HealthContextProvider: React.FC = React.memo(({ children }) => {
7663
});
7764

7865
}).then((dt: any) => {
79-
temp.push(dt);
80-
console.log("temp is:", JSON.stringify(temp));
81-
// temp = [
82-
// {
83-
// "chronos-mon": [
84-
// { metric: 'disk_usage', category: 'Memory', time: 1, value: 10 },
85-
// { metric: 'disk_usage', category: 'Memory', time: 2, value: 20 },
86-
// { metric: 'clockSpeed', category: 'Memory', time: 1, value: 8 },
87-
// { metric: 'clockSpeed', category: 'Memory', time: 2, value: 16 },
88-
// { metric: 'cpu_temp', category: 'CPU', time: 1, value: 100 },
89-
// { metric: 'cpu_temp', category: 'CPU', time: 2, value: 200 },
90-
// ],
91-
// },
92-
// {
93-
// "chronos-mon-2": [
94-
// { metric: 'disk_usage', category: 'Memory', time: 1, value: 10000 },
95-
// { metric: 'disk_usage', category: 'Memory', time: 2, value: 20000 },
96-
// { metric: 'clockSpeed', category: 'Memory', time: 1, value: 8000 },
97-
// { metric: 'clockSpeed', category: 'Memory', time: 2, value: 16000 },
98-
// { metric: 'cpu_temp', category: 'CPU', time: 1, value: 10000 },
99-
// { metric: 'cpu_temp', category: 'CPU', time: 2, value: 20000 },
100-
// ],
101-
// },
102-
// ];
66+
if(service !== 'kafkametrics'){
67+
temp.push(dt);
68+
console.log("temp is:", JSON.stringify(temp));
69+
}
10370
if (checkServicesComplete(temp, serv)) {
104-
105-
// if (temp.length === serv.length) {
10671

10772
setServices(serv);
10873
let transformedData : any = {};
@@ -111,13 +76,11 @@ const HealthContextProvider: React.FC = React.memo(({ children }) => {
11176
console.log("serv", serv);
11277
console.log('transformedData:', JSON.stringify(transformedData));
11378
setHealthData(transformedData);
114-
// setTimeList(transformedData[1]);
115-
// setDataList(transformedData[0]);
116-
117-
11879

11980
}
12081
})
82+
}
83+
// }
12184
)
12285
);
12386
}, []);
@@ -132,8 +95,6 @@ const HealthContextProvider: React.FC = React.memo(({ children }) => {
13295
arr1.push(Object.keys(temp[i])[0]);
13396

13497
}
135-
console.log("arr1",arr1.sort().toString());
136-
console.log("serv:", serv);
13798
return arr1.sort().toString() === serv.sort().toString()
13899

139100
};

electron/routes/data.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ ipcMain.on('commsRequest', async (message: Electron.IpcMainEvent) => {
129129
*/
130130
ipcMain.on('healthRequest', async (message: Electron.IpcMainEvent, service: string) => {
131131
try {
132+
132133
let result: any;
133134

134135
// Mongo Database
@@ -221,7 +222,7 @@ function extractWord(str: string) {
221222
ipcMain.on('kafkaRequest', async (message) => {
222223
try {
223224
let result: any;
224-
225+
console.log("in kafkaRequest electron!!")
225226
// Mongo Database
226227
if (currentDatabaseType === 'MongoDB') {
227228

0 commit comments

Comments
 (0)