Skip to content

Commit 2fd413e

Browse files
Finished parent and local state to keep track of user settings input
1 parent 6cf536c commit 2fd413e

File tree

2 files changed

+109
-21
lines changed

2 files changed

+109
-21
lines changed

ksqLight/src/components/Homepage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const Homepage = () => {
88
const [content, setContent] = useState('Chart placeholder');
99

1010
const queryTypes = [
11-
["runningQueries", "Number of Running Queries"],
11+
// ["runningQueries", "Number of Running Queries"],
1212
// ["rebalancingQueries", "Number of Rebalancing Queries"],
1313
// ["pendingShutdownQueries", "Number of Pending Shutdown Queries"],
1414
// ["pendingErrorQueries", "Number of Pending Error Queries"],

ksqLight/src/components/SettingsSidebar.js

Lines changed: 108 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,85 @@ import { TextField, Typography, MenuItem, Select, Drawer, IconButton, Grid, Butt
44
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
55

66
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+
786
const handleSubmit = (event) => {
887
event.preventDefault();
988

@@ -14,14 +93,14 @@ export const SettingsSidebar = ({ showSettings, setShowSettings, metricsState, s
1493

1594
// change state
1695
setMetricsState({
17-
prometheusURL: event.target[1].value,
18-
ksqlDBURL: event.target[3].value,
96+
prometheusURL: localMetricsState.prometheusURL,
97+
ksqlDBURL: localMetricsState.ksqlDBURL,
1998
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
23102
},
24-
refreshRate: event.target[11].value
103+
refreshRate: localMetricsState.refreshRate
25104
});
26105
}
27106

@@ -31,36 +110,41 @@ export const SettingsSidebar = ({ showSettings, setShowSettings, metricsState, s
31110

32111
return(
33112
<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">
35114
<form noValidate autoComplete="off" onSubmit={handleSubmit}>
36115
<Grid container flexDirection="column" justifyContent="flex-start" alignItems="flex-start">
37116
<IconButton aria-label="Hide" onClick={() => setShowSettings(!showSettings)}>
38-
<ArrowForwardIosIcon sx={{color: "white"}}/>
117+
<ArrowForwardIosIcon sx={{color: "#333"}}/>
39118
</IconButton>
40-
<Typography variant="h6" sx={{color: "white"}}>Prometheus Connection</Typography>
119+
<Typography variant="h6" sx={{color: "#333"}}>Prometheus Connection</Typography>
41120
<hr className="w-full mb-3 mt-1"></hr>
42121
<TextField
43122
fullWidth
44123
variant="outlined"
45-
label="Host URL"
124+
label="URL"
125+
name="prometheus-url"
126+
onChange={handleLocalMetrics}
46127
/>
47128
<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>
49130
<hr className="w-full mb-3 mt-1"></hr>
50131
<TextField
51132
fullWidth
52133
variant="outlined"
53-
label="Host URL"
134+
label="URL"
135+
name="ksqldb-url"
136+
onChange={handleLocalMetrics}
54137
/>
55138
<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>
57140
<hr className="w-full mb-3 mt-1"></hr>
58141
<Select
59142
autoWidth
60143
id="duration-days"
61-
value={metricsState.duration.days ? metricsState.duration.days : 0}
144+
value={localMetricsState.duration.days}
62145
label="Days"
63-
name="days"
146+
name="duration-days"
147+
onChange={handleLocalMetrics}
64148
>
65149
<MenuItem value={0}>0</MenuItem>
66150
<MenuItem value={1}>1</MenuItem>
@@ -80,10 +164,11 @@ export const SettingsSidebar = ({ showSettings, setShowSettings, metricsState, s
80164
</Select>
81165
<Select
82166
id="duration-hours"
83-
defaultValue={metricsState.duration.hours ? metricsState.duration.hours : 0}
167+
value={localMetricsState.duration.hours}
84168
label="Hours"
85169
autoWidth
86-
name="hours"
170+
name="duration-hours"
171+
onChange={handleLocalMetrics}
87172
>
88173
<MenuItem value={0}>0</MenuItem>
89174
<MenuItem value={1}>1</MenuItem>
@@ -112,10 +197,11 @@ export const SettingsSidebar = ({ showSettings, setShowSettings, metricsState, s
112197
</Select>
113198
<Select
114199
id="duration-minutes"
115-
defaultValue={metricsState.duration.minutes ? metricsState.duration.minutes : 0}
200+
value={localMetricsState.duration.minutes}
116201
label="Minutes"
117202
autoWidth
118-
name="minutes"
203+
name="duration-minutes"
204+
onChange={handleLocalMetrics}
119205
>
120206
<MenuItem value={0}>0</MenuItem>
121207
<MenuItem value={5}>5</MenuItem>
@@ -137,7 +223,9 @@ export const SettingsSidebar = ({ showSettings, setShowSettings, metricsState, s
137223
fullWidth
138224
variant="outlined"
139225
label="seconds"
140-
defaultValue={metricsState.refreshRate}
226+
value={localMetricsState.refreshRate}
227+
name="refresh-rate"
228+
onChange={handleLocalMetrics}
141229
/>
142230
{/* <Select
143231
id="refresh-rate-hours"

0 commit comments

Comments
 (0)