@@ -26,50 +26,79 @@ const HealthContainer: React.FC<HealthContainerProps> = React.memo(props => {
2626 useEffect ( ( ) => {
2727 const temp : JSX . Element [ ] = [ ] ;
2828 let counter : number = 0 ;
29- const datalist : any [ ] = healthData . healthDataList ;
30- const timelist : any [ ] = healthData . healthTimeList ;
31- console . log ( 'datalist in healthcontainer is:' , datalist ) ; //array of healthDataList
32- console . log ( 'timelist in healthcontainer is:' , timelist ) ;
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+ // Each element has all its metrics.
33+ // console.log('healthData object in state: ', healthData);
34+ // console.log('dataList in healthcontainer is:', dataList);
35+ // console.log('timelist in healthcontainer is:', timeList);
3336
34- if ( healthData && datalist && timelist && datalist . length > 0 && timelist . length > 0 ) {
37+ if ( healthData && dataList && timeList && dataList . length > 0 && timeList . length > 0 ) {
3538 let selectedMetricsList : string [ ] = [ ] ;
3639 selectedMetrics . forEach ( element => {
3740 if ( Object . keys ( element ) [ 0 ] === category ) {
3841 selectedMetricsList = element [ category ] ;
3942 }
4043 } ) ;
44+ // ***ALERT*** 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 ;
4146
42- datalist . forEach ( ( element : { } ) => {
47+ dataList . forEach ( ( element : { } ) => {
4348 const categoryName : string = Object . keys ( element ) [ 0 ] ;
49+ /*
50+ 'element' is the category found in the dataList response from the server query for metrics data.
51+ The above forEach method loops through the different categories.
52+ The 'category' variable is the specific category passed in to HealthContainer via prop drilling.
53+ The 'category' is the string Memory, CPU, or others that are in the Category column of the Query Selector interface.
54+ The 'categoryName' is the string that is Memory/CPU/other inside the metrics data response ('dataList' or 'timelist').
55+ When the 'element'/'categoryName' matches the 'category' selected in the Query Selection interface...
56+ ... it will dive into that Category object to pull out a chart for each metric selected in the selection interface.
57+ selectedMetricsList is derived from the selectedMetrics that were in the QueryContext.
58+ selectedMetricsList is how we know which metrics should be made into a chart.
59+ selectedMetricsList is the way we can give one chart the multiple metrics being requested.
60+ */
4461 if ( category === categoryName ) {
4562 const categoryObj : [ ] = element [ categoryName ] ;
63+ const filteredMetrics : any [ ] = [ ] ;
4664 for ( const metricObj of categoryObj ) {
47- const serviceName : string = Object . keys ( metricObj ) [ 0 ] ;
48- const serviceValArr : any [ ] = Object . values ( metricObj ) ;
49- const serviceVals : any [ ] = serviceValArr [ 0 ] ;
50- for ( const serviceMetric of serviceVals ) {
51- const metric : string = Object . keys ( serviceMetric ) [ 0 ] ;
52- const valueList = Object . values ( serviceMetric ) [ 0 ] ;
53- 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
56- if ( selectedMetricsList . includes ( metric ) ) {
57- const re = / _ / g;
58- const newHealthChart = (
59- < HealthChart
60- key = { `Chart${ counter } ` }
61- renderService = { serviceName }
62- metric = { metric . replace ( re , " " ) }
63- timeList = { newTimeList }
64- valueList = { valueList }
65- sizing = { props . sizing }
66- colourGenerator = { props . colourGenerator }
67- />
68- ) ;
69- counter ++ ;
70- temp . push ( newHealthChart ) ;
71- }
72- }
65+ // serviceName = category (ex. books)
66+ const serviceName : string = Object . keys ( metricObj ) [ 0 ] ;
67+ console . log ( 'metricObj: ' , metricObj )
68+ const serviceMetricsArr : any [ ] = Object . values ( metricObj ) . flat ( ) ;
69+ console . log ( 'serviceMetricsArr: ' , serviceMetricsArr ) ; // -> array of arrays containing numerical data.
70+ /* serviceMetricsArr = array of all metric objects
71+ [0: {
72+ total-availle-memory-in-bytes: [numbers, more numbers, nums, woo]
73+ }]
74+ */
75+
76+ // filters through the desired metrics and pass them down to HealthChart
77+ selectedMetricsList . forEach ( selected => {
78+ serviceMetricsArr . forEach ( metric => {
79+ if ( metric [ selected ] ) filteredMetrics . push ( metric ) ;
80+ } ) ;
81+ } ) ;
82+ console . log ( 'filteredMetrics: ' , filteredMetrics ) ;
83+
84+ const re = / _ / g;
85+ const newHealthChart = (
86+ < HealthChart
87+ key = { `Chart${ counter } ` }
88+ categoryName = { categoryName }
89+ serviceName = { serviceName }
90+ // metric={metric.replace(re, " ")}
91+ metrics = { filteredMetrics }
92+ timeList = { times }
93+ // valueList={valueList}
94+ sizing = { props . sizing }
95+ colourGenerator = { props . colourGenerator }
96+ />
97+ ) ;
98+ counter ++ ;
99+ temp . push ( newHealthChart ) ;
100+ // }
101+ // }
73102 }
74103 }
75104 } ) ;
0 commit comments