larxius commited on
Commit
e4b71d3
·
verified ·
1 Parent(s): 19db612

Update frontend/src/pages/LogsAndThreats.jsx

Browse files
Files changed (1) hide show
  1. frontend/src/pages/LogsAndThreats.jsx +202 -290
frontend/src/pages/LogsAndThreats.jsx CHANGED
@@ -67,14 +67,15 @@ const LogsAndThreats = () => {
67
  const [auditLogs, setAuditLogs] = useState([]);
68
  const [loading, setLoading] = useState(true);
69
 
70
- // Dedicated Threat Modal State
71
  const [selectedThreat, setSelectedThreat] = useState(null);
 
 
 
 
72
 
73
- // Full Page View Toggles
74
  const [isFullLogsView, setIsFullLogsView] = useState(false);
75
- const [isFullThreatsView, setIsFullThreatsView] = useState(false);
76
-
77
- // Audit Logs State
78
  const [allLogs, setAllLogs] = useState([]);
79
  const [loadingAllLogs, setLoadingAllLogs] = useState(false);
80
  const [searchQuery, setSearchQuery] = useState('');
@@ -85,12 +86,9 @@ const LogsAndThreats = () => {
85
  const [sortLogCol, setSortLogCol] = useState('Timestamp');
86
  const [sortLogDir, setSortLogDir] = useState('desc');
87
 
88
- // Threat Intelligence Dedicated Filters & Pagination State
89
- const [threatSearchQuery, setThreatSearchQuery] = useState('');
90
- const [threatSeverityFilter, setThreatSeverityFilter] = useState('all');
91
- const [threatCategoryFilter, setThreatCategoryFilter] = useState('all');
92
- const [threatCurrentPage, setThreatCurrentPage] = useState(1);
93
- const [threatPageSize, setThreatPageSize] = useState(25);
94
 
95
  const fetchStats = async (isInitial = false) => {
96
  if (isInitial) setLoading(true);
@@ -143,15 +141,11 @@ const LogsAndThreats = () => {
143
  setCurrentPage(1);
144
  }, [searchQuery, actionCategory, dateFilter]);
145
 
146
- useEffect(() => {
147
- setThreatCurrentPage(1);
148
- }, [threatSearchQuery, threatSeverityFilter, threatCategoryFilter]);
149
-
150
  const openFullLogsView = (initialSearch = '') => {
151
  if (initialSearch) {
152
  setSearchQuery(initialSearch);
153
  }
154
- setIsFullThreatsView(false);
155
  setIsFullLogsView(true);
156
  fetchAllAuditLogs();
157
  };
@@ -160,27 +154,12 @@ const LogsAndThreats = () => {
160
  setIsFullLogsView(false);
161
  };
162
 
163
- const openFullThreatsView = () => {
164
- setIsFullLogsView(false);
165
- setIsFullThreatsView(true);
166
- };
167
-
168
- const closeFullThreatsView = () => {
169
- setIsFullThreatsView(false);
170
- };
171
-
172
  const clearLogFilters = () => {
173
  setSearchQuery('');
174
  setActionCategory('all');
175
  setDateFilter('all');
176
  };
177
 
178
- const clearThreatFilters = () => {
179
- setThreatSearchQuery('');
180
- setThreatSeverityFilter('all');
181
- setThreatCategoryFilter('all');
182
- };
183
-
184
  const getThreatDetail = (t) => {
185
  const titleKey = typeof t === 'string' ? t : (t.title || '');
186
  const kb = THREAT_KNOWLEDGE_BASE[titleKey] || {};
@@ -208,33 +187,22 @@ const LogsAndThreats = () => {
208
  return 'bg-blue-500/10 text-blue-500 border-blue-500/30';
209
  };
210
 
211
- // Filtered Threats Calculation
212
- const filteredThreats = trends.map(t => getThreatDetail(t)).filter(t => {
213
- if (threatSearchQuery) {
214
- const q = threatSearchQuery.toLowerCase();
215
- const match = (
216
- t.title.toLowerCase().includes(q) ||
217
- t.category.toLowerCase().includes(q) ||
218
- t.owasp.toLowerCase().includes(q)
219
- );
220
- if (!match) return false;
221
- }
222
- if (threatSeverityFilter !== 'all') {
223
- if (t.severity.toLowerCase() !== threatSeverityFilter.toLowerCase()) return false;
224
- }
225
- if (threatCategoryFilter !== 'all') {
226
- if (t.category.toLowerCase() !== threatCategoryFilter.toLowerCase()) return false;
227
- }
228
- return true;
229
  });
230
 
231
- const totalThreatEntries = filteredThreats.length;
232
- const totalThreatPages = Math.ceil(totalThreatEntries / threatPageSize) || 1;
233
- const validThreatCurrentPage = Math.min(Math.max(1, threatCurrentPage), totalThreatPages);
234
- const startThreatIndex = (validThreatCurrentPage - 1) * threatPageSize;
235
- const endThreatIndex = Math.min(startThreatIndex + threatPageSize, totalThreatEntries);
236
- const paginatedThreats = filteredThreats.slice(startThreatIndex, endThreatIndex);
237
-
238
  // Filtered Audit Logs Calculation
239
  const filteredAllLogs = allLogs.filter(log => {
240
  if (searchQuery) {
@@ -355,216 +323,6 @@ const LogsAndThreats = () => {
355
  );
356
  }
357
 
358
- // Dedicated Full Page Global Threat Intelligence View
359
- if (isFullThreatsView) {
360
- return (
361
- <div className="w-full text-on-surface animate-fade-in">
362
- {/* Full Page Header */}
363
- <div className="flex flex-col md:flex-row md:items-center justify-between mb-lg gap-sm border-b border-outline-variant/60 pb-md">
364
- <div>
365
- <button
366
- onClick={closeFullThreatsView}
367
- className="flex items-center text-primary hover:underline font-bold text-[13px] mb-2 cursor-pointer bg-transparent border-0 p-0"
368
- >
369
- <ArrowLeft className="w-4 h-4 mr-1" />
370
- Back to Summary Dashboard
371
- </button>
372
- <h1 className="text-[26px] font-extrabold font-display tracking-tight text-on-surface flex items-center gap-2">
373
- <span className="material-symbols-outlined text-error text-[28px]">warning</span>
374
- Complete Global Threat Intelligence
375
- <span className="bg-error/10 text-error text-[12px] font-bold px-2.5 py-0.5 rounded-full ml-2">
376
- {totalThreatEntries} Vulnerability Records
377
- </span>
378
- </h1>
379
- <p className="text-on-surface-variant text-[13.5px] mt-1">Full security intelligence breakdown across all target endpoints.</p>
380
- </div>
381
-
382
- <div className="flex items-center gap-2 flex-wrap">
383
- <button
384
- onClick={() => fetchStats(true)}
385
- className="flex items-center gap-1.5 px-3.5 py-2 bg-surface-container border border-outline-variant text-on-surface hover:bg-surface-container-high rounded-lg text-[13px] font-bold transition-colors cursor-pointer"
386
- >
387
- <RefreshCw className={`w-4 h-4 ${loading ? 'animate-spin' : ''}`} />
388
- Refresh Threats
389
- </button>
390
- </div>
391
- </div>
392
-
393
- {/* Filters and Search Bar */}
394
- <div className="mb-md bg-surface-container-lowest border border-outline-variant/70 rounded-xl p-4 flex flex-col md:flex-row items-center justify-between gap-3 shadow-2xs">
395
- <div className="flex flex-wrap items-center gap-3 w-full md:w-auto flex-1">
396
- <div className="relative w-full sm:w-72">
397
- <Search className="w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-on-surface-variant" />
398
- <input
399
- type="text"
400
- placeholder="Search threat title, category, or OWASP..."
401
- value={threatSearchQuery}
402
- onChange={(e) => setThreatSearchQuery(e.target.value)}
403
- className="w-full pl-9 pr-3 py-2 bg-surface border border-outline-variant/60 rounded-lg text-[13px] text-on-surface focus:outline-none focus:border-primary"
404
- />
405
- </div>
406
-
407
- <div className="flex items-center gap-1.5 w-full sm:w-auto">
408
- <span className="text-[11px] font-bold text-on-surface-variant uppercase tracking-wider shrink-0">Severity:</span>
409
- <select
410
- value={threatSeverityFilter}
411
- onChange={(e) => setThreatSeverityFilter(e.target.value)}
412
- className="bg-surface border border-outline-variant/60 text-on-surface text-[13px] font-medium rounded-lg px-3 py-2 focus:outline-none focus:border-primary cursor-pointer w-full sm:w-auto"
413
- >
414
- <option value="all">All Severities</option>
415
- <option value="critical">Critical</option>
416
- <option value="high">High</option>
417
- <option value="medium">Medium</option>
418
- <option value="low">Low</option>
419
- </select>
420
- </div>
421
-
422
- {(threatSearchQuery || threatSeverityFilter !== 'all' || threatCategoryFilter !== 'all') && (
423
- <button
424
- onClick={clearThreatFilters}
425
- className="text-error hover:underline text-[12.5px] font-bold flex items-center gap-1 cursor-pointer bg-transparent border-0 px-1"
426
- >
427
- <span className="material-symbols-outlined text-[16px]">close</span>
428
- Reset Filters
429
- </button>
430
- )}
431
- </div>
432
- </div>
433
-
434
- {/* Threat Data Table */}
435
- <div className="bg-surface-container-lowest border border-outline-variant/70 rounded-xl overflow-hidden shadow-2xs flex flex-col">
436
- {filteredThreats.length === 0 ? (
437
- <div className="text-center py-16 text-on-surface-variant text-[14px]">No threat intelligence records match your search filters.</div>
438
- ) : (
439
- <>
440
- <div className="overflow-x-auto">
441
- <table className="w-full text-left text-[13.5px]">
442
- <thead className="bg-surface-container-high/60 text-on-surface-variant text-[11px] uppercase tracking-wider select-none border-b border-outline-variant/70">
443
- <tr>
444
- <th className="p-3.5 font-bold">#</th>
445
- <th className="p-3.5 font-bold">Vulnerability Title</th>
446
- <th className="p-3.5 font-bold">Severity</th>
447
- <th className="p-3.5 font-bold">CVSS</th>
448
- <th className="p-3.5 font-bold">Category & OWASP</th>
449
- <th className="p-3.5 font-bold text-center">Detections</th>
450
- <th className="p-3.5 font-bold text-right">Actions</th>
451
- </tr>
452
- </thead>
453
- <tbody className="divide-y divide-outline-variant/60">
454
- {paginatedThreats.map((threat, idx) => (
455
- <tr key={idx} className="hover:bg-surface-container-lowest/80 transition-colors">
456
- <td className="p-3.5 font-extrabold text-error text-[12px]">{startThreatIndex + idx + 1}</td>
457
- <td className="p-3.5 font-bold text-on-surface max-w-xs">{threat.title}</td>
458
- <td className="p-3.5">
459
- <span className={`px-2.5 py-0.5 rounded text-[10.5px] font-extrabold uppercase tracking-wider border ${getSeverityBadgeClass(threat.severity)}`}>
460
- {threat.severity}
461
- </span>
462
- </td>
463
- <td className="p-3.5 font-mono font-bold text-primary text-[12.5px]">{threat.cvss}</td>
464
- <td className="p-3.5 text-on-surface-variant text-[12px]">
465
- <div className="font-bold text-on-surface">{threat.category}</div>
466
- <div className="text-[11px] text-primary/90">{threat.owasp}</div>
467
- </td>
468
- <td className="p-3.5 text-center">
469
- <span className="bg-surface-container-high border border-outline-variant/60 px-2.5 py-1 rounded-lg text-[12px] font-bold text-on-surface">
470
- {threat.count} Found
471
- </span>
472
- </td>
473
- <td className="p-3.5 text-right">
474
- <div className="flex items-center justify-end gap-2">
475
- <button
476
- onClick={() => setSelectedThreat(threat)}
477
- className="px-3 py-1.5 bg-primary/10 hover:bg-primary text-primary hover:text-white rounded-lg text-[12px] font-bold flex items-center gap-1 transition-all cursor-pointer border border-primary/30"
478
- >
479
- <Info className="w-3.5 h-3.5" />
480
- View Details
481
- </button>
482
- <button
483
- onClick={() => openFullLogsView(threat.title)}
484
- className="px-3 py-1.5 bg-surface-container hover:bg-surface-container-high text-on-surface rounded-lg text-[12px] font-bold flex items-center gap-1 transition-all cursor-pointer border border-outline-variant"
485
- title="Search audit logs for this threat"
486
- >
487
- <Search className="w-3.5 h-3.5 text-primary" />
488
- Filter Logs
489
- </button>
490
- </div>
491
- </td>
492
- </tr>
493
- ))}
494
- </tbody>
495
- </table>
496
- </div>
497
-
498
- {/* Threat Pagination Controls */}
499
- <div className="p-4 border-t border-outline-variant/60 bg-surface-container-lowest/50 flex flex-col sm:flex-row items-center justify-between gap-3 text-[13px] text-on-surface-variant">
500
- <div className="flex items-center gap-2">
501
- <span>Rows per page:</span>
502
- <select
503
- value={threatPageSize}
504
- onChange={(e) => {
505
- setThreatPageSize(Number(e.target.value));
506
- setThreatCurrentPage(1);
507
- }}
508
- className="bg-surface border border-outline-variant/60 text-on-surface rounded-md px-2 py-1 text-[12px] font-bold focus:outline-none cursor-pointer"
509
- >
510
- <option value={10}>10</option>
511
- <option value={25}>25</option>
512
- <option value={50}>50</option>
513
- <option value={100}>100</option>
514
- </select>
515
- <span className="ml-2 font-medium">
516
- {totalThreatEntries === 0 ? '0' : `${startThreatIndex + 1} - ${endThreatIndex}`} of {totalThreatEntries} threat records
517
- </span>
518
- </div>
519
-
520
- <div className="flex items-center gap-1.5">
521
- <button
522
- onClick={() => setThreatCurrentPage(prev => Math.max(1, prev - 1))}
523
- disabled={validThreatCurrentPage === 1}
524
- className="px-3 py-1.5 rounded-lg border border-outline-variant/60 bg-surface hover:bg-surface-container-high text-on-surface font-bold text-[12px] disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer transition-colors"
525
- >
526
- Previous
527
- </button>
528
-
529
- <div className="flex items-center gap-1 px-1">
530
- {Array.from({ length: totalThreatPages }, (_, i) => i + 1)
531
- .filter(p => p === 1 || p === totalThreatPages || Math.abs(p - validThreatCurrentPage) <= 1)
532
- .map((page, idx, arr) => {
533
- const prev = arr[idx - 1];
534
- return (
535
- <React.Fragment key={page}>
536
- {prev && page - prev > 1 && <span className="px-1 text-on-surface-variant text-[12px]">...</span>}
537
- <button
538
- onClick={() => setThreatCurrentPage(page)}
539
- className={`w-8 h-8 rounded-lg text-[12px] font-bold transition-colors cursor-pointer ${
540
- validThreatCurrentPage === page
541
- ? 'bg-error text-white shadow-2xs'
542
- : 'bg-surface hover:bg-surface-container-high border border-outline-variant/60 text-on-surface'
543
- }`}
544
- >
545
- {page}
546
- </button>
547
- </React.Fragment>
548
- );
549
- })}
550
- </div>
551
-
552
- <button
553
- onClick={() => setThreatCurrentPage(prev => Math.min(totalThreatPages, prev + 1))}
554
- disabled={validThreatCurrentPage >= totalThreatPages}
555
- className="px-3 py-1.5 rounded-lg border border-outline-variant/60 bg-surface hover:bg-surface-container-high text-on-surface font-bold text-[12px] disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer transition-colors"
556
- >
557
- Next
558
- </button>
559
- </div>
560
- </div>
561
- </>
562
- )}
563
- </div>
564
- </div>
565
- );
566
- }
567
-
568
  // Full Page Audit Logs Mode
569
  if (isFullLogsView) {
570
  return (
@@ -809,23 +567,23 @@ const LogsAndThreats = () => {
809
  Global Threat Intelligence
810
  </h2>
811
  <button
812
- onClick={() => openFullThreatsView()}
813
  className="flex items-center gap-1.5 px-3 py-1.5 bg-error/10 hover:bg-error/20 text-error rounded-lg transition-colors font-bold text-[12px] cursor-pointer"
814
  >
815
  <List className="w-4 h-4" />
816
  View All Threats
817
  </button>
818
  </div>
819
- <div className="bg-surface-container-lowest border border-outline-variant rounded-2xl overflow-hidden shadow-2xs p-4">
820
  {loading ? (
821
- <div className="text-center text-on-surface-variant text-[13px] py-4">Loading threats...</div>
822
  ) : trends.length === 0 ? (
823
- <div className="text-center text-on-surface-variant text-[13px] py-4">No global vulnerabilities recorded yet.</div>
824
  ) : (
825
  <div>
826
  <ul className="divide-y divide-outline-variant/60">
827
- {trends.slice(0, 5).map((t, i) => {
828
- const detail = getThreatDetail(t);
829
  return (
830
  <li
831
  key={i}
@@ -835,11 +593,11 @@ const LogsAndThreats = () => {
835
  >
836
  <div className="flex items-start gap-3 pr-2">
837
  <span className="w-7 h-7 rounded-full bg-error/10 text-error flex items-center justify-center text-[12px] font-extrabold shrink-0 mt-0.5">
838
- {i + 1}
839
  </span>
840
  <div>
841
  <h4 className="font-bold text-on-surface text-[13.5px] group-hover:text-primary transition-colors leading-snug">
842
- {t.title}
843
  </h4>
844
  <div className="flex items-center gap-2 mt-1 flex-wrap">
845
  <span className={`px-2 py-0.5 rounded text-[10px] font-extrabold uppercase tracking-wider border ${getSeverityBadgeClass(detail.severity)}`}>
@@ -854,7 +612,7 @@ const LogsAndThreats = () => {
854
 
855
  <div className="flex items-center gap-2 shrink-0 self-end sm:self-center">
856
  <span className="bg-surface-container-high border border-outline-variant/60 px-2.5 py-1 rounded-lg text-[11.5px] font-bold text-on-surface">
857
- {t.count} Found
858
  </span>
859
  <button
860
  type="button"
@@ -872,12 +630,62 @@ const LogsAndThreats = () => {
872
  );
873
  })}
874
  </ul>
875
- <div className="mt-4 pt-3 border-t border-outline-variant text-center">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
876
  <button
877
- onClick={() => openFullThreatsView()}
878
- className="text-error hover:underline text-[13px] font-bold inline-flex items-center gap-1 cursor-pointer bg-transparent border-0"
 
879
  >
880
- View All Complete Threat Intelligence &rarr;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
881
  </button>
882
  </div>
883
  </div>
@@ -900,11 +708,11 @@ const LogsAndThreats = () => {
900
  View All Audit Logs
901
  </button>
902
  </div>
903
- <div className="bg-surface-container-lowest border border-outline-variant rounded-2xl overflow-hidden shadow-2xs p-4">
904
  {loading ? (
905
- <div className="text-center text-on-surface-variant text-[13px] py-4">Loading logs...</div>
906
  ) : auditLogs.length === 0 ? (
907
- <div className="text-center text-on-surface-variant text-[13px] py-4">No admin actions recorded yet.</div>
908
  ) : (
909
  <div>
910
  <ul className="divide-y divide-outline-variant">
@@ -923,20 +731,124 @@ const LogsAndThreats = () => {
923
  </li>
924
  ))}
925
  </ul>
926
- <div className="mt-4 pt-3 border-t border-outline-variant text-center">
927
- <button
928
- onClick={() => openFullLogsView()}
929
- className="text-primary hover:underline text-[13px] font-bold inline-flex items-center gap-1 cursor-pointer bg-transparent border-0"
930
- >
931
- View All Complete Audit Logs &rarr;
932
- </button>
933
- </div>
934
  </div>
935
  )}
 
 
 
 
 
 
 
 
936
  </div>
937
  </div>
938
  </div>
939
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
940
  {/* Global Threat Detail Modal */}
941
  {selectedThreat && (
942
  <div className="fixed inset-0 bg-black/70 backdrop-blur-md flex items-center justify-center p-4 z-50 animate-fade-in">
 
67
  const [auditLogs, setAuditLogs] = useState([]);
68
  const [loading, setLoading] = useState(true);
69
 
70
+ // Selected Threat Detail Modal State
71
  const [selectedThreat, setSelectedThreat] = useState(null);
72
+
73
+ // All Threats Modal View State
74
+ const [showAllThreatsModal, setShowAllThreatsModal] = useState(false);
75
+ const [allThreatsSearch, setAllThreatsSearch] = useState('');
76
 
77
+ // Full Page Audit Logs State
78
  const [isFullLogsView, setIsFullLogsView] = useState(false);
 
 
 
79
  const [allLogs, setAllLogs] = useState([]);
80
  const [loadingAllLogs, setLoadingAllLogs] = useState(false);
81
  const [searchQuery, setSearchQuery] = useState('');
 
86
  const [sortLogCol, setSortLogCol] = useState('Timestamp');
87
  const [sortLogDir, setSortLogDir] = useState('desc');
88
 
89
+ // Threat In-Card Pagination State
90
+ const [threatCardPage, setThreatCardPage] = useState(1);
91
+ const [threatCardPageSize, setThreatCardPageSize] = useState(5);
 
 
 
92
 
93
  const fetchStats = async (isInitial = false) => {
94
  if (isInitial) setLoading(true);
 
141
  setCurrentPage(1);
142
  }, [searchQuery, actionCategory, dateFilter]);
143
 
 
 
 
 
144
  const openFullLogsView = (initialSearch = '') => {
145
  if (initialSearch) {
146
  setSearchQuery(initialSearch);
147
  }
148
+ setShowAllThreatsModal(false);
149
  setIsFullLogsView(true);
150
  fetchAllAuditLogs();
151
  };
 
154
  setIsFullLogsView(false);
155
  };
156
 
 
 
 
 
 
 
 
 
 
157
  const clearLogFilters = () => {
158
  setSearchQuery('');
159
  setActionCategory('all');
160
  setDateFilter('all');
161
  };
162
 
 
 
 
 
 
 
163
  const getThreatDetail = (t) => {
164
  const titleKey = typeof t === 'string' ? t : (t.title || '');
165
  const kb = THREAT_KNOWLEDGE_BASE[titleKey] || {};
 
187
  return 'bg-blue-500/10 text-blue-500 border-blue-500/30';
188
  };
189
 
190
+ // In-Card Threats Pagination Calculations
191
+ const allThreatDetails = trends.map(t => getThreatDetail(t));
192
+ const totalThreatCount = allThreatDetails.length;
193
+ const totalThreatCardPages = Math.ceil(totalThreatCount / threatCardPageSize) || 1;
194
+ const validThreatCardPage = Math.min(Math.max(1, threatCardPage), totalThreatCardPages);
195
+ const startThreatCardIdx = (validThreatCardPage - 1) * threatCardPageSize;
196
+ const endThreatCardIdx = Math.min(startThreatCardIdx + threatCardPageSize, totalThreatCount);
197
+ const paginatedCardThreats = allThreatDetails.slice(startThreatCardIdx, endThreatCardIdx);
198
+
199
+ // Modal All Threats Filtering
200
+ const filteredModalThreats = allThreatDetails.filter(t => {
201
+ if (!allThreatsSearch) return true;
202
+ const q = allThreatsSearch.toLowerCase();
203
+ return t.title.toLowerCase().includes(q) || t.category.toLowerCase().includes(q) || t.owasp.toLowerCase().includes(q);
 
 
 
 
204
  });
205
 
 
 
 
 
 
 
 
206
  // Filtered Audit Logs Calculation
207
  const filteredAllLogs = allLogs.filter(log => {
208
  if (searchQuery) {
 
323
  );
324
  }
325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  // Full Page Audit Logs Mode
327
  if (isFullLogsView) {
328
  return (
 
567
  Global Threat Intelligence
568
  </h2>
569
  <button
570
+ onClick={() => setShowAllThreatsModal(true)}
571
  className="flex items-center gap-1.5 px-3 py-1.5 bg-error/10 hover:bg-error/20 text-error rounded-lg transition-colors font-bold text-[12px] cursor-pointer"
572
  >
573
  <List className="w-4 h-4" />
574
  View All Threats
575
  </button>
576
  </div>
577
+ <div className="bg-surface-container-lowest border border-outline-variant rounded-2xl overflow-hidden shadow-2xs p-4 flex flex-col justify-between min-h-[420px]">
578
  {loading ? (
579
+ <div className="text-center text-on-surface-variant text-[13px] py-8">Loading threats...</div>
580
  ) : trends.length === 0 ? (
581
+ <div className="text-center text-on-surface-variant text-[13px] py-8">No global vulnerabilities recorded yet.</div>
582
  ) : (
583
  <div>
584
  <ul className="divide-y divide-outline-variant/60">
585
+ {paginatedCardThreats.map((detail, i) => {
586
+ const globalIdx = startThreatCardIdx + i + 1;
587
  return (
588
  <li
589
  key={i}
 
593
  >
594
  <div className="flex items-start gap-3 pr-2">
595
  <span className="w-7 h-7 rounded-full bg-error/10 text-error flex items-center justify-center text-[12px] font-extrabold shrink-0 mt-0.5">
596
+ {globalIdx}
597
  </span>
598
  <div>
599
  <h4 className="font-bold text-on-surface text-[13.5px] group-hover:text-primary transition-colors leading-snug">
600
+ {detail.title}
601
  </h4>
602
  <div className="flex items-center gap-2 mt-1 flex-wrap">
603
  <span className={`px-2 py-0.5 rounded text-[10px] font-extrabold uppercase tracking-wider border ${getSeverityBadgeClass(detail.severity)}`}>
 
612
 
613
  <div className="flex items-center gap-2 shrink-0 self-end sm:self-center">
614
  <span className="bg-surface-container-high border border-outline-variant/60 px-2.5 py-1 rounded-lg text-[11.5px] font-bold text-on-surface">
615
+ {detail.count} Found
616
  </span>
617
  <button
618
  type="button"
 
630
  );
631
  })}
632
  </ul>
633
+ </div>
634
+ )}
635
+
636
+ {/* Standardized In-Card Pagination for Threat Intelligence */}
637
+ {totalThreatCount > 0 && (
638
+ <div className="mt-4 pt-3 border-t border-outline-variant/60 flex flex-col sm:flex-row items-center justify-between gap-2 text-[12.5px] text-on-surface-variant">
639
+ <div className="flex items-center gap-1.5">
640
+ <span>Rows:</span>
641
+ <select
642
+ value={threatCardPageSize}
643
+ onChange={(e) => {
644
+ setThreatCardPageSize(Number(e.target.value));
645
+ setThreatCardPage(1);
646
+ }}
647
+ className="bg-surface border border-outline-variant/60 text-on-surface rounded-md px-2 py-1 text-[11.5px] font-bold focus:outline-none cursor-pointer"
648
+ >
649
+ <option value={5}>5</option>
650
+ <option value={10}>10</option>
651
+ <option value={15}>15</option>
652
+ </select>
653
+ <span className="ml-1 font-medium">
654
+ {startThreatCardIdx + 1} - {endThreatCardIdx} of {totalThreatCount} records
655
+ </span>
656
+ </div>
657
+
658
+ <div className="flex items-center gap-1">
659
  <button
660
+ onClick={() => setThreatCardPage(prev => Math.max(1, prev - 1))}
661
+ disabled={validThreatCardPage === 1}
662
+ className="px-2.5 py-1 rounded-md border border-outline-variant/60 bg-surface hover:bg-surface-container-high text-on-surface font-bold text-[11.5px] disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer"
663
  >
664
+ Previous
665
+ </button>
666
+
667
+ <div className="flex items-center gap-1 px-1">
668
+ {Array.from({ length: totalThreatCardPages }, (_, i) => i + 1).map(page => (
669
+ <button
670
+ key={page}
671
+ onClick={() => setThreatCardPage(page)}
672
+ className={`w-7 h-7 rounded-md text-[11.5px] font-bold cursor-pointer ${
673
+ validThreatCardPage === page
674
+ ? 'bg-error text-white shadow-2xs'
675
+ : 'bg-surface hover:bg-surface-container-high border border-outline-variant/60 text-on-surface'
676
+ }`}
677
+ >
678
+ {page}
679
+ </button>
680
+ ))}
681
+ </div>
682
+
683
+ <button
684
+ onClick={() => setThreatCardPage(prev => Math.min(totalThreatCardPages, prev + 1))}
685
+ disabled={validThreatCardPage >= totalThreatCardPages}
686
+ className="px-2.5 py-1 rounded-md border border-outline-variant/60 bg-surface hover:bg-surface-container-high text-on-surface font-bold text-[11.5px] disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer"
687
+ >
688
+ Next
689
  </button>
690
  </div>
691
  </div>
 
708
  View All Audit Logs
709
  </button>
710
  </div>
711
+ <div className="bg-surface-container-lowest border border-outline-variant rounded-2xl overflow-hidden shadow-2xs p-4 flex flex-col justify-between min-h-[420px]">
712
  {loading ? (
713
+ <div className="text-center text-on-surface-variant text-[13px] py-8">Loading logs...</div>
714
  ) : auditLogs.length === 0 ? (
715
+ <div className="text-center text-on-surface-variant text-[13px] py-8">No admin actions recorded yet.</div>
716
  ) : (
717
  <div>
718
  <ul className="divide-y divide-outline-variant">
 
731
  </li>
732
  ))}
733
  </ul>
 
 
 
 
 
 
 
 
734
  </div>
735
  )}
736
+ <div className="mt-4 pt-3 border-t border-outline-variant text-center">
737
+ <button
738
+ onClick={() => openFullLogsView()}
739
+ className="text-primary hover:underline text-[13px] font-bold inline-flex items-center gap-1 cursor-pointer bg-transparent border-0"
740
+ >
741
+ View All Complete Audit Logs &rarr;
742
+ </button>
743
+ </div>
744
  </div>
745
  </div>
746
  </div>
747
 
748
+ {/* All Global Threats Modal Popup (Preserving exact card design) */}
749
+ {showAllThreatsModal && (
750
+ <div className="fixed inset-0 bg-black/70 backdrop-blur-md flex items-center justify-center p-4 z-50 animate-fade-in">
751
+ <div className="bg-surface border border-outline-variant rounded-2xl max-w-3xl w-full p-6 shadow-2xl relative max-h-[90vh] flex flex-col">
752
+ {/* Close Button */}
753
+ <button
754
+ onClick={() => setShowAllThreatsModal(false)}
755
+ className="absolute top-4 right-4 text-on-surface-variant hover:text-on-surface bg-surface-container p-2 rounded-full transition-colors cursor-pointer border-0"
756
+ >
757
+ <X className="w-5 h-5" />
758
+ </button>
759
+
760
+ {/* Modal Header */}
761
+ <div className="flex items-center gap-3 border-b border-outline-variant pb-4 mb-4 pr-10">
762
+ <div className="p-2.5 bg-red-500/10 text-error rounded-xl border border-red-500/20 shrink-0">
763
+ <AlertTriangle className="w-6 h-6 text-error" />
764
+ </div>
765
+ <div>
766
+ <h2 className="text-[20px] font-bold text-on-surface tracking-tight flex items-center gap-2">
767
+ All Global Threat Intelligence
768
+ <span className="bg-error/10 text-error text-[12px] font-extrabold px-2.5 py-0.5 rounded-full border border-error/20">
769
+ {allThreatDetails.length} Records
770
+ </span>
771
+ </h2>
772
+ <p className="text-[13px] text-on-surface-variant mt-0.5">Explore full vulnerability advisories and remediation guides.</p>
773
+ </div>
774
+ </div>
775
+
776
+ {/* Search Bar */}
777
+ <div className="relative mb-4">
778
+ <Search className="w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-on-surface-variant" />
779
+ <input
780
+ type="text"
781
+ placeholder="Search threat title or category..."
782
+ value={allThreatsSearch}
783
+ onChange={(e) => setAllThreatsSearch(e.target.value)}
784
+ className="w-full pl-9 pr-3 py-2 bg-surface-container-lowest border border-outline-variant/70 rounded-xl text-[13px] text-on-surface focus:outline-none focus:border-primary"
785
+ />
786
+ </div>
787
+
788
+ {/* Modal List Body */}
789
+ <div className="overflow-y-auto flex-1 pr-1">
790
+ <ul className="divide-y divide-outline-variant/60">
791
+ {filteredModalThreats.map((detail, idx) => (
792
+ <li
793
+ key={idx}
794
+ onClick={() => {
795
+ setSelectedThreat(detail);
796
+ }}
797
+ className="py-3 px-3 rounded-xl flex flex-col sm:flex-row sm:items-center justify-between gap-3 hover:bg-surface-container-high/70 cursor-pointer transition-all group border border-transparent hover:border-primary/30 my-1"
798
+ >
799
+ <div className="flex items-start gap-3 pr-2">
800
+ <span className="w-7 h-7 rounded-full bg-error/10 text-error flex items-center justify-center text-[12px] font-extrabold shrink-0 mt-0.5">
801
+ {idx + 1}
802
+ </span>
803
+ <div>
804
+ <h4 className="font-bold text-on-surface text-[13.5px] group-hover:text-primary transition-colors leading-snug">
805
+ {detail.title}
806
+ </h4>
807
+ <div className="flex items-center gap-2 mt-1 flex-wrap">
808
+ <span className={`px-2 py-0.5 rounded text-[10px] font-extrabold uppercase tracking-wider border ${getSeverityBadgeClass(detail.severity)}`}>
809
+ {detail.severity}
810
+ </span>
811
+ <span className="text-[11px] text-on-surface-variant font-medium">
812
+ {detail.category}
813
+ </span>
814
+ </div>
815
+ </div>
816
+ </div>
817
+
818
+ <div className="flex items-center gap-2 shrink-0 self-end sm:self-center">
819
+ <span className="bg-surface-container-high border border-outline-variant/60 px-2.5 py-1 rounded-lg text-[11.5px] font-bold text-on-surface">
820
+ {detail.count} Found
821
+ </span>
822
+ <button
823
+ type="button"
824
+ onClick={(e) => {
825
+ e.stopPropagation();
826
+ setSelectedThreat(detail);
827
+ }}
828
+ className="px-3 py-1.5 bg-primary/10 hover:bg-primary text-primary hover:text-white rounded-lg text-[12px] font-bold flex items-center gap-1.5 transition-all cursor-pointer border border-primary/30 shadow-2xs"
829
+ >
830
+ <Info className="w-3.5 h-3.5" />
831
+ View Details
832
+ </button>
833
+ </div>
834
+ </li>
835
+ ))}
836
+ </ul>
837
+ </div>
838
+
839
+ {/* Modal Footer */}
840
+ <div className="mt-4 pt-3 border-t border-outline-variant flex justify-end">
841
+ <button
842
+ onClick={() => setShowAllThreatsModal(false)}
843
+ className="px-5 py-2 bg-primary text-white rounded-xl font-bold text-[13px] hover:brightness-110 cursor-pointer border-0"
844
+ >
845
+ Close Window
846
+ </button>
847
+ </div>
848
+ </div>
849
+ </div>
850
+ )}
851
+
852
  {/* Global Threat Detail Modal */}
853
  {selectedThreat && (
854
  <div className="fixed inset-0 bg-black/70 backdrop-blur-md flex items-center justify-center p-4 z-50 animate-fade-in">