Line data Source code
1 : /*
2 : * Copyright (C) 2021 Red Hat, Inc.
3 : * SPDX-License-Identifier: LGPL-2.1-or-later
4 : */
5 :
6 37 : import React, { useState, useContext } from 'react';
7 37 : 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 37 : const _ = cockpit.gettext;
17 :
18 1 : export const TeamPortDialog = ({ connection, dev, settings }) => {
19 1 : const Dialogs = useDialogs();
20 1 : const idPrefix = "network-team-port-settings";
21 1 : const model = useContext(ModelContext);
22 :
23 1 : const group_settings = connection.Groups[0].Settings;
24 1 : const group_config = group_settings.team.config;
25 1 : const teamMode = group_config.runner.name;
26 1 : let config = settings.team_port.config;
27 :
28 1 : if (!config)
29 0 : config = { };
30 :
31 0 : const [priority, setPriority] = useState(teamMode == 'activebackup' ? config.prio : config.lacp_prio);
32 1 : const [sticky, setSticky] = useState(config.sticky);
33 1 : const [key, setKey] = useState(config.lacp_key);
34 1 : const [dialogError, setDialogError] = useState(undefined);
35 :
36 1 : const onSubmit = (ev) => {
37 1 : const createSettingsObj = () => ({
38 1 : ...settings,
39 1 : team_port: {
40 1 : config: {
41 1 : ...config,
42 1 : ...(teamMode == 'activebackup' && { prio: priority, sticky }),
43 0 : ...(teamMode == 'lacp' && { lacp_prio: priority, lacp_key: key }),
44 1 : }
45 1 : }
46 1 : });
47 :
48 1 : dialogSave({
49 1 : model,
50 1 : dev,
51 1 : connection,
52 1 : settings: createSettingsObj(),
53 1 : setDialogError,
54 1 : onClose: Dialogs.close,
55 1 : });
56 :
57 : // Prevent dialog from closing because of <form> onsubmit event
58 1 : if (ev)
59 1 : ev.preventDefault();
60 :
61 1 : return false;
62 1 : };
63 :
64 1 : return (
65 1 : <NetworkModal dialogError={dialogError}
66 1 : idPrefix={idPrefix}
67 1 : onSubmit={onSubmit}
68 1 : title={_("Team port settings")}
69 : >
70 1 : <FormGroup fieldId={idPrefix + "-" + teamMode + "-prio-input"} label={_("Priority")}>
71 1 : <TextInput id={idPrefix + "-" + teamMode + "-prio-input"} value={priority} onChange={(_event, value) => setPriority(value)} />
72 1 : </FormGroup>
73 1 : {teamMode == 'activebackup'
74 1 : ? <FormGroup fieldId={idPrefix + "-activebackup-sticky-input"}>
75 1 : <Checkbox id={idPrefix + "-activebackup-sticky-input"} isChecked={sticky} onChange={(_, s) => setSticky(s)} label={_("Sticky")} />
76 1 : </FormGroup>
77 0 : : null}
78 1 : {teamMode == 'lacp'
79 0 : ? <FormGroup fieldId={idPrefix + "-" + teamMode + "-key-input"} label={_("LACP key")}>
80 0 : <TextInput id={idPrefix + "-" + teamMode + "-key-input"} value={key} onChange={(_event, value) => setKey(value)} />
81 0 : </FormGroup>
82 1 : : null}
83 1 : </NetworkModal>
84 : );
85 1 : };
|