@@ -26,30 +26,32 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
26
26
useEffect ( ( ) => {
27
27
const temp : JSX . Element [ ] = [ ] ;
28
28
let counter : number = 0 ;
29
- const datalist : any [ ] = healthData . healthDataList ;
30
- const timelist : any [ ] = healthData . healthTimeList ;
31
- // dataList and timeList are the EXACT same thing . An array of 4 objects. [Memory, CPU, Processes, Latency]
29
+ const dataList : any [ ] = healthData . healthdataList ;
30
+ const timeList : any [ ] = healthData . healthTimeList ;
31
+ // dataList and timeList are structured the same, but time holds timestamps . An array of 4 objects. [Memory, CPU, Processes, Latency]
32
32
// Each element has all its metrics.
33
33
console . log ( 'healthData object in state: ' , healthData ) ;
34
- console . log ( 'datalist in healthcontainer is:' , datalist ) ; //array of healthDataList
35
- console . log ( 'timelist in healthcontainer is:' , timelist ) ;
34
+ console . log ( 'dataList in healthcontainer is:' , dataList ) ; //array of healthdataList
35
+ console . log ( 'timelist in healthcontainer is:' , timeList ) ;
36
36
37
- if ( healthData && datalist && timelist && datalist . length > 0 && timelist . length > 0 ) {
37
+ if ( healthData && dataList && timeList && dataList . length > 0 && timeList . length > 0 ) {
38
38
let selectedMetricsList : string [ ] = [ ] ;
39
39
selectedMetrics . forEach ( element => {
40
40
if ( Object . keys ( element ) [ 0 ] === category ) {
41
41
selectedMetricsList = element [ category ] ;
42
42
}
43
43
} ) ;
44
+ // temporary solution to getting the list of times for our single chart
45
+ const times : string [ ] = timeList [ 0 ] . Memory [ 0 ] . books [ 0 ] . activememory_in_bytes ;
44
46
45
- datalist . forEach ( ( element : { } ) => {
47
+ dataList . forEach ( ( element : { } ) => {
46
48
const categoryName : string = Object . keys ( element ) [ 0 ] ;
47
49
/*
48
- 'element' is the category found in the datalist response from the server query for metrics data.
50
+ 'element' is the category found in the dataList response from the server query for metrics data.
49
51
The above forEach method loops through the different categories.
50
52
The 'category' variable is the specific category passed in to HealthContainer via prop drilling.
51
53
The 'category' is the string Memory, CPU, or others that are in the Category column of the Query Selector interface.
52
- The 'categoryName' is the string that is Memory/CPU/other inside the metrics data response ('datalist ' or 'timelist').
54
+ The 'categoryName' is the string that is Memory/CPU/other inside the metrics data response ('dataList ' or 'timelist').
53
55
When the 'element'/'categoryName' matches the 'category' selected in the Query Selection interface...
54
56
... it will dive into that Category object to pull out a chart for each metric selected in the selection interface.
55
57
selectedMetricsList is derived from the selectedMetrics that were in the QueryContext.
@@ -58,33 +60,52 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
58
60
*/
59
61
if ( category === categoryName ) {
60
62
const categoryObj : [ ] = element [ categoryName ] ;
63
+ let filteredMetrics ;
61
64
for ( const metricObj of categoryObj ) {
65
+ // serviceName = category (ex. books)
62
66
const serviceName : string = Object . keys ( metricObj ) [ 0 ] ;
67
+ /* serviceMetricsArr = array of ALL objects
68
+ [0: {
69
+ total-availle-memory-in-bytes: [numbers, more numbers, nums, woo]
70
+ }]
71
+ */
63
72
const serviceMetricsArr : any [ ] = Object . values ( metricObj ) . flat ( ) ;
73
+ // const serviceTimesArr: any[] = Object.values();
64
74
console . log ( 'serviceMetricsArr: ' , serviceMetricsArr ) ; // -> array of objects.
65
- for ( const serviceMetric of serviceMetricsArr ) {
66
- const metric : string = Object . keys ( serviceMetric ) [ 0 ] ;
67
- const valueList = Object . values ( serviceMetric ) [ 0 ] ;
68
- const newTimeList : any = getTime ( timelist , serviceName , metric , categoryName ) ;
69
- // console.log('valueList is', valueList); //-> 50 values in an array
70
- // console.log('newTimeList array is:', newTimeList); //-> 50 values in an array
71
- if ( selectedMetricsList . includes ( metric ) ) {
72
- const re = / _ / g;
73
- const newHealthChart = (
74
- < HealthChart
75
- key = { `Chart${ counter } ` }
76
- renderService = { serviceName }
77
- metric = { metric . replace ( re , " " ) }
78
- timeList = { newTimeList }
79
- valueList = { valueList }
80
- sizing = { props . sizing }
81
- colourGenerator = { props . colourGenerator }
82
- />
83
- ) ;
84
- counter ++ ;
85
- temp . push ( newHealthChart ) ;
86
- }
87
- }
75
+ // filter through the desired metrics and pass them down to HealthChart
76
+ selectedMetricsList . forEach ( selected => {
77
+ filteredMetrics = serviceMetricsArr . filter ( metric => {
78
+ metric [ selected ] ;
79
+ } ) ;
80
+ } ) ;
81
+
82
+ // serviceMetricsArr.filter(...selectedMetricsList)
83
+
84
+ // for (const serviceMetric of serviceMetricsArr) {
85
+ // const metric: string = Object.keys(serviceMetric)[0];
86
+ // const valueList = Object.values(serviceMetric)[0];
87
+ // const newTimeList: any = getTime(timelist, serviceName, metric, categoryName);
88
+ // console.log('valueList is', valueList); //-> 50 values in an array
89
+ // console.log('newTimeList array is:', newTimeList); //-> 50 values in an array
90
+ // if (selectedMetricsList.includes(metric)) {
91
+ const re = / _ / g;
92
+ const newHealthChart = (
93
+ < HealthChart
94
+ key = { `Chart${ counter } ` }
95
+ categoryName = { categoryName }
96
+ serviceName = { serviceName }
97
+ // metric={metric.replace(re, " ")}
98
+ metrics = { filteredMetrics }
99
+ timeList = { times }
100
+ // valueList={valueList}
101
+ sizing = { props . sizing }
102
+ colourGenerator = { props . colourGenerator }
103
+ />
104
+ ) ;
105
+ counter ++ ;
106
+ temp . push ( newHealthChart ) ;
107
+ // }
108
+ // }
88
109
}
89
110
}
90
111
} ) ;
0 commit comments