From 172b3daeabdf85f9d52b6cc43f4cbc4671aeb796 Mon Sep 17 00:00:00 2001 From: karamvir Date: Wed, 9 Aug 2023 21:36:39 -0700 Subject: [PATCH] init some manual configs --- .../src/components/config/manual-config.tsx | 59 +++++++++++++ frontend/src/resources/server/config.tsx | 86 +++++++++++++++++-- frontend/src/resources/server/index.tsx | 4 +- 3 files changed, 139 insertions(+), 10 deletions(-) create mode 100644 frontend/src/components/config/manual-config.tsx diff --git a/frontend/src/components/config/manual-config.tsx b/frontend/src/components/config/manual-config.tsx new file mode 100644 index 000000000..df7e11504 --- /dev/null +++ b/frontend/src/components/config/manual-config.tsx @@ -0,0 +1,59 @@ +import { Button } from "@ui/button"; +import { + Card, + CardHeader, + CardTitle, + CardDescription, + CardContent, +} from "@ui/card"; +import { useState } from "react"; + +interface Layout { + [tab_name: string]: { + components: Array<{ + title: string; + element: React.JSX.Element; + description?: string; + }>; + description?: string; + }; +} + +export const ManualConfig = ({ layout }: { layout: L }) => { + const tab_names = Object.keys(layout); + const [show, setShow] = useState(tab_names[0]); + + return ( +
+
+ {tab_names.map((key) => ( + + ))} +
+ + + {show} + {layout[show].description} + + + {layout[show].components.map((item) => ( +
+
{item.title}
+ {item.element} +
+ ))} +
+
+
+ ); +}; diff --git a/frontend/src/resources/server/config.tsx b/frontend/src/resources/server/config.tsx index 7023fadd2..888dcfd73 100644 --- a/frontend/src/resources/server/config.tsx +++ b/frontend/src/resources/server/config.tsx @@ -1,12 +1,86 @@ import { Configuration } from "@components/config"; +import { ConfirmUpdate } from "@components/config/confirm-update"; +import { ManualConfig } from "@components/config/manual-config"; import { useRead, useWrite } from "@hooks"; import { Section } from "@layouts/page"; import { Types } from "@monitor/client"; import { Button } from "@ui/button"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@ui/card"; +import { Input } from "@ui/input"; import { Settings, Save, History } from "lucide-react"; import { useState } from "react"; import { useParams } from "react-router-dom"; +type ServerUpdate = Partial; + +export const SerCon = ({ id }: { id: string }) => { + const config = useRead("GetServer", { id }).data?.config; + const { mutate, isLoading } = useWrite("UpdateServer"); + const [update, set] = useState({}); + const up = ( + k: K, + v: V + ) => set((p) => ({ ...p, [k]: v })); + + if (!config) return null; + + return ( +
} + actions={ +
+ + +
+ } + > + up("address", e.target.value)} + className="max-w-[400px]" + /> + ), + }, + { + title: "Region", + element: ( + up("region", e.target.value)} + className="max-w-[400px]" + /> + ), + }, + ], + }, + }} + /> +
+ ); +}; + export const ServerConfig = () => { const id = useParams().serverId; const server = useRead("GetServer", { id }).data; @@ -23,13 +97,10 @@ export const ServerConfig = () => { - + mutate({ config: update, id })} + /> } > @@ -50,7 +121,6 @@ export const ServerConfig = () => { "mem_critical", ], }} - // overrides={} /> ); diff --git a/frontend/src/resources/server/index.tsx b/frontend/src/resources/server/index.tsx index 3c060ee86..7c403b749 100644 --- a/frontend/src/resources/server/index.tsx +++ b/frontend/src/resources/server/index.tsx @@ -4,7 +4,7 @@ import { ResourceCard } from "@layouts/card"; import { Resource } from "@layouts/resource"; import { CardDescription } from "@ui/card"; import { useParams, Link } from "react-router-dom"; -import { ServerConfig } from "./config"; +import { SerCon, ServerConfig } from "./config"; import { ServerStats } from "./stats"; import { ServerName, @@ -33,7 +33,7 @@ export const ServerPage = () => { > - + ); };