mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 15:24:52 +09:00
51 lines
1.1 KiB
React
51 lines
1.1 KiB
React
import React, { useContext } from "react";
|
|
|
|
import { libConfig, libLink } from "@clusterio/lib";
|
|
|
|
import BaseConfigTree from "./BaseConfigTree";
|
|
import ControlContext from "./ControlContext";
|
|
|
|
|
|
export default function InstanceConfigTree(props) {
|
|
let control = useContext(ControlContext);
|
|
|
|
async function retrieveConfig() {
|
|
let result = await libLink.messages.getInstanceConfig.send(control, {
|
|
instance_id: props.id,
|
|
});
|
|
return result.serialized_config;
|
|
}
|
|
|
|
async function setField(field, value) {
|
|
await libLink.messages.setInstanceConfigField.send(control, {
|
|
instance_id: props.id,
|
|
field,
|
|
value,
|
|
});
|
|
}
|
|
|
|
async function setProp(field, prop, value) {
|
|
let data = {
|
|
instance_id: props.id,
|
|
field,
|
|
prop,
|
|
};
|
|
if (value) {
|
|
try {
|
|
data.value = JSON.parse(value);
|
|
} catch (err) {
|
|
return;
|
|
}
|
|
}
|
|
await libLink.messages.setInstanceConfigProp.send(control, data);
|
|
}
|
|
|
|
return <BaseConfigTree
|
|
ConfigClass={libConfig.InstanceConfig}
|
|
retrieveConfig={retrieveConfig}
|
|
setField={setField}
|
|
setProp={setProp}
|
|
id={props.id}
|
|
/>;
|
|
}
|