import { useKV } from '@/hooks/use-kv' import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs' import { Terminal, MagnifyingGlass } from '@phosphor-icons/react' import { parseDockerLog } from '@/lib/docker-parser' import { DockerError } from '@/types/docker' import { ErrorList } from '@/components/docker-build-debugger/ErrorList' import { LogAnalyzer } from '@/components/docker-build-debugger/LogAnalyzer' import { KnowledgeBaseView } from '@/components/docker-build-debugger/KnowledgeBaseView' import { toast } from 'sonner' import dockerBuildDebuggerText from '@/data/docker-build-debugger.json' import { useState } from 'react' export function DockerBuildDebugger() { const [logInput, setLogInput] = useKV('docker-log-input', '') const [parsedErrors, setParsedErrors] = useState([]) const handleParse = () => { if (!logInput.trim()) { toast.error(dockerBuildDebuggerText.analyzer.emptyLogError) return } const errors = parseDockerLog(logInput) if (errors.length === 0) { toast.info(dockerBuildDebuggerText.analyzer.noErrorsToast) } else { setParsedErrors(errors) toast.success( dockerBuildDebuggerText.analyzer.errorsFoundToast .replace('{{count}}', String(errors.length)) .replace('{{plural}}', errors.length > 1 ? 's' : '') ) } } const handleCopy = (text: string, label: string) => { navigator.clipboard.writeText(text) toast.success(dockerBuildDebuggerText.errors.copiedToast.replace('{{label}}', label)) } return (
{dockerBuildDebuggerText.tabs.analyzer.label} {dockerBuildDebuggerText.tabs.analyzer.shortLabel} {dockerBuildDebuggerText.tabs.knowledge.label} {dockerBuildDebuggerText.tabs.knowledge.shortLabel} { setLogInput('') setParsedErrors([]) }} text={dockerBuildDebuggerText.analyzer} />
) }