"use client"; import { BookIcon, CircuitBoard, GlobeIcon } from "lucide-react"; import { useRouter } from "next/router"; import React from "react"; import { extractServices, type Services, } from "@/components/dashboard/settings/users/add-permissions"; import { MariadbIcon, MongodbIcon, MysqlIcon, PostgresqlIcon, RedisIcon, } from "@/components/icons/data-tools-icons"; import { CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, } from "@/components/ui/command"; import { authClient } from "@/lib/auth-client"; import { api } from "@/utils/api"; import { StatusTooltip } from "../shared/status-tooltip"; // Extended Services type to include environmentId and environmentName for search navigation type SearchServices = Services & { environmentId: string; environmentName: string; }; const extractAllServicesFromProject = (project: any): SearchServices[] => { const allServices: SearchServices[] = []; // Iterate through all environments in the project project.environments?.forEach((environment: any) => { const environmentServices = extractServices(environment); const servicesWithEnvironmentId: SearchServices[] = environmentServices.map( (service) => ({ ...service, environmentId: environment.environmentId, environmentName: environment.name, }), ); allServices.push(...servicesWithEnvironmentId); }); return allServices; }; export const SearchCommand = () => { const router = useRouter(); const [open, setOpen] = React.useState(false); const [search, setSearch] = React.useState(""); const { data: session } = authClient.useSession(); const { data } = api.project.all.useQuery(undefined, { enabled: !!session, }); const { data: isCloud } = api.settings.isCloud.useQuery(); 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); }, []); return (
No projects added yet. Click on Create project. {data?.map((project) => { // Find default environment from accessible environments, or fall back to first accessible environment const defaultEnvironment = project.environments.find( (environment) => environment.isDefault, ) || project?.environments?.[0]; if (!defaultEnvironment) return null; return ( { router.push( `/dashboard/project/${project.projectId}/environment/${defaultEnvironment.environmentId}`, ); setOpen(false); }} > {project.name} / {defaultEnvironment.name} ); })} {data?.map((project) => { const applications: SearchServices[] = extractAllServicesFromProject(project); return applications.map((application) => ( { router.push( `/dashboard/project/${project.projectId}/environment/${application.environmentId}/services/${application.type}/${application.id}`, ); setOpen(false); }} > {application.type === "postgres" && ( )} {application.type === "redis" && ( )} {application.type === "mariadb" && ( )} {application.type === "mongo" && ( )} {application.type === "mysql" && ( )} {application.type === "application" && ( )} {application.type === "compose" && ( )} {project.name} / {application.environmentName} /{" "} {application.name}{" "}
{application.id}
)); })}
); };