| 1 |
/* |
| 2 |
* Copyright (C) 2021 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
import React, { useState, useContext } from 'react'; |
| 7 |
import cockpit from 'cockpit'; |
| 8 |
import { Checkbox } from "@patternfly/react-core/dist/esm/components/Checkbox/index.js"; |
| 9 |
import { FormGroup } from "@patternfly/react-core/dist/esm/components/Form/index.js"; |
| 10 |
import { TextInput } from "@patternfly/react-core/dist/esm/components/TextInput/index.js"; |
| 11 |
|
| 12 |
import { NetworkModal, dialogSave } from './dialogs-common.jsx'; |
| 13 |
import { ModelContext } from './model-context.jsx'; |
| 14 |
import { useDialogs } from "dialogs.jsx"; |
| 15 |
|
| 16 |
const _ = cockpit.gettext; |
| 17 |
|
| 18 |
export const BridgePortDialog = ({ connection, dev, settings }) => { |
| 19 |
const Dialogs = useDialogs(); |
| 20 |
const idPrefix = "network-bridge-port-settings"; |
| 21 |
const model = useContext(ModelContext); |
| 22 |
|
| 23 |
let config = settings.bridge_port; |
| 24 |
|
| 25 |
if (!config) |
| 26 |
config = { }; |
| 27 |
|
| 28 |
const [priority, setPriority] = useState(config.priority); |
| 29 |
const [hairPin, setHairPin] = useState(config.hairpin_mode); |
| 30 |
const [pathCost, setPathCost] = useState(config.path_cost); |
| 31 |
const [dialogError, setDialogError] = useState(undefined); |
| 32 |
|
| 33 |
const onSubmit = (ev) => { |
| 34 |
const createSettingsObj = () => ({ |
| 35 |
...settings, |
| 36 |
bridge_port: { |
| 37 |
...settings.bridge_port, |
| 38 |
priority: parseInt(priority, 10), |
| 39 |
path_cost: parseInt(pathCost, 10), |
| 40 |
hairpin_mode: hairPin, |
| 41 |
} |
| 42 |
}); |
| 43 |
|
| 44 |
dialogSave({ |
| 45 |
model, |
| 46 |
dev, |
| 47 |
connection, |
| 48 |
settings: createSettingsObj(), |
| 49 |
setDialogError, |
| 50 |
onClose: Dialogs.close, |
| 51 |
}); |
| 52 |
|
| 53 |
// Prevent dialog from closing because of <form> onsubmit event |
| 54 |
if (ev) |
| 55 |
ev.preventDefault(); |
| 56 |
|
| 57 |
return false; |
| 58 |
}; |
| 59 |
|
| 60 |
return ( |
| 61 |
<NetworkModal dialogError={dialogError} |
| 62 |
idPrefix={idPrefix} |
| 63 |
onSubmit={onSubmit} |
| 64 |
title={_("Bridge port settings")} |
| 65 |
> |
| 66 |
<FormGroup fieldId={idPrefix + "-prio-input"} label={_("Priority")}> |
| 67 |
<TextInput id={idPrefix + "-prio-input"} value={priority} onChange={(_event, value) => setPriority(value)} /> |
| 68 |
</FormGroup> |
| 69 |
<FormGroup fieldId={idPrefix + "-path-cost-input"} label={_("Path cost")}> |
| 70 |
<TextInput id={idPrefix + "-path-cost-input"} value={pathCost} onChange={(_event, value) => setPathCost(value)} /> |
| 71 |
</FormGroup> |
| 72 |
<FormGroup fieldId={idPrefix + "-hairPin-mode-input"}> |
| 73 |
<Checkbox id={idPrefix + "-hairPin-mode-input"} isChecked={hairPin} onChange={(_, hp) => setHairPin(hp)} label={_("Hair pin mode")} /> |
| 74 |
</FormGroup> |
| 75 |
</NetworkModal> |
| 76 |
); |
| 77 |
}; |