From 3c5293b60b34a71485e4532b83010ee1b8db17c3 Mon Sep 17 00:00:00 2001 From: karamvir Date: Mon, 24 Jul 2023 00:59:17 -0700 Subject: [PATCH] add actions, refactor deployments --- frontend/src/pages/dashboard/index.tsx | 6 +- frontend/src/pages/deployment/index.tsx | 126 ------------------ .../deployment/components/actions.tsx | 92 +++++++++++++ .../deployment/components/deployment-logs.tsx | 0 .../resources/deployment/components/util.tsx | 42 ++++++ frontend/src/resources/deployment/page.tsx | 63 +++++++++ frontend/src/router.tsx | 2 +- frontend/src/ui/card.tsx | 5 +- 8 files changed, 204 insertions(+), 132 deletions(-) delete mode 100644 frontend/src/pages/deployment/index.tsx create mode 100644 frontend/src/resources/deployment/components/actions.tsx rename frontend/src/{pages => resources}/deployment/components/deployment-logs.tsx (100%) create mode 100644 frontend/src/resources/deployment/components/util.tsx create mode 100644 frontend/src/resources/deployment/page.tsx diff --git a/frontend/src/pages/dashboard/index.tsx b/frontend/src/pages/dashboard/index.tsx index 202978500..0cb04b04c 100644 --- a/frontend/src/pages/dashboard/index.tsx +++ b/frontend/src/pages/dashboard/index.tsx @@ -119,7 +119,7 @@ export const DeploymentCard = ({ id }: { id: string }) => { if (!deployment) return null; return ( - + {deployment.name} @@ -138,7 +138,7 @@ export const ServerCard = ({ id }: { id: string }) => { return ( - +
{server.name} @@ -161,7 +161,7 @@ export const BuildCard = ({ id }: { id: string }) => { return ( - +
{build.name} diff --git a/frontend/src/pages/deployment/index.tsx b/frontend/src/pages/deployment/index.tsx deleted file mode 100644 index 1ed9c68f1..000000000 --- a/frontend/src/pages/deployment/index.tsx +++ /dev/null @@ -1,126 +0,0 @@ -// import { DeploymentLogs } from "@pages/resource/deployment/components/logs"; -import { Resource } from "@layouts/resource"; -// import { Updates } from "@components/updates"; -import { useParams } from "react-router-dom"; -import { CardDescription } from "@ui/card"; -// import { DeploymentConfig } from "@pages/resource/deployment/components/config"; -// import { -// RedeployContainer, -// StartOrStopContainer, -// RemoveContainer, -// } from "@pages/resource/deployment/components/actions"; -// import { DeleteDeployment } from "@pages/resource/deployment/components/delete"; -import { useRead, useSetRecentlyViewed } from "@hooks"; -import { Circle } from "lucide-react"; -import { cn } from "@util/helpers"; -import { DeploymentLogs } from "./components/deployment-logs"; -import { Updates } from "@components/updates/updates"; - -export const DeploymentName = ({ - deploymentId, -}: { - deploymentId: string | undefined; -}) => { - const deployments = useRead({ type: "ListDeployments", params: {} }).data; - const deployment = deployments?.find((d) => d.id === deploymentId); - return <>{deployment?.name ?? "..."}; -}; - -export const DeploymentStatus = ({ - deploymentId, -}: { - deploymentId: string | undefined; -}) => { - const deployments = useRead({ type: "ListDeployments", params: {} }).data; - const deployment = deployments?.find((d) => d.id === deploymentId); - return <>{deployments ? deployment?.status ?? "not deployed" : "..."}; -}; - -export const DeploymentStatusIcon = ({ - deploymentId, -}: { - deploymentId: string | undefined; -}) => { - const deployments = useRead({ type: "ListDeployments", params: {} }).data; - const deployment = deployments?.find((d) => d.id === deploymentId); - return ( - - ); -}; - -// export const DeploymentInfo = ({ deploymentId }: { deploymentId: string }) => { -// const deployments = useRead({ type: "ListDeployments", params: {} }).data; -// const deployment = deployments?.find((d) => d.id === deploymentId); - -// return ( -//
-// -// -// -// {data ? deployment?.container?.image ?? "no image" : "..."} -// -// -// -// -// -// -// -// -//
-// ); -// }; - -export const Deployment = () => { - const { deploymentId } = useParams(); - const push = useSetRecentlyViewed(); - - if (!deploymentId) return null; - push("Deployment", deploymentId); - - return ( - } - info={ -
-
deployment info
- {/* */} - | - - - - - | - {/* */} -
- } - actions={ - <> - {/* - - */} - - } - tabs={[ - { - title: "Logs", - component: , - }, - { - title: "Config", - component: <>Config, - }, - { - title: "Updates", - component: <>Updates, - }, - ]} - /> - ); -}; diff --git a/frontend/src/resources/deployment/components/actions.tsx b/frontend/src/resources/deployment/components/actions.tsx new file mode 100644 index 000000000..6c61e9f55 --- /dev/null +++ b/frontend/src/resources/deployment/components/actions.tsx @@ -0,0 +1,92 @@ +import { ActionButton } from "@components/util"; +import { RefreshCw, Play, Trash, Pause } from "lucide-react"; +import { useExecute, useRead } from "@hooks"; +import { DockerContainerState } from "@monitor/client/dist/types"; + +export const RedeployContainer = ({ + deploymentId, +}: { + deploymentId: string; +}) => { + const { mutate, isLoading } = useExecute(); + return ( + } + onClick={() => + mutate({ type: "Deploy", params: { deployment_id: deploymentId } }) + } + disabled={isLoading} + /> + ); +}; + +const StartContainer = ({ deploymentId }: { deploymentId: string }) => { + const { mutate, isLoading } = useExecute(); + + return ( + } + onClick={() => + mutate({ + type: "StartContainer", + params: { deployment_id: deploymentId }, + }) + } + disabled={isLoading} + /> + ); +}; + +const StopContainer = ({ deploymentId }: { deploymentId: string }) => { + const { mutate, isLoading } = useExecute(); + + return ( + } + onClick={() => + mutate({ + type: "StopContainer", + params: { deployment_id: deploymentId }, + }) + } + disabled={isLoading} + /> + ); +}; + +export const StartOrStopContainer = ({ + deploymentId, +}: { + deploymentId: string; +}) => { + const { data } = useRead({ type: "ListDeployments", params: {} }); + const deployment = data?.find((d) => d.id == deploymentId); + if (deployment?.state === DockerContainerState.Running) + return ; + return ; +}; + +export const RemoveContainer = ({ deploymentId }: { deploymentId: string }) => { + const { mutate, isLoading } = useExecute(); + + return ( + } + onClick={() => + mutate({ + type: "RemoveContainer", + params: { deployment_id: deploymentId }, + }) + } + disabled={isLoading} + /> + ); +}; diff --git a/frontend/src/pages/deployment/components/deployment-logs.tsx b/frontend/src/resources/deployment/components/deployment-logs.tsx similarity index 100% rename from frontend/src/pages/deployment/components/deployment-logs.tsx rename to frontend/src/resources/deployment/components/deployment-logs.tsx diff --git a/frontend/src/resources/deployment/components/util.tsx b/frontend/src/resources/deployment/components/util.tsx new file mode 100644 index 000000000..8f91ff494 --- /dev/null +++ b/frontend/src/resources/deployment/components/util.tsx @@ -0,0 +1,42 @@ +import { useRead } from "@hooks"; +import { cn } from "@util/helpers"; +import { Circle } from "lucide-react"; + +export const DeploymentName = ({ + deploymentId, +}: { + deploymentId: string | undefined; +}) => { + const deployments = useRead({ type: "ListDeployments", params: {} }).data; + const deployment = deployments?.find((d) => d.id === deploymentId); + return <>{deployment?.name ?? "..."}; +}; + +export const DeploymentStatus = ({ + deploymentId, +}: { + deploymentId: string | undefined; +}) => { + const deployments = useRead({ type: "ListDeployments", params: {} }).data; + const deployment = deployments?.find((d) => d.id === deploymentId); + return <>{deployments ? deployment?.status ?? "not deployed" : "..."}; +}; + +export const DeploymentStatusIcon = ({ + deploymentId, +}: { + deploymentId: string | undefined; +}) => { + const deployments = useRead({ type: "ListDeployments", params: {} }).data; + const deployment = deployments?.find((d) => d.id === deploymentId); + return ( + + ); +}; diff --git a/frontend/src/resources/deployment/page.tsx b/frontend/src/resources/deployment/page.tsx new file mode 100644 index 000000000..c96aeacb7 --- /dev/null +++ b/frontend/src/resources/deployment/page.tsx @@ -0,0 +1,63 @@ +import { useParams } from "react-router-dom"; +import { useSetRecentlyViewed } from "@hooks"; +import { Resource } from "@layouts/resource"; +import { CardDescription } from "@ui/card"; +import { + DeploymentName, + DeploymentStatus, + DeploymentStatusIcon, +} from "./components/util"; +import { + RedeployContainer, + RemoveContainer, + StartOrStopContainer, +} from "./components/actions"; +import { DeploymentLogs } from "./components/deployment-logs"; + +export const Deployment = () => { + const { deploymentId } = useParams(); + const push = useSetRecentlyViewed(); + + if (!deploymentId) return null; + push("Deployment", deploymentId); + + return ( + } + info={ +
+
deployment info
+ {/* */} + | + + + + + | + {/* */} +
+ } + actions={ + <> + + + + + } + tabs={[ + { + title: "Logs", + component: , + }, + { + title: "Config", + component: <>Config, + }, + { + title: "Updates", + component: <>Updates, + }, + ]} + /> + ); +}; diff --git a/frontend/src/router.tsx b/frontend/src/router.tsx index a76ca8bec..5f6e327c2 100644 --- a/frontend/src/router.tsx +++ b/frontend/src/router.tsx @@ -4,11 +4,11 @@ import { Login } from "@pages/auth/login"; import { Signup } from "@pages/auth/signup"; import { Dashboard } from "@pages/dashboard"; import { Server } from "@pages/server"; -import { Deployment } from "@pages/deployment"; import { Servers } from "@pages/servers"; import { Deployments } from "@pages/deployments"; import { Builds } from "@pages/builds"; import { Build } from "@pages/build"; +import { Deployment } from "@resources/deployment/page"; const router = createBrowserRouter([ { diff --git a/frontend/src/ui/card.tsx b/frontend/src/ui/card.tsx index 2dad69def..04eca13d7 100644 --- a/frontend/src/ui/card.tsx +++ b/frontend/src/ui/card.tsx @@ -3,12 +3,13 @@ import * as React from "react"; const Card = React.forwardRef< HTMLDivElement, - React.HTMLAttributes ->(({ className, ...props }, ref) => ( + React.HTMLAttributes & { hoverable?: boolean } +>(({ className, hoverable, ...props }, ref) => (