|
1 | 1 | import React, { useState, useContext, useEffect } from 'react'; |
| 2 | +import { ApplicationContext } from '../context/ApplicationContext'; |
2 | 3 | import { useParams } from 'react-router-dom'; |
3 | 4 | import { QueryContext } from '../context/QueryContext'; |
4 | 5 | import { HealthContext } from '../context/HealthContext'; |
@@ -32,6 +33,8 @@ const TransferColumns = React.memo(() => { |
32 | 33 | const { mode } = useContext(DashboardContext.DashboardContext); |
33 | 34 | const [searchTerm, setSearchTerm] = useState<string>(''); |
34 | 35 |
|
| 36 | + const { savedMetrics } = useContext(ApplicationContext) |
| 37 | + |
35 | 38 | const currentMode = mode === 'light' ? lightAndDark.lightModeText : lightAndDark.darkModeText; |
36 | 39 |
|
37 | 40 | useEffect(() => { |
@@ -104,7 +107,7 @@ const TransferColumns = React.memo(() => { |
104 | 107 | } |
105 | 108 | } |
106 | 109 | } else { |
107 | | - // iterate throught the healthData object to populate the `Metrics Query` tab with metrics options |
| 110 | + // iterate throughout the healthData object to populate the `Metrics Query` tab with metrics options |
108 | 111 | // The pool array wants an object with a specific format in order to populate the selection table |
109 | 112 | for (const service in dataObject) { |
110 | 113 | const categoryObjects = dataObject[service]; |
@@ -169,22 +172,31 @@ const TransferColumns = React.memo(() => { |
169 | 172 | }, |
170 | 173 | ]; |
171 | 174 |
|
172 | | - // 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 | | - }); |
| 175 | + const rows:any[] = [] |
| 176 | + let id = 0 |
| 177 | + for(let savedMetric of Object.keys(savedMetrics)) { |
| 178 | + |
| 179 | + const { metric,category } = savedMetrics[savedMetric] |
| 180 | + rows.push({ |
| 181 | + id:id++, |
| 182 | + tag:category, |
| 183 | + title:metric |
| 184 | + }) |
| 185 | + } |
182 | 186 |
|
183 | 187 | // makes the Printed list of 'currently selected rows' on the page using targetKeys array |
184 | 188 | const selectedRows: any[] = []; |
185 | 189 | targetKeys.forEach(el => { |
186 | 190 | selectedRows.push( |
187 | | - <li style={{ marginLeft: '30px', marginTop: '5px', color: currentMode.color }}>{el}</li> |
| 191 | + <li |
| 192 | + style={{ |
| 193 | + marginLeft: '30px', |
| 194 | + marginTop: '5px', |
| 195 | + color: currentMode.color |
| 196 | + }} |
| 197 | + > |
| 198 | + {el} |
| 199 | + </li> |
188 | 200 | ); |
189 | 201 | }); |
190 | 202 |
|
@@ -220,11 +232,17 @@ const TransferColumns = React.memo(() => { |
220 | 232 | }); |
221 | 233 | setTargetKeys(metrics); |
222 | 234 | }} |
223 | | - /> |
| 235 | + /> |
224 | 236 |
|
225 | 237 | </div> |
226 | 238 | {selectedRows.length > 0 && ( |
227 | | - <h3 style={{ marginTop: '20px', color: currentMode.color }}>Selected Rows:</h3> |
| 239 | + <h3 style={{ |
| 240 | + marginTop: '20px', |
| 241 | + color: currentMode.color |
| 242 | + }} |
| 243 | + > |
| 244 | + Selected Rows: |
| 245 | + </h3> |
228 | 246 | )} |
229 | 247 | <ol id="selectedRows">{selectedRows}</ol> |
230 | 248 | </div> |
|
0 commit comments