Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | 'use client'; import { useState, useEffect } from 'react'; import Link from 'next/link'; import { Icon } from '@/components/ui/icons'; import { IconName } from '@/components/ui/icons/registry'; interface ToolStatus { status: 'idle' | 'running' | 'completed' | 'failed'; lastRun?: string; } interface StatusCardProps { title: string; description: string; href: string; iconName: IconName; status?: ToolStatus; onRun?: () => void; isLoading?: boolean; } function StatusCard({ title, description, href, iconName, status, onRun, isLoading }: StatusCardProps) { const getStatusColor = () => { if (!status || status.status === 'idle') return 'bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-400'; if (status.status === 'running') return 'bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400'; if (status.status === 'completed') return 'bg-green-100 dark:bg-green-900/30 text-green-600 dark:text-green-400'; return 'bg-red-100 dark:bg-red-900/30 text-red-600 dark:text-red-400'; }; const getStatusText = () => { if (!status || status.status === 'idle') return 'Not run'; if (status.status === 'running') return 'Running...'; if (status.status === 'completed') return 'Passed'; return 'Failed'; }; return ( <div className="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6"> <div className="flex items-start justify-between"> <div className="flex items-center gap-4"> <div className="p-3 bg-blue/10 dark:bg-blue/20 rounded-lg text-blue"> <Icon name={iconName} size={24} /> </div> <div> <h3 className="font-semibold text-lg text-dark dark:text-gray-100">{title}</h3> <p className="text-sm text-gray-600 dark:text-gray-400">{description}</p> </div> </div> <span className={`px-2 py-1 rounded text-xs font-medium ${getStatusColor()}`}> {getStatusText()} </span> </div> <div className="mt-4 flex gap-2"> <Link href={href} className="px-4 py-2 bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-md text-sm font-medium hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors" > View Details </Link> {onRun && ( <button onClick={onRun} disabled={isLoading || status?.status === 'running'} className="px-4 py-2 bg-blue text-white rounded-md text-sm font-medium hover:bg-blue/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed" > {status?.status === 'running' ? 'Running...' : 'Run Now'} </button> )} </div> </div> ); } export default function DevToolsDashboard() { const [testStatus, setTestStatus] = useState<ToolStatus>({ status: 'idle' }); const [lintStatus, setLintStatus] = useState<ToolStatus>({ status: 'idle' }); const [tsStatus, setTsStatus] = useState<ToolStatus>({ status: 'idle' }); const [isLoading, setIsLoading] = useState({ tests: false, lint: false, typescript: false}); // Fetch initial status useEffect(() => { const fetchStatus = async () => { try { const [testsRes, lintRes, tsRes] = await Promise.all([ fetch('/api/admin/dev-tools/tests'), fetch('/api/admin/dev-tools/lint'), fetch('/api/admin/dev-tools/typescript'), ]); if (testsRes.ok) { const result = await testsRes.json(); // Handle both new wrapped format and legacy format const data = result.data ?? result; setTestStatus({ status: data.status, lastRun: data.completedAt }); } if (lintRes.ok) { const result = await lintRes.json(); const data = result.data ?? result; setLintStatus({ status: data.status, lastRun: data.completedAt }); } if (tsRes.ok) { const result = await tsRes.json(); const data = result.data ?? result; setTsStatus({ status: data.status, lastRun: data.completedAt }); } } catch { // Ignore errors on initial fetch } }; fetchStatus(); }, []); // Poll for status updates when something is running useEffect(() => { const isRunning = testStatus.status === 'running' || lintStatus.status === 'running' || tsStatus.status === 'running'; if (!isRunning) return; const interval = setInterval(async () => { if (testStatus.status === 'running') { const res = await fetch('/api/admin/dev-tools/tests'); if (res.ok) { const result = await res.json(); const data = result.data ?? result; setTestStatus({ status: data.status, lastRun: data.completedAt }); } } if (lintStatus.status === 'running') { const res = await fetch('/api/admin/dev-tools/lint'); if (res.ok) { const result = await res.json(); const data = result.data ?? result; setLintStatus({ status: data.status, lastRun: data.completedAt }); } } if (tsStatus.status === 'running') { const res = await fetch('/api/admin/dev-tools/typescript'); if (res.ok) { const result = await res.json(); const data = result.data ?? result; setTsStatus({ status: data.status, lastRun: data.completedAt }); } } }, 2000); return () => clearInterval(interval); }, [testStatus.status, lintStatus.status, tsStatus.status]); const runTests = async () => { setIsLoading(prev => ({ ...prev, tests: true })); try { const res = await fetch('/api/admin/dev-tools/tests', { method: 'POST' }); if (res.ok) { setTestStatus({ status: 'running' }); } } finally { setIsLoading(prev => ({ ...prev, tests: false })); } }; const runLint = async () => { setIsLoading(prev => ({ ...prev, lint: true })); try { const res = await fetch('/api/admin/dev-tools/lint', { method: 'POST' }); if (res.ok) { setLintStatus({ status: 'running' }); } } finally { setIsLoading(prev => ({ ...prev, lint: false })); } }; const runTypeScript = async () => { setIsLoading(prev => ({ ...prev, typescript: true })); try { const res = await fetch('/api/admin/dev-tools/typescript', { method: 'POST' }); if (res.ok) { setTsStatus({ status: 'running' }); } } finally { setIsLoading(prev => ({ ...prev, typescript: false })); } }; return ( <div className="max-w-[1170px] mx-auto px-4 sm:px-7.5 xl:px-0"> <div className="mb-8"> <h1 className="text-2xl font-bold text-dark dark:text-gray-100">Developer Tools</h1> <p className="text-gray-600 dark:text-gray-400 mt-1"> Run tests, check code quality, and view project documentation </p> </div> {/* Code Quality Tools */} <div className="mb-8"> <h2 className="text-lg font-semibold text-dark dark:text-gray-100 mb-4">Code Quality</h2> <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> <StatusCard title="Test Runner" description="Run Jest tests and view results" href="/admin/dev-tools/tests" status={testStatus} onRun={runTests} isLoading={isLoading.tests} iconName="check-circle" /> <StatusCard title="Lint Checker" description="Run ESLint and view issues" href="/admin/dev-tools/lint" status={lintStatus} onRun={runLint} isLoading={isLoading.lint} iconName="code" /> <StatusCard title="TypeScript Checker" description="Run type checking and view errors" href="/admin/dev-tools/typescript" status={tsStatus} onRun={runTypeScript} isLoading={isLoading.typescript} iconName="cpu" /> </div> </div> {/* Documentation */} <div> <h2 className="text-lg font-semibold text-dark dark:text-gray-100 mb-4">Documentation</h2> <div className="grid grid-cols-1 md:grid-cols-2 gap-6"> <Link href="/admin/dev-tools/plans" className="block p-6 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 hover:shadow-md hover:border-blue transition-all" > <div className="flex items-center gap-4"> <div className="p-3 bg-purple-100 dark:bg-purple-900/30 rounded-lg text-purple-600 dark:text-purple-400"> <Icon name="clipboard-check" size={24} /> </div> <div> <h3 className="font-semibold text-lg text-dark dark:text-gray-100">Project Plans</h3> <p className="text-sm text-gray-600 dark:text-gray-400">View development plans and roadmaps</p> </div> </div> </Link> <Link href="/admin/dev-tools/guides" className="block p-6 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 hover:shadow-md hover:border-blue transition-all" > <div className="flex items-center gap-4"> <div className="p-3 bg-green-100 dark:bg-green-900/30 rounded-lg text-green-600 dark:text-green-400"> <Icon name="book-open" size={24} /> </div> <div> <h3 className="font-semibold text-lg text-dark dark:text-gray-100">Documentation Guides</h3> <p className="text-sm text-gray-600 dark:text-gray-400">Browse development and integration guides</p> </div> </div> </Link> </div> </div> </div> ); } |