mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
- Unlinking a field enables Apply on its own and sends the current value. - The link button no longer toggles the checkbox of its label. - Link and disconnect icons for all four states, pending ones highlighted. - instance.is_template is hidden. - ctl create takes --as-template. - Clearer names for the InstanceManager inheritance helpers. Part of #200 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import React, { useContext, useRef } from "react";
|
|
import { Alert } from "antd";
|
|
|
|
import * as lib from "@clusterio/lib";
|
|
|
|
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={<>
|
|
Linked values are inherited from the template{" "}
|
|
<Link to={`/instances/${props.templateId}/view`}>{template?.name ?? props.templateId}</Link>.
|
|
Unlink a value to set your own on this instance.
|
|
</>}
|
|
/>;
|
|
}
|
|
|
|
export default function InstanceConfigTree(props: InstanceConfigTreeProps) {
|
|
let control = useContext(ControlContext);
|
|
const templateConfig = useRef<lib.ConfigSchema>({});
|
|
|
|
async function retrieveConfig() {
|
|
const config = await control.send(new lib.InstanceConfigGetRequest(props.id));
|
|
const templateId = config["instance.template_id"];
|
|
templateConfig.current = typeof templateId === "number"
|
|
? await control.send(new lib.InstanceConfigGetRequest(templateId))
|
|
: {};
|
|
return config;
|
|
}
|
|
|
|
async function setConfig(fields: Record<string, string | Record<string, string>>) {
|
|
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));
|
|
},
|
|
templateValue: (field, prop) => {
|
|
const value = templateConfig.current[field] as any;
|
|
return prop === undefined ? value : value?.[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}
|
|
/>;
|
|
}
|