mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
Merge pull request #1010 from bbassie/feature/plugin-browser
Plugin management through web interface
This commit is contained in:
1 parent
e36a76acc5
commit
ffe82f81d8
48 files changed
+4275
-536
No files matched your search
@@ -1,12 +1,19 @@
|
||||
import React, { useContext, useEffect, useState } from "react";
|
||||
import { Table } from "antd";
|
||||
import { Space, Table, Typography } from "antd";
|
||||
import CloseCircleFilled from "@ant-design/icons/CloseCircleFilled";
|
||||
import InfoCircleFilled from "@ant-design/icons/InfoCircleFilled";
|
||||
|
||||
import type { PluginWebApi, PluginWebpackEnvInfo } from "@clusterio/lib";
|
||||
|
||||
import notify from "../util/notify";
|
||||
import { useAccount } from "../model/account";
|
||||
import ControlContext from "./ControlContext";
|
||||
import { PluginBrowserButton } from "./PluginBrowser";
|
||||
import { usePluginInstaller } from "./PluginInstall";
|
||||
import {
|
||||
PluginUpdateButton, PluginVersions, RestartPendingButton, UpdateAllButton, useLatestVersions, useMachinePlugins,
|
||||
} from "./PluginClusterStatus";
|
||||
import { PluginStatus, computePluginStatuses, pluginStatusKey } from "../util/plugin_status";
|
||||
import PageLayout from "./PageLayout";
|
||||
import PageHeader from "./PageHeader";
|
||||
import useTableQueryState from "../util/useTableQueryState";
|
||||
@@ -17,20 +24,60 @@ import Link from "./Link";
|
||||
const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare;
|
||||
|
||||
type PluginRow = {
|
||||
meta: PluginWebApi;
|
||||
key: string;
|
||||
title: string;
|
||||
/** Not present for plugins the controller hasn't loaded */
|
||||
meta?: PluginWebApi;
|
||||
info?: PluginWebpackEnvInfo;
|
||||
package?: any;
|
||||
status?: PluginStatus;
|
||||
};
|
||||
|
||||
/** Plugins the controller hasn't loaded are found by their status key instead of the plugin name */
|
||||
function pluginPath(plugin: PluginRow) {
|
||||
return `/plugins/${encodeURIComponent(plugin.meta?.name ?? plugin.key)}/view`;
|
||||
}
|
||||
|
||||
function WebUiStatus(props: { plugin: PluginRow }) {
|
||||
const control = useContext(ControlContext);
|
||||
const { meta } = props.plugin;
|
||||
if (!meta) {
|
||||
return <Typography.Text type="secondary">Not on controller</Typography.Text>;
|
||||
}
|
||||
if (!meta.enabled) {
|
||||
return <><InfoCircleFilled style={{ color: "#1668dc" }} /> Disabled on controller</>;
|
||||
}
|
||||
if (!meta.web.main && !meta.web.error) {
|
||||
return <Typography.Text type="secondary">No web module</Typography.Text>;
|
||||
}
|
||||
if (!meta.web.error && !control.pluginInfos.has(meta.name)) {
|
||||
return <><InfoCircleFilled style={{ color: "#1668dc" }} /> Reload page to load</>;
|
||||
}
|
||||
if (!props.plugin.package) {
|
||||
return <><CloseCircleFilled style={{ color: "#dc4446" }} /> Error loading module</>;
|
||||
}
|
||||
if (props.plugin.package.version !== meta.version) {
|
||||
return <><CloseCircleFilled style={{ color: "#dc4446" }} /> Version mis-matched</>;
|
||||
}
|
||||
return <>Loaded {meta.version}</>;
|
||||
}
|
||||
|
||||
|
||||
export default function PluginsPage() {
|
||||
const control = useContext(ControlContext);
|
||||
const account = useAccount();
|
||||
let [pluginList, setPluginList] = useState<PluginWebApi[]>([]);
|
||||
const tableState = useTableQueryState<PluginRow>({
|
||||
namespace: "plugin", defaultSortKey: "name",
|
||||
});
|
||||
const nameSearch = useColumnSearch<PluginRow>(
|
||||
tableState, "name", plugin => (plugin.info ? plugin.info.title : plugin.meta.name), "Search plugins"
|
||||
tableState, "name", plugin => plugin.title, "Search plugins"
|
||||
);
|
||||
const { machines, unknown, refresh } = useMachinePlugins();
|
||||
const installer = usePluginInstaller(refresh);
|
||||
const statuses = machines ? computePluginStatuses(machines, unknown) : new Map<string, PluginStatus>();
|
||||
const latestVersions = useLatestVersions(
|
||||
[...statuses.values()].flatMap(status => (status.npmPackage ? [status.npmPackage] : []))
|
||||
);
|
||||
const rowNav = useRowNavigation();
|
||||
|
||||
@@ -47,84 +94,96 @@ export default function PluginsPage() {
|
||||
|
||||
let tableContents: PluginRow[] = [];
|
||||
for (let meta of pluginList) {
|
||||
const info = control.loadedPlugins.get(meta.name);
|
||||
if (info) {
|
||||
tableContents.push({
|
||||
meta, info,
|
||||
package: info.package,
|
||||
});
|
||||
} else {
|
||||
tableContents.push({
|
||||
meta, info: control.pluginInfos.get(meta.name),
|
||||
});
|
||||
const key = pluginStatusKey(meta);
|
||||
const loaded = control.loadedPlugins.get(meta.name);
|
||||
const info = loaded ?? control.pluginInfos.get(meta.name);
|
||||
tableContents.push({
|
||||
key,
|
||||
title: info ? info.title : meta.name,
|
||||
meta,
|
||||
info,
|
||||
package: loaded?.package,
|
||||
status: statuses.get(key),
|
||||
});
|
||||
}
|
||||
// Plugins installed on hosts, or waiting for a restart, that the controller hasn't loaded
|
||||
const listedKeys = new Set(tableContents.map(row => row.key));
|
||||
for (const status of statuses.values()) {
|
||||
if (!listedKeys.has(status.key)) {
|
||||
tableContents.push({ key: status.key, title: status.title, status });
|
||||
}
|
||||
}
|
||||
const latestOf = (plugin: PluginRow) => (
|
||||
plugin.status?.npmPackage ? latestVersions[plugin.status.npmPackage] : undefined
|
||||
);
|
||||
|
||||
return <PageLayout nav={[{ name: "Plugins" }]}>
|
||||
<PageHeader title="Plugins" />
|
||||
<PageHeader
|
||||
title="Plugins"
|
||||
extra={<Space wrap>
|
||||
<RestartPendingButton
|
||||
statuses={[...statuses.values()]} machines={machines ?? []} installer={installer}
|
||||
/>
|
||||
<UpdateAllButton
|
||||
statuses={[...statuses.values()]}
|
||||
titles={new Map(tableContents.map(row => [row.key, row.title]))}
|
||||
latestVersions={latestVersions}
|
||||
installer={installer}
|
||||
/>
|
||||
{account.hasPermission("core.plugin.search")
|
||||
&& <PluginBrowserButton statuses={machines && statuses} installer={installer} />}
|
||||
</Space>}
|
||||
/>
|
||||
<Table
|
||||
columns={[
|
||||
{
|
||||
title: "Name",
|
||||
key: "name",
|
||||
className: "table-link-cell",
|
||||
render: (_, plugin) => <Link
|
||||
to={`/plugins/${plugin.meta.name}/view`}
|
||||
style={{ color: "inherit" }}
|
||||
>
|
||||
{plugin.info ? plugin.info.title : plugin.meta.name}
|
||||
render: (_, plugin) => <Link to={pluginPath(plugin)} style={{ color: "inherit" }}>
|
||||
{plugin.title}
|
||||
</Link>,
|
||||
sorter: (a, b) => strcmp(a.info ? a.info.title : a.meta.name, b.info ? b.info.title : b.meta.name),
|
||||
sorter: (a, b) => strcmp(a.title, b.title),
|
||||
sortOrder: tableState.sortOrder("name"),
|
||||
filteredValue: tableState.filteredValue("name"),
|
||||
...nameSearch,
|
||||
},
|
||||
{
|
||||
title: "Version",
|
||||
key: "version",
|
||||
render: (_, plugin) => {
|
||||
if (!plugin.meta.enabled) {
|
||||
return <><InfoCircleFilled style={{ color: "#1668dc" }} /> Disabled on controller</>;
|
||||
}
|
||||
if (!plugin.meta.web.main && !plugin.meta.web.error) {
|
||||
return plugin.meta.version;
|
||||
}
|
||||
if (!plugin.meta.web.error && !control.pluginInfos.has(plugin.meta.name)) {
|
||||
return <><InfoCircleFilled style={{ color: "#1668dc" }} /> Reload page to load</>;
|
||||
}
|
||||
if (!plugin.package) {
|
||||
return <><CloseCircleFilled style={{ color: "#dc4446" }} /> Error loading module</>;
|
||||
}
|
||||
if (plugin.package.version !== plugin.meta.version) {
|
||||
return <><CloseCircleFilled style={{ color: "#dc4446" }} /> Version mis-matched</>;
|
||||
}
|
||||
return plugin.package.version;
|
||||
},
|
||||
sorter: (a, b) => strcmp(a.meta.version, b.meta.version),
|
||||
sortOrder: tableState.sortOrder("version"),
|
||||
title: "Versions",
|
||||
key: "versions",
|
||||
render: (_, plugin) => (plugin.status
|
||||
? <PluginVersions status={plugin.status} latest={latestOf(plugin)} />
|
||||
: plugin.meta?.version
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "Loaded",
|
||||
key: "loaded",
|
||||
render: (_, plugin) => {
|
||||
if (plugin.package) {
|
||||
return "Yes";
|
||||
}
|
||||
if (!plugin.meta.web.main && !plugin.meta.web.error) {
|
||||
return "No web module";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
sorter: (a, b) => Number(Boolean(a.package)) - Number(Boolean(b.package)),
|
||||
sortOrder: tableState.sortOrder("loaded"),
|
||||
title: "Web UI Status",
|
||||
key: "web",
|
||||
render: (_, plugin) => <WebUiStatus plugin={plugin} />,
|
||||
responsive: ["sm"],
|
||||
},
|
||||
{
|
||||
key: "actions",
|
||||
align: "right",
|
||||
render: (_, plugin) => (plugin.status
|
||||
// Keep clicks on the update action from opening the plugin
|
||||
? <span onClick={event => { event.stopPropagation(); }}>
|
||||
<PluginUpdateButton
|
||||
status={plugin.status}
|
||||
title={plugin.title}
|
||||
latest={latestOf(plugin)}
|
||||
installer={installer}
|
||||
/>
|
||||
</span>
|
||||
: null
|
||||
),
|
||||
},
|
||||
]}
|
||||
dataSource={tableContents}
|
||||
rowKey={plugin => plugin.meta.name}
|
||||
rowKey={plugin => plugin.key}
|
||||
pagination={tableState.pagination}
|
||||
onChange={tableState.onChange}
|
||||
onRow={plugin => rowNav(`/plugins/${plugin.meta.name}/view`)}
|
||||
onRow={plugin => rowNav(pluginPath(plugin))}
|
||||
/>
|
||||
</PageLayout>;
|
||||
}
|
||||
Reference in new issue
Block a user