@@ -4,6 +4,85 @@ import { TextField, Typography, MenuItem, Select, Drawer, IconButton, Grid, Butt
4
4
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos' ;
5
5
6
6
export const SettingsSidebar = ( { showSettings, setShowSettings, metricsState, setMetricsState } ) => {
7
+ const [ localMetricsState , setLocalMetricsState ] = useState ( {
8
+ prometheusURL : metricsState . prometheusURL ,
9
+ ksqlDBURL : metricsState . ksqlDBURL ,
10
+ duration : metricsState . duration ,
11
+ refreshRate : metricsState . refreshRate
12
+ } ) ;
13
+
14
+ const handleLocalMetrics = ( event ) => {
15
+ // if (event.target.name === "duration-hours") {
16
+ // setLocalMetricsState({
17
+ // ...localMetricsState,
18
+ // duration: {
19
+ // ...localMetricsState.duration,
20
+ // hours: event.target.value
21
+ // }
22
+ // })
23
+ // }
24
+ switch ( event . target . name ) {
25
+ case "prometheus-url" :
26
+ setLocalMetricsState ( {
27
+ ...localMetricsState ,
28
+ prometheusURL : event . target . value
29
+ } ) ;
30
+ break ;
31
+ case "ksqldb-url" :
32
+ setLocalMetricsState ( {
33
+ ...localMetricsState ,
34
+ ksqlDBURL : event . target . value
35
+ } ) ;
36
+ break ;
37
+ case "duration-days" :
38
+ setLocalMetricsState ( {
39
+ ...localMetricsState ,
40
+ duration : {
41
+ ...localMetricsState . duration ,
42
+ days : event . target . value
43
+ }
44
+ } ) ;
45
+ break ;
46
+ case "duration-hours" :
47
+ setLocalMetricsState ( {
48
+ ...localMetricsState ,
49
+ duration : {
50
+ ...localMetricsState . duration ,
51
+ hours : event . target . value
52
+ }
53
+ } ) ;
54
+ break ;
55
+ case "duration-minutes" :
56
+ setLocalMetricsState ( {
57
+ ...localMetricsState ,
58
+ duration : {
59
+ ...localMetricsState . duration ,
60
+ minutes : event . target . value
61
+ }
62
+ } ) ;
63
+ break ;
64
+ case "refresh-rate" :
65
+ setLocalMetricsState ( {
66
+ ...localMetricsState ,
67
+ refreshRate : event . target . value
68
+ } ) ;
69
+ break ;
70
+ default :
71
+ break ;
72
+ }
73
+ }
74
+
75
+ /*{
76
+ prometheusURL: null,
77
+ ksqlDBURL: null,
78
+ duration: {
79
+ days: 0,
80
+ hours: 0,
81
+ minutes: 10
82
+ },
83
+ refreshRate: 2
84
+ }*/
85
+
7
86
const handleSubmit = ( event ) => {
8
87
event . preventDefault ( ) ;
9
88
@@ -14,14 +93,14 @@ export const SettingsSidebar = ({ showSettings, setShowSettings, metricsState, s
14
93
15
94
// change state
16
95
setMetricsState ( {
17
- prometheusURL : event . target [ 1 ] . value ,
18
- ksqlDBURL : event . target [ 3 ] . value ,
96
+ prometheusURL : localMetricsState . prometheusURL ,
97
+ ksqlDBURL : localMetricsState . ksqlDBURL ,
19
98
duration : {
20
- days : event . target [ 5 ] . value ,
21
- hours : event . target [ 7 ] . value ,
22
- minutes : event . target [ 9 ] . value
99
+ days : localMetricsState . duration . days ,
100
+ hours : localMetricsState . duration . hours ,
101
+ minutes : localMetricsState . duration . minutes
23
102
} ,
24
- refreshRate : event . target [ 11 ] . value
103
+ refreshRate : localMetricsState . refreshRate
25
104
} ) ;
26
105
}
27
106
@@ -31,36 +110,41 @@ export const SettingsSidebar = ({ showSettings, setShowSettings, metricsState, s
31
110
32
111
return (
33
112
< Drawer variant = "temporary" anchor = "right" open = { showSettings } PaperProps = { { sx : { paddingTop : "3.5em" , width : "35%" } } } >
34
- < div className = "flex-1 w-full header-viewport bg-slate-800 p-4" >
113
+ < div className = "flex-1 w-full header-viewport p-4" >
35
114
< form noValidate autoComplete = "off" onSubmit = { handleSubmit } >
36
115
< Grid container flexDirection = "column" justifyContent = "flex-start" alignItems = "flex-start" >
37
116
< IconButton aria-label = "Hide" onClick = { ( ) => setShowSettings ( ! showSettings ) } >
38
- < ArrowForwardIosIcon sx = { { color : "white " } } />
117
+ < ArrowForwardIosIcon sx = { { color : "#333 " } } />
39
118
</ IconButton >
40
- < Typography variant = "h6" sx = { { color : "white " } } > Prometheus Connection</ Typography >
119
+ < Typography variant = "h6" sx = { { color : "#333 " } } > Prometheus Connection</ Typography >
41
120
< hr className = "w-full mb-3 mt-1" > </ hr >
42
121
< TextField
43
122
fullWidth
44
123
variant = "outlined"
45
- label = "Host URL"
124
+ label = "URL"
125
+ name = "prometheus-url"
126
+ onChange = { handleLocalMetrics }
46
127
/>
47
128
< hr className = "w-full invisible mb-2 mt-2" > </ hr >
48
- < Typography variant = "h6" sx = { { color : "white " } } > ksqlDB Connection</ Typography >
129
+ < Typography variant = "h6" sx = { { color : "#333 " } } > ksqlDB Connection</ Typography >
49
130
< hr className = "w-full mb-3 mt-1" > </ hr >
50
131
< TextField
51
132
fullWidth
52
133
variant = "outlined"
53
- label = "Host URL"
134
+ label = "URL"
135
+ name = "ksqldb-url"
136
+ onChange = { handleLocalMetrics }
54
137
/>
55
138
< hr className = "w-full invisible mb-2 mt-2" > </ hr >
56
- < Typography variant = "h6" sx = { { color : "white " } } > Duration</ Typography >
139
+ < Typography variant = "h6" sx = { { color : "#333 " } } > Duration</ Typography >
57
140
< hr className = "w-full mb-3 mt-1" > </ hr >
58
141
< Select
59
142
autoWidth
60
143
id = "duration-days"
61
- value = { metricsState . duration . days ? metricsState . duration . days : 0 }
144
+ value = { localMetricsState . duration . days }
62
145
label = "Days"
63
- name = "days"
146
+ name = "duration-days"
147
+ onChange = { handleLocalMetrics }
64
148
>
65
149
< MenuItem value = { 0 } > 0</ MenuItem >
66
150
< MenuItem value = { 1 } > 1</ MenuItem >
@@ -80,10 +164,11 @@ export const SettingsSidebar = ({ showSettings, setShowSettings, metricsState, s
80
164
</ Select >
81
165
< Select
82
166
id = "duration-hours"
83
- defaultValue = { metricsState . duration . hours ? metricsState . duration . hours : 0 }
167
+ value = { localMetricsState . duration . hours }
84
168
label = "Hours"
85
169
autoWidth
86
- name = "hours"
170
+ name = "duration-hours"
171
+ onChange = { handleLocalMetrics }
87
172
>
88
173
< MenuItem value = { 0 } > 0</ MenuItem >
89
174
< MenuItem value = { 1 } > 1</ MenuItem >
@@ -112,10 +197,11 @@ export const SettingsSidebar = ({ showSettings, setShowSettings, metricsState, s
112
197
</ Select >
113
198
< Select
114
199
id = "duration-minutes"
115
- defaultValue = { metricsState . duration . minutes ? metricsState . duration . minutes : 0 }
200
+ value = { localMetricsState . duration . minutes }
116
201
label = "Minutes"
117
202
autoWidth
118
- name = "minutes"
203
+ name = "duration-minutes"
204
+ onChange = { handleLocalMetrics }
119
205
>
120
206
< MenuItem value = { 0 } > 0</ MenuItem >
121
207
< MenuItem value = { 5 } > 5</ MenuItem >
@@ -137,7 +223,9 @@ export const SettingsSidebar = ({ showSettings, setShowSettings, metricsState, s
137
223
fullWidth
138
224
variant = "outlined"
139
225
label = "seconds"
140
- defaultValue = { metricsState . refreshRate }
226
+ value = { localMetricsState . refreshRate }
227
+ name = "refresh-rate"
228
+ onChange = { handleLocalMetrics }
141
229
/>
142
230
{ /* <Select
143
231
id="refresh-rate-hours"
0 commit comments