Muthukumarank commited on
Commit
3c8eeeb
·
verified ·
1 Parent(s): 59ce6c3

UI 1000x upgrade: frontend/src/pages/AnalyzePage.tsx

Browse files
Files changed (1) hide show
  1. frontend/src/pages/AnalyzePage.tsx +159 -0
frontend/src/pages/AnalyzePage.tsx ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React, { useState } from 'react';
2
+
3
+ const API = import.meta.env.VITE_API_URL || 'http://localhost:8000';
4
+
5
+ export function AnalyzePage() {
6
+ const [code, setCode] = useState('');
7
+ const [result, setResult] = useState<any>(null);
8
+ const [loading, setLoading] = useState(false);
9
+ const [activeView, setActiveView] = useState<'complexity' | 'behaviors' | 'gaps' | 'mutations' | 'security'>('complexity');
10
+
11
+ const analyze = async () => {
12
+ if (!code.trim()) return;
13
+ setLoading(true);
14
+ try {
15
+ const res = await fetch(`${API}/api/v1/generate/multi-agent`, {
16
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
17
+ body: JSON.stringify({ source_code: code, framework: 'pytest', language: 'python', test_types: ['unit'], max_iterations: 0 }),
18
+ });
19
+ if (res.ok) setResult(await res.json());
20
+ } catch {} finally { setLoading(false); }
21
+ };
22
+
23
+ const complexity = result?.analysis?.complexity;
24
+ const gaps = result?.analysis?.gaps;
25
+ const mutations = result?.analysis?.mutations;
26
+ const behaviors = result?.behavior_coverage;
27
+
28
+ return (
29
+ <div className="max-w-[1400px] mx-auto px-6 py-6">
30
+ <div className="mb-6">
31
+ <h1 className="text-xl font-bold">Code Analysis Studio</h1>
32
+ <p className="text-xs text-gray-500 mt-0.5">Deep-dive into complexity, behaviors, gaps, and mutations before generating tests</p>
33
+ </div>
34
+
35
+ <div className="grid lg:grid-cols-[1fr_1.5fr] gap-4">
36
+ {/* Input */}
37
+ <div className="flex flex-col gap-3">
38
+ <textarea value={code} onChange={e => setCode(e.target.value)} placeholder="Paste source code here for deep analysis..."
39
+ className="h-[400px] bg-white/[0.015] border border-white/[0.05] rounded-xl p-4 text-[13px] text-gray-200 placeholder-gray-600 resize-none focus:outline-none focus:border-emerald-500/30 font-mono" />
40
+ <button onClick={analyze} disabled={loading || !code.trim()}
41
+ className="py-2.5 rounded-xl bg-gradient-to-r from-blue-600 to-indigo-600 text-white font-semibold text-sm hover:shadow-lg hover:shadow-blue-500/20 transition disabled:opacity-50">
42
+ {loading ? '🔬 Analyzing...' : '🔬 Run Deep Analysis'}
43
+ </button>
44
+ </div>
45
+
46
+ {/* Results */}
47
+ <div className="bg-white/[0.01] border border-white/[0.04] rounded-xl overflow-hidden">
48
+ {result ? (
49
+ <>
50
+ {/* View Tabs */}
51
+ <div className="flex border-b border-white/[0.04] px-3 py-2 gap-1 overflow-x-auto">
52
+ {[
53
+ { id: 'complexity', label: '🧠 Complexity', count: complexity?.functions?.length },
54
+ { id: 'behaviors', label: '📊 Behaviors', count: behaviors?.total_behaviors },
55
+ { id: 'gaps', label: '🔍 Gaps', count: gaps?.total_gaps },
56
+ { id: 'mutations', label: '🧬 Mutations', count: mutations?.total_mutations },
57
+ ].map(v => (
58
+ <button key={v.id} onClick={() => setActiveView(v.id as any)}
59
+ className={`px-3 py-1.5 rounded-lg text-[11px] font-medium transition whitespace-nowrap ${
60
+ activeView === v.id ? 'bg-blue-500/10 text-blue-300 border border-blue-500/20' : 'text-gray-500 hover:text-gray-300'}`}>
61
+ {v.label} {v.count !== undefined && <span className="ml-1 text-gray-600">({v.count})</span>}
62
+ </button>
63
+ ))}
64
+ </div>
65
+
66
+ <div className="p-4 overflow-auto max-h-[500px]">
67
+ {/* Complexity View */}
68
+ {activeView === 'complexity' && complexity && (
69
+ <div className="space-y-3">
70
+ <div className="flex items-center gap-3 mb-4">
71
+ <div className={`w-12 h-12 rounded-xl flex items-center justify-center text-lg font-bold ${
72
+ complexity.grade === 'A' ? 'bg-emerald-500/20 text-emerald-300' : complexity.grade === 'B' ? 'bg-blue-500/20 text-blue-300' : 'bg-amber-500/20 text-amber-300'}`}>
73
+ {complexity.grade}
74
+ </div>
75
+ <div>
76
+ <div className="text-sm font-semibold text-white">Complexity Grade: {complexity.grade}</div>
77
+ <div className="text-xs text-gray-500">Average: {complexity.average} | Suggested tests: {complexity.suggested_total_tests}</div>
78
+ </div>
79
+ </div>
80
+ {complexity.functions?.map((f: any, i: number) => (
81
+ <div key={i} className="flex items-center justify-between p-2.5 rounded-lg bg-white/[0.02] border border-white/[0.04]">
82
+ <div>
83
+ <span className="text-xs font-mono text-white">{f.name}()</span>
84
+ <span className="text-[10px] text-gray-500 ml-2">complexity: {f.complexity}</span>
85
+ </div>
86
+ <div className="flex items-center gap-2">
87
+ <span className={`text-[10px] px-2 py-0.5 rounded-full font-medium ${
88
+ f.priority === 'HIGH' ? 'bg-red-500/10 text-red-400' : f.priority === 'MEDIUM' ? 'bg-amber-500/10 text-amber-400' : 'bg-green-500/10 text-green-400'}`}>
89
+ {f.priority}
90
+ </span>
91
+ <span className="text-[10px] text-gray-500">{f.suggested_tests} tests</span>
92
+ </div>
93
+ </div>
94
+ ))}
95
+ </div>
96
+ )}
97
+
98
+ {/* Behaviors View */}
99
+ {activeView === 'behaviors' && behaviors && (
100
+ <div className="space-y-2">
101
+ <div className="flex items-center gap-3 mb-4">
102
+ <div className="flex-1 h-2 rounded-full bg-white/[0.05] overflow-hidden">
103
+ <div className="h-full bg-gradient-to-r from-emerald-500 to-cyan-500" style={{ width: `${behaviors.coverage_pct}%` }} />
104
+ </div>
105
+ <span className="text-sm font-medium text-white">{behaviors.coverage_pct}%</span>
106
+ </div>
107
+ <div className="text-xs text-gray-400 mb-3">{behaviors.covered}/{behaviors.total_behaviors} behaviors covered</div>
108
+ {behaviors.uncovered_behaviors?.map((b: any, i: number) => (
109
+ <div key={i} className="flex items-center gap-2 p-2 rounded-lg bg-red-500/5 border border-red-500/10">
110
+ <span className="text-red-400 text-xs">⚠️</span>
111
+ <span className="text-xs text-gray-300 flex-1">{b.description}</span>
112
+ <span className={`text-[10px] px-1.5 py-0.5 rounded-full ${b.priority === 'critical' ? 'bg-red-500/10 text-red-400' : 'bg-amber-500/10 text-amber-400'}`}>{b.priority}</span>
113
+ </div>
114
+ ))}
115
+ </div>
116
+ )}
117
+
118
+ {/* Gaps View */}
119
+ {activeView === 'gaps' && gaps && (
120
+ <div className="space-y-2">
121
+ <div className="text-xs text-gray-400 mb-3">Coverage estimate: {gaps.coverage_estimate}% | {gaps.high_priority} high-priority gaps</div>
122
+ {gaps.gaps?.map((g: any, i: number) => (
123
+ <div key={i} className="flex items-center gap-2 p-2.5 rounded-lg bg-white/[0.02] border border-white/[0.04]">
124
+ <span className={`w-1.5 h-1.5 rounded-full ${g.priority === 'HIGH' ? 'bg-red-500' : 'bg-amber-500'}`} />
125
+ <span className="text-xs text-gray-300 flex-1 font-mono">{g.desc}</span>
126
+ <span className="text-[10px] px-1.5 py-0.5 rounded bg-white/[0.05] text-gray-500">{g.type}</span>
127
+ </div>
128
+ ))}
129
+ </div>
130
+ )}
131
+
132
+ {/* Mutations View */}
133
+ {activeView === 'mutations' && mutations && (
134
+ <div className="space-y-2">
135
+ <div className="text-xs text-gray-400 mb-3">{mutations.kill_target}</div>
136
+ {mutations.mutations?.slice(0, 15).map((m: any, i: number) => (
137
+ <div key={i} className="flex items-center gap-2 p-2 rounded-lg bg-white/[0.02] border border-white/[0.04]">
138
+ <span className="text-[10px] text-gray-600 font-mono w-8">L{m.line}</span>
139
+ <span className="text-xs text-gray-400 flex-1">{m.mutant}</span>
140
+ <span className="text-[10px] px-1.5 py-0.5 rounded bg-purple-500/10 text-purple-300">{m.type}</span>
141
+ </div>
142
+ ))}
143
+ </div>
144
+ )}
145
+ </div>
146
+ </>
147
+ ) : (
148
+ <div className="flex items-center justify-center h-[500px] text-center px-8">
149
+ <div>
150
+ <div className="text-4xl mb-4 opacity-40">🔬</div>
151
+ <p className="text-sm text-gray-500">Paste code and click "Run Deep Analysis" to see complexity, behaviors, gaps, and mutation points.</p>
152
+ </div>
153
+ </div>
154
+ )}
155
+ </div>
156
+ </div>
157
+ </div>
158
+ );
159
+ }