LCOV - code coverage report
Current view: top level - src - ContainerCheckpointModal.jsx Coverage Total Hit
Test: cockpit-podman Lines: 90.6 % 53 48
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 ContainerCheckpointModal = ({ con, containerWillCheckpoint, onAddNotification }) => {
      18            1 :     const Dialogs = useDialogs();
      19            1 :     const [inProgress, setProgress] = useState(false);
      20            1 :     const [keep, setKeep] = useState(false);
      21            1 :     const [leaveRunning, setLeaveRunning] = useState(false);
      22            1 :     const [tcpEstablished, setTcpEstablished] = useState(false);
      23              : 
      24            1 :     const handleCheckpointContainer = () => {
      25            1 :         setProgress(true);
      26            1 :         client.postContainer(con, "checkpoint", containerWillCheckpoint.Id, {
      27            1 :             keep,
      28            1 :             leaveRunning,
      29            1 :             tcpEstablished,
      30            1 :         })
      31            0 :                 .catch(ex => {
      32            0 :                     const error = cockpit.format(_("Failed to checkpoint container $0"), containerWillCheckpoint.Name); // not-covered: OS error
      33            0 :                     onAddNotification({ type: 'danger', error, errorDetail: ex.message });
      34            0 :                     setProgress(false);
      35            0 :                 })
      36            1 :                 .finally(() => {
      37            1 :                     Dialogs.close();
      38            1 :                 });
      39            1 :     };
      40              : 
      41            1 :     return (
      42            1 :         <Modal isOpen
      43            1 :                showClose={false}
      44            1 :                position="top" variant="medium"
      45            1 :                title={cockpit.format(_("Checkpoint container $0"), containerWillCheckpoint.Name)}
      46            1 :                footer={<>
      47            1 :                    <Button variant="primary" isDisabled={inProgress}
      48            1 :                            isLoading={inProgress}
      49            1 :                            onClick={handleCheckpointContainer}>
      50            1 :                        {_("Checkpoint")}
      51            1 :                    </Button>
      52            1 :                    <Button variant="link" isDisabled={inProgress}
      53            1 :                            onClick={Dialogs.close}>
      54            1 :                        {_("Cancel")}
      55            1 :                    </Button>
      56            1 :                </>}
      57              :         >
      58            1 :             <Form isHorizontal>
      59            1 :                 <Checkbox label={_("Keep all temporary checkpoint files")} id="checkpoint-dialog-keep"
      60            1 :                               name="keep" isChecked={keep} onChange={(_, val) => setKeep(val)} />
      61            1 :                 <Checkbox label={_("Leave running after writing checkpoint to disk")}
      62            1 :                               id="checkpoint-dialog-leaveRunning" name="leaveRunning"
      63            1 :                               isChecked={leaveRunning} onChange={(_, val) => setLeaveRunning(val)} />
      64            1 :                 <Checkbox label={_("Support preserving established TCP connections")}
      65            1 :                               id="checkpoint-dialog-tcpEstablished" name="tcpEstablished"
      66            1 :                               isChecked={tcpEstablished} onChange={(_, val) => setTcpEstablished(val) } />
      67            1 :             </Form>
      68            1 :         </Modal>
      69              :     );
      70            1 : };
      71              : 
      72           43 : export default ContainerCheckpointModal;
        

Generated by: LCOV version 2.0-1