'use client'; import { useState } from 'react'; import { ConfigInfo } from '@/lib/supervisor/types'; import { Card, CardContent } from '@/components/ui/card'; import { ChevronUp, ChevronDown } from 'lucide-react'; import { cn } from '@/lib/utils/cn'; interface ConfigTableProps { configs: ConfigInfo[]; } type SortField = 'group' | 'name' | 'command' | 'autostart' | 'directory'; type SortDirection = 'asc' | 'desc'; export function ConfigTable({ configs }: ConfigTableProps) { const [sortField, setSortField] = useState('group'); const [sortDirection, setSortDirection] = useState('asc'); const handleSort = (field: SortField) => { if (sortField === field) { setSortDirection(sortDirection === 'asc' ? 'desc' : 'asc'); } else { setSortField(field); setSortDirection('asc'); } }; const sortedConfigs = [...configs].sort((a, b) => { let aVal: any = a[sortField]; let bVal: any = b[sortField]; // Handle boolean values if (typeof aVal === 'boolean') { aVal = aVal ? 1 : 0; bVal = bVal ? 1 : 0; } // Handle string values if (typeof aVal === 'string') { aVal = aVal.toLowerCase(); bVal = bVal.toLowerCase(); } if (aVal < bVal) return sortDirection === 'asc' ? -1 : 1; if (aVal > bVal) return sortDirection === 'asc' ? 1 : -1; return 0; }); const SortIcon = ({ field }: { field: SortField }) => { if (sortField !== field) return null; return sortDirection === 'asc' ? ( ) : ( ); }; return ( <> {/* Desktop Table View - hidden on mobile */}
{sortedConfigs.map((config, index) => ( ))}
handleSort('group')} > Group handleSort('name')} > Name handleSort('command')} > Command Directory handleSort('autostart')} > Autostart Priority
{config.group} {config.name} {config.command} {config.directory} {config.process_prio}
{/* Mobile Card View - visible on mobile only */}
{sortedConfigs.map((config) => (
{config.name}
{config.group}
Command: {config.command}
Directory:
{config.directory}
Priority: {config.process_prio}
))}
); }