mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat: add dropdown menu for service domains and add download functionality for SSH keys
This commit is contained in:
parent
c6569f70e4
commit
0a826fbf1c
@ -23,8 +23,10 @@ import {
|
|||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuLabel,
|
DropdownMenuLabel,
|
||||||
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
@ -149,14 +151,91 @@ export const ShowProjects = () => {
|
|||||||
href={`/dashboard/project/${project.projectId}`}
|
href={`/dashboard/project/${project.projectId}`}
|
||||||
>
|
>
|
||||||
<Card className="group relative w-full h-full bg-transparent transition-colors hover:bg-border">
|
<Card className="group relative w-full h-full bg-transparent transition-colors hover:bg-border">
|
||||||
<Button
|
{project.applications.length > 0 ||
|
||||||
className="absolute -right-3 -top-3 size-9 translate-y-1 rounded-full p-0 opacity-0 transition-all duration-200 group-hover:translate-y-0 group-hover:opacity-100"
|
project.compose.length > 0 ? (
|
||||||
size="sm"
|
<DropdownMenu>
|
||||||
variant="default"
|
<DropdownMenuTrigger asChild>
|
||||||
>
|
<Button
|
||||||
<ExternalLinkIcon className="size-3.5" />
|
className="absolute -right-3 -top-3 size-9 translate-y-1 rounded-full p-0 opacity-0 transition-all duration-200 group-hover:translate-y-0 group-hover:opacity-100"
|
||||||
</Button>
|
size="sm"
|
||||||
|
variant="default"
|
||||||
|
>
|
||||||
|
<ExternalLinkIcon className="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent
|
||||||
|
className="w-[200px] space-y-2 overflow-y-auto max-h-[400px]"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
{project.applications.length > 0 && (
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuLabel>
|
||||||
|
Applications
|
||||||
|
</DropdownMenuLabel>
|
||||||
|
{project.applications.map((app) => (
|
||||||
|
<div key={app.applicationId}>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuLabel className="font-normal capitalize text-xs">
|
||||||
|
{app.name}
|
||||||
|
</DropdownMenuLabel>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
{app.domains.map((domain) => (
|
||||||
|
<DropdownMenuItem
|
||||||
|
key={domain.domainId}
|
||||||
|
asChild
|
||||||
|
>
|
||||||
|
<Link
|
||||||
|
className="space-x-4 text-xs cursor-pointer justify-between"
|
||||||
|
target="_blank"
|
||||||
|
href={`${domain.https ? "https" : "http"}://${domain.host}${domain.path}`}
|
||||||
|
>
|
||||||
|
<span>{domain.host}</span>
|
||||||
|
<ExternalLinkIcon className="size-4 shrink-0" />
|
||||||
|
</Link>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuGroup>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</DropdownMenuGroup>
|
||||||
|
)}
|
||||||
|
{project.compose.length > 0 && (
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuLabel>
|
||||||
|
Compose
|
||||||
|
</DropdownMenuLabel>
|
||||||
|
{project.compose.map((comp) => (
|
||||||
|
<div key={comp.composeId}>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuLabel className="font-normal capitalize text-xs">
|
||||||
|
{comp.name}
|
||||||
|
</DropdownMenuLabel>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
{comp.domains.map((domain) => (
|
||||||
|
<DropdownMenuItem
|
||||||
|
key={domain.domainId}
|
||||||
|
asChild
|
||||||
|
>
|
||||||
|
<Link
|
||||||
|
className="space-x-4 text-xs cursor-pointer justify-between"
|
||||||
|
target="_blank"
|
||||||
|
href={`${domain.https ? "https" : "http"}://${domain.host}${domain.path}`}
|
||||||
|
>
|
||||||
|
<span>{domain.host}</span>
|
||||||
|
<ExternalLinkIcon className="size-4 shrink-0" />
|
||||||
|
</Link>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuGroup>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</DropdownMenuGroup>
|
||||||
|
)}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
) : null}
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="flex items-center justify-between gap-2">
|
<CardTitle className="flex items-center justify-between gap-2">
|
||||||
<span className="flex flex-col gap-1.5">
|
<span className="flex flex-col gap-1.5">
|
||||||
@ -182,7 +261,10 @@ export const ShowProjects = () => {
|
|||||||
<MoreHorizontalIcon className="size-5" />
|
<MoreHorizontalIcon className="size-5" />
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent className="w-[200px] space-y-2">
|
<DropdownMenuContent
|
||||||
|
className="w-[200px] space-y-2 overflow-y-auto max-h-[280px]"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
<DropdownMenuLabel className="font-normal">
|
<DropdownMenuLabel className="font-normal">
|
||||||
Actions
|
Actions
|
||||||
</DropdownMenuLabel>
|
</DropdownMenuLabel>
|
||||||
|
@ -22,7 +22,7 @@ import { Textarea } from "@/components/ui/textarea";
|
|||||||
import { sshKeyCreate, type sshKeyType } from "@/server/db/validations";
|
import { sshKeyCreate, type sshKeyType } from "@/server/db/validations";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { PenBoxIcon, PlusIcon } from "lucide-react";
|
import { DownloadIcon, PenBoxIcon, PlusIcon } from "lucide-react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
@ -111,6 +111,26 @@ export const HandleSSHKeys = ({ sshKeyId }: Props) => {
|
|||||||
toast.error("Error generating the SSH Key");
|
toast.error("Error generating the SSH Key");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const downloadKey = (
|
||||||
|
content: string,
|
||||||
|
defaultFilename: string,
|
||||||
|
keyType: "private" | "public",
|
||||||
|
) => {
|
||||||
|
const keyName = form.watch("name");
|
||||||
|
const filename = keyName
|
||||||
|
? `${keyName}${sshKeyId ? `_${sshKeyId}` : ""}_${keyType}_${defaultFilename}`
|
||||||
|
: `${keyType}_${defaultFilename}`;
|
||||||
|
const blob = new Blob([content], { type: "text/plain" });
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = url;
|
||||||
|
a.download = filename;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
document.body.removeChild(a);
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||||
<DialogTrigger className="" asChild>
|
<DialogTrigger className="" asChild>
|
||||||
@ -245,7 +265,41 @@ export const HandleSSHKeys = ({ sshKeyId }: Props) => {
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<DialogFooter>
|
<DialogFooter className="flex items-center justify-between">
|
||||||
|
<div className="flex items-center gap-4">
|
||||||
|
{form.watch("privateKey") && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="default"
|
||||||
|
onClick={() =>
|
||||||
|
downloadKey(form.watch("privateKey"), "id_rsa", "private")
|
||||||
|
}
|
||||||
|
className="flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<DownloadIcon className="h-4 w-4" />
|
||||||
|
Private Key
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{form.watch("publicKey") && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="default"
|
||||||
|
onClick={() =>
|
||||||
|
downloadKey(
|
||||||
|
form.watch("publicKey"),
|
||||||
|
"id_rsa.pub",
|
||||||
|
"public",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
className="flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<DownloadIcon className="h-4 w-4" />
|
||||||
|
Public Key
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<Button isLoading={isLoading} type="submit">
|
<Button isLoading={isLoading} type="submit">
|
||||||
{sshKeyId ? "Update" : "Create"}
|
{sshKeyId ? "Update" : "Create"}
|
||||||
</Button>
|
</Button>
|
||||||
|
Loading…
Reference in New Issue
Block a user