From 9ef1e3cd9b52630540bee305a1f929b677a920ae Mon Sep 17 00:00:00 2001 From: karamvir Date: Fri, 11 Aug 2023 01:28:54 -0700 Subject: [PATCH] cleanup build config --- .../src/resources/build/components/config.tsx | 112 +++++++++++ frontend/src/resources/build/config.tsx | 188 ------------------ frontend/src/resources/build/index.tsx | 115 +---------- 3 files changed, 115 insertions(+), 300 deletions(-) create mode 100644 frontend/src/resources/build/components/config.tsx delete mode 100644 frontend/src/resources/build/config.tsx diff --git a/frontend/src/resources/build/components/config.tsx b/frontend/src/resources/build/components/config.tsx new file mode 100644 index 000000000..d908d2653 --- /dev/null +++ b/frontend/src/resources/build/components/config.tsx @@ -0,0 +1,112 @@ +import { ConfigAgain } from "@components/config/again"; +import { ResourceSelector } from "@components/config/util"; +import { useWrite, useRead } from "@hooks"; +import { ConfigLayout } from "@layouts/page"; +import { Types } from "@monitor/client"; +import { Button } from "@ui/button"; +import { Card, CardHeader, CardTitle, CardContent } from "@ui/card"; +import { useState } from "react"; + +const BuildConfigInner = ({ + id, + config, +}: { + id: string; + config: Types.BuildConfig; +}) => { + const [update, set] = useState>({}); + const [show, setShow] = useState("general"); + const { mutate } = useWrite("UpdateBuild"); + + return ( + mutate({ id, config: update })} + onReset={() => set({})} + > +
+
+ {["general", "repo", "docker", "volumes"].map((item) => ( + + ))} +
+ + + {show} + + + {/* General Config */} + {show === "general" && ( + set((p) => ({ ...p, ...u }))} + components={{ + builder_id: (id, set) => ( + set({ builder_id })} + /> + ), + }} + /> + )} + + {/* Networking Config */} + {show === "repo" && ( + set((p) => ({ ...p, ...u }))} + components={{ repo: true, branch: true, github_account: true }} + /> + )} + + {/* Environment Config */} + {show === "docker" && ( + set((p) => ({ ...p, ...u }))} + components={{ + build_path: true, + dockerfile_path: true, + docker_account: true, + // docker_organization, + use_buildx: true, + }} + /> + )} + + {/* Environment Config + {show === "volumes" && ( + set((p) => ({ ...p, ...u }))} + components={{ + volumes: (value, set) => ( + + ), + }} + /> + )} */} + + +
+
+ ); +}; + +export const BuildConfig = ({ id }: { id: string }) => { + const config = useRead("GetBuild", { id }).data?.config; + if (!config) return null; + return ; +}; diff --git a/frontend/src/resources/build/config.tsx b/frontend/src/resources/build/config.tsx deleted file mode 100644 index 0effdb089..000000000 --- a/frontend/src/resources/build/config.tsx +++ /dev/null @@ -1,188 +0,0 @@ -import { useRead } from "@hooks"; -import { Types } from "@monitor/client"; -// import { ServersSelector } from "@resources/deployment/config"; -import { Button } from "@ui/button"; -import { Input } from "@ui/input"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@ui/select"; -import { Trash, PlusCircle } from "lucide-react"; - -const ExtraArgs = ({ - args, - set, -}: { - args: string[] | undefined; - set: (input: Partial) => void; -}) => ( -
- {args?.map((arg, i) => ( -
- { - if (!args) return; - args[i] = e.target.value; - set({ extra_args: [...args] }); - }} - /> - -
- ))} - -
-); - -const EnvVars = ({ - vars, - set, -}: { - vars: Types.EnvironmentVar[] | undefined; - set: (input: Partial) => void; -}) => ( -
- {vars?.map((variable, i) => ( -
- { - vars[i].variable = e.target.value; - set({ build_args: [...vars] }); - }} - /> - = - { - vars[i].value = e.target.value; - set({ build_args: [...vars] }); - }} - /> -
- ))} - -
-); - -export const BuilderSelector = ({ - selected, - onSelect, -}: { - selected: string | undefined; - onSelect: (serverId: string) => void; -}) => { - const builders = useRead("ListBuilders", {}).data; - return ( -
- Builder - -
- ); -}; - -// export const BuildConfig = () => { -// const id = useParams().buildId; -// const build = useRead("GetBuild", { id }).data; -// const [update, set] = useState>({}); -// const { mutate, isLoading } = useWrite("UpdateBuild"); - -// if (!id || !build) return null; - -// return ( -//
} -// actions={ -//
-// -// -//
-// } -// > -// set((update) => ({ ...update, ...input }))} -// layout={{ -// general: ["builder_id"], -// repo: ["repo", "branch", "github_account"], -// docker: [ -// "build_path", -// "dockerfile_path", -// "docker_account", -// "docker_organization", -// "use_buildx", -// ], -// pre_build: ["pre_build"], -// build_args: ["build_args"], -// extra_args: ["extra_args"], -// }} -// overrides={{ -// build_args: (args, set) => , -// extra_args: (args, set) => , -// builder_id: (id, set) => ( -// set({ builder_id })} -// /> -// ), -// }} -// /> -//
-// ); -// }; diff --git a/frontend/src/resources/build/index.tsx b/frontend/src/resources/build/index.tsx index ac720bece..fe32d3069 100644 --- a/frontend/src/resources/build/index.tsx +++ b/frontend/src/resources/build/index.tsx @@ -1,4 +1,4 @@ -import { useAddRecentlyViewed, useWrite } from "@hooks"; +import { useAddRecentlyViewed } from "@hooks"; import { Resource } from "@layouts/resource"; import { BuildName, BuildVersion } from "./util"; import { Link, useParams } from "react-router-dom"; @@ -9,13 +9,7 @@ import { BuildInfo } from "./util"; import { Hammer } from "lucide-react"; import { ResourceCard } from "@layouts/card"; import { ResourceUpdates } from "@components/updates/resource"; -import { Types } from "@monitor/client"; -import { useState } from "react"; -import { ConfigLayout } from "@layouts/page"; -import { Button } from "@ui/button"; -import { Card, CardContent, CardHeader, CardTitle } from "@ui/card"; -import { ConfigAgain } from "@components/config/again"; -import { BuilderSelector } from "./config"; +import { BuildConfig } from "./components/config"; export const BuildCard = ({ id }: { id: string }) => { const builds = useRead("ListBuilds", {}).data; @@ -35,109 +29,6 @@ export const BuildCard = ({ id }: { id: string }) => { ); }; -const BuildConfigInner = ({ - id, - config, -}: { - id: string; - config: Types.BuildConfig; -}) => { - const [update, set] = useState>({}); - const [show, setShow] = useState("general"); - const { mutate } = useWrite("UpdateBuild"); - - return ( - mutate({ id, config: update })} - onReset={() => set({})} - > -
-
- {["general", "repo", "docker", "volumes"].map((item) => ( - - ))} -
- - - {show} - - - {/* General Config */} - {show === "general" && ( - set((p) => ({ ...p, ...u }))} - components={{ - builder_id: (id, set) => ( - set({ builder_id })} - /> - ), - }} - /> - )} - - {/* Networking Config */} - {show === "repo" && ( - set((p) => ({ ...p, ...u }))} - components={{ repo: true, branch: true, github_account: true }} - /> - )} - - {/* Environment Config */} - {show === "docker" && ( - set((p) => ({ ...p, ...u }))} - components={{ - build_path: true, - dockerfile_path: true, - docker_account: true, - // docker_organization, - use_buildx: true, - }} - /> - )} - - {/* Environment Config - {show === "volumes" && ( - set((p) => ({ ...p, ...u }))} - components={{ - volumes: (value, set) => ( - - ), - }} - /> - )} */} - - -
-
- ); -}; - -const BuildConifig = ({ id }: { id: string }) => { - const config = useRead("GetBuild", { id }).data?.config; - if (!config) return null; - return ; -}; - export const BuildPage = () => { const id = useParams().buildId; if (!id) return null; @@ -154,7 +45,7 @@ export const BuildPage = () => { actions={} > - + ); };