LCOV - code coverage report
Current view: top level - pkg/networkmanager - mac.jsx Coverage Total Hit
Test: cockpit Lines: 7.1 % 42 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 { FormGroup } from "@patternfly/react-core/dist/esm/components/Form/index.js";
       9              : 
      10              : import { MacMenu, NetworkModal, dialogSave } from './dialogs-common.jsx';
      11              : import { ModelContext } from './model-context.jsx';
      12              : import { useDialogs } from "dialogs.jsx";
      13              : 
      14            1 : const _ = cockpit.gettext;
      15              : 
      16            0 : export const MacDialog = ({ connection, dev, settings }) => {
      17            0 :     const Dialogs = useDialogs();
      18            0 :     const idPrefix = "network-mac-settings";
      19            0 :     const model = useContext(ModelContext);
      20              : 
      21            0 :     const [mac, setMAC] = useState((settings.ethernet && settings.ethernet.assigned_mac_address) || "");
      22            0 :     const [dialogError, setDialogError] = useState(undefined);
      23              : 
      24            0 :     const onSubmit = (ev) => {
      25            0 :         const createSettingsObj = () => ({
      26            0 :             ...settings,
      27            0 :             ethernet: {
      28            0 :                 assigned_mac_address: mac
      29            0 :             },
      30            0 :         });
      31              : 
      32            0 :         if (!mac) {
      33            0 :             setDialogError(_("Enter a valid MAC address"));
      34            0 :             return;
      35            0 :         }
      36              : 
      37            0 :         dialogSave({
      38            0 :             model,
      39            0 :             dev,
      40            0 :             connection,
      41            0 :             settings: createSettingsObj(),
      42            0 :             setDialogError,
      43            0 :             onClose: Dialogs.close,
      44            0 :         });
      45              : 
      46              :         // Prevent dialog from closing because of <form> onsubmit event
      47            0 :         if (event)
      48            0 :             event.preventDefault();
      49              : 
      50            0 :         return false;
      51            0 :     };
      52              : 
      53            0 :     return (
      54            0 :         <NetworkModal dialogError={dialogError}
      55            0 :                       idPrefix={idPrefix}
      56            0 :                       onSubmit={onSubmit}
      57            0 :                       title={_("Ethernet MAC")}
      58              :         >
      59            0 :             <FormGroup fieldId={idPrefix + "-mac-input"} label={_("MAC")}>
      60            0 :                 <MacMenu idPrefix={idPrefix} model={model} mac={mac} setMAC={setMAC} />
      61            0 :             </FormGroup>
      62            0 :         </NetworkModal>
      63              :     );
      64            0 : };
        

Generated by: LCOV version 2.0-1