mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
Refactor the Config and ConfigGroup classes to match the JSON data class pattern with toJSON, toRemote and fromJSON methods replacing the load, init, and serialize methods. Since fromJSON requires extra information the messages structures passes around the plain JSON representation of the configs instead of serialising instances of the config classes automatically.
41 lines
925 B
TypeScript
41 lines
925 B
TypeScript
import React, { useContext } from "react";
|
|
|
|
import * as lib from "@clusterio/lib";
|
|
|
|
import BaseConfigTree from "./BaseConfigTree";
|
|
import ControlContext from "./ControlContext";
|
|
|
|
|
|
export default function ControllerConfigTree() {
|
|
let control = useContext(ControlContext);
|
|
|
|
async function retrieveConfig() {
|
|
return await control.send(new lib.ControllerConfigGetRequest());
|
|
}
|
|
|
|
async function setField(field: string, value: any) {
|
|
await control.send(new lib.ControllerConfigSetFieldRequest(
|
|
field,
|
|
String(value),
|
|
));
|
|
}
|
|
|
|
async function setProp(field: string, prop: string, value: any) {
|
|
if (value) {
|
|
try {
|
|
value = JSON.parse(value);
|
|
} catch (err) {
|
|
return;
|
|
}
|
|
}
|
|
await control.send(new lib.ControllerConfigSetPropRequest(field, prop, value));
|
|
}
|
|
|
|
return <BaseConfigTree
|
|
ConfigClass={lib.ControllerConfig}
|
|
retrieveConfig={retrieveConfig}
|
|
setField={setField}
|
|
setProp={setProp}
|
|
/>;
|
|
}
|