mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 15:33:12 +09:00
Rename bases to templates and add per property inheritance
Review changes for #1142: - base becomes template everywhere (is_template, template_id, --template, --is-template, --templates, InstanceDetails.isTemplate). - Object fields inherit per property. inherited_fields lists the overridden properties for object fields and the template object is merged with them. - Linking a template also inherits fields that hold the default value. The server name stays per instance. - Ports are never inherited. - InstanceDetails carries templateId. Web UI: inherited values are locked until unlocked, overridden values can be inherited again, templates are listed separately, the create modal can create templates and instances from templates, and the instance page has "Create template" which can link the source. Part of #200 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
01cf789f5d
commit
b5c372f109
21 files changed
+865
-312
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import React, { useContext, useState } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import {
|
||||
Button, Descriptions, Dropdown, Flex, MenuProps, Modal, Segmented, Space, Tooltip, Typography,
|
||||
Button, Descriptions, Dropdown, Flex, MenuProps, Modal, Segmented, Space, Tag, Tooltip, Typography,
|
||||
message,
|
||||
} from "antd";
|
||||
import CopyOutlined from "@ant-design/icons/CopyOutlined";
|
||||
@@ -26,7 +26,8 @@ import LoadScenarioModal from "./LoadScenarioModal";
|
||||
import SavesList from "./SavesList";
|
||||
import OnlinePlayersList from "./OnlinePlayersList";
|
||||
import { notifyErrorHandler } from "../util/notify";
|
||||
import { useInstance } from "../model/instance";
|
||||
import { useInstance, useInstances } from "../model/instance";
|
||||
import { CreateInstanceButton } from "./InstancesPage";
|
||||
import { useHost } from "../model/host";
|
||||
import InstanceStatusTag from "./InstanceStatusTag";
|
||||
import Link from "./Link";
|
||||
@@ -45,6 +46,28 @@ type InstanceDescriptionProps = {
|
||||
host?: Readonly<lib.HostDetails>;
|
||||
instance: Readonly<lib.InstanceDetails>;
|
||||
};
|
||||
function TemplateDescription(props: { instance: Readonly<lib.InstanceDetails> }) {
|
||||
const [instances] = useInstances();
|
||||
const inheritors = [...instances.values()].filter(i => i.templateId === props.instance.id);
|
||||
return <Descriptions bordered size="small" column={1}>
|
||||
<Descriptions.Item label="Inherited by">
|
||||
{inheritors.length
|
||||
? <Space wrap>
|
||||
{inheritors.map(i => <Link key={i.id} to={`/instances/${i.id}/view`}>{i.name}</Link>)}
|
||||
</Space>
|
||||
: <em>No instances</em>}
|
||||
</Descriptions.Item>
|
||||
{props.instance.templateId !== undefined && <Descriptions.Item label="Template">
|
||||
<TemplateLink id={props.instance.templateId} />
|
||||
</Descriptions.Item>}
|
||||
</Descriptions>;
|
||||
}
|
||||
|
||||
function TemplateLink(props: { id: number }) {
|
||||
const [template] = useInstance(props.id);
|
||||
return <Link to={`/instances/${props.id}/view`}>{template?.name ?? props.id}</Link>;
|
||||
}
|
||||
|
||||
function InstanceDescription(props: InstanceDescriptionProps) {
|
||||
let account = useAccount();
|
||||
|
||||
@@ -97,6 +120,9 @@ function InstanceDescription(props: InstanceDescriptionProps) {
|
||||
<Descriptions.Item label="Last Start Time">
|
||||
<MetricRelativeDate timeMs={instance.startedAtMs}/>
|
||||
</Descriptions.Item>
|
||||
{instance.templateId !== undefined && <Descriptions.Item label="Template">
|
||||
<TemplateLink id={instance.templateId} />
|
||||
</Descriptions.Item>}
|
||||
</Descriptions>;
|
||||
}
|
||||
|
||||
@@ -108,6 +134,8 @@ function InstanceButtons(props: { instance: lib.InstanceDetails }) {
|
||||
let instance = props.instance;
|
||||
let instanceId = instance.id!;
|
||||
let [host] = useHost(instance.assignedHost);
|
||||
const [instances] = useInstances();
|
||||
const canCreate = account.hasPermission("core.instance.create");
|
||||
|
||||
let instanceButtonMenuItems: MenuItem[] = [];
|
||||
if (account.hasPermission("core.instance.export_data")) {
|
||||
@@ -136,6 +164,21 @@ function InstanceButtons(props: { instance: lib.InstanceDetails }) {
|
||||
label: "Delete",
|
||||
});
|
||||
}
|
||||
function confirmDelete() {
|
||||
Modal.confirm({
|
||||
autoFocusButton: "cancel",
|
||||
content: "Permamently delete instance and server saves?",
|
||||
okText: "Delete",
|
||||
okButtonProps: { danger: true },
|
||||
onOk: () => {
|
||||
control.send(
|
||||
new lib.InstanceDeleteRequest(instanceId)
|
||||
).then(() => {
|
||||
navigate("/instances");
|
||||
}).catch(notifyErrorHandler("Error deleting instance"));
|
||||
},
|
||||
});
|
||||
}
|
||||
let instanceButtonsMenuProps: MenuProps = {
|
||||
items: instanceButtonMenuItems,
|
||||
onClick: ({ key }: { key: string }) => {
|
||||
@@ -157,22 +200,25 @@ function InstanceButtons(props: { instance: lib.InstanceDetails }) {
|
||||
).catch(notifyErrorHandler("Error extracting player data"));
|
||||
|
||||
} else if (key === "delete") {
|
||||
Modal.confirm({
|
||||
autoFocusButton: "cancel",
|
||||
content: "Permamently delete instance and server saves?",
|
||||
okText: "Delete",
|
||||
okButtonProps: { danger: true },
|
||||
onOk: () => {
|
||||
control.send(
|
||||
new lib.InstanceDeleteRequest(instanceId)
|
||||
).then(() => {
|
||||
navigate("/instances");
|
||||
}).catch(notifyErrorHandler("Error deleting instance"));
|
||||
},
|
||||
});
|
||||
confirmDelete();
|
||||
}
|
||||
},
|
||||
};
|
||||
if (instance.isTemplate) {
|
||||
return <Space wrap>
|
||||
{canCreate && <CreateInstanceButton
|
||||
instances={instances}
|
||||
initial={{ template: instanceId }}
|
||||
buttonText="Create instance from template"
|
||||
/>}
|
||||
{account.hasPermission("core.instance.delete") && <Button
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={confirmDelete}
|
||||
>Delete</Button>}
|
||||
</Space>;
|
||||
}
|
||||
|
||||
return <Space wrap>
|
||||
{
|
||||
account.hasAnyPermission(...InstanceControlButtonPermissions)
|
||||
@@ -190,6 +236,12 @@ function InstanceButtons(props: { instance: lib.InstanceDetails }) {
|
||||
Connect via Steam
|
||||
</Button>
|
||||
{account.hasPermission("core.instance.load_scenario") && <LoadScenarioModal instance={instance} />}
|
||||
{canCreate && <CreateInstanceButton
|
||||
instances={instances}
|
||||
initial={{ instanceClone: instanceId, asTemplate: true, linkSource: true }}
|
||||
buttonText="Create template"
|
||||
buttonType="default"
|
||||
/>}
|
||||
{account.hasAnyPermission(
|
||||
"core.instance.export_data",
|
||||
"core.instance.extract_players",
|
||||
@@ -224,11 +276,16 @@ export default function InstanceViewPage() {
|
||||
return <PageLayout nav={nav}>
|
||||
<PageHeader
|
||||
title={instance.name ?? ""}
|
||||
status={<InstanceStatusTag status={instance.status} />}
|
||||
status={instance.isTemplate
|
||||
? <Tag color="purple">Template</Tag>
|
||||
: <InstanceStatusTag status={instance.status} />}
|
||||
extra={<InstanceButtons instance={instance} />}
|
||||
/>
|
||||
<InstanceDescription host={host} instance={instance} />
|
||||
{instance.isTemplate
|
||||
? <TemplateDescription instance={instance} />
|
||||
: <InstanceDescription host={host} instance={instance} />}
|
||||
<ResourceNotes resourceType="instance" resourceId={instanceId} />
|
||||
{!instance.isTemplate && <>
|
||||
|
||||
{account.hasPermission("core.user.list") && <OnlinePlayersList instanceId={instanceId} />}
|
||||
|
||||
@@ -275,6 +332,7 @@ export default function InstanceViewPage() {
|
||||
account.hasPermission("core.instance.send_rcon")
|
||||
&& <InstanceRcon id={instanceId} disabled={instance.status !== "running"} />
|
||||
}
|
||||
</>}
|
||||
|
||||
{account.hasPermission("core.instance.get_config") && <InstanceConfigTree id={instanceId} />}
|
||||
|
||||
|
||||
Reference in new issue
Block a user