File size: 23,255 Bytes
31b612e | 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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | import React, { useState } from 'react';
import {
FileText,
Search,
Download,
AlertTriangle,
ShieldAlert,
ShieldCheck,
UserX,
Eye
} from 'lucide-react';
export default function TransactionTable({ previewData, topSuspicious, muleAccounts, sessionId, backendUrl }) {
const [activeTab, setActiveTab] = useState('preview');
const [searchTerm, setSearchTerm] = useState('');
const [riskFilter, setRiskFilter] = useState('All');
const [currentPage, setCurrentPage] = useState(1);
const [selectedTx, setSelectedTx] = useState(null); // For detail modal
const itemsPerPage = 15;
// Filter & Search preview data
const filteredPreview = (previewData || []).filter(item => {
// Search matching
const searchStr = `${item.F3886 || ''} ${item.F3893 || ''} ${item.F3891 || ''} ${item.Unnamed_0 || item['Unnamed: 0'] || ''}`.toLowerCase();
const matchesSearch = searchStr.includes(searchTerm.toLowerCase());
// Risk matching
const matchesRisk = riskFilter === 'All' || item.risk_level === riskFilter;
return matchesSearch && matchesRisk;
});
// Pagination
const totalPages = Math.ceil(filteredPreview.length / itemsPerPage);
const paginatedData = filteredPreview.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage);
const getRiskBadge = (level) => {
switch (level) {
case 'High':
return <span className="badge badge-danger">High Risk</span>;
case 'Medium':
return <span className="badge badge-warning">Medium Risk</span>;
default:
return <span className="badge badge-success">Low Risk</span>;
}
};
const handleDownload = () => {
if (!sessionId) return;
window.open(`${backendUrl}/api/download-run/${sessionId}`, '_blank');
};
return (
<div className="glass-card animate-fade-in" style={{ marginTop: '24px' }}>
{/* Header and Download */}
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
flexWrap: 'wrap',
gap: '16px',
marginBottom: '20px',
borderBottom: '1px solid var(--border-color)',
paddingBottom: '16px'
}}>
<div style={{ display: 'flex', gap: '8px', alignItems: 'center' }}>
<FileText style={{ color: 'var(--primary)' }} />
<h2 style={{ fontSize: '1.25rem', margin: 0 }}>Analysis Logs</h2>
</div>
{sessionId && (
<button className="btn btn-primary" onClick={handleDownload}>
<Download size={18} />
Download Annotated CSV
</button>
)}
</div>
{/* Tabs list */}
<div style={{
display: 'flex',
gap: '12px',
borderBottom: '1px solid var(--border-color)',
marginBottom: '20px',
overflowX: 'auto',
paddingBottom: '2px'
}}>
<button
style={{
background: 'none',
border: 'none',
color: activeTab === 'preview' ? 'var(--primary)' : 'var(--text-secondary)',
fontWeight: 600,
padding: '10px 16px',
borderBottom: activeTab === 'preview' ? '2px solid var(--primary)' : '2px solid transparent',
cursor: 'pointer',
transition: 'var(--transition)'
}}
onClick={() => { setActiveTab('preview'); setCurrentPage(1); }}
>
Transactions Preview ({filteredPreview.length})
</button>
<button
style={{
background: 'none',
border: 'none',
color: activeTab === 'alerts' ? 'var(--primary)' : 'var(--text-secondary)',
fontWeight: 600,
padding: '10px 16px',
borderBottom: activeTab === 'alerts' ? '2px solid var(--primary)' : '2px solid transparent',
cursor: 'pointer',
transition: 'var(--transition)'
}}
onClick={() => setActiveTab('alerts')}
>
Top Risky Alerts ({topSuspicious?.length || 0})
</button>
<button
style={{
background: 'none',
border: 'none',
color: activeTab === 'mules' ? 'var(--primary)' : 'var(--text-secondary)',
fontWeight: 600,
padding: '10px 16px',
borderBottom: activeTab === 'mules' ? '2px solid var(--primary)' : '2px solid transparent',
cursor: 'pointer',
transition: 'var(--transition)'
}}
onClick={() => setActiveTab('mules')}
>
<div style={{ display: 'flex', alignItems: 'center', gap: '6px' }}>
<UserX size={16} />
Mule Account Candidates ({muleAccounts?.length || 0})
</div>
</button>
</div>
{/* SEARCH AND FILTERS (Only for preview tab) */}
{activeTab === 'preview' && (
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
flexWrap: 'wrap',
gap: '16px',
marginBottom: '20px'
}}>
{/* Search box */}
<div style={{ position: 'relative', width: '320px', maxWidth: '100%' }}>
<Search
size={18}
style={{
position: 'absolute',
left: '12px',
top: '50%',
transform: 'translateY(-50%)',
color: 'var(--text-secondary)'
}}
/>
<input
type="text"
placeholder="Search by account, channel, job..."
className="form-input"
style={{ paddingLeft: '40px' }}
value={searchTerm}
onChange={(e) => { setSearchTerm(e.target.value); setCurrentPage(1); }}
/>
</div>
{/* Filter dropdown */}
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<span style={{ fontSize: '0.875rem', color: 'var(--text-secondary)' }}>Risk Filter:</span>
<select
className="form-input"
style={{ width: '150px', padding: '8px 12px' }}
value={riskFilter}
onChange={(e) => { setRiskFilter(e.target.value); setCurrentPage(1); }}
>
<option value="All">All Risk Levels</option>
<option value="High">High Risk</option>
<option value="Medium">Medium Risk</option>
<option value="Low">Low Risk</option>
</select>
</div>
</div>
)}
{/* TAB 1: ALL PREVIEW */}
{activeTab === 'preview' && (
<div>
{paginatedData.length === 0 ? (
<div style={{ textAlign: 'center', padding: '40px', color: 'var(--text-secondary)' }}>
No transactions match the selected filters.
</div>
) : (
<div style={{ overflowX: 'auto' }}>
<table style={{
width: '100%',
borderCollapse: 'collapse',
textAlign: 'left',
fontSize: '0.875rem'
}}>
<thead>
<tr style={{ borderBottom: '2px solid var(--border-color)', color: 'var(--text-secondary)' }}>
<th style={{ padding: '12px' }}>ID</th>
<th style={{ padding: '12px' }}>Date</th>
<th style={{ padding: '12px' }}>Account Type</th>
<th style={{ padding: '12px' }}>Channel</th>
<th style={{ padding: '12px' }}>Job Type</th>
<th style={{ padding: '12px' }}>Risk Prob</th>
<th style={{ padding: '12px' }}>Status</th>
<th style={{ padding: '12px' }}>Actions</th>
</tr>
</thead>
<tbody>
{paginatedData.map((row, idx) => {
const rowId = row.Unnamed_0 || row['Unnamed: 0'] || `Row ${idx + 1}`;
return (
<tr
key={idx}
style={{
borderBottom: '1px solid var(--border-color)',
background: row.is_suspicious ? 'rgba(239, 68, 68, 0.03)' : 'transparent'
}}
>
<td style={{ padding: '12px', fontWeight: 600 }}>{rowId}</td>
<td style={{ padding: '12px', color: 'var(--text-secondary)' }}>{row.F3888 || 'N/A'}</td>
<td style={{ padding: '12px' }}>{row.F3886 || 'N/A'}</td>
<td style={{ padding: '12px' }}>{row.F3893 || 'N/A'}</td>
<td style={{ padding: '12px', color: 'var(--text-secondary)' }}>{row.F3891 || 'N/A'}</td>
<td style={{ padding: '12px', fontWeight: 700, color: row.is_suspicious ? 'var(--danger)' : 'var(--text-primary)' }}>
{Math.round(row.fraud_probability * 100)}%
</td>
<td style={{ padding: '12px' }}>
{getRiskBadge(row.risk_level)}
</td>
<td style={{ padding: '12px' }}>
<button
style={{
background: 'rgba(255,255,255,0.05)',
border: 'none',
borderRadius: '4px',
padding: '4px 8px',
cursor: 'pointer',
color: 'var(--text-secondary)'
}}
onClick={() => setSelectedTx(row)}
title="Inspect Details"
>
<Eye size={14} />
</button>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
)}
{/* Pagination controls */}
{totalPages > 1 && (
<div style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginTop: '20px',
borderTop: '1px solid var(--border-color)',
paddingTop: '16px'
}}>
<span style={{ fontSize: '0.875rem', color: 'var(--text-secondary)' }}>
Page {currentPage} of {totalPages}
</span>
<div style={{ display: 'flex', gap: '8px' }}>
<button
className="btn btn-secondary"
style={{ padding: '6px 12px', fontSize: '0.8rem' }}
disabled={currentPage === 1}
onClick={() => setCurrentPage(prev => Math.max(prev - 1, 1))}
>
Previous
</button>
<button
className="btn btn-secondary"
style={{ padding: '6px 12px', fontSize: '0.8rem' }}
disabled={currentPage === totalPages}
onClick={() => setCurrentPage(prev => Math.min(prev + 1, totalPages))}
>
Next
</button>
</div>
</div>
)}
</div>
)}
{/* TAB 2: TOP SUSPICIOUS ALERTS */}
{activeTab === 'alerts' && (
<div style={{ overflowX: 'auto' }}>
{(!topSuspicious || topSuspicious.length === 0) ? (
<div style={{ textAlign: 'center', padding: '40px', color: 'var(--text-secondary)' }}>
No critical fraud alerts detected.
</div>
) : (
<table style={{
width: '100%',
borderCollapse: 'collapse',
textAlign: 'left',
fontSize: '0.875rem'
}}>
<thead>
<tr style={{ borderBottom: '2px solid var(--border-color)', color: 'var(--text-secondary)' }}>
<th style={{ padding: '12px' }}>ID</th>
<th style={{ padding: '12px' }}>Risk Probability</th>
<th style={{ padding: '12px' }}>Date</th>
<th style={{ padding: '12px' }}>Account Type</th>
<th style={{ padding: '12px' }}>Channel</th>
<th style={{ padding: '12px' }}>Job Status</th>
<th style={{ padding: '12px' }}>Risk Assessment</th>
<th style={{ padding: '12px' }}>Action</th>
</tr>
</thead>
<tbody>
{topSuspicious.map((row, idx) => {
const rowId = row.Unnamed_0 || row['Unnamed: 0'] || `Alert ${idx + 1}`;
return (
<tr
key={idx}
style={{
borderBottom: '1px solid var(--border-color)',
background: 'rgba(239, 68, 68, 0.05)'
}}
>
<td style={{ padding: '12px', fontWeight: 600 }}>{rowId}</td>
<td style={{ padding: '12px', fontWeight: 800, color: 'var(--danger)', display: 'flex', alignItems: 'center', gap: '8px' }}>
<ShieldAlert size={16} />
{Math.round(row.fraud_probability * 100)}% Risk
</td>
<td style={{ padding: '12px', color: 'var(--text-secondary)' }}>{row.F3888 || 'N/A'}</td>
<td style={{ padding: '12px' }}>{row.F3886 || 'N/A'}</td>
<td style={{ padding: '12px' }}>{row.F3893 || 'N/A'}</td>
<td style={{ padding: '12px', color: 'var(--text-secondary)' }}>{row.F3891 || 'N/A'}</td>
<td style={{ padding: '12px' }}>
<span className="badge badge-danger">High Threat</span>
</td>
<td style={{ padding: '12px' }}>
<button
className="btn btn-secondary"
style={{ padding: '4px 8px', fontSize: '0.75rem' }}
onClick={() => setSelectedTx(row)}
>
Inspect
</button>
</td>
</tr>
);
})}
</tbody>
</table>
)}
</div>
)}
{/* TAB 3: MULE ACCOUNT CANDIDATES */}
{activeTab === 'mules' && (
<div>
<p style={{ color: 'var(--text-secondary)', fontSize: '0.875rem', marginBottom: '16px' }}>
Mule accounts typically act as intermediaries to circulate stolen funds. The table below lists account IDs that have multiple high-risk/suspicious transactions in this file run.
</p>
<div style={{ overflowX: 'auto' }}>
{(!muleAccounts || muleAccounts.length === 0) ? (
<div style={{ textAlign: 'center', padding: '40px', color: 'var(--text-secondary)' }}>
No repeating account-level suspicious transactions detected.
</div>
) : (
<table style={{
width: '100%',
borderCollapse: 'collapse',
textAlign: 'left',
fontSize: '0.875rem'
}}>
<thead>
<tr style={{ borderBottom: '2px solid var(--border-color)', color: 'var(--text-secondary)' }}>
<th style={{ padding: '12px' }}>Account ID / Value</th>
<th style={{ padding: '12px' }}>Total Transactions</th>
<th style={{ padding: '12px' }}>Suspicious Flagged Count</th>
<th style={{ padding: '12px' }}>Max Probability</th>
<th style={{ padding: '12px' }}>Avg Risk Probability</th>
<th style={{ padding: '12px' }}>Mule Account Threat Rating</th>
</tr>
</thead>
<tbody>
{muleAccounts.map((mule, idx) => {
const avgRisk = Math.round(mule.avg_prob * 100);
const threatScore = mule.suspicious_count * avgRisk;
const isSevere = threatScore > 100 || mule.suspicious_count >= 3;
return (
<tr
key={idx}
style={{
borderBottom: '1px solid var(--border-color)',
background: isSevere ? 'rgba(239, 68, 68, 0.04)' : 'transparent'
}}
>
<td style={{ padding: '12px', fontWeight: 600 }}>{mule.F3887 || mule.F3895 || `Acc #${idx}`}</td>
<td style={{ padding: '12px' }}>{mule.tx_count}</td>
<td style={{ padding: '12px', fontWeight: 700, color: 'var(--danger)' }}>{mule.suspicious_count}</td>
<td style={{ padding: '12px' }}>{Math.round(mule.max_prob * 100)}%</td>
<td style={{ padding: '12px', fontWeight: 600 }}>{avgRisk}%</td>
<td style={{ padding: '12px' }}>
{isSevere ? (
<span className="badge badge-danger" style={{ animation: 'pulse-glow 2s infinite' }}>
CRITICAL MULE
</span>
) : (
<span className="badge badge-warning">SUSPECT MULE</span>
)}
</td>
</tr>
);
})}
</tbody>
</table>
)}
</div>
</div>
)}
{/* DETAILS MODAL */}
{selectedTx && (
<div style={{
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'rgba(0, 0, 0, 0.8)',
backdropFilter: 'blur(8px)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 1000,
padding: '20px'
}}>
<div className="glass-card animate-fade-in" style={{
width: '600px',
maxWidth: '100%',
maxHeight: '90vh',
overflowY: 'auto',
background: '#151e33',
border: '1px solid rgba(255,255,255,0.15)',
boxShadow: '0 10px 40px rgba(0,0,0,0.6)'
}}>
<h3 style={{ fontSize: '1.25rem', marginBottom: '16px', display: 'flex', alignItems: 'center', gap: '8px' }}>
<AlertTriangle style={{ color: selectedTx.is_suspicious ? 'var(--danger)' : 'var(--success)' }} />
Transaction Details & Analysis
</h3>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '16px', marginBottom: '20px', background: 'rgba(0,0,0,0.2)', padding: '16px', borderRadius: '8px' }}>
<div>
<p style={{ fontSize: '0.8rem', color: 'var(--text-secondary)' }}>Transaction ID</p>
<p style={{ fontWeight: 600 }}>{selectedTx.Unnamed_0 || selectedTx['Unnamed: 0'] || 'N/A'}</p>
</div>
<div>
<p style={{ fontSize: '0.8rem', color: 'var(--text-secondary)' }}>Risk Assessment</p>
<p>{getRiskBadge(selectedTx.risk_level)}</p>
</div>
<div>
<p style={{ fontSize: '0.8rem', color: 'var(--text-secondary)' }}>Fraud Probability</p>
<p style={{ fontWeight: 700, fontSize: '1.1rem', color: selectedTx.is_suspicious ? 'var(--danger)' : 'var(--success)' }}>
{Math.round(selectedTx.fraud_probability * 100)}%
</p>
</div>
<div>
<p style={{ fontSize: '0.8rem', color: 'var(--text-secondary)' }}>Transaction DateTime</p>
<p>{selectedTx.F3888 || 'N/A'}</p>
</div>
</div>
<h4 style={{ fontSize: '0.95rem', marginBottom: '8px', color: 'var(--text-secondary)' }}>Key Parameters Loaded</h4>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '12px', fontSize: '0.875rem', marginBottom: '24px' }}>
<div style={{ borderBottom: '1px solid var(--border-color)', paddingBottom: '6px' }}>
<span style={{ color: 'var(--text-secondary)' }}>Account Type (F3886):</span> <span style={{ fontWeight: 500 }}>{selectedTx.F3886 || 'N/A'}</span>
</div>
<div style={{ borderBottom: '1px solid var(--border-color)', paddingBottom: '6px' }}>
<span style={{ color: 'var(--text-secondary)' }}>Channel (F3893):</span> <span style={{ fontWeight: 500 }}>{selectedTx.F3893 || 'N/A'}</span>
</div>
<div style={{ borderBottom: '1px solid var(--border-color)', paddingBottom: '6px' }}>
<span style={{ color: 'var(--text-secondary)' }}>Job Status (F3891):</span> <span style={{ fontWeight: 500 }}>{selectedTx.F3891 || 'N/A'}</span>
</div>
<div style={{ borderBottom: '1px solid var(--border-color)', paddingBottom: '6px' }}>
<span style={{ color: 'var(--text-secondary)' }}>Gender (F3892):</span> <span style={{ fontWeight: 500 }}>{selectedTx.F3892 || 'N/A'}</span>
</div>
<div style={{ borderBottom: '1px solid var(--border-color)', paddingBottom: '6px' }}>
<span style={{ color: 'var(--text-secondary)' }}>Account Code (F3887):</span> <span style={{ fontWeight: 500 }}>{selectedTx.F3887 || 'N/A'}</span>
</div>
<div style={{ borderBottom: '1px solid var(--border-color)', paddingBottom: '6px' }}>
<span style={{ color: 'var(--text-secondary)' }}>Customer Code (F3889):</span> <span style={{ fontWeight: 500 }}>{selectedTx.F3889 || 'N/A'}</span>
</div>
<div style={{ borderBottom: '1px solid var(--border-color)', paddingBottom: '6px' }}>
<span style={{ color: 'var(--text-secondary)' }}>Account State (F3890):</span> <span style={{ fontWeight: 500 }}>{selectedTx.F3890 || 'N/A'}</span>
</div>
<div style={{ borderBottom: '1px solid var(--border-color)', paddingBottom: '6px' }}>
<span style={{ color: 'var(--text-secondary)' }}>Tx Interval (F3894):</span> <span style={{ fontWeight: 500 }}>{selectedTx.F3894 || 'N/A'}</span>
</div>
</div>
<div style={{ display: 'flex', justifyContent: 'flex-end', gap: '12px' }}>
<button className="btn btn-secondary" onClick={() => setSelectedTx(null)}>
Close Inspection
</button>
</div>
</div>
</div>
)}
</div>
);
}
|