From cbf0f37a49c165d21f985f280feb8b88aa934b92 Mon Sep 17 00:00:00 2001 From: djknaeckebrot Date: Tue, 10 Dec 2024 13:37:46 +0100 Subject: [PATCH] feat: add search command dialog with projects and services --- .../dashboard/projects/search-command.tsx | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 apps/dokploy/components/dashboard/projects/search-command.tsx diff --git a/apps/dokploy/components/dashboard/projects/search-command.tsx b/apps/dokploy/components/dashboard/projects/search-command.tsx new file mode 100644 index 00000000..4070d785 --- /dev/null +++ b/apps/dokploy/components/dashboard/projects/search-command.tsx @@ -0,0 +1,114 @@ +"use client" + +import React from "react"; +import {Command, CommandEmpty, CommandList, CommandGroup, CommandInput, CommandItem,CommandDialog, CommandSeparator} from "@/components/ui/command"; +import { useRouter } from 'next/router' +import {extractServices, type Services} from "@/pages/dashboard/project/[projectId]"; +import type {findProjectById} from "@dokploy/server/services/project"; +import {BookIcon, CircuitBoard, GlobeIcon} from "lucide-react"; +import { + MariadbIcon, + MongodbIcon, + MysqlIcon, + PostgresqlIcon, + RedisIcon, +} from "@/components/icons/data-tools-icons"; + +// export type Services = { +// name: string; +// type: +// | "mariadb" +// | "application" +// | "postgres" +// | "mysql" +// | "mongo" +// | "redis" +// | "compose"; +// description?: string | null; +// id: string; +// createdAt: string; +// status?: "idle" | "running" | "done" | "error"; +// }; + +type Project = Awaited>; + +interface Props { + data: Project[]; +} + +export const SearchCommand = ({data}: Props) => { + const router = useRouter() + const [open, setOpen] = React.useState(false) + + React.useEffect(() => { + const down = (e: KeyboardEvent) => { + if (e.key === "j" && (e.metaKey || e.ctrlKey)) { + e.preventDefault() + setOpen((open) => !open) + } + } + + document.addEventListener("keydown", down) + return () => document.removeEventListener("keydown", down) + }, []) + + console.log("DEBUG: data: ", data); + + return ( +
+ + + + No projects added yet. Click on Create project. + + + {data?.map((project) => ( + router.push(project.projectId)}> + + {project.name} + + ))} + + + + + + {data?.map((project) => { + const applications: Services[] = extractServices(project); + return ( + applications.map((application) => ( + router.push(`/dashboard/project/${project.projectId}/services/${application.type}/${application.id}`)}> + {application.type === "postgres" && ( + + )} + {application.type === "redis" && ( + + )} + {application.type === "mariadb" && ( + + )} + {application.type === "mongo" && ( + + )} + {application.type === "mysql" && ( + + )} + {application.type === "application" && ( + + )} + {application.type === "compose" && ( + + )} + {application.name} + + )) + ); + })} + + + + +
+ ) +} \ No newline at end of file