import { useContext, useEffect, useState } from "react"; import { Button, Descriptions, Input, Modal, Select, Space, Table, Typography } from "antd"; import SearchOutlined from "@ant-design/icons/SearchOutlined"; import * as lib from "@clusterio/lib"; import { useAccount } from "../model/account"; import { useHosts } from "../model/host"; import { notifyErrorHandler } from "../util/notify"; import ControlContext from "./ControlContext"; import { InstallTarget, PluginInstaller, RemoteInstallDisabledNotice, addressKey } from "./PluginInstall"; import { PluginInstalledTag, PluginUpdateButton, PluginVersions } from "./PluginClusterStatus"; import type { PluginStatus } from "../util/plugin_status"; const { Text, Link } = Typography; /** Statuses are undefined until the plugin lists of the machines have loaded, or without core.plugin.list */ type BrowserProps = { statuses?: Map, installer: PluginInstaller }; const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare; // Installs on the chosen machines, defaulting to every connected machine that allows installs. function InstallControls(props: { packageSpec: string, installer: PluginInstaller }) { const account = useAccount(); const [hosts] = useHosts(); // Tracks what was deselected so machines connecting later, or allowing installs, start selected const [deselected, setDeselected] = useState(new Set()); const { access, installing, restarting } = props.installer; const machines: (InstallTarget & { key: string, allowed: boolean })[] = [ { name: "Controller", address: "controller" as lib.AddressShorthand }, ...[...hosts.values()] .filter(host => host.connected) .sort((a, b) => strcmp(a.name, b.name)) .map(host => ({ name: host.name, address: { hostId: host.id } as lib.AddressShorthand })), ].map(target => ({ ...target, key: addressKey(target.address), allowed: access.canInstall(target.address) })); const selected = machines.filter(machine => machine.allowed && !deselected.has(machine.key)); const blocked = machines.filter(machine => !machine.allowed); return Install on