refactor: add swarm improvements

This commit is contained in:
Mauricio Siu
2024-12-25 03:45:21 -06:00
parent e65e6d225f
commit 64a449a09d
4 changed files with 99 additions and 3 deletions

View File

@@ -0,0 +1,58 @@
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import dynamic from "next/dynamic";
import type React from "react";
export const DockerLogsId = dynamic(
() =>
import("@/components/dashboard/docker/logs/docker-logs-id").then(
(e) => e.DockerLogsId,
),
{
ssr: false,
},
);
interface Props {
containerId: string;
children?: React.ReactNode;
serverId?: string | null;
}
export const ShowDockerModalStackLogs = ({
containerId,
children,
serverId,
}: Props) => {
return (
<Dialog>
<DialogTrigger asChild>
<DropdownMenuItem
className="w-full cursor-pointer space-x-3"
onSelect={(e) => e.preventDefault()}
>
{children}
</DropdownMenuItem>
</DialogTrigger>
<DialogContent className="max-h-screen overflow-y-auto sm:max-w-7xl">
<DialogHeader>
<DialogTitle>View Logs</DialogTitle>
<DialogDescription>View the logs for {containerId}</DialogDescription>
</DialogHeader>
<div className="flex flex-col gap-4 pt-2.5">
<DockerLogsId
containerId={containerId || ""}
serverId={serverId}
runType="swarm"
/>
</div>
</DialogContent>
</Dialog>
);
};

View File

@@ -1,9 +1,17 @@
import type { ColumnDef } from "@tanstack/react-table";
import { ArrowUpDown } from "lucide-react";
import { ArrowUpDown, MoreHorizontal } from "lucide-react";
import * as React from "react";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuLabel,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Badge } from "@/components/ui/badge";
import { ShowDockerModalStackLogs } from "../../docker/logs/show-docker-modal-stack-logs";
export interface ApplicationList {
ID: string;
@@ -16,6 +24,7 @@ export interface ApplicationList {
DesiredState: string;
Error: string;
Node: string;
serverId: string;
}
export const columns: ColumnDef<ApplicationList>[] = [
@@ -203,4 +212,34 @@ export const columns: ColumnDef<ApplicationList>[] = [
return <div className="w-[10rem]">{row.getValue("Errors")}</div>;
},
},
{
accessorKey: "Logs",
accessorFn: (row) => row.Error,
header: ({ column }) => {
return <span>Logs</span>;
},
cell: ({ row }) => {
return (
<span className="w-[10rem]">
<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>
<ShowDockerModalStackLogs
containerId={row.original.ID}
serverId={row.original.serverId}
>
View Logs
</ShowDockerModalStackLogs>
</DropdownMenuContent>
</DropdownMenu>
</span>
);
},
},
];

View File

@@ -89,6 +89,7 @@ export const ShowNodeApplications = ({ serverId }: Props) => {
Error: detail.Error,
Node: detail.Node,
Ports: detail.Ports || app.Ports,
serverId: serverId || "",
}));
});

View File

@@ -460,8 +460,6 @@ export const getApplicationInfo = async (
.split("\n")
.map((line) => JSON.parse(line));
console.log(appArray);
return appArray;
} catch (error) {}
};