11import React , { useState , useContext , useEffect } from 'react' ;
2+ import { ApplicationContext } from '../context/ApplicationContext' ;
23import { useParams } from 'react-router-dom' ;
34import { QueryContext } from '../context/QueryContext' ;
45import { HealthContext } from '../context/HealthContext' ;
@@ -17,7 +18,9 @@ interface Params {
1718
1819const TransferColumns = React . memo ( ( ) => {
1920 const [ targetKeys , setTargetKeys ] = useState < any [ ] > ( [ ] ) ;
21+ // console.log({targetKeys})
2022 const [ metricsPool , setMetricsPool ] = useState < any [ ] > ( [ ] ) ;
23+ // console.log({metricsPool})
2124 const [ healthMetricsReady , setHealthMetricsReady ] = useState ( false ) ;
2225 const [ healthMetrics , setHealthMetrics ] = useState < any [ ] > ( [ ] ) ;
2326 const [ eventMetricsReady , setEventMetricsReady ] = useState ( false ) ;
@@ -31,11 +34,14 @@ const TransferColumns = React.memo(() => {
3134 const { mode } = useContext ( DashboardContext . DashboardContext ) ;
3235 const [ searchTerm , setSearchTerm ] = useState < string > ( '' ) ;
3336
37+ const { savedMetrics } = useContext ( ApplicationContext )
38+
3439 const currentMode = mode === 'light' ? lightAndDark . lightModeText : lightAndDark . darkModeText ;
3540 const currentStyle = mode === 'light' ? lightAndDark . lightModeData : lightAndDark . darkModeData ;
3641
3742 useEffect ( ( ) => {
3843 if ( healthData ) {
44+ console . log ( { healthData} )
3945 setHealthMetricsReady ( true ) ;
4046 }
4147 } , [ healthData ] ) ;
@@ -103,7 +109,7 @@ const TransferColumns = React.memo(() => {
103109 }
104110 }
105111 } else {
106- // iterate throught the healthData object to populate the `Metrics Query` tab with metrics options
112+ // iterate throughout the healthData object to populate the `Metrics Query` tab with metrics options
107113 // The pool array wants an object with a specific format in order to populate the selection table
108114 for ( const service in dataObject ) {
109115 const categoryObjects = dataObject [ service ] ;
@@ -124,9 +130,10 @@ const TransferColumns = React.memo(() => {
124130 } ;
125131
126132 const createSelectedMetricsList = ( ) => {
133+
127134 const temp : any [ ] = [ ] ;
128135 const categorySet = new Set ( ) ;
129- // console.log('Inside TransferColumns.txs line 124 targetKeys: ', targetKeys)
136+
130137 for ( let i = 0 ; i < targetKeys . length ; i ++ ) {
131138 const str : string = targetKeys [ i ] ;
132139 const strArr : string [ ] = str . split ( ' | ' ) ;
@@ -170,21 +177,31 @@ const TransferColumns = React.memo(() => {
170177 ] ;
171178
172179 // makes the rows needed for the selection grid
173- const rows : any [ ] = [ ] ;
174- metricsPool . forEach ( ( el , index ) => {
175- const row = {
176- id : index ,
177- tag : el . tag ,
178- title : el . title . split ( ' | ' ) [ 1 ] . replace ( / .* \/ .* \/ / g, '' ) ,
179- } ; // gets rid of the full path
180- rows . push ( row ) ;
181- } ) ;
180+ const rows :any [ ] = [ ]
181+ let id = 0
182+ for ( let savedMetric of Object . keys ( savedMetrics ) ) {
183+
184+ const { metric, category } = savedMetrics [ savedMetric ]
185+ rows . push ( {
186+ id :id ++ ,
187+ tag :category ,
188+ title :metric
189+ } )
190+ }
182191
183192 // makes the Printed list of 'currently selected rows' on the page using targetKeys array
184193 const selectedRows : any [ ] = [ ] ;
185194 targetKeys . forEach ( el => {
186195 selectedRows . push (
187- < li style = { { marginLeft : '30px' , marginTop : '5px' , color : currentMode . color } } > { el } </ li >
196+ < li
197+ style = { {
198+ marginLeft : '30px' ,
199+ marginTop : '5px' ,
200+ color : currentMode . color
201+ } }
202+ >
203+ { el }
204+ </ li >
188205 ) ;
189206 } ) ;
190207
@@ -222,7 +239,8 @@ const TransferColumns = React.memo(() => {
222239 onRowSelectionModelChange = { metricIndeces => {
223240 const metrics : any [ ] = [ ] ;
224241 metricIndeces . forEach ( el => {
225- metrics . push ( metricsPool [ el ] . key ) ;
242+ console . log ( { rows} )
243+ metrics . push ( `${ rows [ el ] . tag } | ${ rows [ el ] . title } ` ) ;
226244 } ) ;
227245 setTargetKeys ( metrics ) ;
228246 } }
@@ -231,10 +249,20 @@ const TransferColumns = React.memo(() => {
231249
232250 </ div >
233251 { selectedRows . length > 0 && (
234- < h3 style = { { marginTop : '20px' , color : 'currentStyle' , } }
235- > Selected Rows:</ h3 >
252+ < h3
253+ style = { {
254+ marginTop : '20px' ,
255+ color : 'currentStyle'
256+ } }
257+ >
258+ Selected Rows:
259+ </ h3 >
236260 ) }
237- < ol id = "selectedRows" > { selectedRows } </ ol >
261+ < ol
262+ id = "selectedRows"
263+ >
264+ { selectedRows }
265+ </ ol >
238266 </ div >
239267 </ >
240268 ) ;
0 commit comments