Show the template value while a link is staged

Part of #200

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-02 11:54:37 +00:00
1 parent cd04995b65
commit 943619a657
2 files changed
+21 -4

No files matched your search

@@ -1,4 +1,4 @@
import React, { useContext } from "react";
import React, { useContext, useRef } from "react";
import { Alert } from "antd";
import * as lib from "@clusterio/lib";
@@ -29,9 +29,15 @@ function TemplateNotice(props: { templateId: number }) {
export default function InstanceConfigTree(props: InstanceConfigTreeProps) {
let control = useContext(ControlContext);
const templateConfig = useRef<lib.ConfigSchema>({});
async function retrieveConfig() {
return await control.send(new lib.InstanceConfigGetRequest(props.id));
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>>) {
@@ -47,6 +53,10 @@ export default function InstanceConfigTree(props: InstanceConfigTreeProps) {
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;