vinith17 commited on
Commit
cd0f5b1
Β·
1 Parent(s): d2ce69f

feat: display ALL bugs with tabbed navigation

Browse files

FRONTEND CHANGES:
- Display all detected bugs (not just primary_bug)
- Tab-style navigation with prev/next buttons (← Bug N/M β†’)
- Bug counter shows current position (e.g., 'Bug 3/12')
- Summary grid for quick navigation between bugs
- Click any bug in summary to jump directly to it
- Visual indicator highlights current bug in grid
- Each bug shows: category, severity dots, line hint, comment, fix

NEW CSS STYLES:
- .bug-header: Navigation controls layout
- .bug-nav: Prev/next button group
- .bug-nav-btn: Styled navigation buttons (disabled state)
- .bug-summary-grid: Grid of mini cards for all bugs
- .bug-mini-card: Clickable bug preview with category/severity

NEW JAVASCRIPT:
- allBugs: Store all detected bugs in memory
- currentBugIndex: Track which bug we're viewing
- prevBug(): Navigate to previous bug
- nextBug(): Navigate to next bug
- displayBug(bug): Render single bug details
- updateBugNav(): Update button states and counter
- renderResult(): Enhanced to handle multiple bugs with state

BEHAVIOR:
- If multiple bugs found: Show summary grid + navigation controls
- If single bug: Hide summary grid, keep simple view
- Click bugs in grid for instant navigation
- Prev/next buttons disabled at boundaries
- Counter shows progress (e.g., 'Bug 1/5', 'Bug 5/5')
- All properties preserved: severity dots, comment, fix, line hint

Files changed (1) hide show
  1. templates/index.html +137 -40
templates/index.html CHANGED
@@ -260,6 +260,37 @@ textarea#codeInput {
260
  .r-card { display: none; }
261
  .r-card.on { display: block; }
262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
  .r-badge {
264
  display: inline-flex; align-items: center; gap: 6px;
265
  padding: 4px 12px; border-radius: 2px; margin-bottom: 20px;
@@ -545,7 +576,15 @@ def get_user(uid):
545
  <span class="spinner-lbl">Calling Claude API…</span>
546
  </div>
547
  <div class="r-card" id="rCard">
548
- <div id="rBadge" class="r-badge"></div>
 
 
 
 
 
 
 
 
549
  <div class="r-field">
550
  <div class="r-field-label">Category</div>
551
  <div class="r-field-value" id="rCat">β€”</div>
@@ -771,6 +810,64 @@ const revealObs = new IntersectionObserver(entries => {
771
  document.querySelectorAll('.reveal').forEach(el => revealObs.observe(el));
772
 
773
  /* ── REVIEW ─────────────────────────────────────────────── */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
774
  async function doReview() {
775
  const code = document.getElementById('codeInput').value.trim();
776
  const lang = document.getElementById('langSel').value;
@@ -939,52 +1036,52 @@ function mockReview(code, lang) {
939
 
940
  function renderResult(d) {
941
  // Handle both old (single bug) and new (multiple bugs) formats
942
- let action;
943
- let bugsCount = 0;
944
 
945
- if (d.primary_bug) {
946
  // New format: multiple bugs detected
947
- action = d.primary_bug;
948
- bugsCount = d.bugs_found || 0;
949
- } else if (d.bugs && d.bugs.length > 0) {
950
- // Alternative: use first bug from list
951
- action = d.bugs[0];
952
- bugsCount = d.bugs.length;
 
953
  } else {
954
- // Old format: single bug response or ai_action
955
- action = d.ai_action || d;
956
- bugsCount = action.type === 'approve' ? 0 : 1;
957
  }
958
 
959
- const fixString = (d.fix && d.fix.fixed_code) ? d.fix.fixed_code : action.fix;
 
 
960
 
961
- const badgeCls = action.category === 'security' ? 'sec'
962
- : action.category === 'logic' ? 'lgc'
963
- : action.type === 'approve' ? 'apr' : 'sty';
964
- const badge = document.getElementById('rBadge');
965
- badge.className = 'r-badge ' + badgeCls;
966
-
967
- if (action.type === 'approve') {
968
- badge.textContent = 'βœ“ Approved';
969
- } else if (bugsCount > 1) {
970
- badge.textContent = '⚠ ' + bugsCount + ' bugs found';
971
- } else {
972
- badge.textContent = '⚠ ' + (action.category || action.type);
973
- }
974
-
975
- document.getElementById('rCat').textContent = action.category || action.type || 'β€”';
976
- document.getElementById('rLine').textContent = action.line_hint ? 'Line ' + action.line_hint : 'Not specified';
977
- document.getElementById('rComment').textContent = action.comment || 'β€”';
978
- document.getElementById('rFix').textContent = fixString || (action.type === 'approve' ? '(no fix required)' : 'β€”');
979
-
980
- const dotsEl = document.getElementById('rSev');
981
- dotsEl.innerHTML = '';
982
- for (let i = 1; i <= 5; i++) {
983
- const dot = document.createElement('div');
984
- dot.className = 'sd' + (i <= (action.severity || 0) ? ' on' : '');
985
- dotsEl.appendChild(dot);
986
  }
987
-
 
 
 
 
988
  document.getElementById('rTs').textContent = new Date().toLocaleTimeString();
989
  document.getElementById('rCard').classList.add('on');
990
  }
 
260
  .r-card { display: none; }
261
  .r-card.on { display: block; }
262
 
263
+ .bug-header {
264
+ display: flex; justify-content: space-between; align-items: center;
265
+ margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid #262622;
266
+ }
267
+ .bug-counter {
268
+ font-family: var(--mono); font-size: .65rem; letter-spacing: .08em;
269
+ text-transform: uppercase; color: #666;
270
+ }
271
+ .bug-nav {
272
+ display: flex; gap: 8px; align-items: center;
273
+ }
274
+ .bug-nav-btn {
275
+ background: #161614; border: 1px solid #262622; border-radius: 2px;
276
+ color: #999; font-family: var(--mono); font-size: .65rem;
277
+ padding: 6px 12px; cursor: pointer; transition: all .2s;
278
+ }
279
+ .bug-nav-btn:hover:not(:disabled) { background: #262622; border-color: #3a3a38; color: #ccc; }
280
+ .bug-nav-btn:disabled { opacity: .4; cursor: not-allowed; }
281
+ .bug-summary-grid {
282
+ display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
283
+ gap: 8px; margin-bottom: 20px; padding: 12px;
284
+ background: #0a0a08; border: 1px solid #262622; border-radius: 4px;
285
+ }
286
+ .bug-mini-card {
287
+ padding: 10px; border-radius: 2px; cursor: pointer; transition: all .2s;
288
+ border: 1px solid #262622; font-size: .65rem;
289
+ font-family: var(--mono); text-align: center;
290
+ }
291
+ .bug-mini-card:hover { border-color: #3a3a38; background: #161614; }
292
+ .bug-mini-card.current { border-color: #7eb8d4; background: #1a2a3a; }
293
+
294
  .r-badge {
295
  display: inline-flex; align-items: center; gap: 6px;
296
  padding: 4px 12px; border-radius: 2px; margin-bottom: 20px;
 
576
  <span class="spinner-lbl">Calling Claude API…</span>
577
  </div>
578
  <div class="r-card" id="rCard">
579
+ <div class="bug-header">
580
+ <div id="rBadge" class="r-badge"></div>
581
+ <div class="bug-nav">
582
+ <button class="bug-nav-btn" id="prevBtn" onclick="prevBug()">← Prev</button>
583
+ <span class="bug-counter" id="bugCounter"></span>
584
+ <button class="bug-nav-btn" id="nextBtn" onclick="nextBug()">Next β†’</button>
585
+ </div>
586
+ </div>
587
+ <div id="bugSummary" class="bug-summary-grid" style="display: none;"></div>
588
  <div class="r-field">
589
  <div class="r-field-label">Category</div>
590
  <div class="r-field-value" id="rCat">β€”</div>
 
810
  document.querySelectorAll('.reveal').forEach(el => revealObs.observe(el));
811
 
812
  /* ── REVIEW ─────────────────────────────────────────────── */
813
+ let allBugs = [];
814
+ let currentBugIndex = 0;
815
+
816
+ function prevBug() {
817
+ if (currentBugIndex > 0) {
818
+ currentBugIndex--;
819
+ displayBug(allBugs[currentBugIndex]);
820
+ updateBugNav();
821
+ }
822
+ }
823
+
824
+ function nextBug() {
825
+ if (currentBugIndex < allBugs.length - 1) {
826
+ currentBugIndex++;
827
+ displayBug(allBugs[currentBugIndex]);
828
+ updateBugNav();
829
+ }
830
+ }
831
+
832
+ function updateBugNav() {
833
+ const prevBtn = document.getElementById('prevBtn');
834
+ const nextBtn = document.getElementById('nextBtn');
835
+ const counter = document.getElementById('bugCounter');
836
+
837
+ prevBtn.disabled = currentBugIndex === 0;
838
+ nextBtn.disabled = currentBugIndex >= allBugs.length - 1;
839
+ counter.textContent = `Bug ${currentBugIndex + 1} / ${allBugs.length}`;
840
+ }
841
+
842
+ function displayBug(bug) {
843
+ const badgeCls = bug.category === 'security' ? 'sec'
844
+ : bug.category === 'logic' ? 'lgc'
845
+ : bug.type === 'approve' ? 'apr' : 'sty';
846
+ const badge = document.getElementById('rBadge');
847
+ badge.className = 'r-badge ' + badgeCls;
848
+
849
+ if (bug.type === 'approve') {
850
+ badge.textContent = 'βœ“ Approved';
851
+ } else {
852
+ badge.textContent = '⚠ ' + (bug.category || bug.type);
853
+ }
854
+
855
+ document.getElementById('rCat').textContent = bug.category || bug.type || 'β€”';
856
+ document.getElementById('rLine').textContent = bug.line_hint ? 'Line ' + bug.line_hint : 'Not specified';
857
+ document.getElementById('rComment').textContent = bug.comment || 'β€”';
858
+
859
+ const fixString = (bug.fix && bug.fix.fixed_code) ? bug.fix.fixed_code : bug.fix;
860
+ document.getElementById('rFix').textContent = fixString || (bug.type === 'approve' ? '(no fix required)' : 'β€”');
861
+
862
+ const dotsEl = document.getElementById('rSev');
863
+ dotsEl.innerHTML = '';
864
+ for (let i = 1; i <= 5; i++) {
865
+ const dot = document.createElement('div');
866
+ dot.className = 'sd' + (i <= (bug.severity || 0) ? ' on' : '');
867
+ dotsEl.appendChild(dot);
868
+ }
869
+ }
870
+
871
  async function doReview() {
872
  const code = document.getElementById('codeInput').value.trim();
873
  const lang = document.getElementById('langSel').value;
 
1036
 
1037
  function renderResult(d) {
1038
  // Handle both old (single bug) and new (multiple bugs) formats
1039
+ allBugs = [];
1040
+ currentBugIndex = 0;
1041
 
1042
+ if (d.bugs && d.bugs.length > 0) {
1043
  // New format: multiple bugs detected
1044
+ allBugs = d.bugs;
1045
+ } else if (d.primary_bug) {
1046
+ // Fallback: single primary bug
1047
+ allBugs = [d.primary_bug];
1048
+ } else if (d.ai_action) {
1049
+ // Old format: single bug response
1050
+ allBugs = [d.ai_action];
1051
  } else {
1052
+ // Direct bug object (from mockReview)
1053
+ allBugs = [d];
 
1054
  }
1055
 
1056
+ // Hide summary grid and update main display
1057
+ const summaryGrid = document.getElementById('bugSummary');
1058
+ summaryGrid.style.display = allBugs.length > 1 ? 'grid' : 'none';
1059
 
1060
+ if (allBugs.length > 1) {
1061
+ // Build summary grid for quick navigation
1062
+ summaryGrid.innerHTML = '';
1063
+ allBugs.forEach((bug, idx) => {
1064
+ const miniCard = document.createElement('div');
1065
+ miniCard.className = 'bug-mini-card' + (idx === 0 ? ' current' : '');
1066
+ const sevText = bug.severity ? '●'.repeat(bug.severity) : 'β€”';
1067
+ miniCard.innerHTML = `<div>${bug.category || 'other'}</div><div style="opacity:.6;margin-top:2px;">${sevText}</div>`;
1068
+ miniCard.onclick = () => {
1069
+ currentBugIndex = idx;
1070
+ displayBug(allBugs[idx]);
1071
+ updateBugNav();
1072
+ // Update all mini cards
1073
+ document.querySelectorAll('.bug-mini-card').forEach((c, i) => {
1074
+ c.classList.toggle('current', i === idx);
1075
+ });
1076
+ };
1077
+ summaryGrid.appendChild(miniCard);
1078
+ });
 
 
 
 
 
 
1079
  }
1080
+
1081
+ // Display first bug
1082
+ displayBug(allBugs[0]);
1083
+ updateBugNav();
1084
+
1085
  document.getElementById('rTs').textContent = new Date().toLocaleTimeString();
1086
  document.getElementById('rCard').classList.add('on');
1087
  }