mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 15:14: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.
43 lines
1020 B
TypeScript
43 lines
1020 B
TypeScript
import React, { useContext } from "react";
|
|
|
|
import * as lib from "@clusterio/lib";
|
|
|
|
import BaseConfigTree from "./BaseConfigTree";
|
|
import ControlContext from "./ControlContext";
|
|
|
|
|
|
type InstanceConfigTreeProps = {
|
|
id: number;
|
|
};
|
|
|
|
export default function InstanceConfigTree(props: InstanceConfigTreeProps) {
|
|
let control = useContext(ControlContext);
|
|
|
|
async function retrieveConfig() {
|
|
return await control.send(new lib.InstanceConfigGetRequest(props.id));
|
|
}
|
|
|
|
async function setField(field: string, value: any) {
|
|
await control.send(new lib.InstanceConfigSetFieldRequest(props.id, field, 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.InstanceConfigSetPropRequest(props.id, field, prop, value));
|
|
}
|
|
|
|
return <BaseConfigTree
|
|
ConfigClass={lib.InstanceConfig}
|
|
retrieveConfig={retrieveConfig}
|
|
setField={setField}
|
|
setProp={setProp}
|
|
id={props.id}
|
|
/>;
|
|
}
|