From 262322cfa6ab6bc7ea3000130a4b00da5d041bb5 Mon Sep 17 00:00:00 2001 From: killian-larcher Date: Mon, 11 Nov 2024 19:12:34 +0100 Subject: [PATCH] wrapping some components. --- .../dashboard/agents/[agentId]/page.tsx | 81 ++++++++++++++----- .../dashboard/agents/[agentId]/test.txt | 0 app/(customer)/dashboard/agents/page.tsx | 2 +- app/(customer)/dashboard/layout.tsx | 2 +- prisma/schema.prisma | 53 +++++++----- .../wrappers/cards-with-pagination.tsx | 6 +- .../pagination/pagination-navigation.tsx | 2 +- .../table/data-table-with-pagination.tsx | 4 +- .../wrappers/table/table-pagination-size.tsx | 7 +- .../wrappers/table/table-pagination.tsx | 9 ++- src/features/backup/columns.tsx | 5 +- src/features/layout/page.tsx | 37 ++++++--- src/features/restore/columns.tsx | 5 +- 13 files changed, 145 insertions(+), 68 deletions(-) delete mode 100644 app/(customer)/dashboard/agents/[agentId]/test.txt diff --git a/app/(customer)/dashboard/agents/[agentId]/page.tsx b/app/(customer)/dashboard/agents/[agentId]/page.tsx index 98ace108..69211bc6 100644 --- a/app/(customer)/dashboard/agents/[agentId]/page.tsx +++ b/app/(customer)/dashboard/agents/[agentId]/page.tsx @@ -3,12 +3,28 @@ import {Page, PageActions, PageContent, PageDescription, PageHeader, PageTitle} import {Button} from "@/components/ui/button"; import {Tabs, TabsContent, TabsList, TabsTrigger} from "@/components/ui/tabs"; import {Card, CardContent, CardHeader} from "@/components/ui/card"; -import {TablePagination} from "@/components/wrappers/table/table-pagination"; -import {columns} from "@/features/backup/columns"; +import {backupColumns} from "@/features/backup/columns"; +import {restoreColumns} from "@/features/restore/columns"; import {DataTableWithPagination} from "@/components/wrappers/table/data-table-with-pagination"; +import {prisma} from "@/prisma"; +import {GearIcon} from "@radix-ui/react-icons"; +import Link from "next/link"; -export default async function RoutePage(props: PageParams<{}>) { +export default async function RoutePage(props: PageParams<{ agentId: string }>) { + + // const agent = await prisma.agent.findUnique({ + // where: { + // id: props.params.agentId, + // }, + // }) + + const agent = { + "id": props.params.agentId, + "name": "Agent 1", + "description": "My beautiful project!", + "lastContact": null, + } const backups = [ {'id': 'backup-1', 'createdAt': '2023-11-27T11:26:54.870914Z', 'status': 'pending'}, @@ -46,58 +62,83 @@ export default async function RoutePage(props: PageParams<{}>) { {'id': 'restore-10', 'backupId': 'backup-10', 'createdAt': '2023-11-25T11:26:54.871000Z', 'status': 'failed'} ] + const databaseId = 'db-123'; + + const totalBackups = await prisma.backup.count({ + where: { + databaseId: databaseId, + }, + }); + + const successfulBackups = await prisma.backup.count({ + where: { + databaseId: databaseId, + status: 'success', + }, + }); + + const successRate = totalBackups > 0 ? (successfulBackups / totalBackups) * 100 : null + + return ( - Agent 1 + {agent.name} + + + + - My beautiful project! + {agent.description} - -
+ +
- + Backups - + Success rate - + + {successRate ?? "Unavailable for now."} + - + Last contact - + + {agent.lastContact?.toDateString() ?? "Never connected"} +
- + + Backup - Restore + Backup - - + + - - + + -
- // test ) } \ No newline at end of file diff --git a/app/(customer)/dashboard/agents/[agentId]/test.txt b/app/(customer)/dashboard/agents/[agentId]/test.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/app/(customer)/dashboard/agents/page.tsx b/app/(customer)/dashboard/agents/page.tsx index f4b25e03..38c883d5 100644 --- a/app/(customer)/dashboard/agents/page.tsx +++ b/app/(customer)/dashboard/agents/page.tsx @@ -36,7 +36,7 @@ export default async function RoutePage(props: PageParams<{}>) { - +
-
+
{children}
diff --git a/prisma/schema.prisma b/prisma/schema.prisma index de672dd0..f44dc634 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -61,35 +61,39 @@ model User { image String? role String? password String? + authMethod String? @map("auth_method") + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime? @updatedAt @map("updated_at") - accounts Account[] - sessions Session[] - authMethod String? - createdAt DateTime @default(now()) @map("created_at") - updatedAt DateTime? @updatedAt @map("updated_at") + accounts Account[] + sessions Session[] @@map("users") } model Agent { - id String @id @default(cuid()) - slug String @unique + id String @id @default(cuid()) + slug String @unique name String description String? - lastContact DateTime? @map("last_contact") - createdAt DateTime @default(now()) @map("created_at") - databases Database[] + lastContact DateTime? @map("last_contact") + createdAt DateTime @default(now()) @map("created_at") + + databases Database[] } model Database { - id String @id @default(cuid()) - agentId String @map("agent_id") - agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade) - + id String @id @default(cuid()) name String description String? backupPolicy String? @map("backup_policy") createdAt DateTime @default(now()) @map("created_at") + + agentId String @map("agent_id") + agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade) + + backups Backup[] + restaurations Restauration[] } enum Status { @@ -100,16 +104,25 @@ enum Status { } model Backup { - id String @id @default(cuid()) + id String @id @default(cuid()) + status Status @default(waiting) + file String? + createdAt DateTime @default(now()) @map("created_at") + databaseId String @map("database_id") - status Status @default(waiting) - file String? - createdAt DateTime @default(now()) @map("created_at") + database Database @relation(fields: [databaseId], references: [id], onDelete: Cascade) + + restaurations Restauration[] } -model Restore { +model Restauration { id String @id @default(cuid()) - backupId String @map("backup_id") status Status @default(waiting) createdAt DateTime @default(now()) @map("created_at") + + backupId String @map("backup_id") + backup Backup @relation(fields: [backupId], references: [id], onDelete: Cascade) + + databaseId String? @map("database_id") + database Database? @relation(fields: [databaseId], references: [id], onDelete: Cascade) } diff --git a/src/components/wrappers/cards-with-pagination.tsx b/src/components/wrappers/cards-with-pagination.tsx index e3c2e892..4c78ed2a 100644 --- a/src/components/wrappers/cards-with-pagination.tsx +++ b/src/components/wrappers/cards-with-pagination.tsx @@ -42,14 +42,14 @@ export const CardsWithPagination = (props: cardsWithPaginationProps) => { return ( -
-
+
+
{currentCards.map((card, key) => ( ))}
{ const {className, totalPages, currentPage, goToPage, goToPrevPage, goToNextPage, maxVisiblePages = 3} = props return ( - + diff --git a/src/components/wrappers/table/data-table-with-pagination.tsx b/src/components/wrappers/table/data-table-with-pagination.tsx index b3f39fea..b1e68d38 100644 --- a/src/components/wrappers/table/data-table-with-pagination.tsx +++ b/src/components/wrappers/table/data-table-with-pagination.tsx @@ -30,9 +30,9 @@ export function DataTableWithPagination({columns, data}: DataTabl }) return ( -
+
- +
) } diff --git a/src/components/wrappers/table/table-pagination-size.tsx b/src/components/wrappers/table/table-pagination-size.tsx index 071ede60..f9a20a7d 100644 --- a/src/components/wrappers/table/table-pagination-size.tsx +++ b/src/components/wrappers/table/table-pagination-size.tsx @@ -1,3 +1,4 @@ +import {useEffect} from "react"; import {Select, SelectContent, SelectItem, SelectTrigger, SelectValue} from "@/components/ui/select"; import {cn} from "@/lib/utils"; @@ -12,8 +13,12 @@ export const TablePaginationSize = (props: tablePaginationSizeProps) => { const {className, table, pageSizeOptions = [10, 20, 30, 40, 50]} = props + useEffect(() => { + table.setPageSize(Number(pageSizeOptions[0])) + }, []); + return ( -
+

Rows per page