mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43: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,15 +1,32 @@
|
||||
import React, { useContext } from "react";
|
||||
import { Alert } from "antd";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
|
||||
import BaseConfigTree from "./BaseConfigTree";
|
||||
import BaseConfigTree, { ConfigInheritance } from "./BaseConfigTree";
|
||||
import ControlContext from "./ControlContext";
|
||||
import Link from "./Link";
|
||||
import { useInstance } from "../model/instance";
|
||||
|
||||
|
||||
type InstanceConfigTreeProps = {
|
||||
id: number;
|
||||
};
|
||||
|
||||
function TemplateNotice(props: { templateId: number }) {
|
||||
const [template] = useInstance(props.templateId);
|
||||
return <Alert
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: 8 }}
|
||||
message={<>
|
||||
Locked values are inherited from the template{" "}
|
||||
<Link to={`/instances/${props.templateId}/view`}>{template?.name ?? props.templateId}</Link>.
|
||||
Unlock a value to override it on this instance.
|
||||
</>}
|
||||
/>;
|
||||
}
|
||||
|
||||
export default function InstanceConfigTree(props: InstanceConfigTreeProps) {
|
||||
let control = useContext(ControlContext);
|
||||
|
||||
@@ -21,10 +38,26 @@ export default function InstanceConfigTree(props: InstanceConfigTreeProps) {
|
||||
await control.send(new lib.InstanceConfigSetRequest(props.id, fields));
|
||||
}
|
||||
|
||||
const inheritance: ConfigInheritance = {
|
||||
canInherit: (config, field) => (
|
||||
(config as lib.InstanceConfig).get("instance.template_id") !== null
|
||||
&& lib.InstanceConfig.isInheritable(field)
|
||||
),
|
||||
isInherited: (config, field, prop) => (config as lib.InstanceConfig).isInherited(field, prop),
|
||||
inherit: async (field, prop) => {
|
||||
await control.send(new lib.InstanceConfigInheritFieldRequest(props.id, field, prop));
|
||||
},
|
||||
notice: (config) => {
|
||||
const templateId = (config as lib.InstanceConfig).get("instance.template_id");
|
||||
return templateId !== null ? <TemplateNotice templateId={templateId} /> : null;
|
||||
},
|
||||
};
|
||||
|
||||
return <BaseConfigTree
|
||||
ConfigClass={lib.InstanceConfig}
|
||||
retrieveConfig={retrieveConfig}
|
||||
setConfig={setConfig}
|
||||
inheritance={inheritance}
|
||||
id={props.id}
|
||||
/>;
|
||||
}
|
||||
Reference in new issue
Block a user