-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathNetworkSettings.jsx
144 lines (134 loc) · 4.14 KB
/
NetworkSettings.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import {
Accordion,
AccordionSummary,
AccordionDetails,
Checkbox,
Divider,
Grid,
Typography,
TextField,
Select,
} from "@material-ui/core";
import ExpandMoreIcon from "@material-ui/icons/ExpandMore.js";
import ManagedRoutes from "./components/ManagedRoutes/ManagedRoutes.jsx";
import IPv4AutoAssign from "./components/IPv4AutoAssign/IPv4AutoAssign.jsx";
import API from "utils/API.js";
import { parseValue, replaceValue, setValue } from "utils/ChangeHelper.js";
import { useTranslation } from "react-i18next";
function NetworkSettings({ network, setNetwork }) {
const { t, i18n } = useTranslation();
const sendReq = async (data) => {
try {
const req = await API.post("/network/" + network["config"]["id"], data);
console.log("Action", req);
} catch (err) {
console.error(err);
}
};
const handleChange =
(key1, key2, mode = "text", additionalData = null) =>
(event) => {
const value = parseValue(event, mode, additionalData);
let updatedNetwork = replaceValue({ ...network }, key1, key2, value);
setNetwork(updatedNetwork);
let data = setValue({}, key1, key2, value);
sendReq(data);
};
return (
<Accordion>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<Typography>{t("generalSettings")}</Typography>
</AccordionSummary>
<AccordionDetails>
<Grid container direction="column" spacing={3}>
<Grid item>
<Typography>{t("networkId")}</Typography>
<Typography variant="h5">
<span>{network["config"]["id"]}</span>
</Typography>
</Grid>
<Grid item>
<TextField
value={network["config"]["name"]}
onChange={handleChange("config", "name")}
label={t("name")}
variant="filled"
InputLabelProps={{
shrink: true,
}}
/>
</Grid>
<Grid item>
<TextField
value={network["description"]}
onChange={handleChange("description")}
multiline
minRows={2}
maxRows={Infinity}
label={t("description")}
variant="filled"
InputLabelProps={{
shrink: true,
}}
/>
</Grid>
<Divider />
<Grid item>
<Typography>{t("accessControl")}</Typography>
<Select
native
value={network["config"]["private"]}
onChange={handleChange("config", "private", "json")}
>
<option value={1}>{t("private")}</option>
<option value={0}>{t("public")}</option>
</Select>
</Grid>
<Divider />
<Grid item>
<ManagedRoutes
routes={network["config"]["routes"]}
handleChange={handleChange}
/>
</Grid>
<Divider />
<Grid item>
<IPv4AutoAssign
ipAssignmentPools={network["config"]["ipAssignmentPools"]}
handleChange={handleChange}
/>
</Grid>
{/* TODO: */}
{/* <Grid item>
<Typography>IPv6 Auto-Assign</Typography>
</Grid> */}
<Divider />
<Grid item>
<TextField
label={t("multicastLimit")}
type="number"
value={network["config"]["multicastLimit"]}
onChange={handleChange("config", "multicastLimit", "json")}
InputLabelProps={{
shrink: true,
}}
/>
</Grid>
<Grid item>
<Checkbox
checked={network["config"]["enableBroadcast"]}
color="primary"
onChange={handleChange("config", "enableBroadcast", "checkbox")}
/>
<span>{t("enableBroadcast")}</span>
</Grid>
{/* TODO: */}
{/* <Grid item>
<Typography>DNS</Typography>
</Grid> */}
</Grid>
</AccordionDetails>
</Accordion>
);
}
export default NetworkSettings;