import React, { useContext, useState } from "react"; import { Button, Form, Modal, Select, Typography } from "antd"; import { libLink } from "@clusterio/lib"; import ControlContext from "./ControlContext"; import { notifyErrorHandler } from "../util/notify"; import { useHostList } from "../model/host"; const { Paragraph } = Typography; export default function AssignInstanceModal(props) { let [visible, setVisible] = useState(false); let [hostList] = useHostList(); let [applying, setApplying] = useState(false); let [form] = Form.useForm(); let control = useContext(ControlContext); function open() { setVisible(true); } function handleAssign() { let hostId = form.getFieldValue("host"); if (hostId === undefined) { setVisible(false); return; } if (hostId === "null") { hostId = null; } setApplying(true); libLink.messages.assignInstanceCommand.send(control, { instance_id: props.id, host_id: hostId, }).then(() => { setVisible(false); if (props.onFinish) { props.onFinish(); } }).catch( notifyErrorHandler("Error assigning instance") ).finally( () => setApplying(false) ); } function handleCancel() { setVisible(false); } return <> Select a Host to assign this instance to. Assignment creates the necessary files on the host to start up the instance. Note that reassigning an instance from one host to another will not move the server save over.
; }