@@ -4,10 +4,10 @@ import { ApplicationContext } from '../context/ApplicationContext';
4
4
import * as DashboardContext from '../context/DashboardContext' ;
5
5
import lightAndDark from '../components/Styling' ;
6
6
import '../stylesheets/ModifyMetrics.scss' ;
7
+ import { Button } from '@material-ui/core' ;
7
8
const { ipcRenderer } = window . require ( 'electron' ) ;
8
9
9
- const MetricsContainer :React . FC = React . memo ( props => {
10
-
10
+ const MetricsContainer : React . FC = React . memo ( props => {
11
11
const { savedMetrics, setSavedMetrics } = useContext ( ApplicationContext ) ;
12
12
const kubernetesMetrics : any [ ] = [ ] ;
13
13
const kafkaMetrics : any [ ] = [ ] ;
@@ -18,47 +18,92 @@ const MetricsContainer:React.FC = React.memo(props => {
18
18
19
19
const metricsToChange = { } ;
20
20
21
- const changeMetric = ( event ) => {
22
- const m = { ...savedMetrics [ event . target . id ] } ;
21
+ const changeMetric = event => {
22
+ const m = { ...savedMetrics [ event . target . id ] } ;
23
23
m [ 'selected' ] = event . target . checked ;
24
24
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
+ } ;
26
37
27
38
const updateMetrics = ( ) => {
28
39
// Sets state for savedMetrics with metrics "selected" option updated based on checkbox selection
29
- const newMetrics = { ...savedMetrics } ;
40
+ const newMetrics = { ...savedMetrics } ;
30
41
for ( let key in metricsToChange ) {
31
42
newMetrics [ key ] = metricsToChange [ key ] ;
32
43
}
33
44
setSavedMetrics ( newMetrics ) ;
34
45
// Sends patch request to db to update which metrics get saved to db
35
46
ipcRenderer . send ( 'updateSavedMetrics' , Object . values ( metricsToChange ) ) ;
36
47
// ipcRenderer.on('updateResponse')
37
- }
48
+ } ;
38
49
39
50
Object . values ( savedMetrics ) . forEach ( ( el : any ) => {
40
51
const jsxEl = (
41
52
< div key = { el . metric } className = "modifyMetric" >
42
53
< 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 >
44
61
{ el . metric }
45
62
</ label >
46
- </ div > )
63
+ </ div >
64
+ ) ;
47
65
if ( el . mode === 'kubernetes' ) kubernetesMetrics . push ( jsxEl ) ;
48
66
else if ( el . mode === 'kafka' ) kafkaMetrics . push ( jsxEl ) ;
49
67
else healthMetrics . push ( jsxEl ) ;
50
- } )
68
+ } ) ;
51
69
52
70
return (
53
71
< 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
+ ) }
60
105
</ div >
61
106
) ;
62
107
} ) ;
63
108
64
- export default MetricsContainer ;
109
+ export default MetricsContainer ;
0 commit comments