Merge pull request #3291 from Dokploy/feat/use-cards-in-remote-servers

Feat/use cards in remote servers
This commit is contained in:
Mauricio Siu
2025-12-16 21:14:26 -06:00
committed by GitHub
5 changed files with 366 additions and 242 deletions
@@ -1,3 +1,4 @@
import { Activity } from "lucide-react";
import { useState } from "react"; import { useState } from "react";
import { import {
Dialog, Dialog,
@@ -6,6 +7,7 @@ import {
DialogTitle, DialogTitle,
DialogTrigger, DialogTrigger,
} from "@/components/ui/dialog"; } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu"; import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { ShowStorageActions } from "./show-storage-actions"; import { ShowStorageActions } from "./show-storage-actions";
import { ShowTraefikActions } from "./show-traefik-actions"; import { ShowTraefikActions } from "./show-traefik-actions";
@@ -13,20 +15,30 @@ import { ToggleDockerCleanup } from "./toggle-docker-cleanup";
interface Props { interface Props {
serverId: string; serverId: string;
asButton?: boolean;
} }
export const ShowServerActions = ({ serverId }: Props) => { export const ShowServerActions = ({ serverId, asButton = false }: Props) => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
return ( return (
<Dialog open={isOpen} onOpenChange={setIsOpen}> <Dialog open={isOpen} onOpenChange={setIsOpen}>
{asButton ? (
<DialogTrigger asChild> <DialogTrigger asChild>
<Button variant="outline" size="icon" className="h-9 w-9">
<Activity className="h-4 w-4" />
</Button>
</DialogTrigger>
) : (
<DropdownMenuItem <DropdownMenuItem
className="w-full cursor-pointer" className="w-full cursor-pointer"
onSelect={(e) => e.preventDefault()} onSelect={(e) => {
e.preventDefault();
setIsOpen(true);
}}
> >
View Actions View Actions
</DropdownMenuItem> </DropdownMenuItem>
</DialogTrigger> )}
<DialogContent className="sm:max-w-xl"> <DialogContent className="sm:max-w-xl">
<div className="flex flex-col gap-1"> <div className="flex flex-col gap-1">
<DialogTitle className="text-xl">Web server settings</DialogTitle> <DialogTitle className="text-xl">Web server settings</DialogTitle>
@@ -1,5 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
import { PlusIcon } from "lucide-react"; import { PlusIcon, Pencil } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { useTranslation } from "next-i18next"; import { useTranslation } from "next-i18next";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
@@ -59,9 +59,10 @@ type Schema = z.infer<typeof Schema>;
interface Props { interface Props {
serverId?: string; serverId?: string;
asButton?: boolean;
} }
export const HandleServers = ({ serverId }: Props) => { export const HandleServers = ({ serverId, asButton = false }: Props) => {
const { t } = useTranslation("settings"); const { t } = useTranslation("settings");
const utils = api.useUtils(); const utils = api.useUtils();
@@ -137,21 +138,32 @@ export const HandleServers = ({ serverId }: Props) => {
return ( return (
<Dialog open={isOpen} onOpenChange={setIsOpen}> <Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild>
{serverId ? ( {serverId ? (
asButton ? (
<DialogTrigger asChild>
<Button variant="outline" size="icon" className="h-9 w-9">
<Pencil className="h-4 w-4" />
</Button>
</DialogTrigger>
) : (
<DropdownMenuItem <DropdownMenuItem
className="w-full cursor-pointer " className="w-full cursor-pointer "
onSelect={(e) => e.preventDefault()} onSelect={(e) => {
e.preventDefault();
setIsOpen(true);
}}
> >
Edit Server Edit Server
</DropdownMenuItem> </DropdownMenuItem>
)
) : ( ) : (
<DialogTrigger asChild>
<Button className="cursor-pointer space-x-3"> <Button className="cursor-pointer space-x-3">
<PlusIcon className="h-4 w-4" /> <PlusIcon className="h-4 w-4" />
Create Server Create Server
</Button> </Button>
)}
</DialogTrigger> </DialogTrigger>
)}
<DialogContent className="sm:max-w-3xl "> <DialogContent className="sm:max-w-3xl ">
<DialogHeader> <DialogHeader>
<DialogTitle>{serverId ? "Edit" : "Create"} Server</DialogTitle> <DialogTitle>{serverId ? "Edit" : "Create"} Server</DialogTitle>
@@ -1,5 +1,5 @@
import copy from "copy-to-clipboard"; import copy from "copy-to-clipboard";
import { CopyIcon, ExternalLinkIcon, ServerIcon } from "lucide-react"; import { CopyIcon, ExternalLinkIcon, ServerIcon, Settings } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { useState } from "react"; import { useState } from "react";
import { toast } from "sonner"; import { toast } from "sonner";
@@ -36,9 +36,10 @@ import { ValidateServer } from "./validate-server";
interface Props { interface Props {
serverId: string; serverId: string;
asButton?: boolean;
} }
export const SetupServer = ({ serverId }: Props) => { export const SetupServer = ({ serverId, asButton = false }: Props) => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const { data: server } = api.server.one.useQuery( const { data: server } = api.server.one.useQuery(
{ {
@@ -81,14 +82,23 @@ export const SetupServer = ({ serverId }: Props) => {
return ( return (
<Dialog open={isOpen} onOpenChange={setIsOpen}> <Dialog open={isOpen} onOpenChange={setIsOpen}>
{asButton ? (
<DialogTrigger asChild> <DialogTrigger asChild>
<Button variant="outline" size="icon" className="h-9 w-9">
<Settings className="h-4 w-4" />
</Button>
</DialogTrigger>
) : (
<DropdownMenuItem <DropdownMenuItem
className="w-full cursor-pointer " className="w-full cursor-pointer "
onSelect={(e) => e.preventDefault()} onSelect={(e) => {
e.preventDefault();
setIsOpen(true);
}}
> >
Setup Server Setup Server
</DropdownMenuItem> </DropdownMenuItem>
</DialogTrigger> )}
<DialogContent className="sm:max-w-4xl "> <DialogContent className="sm:max-w-4xl ">
<DialogHeader> <DialogHeader>
<div className="flex flex-col gap-1.5"> <div className="flex flex-col gap-1.5">
@@ -1,5 +1,18 @@
import { format } from "date-fns"; import { format } from "date-fns";
import { KeyIcon, Loader2, MoreHorizontal, ServerIcon } from "lucide-react"; import {
KeyIcon,
Loader2,
MoreHorizontal,
ServerIcon,
Clock,
User,
Key,
Network,
Terminal,
Settings,
Pencil,
Trash2,
} from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useTranslation } from "next-i18next"; import { useTranslation } from "next-i18next";
@@ -24,14 +37,11 @@ import {
DropdownMenuTrigger, DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"; } from "@/components/ui/dropdown-menu";
import { import {
Table, Tooltip,
TableBody, TooltipContent,
TableCaption, TooltipProvider,
TableCell, TooltipTrigger,
TableHead, } from "@/components/ui/tooltip";
TableHeader,
TableRow,
} from "@/components/ui/table";
import { api } from "@/utils/api"; import { api } from "@/utils/api";
import { ShowNodesModal } from "../cluster/nodes/show-nodes-modal"; import { ShowNodesModal } from "../cluster/nodes/show-nodes-modal";
import { TerminalModal } from "../web-server/terminal-modal"; import { TerminalModal } from "../web-server/terminal-modal";
@@ -59,7 +69,7 @@ export const ShowServers = () => {
return ( return (
<div className="w-full"> <div className="w-full">
{query?.success && isCloud && <WelcomeSuscription />} {query?.success && isCloud && <WelcomeSuscription />}
<Card className="h-full bg-sidebar p-2.5 rounded-xl max-w-5xl mx-auto"> <Card className="h-full p-2.5 rounded-xl max-w-5xl mx-auto">
<div className="rounded-xl bg-background shadow-md "> <div className="rounded-xl bg-background shadow-md ">
<CardHeader className=""> <CardHeader className="">
<CardTitle className="text-xl flex flex-row gap-2"> <CardTitle className="text-xl flex flex-row gap-2">
@@ -115,100 +125,27 @@ export const ShowServers = () => {
</div> </div>
) : ( ) : (
<div className="flex flex-col gap-4 min-h-[25vh]"> <div className="flex flex-col gap-4 min-h-[25vh]">
<Table> <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<TableCaption>
<div className="flex flex-col gap-4">
See all servers
</div>
</TableCaption>
<TableHeader>
<TableRow>
<TableHead className="text-left">Name</TableHead>
{isCloud && (
<TableHead className="text-center">
Status
</TableHead>
)}
<TableHead className="text-center">
Type
</TableHead>
<TableHead className="text-center">
IP Address
</TableHead>
<TableHead className="text-center">
Port
</TableHead>
<TableHead className="text-center">
Username
</TableHead>
<TableHead className="text-center">
SSH Key
</TableHead>
<TableHead className="text-center">
Created
</TableHead>
<TableHead className="text-right">
Actions
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{data?.map((server) => { {data?.map((server) => {
const canDelete = server.totalSum === 0; const canDelete = server.totalSum === 0;
const isActive = server.serverStatus === "active"; const isActive = server.serverStatus === "active";
const isBuildServer = const isBuildServer = server.serverType === "build";
server.serverType === "build";
return ( return (
<TableRow key={server.serverId}> <Card
<TableCell className="text-left"> key={server.serverId}
className="relative hover:shadow-lg transition-shadow flex flex-col bg-transparent"
>
<CardHeader className="pb-3">
<div className="flex items-start justify-between">
<div className="flex items-center gap-2">
<ServerIcon className="size-5 text-muted-foreground" />
<CardTitle className="text-lg">
{server.name} {server.name}
</TableCell> </CardTitle>
{isCloud && ( </div>
<TableHead className="text-center"> {isActive &&
<Badge server.sshKeyId &&
variant={ !isBuildServer && (
server.serverStatus === "active"
? "default"
: "destructive"
}
>
{server.serverStatus}
</Badge>
</TableHead>
)}
<TableCell className="text-center">
<Badge
variant={
isBuildServer ? "secondary" : "default"
}
>
{server.serverType}
</Badge>
</TableCell>
<TableCell className="text-center">
<Badge>{server.ipAddress}</Badge>
</TableCell>
<TableCell className="text-center">
{server.port}
</TableCell>
<TableCell className="text-center">
{server.username}
</TableCell>
<TableCell className="text-right">
<span className="text-sm text-muted-foreground">
{server.sshKeyId ? "Yes" : "No"}
</span>
</TableCell>
<TableCell className="text-right">
<span className="text-sm text-muted-foreground">
{format(
new Date(server.createdAt),
"PPpp",
)}
</span>
</TableCell>
<TableCell className="text-right flex justify-end">
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
<Button <Button
@@ -216,46 +153,213 @@ export const ShowServers = () => {
className="h-8 w-8 p-0" className="h-8 w-8 p-0"
> >
<span className="sr-only"> <span className="sr-only">
Open menu More options
</span> </span>
<MoreHorizontal className="h-4 w-4" /> <MoreHorizontal className="h-4 w-4" />
</Button> </Button>
</DropdownMenuTrigger> </DropdownMenuTrigger>
<DropdownMenuContent align="end"> <DropdownMenuContent align="end">
<DropdownMenuLabel> <DropdownMenuLabel>
Actions Advanced
</DropdownMenuLabel> </DropdownMenuLabel>
<ShowTraefikFileSystemModal
{isActive && ( serverId={server.serverId}
/>
<ShowDockerContainersModal
serverId={server.serverId}
/>
{isCloud && (
<ShowMonitoringModal
url={`http://${server.ipAddress}:${server?.metricsConfig?.server?.port}/metrics`}
token={
server?.metricsConfig?.server
?.token
}
/>
)}
<ShowSwarmOverviewModal
serverId={server.serverId}
/>
<ShowNodesModal
serverId={server.serverId}
/>
<ShowSchedulesModal
serverId={server.serverId}
/>
</DropdownMenuContent>
</DropdownMenu>
)}
</div>
<TooltipProvider>
<div className="flex gap-2 mt-2 flex-wrap">
{isCloud && (
<> <>
{server.sshKeyId && ( {server.serverStatus === "active" ? (
<TerminalModal <Badge variant="default">
serverId={server.serverId} {server.serverStatus}
</Badge>
) : (
<Tooltip delayDuration={0}>
<TooltipTrigger asChild>
<span className="inline-block">
<Badge
variant="destructive"
className="cursor-help"
> >
<span> {server.serverStatus}
{t( </Badge>
"settings.common.enterTerminal",
)}
</span> </span>
</TerminalModal> </TooltipTrigger>
)} <TooltipContent
<SetupServer className="max-w-xs"
serverId={server.serverId} side="bottom"
/> >
<p className="text-sm">
<HandleServers This server is deactivated due
serverId={server.serverId} to lack of payment. Please pay
/> your invoice to reactivate it.
If you think this is an error,
{server.sshKeyId && please contact support.
!isBuildServer && ( </p>
<ShowServerActions </TooltipContent>
serverId={server.serverId} </Tooltip>
/>
)} )}
</> </>
)} )}
<Badge
variant={
isBuildServer
? "secondary"
: "default"
}
>
{server.serverType}
</Badge>
</div>
</TooltipProvider>
</CardHeader>
<CardContent className="space-y-3 flex-1 flex flex-col">
<div className="flex items-center gap-2 text-sm">
<Network className="size-4 text-muted-foreground" />
<span className="text-muted-foreground">
IP:
</span>
<Badge variant="outline">
{server.ipAddress}
</Badge>
<span className="text-muted-foreground">
Port:
</span>
<span className="font-medium">
{server.port}
</span>
</div>
<div className="flex items-center gap-2 text-sm">
<User className="size-4 text-muted-foreground" />
<span className="text-muted-foreground">
User:
</span>
<span className="font-medium">
{server.username}
</span>
</div>
<div className="flex items-center gap-2 text-sm">
<Key className="size-4 text-muted-foreground" />
<span className="text-muted-foreground">
SSH Key:
</span>
<span className="font-medium">
{server.sshKeyId ? "Yes" : "No"}
</span>
</div>
<div className="flex items-center gap-2 text-sm pt-2 border-t">
<Clock className="size-4 text-muted-foreground" />
<span className="text-xs text-muted-foreground">
Created{" "}
{format(
new Date(server.createdAt),
"PPp",
)}
</span>
</div>
{/* Compact Actions */}
{isActive && (
<div className="flex items-center gap-2 pt-3 border-t mt-auto">
<TooltipProvider>
{server.sshKeyId && (
<Tooltip>
<TooltipTrigger asChild>
<div>
<TerminalModal
serverId={server.serverId}
asButton={true}
>
<Button
variant="outline"
size="icon"
className="h-9 w-9"
>
<Terminal className="h-4 w-4" />
</Button>
</TerminalModal>
</div>
</TooltipTrigger>
<TooltipContent>
<p>Terminal</p>
</TooltipContent>
</Tooltip>
)}
<Tooltip>
<TooltipTrigger asChild>
<div>
<SetupServer
serverId={server.serverId}
asButton={true}
/>
</div>
</TooltipTrigger>
<TooltipContent>
<p>Setup Server</p>
</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<div>
<HandleServers
serverId={server.serverId}
asButton={true}
/>
</div>
</TooltipTrigger>
<TooltipContent>
<p>Edit Server</p>
</TooltipContent>
</Tooltip>
{server.sshKeyId && !isBuildServer && (
<Tooltip>
<TooltipTrigger asChild>
<div>
<ShowServerActions
serverId={server.serverId}
asButton={true}
/>
</div>
</TooltipTrigger>
<TooltipContent>
<p>Web Server Actions</p>
</TooltipContent>
</Tooltip>
)}
<div className="flex-1" />
<Tooltip>
<TooltipTrigger asChild>
<div>
<DialogAction <DialogAction
disabled={!canDelete} disabled={!canDelete}
title={ title={
@@ -268,12 +372,14 @@ export const ShowServers = () => {
"This will delete the server and all associated data" "This will delete the server and all associated data"
) : ( ) : (
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
You can not delete this server You can not delete this
because it has active services. server because it has
active services.
<AlertBlock type="warning"> <AlertBlock type="warning">
You have active services You have active services
associated with this server, associated with this
please delete them first. server, please delete
them first.
</AlertBlock> </AlertBlock>
</div> </div>
) )
@@ -293,61 +399,34 @@ export const ShowServers = () => {
}); });
}} }}
> >
<DropdownMenuItem <Button
className="w-full cursor-pointer text-red-500 hover:!text-red-600" variant="ghost"
onSelect={(e) => e.preventDefault()} size="icon"
className={`h-9 w-9 ${canDelete ? "text-destructive hover:text-destructive hover:bg-destructive/10" : "text-muted-foreground hover:bg-muted"}`}
> >
Delete Server <Trash2 className="h-4 w-4" />
</DropdownMenuItem> </Button>
</DialogAction> </DialogAction>
</div>
{isActive && </TooltipTrigger>
server.sshKeyId && <TooltipContent>
!isBuildServer && ( <p>
<> {canDelete
<DropdownMenuSeparator /> ? "Delete Server"
<DropdownMenuLabel> : "Cannot delete - has active services"}
Extra </p>
</DropdownMenuLabel> </TooltipContent>
</Tooltip>
<ShowTraefikFileSystemModal </TooltipProvider>
serverId={server.serverId} </div>
/>
<ShowDockerContainersModal
serverId={server.serverId}
/>
{isCloud && (
<ShowMonitoringModal
url={`http://${server.ipAddress}:${server?.metricsConfig?.server?.port}/metrics`}
token={
server?.metricsConfig
?.server?.token
}
/>
)} )}
</CardContent>
<ShowSwarmOverviewModal </Card>
serverId={server.serverId}
/>
<ShowNodesModal
serverId={server.serverId}
/>
<ShowSchedulesModal
serverId={server.serverId}
/>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
); );
})} })}
</TableBody> </div>
</Table>
<div className="flex flex-row gap-2 flex-wrap w-full justify-end mr-4"> <div className="flex flex-row gap-2 flex-wrap w-full justify-end mt-4">
{data && data?.length > 0 && ( {data && data?.length > 0 && (
<div> <div>
<HandleServers /> <HandleServers />
@@ -24,10 +24,16 @@ const getTerminalKey = () => {
interface Props { interface Props {
children?: React.ReactNode; children?: React.ReactNode;
serverId: string; serverId: string;
asButton?: boolean;
} }
export const TerminalModal = ({ children, serverId }: Props) => { export const TerminalModal = ({
children,
serverId,
asButton = false,
}: Props) => {
const [terminalKey, setTerminalKey] = useState<string>(getTerminalKey()); const [terminalKey, setTerminalKey] = useState<string>(getTerminalKey());
const [isOpen, setIsOpen] = useState(false);
const isLocalServer = serverId === "local"; const isLocalServer = serverId === "local";
const { data } = api.server.one.useQuery( const { data } = api.server.one.useQuery(
@@ -43,15 +49,20 @@ export const TerminalModal = ({ children, serverId }: Props) => {
}; };
return ( return (
<Dialog> <Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild> {asButton ? (
<DialogTrigger asChild>{children}</DialogTrigger>
) : (
<DropdownMenuItem <DropdownMenuItem
className="w-full cursor-pointer space-x-3" className="w-full cursor-pointer space-x-3"
onSelect={(e) => e.preventDefault()} onSelect={(e) => {
e.preventDefault();
setIsOpen(true);
}}
> >
{children} {children}
</DropdownMenuItem> </DropdownMenuItem>
</DialogTrigger> )}
<DialogContent <DialogContent
className="sm:max-w-7xl" className="sm:max-w-7xl"
onEscapeKeyDown={(event) => event.preventDefault()} onEscapeKeyDown={(event) => event.preventDefault()}