2025-05-16 15:54:17 +02:00
|
|
|
"use client";
|
2024-11-11 14:56:33 +01:00
|
|
|
|
2025-07-16 20:16:18 +02:00
|
|
|
import {ColumnDef} from "@tanstack/react-table";
|
|
|
|
|
import {StatusBadge} from "@/components/wrappers/common/status-badge";
|
2025-08-29 15:31:23 +02:00
|
|
|
import {Backup, DatabaseWith} from "@/db/schema/07_database";
|
|
|
|
|
import {Setting} from "@/db/schema/01_setting";
|
2025-09-22 20:31:29 +02:00
|
|
|
import {cn} from "@/lib/utils";
|
|
|
|
|
import {Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from "@/components/ui/tooltip";
|
2025-11-01 14:50:08 +01:00
|
|
|
import {MemberWithUser} from "@/db/schema/03_organization";
|
2025-11-08 20:07:49 +01:00
|
|
|
import {formatLocalizedDate} from "@/utils/date-formatting";
|
2026-02-13 22:40:44 +01:00
|
|
|
import {formatBytes} from "@/utils/text";
|
2026-01-17 15:57:37 +01:00
|
|
|
import {DatabaseActionsCell} from "@/components/wrappers/dashboard/database/backup/actions/backup-actions-cell";
|
2026-02-10 11:44:45 +01:00
|
|
|
import { Badge as BadgeC } from "@/components/ui/badge";
|
2026-03-15 12:02:00 +01:00
|
|
|
import {backupOnly} from "@/components/wrappers/dashboard/projects/database/database-tabs";
|
2025-07-16 20:16:18 +02:00
|
|
|
|
2025-11-01 14:50:08 +01:00
|
|
|
export function backupColumns(
|
|
|
|
|
isAlreadyRestore: boolean,
|
|
|
|
|
settings: Setting,
|
|
|
|
|
database: DatabaseWith,
|
|
|
|
|
activeMember: MemberWithUser
|
|
|
|
|
): ColumnDef<Backup>[] {
|
2026-03-15 12:02:00 +01:00
|
|
|
|
|
|
|
|
const isBackupOnly = backupOnly.some((type) => database.dbms === type)
|
|
|
|
|
|
|
|
|
|
|
2025-07-16 20:16:18 +02:00
|
|
|
return [
|
2025-09-22 20:31:29 +02:00
|
|
|
{
|
|
|
|
|
id: "availability",
|
|
|
|
|
cell: ({row}) => {
|
2026-02-13 22:40:44 +01:00
|
|
|
const statusColors: Record<string, string> = {
|
|
|
|
|
waiting: "bg-gray-400 border-gray-600",
|
|
|
|
|
ongoing: "bg-orange-400 border-orange-600",
|
|
|
|
|
success: "bg-green-400 border-green-600",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const colorStatus =
|
|
|
|
|
row.original.deletedAt != null
|
|
|
|
|
? "bg-red-400 border-red-600"
|
|
|
|
|
: statusColors[row.original.status] ?? "bg-gray-400 border-gray-600";
|
|
|
|
|
|
2025-09-22 20:31:29 +02:00
|
|
|
return (
|
|
|
|
|
<TooltipProvider>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<div className={cn("w-5 h-5 rounded-full border-4", colorStatus)}/>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
{row.original.deletedAt != null && (
|
|
|
|
|
<TooltipContent>
|
2025-11-08 20:07:49 +01:00
|
|
|
<p>{formatLocalizedDate(row.original.deletedAt)}</p>
|
2025-09-22 20:31:29 +02:00
|
|
|
</TooltipContent>
|
|
|
|
|
)}
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-07-16 20:16:18 +02:00
|
|
|
{
|
|
|
|
|
accessorKey: "id",
|
|
|
|
|
header: "Reference",
|
2025-12-26 16:08:36 +01:00
|
|
|
cell: ({row}) => {
|
|
|
|
|
const reference = row.original.id
|
2026-01-17 20:56:57 +01:00
|
|
|
const isImported = row.original.imported
|
2026-02-10 11:44:45 +01:00
|
|
|
return (
|
|
|
|
|
<div className="flex items-center space-x-2">
|
|
|
|
|
<span>{reference}</span>
|
|
|
|
|
{isImported && (
|
|
|
|
|
<BadgeC variant="outline" className="bg-orange-400/10 border-orange-600/50 text-orange-600">
|
|
|
|
|
Imported
|
|
|
|
|
</BadgeC>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2025-12-26 16:08:36 +01:00
|
|
|
},
|
2024-11-11 19:12:34 +01:00
|
|
|
},
|
2026-01-02 15:32:36 +01:00
|
|
|
{
|
|
|
|
|
accessorKey: "fileSize",
|
|
|
|
|
header: "Size",
|
|
|
|
|
cell: ({row}) => {
|
|
|
|
|
return formatBytes(row.getValue("fileSize"))
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-07-16 20:16:18 +02:00
|
|
|
{
|
|
|
|
|
accessorKey: "createdAt",
|
|
|
|
|
header: "Created At",
|
|
|
|
|
cell: ({row}) => {
|
2025-11-08 20:07:49 +01:00
|
|
|
return formatLocalizedDate(row.getValue("createdAt"))
|
2025-07-16 20:16:18 +02:00
|
|
|
},
|
2024-11-11 14:56:33 +01:00
|
|
|
},
|
2025-07-16 20:16:18 +02:00
|
|
|
{
|
|
|
|
|
accessorKey: "status",
|
|
|
|
|
header: "Status",
|
|
|
|
|
cell: ({row}) => {
|
|
|
|
|
return <StatusBadge status={row.getValue("status")}/>;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "actions",
|
2026-03-15 12:02:00 +01:00
|
|
|
cell: ({row}) => <DatabaseActionsCell isAlreadyRestore={isAlreadyRestore} activeMember={activeMember} backup={row.original} isBackupOnly={isBackupOnly}/>,
|
2024-11-11 14:56:33 +01:00
|
|
|
},
|
2025-07-16 20:16:18 +02:00
|
|
|
];
|
|
|
|
|
}
|