LCOV - code coverage report
Current view: top level - pkg/networkmanager - bridgeport.jsx Coverage Total Hit
Test: cockpit Lines: 98.1 % 52 51
Test Date: 2026-07-03 07:31:16

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

Generated by: LCOV version 2.0-1