diff --git a/web/src/app/(app)/workflows/[workflow_id]/@deployment/page.tsx b/web/src/app/(app)/workflows/[workflow_id]/@deployment/page.tsx index 34eb1f0..f2a1381 100644 --- a/web/src/app/(app)/workflows/[workflow_id]/@deployment/page.tsx +++ b/web/src/app/(app)/workflows/[workflow_id]/@deployment/page.tsx @@ -1,5 +1,5 @@ import { LoadingWrapper } from "@/components/LoadingWrapper"; -import { DeploymentsTable } from "@/components/RunsTable"; +import { DeploymentsTable } from "@/components/DeploymentsTable"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; export default async function Page({ diff --git a/web/src/components/DeploymentsTable.tsx b/web/src/components/DeploymentsTable.tsx new file mode 100644 index 0000000..30d4480 --- /dev/null +++ b/web/src/components/DeploymentsTable.tsx @@ -0,0 +1,41 @@ +import { + Table, + TableBody, + TableCaption, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; +import { headers } from "next/headers"; +import { findAllDeployments } from "../server/findAllRuns"; +import { DeploymentDisplay } from "./DeploymentDisplay"; + +export async function DeploymentsTable(props: { workflow_id: string }) { + const allRuns = await findAllDeployments(props.workflow_id); + + const headersList = headers(); + const host = headersList.get("host") || ""; + const protocol = headersList.get("x-forwarded-proto") || ""; + const domain = `${protocol}://${host}`; + + return ( +
+ + A list of your deployments + + + Environment + Version + Machine + Updated At + + + + {allRuns.map((run) => ( + + ))} + +
+
+ ); +} diff --git a/web/src/components/RunDisplay.tsx b/web/src/components/RunDisplay.tsx index 022d86d..614ce21 100644 --- a/web/src/components/RunDisplay.tsx +++ b/web/src/components/RunDisplay.tsx @@ -25,7 +25,7 @@ import { LogsType, LogsViewer } from "@/components/LogsViewer"; import { Button } from "@/components/ui/button"; import { Edit, ExternalLink } from "lucide-react"; -export async function RunDisplay({ +export function RunDisplay({ run, }: { run: Awaited>[0]; diff --git a/web/src/components/RunsTable.tsx b/web/src/components/RunsTable.tsx index a790b8a..0ebb5c9 100644 --- a/web/src/components/RunsTable.tsx +++ b/web/src/components/RunsTable.tsx @@ -1,3 +1,5 @@ +"use client"; + import { Table, TableBody, @@ -7,94 +9,69 @@ import { TableRow, } from "@/components/ui/table"; import { parseAsInteger } from "next-usequerystate"; -import { headers } from "next/headers"; import { - findAllDeployments, - findAllRunsWithCounts, + findAllRunsWithCounts, + getAllRunstableContent, } from "../server/findAllRuns"; -import { DeploymentDisplay } from "./DeploymentDisplay"; import { PaginationControl } from "./PaginationControl"; import { RunDisplay } from "./RunDisplay"; +import useSWR from "swr"; const itemPerPage = 6; const pageParser = parseAsInteger.withDefault(1); -export async function RunsTable(props: { +export function RunsTable(props: { workflow_id: string; - searchParams: { [key: string]: string | string[] | undefined }; + searchParams: { [key: string]: any }; }) { - // await new Promise((resolve) => setTimeout(resolve, 5000)); - const page = pageParser.parseServerSide( - props.searchParams?.page ?? undefined + const page = pageParser.parse(props.searchParams?.page ?? undefined) ?? 1; + const { data, error, isLoading } = useSWR( + "runs+" + page, + async () => { + const data = await getAllRunstableContent({ + workflow_id: props.workflow_id, + limit: itemPerPage, + offset: (page - 1) * itemPerPage, + }); + return data; + }, + { + // suspense: false, + refreshInterval: 5000, + }, ); - const { allRuns, total } = await findAllRunsWithCounts({ - workflow_id: props.workflow_id, - limit: itemPerPage, - offset: (page - 1) * itemPerPage, - }); - return ( -
-
- - {allRuns.length === 0 && ( - A list of your recent runs. - )} - - - Number - Machine - Time - Version - Origin - Duration - Live Status - Status - - - - {allRuns.map((run) => ( - - ))} - -
-
- {Math.ceil(total / itemPerPage) > 0 && ( - - )} -
- ); -} - -export async function DeploymentsTable(props: { workflow_id: string }) { - const allRuns = await findAllDeployments(props.workflow_id); - - const headersList = headers(); - const host = headersList.get("host") || ""; - const protocol = headersList.get("x-forwarded-proto") || ""; - const domain = `${protocol}://${host}`; + // await new Promise((resolve) => setTimeout(resolve, 5000)); return ( -
- - A list of your deployments - - - Environment - Version - Machine - Updated At - - - - {allRuns.map((run) => ( - - ))} - -
+
+
+ + {/* {data?.allRuns.length === 0 && ( + A list of your recent runs. + )} */} + + + Number + Machine + Time + Version + Origin + Duration + Live Status + Status + + + {data?.table} +
+
+ + {data && Math.ceil(data.total / itemPerPage) > 0 && ( + + )}
); } diff --git a/web/src/server/findAllRuns.tsx b/web/src/server/findAllRuns.tsx index 77be9d1..7de258a 100644 --- a/web/src/server/findAllRuns.tsx +++ b/web/src/server/findAllRuns.tsx @@ -1,5 +1,6 @@ "use server"; +import { RunDisplay } from "@/components/RunDisplay"; import { db } from "@/db/db"; import { deploymentsTable, workflowRunsTable } from "@/db/schema"; import { count, desc, eq, sql } from "drizzle-orm"; @@ -56,6 +57,15 @@ export async function findAllRuns({ }); } +export async function getAllRunstableContent(props: RunsSearchTypes) { + const data = await findAllRunsWithCounts(props); + + return { + table: data?.allRuns.map((run) => ), + total: data?.total, + }; +} + export async function findAllRunsWithCounts(props: RunsSearchTypes) { const a = await db .select({