Files
factorio-clusterio/packages/web_ui/src/components/ControllerConfigTree.tsx
T
Hornwitser 001db4befe Refactor config to JSON data class pattern
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.
2024-01-06 19:53:32 +01:00

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}
/>;
}