diff --git a/packages/master/webpack.config.js b/packages/master/webpack.config.js index 1d80580b..4c45a621 100644 --- a/packages/master/webpack.config.js +++ b/packages/master/webpack.config.js @@ -25,6 +25,8 @@ module.exports = (env = {}) => merge(common(env), { "antd": { singleton: true }, "react": { singleton: true }, "react-dom": { singleton: true }, + "react-router": { singleton: true }, + "react-router-dom": { singleton: true }, }, }), ], diff --git a/packages/web_ui/src/components/BaseConfigTree.jsx b/packages/web_ui/src/components/BaseConfigTree.jsx index e693d9cb..5f78d44d 100644 --- a/packages/web_ui/src/components/BaseConfigTree.jsx +++ b/packages/web_ui/src/components/BaseConfigTree.jsx @@ -3,6 +3,30 @@ import { Button, Card, Checkbox, Form, Input, InputNumber, Space, Spin, Tree, Ty const { Title } = Typography; +function getInitialValues(config, props) { + let initialValues = {}; + for (let [name, GroupClass] of props.ConfigClass.groups) { + let group = config.group(name); + for (let def of GroupClass.definitions.values()) { + if (!group.canAccess(def.name)) { + continue; + } + + let value = group.get(def.name); + let fieldName = `${group.name}.${def.name}`; + + if (def.type === "object") { + for (let prop of Object.keys(value)) { + let propPath = `${group.name}.${def.name}.${prop}`; + initialValues[propPath] = JSON.stringify(value[prop]); + } + } else { + initialValues[fieldName] = value; + } + } + } + return initialValues; +} export default function BaseConfigTree(props) { let [config, setConfig] = useState(null); @@ -16,8 +40,13 @@ export default function BaseConfigTree(props) { let newConfig = new props.ConfigClass("control"); await newConfig.load(serializedConfig); setConfig(newConfig); + return newConfig; } - useEffect(() => { updateConfig(); }, [props.id]); + useEffect(() => { + updateConfig().then(updatedConfig => { + form.setFieldsValue(getInitialValues(updatedConfig, props)); + }); + }, [props.id]); function renderInput(def) { if (def.type === "boolean") { diff --git a/packages/web_ui/src/components/InstanceStatusTag.jsx b/packages/web_ui/src/components/InstanceStatusTag.jsx index cd37ca1b..1f82c6fa 100644 --- a/packages/web_ui/src/components/InstanceStatusTag.jsx +++ b/packages/web_ui/src/components/InstanceStatusTag.jsx @@ -1,7 +1,7 @@ import { Tag } from "antd"; import React from "react"; -const statusColors = { +export const statusColors = { unknown: "#8c8c8c", unassigned: "#eb2f96", stopped: "#cf1322", diff --git a/packages/web_ui/src/components/LogConsole.jsx b/packages/web_ui/src/components/LogConsole.jsx index aa76c7a7..a9fd58d7 100644 --- a/packages/web_ui/src/components/LogConsole.jsx +++ b/packages/web_ui/src/components/LogConsole.jsx @@ -69,6 +69,7 @@ export default function LogConsole(props) { parent.scrollTop = parent.scrollHeight - parent.clientHeight; if (account.hasPermission("core.log.query")) { + setPastLines([{"Loading past entries..."}
]); libLink.messages.queryLog.send(control, { ...logFilter, max_level: null, diff --git a/packages/web_ui/src/index.jsx b/packages/web_ui/src/index.jsx index ae2b6bbc..92c7975b 100644 --- a/packages/web_ui/src/index.jsx +++ b/packages/web_ui/src/index.jsx @@ -5,6 +5,7 @@ export * from "./model/instance.jsx"; export * from "./model/slave.jsx"; export * from "./model/locale.jsx"; export * from "./model/item_metadata.jsx"; +export * from "./model/account.jsx"; export { default as ControlContext } from "./components/ControlContext"; @@ -18,6 +19,9 @@ export { default as LogConsole } from "./components/LogConsole"; export { default as AssignInstanceModal } from "./components/AssignInstanceModal"; export { default as InstanceList } from "./components/InstanceList"; export { default as InstanceRcon } from "./components/InstanceRcon"; +export { default as InstanceStatusTag } from "./components/InstanceStatusTag"; +export { default as StartStopInstanceButton } from "./components/StartStopInstanceButton"; +export { statusColors } from "./components/InstanceStatusTag"; export { default as PageLayout } from "./components/PageLayout"; export { default as SavesList } from "./components/SavesList"; diff --git a/packages/web_ui/src/model/saves.jsx b/packages/web_ui/src/model/saves.jsx index 83bad774..1f2454f4 100644 --- a/packages/web_ui/src/model/saves.jsx +++ b/packages/web_ui/src/model/saves.jsx @@ -14,10 +14,15 @@ export function useSaves(instanceId) { setSaves(result.list); }).catch(err => { logger.error(`Failed to list instance saves: ${err}`); + setSaves([]); }); } useEffect(() => { + if (!Number.isInteger(instanceId)) { + setSaves([]); + return undefined; + } updateSaves(); function updateHandler(data) {