Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 'use client'; /** * DevTicketTable - Table display of dev tickets with sortable columns */ import React from 'react'; import Link from 'next/link'; import { DevTicketWithRelations, DevTicketCategory } from '@/types/dev-ticket'; import { DEV_TICKET_TYPE_CONFIG, DEV_TICKET_STATUS_CONFIG, DEV_TICKET_PRIORITY_CONFIG, DEV_TICKET_CATEGORY_CONFIG } from '@/constants/dev-ticket'; import type { SortField, SortDirection } from './index'; import Image from 'next/image'; import { Icon } from '@/components/ui/icons'; export interface DevTicketTableProps { /** List of tickets to display */ tickets: DevTicketWithRelations[]; /** Loading state */ loading: boolean; /** Selected ticket IDs */ selectedIds: Set<string>; /** Handler for select all */ onSelectAll: (checked: boolean) => void; /** Handler for selecting individual ticket */ onSelectOne: (id: string, checked: boolean) => void; /** Current sort state */ sort: { field: SortField; direction: SortDirection }; /** Handler for sort change */ onSort: (field: SortField) => void; } // Sort indicator component function SortIndicator({ field, sort }: { field: SortField; sort: { field: SortField; direction: SortDirection } }) { if (sort.field !== field) { return ( <Icon name="sort" size={16} className="text-gray-300 ml-1" /> ); } return sort.direction === 'asc' ? ( <Icon name="chevron-up" size={16} className="text-indigo-600 ml-1" /> ) : ( <Icon name="chevron-down" size={16} className="text-indigo-600 ml-1" /> ); } // Sortable column header component function SortableHeader({ field, label, sort, onSort}: { field: SortField; label: string; sort: { field: SortField; direction: SortDirection }; onSort: (field: SortField) => void; }) { return ( <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700 select-none" onClick={() => onSort(field)} > <div className="flex items-center"> {label} <SortIndicator field={field} sort={sort} /> </div> </th> ); } export default function DevTicketTable({ tickets, loading, selectedIds, onSelectAll, onSelectOne, sort, onSort}: DevTicketTableProps) { const allSelected = tickets.length > 0 && selectedIds.size === tickets.length; const someSelected = selectedIds.size > 0 && selectedIds.size < tickets.length; if (loading) { return ( <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center"> <div className="animate-spin h-8 w-8 border-4 border-indigo-600 border-t-transparent rounded-full mx-auto" /> <p className="text-gray-500 dark:text-gray-400 mt-4">Loading tickets...</p> </div> ); } if (!tickets || tickets.length === 0) { return ( <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-8 text-center"> <Icon name="clipboard-list" size={48} className="text-gray-400 dark:text-gray-500 mx-auto mb-4" /> <p className="text-gray-500 dark:text-gray-400">No tickets found</p> <Link href="/admin/dev/tickets/new" className="inline-flex items-center mt-4 px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors" > <Icon name="plus" size={16} className="mr-2" /> Create Ticket </Link> </div> ); } return ( <div className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden"> <div className="overflow-x-auto"> <table className="min-w-full divide-y divide-gray-200 dark:divide-gray-700"> <thead className="bg-gray-50 dark:bg-gray-900"> <tr> <th className="px-4 py-3 w-10"> <input type="checkbox" checked={allSelected} ref={(el) => { if (el) el.indeterminate = someSelected; }} onChange={(e) => onSelectAll(e.target.checked)} className="h-4 w-4 text-indigo-600 rounded border-gray-300 dark:border-gray-600 focus:ring-indigo-500 dark:bg-gray-700" /> </th> <SortableHeader field="category" label="Category" sort={sort} onSort={onSort} /> <SortableHeader field="type" label="Type" sort={sort} onSort={onSort} /> <SortableHeader field="ticketNumber" label="Ticket" sort={sort} onSort={onSort} /> <SortableHeader field="status" label="Status" sort={sort} onSort={onSort} /> <SortableHeader field="priority" label="Priority" sort={sort} onSort={onSort} /> <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider"> Parent </th> <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider"> Project </th> <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider"> Assignee </th> <th className="px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider"> Children </th> <SortableHeader field="createdAt" label="Created" sort={sort} onSort={onSort} /> </tr> </thead> <tbody className="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700"> {tickets.map((ticket) => { const categoryConfig = DEV_TICKET_CATEGORY_CONFIG[(ticket.category || 'TASK') as DevTicketCategory]; const typeConfig = DEV_TICKET_TYPE_CONFIG[ticket.type as keyof typeof DEV_TICKET_TYPE_CONFIG]; const statusConfig = DEV_TICKET_STATUS_CONFIG[ticket.status as keyof typeof DEV_TICKET_STATUS_CONFIG]; const priorityConfig = DEV_TICKET_PRIORITY_CONFIG[ ticket.priority as keyof typeof DEV_TICKET_PRIORITY_CONFIG ]; const isOverdue = ticket.dueDate && new Date(ticket.dueDate) < new Date() && !['COMPLETED', 'CANCELLED', 'WONT_FIX'].includes(ticket.status); // Child counts const childCount = ticket.childCount || 0; const completedChildCount = ticket.completedChildCount || 0; return ( <tr key={ticket.id} className="hover:bg-gray-50 dark:hover:bg-gray-700"> <td className="px-4 py-3"> <input type="checkbox" checked={selectedIds.has(ticket.id)} onChange={(e) => onSelectOne(ticket.id, e.target.checked)} className="h-4 w-4 text-indigo-600 rounded border-gray-300 dark:border-gray-600 focus:ring-indigo-500 dark:bg-gray-700" /> </td> {/* Category */} <td className="px-4 py-3"> <span className={`inline-flex items-center px-2 py-0.5 text-xs font-medium rounded ${categoryConfig?.bgColor || 'bg-gray-100'} ${categoryConfig?.color || 'text-gray-600'}`} title={categoryConfig?.description} > {categoryConfig?.icon && ( <span className="mr-1">{categoryConfig.icon}</span> )} {categoryConfig?.label || 'Task'} </span> </td> {/* Type */} <td className="px-4 py-3"> <span className={`inline-flex items-center px-2 py-0.5 text-xs font-medium rounded ${typeConfig?.bgColor || 'bg-gray-100'} ${typeConfig?.color || 'text-gray-600'}`} > {typeConfig?.icon && ( <span className="mr-1">{typeConfig.icon}</span> )} {typeConfig?.label || ticket.type} </span> </td> {/* Ticket */} <td className="px-4 py-3"> <Link href={`/admin/dev/tickets/${ticket.id}`} className="group"> <p className="text-sm font-medium text-gray-500 dark:text-gray-400"> {ticket.ticketNumber} </p> <p className="text-sm font-medium text-gray-900 dark:text-gray-100 group-hover:text-indigo-600 dark:group-hover:text-indigo-400"> {ticket.title} </p> {isOverdue && ( <span className="inline-flex items-center text-xs text-red-600 mt-0.5"> <Icon name="warning" size={12} className="mr-1" /> Overdue </span> )} </Link> </td> {/* Status */} <td className="px-4 py-3"> <span className={`inline-flex px-2 py-0.5 text-xs font-medium rounded-full ${statusConfig?.bgColor || 'bg-gray-100'} ${statusConfig?.color || 'text-gray-600'}`} > {statusConfig?.label || ticket.status} </span> </td> {/* Priority */} <td className="px-4 py-3"> <span className={`inline-flex px-2 py-0.5 text-xs font-medium rounded-full ${priorityConfig?.bgColor || 'bg-gray-100'} ${priorityConfig?.color || 'text-gray-600'}`} > {priorityConfig?.label || ticket.priority} </span> </td> {/* Parent */} <td className="px-4 py-3"> {ticket.parent ? ( <Link href={`/admin/dev/tickets/${ticket.parent.id}`} className="text-xs text-indigo-600 hover:text-indigo-800 dark:text-indigo-400 dark:hover:text-indigo-300" > {ticket.parent.ticketNumber} </Link> ) : ( <span className="text-xs text-gray-400 dark:text-gray-500">-</span> )} </td> {/* Project */} <td className="px-4 py-3"> {ticket.project ? ( <span className="inline-flex items-center px-2 py-0.5 text-xs font-medium rounded" style={{ backgroundColor: `${ticket.project.color}20`, color: ticket.project.color}} > [{ticket.project.key}] {ticket.project.name} </span> ) : ( <span className="text-xs text-gray-400 dark:text-gray-500 italic">No project</span> )} </td> {/* Assignee */} <td className="px-4 py-3"> {ticket.assignee ? ( <div className="flex items-center"> {ticket.assignee.image ? ( <Image src={ticket.assignee.image} alt={ticket.assignee.name || ''} width={24} height={24} className="w-6 h-6 rounded-full mr-2" /> ) : ( <div className="w-6 h-6 rounded-full bg-gray-200 dark:bg-gray-600 flex items-center justify-center mr-2"> <span className="text-xs text-gray-600 dark:text-gray-300"> {ticket.assignee.name?.charAt(0) || '?'} </span> </div> )} <span className="text-sm text-gray-900 dark:text-gray-100"> {ticket.assignee.name} </span> </div> ) : ( <span className="text-sm text-gray-400 dark:text-gray-500 italic">Unassigned</span> )} </td> {/* Children */} <td className="px-4 py-3"> {childCount > 0 ? ( <span className="text-sm text-gray-900 dark:text-gray-100"> {completedChildCount}/{childCount} </span> ) : ( <span className="text-xs text-gray-400 dark:text-gray-500">-</span> )} </td> {/* Created */} <td className="px-4 py-3 text-sm text-gray-500 dark:text-gray-400"> {new Date(ticket.createdAt).toLocaleDateString()} </td> </tr> ); })} </tbody> </table> </div> </div> ); } |