From cdc7827b7ebb1ff414a4d70b78709ed3d31f8c90 Mon Sep 17 00:00:00 2001 From: karamvir Date: Thu, 10 Aug 2023 16:43:39 -0700 Subject: [PATCH] config..... again? --- frontend/src/components/config/again.tsx | 26 ++++++++++++ frontend/src/resources/builder/index.tsx | 54 ++++++++++++++++++++---- 2 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 frontend/src/components/config/again.tsx diff --git a/frontend/src/components/config/again.tsx b/frontend/src/components/config/again.tsx new file mode 100644 index 000000000..be0837c7e --- /dev/null +++ b/frontend/src/components/config/again.tsx @@ -0,0 +1,26 @@ +import { Resource } from "@monitor/client/dist/types"; +import { ReactNode } from "react"; + +const keys = (obj: T) => Object.keys(obj) as Array; + +export const ConfigAgain = ["config"]>({ + config, + update, + components, +}: // set, +{ + config: T; + update: Partial; + components: { + [K in keyof T]: (value: T[K]) => ReactNode; + }; + // set: React.Dispatch>>; +}) => { + return ( + <> + {keys(components).map((key) => ( + <>{components[key](update[key] ?? config[key])} + ))} + + ); +}; diff --git a/frontend/src/resources/builder/index.tsx b/frontend/src/resources/builder/index.tsx index d6c3539df..a742655b3 100644 --- a/frontend/src/resources/builder/index.tsx +++ b/frontend/src/resources/builder/index.tsx @@ -9,6 +9,10 @@ import { useState } from "react"; import { Section } from "@layouts/page"; import { Button } from "@ui/button"; import { ConfirmUpdate } from "@components/config/confirm-update"; +import { ConfigAgain } from "@components/config/again"; +import { AwsBuilderConfig } from "@monitor/client/dist/types"; +import { Input } from "@ui/input"; +import { ServersSelector } from "@resources/deployment/config"; // import { // Select, // SelectContent, @@ -70,22 +74,27 @@ export const BuilderCard = ({ id }: { id: string }) => { const BuilderConfig = ({ id }: { id: string }) => { const builder = useRead("GetBuilder", { id }).data; - const [update, setUpdate] = useState>({}); - const { mutate } = useWrite("UpdateBuilder"); - if (!builder?.config) return null; + // const [type, setT] = useState(builder.config.type); + + const [update, set] = useState< + Partial< + Extract< + Types.BuilderConfig, + { type: typeof builder.config.type } + >["params"] + > + >({}); + const { mutate } = useWrite("UpdateBuilder"); + return (
} actions={
- {
} > + {builder.config.type === "Server" && ( +
, + }} + /> + )} + {builder.config.type === "Aws" && ( + ( + set((u) => ({ ...u, region: e.target.value }))} + /> + ), + ami_id: (id) => ( + set((u) => ({ ...u, ami_id: e.target.value }))} + /> + ), + }} + /> + )} {/*