@@ -27,94 +27,85 @@ const TransferColumns = React.memo(() => {
27
27
const { service } = useParams < keyof Params > ( ) as Params ;
28
28
const { mode } = useContext ( DashboardContext . DashboardContext ) ;
29
29
30
- const eventDataList = eventData . eventDataList ;
31
- const healthDataObject = healthData ;
32
-
33
30
const currentMode = mode === 'light' ? lightAndDark . lightModeText : lightAndDark . darkModeText ;
34
31
35
- // console.log('healthMetrics: ', healthMetrics);
36
- // console.log('metricsPool: ', metricsPool);
37
- // console.log('targetKeys: ', targetKeys);
38
- // console.log('eventData: ', eventData);
39
- // console.log('eventDataList: ', eventDataList);
40
-
41
32
useEffect ( ( ) => {
42
- if ( healthDataObject ) {
33
+ if ( healthData ) {
43
34
setHealthMetricsReady ( true ) ;
44
35
}
45
- } , [ healthDataObject ] ) ;
36
+ } , [ healthData ] ) ;
46
37
47
38
useEffect ( ( ) => {
48
- if ( eventDataList && eventDataList . length > 0 ) {
39
+ if ( eventData ) {
49
40
setEventMetricsReady ( true ) ;
50
41
}
51
- } , [ eventDataList ] ) ;
42
+ } , [ eventData ] ) ;
52
43
53
44
useEffect ( ( ) => {
54
- setHealthMetrics ( getMetrics ( 'health' , healthDataObject ) ) ;
45
+ setHealthMetrics ( getMetrics ( 'health' , healthData ) ) ;
55
46
} , [ healthMetricsReady ] ) ;
56
47
57
48
useEffect ( ( ) => {
58
- setEventMetrics ( getMetrics ( 'event' , eventDataList ) ) ;
49
+ setEventMetrics ( getMetrics ( 'event' , eventData ) ) ;
59
50
} , [ eventMetricsReady ] ) ;
60
51
61
52
useEffect ( ( ) => {
62
53
if ( service === '' ) {
63
54
return ;
64
55
}
65
56
if ( service === 'kafkametrics' ) {
66
- if ( eventDataList && eventDataList . length > 0 ) {
67
- setMetricsPool ( getMetrics ( 'event' , eventDataList ) ) ;
57
+ if ( eventData ) {
58
+ setMetricsPool ( getMetrics ( 'event' , eventData ) ) ;
68
59
} else if ( eventMetricsReady ) {
69
60
setMetricsPool ( eventMetrics ) ;
70
61
}
71
62
}
72
63
// JJ-ADDITION (CAN ALSO JUST ADD OR OPERATOR TO ABOVE CONDITIONAL)
73
64
else if ( service === 'kubernetesmetrics' ) {
74
- if ( healthDataObject ) {
75
- setMetricsPool ( getMetrics ( 'health ' , healthDataObject ) ) ;
76
- } else if ( healthMetricsReady ) {
77
- setMetricsPool ( healthMetrics ) ;
65
+ if ( eventData ) {
66
+ setMetricsPool ( getMetrics ( 'event ' , eventData ) ) ;
67
+ } else if ( eventMetricsReady ) {
68
+ setMetricsPool ( eventMetrics ) ;
78
69
}
79
70
} else if ( ! service . includes ( 'kafkametrics' ) ) {
80
- if ( healthDataObject ) {
81
- setMetricsPool ( getMetrics ( 'health' , healthDataObject ) ) ;
71
+ if ( healthData ) {
72
+ setMetricsPool ( getMetrics ( 'health' , healthData ) ) ;
82
73
} else if ( healthMetricsReady ) {
83
74
setMetricsPool ( healthMetrics ) ;
84
75
}
85
76
} else {
86
- if ( healthDataObject && eventDataList && eventDataList . length > 0 ) {
87
- setMetricsPool (
88
- getMetrics ( 'event' , eventDataList ) . concat ( getMetrics ( 'health' , healthDataObject ) )
89
- ) ;
77
+ if ( healthData && eventData ) {
78
+ setMetricsPool ( getMetrics ( 'event' , eventData ) . concat ( getMetrics ( 'health' , healthData ) ) ) ;
90
79
} else if ( healthMetricsReady && eventMetricsReady ) {
91
80
setMetricsPool ( eventMetrics . concat ( healthMetrics ) ) ;
92
81
}
93
82
}
94
83
} , [ service , eventData , healthData ] ) ;
95
84
96
85
// responsible for parsing data and updating state via setMetricsPool
97
- const getMetrics = ( type , datalist ) => {
86
+ const getMetrics = ( type , dataObject ) => {
98
87
let pool : any [ ] = [ ] ;
99
88
if ( type === 'event' ) {
100
- datalist . forEach ( metric => {
101
- const temp = { } ;
102
- const metricName : string = Object . keys ( metric ) [ 0 ] ;
103
- const key = 'Event | ' + metricName ;
104
- temp [ 'key' ] = key ;
105
- temp [ 'title' ] = key ;
106
- temp [ 'tag' ] = 'Event' ;
107
- pool . push ( temp ) ;
108
- } ) ;
89
+ for ( const category in dataObject ) {
90
+ const metricsObjects = dataObject [ category ] ;
91
+ for ( const metricName in metricsObjects ) {
92
+ const key = category + ' | ' + metricName ;
93
+ pool . push ( {
94
+ key : key ,
95
+ title : key ,
96
+ tag : category ,
97
+ } ) ;
98
+ }
99
+ }
109
100
} else {
110
101
// iterate throught the healthData object to populate the `Metrics Query` tab with metrics options
111
102
// The pool array wants an object with a specific format in order to populate the selection table
112
- for ( const service in healthData ) {
113
- const categoryObjects = healthData [ service ] ;
103
+ for ( const service in dataObject ) {
104
+ const categoryObjects = dataObject [ service ] ;
114
105
for ( const category in categoryObjects ) {
115
106
const metricsObjects = categoryObjects [ category ] ;
116
- for ( const metric in metricsObjects ) {
117
- const key = category + ' | ' + metric ;
107
+ for ( const metricName in metricsObjects ) {
108
+ const key = category + ' | ' + metricName ;
118
109
pool . push ( {
119
110
key : key ,
120
111
title : key ,
@@ -127,17 +118,9 @@ const TransferColumns = React.memo(() => {
127
118
return pool ;
128
119
} ;
129
120
130
- // Justin's alternative to getCharts (b/c getCharts is just saving the user-selected metrics into QueryContext)
131
- // getCharts takes data that already exists in state as an array of strings, and makes it into an array of objects, just to save it to QueryContext state
132
- // the selectedMetrics from QueryContext is used in TransferColumns, EventContainer, GraphsContainer, and HealthContainer
133
- // const saveSelectedMetrics = () => {
134
- // // iterate over the targetKeys array
135
- // }
136
-
137
- const getCharts = ( ) => {
121
+ const createSelectedMetricsList = ( ) => {
138
122
const temp : any [ ] = [ ] ;
139
123
const categorySet = new Set ( ) ;
140
- console . log ( 'targetKeys is: ' , targetKeys ) ;
141
124
for ( let i = 0 ; i < targetKeys . length ; i ++ ) {
142
125
const str : string = targetKeys [ i ] ;
143
126
const strArr : string [ ] = str . split ( ' | ' ) ;
@@ -157,7 +140,6 @@ const TransferColumns = React.memo(() => {
157
140
temp . push ( newCategory ) ;
158
141
}
159
142
}
160
- console . log ( 'temp array with requested graphs is: ' , temp ) ;
161
143
setSelectedMetrics ( temp ) ;
162
144
} ;
163
145
@@ -181,10 +163,11 @@ const TransferColumns = React.memo(() => {
181
163
// makes the rows needed for the selection grid
182
164
const rows : any [ ] = [ ] ;
183
165
metricsPool . forEach ( ( el , index ) => {
184
- const row = { } ;
185
- row [ 'id' ] = index ;
186
- row [ 'tag' ] = el . tag ;
187
- row [ 'title' ] = el . title . split ( ' | ' ) [ 1 ] . replace ( 'kubernetes-cadvisor/docker-desktop/' , '' ) ; // gets rid of the full path
166
+ const row = {
167
+ id : index ,
168
+ tag : el . tag ,
169
+ title : el . title . split ( ' | ' ) [ 1 ] . replace ( 'kubernetes-cadvisor/docker-desktop/' , '' ) ,
170
+ } ; // gets rid of the full path
188
171
rows . push ( row ) ;
189
172
} ) ;
190
173
@@ -201,7 +184,12 @@ const TransferColumns = React.memo(() => {
201
184
return (
202
185
< >
203
186
< div id = "getChartsContainer" >
204
- < Button id = "getCharts" onClick = { getCharts } variant = "contained" color = "primary" >
187
+ < Button
188
+ id = "getCharts"
189
+ onClick = { createSelectedMetricsList }
190
+ variant = "contained"
191
+ color = "primary"
192
+ >
205
193
Get Charts
206
194
</ Button >
207
195
</ div >
0 commit comments