From 14dc5e40fecf5b97befc3dc370321ec7ae3e09f7 Mon Sep 17 00:00:00 2001 From: karamvir Date: Tue, 1 Aug 2023 21:14:39 -0700 Subject: [PATCH] init refactor --- frontend/src/components/util.tsx | 5 +- frontend/src/layouts/resource.tsx | 8 +- frontend/src/pages/auth/login.tsx | 86 ++++++++++++---------- frontend/src/resources/dep/index.tsx | 74 +++++++++++++++++++ frontend/src/resources/deployment/card.tsx | 11 +-- frontend/src/resources/ser/index.tsx | 34 +++++++++ frontend/src/router.tsx | 26 ++----- 7 files changed, 170 insertions(+), 74 deletions(-) create mode 100644 frontend/src/resources/dep/index.tsx create mode 100644 frontend/src/resources/ser/index.tsx diff --git a/frontend/src/components/util.tsx b/frontend/src/components/util.tsx index aa75e24e3..495da080d 100644 --- a/frontend/src/components/util.tsx +++ b/frontend/src/components/util.tsx @@ -133,7 +133,10 @@ export const ActionWithDialog = ({ icon={icon} intent={intent} disabled={name !== input} - onClick={onClick} + onClick={() => { + onClick && onClick(); + setOpen(false); + }} /> diff --git a/frontend/src/layouts/resource.tsx b/frontend/src/layouts/resource.tsx index 3ea2d107a..266ea1fd3 100644 --- a/frontend/src/layouts/resource.tsx +++ b/frontend/src/layouts/resource.tsx @@ -1,18 +1,18 @@ import { ReactNode } from "react"; import { Page } from "./page"; -import { Outlet } from "react-router-dom"; interface ResourceProps { title: ReactNode; info: ReactNode; actions: ReactNode; + children: ReactNode; } -export const Resource = ({ title, info, actions }: ResourceProps) => ( +export const Resource = ({ title, info, actions, children }: ResourceProps) => ( {title}} - subtitle={

{info}

} + subtitle={

{info}

} actions={actions} - content={} + content={children} /> ); diff --git a/frontend/src/pages/auth/login.tsx b/frontend/src/pages/auth/login.tsx index 67c947132..5b891e5ce 100644 --- a/frontend/src/pages/auth/login.tsx +++ b/frontend/src/pages/auth/login.tsx @@ -3,49 +3,59 @@ import { Card, CardContent, CardHeader, CardTitle } from "@ui/card"; import { Input } from "@ui/input"; import { Label } from "@ui/label"; import { useLogin } from "@hooks"; -import { useState } from "react"; +import { useEffect, useState } from "react"; export const Login = () => { const { mutate, isLoading } = useLogin(); const [creds, set] = useState({ username: "", password: "" }); + useEffect(() => { + const handler = (e: KeyboardEvent) => e.key === "Enter" && mutate(creds); + addEventListener("keydown", handler); + return () => { + removeEventListener("keydown", handler); + }; + }); + return ( - - - Log In - - -
- - - set((c) => ({ ...c, username: target.value })) - } - /> -
-
- - - set((c) => ({ ...c, password: target.value })) - } - /> -
-
- -
-
-
+
+ + + Log In + + +
+ + + set((c) => ({ ...c, username: target.value })) + } + /> +
+
+ + + set((c) => ({ ...c, password: target.value })) + } + /> +
+
+ +
+
+
+
); }; diff --git a/frontend/src/resources/dep/index.tsx b/frontend/src/resources/dep/index.tsx new file mode 100644 index 000000000..aa75cd301 --- /dev/null +++ b/frontend/src/resources/dep/index.tsx @@ -0,0 +1,74 @@ +import { ResourceUpdates } from "@components/updates/resource"; +import { useRead } from "@hooks"; +import { ResourceCard } from "@layouts/card"; +import { Resource } from "@layouts/resource"; +import { + RedeployContainer, + StartOrStopContainer, + RemoveContainer, +} from "@resources/deployment/components/actions"; +import { DeploymentLogs } from "@resources/deployment/components/deployment-logs"; +import { DeploymentConfig } from "@resources/deployment/config"; +import { + DeploymentBuild, + DeploymentName, + DeploymentServer, + DeploymentStatus, + DeploymentStatusIcon, +} from "@resources/deployment/util"; +import { CardDescription } from "@ui/card"; +import { Link, useParams } from "react-router-dom"; + +export const DeploymentPage = () => { + const id = useParams().deploymentId; + if (!id) return null; + + return ( + } + info={ +
+
+ + +
+ | + + | + +
+ } + actions={ +
+ + + +
+ } + > + + + +
+ ); +}; + +export const DeploymentCard = ({ id }: { id: string }) => { + const deployments = useRead("ListDeployments", {}).data; + const deployment = deployments?.find((d) => d.id === id); + if (!deployment) return null; + return ( + + } + > +
+ + +
+
+ + ); +}; diff --git a/frontend/src/resources/deployment/card.tsx b/frontend/src/resources/deployment/card.tsx index ab0ded7b0..a90fdc894 100644 --- a/frontend/src/resources/deployment/card.tsx +++ b/frontend/src/resources/deployment/card.tsx @@ -17,21 +17,12 @@ export const DeploymentCard = ({ id }: { id: string }) => { title={deployment.name} description={deployment.status ?? "not deployed"} statusIcon={} - // icon={} > -
+
- // } - // icon={} - // > - // - // ); }; diff --git a/frontend/src/resources/ser/index.tsx b/frontend/src/resources/ser/index.tsx new file mode 100644 index 000000000..9531ec4fc --- /dev/null +++ b/frontend/src/resources/ser/index.tsx @@ -0,0 +1,34 @@ +import { ResourceUpdates } from "@components/updates/resource"; +import { Resource } from "@layouts/resource"; +import { ServerConfig } from "@resources/server/config"; +import { ServerStatsPage } from "@resources/server/stats"; +import { + ServerName, + ServerStatusIcon, + ServerStats, +} from "@resources/server/util"; +import { CardDescription } from "@ui/card"; +import { useParams } from "react-router-dom"; + +export const ServerPage = () => { + const id = useParams().serverId; + if (!id) return null; + + return ( + } + info={ +
+ + | + +
+ } + actions={null} + > + + + +
+ ); +}; diff --git a/frontend/src/router.tsx b/frontend/src/router.tsx index d621a9013..d4fe8b7de 100644 --- a/frontend/src/router.tsx +++ b/frontend/src/router.tsx @@ -6,12 +6,11 @@ import { Dashboard } from "@pages/dashboard"; import { Server, ServerContent } from "@resources/server/page"; import { Build } from "@resources/build/page"; import { Deployments, Builds, Servers, Builders } from "@resources/pages"; -import { DeploymentUpdates } from "@resources/deployment/updates"; -import { DeploymentLayout } from "@resources/deployment/layout"; -import { DeploymentPage } from "@resources/deployment/page"; -import { DeploymentConfig } from "@resources/deployment/config"; + import { ServerConfig } from "@resources/server/config"; import { BuildConfig } from "@resources/build/config"; +import { DeploymentPage } from "@resources/dep"; +import { ServerPage } from "@resources/ser"; const router = createBrowserRouter([ { @@ -27,15 +26,7 @@ const router = createBrowserRouter([ path: "deployments", children: [ { path: "", element: }, - { - path: ":deploymentId", - element: , - children: [ - { path: "", element: }, - { path: "updates", element: }, - { path: "config", element: }, - ], - }, + { path: ":deploymentId", element: }, ], }, @@ -44,14 +35,7 @@ const router = createBrowserRouter([ path: "servers", children: [ { path: "", element: }, - { - path: ":serverId", - element: , - children: [ - { path: "", element: }, - { path: "config", element: }, - ], - }, + { path: ":serverId", element: }, ], },