Skip to content

Commit 39d684e

Browse files
committed
Added saved metrics from application context to component
The rows of the data grid were being imporperly created from the full list of all health metrics which resulted in repeat rows. Refactored the rows function to take the values directly from the metrics model
1 parent e63a018 commit 39d684e

1 file changed

Lines changed: 32 additions & 14 deletions

File tree

app/components/TransferColumns.tsx

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState, useContext, useEffect } from 'react';
2+
import { ApplicationContext } from '../context/ApplicationContext';
23
import { useParams } from 'react-router-dom';
34
import { QueryContext } from '../context/QueryContext';
45
import { HealthContext } from '../context/HealthContext';
@@ -32,6 +33,8 @@ const TransferColumns = React.memo(() => {
3233
const { mode } = useContext(DashboardContext.DashboardContext);
3334
const [searchTerm, setSearchTerm] = useState<string>('');
3435

36+
const { savedMetrics } = useContext(ApplicationContext)
37+
3538
const currentMode = mode === 'light' ? lightAndDark.lightModeText : lightAndDark.darkModeText;
3639

3740
useEffect(() => {
@@ -104,7 +107,7 @@ const TransferColumns = React.memo(() => {
104107
}
105108
}
106109
} 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
108111
// The pool array wants an object with a specific format in order to populate the selection table
109112
for (const service in dataObject) {
110113
const categoryObjects = dataObject[service];
@@ -169,22 +172,31 @@ const TransferColumns = React.memo(() => {
169172
},
170173
];
171174

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+
}
182186

183187
// makes the Printed list of 'currently selected rows' on the page using targetKeys array
184188
const selectedRows: any[] = [];
185189
targetKeys.forEach(el => {
186190
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>
188200
);
189201
});
190202

@@ -220,11 +232,17 @@ const TransferColumns = React.memo(() => {
220232
});
221233
setTargetKeys(metrics);
222234
}}
223-
/>
235+
/>
224236

225237
</div>
226238
{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>
228246
)}
229247
<ol id="selectedRows">{selectedRows}</ol>
230248
</div>

0 commit comments

Comments
 (0)