From 19c748bf9756a2c9efc4748670bff5598edac37a Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Mon, 13 Oct 2025 21:11:16 +0530 Subject: [PATCH] feat: implement MessageDetails component for displaying log details in a dialog --- .../[search_space_id]/logs/(manage)/page.tsx | 228 +++++++++--------- 1 file changed, 110 insertions(+), 118 deletions(-) diff --git a/surfsense_web/app/dashboard/[search_space_id]/logs/(manage)/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/logs/(manage)/page.tsx index fc2105274..1d7cae855 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/logs/(manage)/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/logs/(manage)/page.tsx @@ -122,6 +122,55 @@ const logStatusConfig = { FAILED: { icon: X, color: "text-red-600", bgColor: "bg-red-50" }, } as const; +function MessageDetails({ + message, + taskName, + metadata, + createdAt, + children, +}: { + message: string; + taskName?: string; + metadata?: any; + createdAt?: string; + children: React.ReactNode; +}) { + return ( + + {children} + + + + Log details + {createdAt && ( + + {new Date(createdAt).toLocaleString()} + + )} + + + Close + + + + + {taskName && ( + + {taskName} + + )} + + + {message} + + + + + + + ); +} + const columns: ColumnDef[] = [ { id: "select", @@ -219,19 +268,22 @@ const columns: ColumnDef[] = [ cell: ({ row }) => { const message = row.getValue("message") as string; const taskName = row.original.log_metadata?.task_name; + const createdAt = row.getValue("created_at") as string; return ( - - {taskName && ( - - {taskName} - - )} - - {message.length > 100 ? `${message.substring(0, 100)}...` : message} - - - ); + + + {taskName && ( + + {taskName} + + )} + + {message.length > 100 ? `${message.substring(0, 100)}...` : message} + + + + ); }, size: 400, }, @@ -777,12 +829,6 @@ function LogsTable({ onRefresh: () => void; id: string; }) { - const [expandedRows, setExpandedRows] = useState>({}); - - const toggleRowExpanded = (rowId: string) => { - setExpandedRows((prev) => ({ ...prev, [rowId]: !prev[rowId] })); - }; - if (loading) { return ( - {table.getRowModel().rows?.length ? ( - table.getRowModel().rows.map((row: any, index: number) => ( - - {row.getVisibleCells().map((cell: any) => { - const isCreatedAt = cell.column.id === "created_at"; - const isMessage = cell.column.id === "message"; - const isExpanded = Boolean(expandedRows[row.id]); - - // If this is the Message column, render custom inline expandable content - if (isMessage) { - const message = row.getValue("message") as string; - const taskName = row.original.log_metadata?.task_name; - const createdAt = row.getValue("created_at") as string; - - return ( - - {/* Click the preview to toggle expand/collapse */} - toggleRowExpanded(row.id)} - aria-expanded={isExpanded} - > - {taskName && ( - - {taskName} - - )} - - {isExpanded ? ( - /* Expanded: show full message, wrapped, preserve whitespace */ - - {message} - - ) : ( - /* Collapsed: truncated preview (preserve existing behavior & max-w) */ - - {message.length > 100 ? `${message.substring(0, 100)}...` : message} - - )} - - - ); - } - - // Default rendering for other columns - return ( - - {flexRender(cell.column.columnDef.cell, cell.getContext())} - - ); - })} - - )) - ) : ( - - - No logs found. - - - )} - + {table.getRowModel().rows?.length ? ( + table.getRowModel().rows.map((row: any, index: number) => ( + + {row.getVisibleCells().map((cell: any) => { + const isCreatedAt = cell.column.id === "created_at"; + const isMessage = cell.column.id === "message"; + return ( + + {flexRender(cell.column.columnDef.cell, cell.getContext())} + + ); + })} + + )) + ) : ( + + + No logs found. + + + )} +
+ {new Date(createdAt).toLocaleString()} +