From cba6209f293af0192011bf72b8da99b52a087377 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Mon, 28 Nov 2022 17:01:33 +0100 Subject: [PATCH 1/3] Convert ContainerRestoreModal to a functional component --- src/ContainerRestoreModal.jsx | 127 +++++++++++++++------------------- 1 file changed, 54 insertions(+), 73 deletions(-) diff --git a/src/ContainerRestoreModal.jsx b/src/ContainerRestoreModal.jsx index d16ea2f66..551678c89 100644 --- a/src/ContainerRestoreModal.jsx +++ b/src/ContainerRestoreModal.jsx @@ -1,90 +1,71 @@ -import React from 'react'; +import React, { useState } from 'react'; import { Button, Checkbox, Form, Modal } from '@patternfly/react-core'; -import { DialogsContext } from "dialogs.jsx"; +import { useDialogs } from "dialogs.jsx"; import cockpit from 'cockpit'; import * as client from './client.js'; const _ = cockpit.gettext; -class ContainerRestoreModal extends React.Component { - static contextType = DialogsContext; +const ContainerRestoreModal = ({ containerWillRestore, onAddNotification }) => { + const Dialogs = useDialogs(); - constructor(props) { - super(props); - this.state = { - inProgress: false, - keep: false, - tcpEstablished: false, - ignoreRootFS: false, - ignoreStaticIP: false, - ignoreStaticMAC: false - }; - this.handleChange = this.handleChange.bind(this); - } + const [inProgress, setInProgress] = useState(false); + const [keep, setKeep] = useState(false); + const [tcpEstablished, setTcpEstablished] = useState(false); + const [ignoreStaticIP, setIgnoreStaticIP] = useState(false); + const [ignoreStaticMAC, setIgnoreStaticMAC] = useState(false); - handleChange(checked, event) { - if (event.target.type === "checkbox") - this.setState({ [event.target.name]: event.target.checked }); - } - - handleRestoreContainer(args) { - const Dialogs = this.context; - const container = this.props.containerWillRestore; - this.setState({ inProgress: true }); - client.postContainer(container.isSystem, "restore", container.Id, args) + const handleRestoreContainer = (args) => { + setInProgress(true); + client.postContainer(containerWillRestore.isSystem, "restore", containerWillRestore.Id, args) .catch(ex => { - const error = cockpit.format(_("Failed to restore container $0"), container.Names); - this.props.onAddNotification({ type: 'danger', error, errorDetail: ex.message }); - this.setState({ inProgress: false }); + const error = cockpit.format(_("Failed to restore container $0"), containerWillRestore.Names); + onAddNotification({ type: 'danger', error, errorDetail: ex.message }); + setInProgress(false); }) .finally(() => { Dialogs.close(); }); - } + }; - render() { - const Dialogs = this.context; - return ( - - - - } - > -
- - - - - -
- ); - } -} + return ( + + + + } + > +
+ + + + + +
+ ); +}; export default ContainerRestoreModal; From 866d879d8e19dfa22948c63f53fb6643c1d980c5 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Mon, 28 Nov 2022 17:16:09 +0100 Subject: [PATCH 2/3] Pass checkpoint restore form arguments We never passed the ignoreStaticIP or ignoreStaticMAC options to the restore rest call. --- src/ContainerRestoreModal.jsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ContainerRestoreModal.jsx b/src/ContainerRestoreModal.jsx index 551678c89..4f852367d 100644 --- a/src/ContainerRestoreModal.jsx +++ b/src/ContainerRestoreModal.jsx @@ -16,9 +16,14 @@ const ContainerRestoreModal = ({ containerWillRestore, onAddNotification }) => { const [ignoreStaticIP, setIgnoreStaticIP] = useState(false); const [ignoreStaticMAC, setIgnoreStaticMAC] = useState(false); - const handleRestoreContainer = (args) => { + const handleRestoreContainer = () => { setInProgress(true); - client.postContainer(containerWillRestore.isSystem, "restore", containerWillRestore.Id, args) + client.postContainer(containerWillRestore.isSystem, "restore", containerWillRestore.Id, { + keep, + tcpEstablished, + ignoreStaticIP, + ignoreStaticMAC, + }) .catch(ex => { const error = cockpit.format(_("Failed to restore container $0"), containerWillRestore.Names); onAddNotification({ type: 'danger', error, errorDetail: ex.message }); @@ -37,12 +42,7 @@ const ContainerRestoreModal = ({ containerWillRestore, onAddNotification }) => { footer={<>