LCOV - code coverage report
Current view: top level - pkg/networkmanager - mac.jsx Coverage Total Hit
Test: cockpit Lines: 90.5 % 42 38
Test Date: 2026-07-17 07:33:01

            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 { 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           37 : const _ = cockpit.gettext;
      15              : 
      16            2 : export const MacDialog = ({ connection, dev, settings }) => {
      17            2 :     const Dialogs = useDialogs();
      18            2 :     const idPrefix = "network-mac-settings";
      19            2 :     const model = useContext(ModelContext);
      20              : 
      21            2 :     const [mac, setMAC] = useState((settings.ethernet && settings.ethernet.assigned_mac_address) || "");
      22            2 :     const [dialogError, setDialogError] = useState(undefined);
      23              : 
      24            2 :     const onSubmit = (ev) => {
      25            2 :         const createSettingsObj = () => ({
      26            2 :             ...settings,
      27            2 :             ethernet: {
      28            2 :                 assigned_mac_address: mac
      29            2 :             },
      30            2 :         });
      31              : 
      32            0 :         if (!mac) {
      33            0 :             setDialogError(_("Enter a valid MAC address"));
      34            0 :             return;
      35            0 :         }
      36              : 
      37            2 :         dialogSave({
      38            2 :             model,
      39            2 :             dev,
      40            2 :             connection,
      41            2 :             settings: createSettingsObj(),
      42            2 :             setDialogError,
      43            2 :             onClose: Dialogs.close,
      44            2 :         });
      45              : 
      46              :         // Prevent dialog from closing because of <form> onsubmit event
      47            2 :         if (ev)
      48            2 :             ev.preventDefault();
      49              : 
      50            2 :         return false;
      51            2 :     };
      52              : 
      53            2 :     return (
      54            2 :         <NetworkModal dialogError={dialogError}
      55            2 :                       idPrefix={idPrefix}
      56            2 :                       onSubmit={onSubmit}
      57            2 :                       title={_("Ethernet MAC")}
      58              :         >
      59            2 :             <FormGroup fieldId={idPrefix + "-mac-input"} label={_("MAC")}>
      60            2 :                 <MacMenu idPrefix={idPrefix} model={model} mac={mac} setMAC={setMAC} />
      61            2 :             </FormGroup>
      62            2 :         </NetworkModal>
      63              :     );
      64            2 : };
        

Generated by: LCOV version 2.0-1