larxius commited on
Commit
2d5e9bf
·
verified ·
1 Parent(s): 6ae8263

Update frontend/src/pages/Dashboard.jsx

Browse files
Files changed (1) hide show
  1. frontend/src/pages/Dashboard.jsx +34 -15
frontend/src/pages/Dashboard.jsx CHANGED
@@ -154,26 +154,40 @@ export const Dashboard = () => {
154
  setRecentScans(historyData.scans || []);
155
  setLastUpdated(new Date());
156
 
157
- const running = (historyData.scans || []).find(
 
158
  s => (s.status === 'scanning' || s.status === 'queued') && s.id !== completedScanIdRef.current
159
  );
160
 
161
- if (running) {
162
- if (!activeScanRef.current || activeScanRef.current.id !== running.id) {
163
- setActiveScan(running);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  setLiveLogs([]);
165
- startLogPolling(running);
 
 
 
 
 
 
 
 
166
  }
167
- } else if (!running && activeScanRef.current && !logPollRef.current) {
168
- setActiveScan(null);
169
- activeScanRef.current = null;
170
- persistActiveScan(null);
171
- stopLogPolling();
172
- } else if (!running && activeScanRef.current && activeScanRef.current.id === completedScanIdRef.current) {
173
- setActiveScan(null);
174
- activeScanRef.current = null;
175
- persistActiveScan(null);
176
- stopLogPolling();
177
  }
178
  } catch (err) {
179
  console.error('[Dashboard] Fetch error:', err);
@@ -362,6 +376,11 @@ export const Dashboard = () => {
362
  <span className="font-label-sm text-label-sm text-slate-400 bg-slate-800 px-sm py-[2px] rounded uppercase">
363
  {activeScan.scan_type} Scan
364
  </span>
 
 
 
 
 
365
  <span className="font-label-sm text-label-sm text-yellow-400 bg-yellow-400/10 border border-yellow-400/20 px-sm py-[2px] rounded uppercase animate-pulse">
366
  ● Running
367
  </span>
 
154
  setRecentScans(historyData.scans || []);
155
  setLastUpdated(new Date());
156
 
157
+ // Filter all currently active or queued scans (excluding completed ones)
158
+ const runningScans = (historyData.scans || []).filter(
159
  s => (s.status === 'scanning' || s.status === 'queued') && s.id !== completedScanIdRef.current
160
  );
161
 
162
+ // Sort by earliest scan creation time
163
+ runningScans.sort((a, b) => new Date(a.started_at || a.created_at || 0) - new Date(b.started_at || b.created_at || 0));
164
+
165
+ if (runningScans.length > 0) {
166
+ // If we are ALREADY tracking an active scan that is still in progress, STICK WITH IT!
167
+ const currentStillRunning = activeScanRef.current
168
+ ? runningScans.find(s => s.id === activeScanRef.current.id)
169
+ : null;
170
+
171
+ if (currentStillRunning) {
172
+ // Keep current active scan without resetting logs or switching
173
+ setActiveScan(currentStillRunning);
174
+ activeScanRef.current = currentStillRunning;
175
+ } else {
176
+ // No active scan tracked currently — pick the earliest scan in queue
177
+ const nextScan = runningScans[0];
178
+ setActiveScan(nextScan);
179
+ activeScanRef.current = nextScan;
180
  setLiveLogs([]);
181
+ startLogPolling(nextScan);
182
+ }
183
+ } else {
184
+ // No active scans remaining
185
+ if (activeScanRef.current) {
186
+ setActiveScan(null);
187
+ activeScanRef.current = null;
188
+ persistActiveScan(null);
189
+ stopLogPolling();
190
  }
 
 
 
 
 
 
 
 
 
 
191
  }
192
  } catch (err) {
193
  console.error('[Dashboard] Fetch error:', err);
 
376
  <span className="font-label-sm text-label-sm text-slate-400 bg-slate-800 px-sm py-[2px] rounded uppercase">
377
  {activeScan.scan_type} Scan
378
  </span>
379
+ {recentScans.filter(s => (s.status === 'scanning' || s.status === 'queued') && s.id !== activeScan.id).length > 0 && (
380
+ <span className="font-label-sm text-label-sm text-sky-400 bg-sky-950/40 border border-sky-800/40 px-sm py-[2px] rounded uppercase">
381
+ +{recentScans.filter(s => (s.status === 'scanning' || s.status === 'queued') && s.id !== activeScan.id).length} Queued Next
382
+ </span>
383
+ )}
384
  <span className="font-label-sm text-label-sm text-yellow-400 bg-yellow-400/10 border border-yellow-400/20 px-sm py-[2px] rounded uppercase animate-pulse">
385
  ● Running
386
  </span>