From bec4b714e354bc9698ce119f57fedd63906f672a Mon Sep 17 00:00:00 2001 From: Daniel Bedeleanu Date: Sun, 19 Apr 2026 14:58:33 +0300 Subject: [PATCH] refactor: extract LogsTable component from logs/page.tsx --- frontend/app/logs/page.tsx | 160 +------------------------ frontend/components/LogsTable.tsx | 191 ++++++++++++++++++++++++++++++ 2 files changed, 194 insertions(+), 157 deletions(-) create mode 100644 frontend/components/LogsTable.tsx diff --git a/frontend/app/logs/page.tsx b/frontend/app/logs/page.tsx index 1757170d..154f4076 100644 --- a/frontend/app/logs/page.tsx +++ b/frontend/app/logs/page.tsx @@ -4,10 +4,11 @@ import { useState, useEffect } from 'react'; import { db, Item } from '@/lib/db'; import { inventoryApi } from '@/lib/api'; import PageShell from '@/components/PageShell'; -import { History, X, Search, Filter, Activity, ArrowDownCircle, ArrowUpCircle, User, RefreshCw } from 'lucide-react'; +import { History, Search, Activity, ArrowDownCircle, ArrowUpCircle, RefreshCw } from 'lucide-react'; import { cn } from '@/lib/utils'; import { fetchAndCacheItems } from '@/lib/sync'; import StatCard from '@/components/StatCard'; +import LogsTable from '@/components/LogsTable'; export default function LogsPage() { const [auditLogs, setAuditLogs] = useState([]); @@ -15,7 +16,6 @@ export default function LogsPage() { const [loading, setLoading] = useState(true); const [searchQuery, setSearchQuery] = useState(''); const [filterAction, setFilterAction] = useState('ALL'); - const [selectedLog, setSelectedLog] = useState(null); useEffect(() => { loadData(); @@ -179,162 +179,8 @@ export default function LogsPage() {
- {loading ? ( -
-
-

Securing Audit Stream...

-
- ) : filteredLogs.length === 0 ? ( -
-
- -
-
-

No events found

-

Refine your strategic filters

-
-
- ) : ( -
- {filteredLogs.map((log) => ( - - ))} -
- )} +
- - {/* Selected Log Modal */} - {selectedLog && ( -
-
-
-
-
- {selectedLog.action} -
-

- {selectedLog.resolved_name} -

-
- -
- -
-
-

Protocol Operator

-

{selectedLog.username || 'Automated Process'}

-
-
-

Quantity Delta

-

0 ? "text-green-500" : "text-rose-500" - )}> - {selectedLog.quantity_change - ? `${selectedLog.quantity_change > 0 ? '+' : ''}${selectedLog.quantity_change}` - : (selectedLog.action.includes('DB') ? 'SYS' : '±')} -

-
-
- -
-
-

Universal Timestamp

-

- {new Date(selectedLog.timestamp).toLocaleString(undefined, { dateStyle: 'full', timeStyle: 'medium' })} -

-
- - {selectedLog.target_snapshot && (() => { - try { - const snap = JSON.parse(selectedLog.target_snapshot) as Record; - return ( -
-
-
-

Snapshot Record

-
-
-
- {Object.entries(snap).map(([key, val]) => ( - (val && key !== 'image_url' && key !== 'id') ? ( -
-

{key.replace('_', ' ')}

-

{String(val)}

-
- ) : null - ))} -
-
- ); - } catch (e) { return null; } - })()} - - {selectedLog.details && ( -
-

Intervention Details

-
- "{selectedLog.details}" -
-
- )} -
- - -
-
- )} ); diff --git a/frontend/components/LogsTable.tsx b/frontend/components/LogsTable.tsx new file mode 100644 index 00000000..8277e445 --- /dev/null +++ b/frontend/components/LogsTable.tsx @@ -0,0 +1,191 @@ +'use client'; + +import { useState } from 'react'; +import { X, ArrowDownCircle, ArrowUpCircle } from 'lucide-react'; +import { cn } from '@/lib/utils'; + +interface AuditLog { + id: string; + action: string; + username?: string; + timestamp: string; + resolved_name: string; + quantity_change?: number; + target_snapshot?: string; + details?: string; +} + +interface LogsTableProps { + logs: AuditLog[]; + loading: boolean; +} + +export default function LogsTable({ logs, loading }: LogsTableProps) { + const [selectedLog, setSelectedLog] = useState(null); + + if (loading) { + return ( +
+
+

Securing Audit Stream...

+
+ ); + } + + if (logs.length === 0) { + return ( +
+
+ +
+
+

No events found

+

Refine your strategic filters

+
+
+ ); + } + + return ( + <> +
+ {logs.map((log) => ( + + ))} +
+ + {/* Selected Log Modal */} + {selectedLog && ( +
+
+
+
+
+ {selectedLog.action} +
+

+ {selectedLog.resolved_name} +

+
+ +
+ +
+
+

Protocol Operator

+

{selectedLog.username || 'Automated Process'}

+
+
+

Quantity Delta

+

0 ? "text-green-500" : "text-rose-500" + )}> + {selectedLog.quantity_change + ? `${selectedLog.quantity_change > 0 ? '+' : ''}${selectedLog.quantity_change}` + : (selectedLog.action.includes('DB') ? 'SYS' : '±')} +

+
+
+ +
+
+

Universal Timestamp

+

+ {new Date(selectedLog.timestamp).toLocaleString(undefined, { dateStyle: 'full', timeStyle: 'medium' })} +

+
+ + {selectedLog.target_snapshot && (() => { + try { + const snap = JSON.parse(selectedLog.target_snapshot) as Record; + return ( +
+
+
+

Snapshot Record

+
+
+
+ {Object.entries(snap).map(([key, val]) => ( + (val && key !== 'image_url' && key !== 'id') ? ( +
+

{key.replace('_', ' ')}

+

{String(val)}

+
+ ) : null + ))} +
+
+ ); + } catch (e) { return null; } + })()} + + {selectedLog.details && ( +
+

Intervention Details

+
+ "{selectedLog.details}" +
+
+ )} +
+ + +
+
+ )} + + ); +}