2024-12-01 11:11:27 +01:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import Link from "next/link";
|
2025-05-16 15:54:17 +02:00
|
|
|
import Image from "next/image";
|
2026-01-07 13:33:23 +01:00
|
|
|
import {useState} from "react";
|
|
|
|
|
import {Card} from "@/components/ui/card";
|
2026-05-24 17:09:12 +02:00
|
|
|
import {ConnectionIndicator} from "@/components/common/connection-indicator";
|
2025-11-28 23:10:37 +01:00
|
|
|
import {formatDateLastContact} from "@/utils/date-formatting";
|
2025-08-29 15:31:23 +02:00
|
|
|
import {Database} from "@/db/schema/07_database";
|
2026-01-07 13:33:23 +01:00
|
|
|
import {ChevronRight, Activity, Fingerprint, Copy, Check} from "lucide-react";
|
2024-12-01 11:11:27 +01:00
|
|
|
|
2026-05-24 17:09:12 +02:00
|
|
|
export type DatabaseCardProps = {
|
2025-05-16 15:54:17 +02:00
|
|
|
data: Database;
|
2026-01-11 12:37:57 +01:00
|
|
|
withDetails?: boolean;
|
2025-05-16 15:54:17 +02:00
|
|
|
};
|
2024-12-13 14:08:24 +01:00
|
|
|
|
2026-05-24 17:09:12 +02:00
|
|
|
export const DatabaseCard = (props: DatabaseCardProps) => {
|
2026-01-11 12:37:57 +01:00
|
|
|
const {data: database, withDetails = true} = props;
|
2026-01-07 13:33:23 +01:00
|
|
|
const [isCopied, setIsCopied] = useState(false);
|
|
|
|
|
|
|
|
|
|
const handleCopy = (e: React.MouseEvent) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
navigator.clipboard.writeText(database.agentDatabaseId);
|
|
|
|
|
setIsCopied(true);
|
|
|
|
|
setTimeout(() => setIsCopied(false), 2000);
|
|
|
|
|
};
|
2024-12-13 14:08:24 +01:00
|
|
|
|
|
|
|
|
return (
|
2026-01-11 12:37:57 +01:00
|
|
|
<Card
|
|
|
|
|
className="relative h-full flex flex-col p-4 transition-all border-border/50 bg-card hover:bg-accent/50 hover:border-primary/50 group-hover:shadow-lg overflow-hidden gap-0">
|
2026-01-07 15:00:11 +01:00
|
|
|
<div className="flex items-start justify-between mb-2">
|
2026-01-11 12:37:57 +01:00
|
|
|
<div
|
|
|
|
|
className="relative w-12 h-12 p-2 bg-background rounded-xl border border-border/50 shadow-sm flex items-center justify-center group-hover:border-primary/30 transition-all duration-300 group-hover:scale-105">
|
|
|
|
|
<Image
|
|
|
|
|
src={`/images/${database.dbms}.png`}
|
2026-01-07 13:33:23 +01:00
|
|
|
alt={`${database.dbms} icon`}
|
2026-01-11 12:37:57 +01:00
|
|
|
width={32}
|
2026-01-07 15:00:11 +01:00
|
|
|
height={32}
|
2026-01-07 13:33:23 +01:00
|
|
|
className="object-contain w-full h-full"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex flex-col items-end gap-3">
|
2026-01-07 15:00:11 +01:00
|
|
|
<div className="scale-100 origin-right">
|
2026-01-17 19:36:28 +01:00
|
|
|
<ConnectionIndicator date={database.lastContact}/>
|
2025-07-26 16:34:06 +02:00
|
|
|
</div>
|
2024-12-13 14:08:24 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-01-11 12:37:57 +01:00
|
|
|
|
2026-01-07 15:00:11 +01:00
|
|
|
<div className="flex flex-col gap-2 flex-1">
|
|
|
|
|
<h3 className="text-lg font-black text-foreground group-hover:text-primary transition-colors truncate tracking-tight">
|
2026-01-07 13:33:23 +01:00
|
|
|
{database.name}
|
|
|
|
|
</h3>
|
2026-01-11 12:37:57 +01:00
|
|
|
|
2026-01-07 15:00:11 +01:00
|
|
|
<div className="flex flex-col gap-2">
|
2026-01-11 12:37:57 +01:00
|
|
|
<div
|
|
|
|
|
className="flex items-center gap-2 text-muted-foreground group-hover:text-foreground transition-colors">
|
2026-01-07 15:00:11 +01:00
|
|
|
<div className="p-1 bg-muted/50 rounded-lg">
|
2026-01-11 12:37:57 +01:00
|
|
|
<Fingerprint className="w-3.5 h-3.5"/>
|
2026-01-07 13:33:23 +01:00
|
|
|
</div>
|
2026-01-07 15:00:11 +01:00
|
|
|
<span className="font-mono text-[10px] font-bold truncate">
|
2026-01-07 13:33:23 +01:00
|
|
|
{database.agentDatabaseId}
|
|
|
|
|
</span>
|
|
|
|
|
<button
|
|
|
|
|
onClick={handleCopy}
|
2026-01-07 15:00:11 +01:00
|
|
|
className="ml-1 p-0.5 hover:bg-muted rounded-md transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 z-10"
|
2026-01-07 13:33:23 +01:00
|
|
|
title="Copy ID"
|
|
|
|
|
>
|
2026-01-11 12:37:57 +01:00
|
|
|
{isCopied ? <Check className="w-2.5 h-2.5 text-green-500"/> :
|
|
|
|
|
<Copy className="w-2.5 h-2.5"/>}
|
2026-01-07 13:33:23 +01:00
|
|
|
</button>
|
|
|
|
|
</div>
|
2026-01-11 12:37:57 +01:00
|
|
|
<div
|
|
|
|
|
className="flex items-center gap-2 text-muted-foreground group-hover:text-foreground transition-colors">
|
2026-01-07 15:00:11 +01:00
|
|
|
<div className="p-1 bg-muted/50 rounded-lg">
|
2026-01-11 12:37:57 +01:00
|
|
|
<Activity className="w-3.5 h-3.5"/>
|
2026-01-07 13:33:23 +01:00
|
|
|
</div>
|
2026-01-07 15:00:11 +01:00
|
|
|
<span className="text-[10px] font-bold uppercase tracking-tight">
|
2026-01-07 13:33:23 +01:00
|
|
|
{formatDateLastContact(database.lastContact)}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-01-11 12:37:57 +01:00
|
|
|
|
|
|
|
|
{withDetails && (
|
|
|
|
|
<div className="mt-4 flex items-center justify-between pt-3 border-t border-border/50">
|
|
|
|
|
<span
|
|
|
|
|
className="text-[10px] font-black uppercase tracking-widest text-primary opacity-0 group-hover:opacity-100 transition-all duration-300 transform translate-x-[-10px] group-hover:translate-x-0">Open</span>
|
|
|
|
|
<div
|
|
|
|
|
className="flex items-center gap-1 text-muted-foreground group-hover:text-primary transition-colors">
|
|
|
|
|
<span
|
|
|
|
|
className="text-[10px] font-bold uppercase tracking-widest group-hover:hidden">Details</span>
|
|
|
|
|
<ChevronRight className="w-3.5 h-3.5 group-hover:translate-x-1 transition-transform"/>
|
|
|
|
|
</div>
|
2026-01-07 13:33:23 +01:00
|
|
|
</div>
|
2026-01-11 12:37:57 +01:00
|
|
|
)}
|
2024-12-13 14:08:24 +01:00
|
|
|
</Card>
|
2025-05-16 15:54:17 +02:00
|
|
|
);
|
|
|
|
|
};
|