Skip to content

Commit 414d376

Browse files
author
Jeffrey Na
committed
added toggle functionality to ModifyMetricsContainer.tsx
1 parent d258a16 commit 414d376

File tree

1 file changed

+62
-17
lines changed

1 file changed

+62
-17
lines changed

app/containers/ModifyMetricsContainer.tsx

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ 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);
1212
const kubernetesMetrics: any[] = [];
1313
const kafkaMetrics: any[] = [];
@@ -18,47 +18,92 @@ const MetricsContainer:React.FC = React.memo(props => {
1818

1919
const metricsToChange = {};
2020

21-
const changeMetric = (event) => {
22-
const m = {...savedMetrics[event.target.id]};
21+
const changeMetric = event => {
22+
const m = { ...savedMetrics[event.target.id] };
2323
m['selected'] = event.target.checked;
2424
metricsToChange[event.target.id] = m;
25-
}
25+
26+
const updatedMetric = { ...savedMetrics, [event.target.id]: m };
27+
setSavedMetrics(updatedMetric);
28+
};
29+
30+
const deselectMetrics = () => {
31+
const newMetrics = { ...savedMetrics };
32+
for (let key in newMetrics) {
33+
newMetrics[key].selected = !newMetrics[key].selected;
34+
}
35+
setSavedMetrics(newMetrics);
36+
};
2637

2738
const updateMetrics = () => {
2839
// Sets state for savedMetrics with metrics "selected" option updated based on checkbox selection
29-
const newMetrics = {...savedMetrics};
40+
const newMetrics = { ...savedMetrics };
3041
for (let key in metricsToChange) {
3142
newMetrics[key] = metricsToChange[key];
3243
}
3344
setSavedMetrics(newMetrics);
3445
// Sends patch request to db to update which metrics get saved to db
3546
ipcRenderer.send('updateSavedMetrics', Object.values(metricsToChange));
3647
// ipcRenderer.on('updateResponse')
37-
}
48+
};
3849

3950
Object.values(savedMetrics).forEach((el: any) => {
4051
const jsxEl = (
4152
<div key={el.metric} className="modifyMetric">
4253
<label style={currentMode}>
43-
<input type="checkbox" key={el.metric} id={el.metric} defaultChecked={el.selected} onClick={changeMetric}></input>
54+
<input
55+
type="checkbox"
56+
key={el.metric}
57+
id={el.metric}
58+
checked={el.selected}
59+
onChange={changeMetric}
60+
></input>
4461
{el.metric}
4562
</label>
46-
</div>)
63+
</div>
64+
);
4765
if (el.mode === 'kubernetes') kubernetesMetrics.push(jsxEl);
4866
else if (el.mode === 'kafka') kafkaMetrics.push(jsxEl);
4967
else healthMetrics.push(jsxEl);
50-
})
68+
});
5169

5270
return (
5371
<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>}
72+
<h2 style={currentMode}>
73+
Modify which metrics your Chronos app will track by selecting or deselecting from the list
74+
below.
75+
</h2>
76+
<p style={currentMode}>
77+
This can be helpful if you find that you and your team often only care to track a small
78+
handful of metrics, and don't want your database to be overwhelmed with thousands of
79+
datapoints that you don't necessarily need.
80+
</p>
81+
<button id="changeDatabaseSettingsButton" className="select" onClick={updateMetrics}>
82+
Change Database Settings
83+
</button>
84+
<Button className="deselect" onClick={deselectMetrics}>
85+
Toggle
86+
</Button>
87+
{!!kubernetesMetrics.length && (
88+
<div className="metricsSublist">
89+
<h3 style={currentMode}>Kubernetes Metrics:</h3>
90+
{kubernetesMetrics}
91+
</div>
92+
)}
93+
{!!kafkaMetrics.length && (
94+
<div className="metricsSublist">
95+
<h3 style={currentMode}>Kafka Metrics:</h3>
96+
{kafkaMetrics}
97+
</div>
98+
)}
99+
{!!healthMetrics.length && (
100+
<div className="metricsSublist">
101+
<h3 style={currentMode}>Health Metrics:</h3>
102+
{healthMetrics}
103+
</div>
104+
)}
60105
</div>
61106
);
62107
});
63108

64-
export default MetricsContainer;
109+
export default MetricsContainer;

0 commit comments

Comments
 (0)