LCOV - code coverage report
Current view: top level - src - ContainerRestoreModal.jsx Coverage Total Hit
Test: cockpit-podman Lines: 91.4 % 58 53
Test Date: 2025-05-21 17:35:03

            Line data    Source code
       1           43 : import React, { useState } from 'react';
       2              : 
       3              : import { Button } from "@patternfly/react-core/dist/esm/components/Button";
       4              : import { Checkbox } from "@patternfly/react-core/dist/esm/components/Checkbox";
       5              : import { Form } from "@patternfly/react-core/dist/esm/components/Form";
       6              : import {
       7              :     Modal
       8              : } from '@patternfly/react-core/dist/esm/deprecated/components/Modal';
       9              : import { useDialogs } from "dialogs.jsx";
      10              : 
      11              : import cockpit from 'cockpit';
      12              : 
      13              : import * as client from './client.js';
      14              : 
      15           43 : const _ = cockpit.gettext;
      16              : 
      17            1 : const ContainerRestoreModal = ({ con, containerWillRestore, onAddNotification }) => {
      18            1 :     const Dialogs = useDialogs();
      19              : 
      20            1 :     const [inProgress, setInProgress] = useState(false);
      21            1 :     const [keep, setKeep] = useState(false);
      22            1 :     const [tcpEstablished, setTcpEstablished] = useState(false);
      23            1 :     const [ignoreStaticIP, setIgnoreStaticIP] = useState(false);
      24            1 :     const [ignoreStaticMAC, setIgnoreStaticMAC] = useState(false);
      25              : 
      26            1 :     const handleRestoreContainer = () => {
      27            1 :         setInProgress(true);
      28            1 :         client.postContainer(con, "restore", containerWillRestore.Id, {
      29            1 :             keep,
      30            1 :             tcpEstablished,
      31            1 :             ignoreStaticIP,
      32            1 :             ignoreStaticMAC,
      33            1 :         })
      34            0 :                 .catch(ex => {
      35            0 :                     const error = cockpit.format(_("Failed to restore container $0"), containerWillRestore.Name); // not-covered: OS error
      36            0 :                     onAddNotification({ type: 'danger', error, errorDetail: ex.message });
      37            0 :                     setInProgress(false);
      38            0 :                 })
      39            1 :                 .finally(() => {
      40            1 :                     Dialogs.close();
      41            1 :                 });
      42            1 :     };
      43              : 
      44            1 :     return (
      45            1 :         <Modal isOpen
      46            1 :                showClose={false}
      47            1 :                position="top" variant="medium"
      48            1 :                title={cockpit.format(_("Restore container $0"), containerWillRestore.Name)}
      49            1 :                footer={<>
      50            1 :                    <Button variant="primary" isDisabled={inProgress}
      51            1 :                            isLoading={inProgress}
      52            1 :                            onClick={handleRestoreContainer}>
      53            1 :                        {_("Restore")}
      54            1 :                    </Button>
      55            1 :                    <Button variant="link" isDisabled={inProgress}
      56            1 :                            onClick={Dialogs.close}>
      57            1 :                        {_("Cancel")}
      58            1 :                    </Button>
      59            1 :                </>}
      60              :         >
      61            1 :             <Form isHorizontal>
      62            1 :                 <Checkbox label={_("Keep all temporary checkpoint files")} id="restore-dialog-keep" name="keep"
      63            1 :                           isChecked={keep} onChange={(_, val) => setKeep(val)} />
      64            1 :                 <Checkbox label={_("Restore with established TCP connections")}
      65            1 :                           id="restore-dialog-tcpEstablished" name="tcpEstablished"
      66            1 :                           isChecked={tcpEstablished} onChange={(_, val) => setTcpEstablished(val)} />
      67            1 :                 <Checkbox label={_("Ignore IP address if set statically")} id="restore-dialog-ignoreStaticIP"
      68            1 :                           name="ignoreStaticIP" isChecked={ignoreStaticIP}
      69            1 :                           onChange={(_, val) => setIgnoreStaticIP(val)} />
      70            1 :                 <Checkbox label={_("Ignore MAC address if set statically")} id="restore-dialog-ignoreStaticMAC"
      71            1 :                           name="ignoreStaticMAC" isChecked={ignoreStaticMAC}
      72            1 :                           onChange={(_, val) => setIgnoreStaticMAC(val)} />
      73            1 :             </Form>
      74            1 :         </Modal>
      75              :     );
      76            1 : };
      77              : 
      78           43 : export default ContainerRestoreModal;
        

Generated by: LCOV version 2.0-1