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;