LCOV - code coverage report
Current view: top level - pkg/networkmanager - bridgeport.jsx Coverage Total Hit
Test: cockpit Lines: 5.8 % 52 3
Test Date: 2026-06-17 06:28:00

            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 BridgePortDialog = ({ connection, dev, settings }) => {
      19            0 :     const Dialogs = useDialogs();
      20            0 :     const idPrefix = "network-bridge-port-settings";
      21            0 :     const model = useContext(ModelContext);
      22              : 
      23            0 :     let config = settings.bridge_port;
      24              : 
      25            0 :     if (!config)
      26            0 :         config = config = { };
      27              : 
      28            0 :     const [priority, setPriority] = useState(config.priority);
      29            0 :     const [hairPin, setHairPin] = useState(config.hairpin_mode);
      30            0 :     const [pathCost, setPathCost] = useState(config.path_cost);
      31            0 :     const [dialogError, setDialogError] = useState(undefined);
      32              : 
      33            0 :     const onSubmit = (ev) => {
      34            0 :         const createSettingsObj = () => ({
      35            0 :             ...settings,
      36            0 :             bridge_port: {
      37            0 :                 ...settings.bridge_port,
      38            0 :                 priority: parseInt(priority, 10),
      39            0 :                 path_cost: parseInt(pathCost, 10),
      40            0 :                 hairpin_mode: hairPin,
      41            0 :             }
      42            0 :         });
      43              : 
      44            0 :         dialogSave({
      45            0 :             model,
      46            0 :             dev,
      47            0 :             connection,
      48            0 :             settings: createSettingsObj(),
      49            0 :             setDialogError,
      50            0 :             onClose: Dialogs.close,
      51            0 :         });
      52              : 
      53              :         // Prevent dialog from closing because of <form> onsubmit event
      54            0 :         if (event)
      55            0 :             event.preventDefault();
      56              : 
      57            0 :         return false;
      58            0 :     };
      59              : 
      60            0 :     return (
      61            0 :         <NetworkModal dialogError={dialogError}
      62            0 :                       idPrefix={idPrefix}
      63            0 :                       onSubmit={onSubmit}
      64            0 :                       title={_("Bridge port settings")}
      65              :         >
      66            0 :             <FormGroup fieldId={idPrefix + "-prio-input"} label={_("Priority")}>
      67            0 :                 <TextInput id={idPrefix + "-prio-input"} value={priority} onChange={(_event, value) => setPriority(value)} />
      68            0 :             </FormGroup>
      69            0 :             <FormGroup fieldId={idPrefix + "-path-cost-input"} label={_("Path cost")}>
      70            0 :                 <TextInput id={idPrefix + "-path-cost-input"} value={pathCost} onChange={(_event, value) => setPathCost(value)} />
      71            0 :             </FormGroup>
      72            0 :             <FormGroup fieldId={idPrefix + "-hairPin-mode-input"}>
      73            0 :                 <Checkbox id={idPrefix + "-hairPin-mode-input"} isChecked={hairPin} onChange={(_, hp) => setHairPin(hp)} label={_("Hair pin mode")} />
      74            0 :             </FormGroup>
      75            0 :         </NetworkModal>
      76              :     );
      77            0 : };
        

Generated by: LCOV version 2.0-1