Skip to content

Commit 106078b

Browse files
authored
Merge pull request #16 from oslabs-beta/jeffrey/metrics
Jeffrey/metrics
2 parents c8f68c8 + 4690c56 commit 106078b

File tree

1 file changed

+68
-18
lines changed

1 file changed

+68
-18
lines changed
Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import React, { useEffect, useContext } from 'react';
1+
import React, { useState, useEffect, useContext } from 'react';
22
import { JsxElement } from 'typescript';
33
import { ApplicationContext } from '../context/ApplicationContext';
44
import * as DashboardContext from '../context/DashboardContext';
55
import lightAndDark from '../components/Styling';
66
import '../stylesheets/ModifyMetrics.scss';
7+
import { Button } from '@material-ui/core';
78
const { ipcRenderer } = window.require('electron');
89

9-
const MetricsContainer:React.FC = React.memo(props => {
10-
10+
const MetricsContainer: React.FC = React.memo(props => {
1111
const { savedMetrics, setSavedMetrics } = useContext(ApplicationContext);
12+
const [showCheckMark, setShowCheckMark] = useState(true);
1213
const kubernetesMetrics: any[] = [];
1314
const kafkaMetrics: any[] = [];
1415
const healthMetrics: any[] = [];
@@ -18,47 +19,96 @@ const MetricsContainer:React.FC = React.memo(props => {
1819

1920
const metricsToChange = {};
2021

21-
const changeMetric = (event) => {
22-
const m = {...savedMetrics[event.target.id]};
22+
const changeMetric = event => {
23+
const m = { ...savedMetrics[event.target.id] };
2324
m['selected'] = event.target.checked;
2425
metricsToChange[event.target.id] = m;
25-
}
26+
27+
const updatedMetric = { ...savedMetrics, [event.target.id]: m };
28+
setSavedMetrics(updatedMetric);
29+
};
2630

2731
const updateMetrics = () => {
2832
// Sets state for savedMetrics with metrics "selected" option updated based on checkbox selection
29-
const newMetrics = {...savedMetrics};
33+
const newMetrics = { ...savedMetrics };
3034
for (let key in metricsToChange) {
3135
newMetrics[key] = metricsToChange[key];
3236
}
3337
setSavedMetrics(newMetrics);
3438
// Sends patch request to db to update which metrics get saved to db
3539
ipcRenderer.send('updateSavedMetrics', Object.values(metricsToChange));
3640
// ipcRenderer.on('updateResponse')
37-
}
41+
};
42+
43+
/**
44+
* @desc Toggle functionality to deselect and select all metrics.
45+
*/
46+
const toggleCheckbox = () => {
47+
const newMetrics = { ...savedMetrics };
48+
for (let key in newMetrics) {
49+
newMetrics[key].selected = !showCheckMark;
50+
}
51+
setSavedMetrics(newMetrics);
52+
setShowCheckMark(!showCheckMark);
53+
};
3854

3955
Object.values(savedMetrics).forEach((el: any) => {
4056
const jsxEl = (
4157
<div key={el.metric} className="modifyMetric">
4258
<label style={currentMode}>
43-
<input type="checkbox" key={el.metric} id={el.metric} defaultChecked={el.selected} onClick={changeMetric}></input>
59+
<input
60+
type="checkbox"
61+
key={el.metric}
62+
id={el.metric}
63+
checked={el.selected}
64+
onChange={changeMetric}
65+
></input>
4466
{el.metric}
4567
</label>
46-
</div>)
68+
</div>
69+
);
4770
if (el.mode === 'kubernetes') kubernetesMetrics.push(jsxEl);
4871
else if (el.mode === 'kafka') kafkaMetrics.push(jsxEl);
4972
else healthMetrics.push(jsxEl);
50-
})
73+
});
5174

5275
return (
5376
<div className="metricsSelector">
54-
<h2 style={currentMode}>Modify which metrics your Chronos app will track by selecting or deselecting from the list below.</h2>
55-
<p style={currentMode}>This can be helpful if you find that you and your team often only care to track a small handful of metrics, and don't want your database to be overwhelmed with thousands of datapoints that you don't necessarily need.</p>
56-
<button id="changeDatabaseSettingsButton" className="select" onClick={updateMetrics}>Change Database Settings</button>
57-
{!!kubernetesMetrics.length && <div className='metricsSublist'><h3 style={currentMode}>Kubernetes Metrics:</h3>{kubernetesMetrics}</div>}
58-
{!!kafkaMetrics.length && <div className='metricsSublist'><h3 style={currentMode}>Kafka Metrics:</h3>{kafkaMetrics}</div>}
59-
{!!healthMetrics.length && <div className='metricsSublist'><h3 style={currentMode}>Health Metrics:</h3>{healthMetrics}</div>}
77+
<h2 style={currentMode}>
78+
Modify which metrics your Chronos app will track by selecting or deselecting from the list
79+
below.
80+
</h2>
81+
<p style={currentMode}>
82+
This can be helpful if you find that you and your team often only care to track a small
83+
handful of metrics, and don't want your database to be overwhelmed with thousands of
84+
datapoints that you don't necessarily need.
85+
</p>
86+
<button id="changeDatabaseSettingsButton" className="select" onClick={updateMetrics}>
87+
Change Database Settings
88+
</button>
89+
<Button variant="contained" color="primary" id="toggleCheck" onClick={toggleCheckbox}>
90+
{showCheckMark ? 'Deselect All' : 'Select All'}
91+
</Button>
92+
{!!kubernetesMetrics.length && (
93+
<div className="metricsSublist">
94+
<h3 style={currentMode}>Kubernetes Metrics:</h3>
95+
{kubernetesMetrics}
96+
</div>
97+
)}
98+
{!!kafkaMetrics.length && (
99+
<div className="metricsSublist">
100+
<h3 style={currentMode}>Kafka Metrics:</h3>
101+
{kafkaMetrics}
102+
</div>
103+
)}
104+
{!!healthMetrics.length && (
105+
<div className="metricsSublist">
106+
<h3 style={currentMode}>Health Metrics:</h3>
107+
{healthMetrics}
108+
</div>
109+
)}
60110
</div>
61111
);
62112
});
63113

64-
export default MetricsContainer;
114+
export default MetricsContainer;

0 commit comments

Comments
 (0)