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 | 49x 78x 78x 78x 49x 78x 1x 1x 1x 1x | /**
* Table component for displaying SQL macros
*/
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
import { Button } from "@/components/ui/button"
import { Badge } from "@/components/ui/badge"
import { MoreHorizontal, Edit, Trash2, Eye, Terminal } from "lucide-react"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import type { Macro } from "@/types/macro"
import { format } from "date-fns"
interface MacrosTableProps {
macros: Macro[]
onView: (macro: Macro) => void
onEdit: (macro: Macro) => void
onDelete: (macro: Macro) => void
onTest: (macro: Macro) => void
}
export default function MacrosTable({
macros,
onView,
onEdit,
onDelete,
onTest,
}: MacrosTableProps) {
const getParamCount = (paramsStr: string) => {
try {
const params = JSON.parse(paramsStr)
return Array.isArray(params) ? params.length : 0
} catch {
return 0
}
}
return (
<div className="rounded-md border">
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Description</TableHead>
<TableHead className="text-center">Parameters</TableHead>
<TableHead>Last Updated</TableHead>
<TableHead className="text-right">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{macros.length === 0 ? (
<TableRow>
<TableCell colSpan={5} className="h-24 text-center">
No macros found.
</TableCell>
</TableRow>
) : (
macros.map((macro) => (
<TableRow key={macro.id}>
<TableCell className="font-medium">
<div className="flex items-center gap-2">
<span className="text-primary">@</span>
{macro.name}
</div>
</TableCell>
<TableCell className="max-w-xs truncate" title={macro.description || ""}>
{macro.description || <span className="text-muted-foreground italic text-xs">No description</span>}
</TableCell>
<TableCell className="text-center">
<Badge variant="secondary">
{getParamCount(macro.parameters)}
</Badge>
</TableCell>
<TableCell>
{format(new Date(macro.updated_at), "MMM d, yyyy HH:mm")}
</TableCell>
<TableCell className="text-right">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Actions</DropdownMenuLabel>
<DropdownMenuItem onClick={() => onView(macro)}>
<Eye className="mr-2 h-4 w-4" />
View Details
</DropdownMenuItem>
<DropdownMenuItem onClick={() => onTest(macro)}>
<Terminal className="mr-2 h-4 w-4" />
Test Macro
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => onEdit(macro)}>
<Edit className="mr-2 h-4 w-4" />
Edit
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => onDelete(macro)}
className="text-destructive focus:text-destructive"
>
<Trash2 className="mr-2 h-4 w-4" />
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
)
}
|