import { badgeStateColor } from "@/components/dashboard/application/logs/show"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Switch } from "@/components/ui/switch"; import { api } from "@/utils/api"; import { Loader2 } from "lucide-react"; import dynamic from "next/dynamic"; import { useEffect, useState } from "react"; export const DockerLogs = dynamic( () => import("@/components/dashboard/docker/logs/docker-logs-id").then( (e) => e.DockerLogsId, ), { ssr: false, }, ); interface Props { appName: string; serverId?: string; } badgeStateColor; export const ShowDockerLogsStack = ({ appName, serverId }: Props) => { const [option, setOption] = useState<"swarm" | "native">("native"); const [containerId, setContainerId] = useState(); const { data: services, isLoading: servicesLoading } = api.docker.getStackContainersByAppName.useQuery( { appName, serverId, }, { enabled: !!appName && option === "swarm", }, ); const { data: containers, isLoading: containersLoading } = api.docker.getContainersByAppNameMatch.useQuery( { appName, appType: "stack", serverId, }, { enabled: !!appName && option === "native", }, ); useEffect(() => { if (option === "native") { if (containers && containers?.length > 0) { setContainerId(containers[0]?.containerId); } } else { if (services && services?.length > 0) { setContainerId(services[0]?.containerId); } } }, [option, services, containers]); const isLoading = option === "native" ? containersLoading : servicesLoading; const containersLenght = option === "native" ? containers?.length : services?.length; return ( Logs Watch the logs of the application in real time
{option === "native" ? "Native" : "Swarm"} { setOption(checked ? "native" : "swarm"); }} />
); };