LCOV - code coverage report
Current view: top level - pkg/networkmanager - teamport.jsx Coverage Total Hit
Test: cockpit Lines: 5.0 % 60 3
Test Date: 2026-07-02 14:11:36

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

Generated by: LCOV version 2.0-1